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

loglogging.Logger or None, optional

A logger. If None, a logger will be instantiated. (the default is None)

is_cscbool, optional

Is called by the commandable SAL component (CSC) or not. (the default is True)

hoststr or None, optional

Host address. (the default is None)

port_commandint or None, optional

Command port to connect. (the default is None)

port_telemetryint or None, optional

Telemetry port to connect. (the default is None)

timeout_connectionfloat, optional

Connection timeout in second. (the default is 10.0)

Attributes

hoststr or None

Host address.

port_commandint or None

Command port to connect.

port_telemetryint or None

Telemetry port to connect.

timeout_connectionfloat

Connection timeout in second.

mock_serverMockServer or None

Mock server to support the simulation.

Attributes Summary

SLEEP_TIME_CLOSE_MOCK_SERVER

TELEMETRY_WAIT_TIMEOUT

Methods Summary

apply_forces(force_axial, force_tangent[, ...])

Apply the actuator forces.

are_clients_connected()

The command and telemetry sockets are connected or not.

are_ilc_modes_enabled()

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_controller_and_mock_server()

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_server()

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.

is_powered_on_communication()

Communication power is on or not.

is_powered_on_motor()

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_callback_process_lost_connection(...)

Set the callback function to process the lost of connection.

set_callback_process_telemetry(...)

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_ilc_modes_to_nan()

Set the inner-loop controller (ILC) modes to NaN.

set_ilc_modes_to_unknown()

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_axiallist

72 axial actuator forces in Newton.

force_tangentlist

6 tangent actuator forces in Newton.

timeoutfloat, optional

Timeout of command in second. (the default is 10.0)

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

timeoutfloat, optional

Timeout of command in second. (the default is 10.0)

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.

actuatorslist [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_displacementfloat or int, optional

Target displacement of the actuators. (the default is 0)

unitenum ActuatorDisplacementUnit, optional

Displacement unit. (the default is ActuatorDisplacementUnit.Millimeter)

timeoutfloat, optional

Timeout of command in second. (the default is 10.0)

Raises

RuntimeError

No actuator is selected.

RuntimeError

Not in the open-loop control.

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_namestr or None, optional

Name of the script. (the default is None)

timeoutfloat, optional

Timeout of command in second. (the default is 10.0)

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

statusbool

Enable the maximum limit or not.

timeoutfloat, optional

Timeout of command in second. (the default is 10.0)

Raises

RuntimeError

If in the closed-loop control.

async get_ilc_modes(addresses: list[int], timeout: float = 10.0) None

Get the inner-loop controller (ILC) modes.

Parameters

addresseslist [int]

Addresses of ILCs.

timeoutfloat, optional

Timeout of command in second. (the default is 10.0)

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

timeoutfloat, optional

Timeout of command in second. (the default is 10.0)

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

xfloat

Position x in um.

yfloat

Position y in um.

zfloat

Position z in um.

rxfloat

Rotation x in arcsec.

ryfloat

Rotation y in arcsec.

rzfloat

Rotation z in arcsec.

timeoutfloat, optional

Timeout of command in second. (the default is 10.0)

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.

statusbool

True if turn on the power; False if turn off the power.

expected_stateenum MTM2.PowerSystemState or None, optional

Expected state of the power system. This is used in the unit test only. Put None in general. (the default is None)

timeoutfloat, optional

Timeout in second. (the default is 30.0)

Raises

RuntimeError

When the power system status is not expected.

async reboot_controller(timeout: float = 10.0) None

Reboot the cell controller.

Parameters

timeoutfloat, optional

Timeout of command in second. (the default is 10.0)

async reset_actuator_steps(timeout: float = 10.0) None

Resets the user defined actuator steps to zero.

Parameters

timeoutfloat, optional

Timeout of command in second. (the default is 10.0)

async reset_breakers(power_type: PowerType, timeout: float = 10.0) None

Reset the breakers.

Parameters

power_typeenum MTM2.PowerType

Power type.

timeoutfloat, optional

Timeout of command in second. (the default is 10.0)

async reset_enabled_faults_mask(timeout: float = 10.0) None

Reset the enabled faults mask to default.

Parameters

timeoutfloat, optional

Timeout of command in second. (the default is 10.0)

async reset_force_offsets(timeout: float = 10.0) None

Reset the user defined forces to zero.

Parameters

timeoutfloat, optional

Timeout of command in second. (the default is 10.0)

async run_mock_server(config_dir: Path, lut_path: str) None

Run the mock server to support the simulation mode.

Parameters

config_dirpathlib.PosixPath

Configuration directory.

lut_pathstr

Look-up table (LUT) path.

async save_position(timeout: float = 10.0) None

Save the rigid body position.

Parameters

timeoutfloat, optional

Timeout of command in second. (the default is 10.0)

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_anglebool

Use the external elevation angle (e.g. telescope mount assembly, TMA) or not.

max_angle_differencefloat 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_comparisonbool 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)

