ROS 2 Lyrical lab 08 · 2–3 hours
ros2_control and diagnostics
Connect a simulated arm to controller_manager, command a trajectory and record evidence.
Practice this lab in your browser: Controller lifecycleUnderstand before building
How this part of ROS 2 works
ros2_control separates application commands, controllers, and hardware interfaces. controller_manager coordinates lifecycle and update execution.
A controller must be configured, active, and connected to the correct claimed interfaces before a trajectory can affect simulated state.
Before you start
- Lab 07 complete
- Industrial Robots access for model-specific work
Files you will touch
src/training_arm_description/urdf/training_arm.ros2_control.xacrosrc/training_arm_bringup/config/controllers.yaml
Step 1
Set up
sudo apt install ros-lyrical-ros2-control ros-lyrical-ros2-controllers
ros2 control list_hardware_interfaces
ros2 control list_controllersStep 2
Create the file
<!-- Include this block inside the robot description. -->
<ros2_control name="TrainingArm" type="system">
<hardware><plugin>mock_components/GenericSystem</plugin></hardware>
<joint name="joint_1">
<command_interface name="position"/>
<state_interface name="position"/>
<state_interface name="velocity"/>
</joint>
</ros2_control>
# controllers.yaml
controller_manager:
ros__parameters:
update_rate: 100
joint_state_broadcaster:
type: joint_state_broadcaster/JointStateBroadcaster
arm_controller:
type: joint_trajectory_controller/JointTrajectoryController
arm_controller:
ros__parameters:
joints: [joint_1]
command_interfaces: [position]
state_interfaces: [position, velocity]What each part does
- 1.controller_manager runs at the configured update rate and loads two controller plugins.
- 2.The broadcaster publishes state; the trajectory controller claims command interfaces for motion.
Step 3
Build, run and inspect
ros2 run controller_manager spawner joint_state_broadcaster
ros2 run controller_manager spawner arm_controller
ros2 control list_controllers
ros2 bag record /joint_states /arm_controller/controller_stateProof that it works
- Both controllers report active
- Command and state interfaces are claimed correctly
- The bag records joint state and controller state topics
Recovery notes
- Use mock hardware until stop, limit and recovery behavior are proven.
- A robot_description change requires restarting controller_manager; live URDF reload is not supported.