The PAL Module Manager¶
The PAL Module Manager is the application in charge of loading the modules and module sets present in the system and starting the corresponding modules. It also monitors the state of the running modules and can be used for stopping modules or restarting them. Additionally, the module manager handles the modules logs.
This is done with Modules and Module sets.
- A Module defines how an application is launched
- A Module set defines which of these modules are launched at startup.
Modules¶
A module is an execution unit plus some parameters that detail how and when to run it. The expected outcome can also be specified. Modules are configured using yaml files.
There are three supported ways of running applications.
- run: Executes ROS 2 nodes. Works in the same way as the command
ros2 run. - launch: Executes ROS 2 launch files. Works in the same way as the command
ros2 launch. - exec: Executes commands directly.
Module states¶
Modules can be in different states:
- LOADED: Module is loaded and ready to start.
- WAITING: Module has been started but it is waiting for dependencies.
- RUNNING: Module is loaded and running.
- FINISHED: Module finished execution on its own. This was an expected outcome.
- TERMINATED: Module was stopped and ended execution by sending termination signal.
- KILLED: Module was stopped but failed to end execution, it was force stopped with a kill signal.
- CRASHED: Module ended execution unexpectedly.
Module parameters¶
There are additional optional parameters that can be used to modify the behavior of the module.
- after: Do not start the module until the specified modules are running. Empty by default.
- waits: Wait until the specified modules are finished to start the module. The modules specified in this field must set the parameter
finishes: True. Empty by default. - dependencies: A list of diagnostics the module will wait for to be ready, i.e., in OK or WARN status. Once all dependencies are ready the module can start. Empty by default.
- finishes: Specify whether a module is expected to finish execution on its own once started. False by default.
- termination_timeout: Modules are stopped by sending a termination signal. This parameter sets the amount of time to wait before sending a kill signal when trying to stop a module. Five seconds by default.
- enable_unbuffer: Whether unbuffering is enabled. Applications normally don't print their output until they reach a certain amount of bytes then the log is dumped all at once. Unbuffering means any output is printed as soon as it is generated. For logging purposes this is usually preferred. True by default.
- enable_multilog: Used for log rotation, i.e., the log file is switched after it reaches certain size. Useful for applications that are expected to log large amounts of data. Otherwise, all data is logged to one huge, and potentially infinite, file. For logging purposes, rotation is usually preferred. True by default.
Module example¶
As mentioned before, modules are configured in yaml files. An example file for a module is shown below:
foo_module:
run: "foo_package foo_node"
One can specify multiple modules per yaml:
foo_module:
run: "foo_package foo_node"
bar_module:
launch: "bar_package bar.launch.py"
dependencies: ["Foo Feature"]
The modules can make use of the robot info parameters to make them more generic. These parameters are kept by the robot_info_publisher node. Use @parameter_name@ and the Module Manager will do the replacement at runtime.
The play_motion2 module is a good example:
play_motion2:
launch: "@robot_type@_bringup @robot_type@_play_motion2.launch.py
arm_type:=@arm_type@
base_type:=@base_type@
end_effector:=@end_effector@
ft_sensor:=@ft_sensor@"
Module sets¶
Module sets define which modules are started when starting the robot. Just like modules, module sets are defined in yaml files. Sets are just a list of modules.
Here is a sample for a simple module set yaml file:
my_set:
- foo_module
- bar_module
One can specify multiple module sets per yaml file:
my_set:
- foo_module
- bar_module
my_other_set:
- my_module
Virtual groups¶
Virtual groups define a group of modules that can be managed as a group. Just like module sets, virtual groups are configured using yaml files.
The key difference with module sets is that virtual groups allow the user to manage the group of modules as a single unit, while module sets define modules that are started automatically.
Here is a sample for a simple virtual group yaml file:
my_virtual_group:
- foo_module
- bar_module
Startup customization¶
The startup process can be customized by registering new modules and module sets. The register of a module is done in the CMakeLists.txt of a ROS package. For a detailed instruction on how to create new modules and module sets see the tutorial Configure an application to launch at start-up. This tutorial also explains how to modify existing modules and module sets.
find_package(pal_module_cmake QUIET)
# Registering a module
if(pal_module_cmake_FOUND)
pal_register_modules(
module/my_custom_module.yaml
)
endif()
# Registering a module set
if(pal_module_cmake_FOUND)
pal_register_module_sets(
module/my_custom_module_set.yaml
)
endif()
# Registering a virtual group
if(pal_module_cmake_FOUND)
pal_register_virtual_groups(
module/my_custom_virtual_group.yaml
)
endif()
Module Manager¶
Registering with CMake¶
The pal_module_cmake package provides the means to register a module in the system.
Add pal_module_cmake as a build dependency in your package.xml:
<build_depend>pal_module_cmake</build_depend>
Registering Modules¶
To register one or more module, list the YAML files into the ament index under the pal_system_module resource type. This would install them in the package's share directory.
pal_register_modules(foo_module.yaml)
Multiple files can be passed in a single call:
pal_register_modules(
path/to/foo_module.yaml
path/to/bar_module.yaml
)
Note that only one call to pal_register_modules per package is allowed.
Registering Module Sets¶
To register one or more module sets, list the YAML files into the ament index under the pal_system_module_set resource type.
pal_register_module_sets(path/to/my_set.yaml)
Note that only one call to pal_register_module_sets per package is allowed.
Registering Virtual Groups¶
To registers one or more virtual groups, list YAML files into the ament index under the pal_system_virtual_group resource type.
pal_register_virtual_groups(path/to/my_virtual_group.yaml)
Note that only one call to pal_register_virtual_groups per package is allowed.
Registering with Python¶
For Python-only packages, modules can be registered directly through the package's setup.py without requiring pal_module_cmake.
Two files must be added inside a module/ directory at the root of the package:
-
An ament index resource marker file named after the package (e.g.,
module/module_name). Its content must be the relative path to the YAML file with respect to the root of the package:module/module_name.yaml -
A module YAML file (e.g.,
module/module_name.yaml) defining the module.
Then, in setup.py, add both files to data_files so they are installed at the correct ament index locations:
data_files=[
('share/ament_index/resource_index/packages', ['resource/' + package_name]),
('share/' + package_name, ['package.xml']),
# Register the package as a pal_system_module
('share/ament_index/resource_index/pal_system_module', ['module/' + package_name]),
# Install the module YAML file
('share/' + package_name + '/module', ['module/module_name.yaml']),
],
The marker file in share/ament_index/resource_index/pal_system_module/ lets the module manager discover the package at runtime. The YAML file is then loaded from share/<package_name>/module/.
Disclaimer: This approach is discouraged because it bypasses the standard testing and integration workflow, which may result in improperly configured or unverified modules.