PID Controller Instrument

The PID Controller allows for dual channel (independent or MIMO) control of voltage-input, voltage-output signals. The PID includes a double-integrator and fully-configurable integrator saturation (anti-windup) and differentiator saturation.

Example Usage

The following example code and a wide range of other pymoku demo scripts can be found at the pymoku Github repository.

pidcontroller_basic.py
# pymoku example: Basic PID Controller
#
# This script demonstrates how to configure one of the two PID Controllers
# in the PID Controller instrument. Configuration is done by specifying
# frequency response characteristics of the controller.
#
# (c) 2019 Liquid Instruments Pty. Ltd.
#

from pymoku import Moku
from pymoku.instruments import PIDController

def from_dB(dB):
	# Helper function that converts from dB to linear scale
	return 10**(dB/20.0)

# Connect to your Moku by its device name
# Alternatively, use Moku.get_by_serial('#####') or Moku('192.168.###.###')
m = Moku.get_by_name("Moku")

try:
	i = m.deploy_instrument(PIDController)

	# Configure the PID Controller using frequency response characteristics
	# 	P = -10dB
	#	I Crossover = 100Hz
	# 	D Crossover = 10kHz
	# 	I Saturation = 10dB
	# 	D Saturation = 10dB
	# 	Double-I = OFF
	# Note that gains must be converted from dB first
	i.set_by_frequency(1, kp=from_dB(-10), i_xover=1e2, ii_xover=None, d_xover =1e4, si=from_dB(10), sd=from_dB(10))
	i.enable_output(1, True)

finally:
	# Close the connection to the Moku:Lab
	m.close()

The PIDController Class

class pymoku.instruments.PIDController

PIDController instrument object. This should be instantiated and attached to a Moku instance.

__init__()

Must be called as the first line from any child implementations.

hwver

Hardware Version

hwserial

Hardware Serial Number

framerate = 10

Frame Rate, range 1 - 30.

type = "pidcontroller"

Name of this instrument.

commit()

Apply all modified settings.

Note

If the autocommit feature has been turned off, this function can be used to manually apply any instrument settings to the Moku device. These instrument settings are those configured by calling all set_ and gen_ type functions. Manually calling this function allows you to atomically apply many instrument settings at once.

enable_input(*args, **kwargs)

Enable or disable the PID channel input(s).

If ch is None (the default), both channels will be acted upon, otherwise just the one specified by the argument.

Parameters:
  • ch (int; {1,2} or None) – Output channel, or both.
  • en (bool) – Enable the specified input channel(s).
Raises:

InvalidParameterException – Invalid parameters

enable_output(*args, **kwargs)

Enable or disable the PID channel output(s).

If ch is None (the default), both channels will be acted upon, otherwise just the one specified by the argument.

Parameters:
  • ch (int; {1,2} or None) – Output channel, or both.
  • en (bool) – Enable the specified output channel(s).
Raises:

InvalidParameterException – Invalid parameters

get_data(timeout=None, wait=True)

Get full-resolution data from the instrument.

This will pause the instrument and download the entire contents of the instrument’s internal memory. This may include slightly more data than the instrument is set up to record due to rounding of some parameters in the instrument.

All settings must be committed before you call this function. If pymoku.autocommit=True (the default) then this will always be true, otherwise you will need to have called commit first.

The download process may take a second or so to complete. If you require high rate data, e.g. for rendering a plot, see get_realtime_data.

If the wait parameter is true (the default), this function will wait for any new settings to be applied before returning. That is, if you have set a new timebase (for example), calling this with wait=True will guarantee that the data returned has this new timebase.

Note that if instrument configuration is changed, a trigger event must occur before data captured with that configuration set can become available. This can take an arbitrary amount of time. For this reason the timeout should be set appropriately.

Parameters:
  • timeout (float) – Maximum time to wait for new data, or None for indefinite.
  • wait (bool) – If true (default), waits for a new waveform to be captured with the most recently-applied settings, otherwise just return the most recently captured valid data.
