Skip to content

Commit 9e89f2a

Browse files
authored
Add namespace support (#17)
* add namespace for simulation and teleop * add namespace to gazebo entity * change to prefix only in urdfs * enable ns for joint_state_publisher * add namespace support to mir_navigation + ns instructions to readme * switched namespaces to remappings in urdfs * resolved gazeboplugin namespace errors * fixes for namespace support driver * added navigation config namespace examples * minor fixes for namespace launch and adaptions in rviz configs * fixed tf namespace bug in driver * split up of driver launch files * fixed params filename + added namespace args in nav launch * enabled qos settings for ros2 topics in driver * removed unused rviz parameter
1 parent 1d979d5 commit 9e89f2a

27 files changed

+733
-391
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,14 @@ Initialize Pose | Drifted pose | Refined pose
450450
![](doc/img/initial_pose1.png) |![](doc/img/initial_pose2.png)|![](doc/img/initial_pose3.png)
451451

452452

453+
Using a namespace
454+
------------------------------------
455+
456+
When using a namespace for your robot, add the ``--ros-args -p namespace:=my_namespace`` to the launch files.
457+
The driver, description and gazebo packages work out of the box.
458+
However, to use the navigation stack the corresponding config.yaml files need to be adapted to match the renamed topic.
459+
460+
The navigation ``cmd_vel`` topic is automatically remapped by adding the namespace in the ``navigation.py`` launch file.
453461

454462
<!--
455463

mir_description/launch/mir_display_launch.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ def generate_launch_description():
3131
Node(
3232
package='rviz2',
3333
executable='rviz2',
34-
arguments=['-d', rviz_config_file]),
34+
arguments=['-d', rviz_config_file],
35+
parameters=[{'use_sim_time': LaunchConfiguration('use_sim_time')}]
36+
)
3537

3638
])

mir_description/launch/mir_launch.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,28 @@ def generate_launch_description():
1515
mir_description_dir = get_package_share_directory('mir_description')
1616

1717
def create_robot_description(context):
18-
namespace = context.launch_configurations['namespace']
18+
ns = context.launch_configurations['namespace']
19+
if ns.startswith('/'):
20+
ns = ns[1:]
21+
22+
prefix = context.launch_configurations['prefix']
1923
urdf_dir = os.path.join(mir_description_dir, 'urdf')
2024
xacro_file = os.path.join(urdf_dir, 'mir.urdf.xacro')
21-
doc = xacro.process_file(xacro_file, mappings={'tf_prefix' : namespace})
25+
doc = xacro.process_file(xacro_file, mappings={'tf_prefix' : ns})
2226
robot_desc = doc.toprettyxml(indent=' ')
2327
return [SetLaunchConfiguration('robot_description', robot_desc)]
2428

2529
return LaunchDescription([
2630

31+
DeclareLaunchArgument(
32+
'prefix',
33+
default_value='',
34+
description='Robot prefix'),
35+
2736
DeclareLaunchArgument(
2837
'namespace',
2938
default_value='',
30-
description='Robot namespace'),
39+
description='Namespace to push all topics to'),
3140

3241
DeclareLaunchArgument(
3342
'joint_state_publisher_enabled',
@@ -43,12 +52,13 @@ def create_robot_description(context):
4352
output='both',
4453
parameters=[{'use_sim_time': use_sim_time,
4554
'robot_description': LaunchConfiguration('robot_description')}],
46-
namespace=LaunchConfiguration('namespace')),
55+
namespace=LaunchConfiguration('namespace'),
56+
),
4757

4858
Node(
4959
condition=IfCondition(LaunchConfiguration('joint_state_publisher_enabled')),
5060
package='joint_state_publisher',
51-
executable='joint_state_publisher',
52-
namespace=LaunchConfiguration('namespace'))
61+
namespace=LaunchConfiguration('namespace'),
62+
executable='joint_state_publisher')
5363

5464
])

mir_description/rviz/mir_visu_full.rviz

