Tools & simulation · topic G3 · 35 hours
ros2_control & hardware interfaces
This is the only interface between your algorithms and the motors. Without a hardware_interface your controllers stay trapped in simulation; written correctly, the same controllers swap arms, motors, and buses.
What to learn
- Four-layer structure: controller_manager → controller → resource manager → hardware interface (SystemInterface); you must know exactly what runs in the real-time thread
- Lifecycle callbacks: on_init / on_configure / on_activate / read() / write(); configure failures must exit gracefully
- Real-time discipline: read()/write() run in the real-time thread — no memory allocation, no printing, no waiting; a single printf can drag 1 kHz down to 300 Hz
- Controller choices: joint_state_broadcaster, joint_trajectory_controller, forward_command_controller, diff_drive_controller
- The ros2_control tag in URDF + xacro macros: a joint's command_interface (position/velocity/effort) and state_interface must match the drives
- Three things in a real driver: bus read/write (CAN/EtherCAT), status-code mapping, error recovery and enable sequencing
- Cycle management: update_rate, overrun counters, communication jitter compensation (use timestamps, never «assume this tick took exactly 1 ms»)
The lesson · plain words
ros2_control is «the standardized socket between controllers and hardware»: controllers only compute, hardware interfaces only read and write, and the two connect through a uniform protocol. It is the software foundation of productizing a robot.
One tick, three things: read→update→write
Each control cycle does three things: read (sample state from hardware) → update (all active controllers compute one round) → write (send commands to hardware). Drag the frequency in the figure: the per-tick budget and the actual occupancy of the three segments are laid out plainly.
The discipline of choosing a frequency: leave 20% headroom per tick (D10's mindset); if 500 Hz is not being met, do not reach for 1 kHz — «a high frequency you cannot meet» equals dropped ticks and hiccups.
Interactive figure · drag it and see
Hardware interfaces: three layers of abstraction
hardware_interface (what to read and write: position/velocity/effort/temperature), controller_manager (load/activate/switch controllers), controller (the algorithm itself). Write only the first and your driver composes with any controller.
This is the value of the «socket»: swap an EtherCAT drive and the controller changes not a line; swap the control algorithm and the hardware layer changes not a line. Product-level replaceability rests entirely on this layer.
Controller chain and jtc/gripper
Common controllers: JointTrajectoryController (receives trajectories, servo-level), ForwardCommandController (pass-through commands), gripper controllers (grippers), diff_drive_controller (bases). The chained usage: MoveIt sends a trajectory → JTC executes it smoothly → the hardware interface dispatches.
Sim and real hardware unified: controller_manager on the gz plugin is simulation, on your EtherCAT driver it is the real robot — controller code unchanged. This is ros2_control's biggest engineering dividend.
How deep to go
Write ros2_control YAML (controller chain + rates + interface mapping); implement a simple hardware_interface (serial or virtual); explain the controller_manager lifecycle. With that you can build an arm or base control stack from zero.
Three questions — do you really get it?
1. What is the order of the three things in one ros2_control tick?
- Aupdate→read→write
- Bwrite→read→update
- Cread→update→write
Show answer
C. Read the freshest state first, then compute, then send commands. Get the order wrong and the control phase is wrong.
2. What is the engineering value of the hardware abstraction layer?
- AIt runs faster
- BLess code to write
- CControllers and hardware decouple; both sides are independently replaceable
Show answer
C. A uniform interface makes «sim ↔ real robot» and «drive A ↔ B» zero-cost switches.
3. What is the correct basis for choosing a control frequency?
- AThe higher the better
- BCopy whatever others use
- CThe highest frequency with 20% headroom under actual per-tick occupancy
Show answer
C. An unmet frequency drops ticks. Headroom thinking is universal real-time discipline (D10).
Keep going deeper
Links without a marker stay on this site; the rest point to the Chinese edition until its translation batch lands.
How it fails in the field
- printf debugging inside write(): the stdout lock drags a 1 kHz loop to 300 Hz, and you blame the algorithm for being heavy
- Hammering the position interface: the drive already has an internal position loop, your layer integrates on top, the two loops fight, the whole machine sways at low frequency
- Communication failure without setting an error code: the joint is stuck, the upper layer keeps sending targets, and it finally slams into the limit
You have learned enough when
The Chinese edition carries the full topic page for ros2_control & hardware interfaces, including the complete outline, depth requirements per career track, and further derivations: robotguide.dev/k/G3/.