Returns:

InstrumentData subclass, specific to the instrument.

get_frontend(channel)

Get the analog frontend configuration.

Parameters:channel (int; {1,2}) – Channel for which the relay settings are being retrieved
Returns:Array of bool with the front end configuration of channels - [0] 50 Ohm - [1] 10xAttenuation - [2] AC Coupling
get_realtime_data(timeout=None, wait=True)

Get downsampled data from the instrument with low latency.

Returns a new InstrumentData subclass (instrument-specific), containing a version of the data that may have been downsampled from the original in order to be transferred quickly.

This function always returns a new object at framerate (10Hz by default), whether or not there is new data in that object. This can be verified by checking the return object’s waveformid parameter, which increments each time a new waveform is captured internally.

The downsampled, low-latency nature of this data makes it particularly suitable for plotting in real time. If you require high-accuracy, high-resolution data for analysis, see get_data.

If the wait parameter is true (the default), this function will wait for any new settings to be applied before returning. That is, if you have set a new timebase (for example), calling this with wait=True will guarantee that the data returned has this new timebase.

Note that if instrument configuration is changed, a trigger event must occur before data captured with that configuration set can become available. This can take an arbitrary amount of time. For this reason the timeout should be set appropriately.

Parameters:
  • timeout (float) – Maximum time to wait for new data, or None for indefinite.
  • wait (bool) – If true (default), waits for a new waveform to be captured with the most recently-applied settings, otherwise just return the most recently captured valid data.
Returns:

InstrumentData subclass, specific to the instrument.

get_samplerate()
Returns:The current instrument sample rate (Hz)
set_by_frequency(*args, **kwargs)

Configure the selected PID controller using crossover frequencies.

Parameters:
  • ch (int; [1,2]) – Channel of PID controller to configure
  • kp (float; [-1e3,1e3]) – Proportional gain factor
  • i_xover (float; [1e-3,1e6] Hz) – Integrator crossover frequency
  • d_xover (float; [1,10e6] Hz) – Differentiator crossover frequency
  • ii_xover (float; [1, 1e6] Hz) – Second integrator crossover frequency
  • si (float; float; [-1e3,1e3]) – Integrator gain saturation
  • sd (float; [-1e3,1e3]) – Differentiator gain saturation
  • in_offset (float; [-1.0,1.0] V) – Input signal offset
Raises:

InvalidConfigurationException – if the configuration of PID gains is not possible.

set_by_gain(*args, **kwargs)

Configure the selected PID controller using gain coefficients.

Parameters:
  • ch (int; [1,2]) – Channel of the PID controller to be configured.
  • g (float; [0,2^16 - 1]) – Gain
  • kp (float; [-1e3,1e3]) – Proportional gain factor
  • ki (float;) – Integrator gain factor
  • kd (float;) – Differentiator gain factor
  • kii (float;) – Second integrator gain factor
  • si (float; float; [-1e3,1e3]) – Integrator gain saturation
  • sd (float; [-1e3,1e3]) – Differentiator gain saturation
  • in_offset (float; [-1.0,1.0] V) – Input signal offset
Raises:

InvalidConfigurationException – if the configuration of PID gains is not possible.

set_control_matrix(*args, **kwargs)

Set the linear combination of ADC input signals for a given PID channel.

Parameters:
  • ch (int; [1,2]) – PID Channel
  • self_gain (float; [-20,20]) – ADC input gain for same PID channel
  • cross_gain (float; [-20, 20]) –
set_defaults(*args, **kwargs)

Reset the lockinamp to sane defaults.

set_framerate(*args, **kwargs)

Set framerate

set_frontend(channel, fiftyr=True, atten=False, ac=False)

Configures gain, coupling and termination for each channel.

Parameters:
  • channel (int; {1,2}) – Channel to which the settings should be applied
  • fiftyr (bool) – 50Ohm termination; default is 1MOhm.
  • atten (bool) – Turn on 10x attenuation. Changes the dynamic range between 1Vpp and 10Vpp.
  • ac (bool) – AC-couple; default DC.