Lines changed: 11 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ Panels:
44
Name: Displays
55
Property Tree Widget:
66
Expanded:
7+
- /Global Options1
78
- /Status1
89
- /Map1/Topic1
910
- /RobotModel1/Description Topic1
1011
- /TF1/Frames1
1112
- /Path1/Topic1
1213
- /Path2/Topic1
1314
Splitter Ratio: 0.5
14-
Tree Height: 784
15+
Tree Height: 820
1516
- Class: rviz_common/Selection
1617
Name: Selection
1718
- Class: rviz_common/Tool Properties
@@ -32,7 +33,7 @@ Visualization Manager:
3233
Cell Size: 1
3334
Class: rviz_default_plugins/Grid
3435
Color: 160; 160; 164
35-
Enabled: false
36+
Enabled: true
3637
Line Style:
3738
Line Width: 0.029999999329447746
3839
Value: Lines
@@ -45,7 +46,7 @@ Visualization Manager:
4546
Plane: XY
4647
Plane Cell Count: 10
4748
Reference Frame: <Fixed Frame>
48-
Value: false
49+
Value: true
4950
- Alpha: 0.699999988079071
5051
Class: rviz_default_plugins/Map
5152
Color Scheme: map
@@ -124,99 +125,6 @@ Visualization Manager:
124125
Expand Link Details: false
125126
Expand Tree: false
126127
Link Tree Style: Links in Alphabetic Order
127-
back_laser_link:
128-
Alpha: 1
129-
Show Axes: false
130-
Show Trail: false
131-
Value: true
132-
base_footprint:
133-
Alpha: 1
134-
Show Axes: false
135-
Show Trail: false
136-
base_link:
137-
Alpha: 1
138-
Show Axes: false
139-
Show Trail: false
140-
Value: true
141-
bl_caster_rotation_link:
142-
Alpha: 1
143-
Show Axes: false
144-
Show Trail: false
145-
Value: true
146-
bl_caster_wheel_link:
147-
Alpha: 1
148-
Show Axes: false
149-
Show Trail: false
150-
Value: true
151-
br_caster_rotation_link:
152-
Alpha: 1
153-
Show Axes: false
154-
Show Trail: false
155-
Value: true
156-
br_caster_wheel_link:
157-
Alpha: 1
158-
Show Axes: false
159-
Show Trail: false
160-
Value: true
161-
fl_caster_rotation_link:
162-
Alpha: 1
163-
Show Axes: false
164-
Show Trail: false
165-
Value: true
166-
fl_caster_wheel_link:
167-
Alpha: 1
168-
Show Axes: false
169-
Show Trail: false
170-
Value: true
171-
fr_caster_rotation_link:
172-
Alpha: 1
173-
Show Axes: false
174-
Show Trail: false
175-
Value: true
176-
fr_caster_wheel_link:
177-
Alpha: 1
178-
Show Axes: false
179-
Show Trail: false
180-
Value: true
181-
front_laser_link:
182-
Alpha: 1
183-
Show Axes: false
184-
Show Trail: false
185-
Value: true
186-
imu_frame:
187-
Alpha: 1
188-
Show Axes: false
189-
Show Trail: false
190-
imu_link:
191-
Alpha: 1
192-
Show Axes: false
193-
Show Trail: false
194-
left_wheel_link:
195-
Alpha: 1
196-
Show Axes: false
197-
Show Trail: false
198-
Value: true
199-
right_wheel_link:
200-
Alpha: 1
201-
Show Axes: false
202-
Show Trail: false
203-
Value: true
204-
surface:
205-
Alpha: 1
206-
Show Axes: false
207-
Show Trail: false
208-
us_1_frame:
209-
Alpha: 1
210-
Show Axes: false
211-
Show Trail: false
212-
us_2_frame:
213-
Alpha: 1
214-
Show Axes: false
215-
Show Trail: false
216-
virtual_laser_link:
217-
Alpha: 1
218-
Show Axes: false
219-
Show Trail: false
220128
Name: RobotModel
221129
TF Prefix: ""
222130
Update Interval: 0
@@ -251,7 +159,7 @@ Visualization Manager:
251159
Durability Policy: Volatile
252160
Filter size: 10
253161
History Policy: Keep Last
254-
Reliability Policy: Reliable
162+
Reliability Policy: Best Effort
255163
Value: /scan
256164
Use Fixed Frame: true
257165
Use rainbow: true
@@ -404,7 +312,7 @@ Visualization Manager:
404312
Enabled: true
405313
Global Options:
406314
Background Color: 48; 48; 48
407-
Fixed Frame: map
315+
Fixed Frame: base_link
408316
Frame Rate: 30
409317
Name: root
410318
Tools:
@@ -465,21 +373,21 @@ Visualization Manager:
465373
Pitch: 1.5597963333129883
466374
Target Frame: <Fixed Frame>
467375
Value: Orbit (rviz)
468-
Yaw: 0.005398864857852459
376+
Yaw: 0.0003988649696111679
469377
Saved: ~
470378
Window Geometry:
471379
Displays:
472380
collapsed: false
473-
Height: 1013
381+
Height: 1043
474382
Hide Left Dock: false
475383
Hide Right Dock: false
476-
QMainWindow State: 000000ff00000000fd0000000400000000000001ea0000039bfc0200000008fb0000001200530065006c0065006300740069006f006e00000001e10000009b0000005c00fffffffb0000001e0054006f006f006c002000500072006f007000650072007400690065007302000001ed000001df00000185000000a3fb000000120056006900650077007300200054006f006f02000001df000002110000018500000122fb000000200054006f006f006c002000500072006f0070006500720074006900650073003203000002880000011d000002210000017afb000000100044006900730070006c006100790073010000003d0000039b000000c900fffffffb0000002000730065006c0065006300740069006f006e00200062007500660066006500720200000138000000aa0000023a00000294fb00000014005700690064006500530074006500720065006f02000000e6000000d2000003ee0000030bfb0000000c004b0069006e0065006300740200000186000001060000030c00000261000000010000010f0000039bfc0200000003fb0000001e0054006f006f006c002000500072006f00700065007200740069006500730100000041000000780000000000000000fb0000000a00560069006500770073010000003d0000039b000000a400fffffffb0000001200530065006c0065006300740069006f006e010000025a000000b200000000000000000000000200000490000000a9fc0100000001fb0000000a00560069006500770073030000004e00000080000002e10000019700000003000004420000003efc0100000002fb0000000800540069006d00650100000000000004420000000000000000fb0000000800540069006d006501000000000000045000000000000000000000038b0000039b00000004000000040000000800000008fc0000000100000002000000010000000a0054006f006f006c00730100000000ffffffff0000000000000000
384+
QMainWindow State: 000000ff00000000fd0000000400000000000001ea000003bdfc0200000008fb0000001200530065006c0065006300740069006f006e00000001e10000009b0000005c00fffffffb0000001e0054006f006f006c002000500072006f007000650072007400690065007302000001ed000001df00000185000000a3fb000000120056006900650077007300200054006f006f02000001df000002110000018500000122fb000000200054006f006f006c002000500072006f0070006500720074006900650073003203000002880000011d000002210000017afb000000100044006900730070006c006100790073010000003b000003bd000000c700fffffffb0000002000730065006c0065006300740069006f006e00200062007500660066006500720200000138000000aa0000023a00000294fb00000014005700690064006500530074006500720065006f02000000e6000000d2000003ee0000030bfb0000000c004b0069006e0065006300740200000186000001060000030c00000261000000010000010f000003bdfc0200000003fb0000001e0054006f006f006c002000500072006f00700065007200740069006500730100000041000000780000000000000000fb0000000a00560069006500770073010000003b000003bd000000a000fffffffb0000001200530065006c0065006300740069006f006e010000025a000000b200000000000000000000000200000490000000a9fc0100000001fb0000000a00560069006500770073030000004e00000080000002e10000019700000003000004420000003efc0100000002fb0000000800540069006d00650100000000000004420000000000000000fb0000000800540069006d006501000000000000045000000000000000000000047b000003bd00000004000000040000000800000008fc0000000100000002000000010000000a0054006f006f006c00730100000000ffffffff0000000000000000
477385
Selection:
478386
collapsed: false
479387
Tool Properties:
480388
collapsed: false
481389
Views:
482390
collapsed: false
483-
Width: 1680
484-
X: 1920
391+
Width: 1920
392+
X: 0
485393
Y: 0

