github_url: | https://github.com/ros-controls/ros2_control_demos/blob/{REPOS_FILE_BRANCH}/example_9/doc/userdoc.rst |
---|
With example_9, we demonstrate the interaction of simulators with ros2_control. More specifically, Gazebo Classic is used for this purpose.
Note
Follow the installation instructions on :ref:`ros2_control_demos_install` how to install all dependencies, Gazebo Classic should be automatically installed.
If you have installed and compiled this repository locally, you can directly use the commands below.
If you have installed it via the provided docker image: To run the first two steps of this example (without Gazebo Classic), use the commands as described with :ref:`ros2_control_demos_install`. To run the later steps using Gazebo Classic, execute
docker run -it --rm --name ros2_control_demos --net host ros2_control_demos ros2 launch ros2_control_demo_example_9 rrbot_gazebo_classic.launch.py gui:=false
first. Then on your local machine you can run the Gazebo Classic client with
gzclient
and/or
rviz2
withrviz2 -d src/ros2_control_demos/example_9/description/rviz/rrbot.rviz
For details on the gazebo_ros2_control
plugin, see :ref:`gazebo_ros2_control`.
To check that RRBot descriptions are working properly use following launch commands
ros2 launch ros2_control_demo_example_9 view_robot.launch.py
The
joint_state_publisher_gui
provides a GUI to change the configuration for RRbot. It is immediately displayed in RViz.To start RRBot with the hardware interface instead of the simulators, open a terminal, source your ROS2-workspace and execute its launch file with
ros2 launch ros2_control_demo_example_9 rrbot.launch.py
It uses an identical hardware interface as already discussed with example_1, see its docs on details on the hardware interface.
To start RRBot in the simulators, open a terminal, source your ROS2-workspace and Gazebo Classic installation first, i.e., by
source /usr/share/gazebo/setup.sh
Then, execute the launch file with
ros2 launch ros2_control_demo_example_9 rrbot_gazebo_classic.launch.py gui:=trueThe launch file loads the robot description, starts Gazebo Classic, Joint State Broadcaster and Forward Command Controller. If you can see two orange and one yellow "box" in Gazebo Classic everything has started properly.
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.Check if controllers are running by
ros2 control list_controllers
joint_state_broadcaster[joint_state_broadcaster/JointStateBroadcaster] active forward_position_controller[forward_command_controller/ForwardCommandController] 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_9 test_forward_position_controller.launch.py
You should now see the robot moving in Gazebo Classic.
If you echo the
/joint_states
or/dynamic_joint_states
topics you should see the changing values, namely the simulated states of the robotros2 topic echo /joint_states ros2 topic echo /dynamic_joint_states
- Launch files:
- Hardware: rrbot.launch.py
- Gazebo Classic: rrbot_gazebo_classic.launch.py
- Controllers yaml: rrbot_controllers.yaml
- URDF file: rrbot.urdf.xacro
- Description: rrbot_description.urdf.xacro
ros2_control
tag: rrbot.ros2_control.xacro
- RViz configuration: rrbot.rviz
- Test nodes goals configuration:
- Hardware interface plugin: rrbot.cpp
Joint State Broadcaster
(ros2_controllers repository): :ref:`doc <joint_state_broadcaster_userdoc>`Forward Command Controller
(ros2_controllers repository): :ref:`doc <forward_command_controller_userdoc>`