Skip to content

Commit 00ed608

Browse files
port spin behavior to new gazebo (ros-navigation#4470)
Signed-off-by: stevedan <[email protected]>
1 parent d2289e1 commit 00ed608

File tree

4 files changed

+62
-40
lines changed

4 files changed

+62
-40
lines changed

nav2_system_tests/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ if(BUILD_TESTING)
121121
add_subdirectory(src/waypoint_follower)
122122
# Uncomment after https://github.com/ros-navigation/navigation2/pull/3634
123123
# add_subdirectory(src/gps_navigation)
124-
# add_subdirectory(src/behaviors/spin)
124+
add_subdirectory(src/behaviors/spin)
125125
# add_subdirectory(src/behaviors/wait)
126126
# add_subdirectory(src/behaviors/backup)
127127
# add_subdirectory(src/behaviors/drive_on_heading)

nav2_system_tests/src/behaviors/spin/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@ ament_add_test(test_spin_behavior
1515
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
1616
TIMEOUT 180
1717
ENV
18-
TEST_MAP=${PROJECT_SOURCE_DIR}/maps/map_circular.yaml
1918
TEST_EXECUTABLE=$<TARGET_FILE:${test_spin_behavior_exec}>
20-
TEST_WORLD=${PROJECT_SOURCE_DIR}/worlds/turtlebot3_ros2_demo.world
21-
GAZEBO_MODEL_PATH=${PROJECT_SOURCE_DIR}/models
2219
BT_NAVIGATOR_XML=navigate_to_pose_w_replanning_and_recovery.xml
2320
)
2421

@@ -28,7 +25,6 @@ ament_add_test(test_spin_behavior_fake
2825
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
2926
TIMEOUT 180
3027
ENV
31-
TEST_MAP=${PROJECT_SOURCE_DIR}/maps/map_circular.yaml
3228
TEST_EXECUTABLE=$<TARGET_FILE:${test_spin_behavior_exec}>
3329
MAKE_FAKE_COSTMAP=true
3430
)

nav2_system_tests/src/behaviors/spin/test_spin_behavior_fake_launch.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@
3030
def generate_launch_description():
3131

3232
bringup_dir = get_package_share_directory('nav2_bringup')
33+
sim_dir = get_package_share_directory('nav2_minimal_tb3_sim')
34+
35+
urdf = os.path.join(sim_dir, 'urdf', 'turtlebot3_waffle.urdf')
36+
with open(urdf, 'r') as infp:
37+
robot_description = infp.read()
3338

3439
namespace = LaunchConfiguration('namespace')
3540
use_sim_time = LaunchConfiguration('use_sim_time')
@@ -112,25 +117,20 @@ def generate_launch_description():
112117
default_value='false',
113118
description='Whether to set the map subscriber QoS to transient local',
114119
),
115-
# TODO(orduno) Launch the robot state publisher instead
116-
# using a local copy of TB3 urdf file
117120
Node(
118121
package='tf2_ros',
119122
executable='static_transform_publisher',
120123
output='screen',
121124
arguments=['0', '0', '0', '0', '0', '0', 'map', 'odom'],
122125
),
123126
Node(
124-
package='tf2_ros',
125-
executable='static_transform_publisher',
126-
output='screen',
127-
arguments=['0', '0', '0', '0', '0', '0', 'base_footprint', 'base_link'],
128-
),
129-
Node(
130-
package='tf2_ros',
131-
executable='static_transform_publisher',
127+
package='robot_state_publisher',
128+
executable='robot_state_publisher',
129+
name='robot_state_publisher',
132130
output='screen',
133-
arguments=['0', '0', '0', '0', '0', '0', 'base_link', 'base_scan'],
131+
parameters=[
132+
{'use_sim_time': True, 'robot_description': robot_description}
133+
],
134134
),
135135
Node(
136136
package='nav2_behaviors',

nav2_system_tests/src/behaviors/spin/test_spin_behavior_launch.py

Lines changed: 50 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@
1414
# limitations under the License.
1515

1616
import os
17+
from pathlib import Path
1718
import sys
1819

1920
from ament_index_python.packages import get_package_share_directory
2021

2122
from launch import LaunchDescription
2223
from launch import LaunchService
2324
from launch.actions import (
25+
AppendEnvironmentVariable,
2426
ExecuteProcess,
2527
IncludeLaunchDescription,
2628
SetEnvironmentVariable,
@@ -30,11 +32,22 @@
3032
from launch_testing.legacy import LaunchTestService
3133

3234
from nav2_common.launch import RewrittenYaml
35+
from nav2_simple_commander.utils import kill_os_processes
3336

3437

3538
def generate_launch_description():
36-
map_yaml_file = os.getenv('TEST_MAP')
37-
world = os.getenv('TEST_WORLD')
39+
sim_dir = get_package_share_directory('nav2_minimal_tb3_sim')
40+
nav2_bringup_dir = get_package_share_directory('nav2_bringup')
41+
ros_gz_sim_dir = get_package_share_directory('ros_gz_sim')
42+
43+
world_sdf_xacro = os.path.join(sim_dir, 'worlds', 'tb3_sandbox.sdf.xacro')
44+
robot_sdf = os.path.join(sim_dir, 'urdf', 'gz_waffle.sdf.xacro')
45+
46+
urdf = os.path.join(sim_dir, 'urdf', 'turtlebot3_waffle.urdf')
47+
with open(urdf, 'r') as infp:
48+
robot_description = infp.read()
49+
50+
map_yaml_file = os.path.join(nav2_bringup_dir, 'maps', 'tb3_sandbox.yaml')
3851

3952
bt_navigator_xml = os.path.join(
4053
get_package_share_directory('nav2_bt_navigator'),
@@ -55,31 +68,42 @@ def generate_launch_description():
5568
SetEnvironmentVariable('RCUTILS_LOGGING_BUFFERED_STREAM', '1'),
5669
SetEnvironmentVariable('RCUTILS_LOGGING_USE_STDOUT', '1'),
5770
# Launch gazebo server for simulation
58-
ExecuteProcess(
59-
cmd=[
60-
'gzserver',
61-
'-s',
62-
'libgazebo_ros_init.so',
63-
'-s',
64-
'libgazebo_ros_factory.so',
65-
'--minimal_comms',
66-
world,
67-
],
68-
output='screen',
71+
AppendEnvironmentVariable(
72+
'GZ_SIM_RESOURCE_PATH', os.path.join(sim_dir, 'models')
6973
),
70-
# TODO(orduno) Launch the robot state publisher instead
71-
# using a local copy of TB3 urdf file
72-
Node(
73-
package='tf2_ros',
74-
executable='static_transform_publisher',
75-
output='screen',
76-
arguments=['0', '0', '0', '0', '0', '0', 'base_footprint', 'base_link'],
74+
AppendEnvironmentVariable(
75+
'GZ_SIM_RESOURCE_PATH',
76+
str(Path(os.path.join(sim_dir)).parent.resolve())
77+
),
78+
IncludeLaunchDescription(
79+
PythonLaunchDescriptionSource(
80+
os.path.join(ros_gz_sim_dir, 'launch', 'gz_sim.launch.py')
81+
),
82+
launch_arguments={'gz_args': ['-r -s ', world_sdf_xacro]}.items(),
83+
),
84+
IncludeLaunchDescription(
85+
PythonLaunchDescriptionSource(
86+
os.path.join(sim_dir, 'launch', 'spawn_tb3.launch.py')
87+
),
88+
launch_arguments={
89+
'use_sim_time': 'True',
90+
'robot_sdf': robot_sdf,
91+
'x_pose': '-2.0',
92+
'y_pose': '-0.5',
93+
'z_pose': '0.01',
94+
'roll': '0.0',
95+
'pitch': '0.0',
96+
'yaw': '0.0',
97+
}.items(),
7798
),
7899
Node(
79-
package='tf2_ros',
80-
executable='static_transform_publisher',
100+
package='robot_state_publisher',
101+
executable='robot_state_publisher',
102+
name='robot_state_publisher',
81103
output='screen',
82-
arguments=['0', '0', '0', '0', '0', '0', 'base_link', 'base_scan'],
104+
parameters=[
105+
{'use_sim_time': True, 'robot_description': robot_description}
106+
],
83107
),
84108
IncludeLaunchDescription(
85109
PythonLaunchDescriptionSource(
@@ -111,7 +135,9 @@ def main(argv=sys.argv[1:]):
111135
lts.add_test_action(ld, test1_action)
112136
ls = LaunchService(argv=argv)
113137
ls.include_launch_description(ld)
114-
return lts.run(ls)
138+
return_code = lts.run(ls)
139+
kill_os_processes('gz sim')
140+
return return_code
115141

116142

117143
if __name__ == '__main__':

0 commit comments

Comments
 (0)