Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make tb4 sim work with namespaced simulations #15

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions nav2_minimal_tb4_description/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ find_package(ament_cmake REQUIRED)
find_package(urdf REQUIRED)
find_package(xacro REQUIRED)

ament_environment_hooks("${CMAKE_CURRENT_SOURCE_DIR}/hooks/tb4_description.dsv.in")

install(
DIRECTORY launch meshes urdf rviz
DESTINATION share/${PROJECT_NAME}
Expand Down
1 change: 1 addition & 0 deletions nav2_minimal_tb4_description/hooks/tb4_description.dsv.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
prepend-non-duplicate;GZ_SIM_RESOURCE_PATH;share/
SteveMacenski marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion nav2_minimal_tb4_sim/configs/tb4_bridge.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# replace clock_bridge
- ros_topic_name: "clock"
- ros_topic_name: "/clock"
gz_topic_name: "/clock"
ros_type_name: "rosgraph_msgs/msg/Clock"
gz_type_name: "gz.msgs.Clock"
Expand Down
23 changes: 5 additions & 18 deletions nav2_minimal_tb4_sim/launch/spawn_tb4.launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@
# limitations under the License.

import os
from pathlib import Path

from ament_index_python.packages import get_package_share_directory

from launch import LaunchDescription
from launch.actions import AppendEnvironmentVariable
from launch.actions import DeclareLaunchArgument
from launch.conditions import IfCondition
from launch.substitutions import LaunchConfiguration
Expand All @@ -29,7 +27,6 @@

def generate_launch_description():
sim_dir = get_package_share_directory('nav2_minimal_tb4_sim')
desc_dir = get_package_share_directory('nav2_minimal_tb4_description')

use_sim_time = LaunchConfiguration('use_sim_time')
namespace = LaunchConfiguration('namespace')
Expand Down Expand Up @@ -65,15 +62,11 @@ def generate_launch_description():
default_value='turtlebot4',
description='name of the robot')

# declare_robot_sdf_cmd = DeclareLaunchArgument(
# 'robot_sdf',
# default_value=os.path.join(desc_dir, 'urdf', 'standard', 'turtlebot4.urdf.xacro'),
# description='Full path to robot sdf file to spawn the robot in gazebo')

bridge = Node(
package='ros_gz_bridge',
executable='parameter_bridge',
name='bridge_ros_gz',
namespace=namespace,
parameters=[
{
'config_file': os.path.join(
Expand All @@ -89,6 +82,7 @@ def generate_launch_description():
package='ros_gz_image',
executable='image_bridge',
name='bridge_gz_ros_camera_image',
namespace=namespace,
output='screen',
parameters=[{
'use_sim_time': use_sim_time,
Expand All @@ -99,6 +93,7 @@ def generate_launch_description():
package='ros_gz_image',
executable='image_bridge',
name='bridge_gz_ros_camera_depth',
namespace=namespace,
output='screen',
parameters=[{
'use_sim_time': use_sim_time,
Expand All @@ -109,31 +104,23 @@ def generate_launch_description():
condition=IfCondition(use_simulator),
SteveMacenski marked this conversation as resolved.
Show resolved Hide resolved
package='ros_gz_sim',
executable='create',
namespace=namespace,
output='screen',
arguments=[
'-entity', robot_name,
'-name', robot_name,
'-topic', 'robot_description',
# '-file', Command(['xacro', ' ', robot_sdf]), # TODO SDF file is unhappy, not sure why
'-robot_namespace', namespace,
'-x', pose['x'], '-y', pose['y'], '-z', pose['z'],
'-R', pose['R'], '-P', pose['P'], '-Y', pose['Y']],
parameters=[{'use_sim_time': use_sim_time}]
)

set_env_vars_resources = AppendEnvironmentVariable(
'GZ_SIM_RESOURCE_PATH',
str(Path(os.path.join(desc_dir)).parent.resolve()))

# Create the launch description and populate
ld = LaunchDescription()
ld.add_action(declare_namespace_cmd)
ld.add_action(declare_robot_name_cmd)
# ld.add_action(declare_robot_sdf_cmd)
ld.add_action(declare_use_simulator_cmd)
ld.add_action(declare_use_sim_time_cmd)

ld.add_action(set_env_vars_resources)

ld.add_action(bridge)
ld.add_action(camera_bridge_image)
ld.add_action(camera_bridge_depth)
Expand Down
Loading