Hardware Controls

This module contains GPIO hardware controls for:

  1. the temperature sensors,
  2. the electric heaters (PID controlled),
  3. the LEDs.
Jin Cheng & Hayley Weir 08/12/16:
the PID class
Hayley Weir 11/12/16:
GPIO controls, LED controls, initialisation function, hardware components testing
Jin Cheng 12/12/16:
function cleanup and asynchronisation, the asynchronous PWM control queue, documentation
Jin Cheng 17/01/17:
allow customisation of PID params from the web interface
class robotchem.hardware.PID(init_val, Kp=None, Ki=None, Kd=None, set_point=None)[source]

Bases: object

An object representing a PID controller, allowing the two heaters to have separate PID params.

Stores historical integral and derivative values so far, while the set point can be updated after class construction and at any point in time.

clear()[source]

Clears all PID computations and coefficients.

set_setpoint(set_point)[source]

Set a new set-point temperature for this PID controller object.

Parameters:set_point (float | int) – New setpoint.
update(feedback_value)[source]

Calculates PID output for a given feedback from sensor.

u(t) = K_p e(t) + K_i \int_{0}^{t} e(t) dt + K_d \frac{de}{dt}

Parameters:feedback_value (float | int) – temperature reading
Return type:float
Returns:PID output after accounting for feedback value
robotchem.hardware._read_adc(channel, adc_object, gain=1, scale=5.405405405405405e-06)[source]

Reads measurement at a ADC channel with a specified GAIN. Converts the measurement mV into current in amps with a scaling factor.

Parameters:
  • channel – channel number on the ADC device
  • gain – factor of gain in ADC. No gain by default.
  • scale – scale factor of the final output, by default converts mV into current in ampere.
Returns:

ADC measurement.

robotchem.hardware.cleanup(*heaters, wipe=False)[source]

Cleans up the whole GPIO board. Use when exception is raised.

Parameters:
  • heaters (list[ RPi.GPIO.PWM, ..) – heater PWM objects
  • wipe (bool) – run the hardware GPIO cleanup. Resets all previous PWM and ADC instances.
robotchem.hardware.flash_LED(*pins, period=0.15)[source]

An async coroutine that routinely flashes the LEDs.

Parameters:
  • pins – pin numbers of LED bulbs
  • period – the LED will flash every x seconds.
robotchem.hardware.indicate_heating(_loop)[source]

Indicate the device is heating in an active calorimetry by turning on/off LED lights.

Parameters:_loop (asyncio.BaseEventLoop) – the main event loop
robotchem.hardware.indicate_starting_up()[source]

Indicate the device is heating to start_temp by turning on/off LED lights.

robotchem.hardware.initialize(board_only=False)[source]
  1. Initial setup for GPIO board.
  2. Make all GPIO output pins set up as outputs.
  3. Start standby LED color (green).
  4. If not board_only, instantiate and return new heater PWM and ADC reader objects.
Parameters:board_only (bool) – If false, do not instantiate new heater and ADC reader objects.
Return type:None | tuple[ (RPi.GPIO.PWM, RPi.GPIO.PWM, Adafruit_ADS1x15.ADS1115, )
Returns:If not board-only, a tuple of reference, sample PWM objects
robotchem.hardware.measure_all(loop, adc_object)[source]

A convenience function to measure all readings with one concurrent Future object.

Parameters:
  • loop – the main event loop.
  • adc_object – the adc object representing the Analogue-to-Digital converter bytes reader from the Adafruit library.
Returns:

a tuple containing reference cell temp, sample cell temp, reference heater current, sample heater current.

robotchem.hardware.read_current_ref(adc_object, *args, **kwargs)[source]

An async wrapper function for reading real-time current at the reference.

robotchem.hardware.read_current_sample(adc_object, *args, **kwargs)[source]

An async wrapper function for reading real-time current at the sample.

robotchem.hardware.read_temp(identifier)[source]

Reads from the One-Wire thermocouple temperature info from its bus.

Parameters:identifier (str) – the unique 1-wire device identifier string.
Return type:float
Returns:measured temperature, in Celsius
robotchem.hardware.read_temp_ref()[source]

Reads reference cell temperature. This is a wrapper for the read_temp function, with the device ID set with TEMP_SENSOR_ID_REF in the settings.py file.

Returns:Temperature of the reference cell in Celsius.
robotchem.hardware.read_temp_sample()[source]

Reads sample cell temperature. This is a wrapper for the read_temp function, with the device ID set with TEMP_SENSOR_ID_SAMPLE in the settings.py file.

Returns:Temperature of the sample cell in Celsius.