Skip to content

Commit

Permalink
Restructuring for example_1 (#234)
Browse files Browse the repository at this point in the history
* First compilable version

* Fix wrong paths

* Fix rst

* Update copyright

Co-authored-by: Dr. Denis <denis@stoglrobotics.de>

* Restructure cmakelists

* Add maintainer

* Cleanup old paths

* Update Dr. Denis' Email and add him as author.

* Update maintainer

* Use test_nodes from ros2_controllers

* Fix trailing whitespaces

* Fix rviz display

* Add image to readme

---------

Co-authored-by: Dr. Denis <denis@stoglrobotics.de>
  • Loading branch information
christophfroehlich and destogl committed Mar 8, 2023
1 parent 0572d28 commit 7902db1
Show file tree
Hide file tree
Showing 20 changed files with 469 additions and 212 deletions.
45 changes: 27 additions & 18 deletions example_1/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.5)
project(ros2_control_demo_hardware)
project(ros2_control_demo_example_1)

# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
Expand All @@ -10,12 +10,19 @@ if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra)
endif()

# find dependencies
set(THIS_PACKAGE_INCLUDE_DEPENDS
hardware_interface
pluginlib
rclcpp
rclcpp_lifecycle
)

# find dependencies
find_package(ament_cmake REQUIRED)
find_package(hardware_interface REQUIRED)
find_package(pluginlib REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rclcpp_lifecycle REQUIRED)
foreach(Dependency IN ITEMS ${THIS_PACKAGE_INCLUDE_DEPENDS})
find_package(${Dependency} REQUIRED)
endforeach()


