generated from joshnewans/my_bot
-
Notifications
You must be signed in to change notification settings - Fork 1
/
robot.launch.py
218 lines (181 loc) · 6.45 KB
/
robot.launch.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
import os
from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch.actions import RegisterEventHandler, DeclareLaunchArgument, IncludeLaunchDescription
from launch.event_handlers import OnProcessStart
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch_ros.actions import Node
from launch_ros.parameter_descriptions import ParameterValue
from launch.substitutions import LaunchConfiguration, Command
# Image Transport Republishers
# terminal command example: ros2 run image_transport republish raw compressed --ros-args -r in:=/camera/image_raw -r out/compressed:=/camera/image_raw/compressed
def image_transport_republisher(transport, camera_topics):
base_topic = camera_topics.split('/')[-1]
return Node(
package='image_transport',
executable='republish',
name=f'image_transport_republish_{transport}_{base_topic}',
arguments=['raw', transport],
remappings=[
('in', f'/camera/{camera_topics}'),
(f'out/{transport}', f'/camera/{camera_topics}/{transport}'),
],
)
def generate_launch_description():
package_name= 'minibot'
package_dir= get_package_share_directory(package_name)
use_sim_time = LaunchConfiguration('use_sim_time')
use_ros2_control = LaunchConfiguration('use_ros2_control')
lidar_serial_port = LaunchConfiguration('lidar_serial_port')
declare_use_sim_time= DeclareLaunchArgument(
'use_sim_time',
default_value='false',
description='If true, use simulated clock'
)
declare_use_ros2_control = DeclareLaunchArgument(
'use_ros2_control',
default_value='true',
description='If true, use ros2_control'
)
declare_lidar_serial_port = DeclareLaunchArgument(
'lidar_serial_port',
default_value='/dev/ttyUSB0',
description='Specifying usb port to connected lidar'
)
# Declare the path to files
robot_description_xacro_file = os.path.join(
package_dir,
'description',
'robot.urdf.xacro'
)
rviz_config_file_dir = os.path.join(
package_dir,
'config',
'minibot_config.rviz'
)
robot_controllers_file_dir = os.path.join(
package_dir,
'config',
'controller.yaml'
)
twist_mux_params_file = os.path.join(
package_dir,
'config',
'twist_mux.yaml'
)
# robot_state_publisher setup
robot_description_config = Command ([
'xacro ',
robot_description_xacro_file,
' use_ros2_control:=',
use_ros2_control
])
params = {
'robot_description': ParameterValue(robot_description_config, value_type=str),
'use_sim_time': use_sim_time,
'use_ros2_control': use_ros2_control
}
# robot_state_publisher node
node_robot_state_publisher = Node(
package='robot_state_publisher',
executable='robot_state_publisher',
output='screen',
parameters=[params]
)
# Image Transport Republishers Node
camera = 'image_raw'
depth_camera = 'depth/image_raw'
image_transports = ['compressed','compressedDepth', 'theora', 'zstd' ]
node_image_republishers = [image_transport_republisher(transport, depth_camera)
for transport in image_transports]
# controller spawn
node_ros2_control = Node(
package="controller_manager",
executable="ros2_control_node",
parameters=[params,
robot_controllers_file_dir
],
)
joint_state_broadcaster_spawner = Node(
package="controller_manager",
executable="spawner",
arguments=["joint_state_broadcaster"],
)
diff_drive_controller_spawner = Node(
package="controller_manager",
executable="spawner",
arguments=["diff_drive_controller",
"--param-file",
robot_controllers_file_dir
],
)
node_twist_mux = Node(
package="twist_mux",
executable="twist_mux",
name='twist_mux',
output='screen',
parameters=[
twist_mux_params_file,
{'use_stamped': True},
],
remappings=[
('cmd_vel_out',
'diff_drive_controller/cmd_vel'),
],
)
node_twist_stamper = Node(
package="twist_stamper",
executable="twist_stamper",
name='twist_stamper',
output='screen',
remappings=[
('cmd_vel_in', 'cmd_vel_smoothed'),
('cmd_vel_out', 'nav_vel'),
],
)
register_node_ros2_control = RegisterEventHandler(
event_handler=OnProcessStart(
target_action= node_robot_state_publisher,
on_start= [node_ros2_control],
)
)
register_joint_state_broadcaster_spawner = RegisterEventHandler(
event_handler=OnProcessStart(
target_action= node_ros2_control,
on_start=[joint_state_broadcaster_spawner],
)
)
register_diff_drive_controller_spawner = RegisterEventHandler(
event_handler=OnProcessStart(
target_action= joint_state_broadcaster_spawner,
on_start=[diff_drive_controller_spawner],
)
)
node_rplidar_drive = IncludeLaunchDescription(
PythonLaunchDescriptionSource([os.path.join(
get_package_share_directory('sllidar_ros2'),
'launch',
'sllidar_c1_launch.py'
)]),
launch_arguments={
'serial_port': lidar_serial_port,
'frame_id': 'lidar_frame'
}.items()
)
# Create the launch description and populate
ld = LaunchDescription()
# Add the nodes to the launch description
ld.add_action(declare_use_sim_time)
ld.add_action(declare_use_ros2_control)
ld.add_action(declare_lidar_serial_port)
ld.add_action(register_node_ros2_control)
ld.add_action(register_joint_state_broadcaster_spawner)
ld.add_action(register_diff_drive_controller_spawner)
ld.add_action(node_robot_state_publisher)
ld.add_action(node_twist_mux)
ld.add_action(node_twist_stamper)
for node_republisher in node_image_republishers:
ld.add_action(node_republisher)
ld.add_action(node_rplidar_drive)
# Generate the launch description
return ld