mir_description/urdf/include/imu.gazebo.urdf.xacro

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@
8181
</ros>
8282
</plugin>
8383
</sensor>
84-
-->
8584
</gazebo>
8685
</xacro:macro>
8786
</robot>

mir_description/urdf/include/mir_100.gazebo.xacro

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
<robot xmlns:xacro="http://ros.org/wiki/xacro">
33

44
<!-- See https://github.com/ros-simulation/gazebo_ros_pkgs/wiki/ROS-2-Migration:-Diff-drive for ros2 information -->
5-
<xacro:macro name="diff_controller_plugin_gazebo" params="prefix namespace left_wheel_joint right_wheel_joint wheel_separation wheel_radius">
5+
<xacro:macro name="diff_controller_plugin_gazebo" params="prefix ns left_wheel_joint right_wheel_joint wheel_separation wheel_radius">
66
<gazebo>
77
<!-- Use gazebo_ros_joint_state_publisher instead of publishWheelJointState -->
88
<plugin name="joint_states" filename="libgazebo_ros_joint_state_publisher.so">
99
<ros>
10-
<namespace>${namespace}</namespace>
10+
<namespace>${ns}</namespace>
1111
</ros>
1212
<update_rate>1000.0</update_rate>
1313
<joint_name>${right_wheel_joint}</joint_name>
@@ -16,7 +16,8 @@
1616