## COMPILE
Expand All @@ -27,32 +34,37 @@ add_library(
target_include_directories(
${PROJECT_NAME}
PRIVATE
include
hardware/include
)
ament_target_dependencies(
${PROJECT_NAME}
hardware_interface
pluginlib
rclcpp
rclcpp_lifecycle
${THIS_PACKAGE_INCLUDE_DEPENDS}
)

# Causes the visibility macros to use dllexport rather than dllimport,
# which is appropriate when building the dll but not consuming it.
target_compile_definitions(${PROJECT_NAME} PRIVATE "ROS2_CONTROL_DEMO_HARDWARE_BUILDING_DLL")
target_compile_definitions(${PROJECT_NAME} PRIVATE "ROS2_CONTROL_DEMO_EXAMPLE_1_BUILDING_DLL")

# Export hardware pligins
pluginlib_export_plugin_description_file(hardware_interface ros2_control_demo_hardware.xml)
# Export hardware plugins
pluginlib_export_plugin_description_file(hardware_interface ros2_control_demo_example_1.xml)

# INSTALL
install(
TARGETS ${PROJECT_NAME}
DESTINATION lib
)
install(
DIRECTORY include/
DIRECTORY hardware/include/
DESTINATION include
)
install(
DIRECTORY description/launch description/ros2_control description/urdf description/rviz description/meshes
DESTINATION share/${PROJECT_NAME}
)
install(
DIRECTORY bringup/launch bringup/config
DESTINATION share/${PROJECT_NAME}
)

if(BUILD_TESTING)
find_package(ament_cmake_gtest REQUIRED)
Expand All @@ -66,9 +78,6 @@ ament_export_libraries(
${PROJECT_NAME}
)
ament_export_dependencies(
hardware_interface
pluginlib
rclcpp
rclcpp_lifecycle
${THIS_PACKAGE_INCLUDE_DEPENDS}
)
ament_package()
151 changes: 81 additions & 70 deletions example_1/README.rst
Original file line number Diff line number Diff line change
@@ -1,98 +1,109 @@


TODO(destogl): This is not adjusted yet!!
****************
Example 1: RRBot
****************


*RRBot*, or ''Revolute-Revolute Manipulator Robot'', is a simple 3-linkage, 2-joint arm that we will use to demonstrate various features.
It is essentially a double inverted pendulum and demonstrates some fun control concepts within a simulator and was originally introduced for Gazebo tutorials.
The *RRBot* URDF files can be found in the ``urdf`` folder of ``rrbot_description`` package.
The *RRBot* URDF files can be found in the ``description/urdf`` folder.

1. To check that *RRBot* descriptions are working properly use following launch commands

.. code-block:: shell
1. To check that *RRBot* descriptions are working properly use following launch commands:
ros2 launch ros2_control_demo_example_1 view_robot.launch.py
*RRBot*
```
ros2 launch rrbot_description 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 because ``joint_state_publisher_gui`` node need some time to start.
The ``joint_state_publisher_gui`` provides a GUI to generate a random configuration for rrbot. It is immediately displayed in ``Rviz``.
The ``joint_state_publisher_gui`` provides a GUI to change the configuration for rrbot. It is immediately displayed in *RViz*.

.. image:: doc/rrbot.png
:width: 400
:alt: Revolute-Revolute Manipulator Robot

1. To check that *RRBot* descriptions are working properly use following launch commands:

*RRBot*
```
ros2 launch rrbot_description 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 because ``joint_state_publisher_gui`` node need some time to start.
The ``joint_state_publisher_gui`` provides a GUI to generate a random configuration for rrbot. It is immediately displayed in ``Rviz``.
2. To start *RRBot* example open a terminal, source your ROS2-workspace and execute its launch file with

.. code-block:: shell
1. To start *RRBot* example open a terminal, source your ROS2-workspace and execute its launch file with:
```
ros2 launch ros2_control_demo_bringup rrbot.launch.py
```
The launch file loads and starts the robot hardware, controllers and opens ``RViz``.
ros2 launch ros2_control_demo_example_1 rrbot.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.
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*.

1. Check if the hardware interface loaded properly, by opening another terminal and executing:
```
ros2 control list_hardware_interfaces
```
3. Check if the hardware interface loaded properly, by opening another terminal and executing

.. code-block:: shell
You should get::
ros2 control list_hardware_interfaces
.. code-block:: shell
command interfaces
joint1/position [claimed]
joint2/position [claimed]
joint1/position [available] [claimed]
joint2/position [available] [claimed]
state interfaces
joint1/position
joint2/position
joint1/position
joint2/position
Marker ``[claimed]`` by command interfaces means that a controller has access to command *RRBot*.

1. Check is controllers are running:
```
ros2 control list_controllers
```
You should get:
```
joint_state_broadcaster[joint_state_broadcaster/JointStateBroadcaster] active
forward_position_controller[forward_command_controller/ForwardCommandController] active
```
4. Check is controllers are running by

.. code-block:: shell
ros2 control list_controllers
.. code-block:: shell
1. If you get output from above you can send commands to *Forward Command Controller*, either:
joint_state_broadcaster[joint_state_broadcaster/JointStateBroadcaster] active
forward_position_controller[forward_command_controller/ForwardCommandController] active
5. If you get output from above you can send commands to *Forward Command Controller*, either:

a. Manually using ros2 cli interface:
```
ros2 topic pub /position_commands std_msgs/msg/Float64MultiArray "data:
- 0.5
- 0.5"
```
B. Or you can start a demo node which sends two goals every 5 seconds in a loop:
```
ros2 launch ros2_control_demo_bringup 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.


Files used for this demos:
- Launch file: [rrbot.launch.py](ros2_control_demo_bringup/launch/rrbot.launch.py)
- Controllers yaml: [rrbot_controllers.yaml](ros2_control_demo_bringup/config/rrbot_controllers.yaml)
- URDF file: [rrbot.urdf.xacro](ros2_control_demo_description/rrbot_description/urdf/rrbot.urdf.xacro)
- Description: [rrbot_description.urdf.xacro](ros2_control_demo_description/rrbot_description/urdf/rrbot_description.urdf.xacro)
- `ros2_control` tag: [rrbot.ros2_control.xacro](ros2_control_demo_description/rrbot_description/ros2_control/rrbot.ros2_control.xacro)
- RViz configuration: [rrbot.rviz](ros2_control_demo_description/rrbot_description/config/rrbot.rviz)

- Hardware interface plugin: [rrbot_system_position_only.cpp](ros2_control_demo_hardware/src/rrbot_system_position_only.cpp)


Controllers from this demo:
- ``Joint State Broadcaster`` ([``ros2_controllers`` repository](https://github.com/ros-controls/ros2_controllers)): [doc](https://ros-controls.github.io/control.ros.org/ros2_controllers/joint_state_broadcaster/doc/userdoc.html)
- ``Forward Command Controller`` ([``ros2_controllers`` repository](https://github.com/ros-controls/ros2_controllers)): [doc](https://ros-controls.github.io/control.ros.org/ros2_controllers/forward_command_controller/doc/userdoc.html)

.. code-block:: shell
ros2 topic pub /position_commands std_msgs/msg/Float64MultiArray "data:
- 0.5
- 0.5"
B. Or you can start a demo node which sends two goals every 5 seconds in a loop

.. code-block:: shell
ros2 launch ros2_control_demo_example_1 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.

.. code-block:: shell
[RRBotSystemPositionOnlyHardware]: Got command 0.50000 for joint 0!
[RRBotSystemPositionOnlyHardware]: Got command 0.50000 for joint 1!
Files used for this demos
#########################

- Launch file: `rrbot.launch.py <bringup/launch/rrbot.launch.py>`__
- Controllers yaml: `rrbot_controllers.yaml <bringup/config/rrbot_controllers.yaml>`__
- URDF file: `rrbot.urdf.xacro <description/urdf/rrbot.urdf.xacro>`__

+ Description: `rrbot_description.urdf.xacro <description/urdf/rrbot_description.urdf.xacro>`__
+ ``ros2_control`` tag: `rrbot.ros2_control.xacro <description/ros2_control/rrbot.ros2_control.xacro>`__

- RViz configuration: `rrbot.rviz <description/rviz/rrbot.rviz>`__

- Hardware interface plugin: `rrbot.cpp <hardware/rrbot.cpp>`__


Controllers from this demo
##########################
- ``Joint State Broadcaster`` (`ros2_controllers repository <https://github.com/ros-controls/ros2_controllers>`__): `doc <https://control.ros.org/master/doc/ros2_controllers/joint_state_broadcaster/doc/userdoc.html>`__
- ``Forward Command Controller`` (`ros2_controllers repository <https://github.com/ros-controls/ros2_controllers>`__): `doc <https://control.ros.org/master/doc/ros2_controllers/forward_command_controller/doc/userdoc.html>`__
11 changes: 11 additions & 0 deletions example_1/bringup/config/rrbot_forward_position_publisher.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
publisher_forward_position_controller:
ros__parameters:

wait_sec_between_publish: 5
publish_topic: "/forward_position_controller/commands"

goal_names: ["pos1", "pos2", "pos3", "pos4"]
pos1: [0.785, 0.785]
pos2: [0, 0]
pos3: [-0.785, -0.785]
pos4: [0, 0]
12 changes: 3 additions & 9 deletions example_1/bringup/launch/rrbot.launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def generate_launch_description():
" ",
PathJoinSubstitution(
[
FindPackageShare("rrbot_description"),
FindPackageShare("ros2_control_demo_example_1"),
"urdf",
"rrbot.urdf.xacro",
]
Expand All @@ -41,25 +41,19 @@ def generate_launch_description():

robot_controllers = PathJoinSubstitution(
[
FindPackageShare("ros2_control_demo_bringup"),
FindPackageShare("ros2_control_demo_example_1"),
"config",
"rrbot_controllers.yaml",
]
)
rviz_config_file = PathJoinSubstitution(
[FindPackageShare("rrbot_description"), "config", "rrbot.rviz"]
[FindPackageShare("ros2_control_demo_example_1"), "rviz", "rrbot.rviz"]
)

control_node = Node(
package="controller_manager",
executable="ros2_control_node",
parameters=[robot_description, robot_controllers],
remappings=[
(
"/forward_position_controller/commands",
"/position_commands",
),
],
output="both",
)
robot_state_pub_node = Node(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def generate_launch_description():

position_goals = PathJoinSubstitution(
[
FindPackageShare("ros2_control_demo_bringup"),
FindPackageShare("ros2_control_demo_example_1"),
"config",
"rrbot_forward_position_publisher.yaml",
]
Expand All @@ -31,7 +31,7 @@ def generate_launch_description():
return LaunchDescription(
[
Node(
package="ros2_control_test_nodes",
package="ros2_controllers_test_nodes",
executable="publisher_forward_position_controller",
name="publisher_forward_position_controller",
parameters=[position_goals],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def generate_launch_description():
declared_arguments.append(
DeclareLaunchArgument(
"description_package",
default_value="rrbot_description",
default_value="ros2_control_demo_example_1",
description="Description package with robot URDF/xacro files. Usually the argument \
is not set, it enables use of a custom description.",
)
Expand Down Expand Up @@ -69,7 +69,7 @@ def generate_launch_description():
robot_description = {"robot_description": robot_description_content}

rviz_config_file = PathJoinSubstitution(
[FindPackageShare(description_package), "config", "rrbot.rviz"]
[FindPackageShare(description_package), "rviz", "rrbot.rviz"]
)

joint_state_publisher_node = Node(
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<ros2_control name="${name}" type="system">
<hardware>
<plugin>ros2_control_demo_hardware/RRBotSystemPositionOnlyHardware</plugin>
<plugin>ros2_control_demo_example_1/RRBotSystemPositionOnlyHardware</plugin>
<param name="example_param_hw_start_duration_sec">0</param>
<param name="example_param_hw_stop_duration_sec">3.0</param>
<param name="example_param_hw_slowdown">100</param>
Expand Down
Loading

0 comments on commit 7902db1

Please sign in to comment.