Skip to content

Commit

Permalink
[example_9] Switch to gz_ros2_control (ros-controls#482)
Browse files Browse the repository at this point in the history
* Switch from gazebo classic to gazebo

* update docs

* Use gz_ros2_control in semi-binary builds

* rm dependency conditional

Co-authored-by: Dr. Denis <[email protected]>
  • Loading branch information
christophfroehlich and destogl authored Apr 4, 2024
1 parent 02e359d commit b3a4666
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 63 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ The following examples are part of this demo repository:

*RRBot* with an exposed transmission interface.

* Example 9: ["Gazebo classic simulation"](example_9)
* Example 9: ["Gazebo simulation"](example_9)

Demonstrates how to switch between simulation and hardware.

Expand Down
2 changes: 1 addition & 1 deletion doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ Examples
Example 6: Modular robots with separate communication to each actuator <../example_6/doc/userdoc.rst>
Example 7: Full tutorial with a 6DOF robot <../example_7/doc/userdoc.rst>
Example 8: Using transmissions <../example_8/doc/userdoc.rst>
Example 9: Gazebo classic <../example_9/doc/userdoc.rst>
Example 9: Gazebo <../example_9/doc/userdoc.rst>
Example 10: Industrial robot with GPIO interfaces <../example_10/doc/userdoc.rst>
Example 11: CarlikeBot <../example_11/doc/userdoc.rst>
Example 12: Controller chaining <../example_12/doc/userdoc.rst>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,26 @@ def generate_launch_description():
# Initialize Arguments
gui = LaunchConfiguration("gui")

# gazebo
gazebo = IncludeLaunchDescription(
PythonLaunchDescriptionSource(
[PathJoinSubstitution([FindPackageShare("gazebo_ros"), "launch", "gazebo.launch.py"])]
[FindPackageShare("ros_gz_sim"), "/launch/gz_sim.launch.py"]
),
launch_arguments={"verbose": "false"}.items(),
launch_arguments={"gz_args": " -r -v 3 empty.sdf"}.items(),
)

gz_spawn_entity = Node(
package="ros_gz_sim",
executable="create",
output="screen",
arguments=[
"-topic",
"/robot_description",
"-name",
"rrbot_system_position",
"-allow_renaming",
"true",
],
)

# Get URDF via xacro
Expand All @@ -52,7 +67,7 @@ def generate_launch_description():
[FindPackageShare("ros2_control_demo_example_9"), "urdf", "rrbot.urdf.xacro"]
),
" ",
"use_gazebo_classic:=true",
"use_gazebo:=true",
]
)
robot_description = {"robot_description": robot_description_content}
Expand All @@ -67,13 +82,6 @@ def generate_launch_description():
parameters=[robot_description],
)

spawn_entity = Node(
package="gazebo_ros",
executable="spawn_entity.py",
arguments=["-topic", "robot_description", "-entity", "rrbot_system_position"],
output="screen",
)

