Skip to content

Commit 8bfff84

Browse files
Make tb4 sim work with namespaced simulations (#15)
* Make tb4 sim work with namespaced simulations Signed-off-by: Luca Della Vedova <[email protected]> * Remove remaining use_simulator usages Signed-off-by: Luca Della Vedova <[email protected]> * Cleanup Signed-off-by: Luca Della Vedova <[email protected]> * Add back `use_simulator` parameter Signed-off-by: Luca Della Vedova <[email protected]> * Fix namespace Signed-off-by: Luca Della Vedova <[email protected]> * Remove all commented code Signed-off-by: Luca Della Vedova <[email protected]> --------- Signed-off-by: Luca Della Vedova <[email protected]> Signed-off-by: Luca Della Vedova <[email protected]>
1 parent f0eeedb commit 8bfff84

File tree

4 files changed

+9
-19
lines changed

4 files changed

+9
-19
lines changed

nav2_minimal_tb4_description/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ find_package(ament_cmake REQUIRED)
66
find_package(urdf REQUIRED)
77
find_package(xacro REQUIRED)
88

9+
ament_environment_hooks("${CMAKE_CURRENT_SOURCE_DIR}/hooks/tb4_description.dsv.in")
10+
911
install(
1012
DIRECTORY launch meshes urdf rviz
1113
DESTINATION share/${PROJECT_NAME}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
prepend-non-duplicate;GZ_SIM_RESOURCE_PATH;share/

nav2_minimal_tb4_sim/configs/tb4_bridge.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# replace clock_bridge
2-
- ros_topic_name: "clock"
2+
- ros_topic_name: "/clock"
33
gz_topic_name: "/clock"
44
ros_type_name: "rosgraph_msgs/msg/Clock"
55
gz_type_name: "gz.msgs.Clock"

nav2_minimal_tb4_sim/launch/spawn_tb4.launch.py

+5-18
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,10 @@
1414
# limitations under the License.
1515

1616
import os
17-
from pathlib import Path
1817

1918
from ament_index_python.packages import get_package_share_directory
2019

2120
from launch import LaunchDescription
22-
from launch.actions import AppendEnvironmentVariable
2321
from launch.actions import DeclareLaunchArgument
2422
from launch.conditions import IfCondition
2523
from launch.substitutions import LaunchConfiguration
@@ -29,7 +27,6 @@
2927

3028
def generate_launch_description():
3129
sim_dir = get_package_share_directory('nav2_minimal_tb4_sim')
32-
desc_dir = get_package_share_directory('nav2_minimal_tb4_description')
3330

3431
use_sim_time = LaunchConfiguration('use_sim_time')
3532
namespace = LaunchConfiguration('namespace')
@@ -65,15 +62,11 @@ def generate_launch_description():
6562
default_value='turtlebot4',
6663
description='name of the robot')
6764

68-
# declare_robot_sdf_cmd = DeclareLaunchArgument(
69-
# 'robot_sdf',
70-
# default_value=os.path.join(desc_dir, 'urdf', 'standard', 'turtlebot4.urdf.xacro'),
71-
# description='Full path to robot sdf file to spawn the robot in gazebo')
72-
7365
bridge = Node(
7466
package='ros_gz_bridge',
7567
executable='parameter_bridge',
7668
name='bridge_ros_gz',
69+
namespace=namespace,
7770
parameters=[
7871
{
7972
'config_file': os.path.join(
@@ -89,6 +82,7 @@ def generate_launch_description():
8982
package='ros_gz_image',
9083
executable='image_bridge',
9184
name='bridge_gz_ros_camera_image',
85+
namespace=namespace,
9286
output='screen',
9387
parameters=[{
9488
'use_sim_time': use_sim_time,
@@ -99,6 +93,7 @@ def generate_launch_description():
9993
package='ros_gz_image',
10094
executable='image_bridge',
10195
name='bridge_gz_ros_camera_depth',
96+
namespace=namespace,
10297
output='screen',
10398
parameters=[{
10499
'use_sim_time': use_sim_time,
@@ -109,31 +104,23 @@ def generate_launch_description():
109104
condition=IfCondition(use_simulator),
110105
package='ros_gz_sim',
111106
executable='create',
107+
namespace=namespace,
112108
output='screen',
113109
arguments=[
114-
'-entity', robot_name,
110+
'-name', robot_name,
115111
'-topic', 'robot_description',
116-
# '-file', Command(['xacro', ' ', robot_sdf]), # TODO SDF file is unhappy, not sure why
117-
'-robot_namespace', namespace,
118112
'-x', pose['x'], '-y', pose['y'], '-z', pose['z'],
119113
'-R', pose['R'], '-P', pose['P'], '-Y', pose['Y']],
120114
parameters=[{'use_sim_time': use_sim_time}]
121115
)
122116

123-
set_env_vars_resources = AppendEnvironmentVariable(
124-
'GZ_SIM_RESOURCE_PATH',
125-
str(Path(os.path.join(desc_dir)).parent.resolve()))
126-
127117
# Create the launch description and populate
128118
ld = LaunchDescription()
129119
ld.add_action(declare_namespace_cmd)
130120
ld.add_action(declare_robot_name_cmd)
131-
# ld.add_action(declare_robot_sdf_cmd)
132121
ld.add_action(declare_use_simulator_cmd)
133122
ld.add_action(declare_use_sim_time_cmd)
134123

135-
ld.add_action(set_env_vars_resources)
136-
137124
ld.add_action(bridge)
138125
ld.add_action(camera_bridge_image)
139126
ld.add_action(camera_bridge_depth)

0 commit comments

Comments
 (0)