1717
<plugin name="diff_drive_controller" filename="libgazebo_ros_diff_drive.so">
1818
<ros>
19-
<namespace>${prefix}</namespace>
19+
<remapping>cmd_vel:=${prefix}cmd_vel</remapping>
20+
<remapping>odom:=${prefix}odom</remapping>
2021
</ros>
2122

2223
<legacy_mode>false</legacy_mode>
@@ -61,12 +62,11 @@
6162
</xacro:macro>
6263

6364
<!-- See https://github.com/ros-simulation/gazebo_ros_pkgs/wiki/ROS-2-Migration:-P3D for ros2 information -->
64-
<xacro:macro name="p3d_base_controller" params="namespace prefix">
65+
<xacro:macro name="p3d_base_controller" params="prefix">
6566
<gazebo>
6667
<plugin name="p3d_base_controller" filename="libgazebo_ros_p3d.so">
6768
<ros>
68-
<namespace>${namespace}</namespace>
69-
<remapping>odom:=base_pose_ground_truth</remapping>
69+
<remapping>odom:=${prefix}base_pose_ground_truth</remapping>
7070
</ros>
7171
<always_on>true</always_on>
7272
<update_rate>50.0</update_rate>

mir_description/urdf/include/mir_100_v1.urdf.xacro

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
<xacro:property name="imu_stdev" value="0.00017" />
3232

33-
<xacro:macro name="actuated_wheel" params="prefix namespace locationprefix locationright">
33+
<xacro:macro name="actuated_wheel" params="prefix locationprefix locationright">
3434
<joint name="${prefix}${locationprefix}_wheel_joint" type="continuous">
3535
<origin xyz="0.0 ${-mir_100_act_wheel_dy * locationright} ${mir_100_act_wheel_radius}" rpy="0 0 0" />
3636
<parent link="${prefix}base_link" />
@@ -62,7 +62,7 @@
6262
</gazebo>
6363
</xacro:macro>
6464

65-
<xacro:macro name="caster_wheel" params="prefix locationprefix locationright wheel_base_dx">
65+
<xacro:macro name="caster_wheel" params="prefix ns locationprefix locationright wheel_base_dx">
6666
<!-- caster hub -->
6767
<joint name="${prefix}${locationprefix}_caster_rotation_joint" type="continuous">
6868
<origin xyz="${wheel_base_dx} ${-mir_100_caster_wheel_base_dy * locationright} ${mir_100_caster_wheel_base_dz}" rpy="0 0 0" />
@@ -75,6 +75,7 @@
7575
<gazebo>
7676
<plugin name="${locationprefix}_caster_rotation_joint_states" filename="libgazebo_ros_joint_state_publisher.so">
7777
<ros>
78+
<namespace>${ns}</namespace>
7879
</ros>
7980
<update_rate>200.0</update_rate>
8081
<joint_name>${prefix}${locationprefix}_caster_rotation_joint</joint_name>
@@ -123,7 +124,7 @@
123124
<gazebo>
124125
<plugin name="${locationprefix}_caster_wheel_joint_states" filename="libgazebo_ros_joint_state_publisher.so">
125126
<ros>
126-
<namespace>${namespace}</namespace>
127+
<namespace>${ns}</namespace>
127128
</ros>
128129
<update_rate>200.0</update_rate>
129130
<joint_name>${prefix}${locationprefix}_caster_wheel_joint</joint_name>
@@ -153,7 +154,7 @@
153154
</gazebo>
154155
</xacro:macro>
155156

