layout: true
--- class: center, middle name: main_title # ROS2_CONTROL ### From joint states to motion After this session you can explain where the joint states come from, choose a controller, inspect and switch controllers with the CLI and the rqt tools, and run the same setup on mock or real hardware. --- ## Joint states and commands
- You have seen two sources of `/joint_states`: the `joint_state_publisher_gui` sliders, and the **robot bringup** (move the robot with the teach pendant, and the TFs move in RViz) - **States:** in the bringup, the `joint_state_broadcaster` publishes the positions read from the hardware. Check: `ros2 topic info /joint_states -v` - **Commands:** go the other way, through a controller to the hardware. With the teach pendant, you moved the robot *without* this path --- class: dense ## Architecture
- **Hardware components** (plugins) give access to the hardware through **state** and **command interfaces**, e.g. `joint1/position` - **Controllers** (plugins) read state interfaces and write command interfaces. ROS topics and actions are their outside view - The **controller manager** runs everything in one real-time loop: read the hardware, update the controllers, write the hardware --- class: dense, small-code ## The controller manager The node `/controller_manager` (executable `ros2_control_node`) is the centre of ros2_control: - Gets the URDF from the `/robot_description` **topic** ([`std_msgs/msg/String`](https://github.com/ros2/common_interfaces/blob/jazzy/std_msgs/msg/String.msg), transient local), published by `robot_state_publisher` - Reads its `
` tags and **loads the hardware** plugins. Only **once**: restart it after changing the URDF - Runs the **loop** read → update → write at `update_rate` - **Manages the controllers:** load, configure, activate, deactivate; one owner per command interface - Offers **services** (`list_controllers`, `load_controller`, `configure_controller`, `switch_controller`, `list_hardware_interfaces`, `set_hardware_component_state`, ...): `ros2 control`, `rqt_controller_manager` and the `spawner` are their clients - Can **limit commands** to the URDF limits: `enforce_command_limits`, off by default .cols[ .fifty[ ```yaml controller_manager: ros__parameters: update_rate: 500 # [Hz] joint_state_broadcaster: type: joint_state_broadcaster/JointStateBroadcaster scaled_joint_trajectory_controller: type: ur_controllers/ScaledJointTrajectoryController forward_position_controller: type: position_controllers/JointGroupPositionController ``` ] .fifty[ ```python # launch file Node(package="controller_manager", executable="ros2_control_node", parameters=["ros2_controllers.yaml"]) # spawner: load from the YAML file, then activate Node(package="controller_manager", executable="spawner", arguments=["joint_state_broadcaster", "scaled_joint_trajectory_controller"]) Node(package="controller_manager", executable="spawner", arguments=["forward_position_controller", "--inactive"]) ``` ] ] --- class: dense, small-code ## The `
` tag .cols[ .sixty[ ```xml
mock_components/GenericSystem
my_robot_driver/MyRobotHardware
$(arg robot_ip)
0.0
``` ] .forty[ - Part of the robot's URDF: the bringup adds it to the cell description (URDF deck) - `type`: `system` (several joints), `actuator` (one joint) or `sensor` - `
`: **which hardware**. The joints and interfaces stay the same - Each `command_interface` and `state_interface` becomes an interface in `ros2 control list_hardware_interfaces` - The vendor's xacro usually provides this tag, with a `use_mock_hardware` argument ] ] .note[Workshop examples (private: [ROS-Industrial-Session-Robots](https://github.com/ROS-Industrial-Session-Robots)): Cartesian robot ([mock](https://github.com/ROS-Industrial-Session-Robots/cartesian_robot_tutorial_cell/blob/ros2/cartesian_robot_moveit_config/config/cartesian_robot.ros2_control.xacro) · [Gazebo](https://github.com/ROS-Industrial-Session-Robots/cartesian_robot_tutorial_cell/blob/ros2/cartesian_robot_simulation_gz/urdf/cartesian_urdf_gz_sim.xacro)) · [GP50](https://github.com/ROS-Industrial-Session-Robots/motoman_gp50_cell/blob/ros2/gp50_moveit_config/config/motoman_gp50.ros2_control.xacro) (mock or real) · [UR5e cell](https://github.com/ROS-Industrial-Session-Robots/simple_ur_cell/blob/ros2/simple_ur_cell_bringup/urdf/simple_ur_cell_controlled.urdf.xacro), using [UR's tag](https://github.com/UniversalRobots/Universal_Robots_ROS2_Driver/blob/jazzy/ur_robot_driver/urdf/ur.ros2_control.xacro) (public) · [two FR3](https://github.com/ROS-Industrial-Session-Robots/dual_fr3_cell/blob/ros2/dual_fr3_cell_moveit_config/config/dual_fr3_cell.ros2_control.xacro) (mock)] --- class: dense ## Mocked, simulated or real hardware | | Mock | Simulation | Real | |---|---|---|---| | Plugin | `mock_components/GenericSystem` | `gz_ros2_control/GazeboSimSystem` | The robot's driver, e.g.
UR: `ur_robot_driver/URPositionHardwareInterface`
FR3: `franka_hardware/FrankaHardwareInterface` | | Behaviour | The state copies the command at once: no dynamics, no errors | Physics: dynamics, contacts, sensors | The real robot: tracking errors, limits, safety |
- **Same controllers, same YAML file**: only the `
` changes, usually with a launch argument such as `use_mock_hardware:=true` - Some vendors also provide a **simulator of their robot controller**, which the real driver connects to (e.g. URSim for Universal Robots) - Our cells: mock bringups for the UR5e, FR3, GP50 and Piper H cells; real drivers for the UR5e and the GP50 --- class: dense ## Standard controllers (ros2_controllers) | Group | Controllers | Use | |---|---|---| | **Broadcasters** (read only) | `joint_state_broadcaster`, `force_torque_sensor_broadcaster`, `imu_sensor_broadcaster`, `pose_broadcaster`, `range_sensor_broadcaster`, `gps_sensor_broadcaster`, `battery_state_broadcaster`, `state_interfaces_broadcaster` | Publish state interfaces as ROS messages | | **Joints, arms** | `joint_trajectory_controller` | Planned motion: trajectories, tolerances | | | `position_controllers`, `velocity_controllers`, `effort_controllers` (forward command) | Stream one value per joint | | | `pid_controller`, `admittance_controller` | Closed loop on a value, force-guided motion | | **Grippers** | `parallel_gripper_controller`, `gripper_controllers` | Open, close, hold with a maximum effort | | **Mobile bases** | `diff_drive_controller`, `mecanum_drive_controller`, `omni_wheel_drive_controller`, `tricycle_controller`, Ackermann and bicycle steering | Velocity commands → wheels, odometry | | **Other** | `gpio_controllers`, `chained_filter_controller`, `motion_primitives_controllers` | I/O, filtering, motion primitives |
- Vendors add their own, e.g. UR: `scaled_joint_trajectory_controller`, freedrive, force mode - Installed on your computer: `ros2 control list_controller_types` --- class: dense, small-code ## The joint trajectory controller .cols[ .fifty[ - **Input**: the action `
/follow_joint_trajectory` ([`FollowJointTrajectory`](https://github.com/ros-controls/control_msgs/blob/jazzy/control_msgs/action/FollowJointTrajectory.action): feedback and result), or the topic `
/joint_trajectory` ([`JointTrajectory`](https://github.com/ros2/common_interfaces/blob/jazzy/trajectory_msgs/msg/JointTrajectory.msg)) - **Interpolates** from the current state through the points ([`JointTrajectoryPoint`](https://github.com/ros2/common_interfaces/blob/jazzy/trajectory_msgs/msg/JointTrajectoryPoint.msg)): linear with positions only, cubic with velocities, quintic with accelerations - **No velocity, acceleration or jerk limits:** the sender chooses the timing - **Tolerances**: deviation along the path, at the goal, and the time allowed to reach the goal. A violation aborts the goal with an error code - **Command interface**: `position` (our cells), or `velocity` / `effort` with PID `gains` - A new goal preempts the running one (not configurable). A goal must contain all the joints, unless `allow_partial_joints_goal` ] .fifty[ ```yaml scaled_joint_trajectory_controller: ros__parameters: joints: [shoulder_pan_joint, shoulder_lift_joint, elbow_joint, wrist_1_joint, wrist_2_joint, wrist_3_joint] command_interfaces: [position] state_interfaces: [position, velocity] allow_partial_joints_goal: false constraints: stopped_velocity_tolerance: 0.2 goal_time: 5.0 # [s] shoulder_pan_joint: {trajectory: 0.4, goal: 0.2} # [rad] # ... one line per joint ``` From the UR5e cell (`simple_ur_cell_bringup/config/ros2_controllers.yaml`) ] ] --- class: dense ## Which controller when? | | Joint trajectory | Forward command | Gripper action | |---|---|---|---| | Message type | action [`FollowJointTrajectory`](https://github.com/ros-controls/control_msgs/blob/jazzy/control_msgs/action/FollowJointTrajectory.action), topic [`JointTrajectory`](https://github.com/ros2/common_interfaces/blob/jazzy/trajectory_msgs/msg/JointTrajectory.msg) | topic [`Float64MultiArray`](https://github.com/ros2/common_interfaces/blob/jazzy/std_msgs/msg/Float64MultiArray.msg) | action [`GripperCommand`](https://github.com/ros-controls/control_msgs/blob/jazzy/control_msgs/action/GripperCommand.action) or [`ParallelGripperCommand`](https://github.com/ros-controls/control_msgs/blob/jazzy/control_msgs/action/ParallelGripperCommand.action) | | You send | Points over time, with joint names | One value per joint, in the controller's joint order | A target position and maximum effort | | Between two commands | Interpolates | Holds the last value (position: jumps there; velocity: keeps moving) | Moves there, stops when blocked | | Checks | Tolerances, result code | None | Reached or stalled | | Typical use | Point-to-point and planned motions | Small steps streamed at a high rate: servoing, teleoperation with a setpoint generator, learned policies | Open and close, pick and place | .note["Controller" in ros2_control means a plugin that uses the interfaces: the forward command controller only passes values through, without feedback.]
- Several controllers can be loaded for the same joints, but only **one at a time** can be active on a command interface - Broadcasters only read: any number of them can run next to the commanding controllers - **A forward command controller does not smooth or limit anything:** the sender must produce close, smooth setpoints --- class: dense, small-code ## Controller lifecycle and claiming
| State | Meaning | |---|---| | unconfigured | Loaded: the plugin exists in the controller manager, its parameters are not read yet | | inactive | Configured: parameters read, topics and actions created. It claims and commands nothing | | active | Runs in every cycle of the loop and owns its command interfaces |
- A command interface has **at most one** active owner: activating a second controller for it fails, so **switch** - State interfaces are not claimed: any number of controllers can read them --- class: dense ## The command line: `ros2 control` | Command | Shows or does | |---|---| | `list_hardware_components` | Hardware plugins and their state: mock or real driver? | | `list_hardware_interfaces` | Command and state interfaces, `[claimed]` or not | | `list_controllers` (`-v`) | Controllers, type, state (`-v`: claimed interfaces, update rate) | | `list_controller_types` | Controller plugins installed on the computer | | `load_controller` / `unload_controller` | Load a controller defined in the YAML file (`--set-state inactive` or `active`) | | `set_controller_state` | `inactive` ↔ `active` | | `switch_controllers --deactivate A --activate B` | Swap two controllers in one step | | `cleanup_controller` | Back to unconfigured | | `set_hardware_component_state` | Start or stop a hardware component | | `view_controller_chains` | Diagram of the controllers and interfaces (`--save`: PDF) |
Also useful: `ros2 topic info /joint_states -v`, `ros2 action list`, PlotJuggler on `/joint_states` --- class: dense ## rqt tools .cols[ .thirty[ #### rqt_controller_manager *(screenshot to come)* - The controllers and their state - Activate, deactivate (right click) - `ros2 run rqt_controller_manager rqt_controller_manager` ] .thirty[ #### rqt_joint_trajectory_controller *(screenshot to come)* - Choose a controller, enable it, move the joints with sliders - Sends trajectories to the joint trajectory controller - `ros2 run rqt_joint_trajectory_controller rqt_joint_trajectory_controller` ] .thirty[ #### rqt_reconfigure *(screenshot to come)* - Change node parameters while they run - The joint trajectory controller **re-reads** its changeable parameters: tolerances, `allow_partial_joints_goal`, ... - Read-only ones (`joints`, interfaces) need a reload - `ros2 run rqt_reconfigure rqt_reconfigure` ] ] --- class: dense, small-code ## Commanding from code .cols[ .sixty[ Action: a trajectory goal ```python client = ActionClient(node, FollowJointTrajectory, "/scaled_joint_trajectory_controller/follow_joint_trajectory") goal = FollowJointTrajectory.Goal() goal.trajectory.joint_names = UR_JOINTS goal.trajectory.points = [JointTrajectoryPoint( positions=[0.0, -1.57, 1.57, -1.57, -1.57, 0.0], velocities=[0.0] * 6, time_from_start=Duration(seconds=3.0).to_msg())] future = client.send_goal_async(goal) # accepted? then wait for the result ``` Topic: a forward command (the controller must be active) ```bash ros2 topic pub --once /forward_position_controller/commands \ std_msgs/msg/Float64MultiArray "{data: [1.0, -1.57, 1.57, -1.57, -1.57, 0.0]}" ``` ] .forty[ - One trajectory point is enough: the controller interpolates from the current position - `error_code` 0 means success. A negative code says which check failed - `/joint_states` lists the joints in its own order: always read the `name` field - With a forward command controller, the robot **jumps**: on a real robot, a large step can cause a violent motion or a protective stop: stream small steps only ] ] .note[Exercise: [ros2_control_python_capabilities_demo](https://github.com/ROS-Industrial-Session-B/ros2_control_python_capabilities_demo) with the UR5e cell, mock and real ([exercise draft](https://github.com/ROS-Industrial-Session-B/root_project_session_B/blob/main/exercices/02_ros2_control/ros2_control.md), session B) · more examples: [ros2_control demos](../../../_source/control/01_Example.html) (workshop: ROS 2 Control)]