ControllerCell¶
- class lsst.ts.m2com.ControllerCell(log: Logger | None = None, is_csc: bool = True, host: str | None = None, port_command: int | None = None, port_telemetry: int | None = None, timeout_connection: float = 10.0)¶
Bases:
Controller
Cell controller class.
Parameters¶
- log
logging.Logger
or None, optional A logger. If None, a logger will be instantiated. (the default is None)
- is_csc
bool
, optional Is called by the commandable SAL component (CSC) or not. (the default is True)
- host
str
or None, optional Host address. (the default is None)
- port_command
int
or None, optional Command port to connect. (the default is None)
- port_telemetry
int
or None, optional Telemetry port to connect. (the default is None)
- timeout_connection
float
, optional Connection timeout in second. (the default is 10.0)
Attributes¶
- host
str
or None Host address.
- port_command
int
or None Command port to connect.
- port_telemetry
int
or None Telemetry port to connect.
- timeout_connection
float
Connection timeout in second.
- mock_server
MockServer
or None Mock server to support the simulation.
Attributes Summary
Methods Summary
apply_forces
(force_axial, force_tangent[, ...])Apply the actuator forces.
The command and telemetry sockets are connected or not.
All the inner-loop controller (ILC) modes are enabled or not.
clear_errors
([timeout])Clear the errors.
close
()Cancel the task and close the connection.
Close the controller and mock server.
command_actuator
(command[, actuators, ...])Run the actuator command.
command_script
(command[, script_name, timeout])Run the script command.
Connect the TCP/IP server.
enable_open_loop_max_limit
(status[, timeout])Enable the maximum limit in open-loop control.
get_ilc_modes
(addresses[, timeout])Get the inner-loop controller (ILC) modes.
Communication power is on or not.
Motor power is on or not.
load_configuration
([timeout])Load the configuration.
position_mirror
(x, y, z, rx, ry, rz[, timeout])Position the mirror by the rigid body movement.
power
(power_type, status[, expected_state, ...])Power on/off the motor/communication system.
reboot_controller
([timeout])Reboot the cell controller.
reset_actuator_steps
([timeout])Resets the user defined actuator steps to zero.
reset_breakers
(power_type[, timeout])Reset the breakers.
reset_enabled_faults_mask
([timeout])Reset the enabled faults mask to default.
reset_force_offsets
([timeout])Reset the user defined forces to zero.
run_mock_server
(config_dir, lut_path)Run the mock server to support the simulation mode.
save_position
([timeout])Save the rigid body position.
select_inclination_source
(...[, ...])Select the inclination source.
set_bit_digital_status
(idx, status[, timeout])Set the bit value of digital status.
set_callback_process_event
(process_event, *args)Set the callback function to process the event.
Set the callback function to process the lost of connection.
Set the callback function to process the telemetry.
set_closed_loop_control_mode
(mode[, timeout])Set the closed-loop control mode.
set_configuration_file
(file[, timeout])Set the configuration file.
set_control_parameters
([timeout])Set the control parameters of closed-loop controller (CLC).
set_enabled_faults_mask
(mask[, timeout])Set the enabled faults mask.
set_external_elevation_angle
(angle)""Set the external elevation angle in degree.
set_hardpoint_list
(hardpoints[, timeout])Set the hardpoint list.
set_home
([timeout])Set the home position.
Set the inner-loop controller (ILC) modes to NaN.
Set the inner-loop controller (ILC) modes to unknown.
set_ilc_to_enabled
([reset_nan_first, ...])Set the inner-loop control (ILC) mode to Enabled.
set_temperature_offset
(ring, intake, exhaust)Set the temperature offset used in the look-up table (LUT) calculation.
start
(host, port_command, port_telemetry[, ...])Start the task and connection.
switch_command_source
(is_remote[, timeout])Switch the command source.
switch_force_balance_system
(status[, timeout])Switch the force balance system.
write_command_to_server
(message_name[, ...])Write the command (message_name) to server.
Attributes Documentation
- SLEEP_TIME_CLOSE_MOCK_SERVER = 10¶
- TELEMETRY_WAIT_TIMEOUT = 900¶
Methods Documentation
- async apply_forces(force_axial: list[float], force_tangent: list[float], timeout: float = 10.0) None ¶
Apply the actuator forces.
Parameters¶
- force_axial
list
72 axial actuator forces in Newton.
- force_tangent
list
6 tangent actuator forces in Newton.
- timeout
float
, optional Timeout of command in second. (the default is 10.0)
- force_axial
- are_clients_connected() bool ¶
The command and telemetry sockets are connected or not.
Returns¶
- bool
True if clients are connected. Else, False.
- are_ilc_modes_enabled() bool ¶
All the inner-loop controller (ILC) modes are enabled or not.
Notes¶
The bypassed ILCs will be assumed to be “Enabled” to simplify the judgement because we only care about the available ILCs are all “Enabled” or not.
Returns¶
bool
True if all ILC modes are enabled. Otherwise, False.
- async clear_errors(timeout: float = 10.0) None ¶
Clear the errors.
Parameters¶
- timeout
float
, optional Timeout of command in second. (the default is 10.0)
- timeout
- async close() None ¶
Cancel the task and close the connection.
Note: this function is safe to call even though there is no connection.
- async close_controller_and_mock_server() None ¶
Close the controller and mock server.
- async command_actuator(command: CommandActuator, actuators: list[int] | None = None, target_displacement: float | int = 0, unit: ActuatorDisplacementUnit = ActuatorDisplacementUnit.Millimeter, timeout: float = 10.0) None ¶
Run the actuator command.
Parameters¶
- commandenum
CommandActuator
Actuator command.
- actuators
list [int]
or None, optional Selected actuators to do the movement. If the empty list [] is passed, the function will raise the RuntimeError. (the default is None)
- target_displacement
float
orint
, optional Target displacement of the actuators. (the default is 0)
- unitenum
ActuatorDisplacementUnit
, optional Displacement unit. (the default is ActuatorDisplacementUnit.Millimeter)
- timeout
float
, optional Timeout of command in second. (the default is 10.0)
Raises¶
RuntimeError
No actuator is selected.
RuntimeError
Not in the open-loop control.
- commandenum
- async command_script(command: CommandScript, script_name: str | None = None, timeout: float = 10.0) None ¶
Run the script command.
Parameters¶
- commandenum
CommandScript
Script command.
- script_name
str
or None, optional Name of the script. (the default is None)
- timeout
float
, optional Timeout of command in second. (the default is 10.0)
- commandenum
- async connect_server() None ¶
Connect the TCP/IP server.
Raises¶
RuntimeError
If timeout in connection.
- async enable_open_loop_max_limit(status: bool, timeout: float = 10.0) None ¶
Enable the maximum limit in open-loop control.
Parameters¶
- status
bool
Enable the maximum limit or not.
- timeout
float
, optional Timeout of command in second. (the default is 10.0)
Raises¶
RuntimeError
If in the closed-loop control.
- status
- async get_ilc_modes(addresses: list[int], timeout: float = 10.0) None ¶
Get the inner-loop controller (ILC) modes.
Parameters¶
- addresses
list
[int
] Addresses of ILCs.
- timeout
float
, optional Timeout of command in second. (the default is 10.0)
- addresses
- is_powered_on_communication() bool ¶
Communication power is on or not.
Returns¶
bool
True if powered on. Otherwise, False.
- is_powered_on_motor() bool ¶
Motor power is on or not.
Returns¶
bool
True if powered on. Otherwise, False.
- async load_configuration(timeout: float = 10.0) None ¶
Load the configuration.
Parameters¶
- timeout
float
, optional Timeout of command in second. (the default is 10.0)
- timeout
- async position_mirror(x: float, y: float, z: float, rx: float, ry: float, rz: float, timeout: float = 10.0) None ¶
Position the mirror by the rigid body movement.
Parameters¶
- x
float
Position x in um.
- y
float
Position y in um.
- z
float
Position z in um.
- rx
float
Rotation x in arcsec.
- ry
float
Rotation y in arcsec.
- rz
float
Rotation z in arcsec.
- timeout
float
, optional Timeout of command in second. (the default is 10.0)
- x
- async power(power_type: PowerType, status: bool, expected_state: PowerSystemState | None = None, timeout: float = 30.0) None ¶
Power on/off the motor/communication system.
Parameters¶
- power_typeenum
MTM2.PowerType
Power type.
- status
bool
True if turn on the power; False if turn off the power.
- expected_stateenum
MTM2.PowerSystemState
orNone
, optional Expected state of the power system. This is used in the unit test only. Put None in general. (the default is None)
- timeout
float
, optional Timeout in second. (the default is 30.0)
Raises¶
RuntimeError
When the power system status is not expected.
- power_typeenum
- async reboot_controller(timeout: float = 10.0) None ¶
Reboot the cell controller.
Parameters¶
- timeout
float
, optional Timeout of command in second. (the default is 10.0)
- timeout
- async reset_actuator_steps(timeout: float = 10.0) None ¶
Resets the user defined actuator steps to zero.
Parameters¶
- timeout
float
, optional Timeout of command in second. (the default is 10.0)
- timeout
- async reset_breakers(power_type: PowerType, timeout: float = 10.0) None ¶
Reset the breakers.
Parameters¶
- power_typeenum
MTM2.PowerType
Power type.
- timeout
float
, optional Timeout of command in second. (the default is 10.0)
- power_typeenum
- async reset_enabled_faults_mask(timeout: float = 10.0) None ¶
Reset the enabled faults mask to default.
Parameters¶
- timeout
float
, optional Timeout of command in second. (the default is 10.0)
- timeout
- async reset_force_offsets(timeout: float = 10.0) None ¶
Reset the user defined forces to zero.
Parameters¶
- timeout
float
, optional Timeout of command in second. (the default is 10.0)
- timeout
- async run_mock_server(config_dir: Path, lut_path: str) None ¶
Run the mock server to support the simulation mode.
Parameters¶
- config_dir
pathlib.PosixPath
Configuration directory.
- lut_path
str
Look-up table (LUT) path.
- config_dir
- async save_position(timeout: float = 10.0) None ¶
Save the rigid body position.
Parameters¶
- timeout
float
, optional Timeout of command in second. (the default is 10.0)
- timeout
- select_inclination_source(use_external_elevation_angle: bool, max_angle_difference: float | None = None, enable_angle_comparison: bool | None = None) None ¶
Select the inclination source. This will affect the angle used to do the look-up table (LUT) calculation.
Parameters¶
- use_external_elevation_angle
bool
Use the external elevation angle (e.g. telescope mount assembly, TMA) or not.
- max_angle_difference
float
or None, optional Maximum angle difference between the internal and external values in degree. If None, the default value is applied. (the default is None)
- enable_angle_comparison
bool
or None, optional Enable the comparison of angles or not. If the external angle is used, the value should be True. (the default is None)
- use_external_elevation_angle
- async set_bit_digital_status(idx: int, status: DigitalOutputStatus, timeout: float = 10.0) None ¶
Set the bit value of digital status.
Parameters¶
- idx
int
Bit index that begins from 0, which should be >= 0.
- statusenum
DigitalOutputStatus
Digital output status.
- timeout
float
, optional Timeout of command in second. (the default is 10.0)
- idx
- set_callback_process_event(process_event: Callable[[...], Coroutine], *args: Any) None ¶
Set the callback function to process the event.
Parameters¶
- process_event
coroutine
Function to process the event. It must has a keyward argument of “message” to receive the event as a dictionary.
- args
args
Arguments needed in “process_event” function call.
- process_event
- set_callback_process_lost_connection(process_lost_connection: Callable[[...], Coroutine], *args: Any) None ¶
Set the callback function to process the lost of connection.
Parameters¶
- process_lost_connection
coroutine
Function to process the lost of connection.
- args
args
Arguments needed in “process_lost_connection” function call.
- process_lost_connection
- set_callback_process_telemetry(process_telemetry: Callable[[...], Coroutine], *args: Any) None ¶
Set the callback function to process the telemetry.
Parameters¶
- process_telemetry
coroutine
Function to process the telemetry. It must has a keyward argument of “message” to receive the telemetry as a dictionary.
- args
args
Arguments needed in “process_telemetry” function call.
- process_telemetry
- async set_closed_loop_control_mode(mode: ClosedLoopControlMode, timeout: float = 10.0) None ¶
Set the closed-loop control mode.
Parameters¶
- modeenum
MTM2.ClosedLoopControlMode
Closed-loop control mode.
- timeout
float
, optional Timeout in second. (the default is 10.0)
Raises¶
RuntimeError
When the closed-loop control mode is not expected.
- modeenum
- async set_configuration_file(file: str, timeout: float = 10.0) None ¶
Set the configuration file.
Parameters¶
- file
str
Configuration file.
- timeout
float
, optional Timeout of command in second. (the default is 10.0)
- file
- async set_control_parameters(timeout: float = 10.0) None ¶
Set the control parameters of closed-loop controller (CLC).
Parameters¶
- timeout
float
, optional Timeout of command in second. (the default is 10.0)
- timeout
- async set_enabled_faults_mask(mask: int, timeout: float = 10.0) None ¶
Set the enabled faults mask.
Parameters¶
- mask
int
Enabled faults mask.
- timeout
float
, optional Timeout of command in second. (the default is 10.0)
- mask
- async set_external_elevation_angle(angle: float) None ¶
“”Set the external elevation angle in degree.
Parameters¶
- angle
float
Angle in degree.
- angle
- async set_hardpoint_list(hardpoints: list[int], timeout: float = 10.0) None ¶
Set the hardpoint list.
Parameters¶
- hardpoints
list
List of the 0-based hardpoints. There are 6 actuators. The first three are the axial actuators and the latter three are the tangent links.
- timeout
float
, optional Timeout of command in second. (the default is 10.0)
- hardpoints
- async set_home(timeout: float = 10.0) None ¶
Set the home position.
Parameters¶
- timeout
float
, optional Timeout of command in second. (the default is 10.0)
- timeout
- set_ilc_modes_to_nan() None ¶
Set the inner-loop controller (ILC) modes to NaN.
- set_ilc_modes_to_unknown() None ¶
Set the inner-loop controller (ILC) modes to unknown.
- async set_ilc_to_enabled(reset_nan_first: bool = True, retry_times: int = 3, timeout: float = 20.0) None ¶
Set the inner-loop control (ILC) mode to Enabled.
Notes¶
1. This is translated from the SequenceEngine.set_ILC_mode.vi in ts_mtm2. The “retry_times” is the work-around method to deal with ILC, which is not very reliable to set the new mode.
2. There are two state machines based on the ILC’s type: (i) Actuator ILC: Standby –> Disabled –> Enabled (ii) Sensor ILC: Standby –> Enabled
3. The ModBUS ID begins from 1 based on: “CellConfiguration.xlsx” in ts_mtm2.
Parameters¶
- reset_nan_first
bool
, optional Reset all ILC states to NaN first. (the default is True)
- retry_times
int
, optional Retry times. (the default is 3)
- timeout
float
, optional Timeout in second. (the default is 20.0)
Raises¶
RuntimeError
When no response from ILC.
RuntimeError
When the ILC has the unknown state.
RuntimeError
When not all ILCs are Enabled.
- reset_nan_first
- async set_temperature_offset(ring: list[float], intake: list[float], exhaust: list[float], timeout: float = 10.0) None ¶
Set the temperature offset used in the look-up table (LUT) calculation.
Parameters¶
- ring
list
Ring temperature offset in degree C.
- intake
list
Intake temperature offset in degree C.
- exhaust
list
Exhaust temperature offset in degree C.
- timeout
float
, optional Timeout of command in second. (the default is 10.0)
- ring
- start(host: str, port_command: int, port_telemetry: int, sequence_generator: Generator | None = None, timeout: float = 10.0) None ¶
Start the task and connection.
Parameters¶
- host
str
Host address.
- port_command
int
IP port for the command server.
- port_telemetry
int
IP port for the telemetry server.
- sequence_generator
generator
orNone
, optional Sequence generator. (the default is None)
- timeout
float
, optional Connection timeout in second. (default is 10.0)
- host
- async switch_command_source(is_remote: bool, timeout: float = 10.0) None ¶
Switch the command source.
Parameters¶
- is_remote
bool
Remote commandable SAL component (CSC) is the commander or not.
- timeout
float
, optional Timeout of command in second. (the default is 10.0)
- is_remote
- async switch_force_balance_system(status: bool, timeout: float = 10.0) None ¶
Switch the force balance system.
Parameters¶
- status
bool
True if turn on the force balance system. Otherwise, False.
- timeout
float
, optional Timeout of command in second. (the default is 10.0)
Raises¶
RuntimeError
If the gravity LUT is not enabled.
RuntimeError
If not all actuator ILCs enabled.
RuntimeError
If the inclinometer ILC is not enabled.
RuntimeError
If not all temperature ILCs enabled.
RuntimeError
If temperature sensor is out of range.
- status
- async write_command_to_server(message_name: str, message_details: dict | None = None, timeout: float = 10.0) None ¶
Write the command (message_name) to server.
Parameters¶
- message_name
str
Message name to server.
- message_details
dict
or None, optional Message details. (the default is None)
- timeout
float
, optional Timeout of command in second. (the default is 10.0)
Raises¶
OSError
When no TCP/IP connection.
RuntimeError
When the command failed.
- message_name
- log