Skip to content

Commit 90fac3d

Browse files
christophfroehlichdestogljackcenter
authored
[Example 14] Modular robot with actuators not providing states (ros-controls#334)
Co-authored-by: Denis Štogl <[email protected]> Co-authored-by: Jack <[email protected]> Co-authored-by: Dr. Denis <[email protected]>
1 parent 07a897f commit 90fac3d

23 files changed

+1518
-4
lines changed

.github/workflows/ci-coverage-build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ jobs:
3636
ros2_control_demo_example_9
3737
ros2_control_demo_example_10
3838
ros2_control_demo_example_12
39+
ros2_control_demo_example_14
3940

4041
vcs-repo-file-url: |
4142
https://raw.githubusercontent.com/${{ github.repository }}/${{ github.sha }}/ros2_control_demos-not-released.${{ env.ROS_DISTRO }}.repos?token=${{ secrets.GITHUB_TOKEN }}

.github/workflows/ci-ros-lint.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ jobs:
3131
ros2_control_demo_example_9
3232
ros2_control_demo_example_10
3333
ros2_control_demo_example_12
34+
ros2_control_demo_example_14
3435

3536
ament_lint_100:
3637
name: ament_${{ matrix.linter }}
@@ -58,3 +59,4 @@ jobs:
5859
ros2_control_demo_example_8
5960
ros2_control_demo_example_9
6061
ros2_control_demo_example_12
62+
ros2_control_demo_example_14

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ The following examples are part of this demo repository:
6363

6464
* Example 13: "Multi-robot example (tba.)"
6565

66+
* Example 14: ["Modular robots with actuators not providing states and with additional sensors"](example_14)
67+
6668
## Getting started
6769

6870
The repository is structured into `example_XY` folders that fully contained packages with names `ros2_control_demos_example_XY`.

doc/index.rst

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ Example 3: "RRBot with multiple interfaces"
5252
Example 4: "Industrial robot with integrated sensor"
5353
*RRBot* with an integrated sensor.
5454

55-
Example 5: "Industrial Robots with externally connected sensor"
55+
Example 5: "Industrial robot with externally connected sensor"
5656
*RRBot* with an externally connected sensor.
5757

58-
Example 6: "Modular Robots with separate communication to each actuator"
58+
Example 6: "Modular robot with separate communication to each actuator"
5959
The example shows how to implement robot hardware with separate communication to each actuator.
6060

6161
Example 7: "6-DOF robot"
@@ -70,9 +70,16 @@ Example 9: "Gazebo Classic"
7070
Example 10: "GPIO interfaces"
7171
Industrial robot with GPIO interfaces
7272

73+
Example 11: "Car-like robot using steering controller library (tba.)"
74+
7375
Example 12: "Controller chaining"
7476
The example shows a simple chainable controller and its integration to form a controller chain to control the joints of *RRBot*.
7577

78+
Example 13: "Multi-robot example (tba.)"
79+
80+
Example 14: "Modular robots with actuators not providing states and with additional sensors"
81+
82+
7683
.. _ros2_control_demos_install:
7784

7885
=====================
@@ -264,3 +271,4 @@ Examples
264271
Example 9: Gazebo classic <../example_9/doc/userdoc.rst>
265272
Example 10: Industrial robot with GPIO interfaces <../example_10/doc/userdoc.rst>
266273
Example 12: Controller chaining <../example_12/doc/userdoc.rst>
274+
Example 14: Modular robots with actuators not providing states <../example_14/doc/userdoc.rst>

example_14/CMakeLists.txt

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
cmake_minimum_required(VERSION 3.16)
2+
project(ros2_control_demo_example_14 LANGUAGES CXX)
3+
4+
if(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang)")
5+
add_compile_options(-Wall -Wextra)
6+
endif()
7+
8+
# find dependencies
9+
set(THIS_PACKAGE_INCLUDE_DEPENDS
10+
hardware_interface
11+
pluginlib
12+
rclcpp
13+
rclcpp_lifecycle
14+
realtime_tools
15+
)
16+
17+
# find dependencies
18+
find_package(ament_cmake REQUIRED)
19+
foreach(Dependency IN ITEMS ${THIS_PACKAGE_INCLUDE_DEPENDS})
20+
find_package(${Dependency} REQUIRED)
21+
endforeach()
22+
23+
24+
## COMPILE
25+
add_library(
26+
ros2_control_demo_example_14
27+
SHARED
28+
hardware/rrbot_actuator_without_feedback.cpp
29+
hardware/rrbot_sensor_for_position_feedback.cpp
30+
)
31+
target_compile_features(ros2_control_demo_example_14 PUBLIC cxx_std_17)
32+
target_include_directories(ros2_control_demo_example_14 PUBLIC
33+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/hardware/include>
34+
$<INSTALL_INTERFACE:include/ros2_control_demo_example_14>
35+
)
36+
ament_target_dependencies(
37+
ros2_control_demo_example_14 PUBLIC
38+
${THIS_PACKAGE_INCLUDE_DEPENDS}
39+
)
40+
41+
# Causes the visibility macros to use dllexport rather than dllimport,
42+
# which is appropriate when building the dll but not consuming it.
43+
target_compile_definitions(${PROJECT_NAME} PRIVATE "ROS2_CONTROL_DEMO_EXAMPLE_14_BUILDING_DLL")
44+
45+
# Export hardware plugins
46+
pluginlib_export_plugin_description_file(hardware_interface ros2_control_demo_example_14.xml)
47+
48+
# INSTALL
49+
install(
50+
DIRECTORY hardware/include/
51+
DESTINATION include/ros2_control_demo_example_14
52+
)
53+
install(
54+
DIRECTORY description/launch description/ros2_control description/urdf
55+
DESTINATION share/ros2_control_demo_example_14
56+
)
57+
install(
58+
DIRECTORY bringup/launch bringup/config
59+
DESTINATION share/ros2_control_demo_example_14
60+
)
61+
install(TARGETS ros2_control_demo_example_14
62+
EXPORT export_ros2_control_demo_example_14
63+
ARCHIVE DESTINATION lib
64+
LIBRARY DESTINATION lib
65+
RUNTIME DESTINATION bin
66+
)
67+
68+
if(BUILD_TESTING)
69+
find_package(ament_cmake_gtest REQUIRED)
70+
endif()
71+
72+
## EXPORTS
73+
ament_export_targets(export_ros2_control_demo_example_14 HAS_LIBRARY_TARGET)
74+
ament_export_dependencies(${THIS_PACKAGE_INCLUDE_DEPENDS})
75+
ament_package()

example_14/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# ros2_control_demo_example_14
2+
3+
The example shows how to implement robot hardware with actuators not providing states and with additional sensors.
4+
5+
Find the documentation in [doc/userdoc.rst](doc/userdoc.rst) or on [control.ros.org](https://control.ros.org/master/doc/ros2_control_demos/example_14/doc/userdoc.html).
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
controller_manager:
2+
ros__parameters:
3+
update_rate: 100 # Hz
4+
5+
joint_state_broadcaster:
6+
type: joint_state_broadcaster/JointStateBroadcaster
7+
8+
forward_velocity_controller:
9+
type: forward_command_controller/ForwardCommandController
10+
11+
12+
forward_velocity_controller:
13+
ros__parameters:
14+
joints:
15+
- joint1
16+
- joint2
17+
interface_name: velocity
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
# Copyright 2021 Stogl Robotics Consulting UG (haftungsbeschränkt)
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from launch import LaunchDescription
16+
from launch.actions import DeclareLaunchArgument, RegisterEventHandler
17+
from launch.conditions import IfCondition
18+
from launch.event_handlers import OnProcessExit
19+
from launch.substitutions import Command, FindExecutable, LaunchConfiguration, PathJoinSubstitution
20+
21+
from launch_ros.actions import Node
22+
from launch_ros.substitutions import FindPackageShare
23+
24+
25+
def generate_launch_description():
26+
# Declare arguments
27+
declared_arguments = []
28+
declared_arguments.append(
29+
DeclareLaunchArgument(
30+
"prefix",
31+
default_value='""',
32+
description="Prefix of the joint names, useful for \
33+
multi-robot setup. If changed than also joint names in the controllers' configuration \
34+
have to be updated.",
35+
)
36+
)
37+
declared_arguments.append(
38+
DeclareLaunchArgument(
39+
"slowdown", default_value="50.0", description="Slowdown factor of the RRbot."
40+
)
41+
)
42+
declared_arguments.append(
43+
DeclareLaunchArgument(
44+
"robot_controller",
45+
default_value="forward_velocity_controller",
46+
description="Robot controller to start.",
47+
)
48+
)
49+
declared_arguments.append(
50+
DeclareLaunchArgument(
51+
"gui",
52+
default_value="true",
53+
description="Start RViz2 automatically with this launch file.",
54+
)
55+
)
56+
57+
# Initialize Arguments
58+
prefix = LaunchConfiguration("prefix")
59+
slowdown = LaunchConfiguration("slowdown")
60+
robot_controller = LaunchConfiguration("robot_controller")
61+
gui = LaunchConfiguration("gui")
62+
63+
# Get URDF via xacro
64+
robot_description_content = Command(
65+
[
66+
PathJoinSubstitution([FindExecutable(name="xacro")]),
67+
" ",
68+
PathJoinSubstitution(
69+
[
70+
FindPackageShare("ros2_control_demo_example_14"),
71+
"urdf",
72+
"rrbot_modular_actuators_without_feedback_sensors_for_position_feedback.urdf.xacro",
73+
]
74+
),
75+
" ",
76+
"prefix:=",
77+
prefix,
78+
" ",
79+
"slowdown:=",
80+
slowdown,
81+
]
82+
)
83+
robot_description = {"robot_description": robot_description_content}
84+
85+
robot_controllers = PathJoinSubstitution(
86+
[
87+
FindPackageShare("ros2_control_demo_example_14"),
88+
"config",
89+
"rrbot_modular_actuators_without_feedback_sensors_for_position_feedback.yaml",
90+
]
91+
)
92+
rviz_config_file = PathJoinSubstitution(
93+
[FindPackageShare("ros2_control_demo_description"), "rrbot/rviz", "rrbot.rviz"]
94+
)
95+
96+
control_node = Node(
97+
package="controller_manager",
98+
executable="ros2_control_node",
99+
parameters=[robot_description, robot_controllers],
100+
output="both",
101+
)
102+
robot_state_pub_node = Node(
103+
package="robot_state_publisher",
104+
executable="robot_state_publisher",
105+
output="both",
106+
parameters=[robot_description],
107+
)
108+
rviz_node = Node(
109+
package="rviz2",
110+
executable="rviz2",
111+
name="rviz2",
112+
output="log",
113+
arguments=["-d", rviz_config_file],
114+
condition=IfCondition(gui),
115+
)
116+
117+
joint_state_broadcaster_spawner = Node(
118+
package="controller_manager",
119+
executable="spawner",
120+
arguments=["joint_state_broadcaster", "--controller-manager", "/controller_manager"],
121+
)
122+
123+
robot_controller_spawner = Node(
124+
package="controller_manager",
125+
executable="spawner",
126+
arguments=[robot_controller, "--controller-manager", "/controller_manager"],
127+
)
128+
129+
# Delay rviz start after `joint_state_broadcaster`
130+
delay_rviz_after_joint_state_broadcaster_spawner = RegisterEventHandler(
131+
event_handler=OnProcessExit(
132+
target_action=joint_state_broadcaster_spawner,
133+
on_exit=[rviz_node],
134+
)
135+
)
136+
137+
# Delay start of robot_controller after `joint_state_broadcaster`
138+
delay_robot_controller_spawner_after_joint_state_broadcaster_spawner = RegisterEventHandler(
139+
event_handler=OnProcessExit(
140+
target_action=joint_state_broadcaster_spawner,
141+
on_exit=[robot_controller_spawner],
142+
)
143+
)
144+
145+
nodes = [
146+
control_node,
147+
robot_state_pub_node,
148+
joint_state_broadcaster_spawner,
149+
delay_rviz_after_joint_state_broadcaster_spawner,
150+
delay_robot_controller_spawner_after_joint_state_broadcaster_spawner,
151+
]
152+
153+
return LaunchDescription(declared_arguments + nodes)

0 commit comments

Comments
 (0)