### Install Debugging Tools
Source: https://github.com/ros-controls/ros2_control/blob/master/doc/debugging.rst
Installs xterm, gdb, and gdbserver required for debugging.
```bash
sudo apt install xterm gdb gdbserver
```
--------------------------------
### Controller Configuration with Simple Name
Source: https://github.com/ros-controls/ros2_control/blob/master/controller_manager/doc/userdoc.rst
Example of a controller configuration file specifying parameters using the controller's simple name.
```yaml
position_trajectory_controller:
ros__parameters:
type: joint_trajectory_controller/JointTrajectoryController
joints:
- joint1
- joint2
command_interfaces:
- position
.....
```
--------------------------------
### Installing Test Components Library
Source: https://github.com/ros-controls/ros2_control/blob/master/hardware_interface_testing/CMakeLists.txt
Installs the compiled test components library to the 'lib' directory.
```cmake
install(TARGETS test_components
DESTINATION lib
)
```
--------------------------------
### Controller Configuration with Wildcard and Absolute Namespace
Source: https://github.com/ros-controls/ros2_control/blob/master/controller_manager/doc/userdoc.rst
Example of a controller configuration file using wildcard entries and absolute namespaces for parameter definition.
```yaml
/**:
ros__parameters:
type: joint_trajectory_controller/JointTrajectoryController
command_interfaces:
- position
.....
position_trajectory_controller_joint1:
ros__parameters:
joints:
- joint1
position_trajectory_controller_joint2:
ros__parameters:
joints:
- joint2
```
--------------------------------
### Controller Configuration with Absolute Namespace
Source: https://github.com/ros-controls/ros2_control/blob/master/controller_manager/doc/userdoc.rst
Example of a controller configuration file specifying parameters for a controller in an absolute namespace.
```yaml
/position_trajectory_controller:
ros__parameters:
type: joint_trajectory_controller/JointTrajectoryController
joints:
- joint1
- joint2
command_interfaces:
- position
.....
```
--------------------------------
### Generic Hardware Interface Configuration Example
Source: https://github.com/ros-controls/ros2_control/blob/master/hardware_interface/doc/hardware_interface_types_userdoc.rst
This XML snippet illustrates the general structure for defining hardware components, including hardware plugins, parameters, joints with command and state interfaces, and their associated parameters.
```xml
library_name/ClassName
value
-1
1
0.0
some_value
other_value
```
--------------------------------
### Controller Configuration with Namespace Wildcard
Source: https://github.com/ros-controls/ros2_control/blob/master/controller_manager/doc/userdoc.rst
Example of a controller configuration file using a namespace wildcard to match controllers within any namespace.
```yaml
/**/position_trajectory_controller:
ros__parameters:
type: joint_trajectory_controller/JointTrajectoryController
joints:
- joint1
- joint2
command_interfaces:
- position
.....
```
--------------------------------
### Command-line Spawner for Multiple Controllers
Source: https://github.com/ros-controls/ros2_control/blob/master/controller_manager/doc/userdoc.rst
Example of using the 'ros2 run spawner' command to launch multiple controllers with individual parameter files and ROS arguments.
```console
$ ros2 run controller_manager spawner --controller position_trajectory_controller \
--param-file /path/to/position_trajectory_controller_params.yaml \
--controller-ros-args "--ros-args --remap /joint_states:=/rrbot/joint_states" \
--controller velocity_trajectory_controller \
--param-file /path/to/velocity_trajectory_controller_params.yaml \
--controller-ros-args "--ros-args --remap /joint_states:=/rrbot/joint_states"
```
--------------------------------
### ROS 2 Control: Example List Controllers Output
Source: https://github.com/ros-controls/ros2_control/blob/master/ros2controlcli/doc/userdoc.rst
Shows an example of the output from the 'ros2 control list_controllers' command, indicating a loaded controller and its active state.
```console
$ ros2 control list_controllers
test_controller_name[test_controller] active
```
--------------------------------
### ROS 2 Control: Example List Controller Types Output
Source: https://github.com/ros-controls/ros2_control/blob/master/ros2controlcli/doc/userdoc.rst
Provides an example output of the 'ros2 control list_controller_types' command, listing controller names and their base classes.
```console
$ ros2 control list_controller_types
diff_drive_controller/DiffDriveController controller_interface::ControllerInterface
joint_state_broadcaster/JointStateBroadcaster controller_interface::ControllerInterface
joint_trajectory_controller/JointTrajectoryController controller_interface::ControllerInterface
```
--------------------------------
### Configure Async Thread Parameters
Source: https://github.com/ros-controls/ros2_control/blob/master/controller_manager/doc/running_controllers_asynchronously.rst
Example of configuring additional thread parameters for an asynchronous controller, including thread priority and CPU affinity.
```yaml
example_async_controller:
ros__parameters:
type: example_controller/ExampleController
is_async: true
update_rate: 20 # Hz
async_parameters:
thread_priority: 50
cpu_affinity: [2, 4]
```
--------------------------------
### Spawner Command-Line Help
Source: https://github.com/ros-controls/ros2_control/blob/master/controller_manager/doc/userdoc.rst
Displays the help message for the 'spawner' command, outlining its arguments and options for loading, configuring, and starting controllers. Use this to understand available parameters for controller management.
```console
$ ros2 run controller_manager spawner -h
usage: spawner [-h] [-c CONTROLLER_MANAGER] [-p PARAM_FILE] [--load-only] [--inactive] [-u] [--controller-manager-timeout CONTROLLER_MANAGER_TIMEOUT] [--switch-timeout SWITCH_TIMEOUT]
[--service-call-timeout SERVICE_CALL_TIMEOUT] [--activate-as-group] [--switch-asap | --no-switch-asap] [--controller-ros-args CONTROLLER_ROS_ARGS]
controller_names [controller_names ...]
positional arguments:
controller_names List of controllers
options:
-h, --help show this help message and exit
-c CONTROLLER_MANAGER, --controller-manager CONTROLLER_MANAGER
Name of the controller manager ROS node
-p PARAM_FILE, --param-file PARAM_FILE
Controller param file to be loaded into controller node before configure. Pass multiple times to load different files for different controllers or to override the parameters of the same controller.
--load-only Only load the controller and leave unconfigured.
--inactive Load and configure the controller, however do not activate them
-u, --unload-on-kill Wait until this application is interrupted and unload controller
--controller-manager-timeout CONTROLLER_MANAGER_TIMEOUT
Time to wait for the controller manager service to be available
--switch-timeout SWITCH_TIMEOUT
Time to wait for a successful state switch of controllers. Useful when switching cannot be performed immediately, e.g., paused simulations at startup
--service-call-timeout SERVICE_CALL_TIMEOUT
Time to wait for the service response from the controller manager
--activate-as-group Activates all the parsed controllers list together instead of one by one. Useful for activating all chainable controllers altogether
--switch-asap, --no-switch-asap
Option to switch the controllers in the realtime loop at the earliest possible time or in the non-realtime loop.
--controller-ros-args CONTROLLER_ROS_ARGS
The --ros-args to be passed to the controller node, e.g., for remapping topics. Pass multiple times for every argument.
```
--------------------------------
### Node Definition for Controller Spawner
Source: https://github.com/ros-controls/ros2_control/blob/master/doc/migration.rst
Example of defining a Node for the controller spawner, including package, executable, and arguments for remapping.
```python
spawner_node = Node(
package="controller_manager",
executable="spawner",
arguments=[
"diffbot_base_controller",
"--controller-ros-args",
"--remap",
"/diffbot_base_controller/cmd_vel:=/cmd_vel",
],
)
```
--------------------------------
### Controller Configuration for Specific Robot Namespace
Source: https://github.com/ros-controls/ros2_control/blob/master/controller_manager/doc/userdoc.rst
Example of a controller configuration file specifying parameters for a controller within a specific robot's namespace.
```yaml
/rrbot_1/position_trajectory_controller:
ros__parameters:
type: joint_trajectory_controller/JointTrajectoryController
```
--------------------------------
### Implement Hardware Status Update
Source: https://github.com/ros-controls/ros2_control/blob/master/hardware_interface/doc/writing_new_hardware_component.rst
Map internal hardware states to the standard `HardwareStatus` message fields. This example shows how to set the health status based on joint limits.
```cpp
hardware_interface::return_type MyHardware::update_hardware_status_message(
control_msgs::msg::HardwareStatus & msg)
{
for (size_t i = 0; i < get_hardware_info().joints.size(); ++i)
{
auto & generic_status = msg.hardware_device_states[i].generic_hardware_status;
// Example: Map internal state to a standard status field
if (std::abs(hw_positions_[i]) > joint_limits_[i].max_position)
{
generic_status.health_status = control_msgs::msg::GenericState::HEALTH_ERROR;
}
else
{
generic_status.health_status = control_msgs::msg::GenericState::HEALTH_OK;
}
}
return hardware_interface::return_type::OK;
}
```
--------------------------------
### ChainableController Base Class Example
Source: https://github.com/ros-controls/ros2_control/blob/master/controller_manager/doc/controller_chaining.rst
Illustrates the abstract methods that must be implemented by controllers intended for chaining. These methods handle exporting reference and state interfaces, and reacting to chained mode activation.
```C++
class ChainableController : public ControllerInterface
{
public:
virtual ~ChainableController() = default;
virtual std::vector export_reference_interfaces() = 0;
virtual std::vector export_state_interfaces() = 0;
void set_chained_mode(bool activate)
{
is_chained_mode_ = activate;
on_set_chained_mode(activate);
}
protected:
// Controller specific actions when chained mode is activated or deactivated
virtual void on_set_chained_mode(bool activate) = 0;
private:
bool is_chained_mode_ = false;
};
```
--------------------------------
### Configure Asynchronous Controller in YAML
Source: https://github.com/ros-controls/ros2_control/blob/master/controller_manager/doc/running_controllers_asynchronously.rst
Example of configuring a controller to run asynchronously with a specific update rate in a ROS 2 YAML parameters file.
```yaml
controller_manager:
ros__parameters:
update_rate: 100 # Hz
example_async_controller:
ros__parameters:
type: example_controller/ExampleController
is_async: true
update_rate: 20 # Hz
```
--------------------------------
### Basic ros2_control CMakeLists.txt
Source: https://github.com/ros-controls/ros2_control/blob/master/ros2_control/CMakeLists.txt
This snippet shows the essential CMake commands for a ros2_control package. It sets the minimum CMake version, defines the project, finds the ament_cmake package, and configures the package for installation.
```cmake
cmake_minimum_required(VERSION 3.16)
project(ros2_control)
find_package(ament_cmake REQUIRED)
ament_package()
```
--------------------------------
### Instantiate ControllerManager in C++ Process
Source: https://github.com/ros-controls/ros2_control/blob/master/controller_manager/doc/userdoc.rst
Example of how to instantiate the ControllerManager class within a C++ process, including setting node options and remap rules to avoid naming conflicts.
```cpp
auto options = controller_manager::get_cm_node_options();
options.arguments({
"--ros-args",
"--remap", "_target_node_name:__node:=dst_node_name",
"--log-level", "info"});
auto cm = std::make_shared(
executor, "_target_node_name", "some_optional_namespace", options);
```
--------------------------------
### Hardware Interface Initialization in Source File
Source: https://github.com/ros-controls/ros2_control/blob/master/hardware_interface/doc/writing_new_hardware_component.rst
Implement the on_init method in your hardware interface's source file. Initialize member variables, process parameters, and call the parent class's on_init. Return SUCCESS if initialization is successful, otherwise ERROR.
```c++
#include "my_hardware_interface.hpp"
namespace my_hardware_interface {
MyHardwareInterface::MyHardwareInterface() : hardware_interface::SystemInterface()
{}
hardware_interface::return_type MyHardwareInterface::on_init(hardware_interface::HardwareInfo &info)
{
// Initialize member variables and process parameters from info
// ...
// Call parent on_init to process standard values like name
if (hardware_interface::SystemInterface::on_init(info) != hardware_interface::return_type::OK)
{
return hardware_interface::return_type::ERROR;
}
// Check if all required parameters are set and valid
// ...
return hardware_interface::return_type::OK;
}
// ... other method implementations ...
} // namespace my_hardware_interface
```
--------------------------------
### CMakeLists.txt for Hardware Interface Package
Source: https://github.com/ros-controls/ros2_control/blob/master/hardware_interface/doc/writing_new_hardware_component.rst
Configure your package's `CMakeLists.txt` to include necessary dependencies, compile the hardware interface source file into a shared library, and export the plugin description file.
```cmake
find_package(ament_cmake REQUIRED)
find_package(hardware_interface REQUIRED)
find_package(pluginlib REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rclcpp_lifecycle REQUIRED)
add_library(my_hardware_interface SHARED src/my_hardware_interface.cpp)
target_include_directories(my_hardware_interface PUBLIC include)
target_link_libraries(my_hardware_interface
PRIVATE
hardware_interface::hardware_interface
pluginlib::pluginlib
rclcpp::rclcpp
rclcpp_lifecycle::rclcpp_lifecycle
)
pluginlib_export_plugin_description_file(hardware_interface my_hardware_interface.xml)
install(TARGETS my_hardware_interface
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
)
install(DIRECTORY include/${PROJECT_NAME}/
DESTINATION include/${PROJECT_NAME}
)
# Test section dependencies
find_package(ament_cmake_gmock REQUIRED)
# Compile definitions for tests
ament_add_gmock(test_my_hardware_interface
# ... other options ...
)
```
--------------------------------
### Spawner Global Options Help
Source: https://github.com/ros-controls/ros2_control/blob/master/controller_manager/doc/userdoc.rst
Detailed help for global options available when running the spawner command.
```console
Usage: spawner [global_options] --controller [controller_options] --controller ...
Global Options:
usage: spawner [-c CONTROLLER_MANAGER] [--controller-manager-timeout CONTROLLER_MANAGER_TIMEOUT] [--switch-timeout SWITCH_TIMEOUT] [--service-call-timeout SERVICE_CALL_TIMEOUT] [--activate-as-group]
[--switch-asap | --no-switch-asap] [-u] [-h]
options:
-c CONTROLLER_MANAGER, --controller-manager CONTROLLER_MANAGER
Name of the controller manager
--controller-manager-timeout CONTROLLER_MANAGER_TIMEOUT
Timeout for controller manager services
--switch-timeout SWITCH_TIMEOUT
Timeout for switch controller service
--service-call-timeout SERVICE_CALL_TIMEOUT
Timeout for service calls
--activate-as-group Activate controllers as a group
--switch-asap, --no-switch-asap
Switch controllers as soon as possible
-u, --unload-on-kill Deactivate the active controllers and unload them on kill
-h, --help Show help
```
--------------------------------
### Spawner Controller Options Help
Source: https://github.com/ros-controls/ros2_control/blob/master/controller_manager/doc/userdoc.rst
Detailed help for controller-specific options available when running the spawner command.
```console
Controller Options:
usage: spawner [-p PARAM_FILE] [--load-only] [--inactive] [--controller-ros-args CONTROLLER_ROS_ARGS] controller_name
positional arguments:
controller_name Name of the controller
options:
-p PARAM_FILE, --param-file PARAM_FILE
Parameter files to load for the controller
--load-only Load the controller but do not configure/activate it
--inactive Configure the controller but do not switch it
--controller-ros-args CONTROLLER_ROS_ARGS
ROS arguments to pass to the controller
```
--------------------------------
### Synchronous Hardware Component Configuration
Source: https://github.com/ros-controls/ros2_control/blob/master/hardware_interface/doc/asynchronous_components.rst
Example of a synchronous system hardware component configuration in URDF. This includes joint configurations and GPIO interfaces.
```xml
ros2_control_demo_hardware/RRBotSystemPositionOnlyHardware
2.0
3.0
2.0
-1
1
-1
1
```
--------------------------------
### ROS 2 Control: List Hardware Components Help
Source: https://github.com/ros-controls/ros2_control/blob/master/ros2controlcli/doc/userdoc.rst
Shows help for the 'ros2 control list_hardware_components' command, including options for verbose output and specifying the controller manager.
```console
$ ros2 control list_hardware_components -h
usage: ros2 control list_hardware_components [-h] [--spin-time SPIN_TIME] [-s] [--verbose] [-c CONTROLLER_MANAGER] [--include-hidden-nodes] [--ros-args ...]
Output the list of available hardware components
options:
-h, --help show this help message and exit
--spin-time SPIN_TIME
Spin time in seconds to wait for discovery (only applies when not using an already running daemon)
-s, --use-sim-time Enable ROS simulation time
--verbose, -v List hardware components with command and state interfaces along with their data types
-c CONTROLLER_MANAGER, --controller-manager CONTROLLER_MANAGER
Name of the controller manager ROS node (default: controller_manager)
--include-hidden-nodes
Consider hidden nodes as well
--ros-args ... Pass arbitrary arguments to the executable
```
--------------------------------
### Asynchronous Sensor Component Configuration
Source: https://github.com/ros-controls/ros2_control/blob/master/hardware_interface/doc/asynchronous_components.rst
Configures a sensor component to run asynchronously. This example shows a ForceTorqueSensor2D with a specific hardware parameter and state interfaces.
```xml
ros2_control_demo_hardware/ForceTorqueSensor2DHardware
0.43
kuka_tcp
```
--------------------------------
### Hardware Spawner Command-Line Help
Source: https://github.com/ros-controls/ros2_control/blob/master/controller_manager/doc/userdoc.rst
Shows the help message for the 'hardware_spawner' command-line tool, outlining its options for activating and configuring hardware components.
```console
$ ros2 run controller_manager hardware_spawner -h
usage: hardware_spawner [-h] [-c CONTROLLER_MANAGER] [--controller-manager-timeout CONTROLLER_MANAGER_TIMEOUT]
(--activate | --configure)
hardware_component_names [hardware_component_names ...]
positional arguments:
hardware_component_names
The name of the hardware components which should be activated.
options:
-h, --help show this help message and exit
-c CONTROLLER_MANAGER, --controller-manager CONTROLLER_MANAGER
Name of the controller manager ROS node
--controller-manager-timeout CONTROLLER_MANAGER_TIMEOUT
Time to wait for the controller manager
--activate Activates the given components. Note: Components are by default configured before activated.
--configure Configures the given components.
```
--------------------------------
### Updated initialize Method Signature for Hardware Components
Source: https://github.com/ros-controls/ros2_control/blob/master/doc/migration.rst
Demonstrates the change in the initialize methods for hardware components, now accepting HardwareComponentParams instead of HardwareInfo.
```cpp
const HardwareInfo &
```
```cpp
const HardwareComponentParams &
```
--------------------------------
### Load Controller Command Help
Source: https://github.com/ros-controls/ros2_control/blob/master/ros2controlcli/doc/userdoc.rst
Displays help information for the load_controller command, detailing its usage and options.
```console
$ ros2 control load_controller -h
usage: ros2 control load_controller [-h] [--spin-time SPIN_TIME] [-s] [--set-state {inactive,active}] [-c CONTROLLER_MANAGER] [--include-hidden-nodes] [--ros-args ...] controller_name [param_file]
Load a controller in a controller manager
positional arguments:
controller_name Name of the controller
param_file The YAML file with the controller parameters
options:
-h, --help show this help message and exit
--spin-time SPIN_TIME
Spin time in seconds to wait for discovery (only applies when not using an already running daemon)
-s, --use-sim-time Enable ROS simulation time
--set-state {inactive,active}
Set the state of the loaded controller
-c CONTROLLER_MANAGER, --controller-manager CONTROLLER_MANAGER
Name of the controller manager ROS node (default: controller_manager)
--include-hidden-nodes
Consider hidden nodes as well
--ros-args ... Pass arbitrary arguments to the executable
```
--------------------------------
### Updated on_init Signature for Hardware Interfaces
Source: https://github.com/ros-controls/ros2_control/blob/master/doc/migration.rst
Illustrates the change in the on_init method signature for hardware interfaces, from accepting HardwareInfo to HardwareComponentInterfaceParams.
```cpp
CallbackReturn on_init(const hardware_interface::HardwareInfo& info)
```
```cpp
CallbackReturn on_init(const HardwareComponentInterfaceParams& params)
```
--------------------------------
### Basic CMake Configuration
Source: https://github.com/ros-controls/ros2_control/blob/master/hardware_interface_testing/CMakeLists.txt
Sets the minimum CMake version and project name for the hardware interface testing package.
```cmake
cmake_minimum_required(VERSION 3.16)
project(hardware_interface_testing LANGUAGES CXX)
```
--------------------------------
### Add realtime group and user
Source: https://github.com/ros-controls/ros2_control/blob/master/controller_manager/doc/userdoc.rst
Configure Linux to allow users to set real-time priorities for the controller manager. This involves creating a 'realtime' group and adding the user to it.
```bash
sudo addgroup realtime
sudo usermod -a -G realtime $(whoami)
```
--------------------------------
### ROS 2 CLI Help for switch_controllers
Source: https://github.com/ros-controls/ros2_control/blob/master/ros2controlcli/doc/userdoc.rst
Provides help for the 'switch_controllers' command, explaining how to activate and deactivate multiple controllers simultaneously.
```console
$ ros2 control switch_controllers -h
usage: ros2 control switch_controllers [-h] [--spin-time SPIN_TIME] [-s] [--deactivate [DEACTIVATE ...]] [--activate [ACTIVATE ...]] [--strict] [--activate-asap] [--switch-timeout SWITCH_TIMEOUT]
[-c CONTROLLER_MANAGER] [--include-hidden-nodes] [--ros-args ...]
Switch controllers in a controller manager
options:
-h, --help show this help message and exit
--spin-time SPIN_TIME
Spin time in seconds to wait for discovery (only applies when not using an already running daemon)
-s, --use-sim-time Enable ROS simulation time
--deactivate [DEACTIVATE ...]
Name of the controllers to be deactivated
--activate [ACTIVATE ...]
Name of the controllers to be activated
--strict Strict switch
--activate-asap Start asap controllers
--switch-timeout SWITCH_TIMEOUT
Timeout for switching controllers
-c CONTROLLER_MANAGER, --controller-manager CONTROLLER_MANAGER
Name of the controller manager ROS node (default: controller_manager)
--include-hidden-nodes
Consider hidden nodes as well
--ros-args ... Pass arbitrary arguments to the executable
```
--------------------------------
### GenericSystem Mock Component Configuration
Source: https://github.com/ros-controls/ros2_control/blob/master/hardware_interface/doc/mock_components_userdoc.rst
This XML configuration sets up the GenericSystem mock component with various parameters. It defines joints with command and state interfaces, and a GPIO interface. Optional parameters like 'calculate_dynamics', 'custom_interface_with_following_offset', 'disable_commands', 'mock_gpio_commands', 'mock_sensor_commands', and 'position_state_following_offset' can be configured.
```xml
mock_components/GenericSystem
false
false
false
false
0.0
3.45
2.78
```
--------------------------------
### ROS 2 CLI Help for set_hardware_component_state
Source: https://github.com/ros-controls/ros2_control/blob/master/ros2controlcli/doc/userdoc.rst
Displays help information for the 'set_hardware_component_state' command, detailing how to adjust the state of hardware components.
```console
$ ros2 control set_hardware_component_state -h
usage: ros2 control set_hardware_component_state [-h] [--spin-time SPIN_TIME] [-s] [-c CONTROLLER_MANAGER] [--include-hidden-nodes] [--ros-args ...] hardware_component_name {unconfigured,inactive,active}
Adjust the state of the hardware component
positional arguments:
hardware_component_name
Name of the hardware_component to be changed
{unconfigured,inactive,active}
State in which the hardware component should be changed to
options:
-h, --help show this help message and exit
--spin-time SPIN_TIME
Spin time in seconds to wait for discovery (only applies when not using an already running daemon)
-s, --use-sim-time Enable ROS simulation time
-c CONTROLLER_MANAGER, --controller-manager CONTROLLER_MANAGER
Name of the controller manager ROS node (default: controller_manager)
--include-hidden-nodes
Consider hidden nodes as well
--ros-args ... Pass arbitrary arguments to the executable
```
--------------------------------
### ROS 2 Control View Controller Chains Help
Source: https://github.com/ros-controls/ros2_control/blob/master/ros2controlcli/doc/userdoc.rst
Displays help information for the 'view_controller_chains' command, used to generate a diagram of loaded chained controllers.
```console
$ ros2 control view_controller_chains -h
usage: ros2 control view_controller_chains [-h] [--spin-time SPIN_TIME] [-s] [-c CONTROLLER_MANAGER] [--include-hidden-nodes] [--ros-args ...]
Generates a diagram of the loaded chained controllers into /tmp/controller_diagram.gv.pdf
options:
-h, --help show this help message and exit
--spin-time SPIN_TIME
Spin time in seconds to wait for discovery (only applies when not using an already running daemon)
-s, --use-sim-time Enable ROS simulation time
-c CONTROLLER_MANAGER, --controller-manager CONTROLLER_MANAGER
Name of the controller manager ROS node (default: controller_manager)
--include-hidden-nodes
Consider hidden nodes as well
--ros-args ... Pass arbitrary arguments to the executable
```
--------------------------------
### List Hardware Interfaces
Source: https://github.com/ros-controls/ros2_control/blob/master/ros2controlcli/doc/userdoc.rst
Outputs the list of available command and state interfaces. Use -v to list interface data types.
```console
$ ros2 control list_hardware_interfaces -h
usage: ros2 control list_hardware_interfaces [-h] [--spin-time SPIN_TIME] [-s] [--verbose] [-c CONTROLLER_MANAGER] [--include-hidden-nodes] [--ros-args ...]
Output the list of available command and state interfaces
options:
-h, --help show this help message and exit
--spin-time SPIN_TIME
Spin time in seconds to wait for discovery (only applies when not using an already running daemon)
-s, --use-sim-time Enable ROS simulation time
--verbose, -v List hardware interfaces and their data types
-c CONTROLLER_MANAGER, --controller-manager CONTROLLER_MANAGER
Name of the controller manager ROS node (default: controller_manager)
--include-hidden-nodes
Consider hidden nodes as well
--ros-args ... Pass arbitrary arguments to the executable
```
```console
$ ros2 control list_hardware_interfaces
command interfaces
joint1/position [unclaimed]
joint2/position [unclaimed]
state interfaces
joint1/position
joint2/position
```
```console
$ ros2 control list_hardware_interfaces -v
command interfaces
joint1/position [double] [unclaimed]
joint2/position [double] [unclaimed]
state interfaces
joint1/position [double]
joint2/position [double]
```
--------------------------------
### Launch RQT Controller Manager GUI
Source: https://github.com/ros-controls/ros2_control/blob/master/controller_manager/doc/userdoc.rst
Command to launch the graphical user interface for interacting with the controller manager.
```console
ros2 run rqt_controller_manager rqt_controller_manager
```
--------------------------------
### ROS 2 CLI Help for cleanup_controller
Source: https://github.com/ros-controls/ros2_control/blob/master/ros2controlcli/doc/userdoc.rst
Shows help information for the 'cleanup_controller' command, used for cleaning up controller resources.
```console
$ ros2 control cleanup_controller -h
```
--------------------------------
### Reload Controller Libraries Command Help
Source: https://github.com/ros-controls/ros2_control/blob/master/ros2controlcli/doc/userdoc.rst
Displays help information for the reload_controller_libraries command, including options like force-kill.
```console
$ ros2 control reload_controller_libraries -h
usage: ros2 control reload_controller_libraries [-h] [--spin-time SPIN_TIME] [-s] [--force-kill] [-c CONTROLLER_MANAGER] [--include-hidden-nodes] [--ros-args ...]
Reload controller libraries
options:
-h, --help show this help message and exit
--spin-time SPIN_TIME
Spin time in seconds to wait for discovery (only applies when not using an already running daemon)
-s, --use-sim-time Enable ROS simulation time
--force-kill Force stop of loaded controllers
-c CONTROLLER_MANAGER, --controller-manager CONTROLLER_MANAGER
Name of the controller manager ROS node (default: controller_manager)
--include-hidden-nodes
Consider hidden nodes as well
--ros-args ... Pass arbitrary arguments to the executable
```
--------------------------------
### Updated init Signature for Hardware Interfaces
Source: https://github.com/ros-controls/ros2_control/blob/master/doc/migration.rst
Shows the updated signature for the init() method in hardware interfaces, changing from HardwareInfo and logger/clock to HardwareComponentParams.
```cpp
CallbackReturn init(const HardwareInfo & hardware_info, rclcpp::Logger logger, rclcpp::Clock::SharedPtr clock)
```
```cpp
CallbackReturn init(const hardware_interface::HardwareComponentParams & params)
```
--------------------------------
### Spawner Node with Parameters and ParameterFile
Source: https://github.com/ros-controls/ros2_control/blob/master/controller_manager/doc/userdoc.rst
Defines a Node for the spawner executable, using the 'parameters' argument with ParameterFile for controller configuration.
```console
Node(
package="controller_manager",
executable="spawner",
parameters=[
ParameterFile(
PathSubstitution(FindPackageShare("my_config_pkg"))
/ "config"
/ "controllers.yaml",
),
],
arguments=[
"my_controller"
],
),
```
--------------------------------
### Launch ros2_control_node with Controller Manager
Source: https://github.com/ros-controls/ros2_control/blob/master/controller_manager/doc/userdoc.rst
Python code snippet demonstrating how to launch the ros2_control_node executable, which includes the controller_manager, with specified parameters.
```python
control_node = Node(
package="controller_manager",
executable="ros2_control_node",
parameters=[robot_controllers],
output="both",
)
```
--------------------------------
### Building Test Components Library
Source: https://github.com/ros-controls/ros2_control/blob/master/hardware_interface_testing/CMakeLists.txt
Compiles the shared library for test components, linking against necessary hardware interface libraries.
```cmake
add_library(test_components SHARED
test/test_components/test_actuator.cpp
test/test_components/test_sensor.cpp
test/test_components/test_system.cpp
test/test_components/test_actuator_exclusive_interfaces.cpp)
target_link_libraries(test_components
hardware_interface::hardware_interface
rclcpp_lifecycle::rclcpp_lifecycle
ros2_control_test_assets::ros2_control_test_assets
pluginlib::pluginlib
fmt::fmt)
```
--------------------------------
### Configure Build for Debugging
Source: https://github.com/ros-controls/ros2_control/blob/master/doc/debugging.rst
Builds the ROS 2 workspace with debug information. Use RelWithDebInfo for release builds with debug symbols or Debug for full debug builds.
```bash
colcon build --cmake-args -DCMAKE_BUILD_TYPE=RelWithDebInfo
```
```bash
colcon build --cmake-args -DCMAKE_BUILD_TYPE=Debug
```
--------------------------------
### ROS 2 CLI Help for set_controller_state
Source: https://github.com/ros-controls/ros2_control/blob/master/ros2controlcli/doc/userdoc.rst
Displays help information for the 'set_controller_state' command, outlining its arguments and options for adjusting controller states.
```console
$ ros2 control set_controller_state -h
usage: ros2 control set_controller_state [-h] [--spin-time SPIN_TIME] [-s] [-c CONTROLLER_MANAGER] [--include-hidden-nodes] [--ros-args ...] controller_name {unconfigured,inactive,active}
Adjust the state of the controller
positional arguments:
controller_name Name of the controller to be changed
{unconfigured,inactive,active} State in which the controller should be changed to
options:
-h, --help show this help message and exit
--spin-time SPIN_TIME
Spin time in seconds to wait for discovery (only applies when not using an already running daemon)
-s, --use-sim-time Enable ROS simulation time
-c CONTROLLER_MANAGER, --controller-manager CONTROLLER_MANAGER
Name of the controller manager ROS node (default: controller_manager)
--include-hidden-nodes
Consider hidden nodes as well
--ros-args ... Pass arbitrary arguments to the executable
```
--------------------------------
### Spawner Help Usage
Source: https://github.com/ros-controls/ros2_control/blob/master/controller_manager/doc/userdoc.rst
Displays the help message for the 'ros2 run controller_manager spawner' command, outlining global and controller-specific options.
```console
$ ros2 run controller_manager spawner --controller -h
```
--------------------------------
### Run Docker with real-time capabilities
Source: https://github.com/ros-controls/ros2_control/blob/master/controller_manager/doc/userdoc.rst
Launch a Docker container with necessary capabilities for real-time scheduling and memory locking. This allows ros2_control to operate with low jitter within the container.
```bash
docker run -it \
--cap-add=sys_nice \
--ulimit rtprio=99 \
--ulimit memlock=-1 \
--rm --net host
```
--------------------------------
### List Hardware Components
Source: https://github.com/ros-controls/ros2_control/blob/master/ros2controlcli/doc/userdoc.rst
Lists all hardware components managed by the controller manager. Use -v for verbose output including interface data types.
```console
$ ros2 control list_hardware_components
Hardware Component 0
name: RRBot
type: system
plugin name: ros2_control_demo_hardware/RRBotSystemPositionOnlyHardware
state: id=3 label=active
command interfaces
joint2/position [available] [claimed]
joint1/position [available] [claimed]
```
```console
$ ros2 control list_hardware_components -v
Hardware Component 0
name: RRBot
type: system
plugin name: ros2_control_demo_hardware/RRBotSystemPositionOnlyHardware
state: id=3 label=active
command interfaces
joint2/position [double] [available] [claimed]
joint1/position [double] [available] [claimed]
state interfaces
joint2/position [double] [available]
joint1/position [double] [available]
```
--------------------------------
### Unspawner Command-Line Help
Source: https://github.com/ros-controls/ros2_control/blob/master/controller_manager/doc/userdoc.rst
Displays the help message for the 'unspawner' command-line tool, detailing its arguments and options for managing controllers.
```console
$ ros2 run controller_manager unspawner -h
usage: unspawner [-h] [-c CONTROLLER_MANAGER] [--switch-timeout SWITCH_TIMEOUT] controller_names [controller_names ...]
positional arguments:
controller_names Name of the controller
options:
-h, --help show this help message and exit
-c CONTROLLER_MANAGER, --controller-manager CONTROLLER_MANAGER
Name of the controller manager ROS node
--switch-timeout SWITCH_TIMEOUT
Time to wait for a successful state switch of controllers. Useful if controllers cannot be switched immediately, e.g., paused
simulations at startup
```
--------------------------------
### Setting Compiler Options and Exporting Symbols
Source: https://github.com/ros-controls/ros2_control/blob/master/hardware_interface_testing/CMakeLists.txt
Configures compiler options and exports symbols for Windows compatibility.
```cmake
set_compiler_options()
export_windows_symbols()
```
--------------------------------
### Initializing Hardware Status Message Template
Source: https://github.com/ros-controls/ros2_control/blob/master/hardware_interface/doc/writing_new_hardware_component.rst
This C++ code defines the static structure of the hardware status message during initialization. It sets the hardware ID, resizes device states, and populates static fields for each device. This method is non-realtime.
```cpp
hardware_interface::CallbackReturn MyHardware::init_hardware_status_message(
control_msgs::msg::HardwareStatus & msg)
{
msg.hardware_id = get_hardware_info().name;
msg.hardware_device_states.resize(get_hardware_info().joints.size());
for (size_t i = 0; i < get_hardware_info().joints.size(); ++i)
{
msg.hardware_device_states[i].device_id = get_hardware_info().joints[i].name;
// This example uses one generic status per joint
msg.hardware_device_states[i].generic_hardware_status.resize(1);
}
return hardware_interface::CallbackReturn::SUCCESS;
}
```
--------------------------------
### ROS 2 Control View Hardware Status Help
Source: https://github.com/ros-controls/ros2_control/blob/master/ros2controlcli/doc/userdoc.rst
Displays help information for the 'view_hardware_status' command, which echoes hardware status messages with filtering capabilities.
```console
$ ros2 control view_hardware_status -h
usage: ros2 control view_hardware_status [-h] [--spin-time SPIN_TIME] [-s] [-i HARDWARE_ID] [-d DEVICE_ID]
Echo hardware status messages with filtering capabilities
options:
-h, --help show this help message and exit
--spin-time SPIN_TIME
Spin time in seconds to wait for discovery (only applies when not using an already running daemon)
-s, --use-sim-time Enable ROS simulation time
-i HARDWARE_ID, --hardware-id HARDWARE_ID
Filter by a specific hardware component ID.
-d DEVICE_ID, --device-id DEVICE_ID
Filter by a specific device ID within a hardware component.
```
--------------------------------
### Exporting Unlisted Command Interface Descriptions
Source: https://github.com/ros-controls/ros2_control/blob/master/hardware_interface/doc/writing_new_hardware_component.rst
This C++ snippet demonstrates how to create and export unlisted command interface descriptions. Ensure that names are unique and that the created interfaces are stored internally.
```cpp
std::vector my_unlisted_interfaces;
InterfaceInfo unlisted_interface;
unlisted_interface.name = "some_unlisted_interface";
unlisted_interface.min = "-5.0";
unlisted_interface.data_type = "double";
my_unlisted_interfaces.push_back(InterfaceDescription(info_.name, unlisted_interface));
return my_unlisted_interfaces;
```
--------------------------------
### Build Specific Package with Debug Info
Source: https://github.com/ros-controls/ros2_control/blob/master/doc/debugging.rst
Builds only a specified package with debug information, useful for targeted debugging.
```bash
colcon build --packages-select [package_name] --cmake-args -DCMAKE_BUILD_TYPE=RelWithDebInfo
```
```bash
colcon build --packages-select [package_name] --cmake-args -DCMAKE_BUILD_TYPE=Debug
```