async set_bit_digital_status(idx: int, status: DigitalOutputStatus, timeout: float = 10.0) None

Set the bit value of digital status.

Parameters

idxint

Bit index that begins from 0, which should be >= 0.

statusenum DigitalOutputStatus

Digital output status.

timeoutfloat, optional

Timeout of command in second. (the default is 10.0)

set_callback_process_event(process_event: Callable[[...], Coroutine], *args: Any) None

Set the callback function to process the event.

Parameters

process_eventcoroutine

Function to process the event. It must has a keyward argument of “message” to receive the event as a dictionary.

argsargs

Arguments needed in “process_event” function call.

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_connectioncoroutine

Function to process the lost of connection.

argsargs

Arguments needed in “process_lost_connection” function call.

set_callback_process_telemetry(process_telemetry: Callable[[...], Coroutine], *args: Any) None

Set the callback function to process the telemetry.

Parameters

process_telemetrycoroutine

Function to process the telemetry. It must has a keyward argument of “message” to receive the telemetry as a dictionary.

argsargs

Arguments needed in “process_telemetry” function call.

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.

timeoutfloat, optional

Timeout in second. (the default is 10.0)

Raises

RuntimeError

When the closed-loop control mode is not expected.

async set_configuration_file(file: str, timeout: float = 10.0) None

Set the configuration file.

Parameters

filestr

Configuration file.

timeoutfloat, optional

Timeout of command in second. (the default is 10.0)

async set_control_parameters(timeout: float = 10.0) None

Set the control parameters of closed-loop controller (CLC).

Parameters

timeoutfloat, optional

Timeout of command in second. (the default is 10.0)

async set_enabled_faults_mask(mask: int, timeout: float = 10.0) None

Set the enabled faults mask.

Parameters

maskint

Enabled faults mask.

timeoutfloat, optional

Timeout of command in second. (the default is 10.0)

async set_external_elevation_angle(angle: float) None

“”Set the external elevation angle in degree.

Parameters

anglefloat

Angle in degree.

async set_hardpoint_list(hardpoints: list[int], timeout: float = 10.0) None

Set the hardpoint list.

Parameters

hardpointslist

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.

timeoutfloat, optional

Timeout of command in second. (the default is 10.0)

async set_home(timeout: float = 10.0) None

Set the home position.

Parameters

timeoutfloat, optional

Timeout of command in second. (the default is 10.0)

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_firstbool, optional

Reset all ILC states to NaN first. (the default is True)

retry_timesint, optional

Retry times. (the default is 3)

timeoutfloat, 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.

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

ringlist

Ring temperature offset in degree C.

intakelist

Intake temperature offset in degree C.

exhaustlist

Exhaust temperature offset in degree C.

timeoutfloat, optional

Timeout of command in second. (the default is 10.0)

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

hoststr

Host address.

port_commandint

IP port for the command server.

port_telemetryint

IP port for the telemetry server.

sequence_generatorgenerator or None, optional

Sequence generator. (the default is None)

timeoutfloat, optional

Connection timeout in second. (default is 10.0)

async switch_command_source(is_remote: bool, timeout: float = 10.0) None

Switch the command source.

Parameters

is_remotebool

Remote commandable SAL component (CSC) is the commander or not.

timeoutfloat, optional

Timeout of command in second. (the default is 10.0)

async switch_force_balance_system(status: bool, timeout: float = 10.0) None

Switch the force balance system.

Parameters

statusbool

True if turn on the force balance system. Otherwise, False.

timeoutfloat, 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.

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_namestr

Message name to server.

message_detailsdict or None, optional

Message details. (the default is None)

timeoutfloat, optional

Timeout of command in second. (the default is 10.0)

Raises

OSError

When no TCP/IP connection.

RuntimeError

When the command failed.