Skip to content

Commit 19e10f0

Browse files
[Example 6] Moving and Restructuring (#238)
Co-authored-by: Dr. Denis <[email protected]>
1 parent 1ce8524 commit 19e10f0

21 files changed

+1360
-56
lines changed

README.md

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ The robot is basically a box moving according to differential drive kinematics.
7777

7878
*RRBot* - or ''Revolute-Revolute Manipulator Robot'' with multiple interfaces
7979

80+
##### Example 6: "Modular Robots with separate communication to each actuator"
81+
82+
The example shows how to implement robot hardware with separate communication to each actuator.
83+
8084
## Quick Hints
8185

8286
These are some quick hints, especially for those coming from a ROS1 control background:
@@ -261,27 +265,6 @@ Available launch file options:
261265

262266

263267

264-
### Example 5: "Modular Robots with separate communication to each actuator"
265-
266-
- Launch file: [rrbot_modular_actuators.launch.py](ros2_control_demo_bringup/launch/rrbot_modular_actuators.launch.py)
267-
- Controllers: [rrbot_modular_actuators.yaml](ros2_control_demo_bringup/config/rrbot_modular_actuators.yaml)
268-
- URDF: [rrbot_modular_actuators.urdf.xacro](ros2_control_demo_description/rrbot_description/urdf/rrbot_modular_actuators.urdf.xacro)
269-
- ros2_control URDF: [rrbot_modular_actuators.ros2_control.xacro](ros2_control_demo_description/rrbot_description/ros2_control/rrbot_modular_actuators.ros2_control.xacro)
270-
271-
- Command interfaces:
272-
- joint1/position
273-
- joint2/position
274-
- State interfaces:
275-
- joint1/position
276-
- joint2/position
277-
278-
Available controllers:
279-
- `forward_position_controller[forward_command_controller/ForwardCommandController]`
280-
- `joint_state_broadcaster[joint_state_broadcaster/JointStateBroadcaster]`
281-
282-
Commanding the robot: see the commands below.
283-
284-
285268
### Example 6: "Industrial Robots with an exposed transmission interface"
286269

287270
Files:

example_6/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_6)
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_actuator.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_6_BUILDING_DLL")
47+
48+
# Export hardware plugins
49+
pluginlib_export_plugin_description_file(hardware_interface ros2_control_demo_example_6.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_6/README.rst

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
***********************************************************************
2+
Example 6: Modular Robots with separate communication to each actuator
3+
***********************************************************************
4+
5+
The example shows how to implement robot hardware with separate communication to each actuator. This
6+
is implemented with a hardware interface of type ``hardware_interface::ActuatorInterface``.
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_6 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_6 rrbot.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+
47+
Marker ``[claimed]`` by command interfaces means that a controller has access to command *RRBot*.
48+
49+
4. Check is controllers are running
50+
51+
.. code-block:: shell
52+
53+
ros2 control list_controllers
54+
55+
.. code-block:: shell
56+
57+
forward_position_controller[forward_command_controller/ForwardCommandController]
58+
joint_state_broadcaster[joint_state_broadcaster/JointStateBroadcaster]
59+
60+
5. If you get output from above you can send commands to *Forward Command Controller*, either:
61+
62+
#. Manually using ros2 cli interface.
63+
64+
.. code-block:: shell
65+
66+
ros2 topic pub /forward_position_controller/commands std_msgs/msg/Float64MultiArray "data:
67+
- 0.5
68+
- 0.5"
69+
70+
#. Or you can start a demo node which sends two goals every 5 seconds in a loop
71+
72+
.. code-block:: shell
73+
74+
ros2 launch ros2_control_demo_example_6 test_forward_position_controller.launch.py
75+
76+
You should now see orange and yellow blocks moving in *RViz*.
77+
Also, you should see changing states in the terminal where launch file is started, e.g.
78+
79+
.. code-block:: shell
80+
81+
[RRBotModularJoint]: Writing...please wait...
82+
[RRBotModularJoint]: Got command 0.50000 for joint 'joint1'!
83+
[RRBotModularJoint]: Joints successfully written!
84+
[RRBotModularJoint]: Writing...please wait...
85+
[RRBotModularJoint]: Got command 0.50000 for joint 'joint2'!
86+
[RRBotModularJoint]: Joints successfully written!
87+
88+
89+
Files used for this demos
90+
#########################
91+
92+
- Launch file: `rrbot_modular_actuators.launch.py <https://github.com/ros-controls/ros2_control_demos/example_6/bringup/launch/rrbot_modular_actuators.launch.py>`__
93+
- Controllers yaml: `rrbot_modular_actuators.yaml <https://github.com/ros-controls/ros2_control_demos/example_6/bringup/config/rrbot_modular_actuators.yaml>`__
94+
- URDF: `rrbot_modular_actuators.urdf.xacro <https://github.com/ros-controls/ros2_control_demos/example_6/description/urdf/rrbot_modular_actuators.urdf.xacro>`__
95+
96+
+ ``ros2_control`` URDF tag: `rrbot_modular_actuators.ros2_control.xacro <https://github.com/ros-controls/ros2_control_demos/example_6/description/ros2_control/rrbot_modular_actuators.ros2_control.xacro>`__
97+
98+
- RViz configuration: `rrbot.rviz <https://github.com/ros-controls/ros2_control_demos/example_6/description/rviz/rrbot.rviz>`__
99+
100+
- Hardware interface plugin: `rrbot_modular_actuators.cpp <https://github.com/ros-controls/ros2_control_demos/example_6/hardware/rrbot_modular_actuators.cpp>`__
101+
102+
Controllers from this demo
103+
##########################
104+
- ``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>`__
105+
- ``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>`__
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)