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
andON
control bits (seeControlBits
); 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 theCOMMAND
control bit is supplied.
- 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.
- shutoff_time¶
The automatic shutoff interval of the pump in seconds.
The pump automatically turns off after
shutoff_time
seconds have elapsed since the laston()
command. The real pump has a shutoff time of 10 seconds, but the value of this attribute can be lowered for testing purposes.
- 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
ofExtendedParameter
objects as used byParameterComponent
. 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 (seeHWParameters
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 updatesfrequency
. The purpose of this is to prevent race conditions between that thread and thehandle_hardware()
andParameterComponent.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 caseHardwareComponent
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
.
- 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
ofExtendedParameter
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 syntaxvariables.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 inparameters
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. afloat
can be converted into aFloat
but not into anUint
.
- __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 makeparameters
into a special case.