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 3 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
24 changes: 4 additions & 20 deletions nav2_minimal_tb4_sim/launch/spawn_tb4.launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,22 @@
# 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

from launch_ros.actions import Node
from launch_ros.actions import Node, PushRosNamespace


def generate_launch_description():
sim_dir = get_package_share_directory('nav2_minimal_tb4_sim')
desc_dir = get_package_share_directory('nav2_minimal_tb4_description')
# desc_dir = get_package_share_directory('nav2_minimal_tb4_description')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just remove the line if its not needed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rest of its usage is under commented code that imho should be addressed at some point (spawning the robot through SDF the same way it's done for TB3 i.e. here. I commented it as consistency with the rest of the TODO and to make it easier to address it later, otherwise might as well remove all the related commented code.

Copy link
Member

@SteveMacenski SteveMacenski Oct 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, I think we should remove all commented out code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done cdacf92


use_sim_time = LaunchConfiguration('use_sim_time')
namespace = LaunchConfiguration('namespace')
use_simulator = LaunchConfiguration('use_simulator')
robot_name = LaunchConfiguration('robot_name')
# robot_sdf = LaunchConfiguration('robot_sdf')
pose = {'x': LaunchConfiguration('x_pose', default='-8.00'),
Expand All @@ -49,11 +45,6 @@ def generate_launch_description():
default_value='',
description='Top-level namespace')

declare_use_simulator_cmd = DeclareLaunchArgument(
'use_simulator',
default_value='True',
description='Whether to start the simulator')

declare_use_sim_time_cmd = DeclareLaunchArgument(
'use_sim_time',
default_value='true',
Expand Down Expand Up @@ -106,33 +97,26 @@ def generate_launch_description():
arguments=['/rgbd_camera/depth_image'])

spawn_model = Node(
condition=IfCondition(use_simulator),
SteveMacenski marked this conversation as resolved.
Show resolved Hide resolved
package='ros_gz_sim',
executable='create',
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(PushRosNamespace(namespace))

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