Skip to content

Commit 6f697ad

Browse files
iserverobotics-bonaalexlin2
authored andcommitted
feat: add use_sim_time support to bagfile launch files
Enable proper TF synchronization when playing back bagfiles with ros2 bag play --clock. Defaults to true for bagfile mode.
1 parent c5bd6d1 commit 6f697ad

3 files changed

Lines changed: 29 additions & 5 deletions

File tree

src/base_autonomy/vehicle_simulator/launch/system_bagfile.launch.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22

33
from ament_index_python.packages import get_package_share_directory
44
from launch import LaunchDescription
5-
from launch.actions import DeclareLaunchArgument, IncludeLaunchDescription, TimerAction
5+
from launch.actions import DeclareLaunchArgument, IncludeLaunchDescription, SetParameter, TimerAction
66
from launch.launch_description_sources import FrontendLaunchDescriptionSource, PythonLaunchDescriptionSource
77
from launch_ros.actions import Node
8-
from launch.substitutions import LaunchConfiguration
8+
from launch.substitutions import LaunchConfiguration
99
from launch.conditions import IfCondition, UnlessCondition
1010

1111
def generate_launch_description():
12+
use_sim_time = LaunchConfiguration('use_sim_time')
1213
use_fastlio2 = LaunchConfiguration('use_fastlio2')
1314
world_name = LaunchConfiguration('world_name')
1415
sensorOffsetX = LaunchConfiguration('sensorOffsetX')
@@ -18,6 +19,11 @@ def generate_launch_description():
1819
vehicleY = LaunchConfiguration('vehicleY')
1920
checkTerrainConn = LaunchConfiguration('checkTerrainConn')
2021

22+
declare_use_sim_time = DeclareLaunchArgument(
23+
'use_sim_time',
24+
default_value='true',
25+
description='Use simulation clock for bagfile playback (default true for bagfile mode)'
26+
)
2127
declare_use_fastlio2 = DeclareLaunchArgument(
2228
'use_fastlio2',
2329
default_value='false',
@@ -104,6 +110,8 @@ def generate_launch_description():
104110
ld = LaunchDescription()
105111

106112
# Add the actions
113+
ld.add_action(declare_use_sim_time)
114+
ld.add_action(SetParameter(name='use_sim_time', value=use_sim_time))
107115
ld.add_action(declare_use_fastlio2)
108116
ld.add_action(declare_world_name)
109117
ld.add_action(declare_sensorOffsetX)

src/base_autonomy/vehicle_simulator/launch/system_bagfile_with_exploration_planner.launch.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22

33
from ament_index_python.packages import get_package_share_directory
44
from launch import LaunchDescription
5-
from launch.actions import DeclareLaunchArgument, IncludeLaunchDescription, TimerAction
5+
from launch.actions import DeclareLaunchArgument, IncludeLaunchDescription, SetParameter, TimerAction
66
from launch.launch_description_sources import FrontendLaunchDescriptionSource, PythonLaunchDescriptionSource
77
from launch_ros.actions import Node
8-
from launch.substitutions import LaunchConfiguration
8+
from launch.substitutions import LaunchConfiguration
99
from launch.conditions import IfCondition, UnlessCondition
1010

1111
def generate_launch_description():
12+
use_sim_time = LaunchConfiguration('use_sim_time')
1213
use_fastlio2 = LaunchConfiguration('use_fastlio2')
1314
exploration_planner_config = LaunchConfiguration('exploration_planner_config')
1415
world_name = LaunchConfiguration('world_name')
@@ -19,6 +20,11 @@ def generate_launch_description():
1920
vehicleY = LaunchConfiguration('vehicleY')
2021
checkTerrainConn = LaunchConfiguration('checkTerrainConn')
2122

23+
declare_use_sim_time = DeclareLaunchArgument(
24+
'use_sim_time',
25+
default_value='true',
26+
description='Use simulation clock for bagfile playback (default true for bagfile mode)'
27+
)
2228
declare_use_fastlio2 = DeclareLaunchArgument(
2329
'use_fastlio2',
2430
default_value='false',
@@ -114,6 +120,8 @@ def generate_launch_description():
114120
ld = LaunchDescription()
115121

116122
# Add the actions
123+
ld.add_action(declare_use_sim_time)
124+
ld.add_action(SetParameter(name='use_sim_time', value=use_sim_time))
117125
ld.add_action(declare_use_fastlio2)
118126
ld.add_action(declare_exploration_planner_config)
119127
ld.add_action(declare_world_name)

src/base_autonomy/vehicle_simulator/launch/system_bagfile_with_route_planner.launch.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22

33
from ament_index_python.packages import get_package_share_directory
44
from launch import LaunchDescription
5-
from launch.actions import DeclareLaunchArgument, IncludeLaunchDescription, TimerAction
5+
from launch.actions import DeclareLaunchArgument, IncludeLaunchDescription, SetParameter, TimerAction
66
from launch.launch_description_sources import FrontendLaunchDescriptionSource, PythonLaunchDescriptionSource
77
from launch_ros.actions import Node
88
from launch.substitutions import LaunchConfiguration, PathJoinSubstitution
99
from launch.conditions import IfCondition, UnlessCondition
1010
from launch_ros.substitutions import FindPackageShare
1111

1212
def generate_launch_description():
13+
use_sim_time = LaunchConfiguration('use_sim_time')
1314
use_fastlio2 = LaunchConfiguration('use_fastlio2')
1415
use_pct_planner = LaunchConfiguration('use_pct_planner')
1516
route_planner_config = LaunchConfiguration('route_planner_config')
@@ -21,6 +22,11 @@ def generate_launch_description():
2122
vehicleY = LaunchConfiguration('vehicleY')
2223
checkTerrainConn = LaunchConfiguration('checkTerrainConn')
2324

25+
declare_use_sim_time = DeclareLaunchArgument(
26+
'use_sim_time',
27+
default_value='true',
28+
description='Use simulation clock for bagfile playback (default true for bagfile mode)'
29+
)
2430
declare_use_fastlio2 = DeclareLaunchArgument(
2531
'use_fastlio2',
2632
default_value='false',
@@ -131,6 +137,8 @@ def generate_launch_description():
131137
ld = LaunchDescription()
132138

133139
# Add the actions
140+
ld.add_action(declare_use_sim_time)
141+
ld.add_action(SetParameter(name='use_sim_time', value=use_sim_time))
134142
ld.add_action(declare_use_fastlio2)
135143
ld.add_action(declare_use_pct_planner)
136144
ld.add_action(declare_route_planner_config)

0 commit comments

Comments
 (0)