set_monitor(*args, **kwargs)

Configures the specified monitor channel to view the desired PID instrument signal.

There are two 12-bit monitoring channels available, ‘a’ and ‘b’; each of these can be assigned to source signals from any of the internal PID instrument monitoring points. Signals larger than 12-bits must be either truncated or clipped to the allowed size.

The source is one of:
  • adc1 : Channel 1 ADC input
  • in1 : PID Channel 1 input (after mixing, offset and scaling)
  • out1 : PID Channel 1 output
  • adc2 : Channel 2 ADC Input
  • in2 : PID Channel 2 input (after mixing, offset and scaling)
  • out2 : PID Channel 2 output
Parameters:
  • monitor_ch (str; {'a','b'}) – Monitor channel
  • source (str; {'adc1', 'in1', 'out1', 'adc2', 'in2', 'out2'}) – Signal to connect to the monitor channel
set_precision_mode(*args, **kwargs)

Change aquisition mode between downsampling and decimation. Precision mode, a.k.a Decimation, samples at full rate and applies a low-pass filter to the data. This improves precision. Normal mode works by direct downsampling, throwing away points it doesn’t need.

Parameters:state (bool) – Select Precision Mode
set_samplerate(*args, **kwargs)

Manually set the sample rate of the instrument.

The sample rate is automatically calculated and set in set_timebase.

This interface allows you to specify the rate at which data is sampled, and set a trigger offset in number of samples. This interface is useful for datalogging and capturing of data frames.

Parameters:
  • samplerate (float; 0 < samplerate <= MAX_SAMPLERATE smp/s) – Target samples per second. Will get rounded to the nearest allowable unit.
  • trigger_offset (int; -2^16 < trigger_offset < 2^31) – Number of samples before (-) or after (+) the trigger point to start capturing.
Raises:

ValueOutOfRangeException – if either parameter is out of range.

set_timebase(*args, **kwargs)

Set the left- and right-hand span for the time axis. Units are seconds relative to the trigger point.

Parameters:
  • t1 (float) – Time, in seconds, from the trigger point to the left of screen. This may be negative (trigger on-screen) or positive (trigger off the left of screen).
  • t2 (float) – As t1 but to the right of screen.
Raises:

InvalidConfigurationException – if the timebase is backwards or zero.

set_trigger(*args, **kwargs)

Set the trigger source for the monitor channel signals. This can be either of the input or monitor signals, or the external input.

Parameters:
  • source (string, {'in1','in2','A','B','ext'}) – Trigger Source. May be either an input or monitor channel (as set by set_monitor()), or external. External refers to the back-panel connector of the same name, allowing triggering from an externally-generated digital [LV]TTL or CMOS signal.
  • edge (string, {'rising','falling','both'}) – Which edge to trigger on. In Pulse Width modes this specifies whether the pulse is positive (rising) or negative (falling), with the ‘both’ option being invalid.
  • level (float, [-10.0, 10.0] volts) – Trigger level
  • minwidth (float, seconds) – Minimum Pulse Width. 0 <= minwidth < (2^32/samplerate). Can’t be used with maxwidth.
  • maxwidth (float, seconds) – Maximum Pulse Width. 0 <= maxwidth < (2^32/samplerate). Can’t be used with minwidth.
  • hysteresis (float, [100e-6, 1.0] volts) – Hysteresis around trigger point.
  • hf_reject (bool) – Enable high-frequency noise rejection
  • mode (string, {'auto', 'normal'}) – Trigger mode.
set_xmode(*args, **kwargs)

Set rendering mode for the horizontal axis.

Parameters:xmode (string, {'roll','sweep','fullframe'}) – Respectively; Roll Mode (scrolling), Sweep Mode (normal oscilloscope trace sweeping across the screen) or Full Frame (like sweep, but waits for the frame to be completed).