Skip to content

Commit 1ce8524

Browse files
[Example 4] Moving and Restructuring (#236)
Co-authored-by: Dr. Denis <[email protected]>
1 parent f10597e commit 1ce8524

20 files changed

+1412
-58
lines changed

README.md

Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,6 @@ 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.
7875

7976
##### Example 3
8077

@@ -97,6 +94,14 @@ These are some quick hints, especially for those coming from a ROS1 control back
9794
* Joint names in <ros2_control> tags in the URDF must be compatible with the controller's configuration.
9895

9996

97+
##### Example 4: "Industrial robot with integrated sensor"
98+
*RRBot* - or ''Revolute-Revolute Manipulator Robot'' - a simple position controlled robot with an integrated sensor.
99+
100+
101+
##### Example 5: "Industrial Robots with externally connected sensor"
102+
*RRBot* - or ''Revolute-Revolute Manipulator Robot'' - a simple position controlled robot with an externally connected sensor.
103+
104+
100105
## Build status
101106

102107
ROS2 Distro | Branch | Build status | Documentation
@@ -255,37 +260,6 @@ Available launch file options:
255260

256261

257262

258-
### Example 3: "Industrial robot with integrated sensor"
259-
260-
- Launch file: [rrbot_system_with_sensor.launch.py](ros2_control_demo_bringup/launch/rrbot_system_with_sensor.launch.py)
261-
- Controllers: [rrbot_with_sensor_controllers.yaml](ros2_control_demo_bringup/config/rrbot_with_sensor_controllers.yaml)
262-
- URDF: [rrbot_system_with_sensor.urdf.xacro](ros2_control_demo_description/rrbot_description/urdf/rrbot_system_with_sensor.urdf.xacro)
263-
- ros2_control URDF: [rrbot_system_with_sensor.ros2_control.xacro](ros2_control_demo_description/rrbot_description/ros2_control/rrbot_system_with_sensor.ros2_control.xacro)
264-
265-
- Command interfaces:
266-
- joint1/position
267-
- joint2/position
268-
- State interfaces:
269-
- joint1/position
270-
- joint2/position
271-
- tcp_fts_sensor/force.x
272-
- tcp_fts_sensor/torque.z
273-
274-
Available controllers:
275-
- `forward_position_controller[forward_command_controller/ForwardCommandController]`
276-
- `fts_broadcaster[force_torque_sensor_broadcaster/ForceTorqueSensorBroadcaster]`
277-
- `joint_state_broadcaster[joint_state_broadcaster/JointStateBroadcaster]`
278-
279-
Notes:
280-
- Wrench messages are may not be displayed properly in Rviz as NaN values are not handled in Rviz and FTS Broadcaster may send NaN values.
281-
282-
Commanding the robot: see the commands below.
283-
284-
Accessing Wrench data from 2D FTS:
285-
```
286-
ros2 topic echo /fts_broadcaster/wrench
287-
```
288-
289263

290264
### Example 5: "Modular Robots with separate communication to each actuator"
291265

example_4/CMakeLists.txt

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
cmake_minimum_required(VERSION 3.5)
2+
project(ros2_control_demo_example_4)
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/rrbot_system_with_sensor.cpp
33+
)
34+
target_include_directories(
35+
${PROJECT_NAME}
36+
PRIVATE
37+
hardware/include
38+
)
39+
ament_target_dependencies(
40+
${PROJECT_NAME}
41+
${THIS_PACKAGE_INCLUDE_DEPENDS}
42+
)
43+
44+
# Causes the visibility macros to use dllexport rather than dllimport,
45+
# which is appropriate when building the dll but not consuming it.
46+
target_compile_definitions(${PROJECT_NAME} PRIVATE "ROS2_CONTROL_DEMO_EXAMPLE_4_BUILDING_DLL")
47+
48+
# Export hardware plugins
49+
pluginlib_export_plugin_description_file(hardware_interface ros2_control_demo_example_4.xml)
50+
51+
# INSTALL
52+
install(
53+
TARGETS ${PROJECT_NAME}
54+
DESTINATION lib
55+
)
56+
install(
57+
DIRECTORY hardware/include/
58+
DESTINATION include
59+
)
60+
install(
61+
DIRECTORY description/launch description/ros2_control description/urdf description/rviz description/meshes
62+
DESTINATION share/${PROJECT_NAME}
63+
)
64+
install(
65+
DIRECTORY bringup/launch bringup/config
66+
DESTINATION share/${PROJECT_NAME}
67+
)
68+
69+
if(BUILD_TESTING)
70+
find_package(ament_cmake_gtest REQUIRED)
71+
endif()
72+
73+
## EXPORTS
74+
ament_export_include_directories(
75+
include
76+
)
77+
ament_export_libraries(
78+
${PROJECT_NAME}
79+
)
80+
ament_export_dependencies(
81+
${THIS_PACKAGE_INCLUDE_DEPENDS}
82+
)
83+
ament_package()

example_4/README.rst

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