joint_state_broadcaster_spawner = Node(
package="controller_manager",
executable="spawner",
Expand All @@ -97,7 +105,7 @@ def generate_launch_description():
nodes = [
gazebo,
node_robot_state_publisher,
spawn_entity,
gz_spawn_entity,
joint_state_broadcaster_spawner,
robot_controller_spawner,
rviz_node,
Expand Down
2 changes: 1 addition & 1 deletion example_9/description/gazebo/rrbot.gazebo.xacro
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ https://github.com/ros-simulation/gazebo_ros_demos/blob/kinetic-devel/rrbot_desc

<!-- ros_control plugin -->
<gazebo>
<plugin filename="libgazebo_ros2_control.so" name="gazebo_ros2_control">
<plugin filename="gz_ros2_control-system" name="gz_ros2_control::GazeboSimROS2ControlPlugin">
<parameters>$(find ros2_control_demo_example_9)/config/rrbot_controllers.yaml</parameters>
</plugin>
</gazebo>
Expand Down
8 changes: 4 additions & 4 deletions example_9/description/ros2_control/rrbot.ros2_control.xacro
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?xml version="1.0"?>
<robot xmlns:xacro="http://www.ros.org/wiki/xacro">

<xacro:macro name="rrbot_ros2_control" params="name prefix use_gazebo_classic:=^|false">
<xacro:macro name="rrbot_ros2_control" params="name prefix use_gazebo:=^|false">

<ros2_control name="${name}" type="system">
<hardware>
<xacro:if value="${use_gazebo_classic}">
<plugin>gazebo_ros2_control/GazeboSystem</plugin>
<xacro:if value="${use_gazebo}">
<plugin>gz_ros2_control/GazeboSimSystem</plugin>
</xacro:if>
<xacro:unless value="${use_gazebo_classic}">
<xacro:unless value="${use_gazebo}">
<plugin>ros2_control_demo_example_9/RRBotSystemPositionOnlyHardware</plugin>
<param name="example_param_hw_start_duration_sec">0</param>
<param name="example_param_hw_stop_duration_sec">3.0</param>
Expand Down
6 changes: 3 additions & 3 deletions example_9/description/urdf/rrbot.urdf.xacro
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ https://github.com/ros-simulation/gazebo_ros_demos/blob/kinetic-devel/rrbot_desc
-->
<robot xmlns:xacro="http://www.ros.org/wiki/xacro" name="2dof_robot">
<xacro:arg name="prefix" default="" />
<xacro:arg name="use_gazebo_classic" default="false" />
<xacro:arg name="use_gazebo" default="false" />

<!-- Import RRBot macro -->
<xacro:include filename="$(find ros2_control_demo_description)/rrbot/urdf/rrbot_description.urdf.xacro" />
Expand All @@ -25,9 +25,9 @@ https://github.com/ros-simulation/gazebo_ros_demos/blob/kinetic-devel/rrbot_desc
</xacro:rrbot>

<xacro:rrbot_ros2_control
name="RRBot" prefix="$(arg prefix)" use_gazebo_classic="$(arg use_gazebo_classic)"/>
name="RRBot" prefix="$(arg prefix)" use_gazebo="$(arg use_gazebo)"/>

<xacro:if value="$(arg use_gazebo_classic)">
<xacro:if value="$(arg use_gazebo)">
<!-- Import Gazebo Classic definitions + plugin -->
<xacro:include filename="$(find ros2_control_demo_example_9)/gazebo/rrbot.gazebo.xacro" />
<xacro:rrbot_gazebo prefix="$(arg prefix)"/>
Expand Down
Binary file added example_9/doc/rrbot_gazebo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed example_9/doc/rrbot_gazebo_classic.png
Binary file not shown.
48 changes: 10 additions & 38 deletions example_9/doc/userdoc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,12 @@ Example 9: Simulation with RRBot
=================================

With *example_9*, we demonstrate the interaction of simulators with ros2_control. More specifically,
Gazebo Classic is used for this purpose.
gazebo 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

.. code::
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

.. code-block:: shell
gzclient
and/or ``rviz2`` with

.. code-block:: shell
rviz2 -d src/ros2_control_demos/example_9/description/rviz/rrbot.rviz
For details on the ``gazebo_ros2_control`` plugin, see :ref:`gazebo_ros2_control`.
gazebo should be automatically installed. For details on the ``gz_ros2_control`` plugin, see :ref:`gz_ros2_control`.

Tutorial steps
--------------------------
Expand All @@ -55,24 +33,18 @@ Tutorial steps
It uses an identical hardware interface as already discussed with *example_1*, see its docs on details on the hardware interface.

3. To start *RRBot* in the simulators, open a terminal, source your ROS2-workspace and Gazebo Classic installation first, i.e., by

.. code-block:: shell
source /usr/share/gazebo/setup.sh
Then, execute the launch file with
3. To start *RRBot* in the simulators, open a terminal, source your ROS2-workspace first. Then, execute the launch file with

.. code-block:: shell
ros2 launch ros2_control_demo_example_9 rrbot_gazebo_classic.launch.py gui:=true
ros2 launch ros2_control_demo_example_9 rrbot_gazebo.launch.py gui:=true
The 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.
The launch file loads the robot description, starts gazebo, *Joint State Broadcaster* and *Forward Command Controller*.
If you can see two orange and one yellow "box" in gazebo everything has started properly.

.. image:: rrbot_gazebo_classic.png
.. image:: rrbot_gazebo.png
:width: 400
:alt: Revolute-Revolute Manipulator Robot in Gazebo Classic
:alt: Revolute-Revolute Manipulator Robot in gazebo

4. Check if the hardware interface loaded properly, by opening another terminal and executing

Expand Down Expand Up @@ -118,7 +90,7 @@ Tutorial steps
ros2 launch ros2_control_demo_example_9 test_forward_position_controller.launch.py
You should now see the robot moving in Gazebo Classic.
You should now see the robot moving in gazebo.

If you echo the ``/joint_states`` or ``/dynamic_joint_states`` topics you should see the changing values,
namely the simulated states of the robot
Expand All @@ -135,7 +107,7 @@ Files used for this demos
- Launch files:

+ Hardware: `rrbot.launch.py <https://github.com/ros-controls/ros2_control_demos/tree/{REPOS_FILE_BRANCH}/example_9/bringup/launch/rrbot.launch.py>`__
+ Gazebo Classic: `rrbot_gazebo_classic.launch.py <https://github.com/ros-controls/ros2_control_demos/tree/{REPOS_FILE_BRANCH}/example_9/bringup/launch/rrbot_gazebo_classic.launch.py>`__
+ gazebo: `rrbot_gazebo.launch.py <https://github.com/ros-controls/ros2_control_demos/tree/{REPOS_FILE_BRANCH}/example_9/bringup/launch/rrbot_gazebo.launch.py>`__

- Controllers yaml: `rrbot_controllers.yaml <https://github.com/ros-controls/ros2_control_demos/tree/{REPOS_FILE_BRANCH}/example_9/bringup/config/rrbot_controllers.yaml>`__
- URDF file: `rrbot.urdf.xacro <https://github.com/ros-controls/ros2_control_demos/tree/{REPOS_FILE_BRANCH}/example_9/description/urdf/rrbot.urdf.xacro>`__
Expand Down
4 changes: 2 additions & 2 deletions example_9/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@

<exec_depend>controller_manager</exec_depend>
<exec_depend>forward_command_controller</exec_depend>
<exec_depend>gazebo_ros</exec_depend>
<exec_depend>gazebo_ros2_control</exec_depend>
<exec_depend>ros_gz_sim</exec_depend>
<exec_depend>gz_ros2_control</exec_depend>
<exec_depend>joint_state_broadcaster</exec_depend>
<exec_depend>joint_state_publisher_gui</exec_depend>
<exec_depend>joint_trajectory_controller</exec_depend>
Expand Down
4 changes: 2 additions & 2 deletions ros2_control_demos.rolling.repos
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ repositories:
type: git
url: https://github.com/ros-controls/ros2_controllers.git
version: master
gazebo_ros2_control:
gz_ros2_control:
type: git
url: https://github.com/ros-controls/gazebo_ros2_control.git
url: https://github.com/ros-controls/gz_ros2_control.git
version: master

0 comments on commit b3a4666

Please sign in to comment.