You're reading the documentation for a development version. For the latest released version, please have a look at Iron.
Example 6: Modular Robots with separate communication to each actuator
The example shows how to implement robot hardware with separate communication to each actuator:
The communication is done on actuator level using proprietary or standardized API (e.g., canopen_402, Modbus, RS232, RS485).
Data for all actuators is exchanged separately from each other.
Examples: Mara, Arduino-based-robots
This is implemented with a hardware interface of type hardware_interface::ActuatorInterface
.
Note
The commands below are given for a local installation of this repository and its dependencies as well as for running them from a docker container. For more information on the docker usage see Using Docker.
Tutorial steps
To check that RRBot descriptions are working properly use following launch commands
ros2 launch ros2_control_demo_example_6 view_robot.launch.py
Note
Getting the following output in terminal is OK:
Warning: Invalid frame ID "odom" passed to canTransform argument target_frame - frame does not exist
. This happens becausejoint_state_publisher_gui
node need some time to start. Thejoint_state_publisher_gui
provides a GUI to generate a random configuration for rrbot. It is immediately displayed in RViz.To start RRBot example open a terminal, source your ROS2-workspace and execute its launch file with
ros2 launch ros2_control_demo_example_6 rrbot_modular_actuators.launch.py
The launch file loads and starts the robot hardware, controllers and opens RViz. In starting terminal you will see a lot of output from the hardware implementation showing its internal states. This is only of exemplary purposes and should be avoided as much as possible in a hardware interface implementation.
If you can see two orange and one yellow rectangle in in RViz everything has started properly. Still, to be sure, let’s introspect the control system before moving RRBot.
Check if the hardware interface loaded properly, by opening another terminal and executing
ros2 control list_hardware_interfaces
command interfaces joint1/position [available] [claimed] joint2/position [available] [claimed] state interfaces joint1/position joint2/position
Marker
[claimed]
by command interfaces means that a controller has access to command RRBot.Now, let’s introspect the hardware components with
ros2 control list_hardware_components
There are two hardware components, one for each actuator and one for each sensor:
Hardware Component 1 name: RRBotModularJoint2 type: actuator plugin name: ros2_control_demo_example_6/RRBotModularJoint state: id=3 label=active command interfaces joint2/position [available] [claimed] Hardware Component 2 name: RRBotModularJoint1 type: actuator plugin name: ros2_control_demo_example_6/RRBotModularJoint state: id=3 label=active command interfaces joint1/position [available] [claimed]
Check if controllers are running
ros2 control list_controllers
forward_position_controller[forward_command_controller/ForwardCommandController] active joint_state_broadcaster[joint_state_broadcaster/JointStateBroadcaster] active
If you get output from above you can send commands to Forward Command Controller, either:
Manually using ROS 2 CLI interface.
ros2 topic pub /forward_position_controller/commands std_msgs/msg/Float64MultiArray "data: - 0.5 - 0.5"
Or you can start a demo node which sends two goals every 5 seconds in a loop
ros2 launch ros2_control_demo_example_6 test_forward_position_controller.launch.py
You should now see orange and yellow blocks moving in RViz. Also, you should see changing states in the terminal where launch file is started, e.g.
[ros2_control_node-1] [INFO] [1721764663.304187517] [controller_manager.resource_manager.hardware_component.actuator.RRBotModularJoint1]: Writing commands: [ros2_control_node-1] 0.50 for joint 'joint1' [ros2_control_node-1] [INFO] [1721764663.304196897] [controller_manager.resource_manager.hardware_component.actuator.RRBotModularJoint2]: Writing commands: [ros2_control_node-1] 0.50 for joint 'joint2'
Files used for this demos
Launch file: rrbot_modular_actuators.launch.py
Controllers yaml: rrbot_modular_actuators.yaml
URDF: rrbot_modular_actuators.urdf.xacro
Description: rrbot_description.urdf.xacro
ros2_control
URDF tag: rrbot_modular_actuators.ros2_control.xacro
RViz configuration: rrbot.rviz
Hardware interface plugin: rrbot_actuator.cpp
Controllers from this demo
Joint State Broadcaster
(ros2_controllers repository): docForward Command Controller
(ros2_controllers repository): doc