156-
<xacro:macro name="mir_100" params="prefix namespace">
157+
<xacro:macro name="mir_100" params="prefix ns">
157158
<link name="${prefix}base_footprint" />
158159

159160
<joint name="${prefix}base_joint" type="fixed">
@@ -221,15 +222,15 @@
221222
<child link="${prefix}front_laser_link" />
222223
<origin xyz="0.4288 0.2358 0.1914" rpy="0.0 0.0 ${0.25 * pi}" /> <!-- from visually matching up the meshes of the MiR and the laser scanner -->
223224
</joint>
224-
<xacro:sick_s300 prefix="${prefix}" namespace="${namespace}" link="front_laser_link" topic="f_scan" />
225+
<xacro:sick_s300 prefix="${prefix}" link="front_laser_link" topic="f_scan" />
225226

226227
<joint name="${prefix}base_link_to_back_laser_joint" type="fixed">
227228
<parent link="${prefix}base_link" />
228229
<child link="${prefix}back_laser_link" />
229230
<origin xyz="-0.3548 -0.2352 0.1914" rpy="0.0 0.0 ${-0.75 * pi}" /> <!-- from visually matching up the meshes of the MiR and the laser scanner -->
230231
</joint>
231232

232-
<xacro:sick_s300 prefix="${prefix}" namespace="${namespace}" link="back_laser_link" topic="b_scan" />
233+
<xacro:sick_s300 prefix="${prefix}" link="back_laser_link" topic="b_scan" />
233234

234235
<!-- Ultrasound sensors -->
235236
<joint name="${prefix}us_1_joint" type="fixed"> <!-- right ultrasound -->
@@ -249,12 +250,12 @@
249250
<link name="${prefix}us_2_frame" />
250251

251252
<!-- wheels -->
252-
<xacro:actuated_wheel prefix="${prefix}" namespace="${namespace}" locationprefix="left" locationright="-1"/>
253-
<xacro:actuated_wheel prefix="${prefix}" namespace="${namespace}" locationprefix="right" locationright="1"/>
254-
<xacro:caster_wheel prefix="${prefix}" locationprefix="fl" locationright="-1" wheel_base_dx="${mir_100_front_caster_wheel_base_dx}"/>
255-
<xacro:caster_wheel prefix="${prefix}" locationprefix="fr" locationright="1" wheel_base_dx="${mir_100_front_caster_wheel_base_dx}"/>
256-
<xacro:caster_wheel prefix="${prefix}" locationprefix="bl" locationright="-1" wheel_base_dx="${mir_100_back_caster_wheel_base_dx}"/>
257-
<xacro:caster_wheel prefix="${prefix}" locationprefix="br" locationright="1" wheel_base_dx="${mir_100_back_caster_wheel_base_dx}"/>
253+
<xacro:actuated_wheel prefix="${prefix}" locationprefix="left" locationright="-1"/>
254+
<xacro:actuated_wheel prefix="${prefix}" locationprefix="right" locationright="1"/>
255+
<xacro:caster_wheel prefix="${prefix}" ns="${ns}" locationprefix="fl" locationright="-1" wheel_base_dx="${mir_100_front_caster_wheel_base_dx}"/>
256+
<xacro:caster_wheel prefix="${prefix}" ns="${ns}" locationprefix="fr" locationright="1" wheel_base_dx="${mir_100_front_caster_wheel_base_dx}"/>
257+
<xacro:caster_wheel prefix="${prefix}" ns="${ns}" locationprefix="bl" locationright="-1" wheel_base_dx="${mir_100_back_caster_wheel_base_dx}"/>
258+
<xacro:caster_wheel prefix="${prefix}" ns="${ns}" locationprefix="br" locationright="1" wheel_base_dx="${mir_100_back_caster_wheel_base_dx}"/>
258259

259260
<joint name="${prefix}base_link_surface_joint" type="fixed">
260261
<origin xyz="${mir_100_act_wheel_dx} 0 0.352" rpy="0 0 0" />
@@ -270,6 +271,6 @@
270271
<!-- set the gazebo friction parameters for the wheels -->
271272
<xacro:set_all_wheel_frictions prefix="${prefix}"/>
272273

273-
<xacro:p3d_base_controller prefix="${prefix}" namespace="${namespace}"/>
274+
<xacro:p3d_base_controller prefix="${prefix}"/>
274275
</xacro:macro>
275276
</robot>

0 commit comments

Comments
 (0)