Skip to content

Commit 69e8efe

Browse files
[Example 5] Moving and Restructuring (#237)
Co-authored-by: Dr. Denis <[email protected]>
1 parent bcd5e51 commit 69e8efe

25 files changed

+1784
-62
lines changed

README.md

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ Check README file inside each example folder for detailed description.
7272
*DiffBot*, or ''Differential Mobile Robot'', is a simple mobile base with differential drive.
7373
The robot is basically a box moving according to differential drive kinematics.
7474

75+
##### Example 5: "Industrial Robots with externally connected sensor"
76+
*RRBot* - or ''Revolute-Revolute Manipulator Robot'' - a simple position controlled robot
77+
with an externally connected sensor.
7578

7679
##### Example 3
7780

@@ -284,41 +287,6 @@ ros2 topic echo /fts_broadcaster/wrench
284287
```
285288

286289

287-
### Example 4: "Industrial Robots with externally connected sensor"
288-
289-
- Launch file: [rrbot_system_with_external_sensor.launch.py](ros2_control_demo_bringup/launch/rrbot_system_with_external_sensor.launch.py)
290-
- Controllers: [rrbot_with_external_sensor_controllers.yaml](ros2_control_demo_bringup/config/rrbot_with_external_sensor_controllers.yaml)
291-
- URDF: [rrbot_with_external_sensor_controllers.urdf.xacro](ros2_control_demo_description/rrbot_description/urdf/rrbot_with_external_sensor_controllers.urdf.xacro)
292-
- ros2_control URDF:
293-
- robot: [rrbot_system_position_only.ros2_control.xacro](ros2_control_demo_description/rrbot_description/ros2_control/rrbot_system_position_only.ros2_control.xacro)
294-
- sensor: [external_rrbot_force_torque_sensor.ros2_control.xacro](ros2_control_demo_description/rrbot_description/ros2_control/external_rrbot_force_torque_sensor.ros2_control.xacro)
295-
296-
- Command interfaces:
297-
- joint1/position
298-
- joint2/position
299-
- State interfaces:
300-
- joint1/position
301-
- joint2/position
302-
- tcp_fts_sensor/force.x
303-
- tcp_fts_sensor/force.y
304-
- tcp_fts_sensor/force.z
305-
- tcp_fts_sensor/torque.x
306-
- tcp_fts_sensor/torque.y
307-
- tcp_fts_sensor/torque.z
308-
309-
Available controllers:
310-
- `forward_position_controller[forward_command_controller/ForwardCommandController]`
311-
- `fts_broadcaster[force_torque_sensor_broadcaster/ForceTorqueSensorBroadcaster]`
312-
- `joint_state_broadcaster[joint_state_broadcaster/JointStateBroadcaster]`
313-
314-
Commanding the robot: see the commands below.
315-
316-
Accessing Wrench data from 2D FTS:
317-
```
318-
ros2 topic echo /fts_broadcaster/wrench
319-
```
320-
321-
322290
### Example 5: "Modular Robots with separate communication to each actuator"
323291

324292
- Launch file: [rrbot_modular_actuators.launch.py](ros2_control_demo_bringup/launch/rrbot_modular_actuators.launch.py)

example_5/CMakeLists.txt

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
cmake_minimum_required(VERSION 3.5)
2+
project(ros2_control_demo_example_5)
3+
4+
# Default to C++14
5+
if(NOT CMAKE_CXX_STANDARD)
6+
set(CMAKE_CXX_STANDARD 14)
7+
endif()
8+
9+
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
10+
add_compile_options(-Wall -Wextra)
11+
endif()
12+
13+
# find dependencies
14+
set(THIS_PACKAGE_INCLUDE_DEPENDS
15+
hardware_interface
16+
pluginlib
17+
rclcpp
18+
rclcpp_lifecycle
19+
)
20+
21+
# find dependencies
22+
find_package(ament_cmake REQUIRED)
23+
foreach(Dependency IN ITEMS ${THIS_PACKAGE_INCLUDE_DEPENDS})
24+
find_package(${Dependency} REQUIRED)
25+
endforeach()
26+
27+
28+
## COMPILE
29+
add_library(
30+
${PROJECT_NAME}
31+
SHARED
32+
hardware/external_rrbot_force_torque_sensor.cpp
33+
hardware/rrbot.cpp
34+
)
35+
target_include_directories(
36+
${PROJECT_NAME}
37+
PRIVATE
38+
hardware/include
39+
)
40+
ament_target_dependencies(
41+
${PROJECT_NAME}
42+
${THIS_PACKAGE_INCLUDE_DEPENDS}
43+
)
44+
45+
# Causes the visibility macros to use dllexport rather than dllimport,
46+
# which is appropriate when building the dll but not consuming it.
47+
target_compile_definitions(${PROJECT_NAME} PRIVATE "ROS2_CONTROL_DEMO_EXAMPLE_5_BUILDING_DLL")
48+
49+
# Export hardware plugins
50+
pluginlib_export_plugin_description_file(hardware_interface ros2_control_demo_example_5.xml)
51+
52+
# INSTALL
53+
install(
54+
TARGETS ${PROJECT_NAME}
55+
DESTINATION lib
56+
)
57+
install(
58+
DIRECTORY hardware/include/
59+
DESTINATION include
60+
)
61+
install(
62+
DIRECTORY description/launch description/ros2_control description/urdf description/rviz description/meshes
63+
DESTINATION share/${PROJECT_NAME}
64+
)
65+
install(
66+
DIRECTORY bringup/launch bringup/config
67+
DESTINATION share/${PROJECT_NAME}
68+
)
69+
70+
if(BUILD_TESTING)
71+
find_package(ament_cmake_gtest REQUIRED)
72+
endif()
73+
74+
## EXPORTS
75+
ament_export_include_directories(
76+
include
77+
)
78+
ament_export_libraries(
79+
${PROJECT_NAME}
80+
)
81+
ament_export_dependencies(
82+
${THIS_PACKAGE_INCLUDE_DEPENDS}
83+
)
84+
ament_package()

example_5/README.rst

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
*************************************************************
2+
Example 5: Industrial robot with externally connected sensor
3+
*************************************************************
4+
5+
This example shows how an externally connected sensor can be accessed via a hardware interface of
6+
type ``hardware_interface::SensorInterface``: A 3D Force-Torque Sensor (FTS) is simulated by
7+
generating random sensor readings.
8+
9+
1. To check that *RRBot* descriptions are working properly use following launch commands
10+
11+
.. code-block:: shell
12+
13+
ros2 launch ros2_control_demo_example_5 view_robot.launch.py
14+
15+
**NOTE**: Getting the following output in terminal is OK: ``Warning: Invalid frame ID "odom" passed to canTransform argument target_frame - frame does not exist``.
16+
This happens because ``joint_state_publisher_gui`` node need some time to start.
17+
The ``joint_state_publisher_gui`` provides a GUI to generate a random configuration for rrbot. It is immediately displayed in *RViz*.
18+
19+
20+
2. To start *RRBot* example open a terminal, source your ROS2-workspace and execute its launch file with
21+
22+
.. code-block:: shell
23+
24+
ros2 launch ros2_control_demo_example_5 rrbot_system_with_external_sensor.launch.py
25+
26+
The launch file loads and starts the robot hardware, controllers and opens *RViz*.
27+
In starting terminal you will see a lot of output from the hardware implementation showing its internal states.
28+
This is only of exemplary purposes and should be avoided as much as possible in a hardware interface implementation.
29+
30+
If you can see two orange and one yellow rectangle in in *RViz* everything has started properly.
31+
Still, to be sure, let's introspect the control system before moving *RRBot*.
32+
33+
3. Check if the hardware interface loaded properly, by opening another terminal and executing
34+
35+
.. code-block:: shell
36+
37+
ros2 control list_hardware_interfaces
38+
39+
.. code-block:: shell
40+
41+
command interfaces
42+
joint1/position [available] [claimed]
43+
joint2/position [available] [claimed]
44+
state interfaces
45+
joint1/position
46+
joint2/position
47+
tcp_fts_sensor/force.x
48+
tcp_fts_sensor/force.y
49+
tcp_fts_sensor/force.z
50+
tcp_fts_sensor/torque.x
51+
tcp_fts_sensor/torque.y
52+
53+
Marker ``[claimed]`` by command interfaces means that a controller has access to command *RRBot*.
54+
55+
4. Check is controllers are running
56+
57+
.. code-block:: shell
58+
59+
ros2 control list_controllers
60+
61+
.. code-block:: shell
62+
63+
forward_position_controller[forward_command_controller/ForwardCommandController] active
64+
fts_broadcaster[force_torque_sensor_broadcaster/ForceTorqueSensorBroadcaster] active
65+
joint_state_broadcaster[joint_state_broadcaster/JointStateBroadcaster] active
66+
67+
5. If you get output from above you can send commands to *Forward Command Controller*, either:
68+
69+
#. Manually using ros2 cli interface.
70+
71+
.. code-block:: shell
72+
73+
ros2 topic pub /forward_position_controller/commands std_msgs/msg/Float64MultiArray "data:
74+
- 0.5
75+
- 0.5"
76+
77+
#. Or you can start a demo node which sends two goals every 5 seconds in a loop
78+
79+
.. code-block:: shell
80+
81+
ros2 launch ros2_control_demo_example_5 test_forward_position_controller.launch.py
82+
83+
You should now see orange and yellow blocks moving in *RViz*.
84+
Also, you should see changing states in the terminal where launch file is started, e.g.
85+
86+
.. code-block:: shell
87+
88+
[RRBotSystemPositionOnlyHardware]: Got command 0.50000 for joint 0!
89+
[RRBotSystemPositionOnlyHardware]: Got command 0.50000 for joint 1!
90+
91+
6. Access wrench data from 2D FTS via
92+
93+
.. code-block:: shell
94+
95+
ros2 topic echo /fts_broadcaster/wrench
96+
97+
shows the random generated sensor values, republished by *Force Torque Sensor Broadcaster* as
98+
``geometry_msgs/msg/WrenchStamped`` message
99+
100+
.. code-block:: shell
101+
102+
header:
103+
stamp:
104+
sec: 1676444704
105+
nanosec: 332221422
106+
frame_id: tool_link
107+
wrench:
108+
force:
109+
x: 1.2126582860946655
110+
y: 2.3202226161956787
111+
z: 3.4302282333374023
112+
torque:
113+
x: 4.540233612060547
114+
y: 0.647800624370575
115+
z: 1.7602499723434448
116+
117+
Wrench data are also visualized in *RViz*:
118+
119+
.. image:: doc/rrbot_wrench.png
120+
:width: 400
121+
:alt: Revolute-Revolute Manipulator Robot with wrench visualization
122+
123+
Files used for this demos
124+
#########################
125+
126+
- Launch file: `rrbot_system_with_external_sensor.launch.py <https://github.com/ros-controls/ros2_control_demos/example_5/bringup/launch/rrbot_system_with_external_sensor.launch.py>`__
127+
- Controllers yaml: `rrbot_with_external_sensor_controllers.yaml <https://github.com/ros-controls/ros2_control_demos/example_5/bringup/config/rrbot_with_external_sensor_controllers.yaml>`__
128+
- URDF: `rrbot_with_external_sensor_controllers.urdf.xacro <https://github.com/ros-controls/ros2_control_demos/example_5/description/urdf/rrbot_with_external_sensor_controllers.urdf.xacro>`__
129+
130+
+ ``ros2_control`` robot: `rrbot_system_position_only.ros2_control.xacro <https://github.com/ros-controls/ros2_control_demos/example_5/description/ros2_control/rrbot_system_position_only.ros2_control.xacro>`__
131+
+ ``ros2_control`` sensor: `external_rrbot_force_torque_sensor.ros2_control.xacro <https://github.com/ros-controls/ros2_control_demos/example_5/description/ros2_control/external_rrbot_force_torque_sensor.ros2_control.xacro>`__
132+
133+
- RViz configuration: `rrbot.rviz <https://github.com/ros-controls/ros2_control_demos/example_4/description/rviz/rrbot.rviz>`__
134+
- Hardware interface plugin:
135+
136+
+ robot `rrbot.cpp <https://github.com/ros-controls/ros2_control_demos/example_5/hardware/rrbot.cpp>`__
137+
+ sensor `external_rrbot_force_torque_sensor.cpp <https://github.com/ros-controls/ros2_control_demos/example_5/hardware/external_rrbot_force_torque_sensor.cpp>`__
138+
139+
Controllers from this demo
140+
##########################
141+
- ``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>`__
142+
- ``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>`__
143+
- ``Force Torque Sensor Broadcaster`` (`ros2_controllers repository <https://github.com/ros-controls/ros2_controllers>`__): `doc <https://control.ros.org/master/doc/ros2_controllers/force_torque_sensor_broadcaster/doc/userdoc.html>`__
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
publisher_forward_position_controller:
2+
ros__parameters:
3+
4+
wait_sec_between_publish: 5
5+
publish_topic: /forward_position_controller/commands
6+
7+
goal_names: ["pos1", "pos2", "pos3", "pos4"]
8+
pos1: [0.785, 0.785]
9+
pos2: [0, 0]
10+
pos3: [-0.785, -0.785]
11+
pos4: [0, 0]

0 commit comments

Comments
 (0)