HexapodCommander¶
- class lsst.ts.mthexapod.HexapodCommander(index: int, enable: bool)¶
Bases:
CscCommander
Command the MTHexapod CSC from the command line.
- Parameters:
- index
int
SAL index of MTHexapod CSC.
- Read commands from stdin and write updated events and telemetry to stdout.
- The telemetry is filtered so that tiny changes due to encoder jitter
- are ignored.
- Used by `command_mthexapod`.
- index
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)Construct the commander and run it.
check_arguments
(args, *names)Check that the required arguments are provided.
close
()Close the commander, prior to quitting.
do_start
(args)Allow the start command to have no arguments.
event_callback
(data, name)Generic callback for events.
evt_logMessage_callback
(data)Abbreviate the log output by omitting less-interesting fields.
field_is_public
(name)Return True if the specified field name is public, False otherwise.
format_data
(data)Format the public fields of an event or telemetry sample, for printing.
format_dict
(data)Format a dict for printing.
format_item
(key, value)Format one event or telemetry field for printing.
Get help for each command, as a list of strings.
get_public_data
(data)Get a dict of field_name: value for public fields of a message.
get_rounded_public_data
(data[, digits])Get a dict of field_name: value for public fields of a DDS sample with float values rounded.
get_telemetry_comparison_dict
(public_dict, ...)Get a dict of field name: rounded data, for comparing new telemetry to old.
make_from_cmd_line
(index, **kwargs)Construct a SAL-related class from command line arguments.
output
(msg)Print a message to output, appending a final newline.
positions_close
(position1, position2)Return True if two positions are nearly equal.
Print help.
run_command
(cmd)Run the specified command string and wait for it to finish.
run_command_topic
(command_name, args)Run a command that has an associated salobj RemoteCommand topic.
start
()Start asynchonous processes.
tel_actuators_callback
(data)Callback for actuators telemetry.
tel_application_callback
(data)Callback for the application telemetry.
telemetry_callback
(data, name[, digits])Default callback for telemetry topics.
Methods Documentation
- classmethod add_arguments(parser: ArgumentParser) None ¶
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: Namespace, kwargs: dict[str, Any]) None ¶
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: int | enum.IntEnum | bool | None, **kwargs: Any) None ¶
Construct the commander and run it.
Parse the command line to construct the commander, then parse and execute commands until the
exit
is seen.- 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
- check_arguments(args: Sequence[str], *names: str | tuple[str, collections.abc.Callable[[str], Any]]) dict[str, Any] ¶
Check that the required arguments are provided. and return them as a keyword argument dict with cast values.
- Parameters:
- args
List
[str
] Command arguments, as strings.
- *names
List
[str
ortuple
] Argument name and optional cast function. Each element is either:
An argument name, in which case the argument is cast to a float
A tuple of (name, cast function), in which case the argument is cast using the cast function. The cast function takes one str argument and returns the cast value.
- args
- async event_callback(data: BaseMsgType, name: str) None ¶
Generic callback for events.
You may provide evt_<event_name> methods to override printing of specific events.
- async evt_logMessage_callback(data: BaseMsgType) None ¶
Abbreviate the log output by omitting less-interesting fields.
Omit traceback unless it is non-blank. Always omit filePath, functionName, lineNumber, process, and timestamp.
- async evt_summaryState_callback(data: BaseMsgType) None ¶
- field_is_public(name: str) bool ¶
Return True if the specified field name is public, False otherwise.
- format_data(data: BaseMsgType) str ¶
Format the public fields of an event or telemetry sample, for printing.
- format_dict(data: dict[str, Any]) str ¶
Format a dict for printing.
Unlike format_data, this requires a dict and formats all fields.
- get_commands_help() list[str] ¶
Get help for each command, as a list of strings.
End with “Other Commands:” and any commands in help_dict that are not in command_dict.
- get_public_data(data: BaseMsgType) dict[str, Any] ¶
Get a dict of field_name: value for public fields of a message.
- Parameters:
- data
BaseMsgType
Message.
- data
- get_rounded_public_data(data: BaseMsgType, digits: int = 2) dict[str, Any] ¶
Get a dict of field_name: value for public fields of a DDS sample with float values rounded.
- get_telemetry_comparison_dict(public_dict: dict[str, Any], digits: int) dict[str, Any] ¶
Get a dict of field name: rounded data, for comparing new telemetry to old.
- classmethod make_from_cmd_line(index: int | enum.IntEnum | bool | None, **kwargs: Any) CscCommander ¶
Construct a SAL-related class 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 class’s constructor.
- index
- Returns:
- instance
cls
The constructed instance.
- instance
Notes
To add additional command-line arguments, override
add_arguments
andadd_kwargs_from_args
.
- output(msg: str) None ¶
Print a message to output, appending a final newline.
Please call this instead of print to support unit tests.
If
self.testing
is True then appendstr
toself.output_queue
instead of printing it. Use this mode for unit testing a CSC commander.
- positions_close(position1: list[float], position2: list[float]) bool ¶
Return True if two positions are nearly equal.
- async run_command(cmd: str) None ¶
Run the specified command string and wait for it to finish.
- Parameters:
- cmd
str
Command string (command name and arguments). Note: does not handle the “exit” command.
- cmd
- async run_command_topic(command_name: str, args: Sequence[str]) None ¶
Run a command that has an associated salobj RemoteCommand topic.
- Parameters:
Notes
This method works for command topics that take scalar arguments. To support command topics with more exotic arguments you must provide a do_<command> method that parses the arguments and add an entry to self.help_dict.
- async tel_actuators_callback(data: BaseMsgType) None ¶
Callback for actuators telemetry.
Output actuators telemetry data if the values have changed enough to be interesting.
- Parameters:
- dataself.controller.tel_actuators.DataType.
Actuators data.
- async tel_application_callback(data: BaseMsgType) None ¶
Callback for the application telemetry.
Output application telemetry if the values have changed enough to be interesting.
- Parameters:
- dataself.controller.tel_application.DataType.
Actuators data.
- async telemetry_callback(data: BaseMsgType, name: str, digits: int = 2) None ¶
Default callback for telemetry topics.
Print the telemetry information if it has changed enough (as specified by
digits
).- Parameters:
- data
type_hints.BaseMsgType
The message data.
- name
str
The name to print. Typically the basic topic name with no prefix.
- digits
int
The default number of digits to which to round float values before comparing if fields have changed enough to be worth printing the new data. May be overridden for specific fields using constructor argument
telemetry_fields_compare_digits
.
- data
Notes
This method cannot be directly assigned as a topic callback. Use
functools.partial
or similar to specifyname
, and, if you like,digits
.This method can also be used for events, if you only want The event published when the data changes significantly. One good candidate is the generic clockOffset event.