HexapodCsc¶
-
class
lsst.ts.mthexapod.
HexapodCsc
(index, config_dir=None, initial_state=<State.OFFLINE: 4>, settings_to_apply='', simulation_mode=0)¶ Bases:
lsst.ts.hexrotcomm.base_csc.BaseCsc
MTHexapod CSC.
- Parameters
- index
SalIndex
orint
SAL index; see
SalIndex
for the allowed values.- config_dir
str
, optional Directory of configuration files, or None for the standard configuration directory (obtained from
_get_default_config_dir
). This is provided for unit testing.- initial_state
lsst.ts.salobj.State
orint
(optional) The initial state of the CSC. Must be
lsst.ts.salobj.State.OFFLINE
unless simulating (simulation_mode != 0
).- settings_to_apply
str
, optional Settings to apply if
initial_state
isState.DISABLED
orState.ENABLED
.- simulation_mode
int
(optional) Simulation mode. Allowed values:
0: regular operation.
1: simulation: use a mock low level controller.
- index
- Raises
- ValueError
If
initial_state != lsst.ts.salobj.State.OFFLINE
and not simulating (simulation_mode = 0
).
Notes
Error Codes
1: invalid data read on the telemetry socket
This CSC is unusual in several respect:
It acts as a server (not a client) for a low level controller (because that is how the low level controller is written).
The low level controller maintains the summary state and detailed state (that’s why this code inherits from Controller instead of BaseCsc).
The simulation mode can only be set at construction time.
Attributes Summary
Return True if moves are compensated, False otherwise.
Get or set the configuration directory.
Return True if the summary state is
State.DISABLED
orState.ENABLED
.Get the current simulation mode.
Return the current summary state as a salobj.State, or OFFLINE if unknown.
Methods Summary
add_arguments
(parser)Add arguments to the parser created by
make_from_cmd_line
.add_kwargs_from_args
(args, kwargs)Add constructor keyword arguments based on parsed arguments.
amain
(index, **kwargs)Make a CSC from command-line arguments and run it.
Assert that CSC is connected to the low-level controller and can command it.
Assert that the CSC is enabled.
assert_enabled_substate
(substate)Assert that the CSC is enabled and that the low-level controller is in the specified enabled substate.
assert_summary_state
(*allowed_states, isbefore)Assert that the current summary state is as specified.
basic_run_command
(command)Acquire the write_lock and run the command.
begin_disable
(data)Begin do_disable; called before state changes.
begin_enable
(data)Begin do_enable; called before state changes.
begin_exitControl
(data)Begin do_exitControl; called before state changes.
begin_standby
(data)Begin do_standby; called before the state changes.
begin_start
(data)Begin do_start; configure the CSC before changing state.
close
([exception, cancel_start])Shut down, clean up resources and set done_task done.
Shut down pending tasks.
Apply compensation at regular intervals.
Wait until it is time to apply the next compensation update.
compute_compensation
(uncompensated_pos)Check uncompensated and, if relevant, compensated position and return compensation information.
config_callback
(server)Called when the low-level controller outputs configuration.
configure
(config)Configure the CSC.
connect_callback
(server)Called when the server’s command or telemetry sockets connect or disconnect.
Cancel compensation and report compensationMode.enabled=False.
do_clearError
(data)Reset the FAULT state to STANDBY.
do_configureAcceleration
(data)Specify the acceleration limit.
do_configureLimits
(data)Specify position and rotation limits.
do_configureVelocity
(data)Specify velocity limits.
do_disable
(data)Go from ENABLED state to DISABLED.
do_enable
(data)Go from DISABLED state to ENABLED.
do_enterControl
(data)Go from OFFLINE state, AVAILABLE offline substate to STANDBY.
do_exitControl
(data)Go from STANDBY state to OFFLINE state, AVAILABLE offline substate.
do_move
(data)Move to a specified position and orientation.
do_offset
(data)Move by a specified offset in position and orientation.
do_setAuthList
(data)Update the authorization list.
do_setCompensationMode
(data)do_setLogLevel
(data)Set logging level.
do_setPivot
(data)Set the coordinates of the pivot point.
do_standby
(data)Go from DISABLED state to STANDBY.
do_start
(data)Go from STANDBY state to DISABLED.
do_stop
(data)Halt tracking or any other motion.
end_disable
(data)End do_disable; called after state changes but before command acknowledged.
end_enable
(data)End do_enable; called after state changes but before command acknowledged.
end_exitControl
(data)End do_exitControl; called after state changes but before command acknowledged.
end_standby
(data)End do_standby; called after state changes but before command acknowledged.
end_start
(data)End do_start; called after state changes but before command acknowledged.
fault
(code, report[, traceback])Warning: the fault method is not support in this class.
Return the current compensation inputs, or None if not available.
Get the name of the configuration package, e.g.
Called when the summary state has changed.
implement_simulation_mode
(simulation_mode)Implement going into or out of simulation mode.
make_command
(code[, param1, param2, param3, …])Make a command from the command identifier and keyword arguments.
make_from_cmd_line
(index, **kwargs)Construct a CSC from command line arguments.
make_mock_controller
(initial_ctrl_state)Construct and return a mock controller.
Output the logLevel event.
Set
self.config_label_dict
and outputevt_settingVersions
.Report a new value for summary_state, including current state.
run_command
(code[, param1, param2, param3, …])Run one command.
run_multiple_commands
(*commands[, delay])Run multiple commands, without allowing other commands to run between them.
set_simulation_mode
(simulation_mode)Set the simulation mode.
start
()Finish constructing the CSC.
Stop motion and wait for it to stop.
telemetry_callback
(server)Called when the low-level controller outputs telemetry.
wait_n_telemetry
([n_telemetry])Wait for n_telemetry telemetry messages since the most recent low-level command.
wait_stopped
([n_telemetry])Wait for the current motion, if any, to stop.
Attributes Documentation
-
compensation_mode
¶ Return True if moves are compensated, False otherwise.
-
config_dir
¶ Get or set the configuration directory.
- Parameters
- config_dir
str
,bytes
, orpathlib.Path
New configuration directory.
- config_dir
- Returns
- config_dir
pathlib.Path
Absolute path to the configuration directory.
- config_dir
- Raises
- ValueError
If the new configuration dir is not a directory.
-
default_initial_state
= 4¶
-
disabled_or_enabled
¶ Return True if the summary state is
State.DISABLED
orState.ENABLED
.This is useful in
handle_summary_state
to determine if you should start or stop a telemetry loop, and connect to or disconnect from an external controller
-
domain
¶
-
enable_cmdline_state
= False¶
-
require_settings
= False¶
-
simulation_help
= None¶
-
simulation_mode
¶ Get the current simulation mode.
0 means normal operation (no simulation).
- Raises
- ExpectedError
If the new simulation mode is not a supported value.
-
summary_state
¶ Return the current summary state as a salobj.State, or OFFLINE if unknown.
-
valid_simulation_modes
= [0, 1]¶
-
version
= '?'¶
Methods Documentation
-
classmethod
add_arguments
(parser)¶ Add arguments to the parser created by
make_from_cmd_line
.- Parameters
- parser
argparse.ArgumentParser
The argument parser.
- parser
Notes
If you override this method then you should almost certainly override
add_kwargs_from_args
as well.
-
classmethod
add_kwargs_from_args
(args, kwargs)¶ Add constructor keyword arguments based on parsed arguments.
- Parameters
- args
argparse.namespace
Parsed command.
- kwargs
dict
Keyword argument dict for the constructor. Update this based on
args
. The index argument will already be present if relevant.
- args
Notes
If you override this method then you should almost certainly override
add_arguments
as well.
-
async classmethod
amain
(index, **kwargs)¶ Make a CSC from command-line arguments and run it.
- Parameters
- index
int
,enum.IntEnum
,True
, orNone
If the CSC is indexed, do one of the following:
Specify
True
to makeindex
a required command-line argument that accepts any nonzero index.Specify an
enum.IntEnum
class to makeindex
a required command-line argument that only accepts the enum values.Specify a non-zero integer to use that index. This is rare; if the CSC is indexed then the user should usually be allowed to specify the index.
If the CSC is not indexed, specify
None
or 0.- **kwargs
dict
, optional Additional keyword arguments for your CSC’s constructor.
- index
-
assert_commandable
()¶ Assert that CSC is connected to the low-level controller and can command it.
-
assert_enabled
()¶ Assert that the CSC is enabled.
First check that CSC can command the low-level controller.
-
assert_enabled_substate
(substate)¶ Assert that the CSC is enabled and that the low-level controller is in the specified enabled substate.
First check that CSC can command the low-level controller.
- Parameters
- substate
lsst.ts.idl.enums.MTHexapod.EnabledSubstate
Substate of low-level controller.
- substate
-
assert_summary_state
(*allowed_states, isbefore)¶ Assert that the current summary state is as specified.
First check that CSC can command the low-level controller.
Used in do_xxx methods to check that a command is allowed.
- Parameters
- allowed_states
List
[lsst.ts.salobj.State
] Allowed summary states.
- isbefore
bool
Determines the error message prefix. Set True if checking initial conditions before commanding the low-level controller. Message is “Rejected: initial state …”. Set False if checking the state after commanding the low-level controller. Message is “Failed: final state …”
- allowed_states
-
async
basic_run_command
(command)¶ Acquire the write_lock and run the command.
- Parameters
- command
Command
Command to run, as constructed by
make_command
.
- command
-
async
begin_disable
(data)¶ Begin do_disable; called before state changes.
- Parameters
- data
DataType
Command data
- data
-
async
begin_enable
(data)¶ Begin do_enable; called before state changes.
- Parameters
- data
DataType
Command data
- data
-
async
begin_exitControl
(data)¶ Begin do_exitControl; called before state changes.
- Parameters
- data
DataType
Command data
- data
-
async
begin_standby
(data)¶ Begin do_standby; called before the state changes.
- Parameters
- data
DataType
Command data
- data
-
async
begin_start
(data)¶ Begin do_start; configure the CSC before changing state.
- Parameters
- data
cmd_start.DataType
Command data
- data
Notes
The
settingsToApply
field must be one of:The name of a config label or config file
The name and version of a config file, formatted as
<file_name>:<version>
, where the version is a git reference, such as a git tag or commit hash. This form does not support labels.
-
async
close
(exception=None, cancel_start=True)¶ Shut down, clean up resources and set done_task done.
May be called multiple times. The first call closes the Controller; subsequent calls wait until the Controller is closed.
Subclasses should override
close_tasks
instead ofclose
, unless you have a good reason to do otherwise.- Parameters
- exception
Exception
, optional The exception that caused stopping, if any, in which case the
self.done_task
exception is set to this value. SpecifyNone
for a normal exit, in which case theself.done_task
result is set toNone
.- cancel_start
bool
, optional Cancel the start task? Leave this true unless calling this from the start task.
- exception
Notes
Removes the SAL log handler, calls
close_tasks
to stop all background tasks, pauses briefly to allow final SAL messages to be sent, then closes the dds domain.
-
async
compensation_loop
()¶ Apply compensation at regular intervals.
The algorithm is to repeat the following sequence:
Wait until it is time to apply compensation (see
compensation_wait
for details).Compute the compensation offset and apply it if large enough.
If a compensation update fails then compensation is disabled.
-
async
compensation_wait
()¶ Wait until it is time to apply the next compensation update.
Wait for motion to stop, then wait for self.compensation_interval seconds (a configuration parameter). Warn and repeat if the axes are moving again (very unlikely).
- Raises
- asyncio.CancelledError
If the CSC is no longer enabled.
- asyncio.TimeoutError
If waiting for motion to stop takes longer than
self.max_move_duration
.
-
compute_compensation
(uncompensated_pos)¶ Check uncompensated and, if relevant, compensated position and return compensation information.
- Parameters
- uncompensated_pos
Position
Target position (without compensation applied).
- uncompensated_pos
- Returns
- compensation_info
CompensationInfo
Compensation information.
- compensation_info
- Raises
- salobj.ExpectedError
If uncompensated or compensated position is out of bounds.
-
config_callback
(server)¶ Called when the low-level controller outputs configuration.
- Parameters
- server
lsst.ts.hexrotcomm.CommandTelemetryServer
TCP/IP server.
- server
-
async
configure
(config)¶ Configure the CSC.
- Parameters
- config
object
The configuration as described by the schema at
schema_path
, as a struct-like object.
- config
Notes
Called when running the
start
command, just before changing summary state fromState.STANDBY
toState.DISABLED
.
-
connect_callback
(server)¶ Called when the server’s command or telemetry sockets connect or disconnect.
- Parameters
- server
CommandTelemetryServer
TCP/IP server.
- server
-
disable_compensation
()¶ Cancel compensation and report compensationMode.enabled=False.
-
async
do_clearError
(data)¶ Reset the FAULT state to STANDBY.
-
async
do_configureAcceleration
(data)¶ Specify the acceleration limit.
-
async
do_configureLimits
(data)¶ Specify position and rotation limits.
-
async
do_configureVelocity
(data)¶ Specify velocity limits.
-
async
do_disable
(data)¶ Go from ENABLED state to DISABLED.
-
async
do_enable
(data)¶ Go from DISABLED state to ENABLED.
-
async
do_enterControl
(data)¶ Go from OFFLINE state, AVAILABLE offline substate to STANDBY.
-
async
do_exitControl
(data)¶ Go from STANDBY state to OFFLINE state, AVAILABLE offline substate.
-
async
do_move
(data)¶ Move to a specified position and orientation.
Check the target before and after compensation (if applied). Both the target and the compensated position (if compensating) should be in range, so we can turn off compensation at will. If compensation mode is off we do not test compensated position, as it allows running with invalid compensation coefficients or inputs.
-
async
do_offset
(data)¶ Move by a specified offset in position and orientation.
See note for do_move regarding checking the target position.
-
do_setAuthList
(data)¶ Update the authorization list.
- Parameters
- data
cmd_setAuthList.DataType
Authorization lists.
- data
Notes
Add items if the data string starts with “+”, ignoring duplicates (both with respect to the existing items and within the data string). Remove items if the data string starts with “-“, ignoring missing items (items specified for removal that do not exist). Ignore whitespace after each comma and after the +/- prefix.
-
async
do_setCompensationMode
(data)¶
-
do_setLogLevel
(data)¶ Set logging level.
- Parameters
- data
cmd_setLogLevel.DataType
Logging level.
- data
-
async
do_setPivot
(data)¶ Set the coordinates of the pivot point.
-
async
do_standby
(data)¶ Go from DISABLED state to STANDBY.
Note: use the clearError command to go from FAULT to STANDBY.
-
async
do_start
(data)¶ Go from STANDBY state to DISABLED.
Notes
This ignores the data, unlike the vendor’s CSC code, which writes the supplied file name into a file on an nfs-mounted partition. I hope we won’t need to do that, as it seems complicated.
-
async
do_stop
(data)¶ Halt tracking or any other motion.
-
async
end_disable
(data)¶ End do_disable; called after state changes but before command acknowledged.
- Parameters
- data
DataType
Command data
- data
-
async
end_enable
(data)¶ End do_enable; called after state changes but before command acknowledged.
- Parameters
- data
DataType
Command data
- data
-
async
end_exitControl
(data)¶ End do_exitControl; called after state changes but before command acknowledged.
- Parameters
- data
DataType
Command data
- data
-
async
end_standby
(data)¶ End do_standby; called after state changes but before command acknowledged.
- Parameters
- data
DataType
Command data
- data
-
async
end_start
(data)¶ End do_start; called after state changes but before command acknowledged.
- Parameters
- data
DataType
Command data
- data
-
fault
(code, report, traceback='')¶ Warning: the fault method is not support in this class.
The problem is that the summary state is maintained by the low-level controller and the CSC has no way to reliably send the low-level controller to FAULT state.
-
get_compensation_inputs
()¶ Return the current compensation inputs, or None if not available.
Log a warning if inputs are missing and the missing list does not match the previous warning.
- Returns
- compensation_inputs
CompensationInputs
orNone
The compensation inputs, if all inputs are available, else
None
.
- compensation_inputs
-
static
get_config_pkg
()¶ Get the name of the configuration package, e.g. “ts_config_ocs”.
-
async
handle_summary_state
()¶ Called when the summary state has changed.
Override to perform tasks such as starting and stopping telemetry (example).
Notes
The versions in
BaseCsc
andConfigurableCsc
do nothing, so if you subclass one of those you do not need to callawait super().handle_summary_state()
.
-
async
implement_simulation_mode
(simulation_mode)¶ Implement going into or out of simulation mode.
Deprecated. See simulation mode for details.
- Parameters
- simulation_mode
int
Requested simulation mode; 0 for normal operation.
- simulation_mode
- Raises
- ExpectedError
If
simulation_mode
is not a supported value.
-
make_command
(code, param1=0, param2=0, param3=0, param4=0, param5=0, param6=0)¶ Make a command from the command identifier and keyword arguments.
Used to make commands for
run_multiple_commands
.- Parameters
- code
CommandCode
Command to run.
- param1, param2, param3, param4, param5, param6
double
Command parameters. The meaning of these parameters depends on the command code.
- code
- Returns
- command
Command
The command. Note that the
counter
field is 0; it is set byCommandTelemetryServer.put_command
.
- command
-
classmethod
make_from_cmd_line
(index, **kwargs)¶ Construct a CSC from command line arguments.
- Parameters
- index
int
,enum.IntEnum
,True
, orNone
If the CSC is indexed, do one of the following:
Specify
True
to makeindex
a required command-line argument that accepts any nonzero index.Specify an
enum.IntEnum
class to makeindex
a required command-line argument that only accepts the enum values.Specify a non-zero integer to use that index. This is rare; if the CSC is indexed then the user should usually be allowed to specify the index.
If the CSC is not indexed, specify
None
or 0.- **kwargs
dict
, optional Additional keyword arguments for your CSC’s constructor.
- index
- Returns
- csc
cls
The CSC.
- csc
Notes
To add additional command-line arguments, override
add_arguments
andadd_kwargs_from_args
.
-
make_mock_controller
(initial_ctrl_state)¶ Construct and return a mock controller.
- Parameters
- initial_ctrl_state
int
Initial controller state.
- initial_ctrl_state
-
put_log_level
()¶ Output the logLevel event.
-
read_config_dir
()¶ Set
self.config_label_dict
and outputevt_settingVersions
.Set
self.config_label_dict
fromself.config_dir/_labels.yaml
. Output thesettingVersions
event (if changed) as follows:recommendedSettingsLabels
is a comma-separated list of labels inself.config_label_dict
, truncated by omitting labels if necessary.recommendedSettingsVersion
is derived from git information forself.config_dir
, if it is a git repository, else “”.
-
report_summary_state
()¶ Report a new value for summary_state, including current state.
Subclasses may wish to override for code that depends on the current state (rather than the state transition command that got it into that state).
-
async
run_command
(code, param1=0, param2=0, param3=0, param4=0, param5=0, param6=0)¶ Run one command.
- Parameters
- code
CommandCode
Command to run.
- param1, param2, param3, param4, param5, param6
double
Command parameters. The meaning of these parameters depends on the command code.
- code
-
async
run_multiple_commands
(*commands, delay=None)¶ Run multiple commands, without allowing other commands to run between them.
- Parameters
- commands
List
[Command
] Commands to run, as constructed by
make_command
.- delay
float
(optional) Delay between commands (sec); or no delay if
None
. Only intended for unit testing.
- commands
-
async
set_simulation_mode
(simulation_mode)¶ Set the simulation mode.
Await implement_simulation_mode, update the simulation mode property and report the new value.
- Parameters
- simulation_mode
int
Requested simulation mode; 0 for normal operation.
- simulation_mode
-
async
start
()¶ Finish constructing the CSC.
If
initial_summary_state
isState.DISABLED
orState.ENABLED
then callconfigure
.Run
BaseCsc.start
-
async
stop_motion
()¶ Stop motion and wait for it to stop.
- Raises:
asyncio.CancelledError if not in enabled state.
-
telemetry_callback
(server)¶ Called when the low-level controller outputs telemetry.
- Parameters
- server
lsst.ts.hexrotcomm.CommandTelemetryServer
TCP/IP server.
- server
-
async
wait_n_telemetry
(n_telemetry=4)¶ Wait for n_telemetry telemetry messages since the most recent low-level command.
- Parameters
- n_telemetry
int
, optional Minimum number of telemetry messages since the most recent low-level command. Must be positive. A value of 3 is necessary to reliably allow stop or move to interrupt another move.
- n_telemetry
- Raises
- asyncio.CancelledError
If the system goes out of enabled state.
-
async
wait_stopped
(n_telemetry=4)¶ Wait for the current motion, if any, to stop.
- Parameters
- n_telemetry
int
, optional Minimum number of telemetry messages since the most recent low-level command. Must be positive. A value of 3 is necessary to reliably allow stop or move to interrupt another move.
- n_telemetry
- Returns
- is_stopped
bool
Is motion stopped? Always True unless max_nstatus is not None.
- Raises:
asyncio.CancelledError if not in enabled state.
- is_stopped