Overview
The big picture
A learned policy is a function: it takes an observation (numbers describing the robot and what it is asked to do) and returns an action (numbers that become joint commands). Running it on a robot takes much more than calling that function:
the observation must be built from sensors exactly as it was built in training;
the action must be scaled into commands the robot understands;
all of it must happen on time, every cycle, next to a fast joint control loop;
and it must stay safe when something is missing, late or wrong.
The framework splits this work into small pieces with one job each. The policy-specific pieces are in the middle and mostly do not see where the data comes from or goes to. The transport pieces are at both ends and never see the model. Two exceptions: an observation term may subscribe to its own topic (Extending the framework), and a postprocessor may send gains to another controller (mjlab policies).
Read it top to bottom: sensors fill the state store; the active policy reads it, runs its
three stages and fills the command store; executors send the commands to the robot. The
optional kinematics model gives the policies and the safety checks the poses of the robot’s
links (Kinematics). The safety checks watch the state store on every cycle. On a fault,
either the policy keeps running with neutral user commands (the runner sets a state entry that
closes every CommandGate, see Safety behaviour), or it is no longer stepped: the
node stops sending, and the controller’s executors hold, damp or write their safe values (zero effort for
PdEffortExecutor), or hand
over to the fallback controllers (Safety behaviour).
The packages
policy_frameworkThe core. It knows nothing about any training framework: the stores, the pipeline that runs and switches policies, the two hosts (node and controller), the kinematics model, and generic plugins (ONNX inference, topic sources, executors), and the safety layer: the built-in monitor checks, the
SafetyCheckplugins and the fault reactions.policy_framework_mjlabEverything specific to policies exported by mjlab and pal_mjlab: how their observation is laid out, how their actions are scaled, where their gains go, and the configuration and launch file for the Kangaroo robot.
policy_framework_msgsThe interfaces: the
SwitchPolicyandListPoliciesservices and theActivePoliciestopic of the hosts (with thePolicyInfomessage they share), theSafetyStatusArrayof~/safety_status(with itsSafetyStatus), and theMockFaultmessage of theMockSafetyCheck.
To support another training framework you would write a package like
policy_framework_mjlab, without changing policy_framework.
Repository layout
policy_framework groups its files by the role they play. The same folders appear under
include/policy_framework/ (headers), src/ (sources), test/ (tests) and
params/ (parameter definitions) where they apply, so a class, its implementation, its test
and its parameters are found under the same path. interfaces/ is header-only, and the
shared topic parameter is in params/plugins/sources/topic_parameters.yaml.
policy_framework/
include/policy_framework/
interfaces/ what plugins derive from
core/ what the hosts are built on
hosts/ the programs that run the cycle
plugins/
sources/ where the data comes from
inference/ what runs the model
stages/ generic preprocessors and postprocessors
executors/ where the commands go
safety/ SafetyCheck plugins
plugin_interfaces.hpp
src/ test/ params/ same folders as above
test/fixtures/ test models and URDF
Folder |
Content |
Example include |
|---|---|---|
|
One header per plugin base class ( |
|
|
The pieces the hosts are built on: the stores, the pipeline, the kinematics model and the safety monitor. |
|
|
The runner and the two hosts: standalone node and ros2_control controller. |
|
|
The generic plugins shipped with the framework, one folder per kind of plugin. |
|
policy_framework/plugin_interfaces.hpp includes every interface except the observation
terms, for a plugin that needs several of them.
policy_framework_mjlab is small and stays flat (include/, src/, test/,
params/). Its test-only plugins are in test/plugins/, and the deployment
configuration has one folder per robot (config/kangaroo/) next to the launch/ files.
A new file goes in the folder of its role. For example, a new input source plugin goes in
plugins/sources/ in all four trees: header, source, test and parameters.
Vocabulary
These words are used with one meaning throughout the code and the documentation.
Term |
Meaning |
|---|---|
Policy |
A trained model together with the three stages that run it: a preprocessor, an
inference and a postprocessor. It has a name, for example |
Observation |
The input of the model: one flat vector of numbers, built every step. |
Observation term |
One named block of the observation, for example |
History |
The past values of a term that the model also receives. A term with a history of 3 appears as its three most recent values. |
Action |
The raw output of the model. It is not a joint command yet. |
State store |
A table of named numbers holding the latest inputs, for example
|
Command store |
The same kind of table holding the latest outputs, for example
|
Entry |
One named number in a store, with the time it was produced. |
Input source |
A plugin that copies a topic into the state store. |
Executor |
A plugin that sends the command store to the robot. |
Host |
The program that runs the cycle: the standalone node or the ros2_control controller. |
Runner |
The part shared by both hosts. It loads the plugins from the parameters (except the
controller’s |
Pipeline |
Holds all the policies, runs the active one and switches between them. |
Step |
One run of the active policy: preprocessor, inference, postprocessor. |
Update |
One run of the host’s loop. In the controller there can be several updates per step. |
Plugin |
A class loaded by name at start-up (pluginlib). Every stage, source, executor and safety check is one, so new ones can be added from other packages. |
User command |
An input a person or a planner sends, such as a velocity command or a motion reference. It is replaced by a neutral command (for example zero velocity) when it times out or must be ignored. |
Safety check |
A test of the state on every cycle: built into the |
Fault reaction |
What a failing check makes the host do: |
Safety entry |
A state entry that is 0 while user commands must be ignored, for example a dead-man
switch. |
Where to go next
Data flow follows one number from a sensor to a motor.
The two hosts compares the node and the controller, and explains the rates and threads.
Policies and switching explains switching between policies and what each one remembers.
Safety behaviour lists what happens when something is missing or goes wrong.
Kinematics explains the robot model available to the policies.
mjlab policies explains how mjlab and pal_mjlab policies are run.
Extending the framework shows which plugin to write for what.