Skip to content

Commit 0b6feb4

Browse files
authored
feat: add time filter (#342)
* feat: add time filter Signed-off-by: MasatoSaeki <masato.saeki@tier4.jp> * reset original params Signed-off-by: MasatoSaeki <masato.saeki@tier4.jp> * chore Signed-off-by: MasatoSaeki <masato.saeki@tier4.jp> --------- Signed-off-by: MasatoSaeki <masato.saeki@tier4.jp>
1 parent 88d86c8 commit 0b6feb4

4 files changed

Lines changed: 43 additions & 0 deletions

File tree

docs/scenario_format/index.en.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Evaluation:
4444
DirectInitialPose: Dictionary # optional; omit this key or use {} to disable the pose
4545
GoalPose: Dictionary # optional; omit this key or use {} to disable the pose
4646
goal_method: String # optional, default: set_goal_from_scenario
47+
time_offset: Dictionary # optional, default: {}
4748
include_use_case:
4849
UseCaseName: String
4950
UseCaseFormatVersion: String
@@ -185,6 +186,16 @@ GoalPose:
185186
| `set_goal_from_scenario` | (Default) Use `GoalPose` from scenario to set goal. Skip setting goal if `GoalPose` is not specified. |
186187
| `set_goal_from_rosbag` | Read the last `/localization/kinematic_state` from rosbag and use its position as the goal. Even if `GoalPose` is specified ignore it. |
187188

189+
#### time_offset
190+
191+
(Optional) Specify the start time and duration of rosbag playback. The start time is specified as a relative time from the start of the rosbag, not based on timestamp. Place it at the same level as `GoalPose` in the dataset section of the scenario YAML.
192+
193+
```yaml
194+
time_offset:
195+
start: float # the start time [s]
196+
duration: float # the duration [s]
197+
```
198+
188199
### include_use_case
189200

190201
Use this when you want to perform evaluation with a different use case simultaneously with the use case specified in Evaluation.

docs/scenario_format/index.ja.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Evaluation:
4444
DirectInitialPose: Dictionary # optional, 省略時は {} として扱われる (無効化する場合はキーを省略するか {} を指定すること)
4545
GoalPose: Dictionary # optional, 省略時は {} として扱われる (無効化する場合はキーを省略するか {} を指定すること)
4646
goal_method: String # optional, default: set_goal_from_scenario
47+
time_offset: Dictionary # optional, default: {}
4748
include_use_case:
4849
UseCaseName: String
4950
UseCaseFormatVersion: String
@@ -184,6 +185,16 @@ GoalPose:
184185
| `set_goal_from_scenario` | (デフォルト)シナリオの `GoalPose` を使用してゴールを設定する。`GoalPose` が未指定の場合は何もしない。 |
185186
| `set_goal_from_rosbag` | rosbagの最後の `/localization/kinematic_state` を読み取り、その位置をゴールとして使用する。 `GoalPose` が指定されていても無視する。 |
186187

188+
#### time_offset
189+
190+
(オプション)rosbagの再生開始時刻と再生時間を指定する。前者はtimestamp基準ではなく、rosbagの開始からの相対時間で指定する。シナリオYAMLのデータセットセクションで `GoalPose` と同じ階層に配置する。
191+
192+
```yaml
193+
time_offset:
194+
start: float # rosbag再生開始時刻 [s]
195+
duration: float # rosbag再生時間 [s]
196+
```
197+
187198
### include_use_case
188199

189200
Evaluationで指定したユースケースとは別のユースケースの評価を同時に行う場合に使用する。

driving_log_replayer_v2/driving_log_replayer_v2/launch/argument.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ def update_conf_with_dataset_info(
232232
conf["direct_initial_pose"] = json.dumps(dataset_info.get("DirectInitialPose", {}))
233233
conf["goal_pose"] = json.dumps(dataset_info.get("GoalPose", {}))
234234
conf["goal_method"] = dataset_info.get("goal_method", "set_goal_from_scenario")
235+
conf["time_offset"] = json.dumps(dataset_info.get("time_offset", {}))
235236
conf["t4_dataset_path"] = t4_dataset_path.as_posix()
236237
if "vehicle_model" not in conf:
237238
conf["vehicle_model"] = yaml_obj["VehicleModel"]
@@ -299,6 +300,9 @@ def ensure_arg_compatibility(context: LaunchContext) -> list:
299300
LogInfo(
300301
msg=f"{check_launch_component(conf)=}",
301302
),
303+
LogInfo(
304+
msg=f"{conf['time_offset']=}",
305+
),
302306
LogInfo(
303307
msg=f"{conf['initial_pose']=}, {conf['direct_initial_pose']=}",
304308
),

driving_log_replayer_v2/driving_log_replayer_v2/launch/rosbag.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414

1515
from importlib import import_module
16+
import json
1617
from pathlib import Path
1718

1819
from ament_index_python.packages import get_package_prefix
@@ -139,6 +140,20 @@ def get_pre_task_before_play_rosbag(
139140
)
140141

141142

143+
def get_rosbag_timestamp_offset(play_cmd: list[str], context: LaunchContext) -> list[str]:
144+
conf = context.launch_configurations
145+
if conf["time_offset"] == "{}":
146+
return play_cmd
147+
time_offset = json.loads(conf["time_offset"])
148+
start = time_offset.get("start", None)
149+
if start is not None:
150+
play_cmd.extend(["--start-offset", str(start)])
151+
duration = time_offset.get("duration", None)
152+
if duration is not None:
153+
play_cmd = ["timeout", "--preserve-status", str(duration), *play_cmd]
154+
return play_cmd
155+
156+
142157
def launch_bag_player(
143158
context: LaunchContext,
144159
) -> IncludeLaunchDescription:
@@ -155,6 +170,8 @@ def launch_bag_player(
155170
"--qos-profile-overrides-path",
156171
QOS_PROFILE_PATH_STR,
157172
]
173+
# timestamp offset
174+
play_cmd = get_rosbag_timestamp_offset(play_cmd, context)
158175
# topics
159176
publish_list = ["--topics"]
160177
publish_list.extend(user_defined_publish(conf))

0 commit comments

Comments
 (0)