hardware_component

This module handles the simulation of pump hardware in a VirtualPump.

class turboctl.virtualpump.hardware_component.HardwareComponent(parameters, lock)

This class defines the part of a VirtualPump that handles hardware data and command/status bits.

The following pump properties are simulated:

  • The pump can be turned on and off.

  • Temperature, current and voltage are 0 when the pump is off, and have constant positive values when the pump is on. This is reflected both in the reply telegrams and the values of corresponding parameters.

  • When the pump is on, the pump frequency moves towards the setpoint at a constant rate. When the pump is off, the frequency moves towards 0 at the same rate.

  • The frequency setpoint is always read from the corresponding parameter, and cannot currently be set with the frequency field of a telegram.

  • Currently this class only recognizes the COMMAND and ON control bits (see ControlBits); all others are ignored.

  • The following status bits (see StatusBits) are applied to the reply telegram:

    • OPERATION': When the pump is on.

    • READY: When the pump is off.

    • TURNING: When the pump frequency is not 0.

    • ACCELERATION: When the pump acceleration is above 0.

    • DECELERATION: When the pump acceleration is below 0.

    • PARAM_CHANNEL: Always.

    • PROCESS_CHANNEL: When the COMMAND control bit is supplied.

variables

A Variables instance that contains the parameters that can be modified by this object.

step

The timestep of iteration; the parallel thread that updates frequency waits this amount of seconds between iterations.

abs_acceleration

How fast the pump accelerates or decelerates, in Hz / second.

frequency

The exact frequency of the pump as a float.

This is needed to correctly simulate gradual changes in the frequency, because the frequency parameter only saves integer values.

is_on

A bool flag to keep track of whether the pump is on or off.

shutoff_time

The automatic shutoff interval of the pump in seconds.

The pump automatically turns off after shutoff_time seconds have elapsed since the last on() command. The real pump has a shutoff time of 10 seconds, but the value of this attribute can be lowered for testing purposes.

on_time

How long (in seconds) has elapsed since the last on() command.

TEMPERATURE = 30

The pump reports this constant temperature when it’s on. The unit is °C.

CURRENT = 10

The pump reports this constant temperature when it’s on. The unit is 0.1 A.

VOLTAGE = 24

The pump reports this constant temperature when it’s on. The unit is 0.1 V.

__init__(parameters, lock)

Initialize a new HardwareComponent.

Parameters:
  • parameters – The same dict of ExtendedParameter objects as used by ParameterComponent. This is needed because some hardware components affect the values of parameters and vice versa. Note that these need to be the actual parameters of the pump; dummy values cannot be used even for testing purposes, since all hardware-related parameters (see HWParameters for a list of those) need to be present for this class to function.

  • lock – A threading.Lock object that can be used to temporarily freeze the parallel thread which updates frequency. The purpose of this is to prevent race conditions between that thread and the handle_hardware() and ParameterComponent.handle_parameter() methods, since they all can access and modify the value of the frequency parameter.

handle_hardware(query, reply)

Write hardware data to reply.

Apply the hardware-related commands specified by query, change pump attributes accordingly, and write hardware data and status bits to reply.

Parameters:
  • query (TelegramReader) – The telegram sent to the pump.

  • reply (TelegramBuilder) – This will be used to build the telegram sent from the pump.

stop()

Order the parallel thread to stop.

on()

Turn the pump on and update parameters accordingly.

off()

Turn the pump off and update parameters accordingly.

class turboctl.virtualpump.hardware_component.HWParameters(parameters)

A collection of parameters related to pump hardware.

Each of the attributes of this class is an ExtendedParameter object. This class gives these parameters descriptive names and makes it possible to access them without having to find out the parameter numbers.

Note that HardwareComponent currently cannot modify most of these parameters, but they are included in case HardwareComponent is expanded in the future.

frequency

Parameter 3. Current rotor frequency in Hz. This value is included in every reply telegram.

Type: 16-bit Uint.

voltage

Parameter 4. Current intermediate circuit voltage in 0.1 V. This value is included in every reply telegram.

Type: 16-bit Uint.

current

Parameter 5. Current motor current in 0.1 A. This value is included in every reply telegram.

Type: 16-bit Uint.

motor_power

Parameter 6. Current motor input power in 0.1 W.

Type: 16-bit Uint.

motor_temperature

Parameter 7. Current motor temperature in 0.1 °C.

Type: 16-bit Sint.

save_data

Parameter 8. Writing any value to this parameter saves all changed parameter values into nonvolatile memory. Otherwise all changes are lost when power to the pump is cut off.

Type: 16-bit Sint.

temperature

Parameter 11. Current frequency converter temperature in °C. This value is included in every reply telegram.

Type: 16-bit Sint.

frequency_setpoint

Parameter 24. Setpoint for the rotor frequency in Hz. The pump tries to keep the frequency at this number.

Type: 16-bit Uint.

error_counter

Parameter 40. Counts the total number of error conditions that have occurred to the pump.

Type: 16-bit Uint.

overload_error_counter

Parameter 41. Counts the number of error conditions caused by an overload. An overload error is represented by the error code 106.

Type: 16-bit Uint.

power_failure_error_counter

Parameter 43. Counts the number of error conditions caused by a disturbance in power supply. A power supply error is reprsented by the error code 603.

Type: 16-bit Uint.

error_list

Parameter 171. This parameter has 254 indices, each of which stores an error code. The most recent error is located at index 0 and the oldest at index 253.

Type: 16-bit Uint, 254 indices.

error_frequency_list

Parameter 174. The indices of this parameter contain the frequency of the pump at the time of the corresponding error in error_list.

Type: 16-bit Uint, 254 indices.

error_hour_list

Parameter 176. This parameter works analogously to error_frequency_list, but contains the number of operational hours of the pump instead of the frequency.

Type: 32-bit Sint, 254 indices.

operating_hours

Parameter 184. Counts the total number of operational hours for the pump.

Type: 32-bit Sint, 254 indices.

warning_list

Parameter 227. Works analogously to error_list, but lists warnings instead of errors.

Type: 16-bit Uint, 254 indices.

__init__(parameters)

Initializer.

Parameters:

parameters – A dict of ExtendedParameter objects, which needs to include at least all the parameters which are attributes of this class.

class turboctl.virtualpump.hardware_component.Variables(parameters)

This class encapsulates HWParameters in order to allow the simpler syntax

variables.parameter_name = value

instead of

parameter = hwparameters.parameter_name
parameter.value[0] = parameter.datatype(value, parameter.bits)
parameters

The encapsulated HWParameters object.

__init__(parameters)

Initialize a new Variables instance.

Parameters:

parameters – Passed on to HWParameters.__init__().

__setattr__(name, value)

Set the attribute name to value.

The parameters attribute is handled as a special case and is accessed normally. For all other attributes, the value of the parameter in parameters with the name name is set to value.

value should be given as an instance of a built-in Python type, and will automatically be converted to a Data subclass instance. However, note that the type of value should match the type of the parameter; e.g. a float can be converted into a Float but not into an Uint.

__getattr__(name)

Return the the value of the attribute name.

This method returns the value of the parameter in parameters with the name name. The value is automatically converted to a built-in type.

Since __getattr__ (unlike __getattribute__) is only called if the attribute cannot be found through normal routes, there is no need to make parameters into a special case.