RotatorCsc¶
-
class
lsst.ts.rotator.
RotatorCsc
(config_dir=None, initial_state=<State.OFFLINE: 4>, simulation_mode=0)¶ Bases:
lsst.ts.hexrotcomm.base_csc.BaseCsc
MT rotator CSC.
Parameters: - 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
).- simulation_mode :
int
(optional) Simulation mode. Allowed values:
- 0: regular operation.
- 1: simulation: use a mock low level controller.
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
config_dir
Get or set the configuration directory. default_initial_state
disabled_or_enabled
Return True if the summary state is State.DISABLED
orState.ENABLED
.domain
enable_cmdline_state
require_settings
simulation_mode
Get the current simulation mode. summary_state
Return the current summary state as a salobj.State, or OFFLINE if unknown. valid_simulation_modes
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_commandable
()Assert that the controller is connected and has CSC commands enabled. assert_enabled
([action])Assert that an action that requires ENABLED state can be run. assert_enabled_substate
(substate)Assert the controller is enabled and in the specified substate. assert_summary_state
(*allowed_states, isbefore)Assert that the current summary state is as specified. 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. close_tasks
()Shut down pending tasks. config_callback
(server)Called when the TCP/IP controller outputs configuration. configure
(config)Configure the CSC. connect_callback
(server)Called when the server’s command or telemetry sockets connect or disconnect. do_clearError
(data)Reset the FAULT state to STANDBY. do_configureAcceleration
(data)Specify the acceleration limit. do_configureVelocity
(data)Specify the velocity limit. 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)Go to the position specified by the most recent positionSet
command.do_setAuthList
(data)Update the authorization list. do_setLogLevel
(data)Set logging level. 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. do_track
(data)Specify a position, velocity, TAI time tracking update. do_trackStart
(data)Start tracking. 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. get_config_pkg
()Get the name of the configuration package, e.g. handle_summary_state
()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. put_log_level
()Output the logLevel event. read_config_dir
()Set self.config_label_dict
and outputevt_settingVersions
.report_summary_state
()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. telemetry_callback
(server)Called when the TCP/IP controller outputs telemetry. Attributes Documentation
-
config_dir
¶ Get or set the configuration directory.
Parameters: - config_dir :
str
,bytes
, orpathlib.Path
New configuration directory.
Returns: - config_dir :
pathlib.Path
Absolute path to the configuration directory.
Raises: - ValueError
If the new configuration dir is not a directory.
- config_dir :
-
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_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]¶
Methods Documentation
-
classmethod
add_arguments
(parser)¶ Add arguments to the parser created by
make_from_cmd_line
.Parameters: - parser :
argparse.ArgumentParser
The argument parser.
Notes
If you override this method then you should almost certainly override
add_kwargs_from_args
as well.- parser :
-
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.
Notes
If you override this method then you should almost certainly override
add_arguments
as well.- args :
-
classmethod
amain
(index, **kwargs)¶ Make a CSC from command-line arguments and run it.
Parameters: - index :
int
,enum.IntEnum
,True
,False
orNone
If the CSC is indexed: specify
True
makeindex
a required command-line argument that accepts any index, or an enum.IntEnum class to makeindex
a required command-line argument that only accepts the enum values. If the CSC is not indexed specifyNone
or 0.- **kwargs :
dict
, optional Additional keyword arguments for your CSC’s constructor.
- index :
-
assert_commandable
()¶ Assert that the controller is connected and has CSC commands enabled.
-
assert_enabled
(action='')¶ Assert that an action that requires ENABLED state can be run.
Parameters: - action :
str
, optional Action attempted. Not needed if this is called at the beginning of a
do_...
method, since the user will know what command was called.
- action :
-
assert_enabled_substate
(substate)¶ Assert the controller is enabled and in the specified substate.
-
assert_summary_state
(*allowed_states, isbefore)¶ Assert that the current summary state is as specified.
Also checks that the controller is commandable.
Used in do_xxx methods to check that a command is allowed.
-
begin_disable
(data)¶ Begin do_disable; called before state changes.
Parameters: - data :
DataType
Command data
- data :
-
begin_enable
(data)¶ Begin do_enable; called before state changes.
Parameters: - data :
DataType
Command data
- data :
-
begin_exitControl
(data)¶ Begin do_exitControl; called before state changes.
Parameters: - data :
DataType
Command data
- data :
-
begin_standby
(data)¶ Begin do_standby; called before the state changes.
Parameters: - data :
DataType
Command data
- data :
-
begin_start
(data)¶ Begin do_start; configure the CSC before changing state.
Parameters: - data :
cmd_start.DataType
Command 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.
- data :
-
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.
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.- exception :
-
config_callback
(server)¶ Called when the TCP/IP controller outputs configuration.
Parameters: - server :
lsst.ts.hexrotcomm.CommandTelemetryServer
TCP/IP server.
- server :
-
configure
(config)¶ Configure the CSC.
Parameters: - config :
object
The configuration as described by the schema at
schema_path
, as a struct-like object.
Notes
Called when running the
start
command, just before changing summary state fromState.STANDBY
toState.DISABLED
.- config :
-
connect_callback
(server)¶ Called when the server’s command or telemetry sockets connect or disconnect.
Parameters: - server :
CommandTelemetryServer
TCP/IP server.
- server :
-
do_clearError
(data)¶ Reset the FAULT state to STANDBY.
-
do_configureAcceleration
(data)¶ Specify the acceleration limit.
-
do_configureVelocity
(data)¶ Specify the velocity limit.
-
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)¶ Go to the position specified by the most recent
positionSet
command.
-
do_setAuthList
(data)¶ Update the authorization list.
Parameters: - data :
cmd_setAuthList.DataType
Authorization lists.
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.
- data :
-
do_setLogLevel
(data)¶ Set logging level.
Parameters: - data :
cmd_setLogLevel.DataType
Logging level.
- data :
-
do_standby
(data)¶ Go from DISABLED state to STANDBY.
Note: use the clearError command to go from FAULT to STANDBY.
-
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.
-
do_stop
(data)¶ Halt tracking or any other motion.
-
do_track
(data)¶ Specify a position, velocity, TAI time tracking update.
-
do_trackStart
(data)¶ Start tracking.
Once this is run you must issue
track
commands at 10-20Hz until you are done tracking, then issue thestop
command.
-
end_disable
(data)¶ End do_disable; called after state changes but before command acknowledged.
Parameters: - data :
DataType
Command data
- data :
-
end_enable
(data)¶ End do_enable; called after state changes but before command acknowledged.
Parameters: - data :
DataType
Command data
- data :
-
end_exitControl
(data)¶ End do_exitControl; called after state changes but before command acknowledged.
Parameters: - data :
DataType
Command data
- data :
-
end_standby
(data)¶ End do_standby; called after state changes but before command acknowledged.
Parameters: - data :
DataType
Command data
- data :
-
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.
-
static
get_config_pkg
()¶ Get the name of the configuration package, e.g. “ts_config_ocs”.
-
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()
.
-
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.
Raises: - ExpectedError
If
simulation_mode
is not a supported value.
- simulation_mode :
-
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.
Returns: - command :
Command
The command. Note that the
counter
field is 0; it is set byCommandTelemetryServer.put_command
.
- code :
-
classmethod
make_from_cmd_line
(index, **kwargs)¶ Construct a CSC from command line arguments.
Parameters: - index :
int
,enum.IntEnum
,True
,False
orNone
If the CSC is indexed: specify
True
makeindex
a required command-line argument that accepts any index, or an enum.IntEnum class to makeindex
a required command-line argument that only accepts the enum values. If the CSC is not indexed specifyNone
or 0.- **kwargs :
dict
, optional Additional keyword arguments for your CSC’s constructor.
Returns: - csc :
cls
The CSC.
Notes
To add additional command-line arguments, override
add_arguments
andadd_kwargs_from_args
.- index :
-
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).
-
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 :
-
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 :
-
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 :
-
start
()¶ Finish constructing the CSC.
- If
initial_summary_state
isState.DISABLED
orState.ENABLED
then callconfigure
. - Run
BaseCsc.start
- If
-
telemetry_callback
(server)¶ Called when the TCP/IP controller outputs telemetry.
Parameters: - server :
lsst.ts.hexrotcomm.CommandTelemetryServer
TCP/IP server.
- server :
- config_dir :