Running BeTFSM
Executing a state machine is done using a Runner. This Runner iteratively executes the state machine at a fixed frequency and returns when the state machine gives an outcome not equal to TICKING.
Most of the parameters are defined by RunnerBase. The actual runners inherit from this base class and implement the environment related aspects such as timing, scheduling etc. There are currently two runners Runner only depends on a pure Python environment, and ROSRunner depends on a ROS2 environment and allow to use BeTFSM to implement a proper ROS2 node.
Besides their constructor arguments, all the runners will interpret command line arguments that allow all users to further configure the execution. Using the --help command line argument you can get a full list:
usage: example_runner.py [-h] [--frequency FREQUENCY]
[--publish_frequency PUBLISH_FREQUENCY]
[--debug | --no-debug]
[--display_active | --no-display_active]
[--betfsm_log BETFSM_LOG] [--name-filter NAME_FILTER]
[--generate_dot GENERATE_DOT]
[--generate_json GENERATE_JSON]
[--serve | --no-serve] [--host HOST] [--port PORT]
[--workers WORKERS]
[--log-level {critical,error,warning,info,debug,trace}]
BeTFSMRunnerGUI command line options
options:
-h, --help show this help message and exit
BeTFSMRunnerGUI Options:
--frequency FREQUENCY
frequency at which BeTFSM runs [default:100.0]
--publish_frequency PUBLISH_FREQUENCY
publishing frequency for GUI [default:5 ]
--debug, --no-debug Log statistics of the timing of each tick at
publish_frequency [default: False] (default: False)
--display_active, --no-display_active
Log the active nodes at rate equal to
publish_frequency, only logs changes to
activity[default: False] (default: False)
--betfsm_log BETFSM_LOG
BeTFSM Log specification string, i.e. a list of
categories separated with ':'. Known categories are
{'state', 'default', 'service', 'unknown'} but there
can be user-defined categories [default: 'None']
--name-filter NAME_FILTER
specifies a comma-separated list of naes (can be
regular expressions) to filter out.[default: ''
--generate_dot GENERATE_DOT
generate a graphviz .dot file from the state machine
and store in the specified file (and quit the program
without running)
--generate_json GENERATE_JSON
generate a json file from the state machine and store
in the specified file (and quit the program without
running)
--serve, --no-serve Start-up server with graphical user interface
[default:True] (default: True)
Uvicorn Web Server Options:
--host HOST Bind socket to this host [default: 0.0.0.0]
--port PORT Bind socket to this port [default: 8000]
--workers WORKERS Number of worker processes[default: 1]
--log-level {critical,error,warning,info,debug,trace}
log-level of the web-server [default: info ]
You can still pass ROS2 arguments according to ROS2 conventions: e.g. adding :
"--ros-args --log-level debug" to your arguments
You can also use the command-line arguments not to execute, but to generate a .dot file, in GraphViz format, or to generate a .json file that can be used for further analysis of the BeTFSM-tree. Currently the .json format does not contain enough information to reconstruct the BeTFSM tree.
RunnerBase
betfsm.RunnerBase
__init__(statemachine, blackboard, frequency=100.0, publish_frequency=10, debug=False, display_active=False, betfsm_log=None, select_name='', type_filter='', allow_generate_dot=True, allow_generate_sm_dot=True, allow_generate_json=True, serve=True, host='0.0.0.0', port=8000, workers=1, log_level='info')
Initializes the BeTFSMRunner. This BeTFSMRunner has no other dependencies and runs in the main thread. The parameters frequency, publish_frequency, debug, display_active, and serve can be overridden by command-line parameters. Use "--help" to show all command-line parameters.
| Parameters: |
|
|---|
parse_arguments(parser, group_app, group_uvr)
Parses the arguments from the command-line. This function could further add parameters to the parser if necessary.
Runner
betfsm.Runner
Bases: RunnerBase
Runner for a BeTFSM ticking state machine. Initializes the BeTFSMRunner. This BeTFSMRunner has no other dependencies and runs in the main thread. You typically call this class in the main body of your program.
This is multi-threaded, only access member variables using the methods designed for this. (i.e. set_outcome, get_outcome)
run()
Runs the statemachine until it returns an outcome different from TICKING
Refers to absolute time to avoid drifting. Uses monotonic clock to avoid problems with system time changes.
| Returns: |
|
|---|
ROSRunner
betfsm_ros.ROSRunner
Bases: RunnerBase
Runner for a BeTFSM ticking state machine. Initializes the BeTFSMRunner. This BeTFSMRunner has no other dependencies and runs in the main thread. You typically call this class in the main body of your program.
This is multi-threaded, only access member variables using the methods designed for this. (i.e. set_outcome, get_outcome)
run()
Runs the statemachine until it returns an outcome different from TICKING
Refers to absolute time to avoid drifting. Uses monotonic clock to avoid problems with system time changes.
| Returns: |
|
|---|
timer_cb()
called by ROS timer, should not be called by user.