Controller

class lsst.ts.m2com.Controller(log: Optional[Logger] = None, timeout_in_second: float = 0.05, maxsize_queue: int = 1000, is_csc: bool = True)

Bases: object

Controller class.

Parameters:
loglogging.Logger or None, optional

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

timeout_in_secondfloat, optional

Time limit for reading data from the TCP/IP interface (sec). (the default is 0.05)

maxsize_queueint, optional

Maximum size of queue. (the default is 1000)

is_cscbool, optional

Is called by the commandable SAL component (CSC) or not. This is a temporary option to separate the CSC and engineering user interface (EUI). This will be removed in the future after the state machines in the cell controller are unified to a single one. (the default is True)

Attributes:
loglogging.Logger

A logger.

error_handlerErrorHandler

Error handler.

client_commandTcpClient or None

Command client.

client_telemetryTcpClient or None

Telemetry client.

queue_eventasyncio.Queue

Queue of the event.

last_command_statusCommandStatus

Last command status.

timeoutfloat

Time limit for reading data from the TCP/IP interface (sec).

is_cscbool

Is CSC or not. Remove this after the state machines in cell controller are unified.

controller_stateenum salobj.State

Controller’s state.

power_system_statusdict

Power system status in the cell controller.

closed_loop_control_modeenum ClosedLoopControlMode

Closed loop control mode in the cell controller.

ilc_modesnumpy.ndarray [InnerLoopControlMode]

Modes of the inner-loop controller (ILC).

control_parametersdict

Control parameters in the closed-loop controller (CLC).

Methods Summary

are_clients_connected()

The command and telemetry sockets are connected or not.

assert_controller_state(command_name, ...)

Assert the current controller's state is allowed to do the command or not.

clear_errors([bypass_state_checking])

Clear the errors.

close()

Cancel the task and close the connection.

load_configuration()

Load the configuration.

power(power_type, status[, expected_state, ...])

Power on/off the motor/communication system.

reset_actuator_steps()

Resets the user defined actuator steps to zero.

reset_enabled_faults_mask()

Reset the enabled faults mask to default.

reset_force_offsets()

Reset the user defined forces to zero.

set_closed_loop_control_mode(mode[, timeout])

Set the closed-loop control mode.

set_configuration_file(file)

Set the configuration file.

set_control_parameters()

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

set_enabled_faults_mask(mask)

Set the enabled faults mask.

set_ilc_to_enabled([retry_times, timeout])

Set the inner-loop control (ILC) mode to Enabled.

start(host, port_command, port_telemetry[, ...])

Start the task and connection.

write_command_to_server(message_name[, ...])

Write the command (message_name) to server.

Methods Documentation

are_clients_connected() bool

The command and telemetry sockets are connected or not.

Returns:
bool

True if clients are connected. Else, False.

assert_controller_state(command_name: str, allowed_curr_states: list[lsst.ts.salobj.sal_enums.State]) None

Assert the current controller’s state is allowed to do the command or not.

Parameters:
command_namestr

Command name.

allowed_curr_stateslist [salobj.State]

Allowed current states.

Raises:
ValueError

When the command is not allowed in current controller’s state.

async clear_errors(bypass_state_checking: bool = False) None

Clear the errors.

Parameters:
bypass_state_checkingbool, optional

Bypass the state checking or not. (the default is False.)

Notes

Remove the ‘bypass_state_checking’ after we fully test the ts_m2gui on summit. This function is just to maintain the ts_m2gui and ts_mtm2 compatibility at the moment.

async close() None

Cancel the task and close the connection.

Note: this function is safe to call even though there is no connection.

async load_configuration() None

Load the configuration.

async power(power_type: PowerType, status: bool, expected_state: Optional[PowerSystemState] = None, timeout: float = 20.0) None

Power on/off the motor/communication system.

Parameters:
power_typeenum PowerType

Power type.

statusbool

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

expected_stateenum 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 20.0)

Raises:
RuntimeError

When the power system status is not expected.

async reset_actuator_steps() None

Resets the user defined actuator steps to zero.

async reset_enabled_faults_mask() None

Reset the enabled faults mask to default.

async reset_force_offsets() None

Reset the user defined forces to zero.

async set_closed_loop_control_mode(mode: ClosedLoopControlMode, timeout: float = 10.0) None

Set the closed-loop control mode.

Parameters:
modeenum 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) None

Set the configuration file.

Parameters:
filestr

Configuration file.

async set_control_parameters() None

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

async set_enabled_faults_mask(mask: int) None

Set the enabled faults mask.

Parameters:
maskint

Enabled faults mask.

async set_ilc_to_enabled(retry_times: int = 3, timeout: float = 10.0) None

Set the inner-loop control (ILC) mode to Enabled.

Parameters:
retry_timesint, optional

Retry times. (the default is 3)

timeoutfloat, optional

Timeout in second. (the default is 10.0)

Raises:
RuntimeError

When no response from ILC.

RuntimeError

When the ILC has the unknown state.

RuntimeError

When not all ILCs are 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.

start(host: str, port_command: int, port_telemetry: int, sequence_generator: Optional[Generator] = 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 write_command_to_server(message_name: str, message_details: Optional[dict] = None, timeout: float = 10.0, controller_state_expected: Optional[State] = None) 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)

controller_state_expectedenum salobj.State or None, optional

Expected controller’s state. This is only used for the commands related to the state transition. (the default is None)

Raises:
OSError

When no TCP/IP connection.

RuntimeError

When the command failed.