Setup

class setup.Setup(config: Utility.ConfigurationHandler.ConfigurationHandler)[source]

The Setup handles all interaction with the hardware of the experiment.

Parameters
  • serials (dict) – Dictionary of device names and corresponding USB serials.

  • t_sampling_s (float) – Measurement sampling time in seconds.

  • interval_s (float) – Total buffered time interval in seconds, which in combination with the sampling time defines the number of stored measurements.

_measure_normal_mode() → dict[source]

Measures all devices.

Returns

A dictionary with all measured signals.

_measure_simulation_mode() → dict[source]

When no devices are connected random values are generated instead of actual measurements.

Returns

A dictionary with all signals

_setup_measurement_buffer()Utility.MeasurementBuffer.MeasurementBuffer[source]

Defines the set of recorded signals and creates a corresponding MeasurementBuffer.

Returns

An instance of MeasurementBuffer containing a deque instance for every signal.

close() → None[source]

Closes all connected devices.

disable_output() → None[source]

Disable the output for either pwm or pid mode.

enable_output(desired_pwm_output=0) → None[source]

Enables the output in either pwn or pid mode.

Parameters

desired_pwm_output (float) – Optionally enable pwm mode with a predefined nonzero output.

get_current_flow_value()[source]

Getter for last set target flow value.

Returns

Last set target flow value in normalized units.

measure() → None[source]

Handles measuring and storing signals depending on the system mode and handles updating the PID controller output.

open() → None[source]

Finds and opens all the USB devices previously defined within self.serials by their serial number. If one of the devices is not responsive or cannot be found, the setup is switching to simulation mode in which all measurements are simulated. This allows to test the GUI without any attached devices.

reset_temperature_calibration() → None[source]

Reset the current temperature offset to zero.

reverse_temp_sensors(update=True) → None[source]

Reverse the order of the temperature sensors if the have been set up wrongly.

save_measurement_buffer(folder, name, type='mat')[source]

Saves the current measurement buffer to a file. :param folder: Destination folder. :param name: Name of the file. A time tag will be appended for uniqueness. :param type: To allow different export filetypes.

set_flow(value)[source]

Interface to the SFC5xxx drive for defining the current flow setpoint

Parameters

flow (float) – The desired massflow in normalized units, in [0, 1].

set_kd(kd: float) → None[source]

Allows setting the Kd gain of the controller.

Parameters

kd (float) – Kd gain of the controller

set_ki(ki: float) → None[source]

Allows setting the Ki gain of the controller.

Parameters

ki (float) – Ki gain of the controller

set_kp(kp: float) → None[source]

Allows setting the Kp gain of the controller.

Parameters

kp (float) – Kp gain of the controller.

set_pid_parameters(kp=None, ki=None, kd=None) → None[source]

Interface to the pid-setting functionality of simple_pid.

Parameters
  • kp (float) – Kp gain of the controller

  • ki (float) – Ki gain of the controller

  • kd (float) – Kd gain of the controller

set_pwm(value: float) → None[source]

Safely sets the desired PWM value depending on the current system mode.

Parameters

value (float) – Desired PWM value as a normalized value between 0 and 1.

See also

setup.Mode

set_setpoint(value: float) → None[source]

Allows to define the temperature difference setpoint.

Parameters

value (float) – Positive value smaller 20 degrees.

set_temperature_calibration() → None[source]

Record the current temperature offset, assuming steady state.

start_buffering() → None[source]

Start recording measurements in the MeasurementBuffer and delete previously recorded measurements.

start_direct_power_setting() → None[source]

Start pwm mode with the output set to off.

start_measurement_thread() → None[source]

Creates a thread.Timer that schedules future measurements at the desired sampling time.

start_pid_controller(setpoint=None) → None[source]

Start pid mode with the output set to off.

Parameters

setpoint (float) – Can be used to define a new temperature difference setpoint.

stop_buffering() → None[source]

Stop recording measurements in the MeasurementBuffer.

stop_measurement_thread() → None[source]

Cancels the current measurement thread.

Setup Modes

class setup.Mode(value)[source]

Defines a set of system modes.

  1. IDLE: Before any of the experiment modes has been loaded the system is idle.

  2. FORCE_PWM_OFF: In this mode the pwm can be set directly, but the output is currently turned off.

  3. FORCE_PWM_ON: In this mode the pwm can be set directly.

  4. PID_OFF: In this mode the pid parameters can be set, but the output is currently turned off.

  5. PID_ON: In this mode the pid parameters can be set and the controller is allowed to set pwm values.

Additional Utility

Logging Facility

Utility.Logger.setup_custom_logger(name: str, level: int) → logging.log[source]

Sets the logging format, level and name of the logger.

Parameters
  • name (str) – Name of the logger.

  • level (int) – Initial logging level.

Returns

Returns a log.

Measurement Buffer

class Utility.MeasurementBuffer.MeasurementBuffer(signals: list, sampling_time_s: float, buffer_interval_s: float)[source]

The MeasurementBuffer holds a number of deque instances, one for each recorded signal and manages them as a ring buffer, always keeping a record of the most up to date measurements, reaching back buffer_interval_s seconds.

Parameters
  • signals (list) – List of signal names.

  • sampling_time_s (float) – Measurement sampling time in seconds.

  • buffer_interval_s (float) – Total buffered time interval in seconds which together with the sampling time defines the number of measurements to be stored.

clear() → None[source]

Clears the buffer.

update(measurement: dict) → None[source]

A buffer update is done by adding an entry to each signal buffer. Before the buffer is full this leads to an increase in length, afterwards the deque instances automatically forget their oldest entry in favor of the new one.

Parameters

measurement (object) – Dictionary containing a value for each signal name

Timer

class Utility.Timer.RepeatTimer(interval, function, args=None, kwargs=None)[source]

The RepeatTimer is a special type of timer thread that can be run indefinitely and executes a given function each time a specified interval has passed.

Note

Example of usage:

def dummyfn(msg="foo"):
    print(msg)

timer = RepeatTimer(interval=1, function=dummyfn)
timer.start()
time.sleep(5)  # During which 5 calls of dummyfn will happen.
timer.cancel()
run() → None[source]

Method representing the thread’s activity.

Overrides Timer.run such that we have a repeated timer.