18
18
from typing import Any
19
19
from typing import TYPE_CHECKING
20
20
21
- from autoware_adapi_v1_msgs .srv import InitializeLocalization
22
21
from autoware_auto_perception_msgs .msg import ObjectClassification
23
22
from autoware_auto_perception_msgs .msg import TrafficLight
24
23
from builtin_interfaces .msg import Time as Stamp
45
44
from tf2_ros import TransformException
46
45
from tf2_ros import TransformListener
47
46
from tf_transformations import euler_from_quaternion
48
- from tier4_localization_msgs .srv import InitializeLocalization as T4InitializeLocalization
47
+ from tier4_localization_msgs .srv import InitializeLocalization
49
48
from tier4_localization_msgs .srv import PoseWithCovarianceStamped as PoseWithCovarianceStampedSrv
50
49
import yaml
51
50
55
54
from driving_log_replayer .scenario import load_scenario
56
55
57
56
if TYPE_CHECKING :
58
- from autoware_adapi_v1_msgs .msg import ResponseStatus
59
- from autoware_common_msgs .msg import ResponseStatus as CommonResponseStatus
57
+ from autoware_common_msgs .msg import ResponseStatus
60
58
61
59
62
60
class DLREvaluator (Node ):
@@ -113,15 +111,9 @@ def __init__(self, name: str, scenario_class: Callable, result_class: Callable)
113
111
# initial pose estimation
114
112
self ._initial_pose_running : bool = False
115
113
self ._initial_pose_success : bool = False
116
- self ._initial_pose = self .set_initial_pose ()
114
+ self ._initial_pose , self . _initial_pose_method = self .set_initial_pose ()
117
115
self .start_initialpose_service ()
118
116
119
- # initial pose estimation
120
- self ._direct_initial_pose_running : bool = False
121
- self ._direct_initial_pose_success : bool = False
122
- self ._direct_initial_pose = self .set_direct_initial_pose ()
123
- self .start_direct_initialpose_service ()
124
-
125
117
self ._current_time = Time ().to_msg ()
126
118
self ._prev_time = Time ().to_msg ()
127
119
self ._clock_stop_counter = 0
@@ -169,8 +161,6 @@ def timer_cb(
169
161
register_loop_func ()
170
162
if self ._initial_pose is not None :
171
163
self .call_initialpose_service ()
172
- if self ._direct_initial_pose is not None :
173
- self .call_direct_initialpose_service ()
174
164
self ._clock_stop_counter = (
175
165
self ._clock_stop_counter + 1 if self ._current_time == self ._prev_time else 0
176
166
)
@@ -186,29 +176,20 @@ def start_initialpose_service(self) -> None:
186
176
return
187
177
self ._initial_pose_client = self .create_client (
188
178
InitializeLocalization ,
189
- "/api/localization/initialize" ,
190
- )
191
- self ._map_fit_client = self .create_client (
192
- PoseWithCovarianceStampedSrv ,
193
- "/map/map_height_fitter/service" ,
179
+ "/localization/initialize" ,
194
180
)
195
-
196
181
while not self ._initial_pose_client .wait_for_service (timeout_sec = 1.0 ):
197
182
self .get_logger ().warning ("initial pose service not available, waiting again..." )
198
- while not self ._map_fit_client .wait_for_service (timeout_sec = 1.0 ):
199
- self .get_logger ().warning ("map height fitter service not available, waiting again..." )
200
183
201
- def start_direct_initialpose_service (self ) -> None :
202
- self .get_logger ().info ("start direct initialpose service" )
203
- if self ._direct_initial_pose is None :
204
- return
205
- self ._direct_initial_pose_client = self .create_client (
206
- T4InitializeLocalization ,
207
- "/localization/initialize" ,
208
- )
209
-
210
- while not self ._direct_initial_pose_client .wait_for_service (timeout_sec = 1.0 ):
211
- self .get_logger ().warning ("direct initial pose service not available, waiting again..." )
184
+ if self ._initial_pose_method == InitializeLocalization .Request .AUTO :
185
+ self ._map_fit_client = self .create_client (
186
+ PoseWithCovarianceStampedSrv ,
187
+ "/map/map_height_fitter/service" ,
188
+ )
189
+ while not self ._map_fit_client .wait_for_service (timeout_sec = 1.0 ):
190
+ self .get_logger ().warning (
191
+ "map height fitter service not available, waiting again..." ,
192
+ )
212
193
213
194
def call_initialpose_service (self ) -> None :
214
195
if self ._initial_pose is None or self ._initial_pose_success or self ._initial_pose_running :
@@ -218,17 +199,29 @@ def call_initialpose_service(self) -> None:
218
199
)
219
200
self ._initial_pose_running = True
220
201
self ._initial_pose .header .stamp = self ._current_time
221
- future_map_fit = self ._map_fit_client .call_async (
222
- PoseWithCovarianceStampedSrv .Request (pose_with_covariance = self ._initial_pose ),
223
- )
224
- future_map_fit .add_done_callback (self .map_fit_cb )
202
+ if self ._initial_pose_method == InitializeLocalization .Request .AUTO :
203
+ future_map_fit = self ._map_fit_client .call_async (
204
+ PoseWithCovarianceStampedSrv .Request (pose_with_covariance = self ._initial_pose ),
205
+ )
206
+ future_map_fit .add_done_callback (self .map_fit_cb )
207
+ else :
208
+ future_direct_init_pose = self ._initial_pose_client .call_async (
209
+ InitializeLocalization .Request (
210
+ method = self ._initial_pose_method ,
211
+ pose_with_covariance = [self ._initial_pose ],
212
+ ),
213
+ )
214
+ future_direct_init_pose .add_done_callback (self .initial_pose_cb )
225
215
226
216
def map_fit_cb (self , future : Future ) -> None :
227
217
result = future .result ()
228
218
if result is not None :
229
219
if result .success :
230
220
future_init_pose = self ._initial_pose_client .call_async (
231
- InitializeLocalization .Request (pose = [result .pose_with_covariance ]),
221
+ InitializeLocalization .Request (
222
+ method = self ._initial_pose_method ,
223
+ pose_with_covariance = [result .pose_with_covariance ],
224
+ ),
232
225
)
233
226
future_init_pose .add_done_callback (self .initial_pose_cb )
234
227
else :
@@ -240,26 +233,6 @@ def map_fit_cb(self, future: Future) -> None:
240
233
self ._initial_pose_running = False
241
234
self .get_logger ().error (f"Exception for service: { future .exception ()} " )
242
235
243
- def call_direct_initialpose_service (self ) -> None :
244
- if (
245
- self ._direct_initial_pose is None
246
- or self ._direct_initial_pose_success
247
- or self ._direct_initial_pose_running
248
- ):
249
- return
250
- self .get_logger ().info (
251
- f"call direct initial_pose time: { self ._current_time .sec } .{ self ._current_time .nanosec } " ,
252
- )
253
- self ._direct_initial_pose_running = True
254
- self ._direct_initial_pose .header .stamp = self ._current_time
255
- future_direct_init_pose = self ._direct_initial_pose_client .call_async (
256
- T4InitializeLocalization .Request (
257
- method = T4InitializeLocalization .Request .DIRECT ,
258
- pose_with_covariance = [self ._direct_initial_pose ],
259
- ),
260
- )
261
- future_direct_init_pose .add_done_callback (self .direct_initial_pose_cb )
262
-
263
236
def initial_pose_cb (self , future : Future ) -> None :
264
237
result = future .result ()
265
238
if result is not None :
@@ -273,19 +246,6 @@ def initial_pose_cb(self, future: Future) -> None:
273
246
# free self._initial_pose_running
274
247
self ._initial_pose_running = False
275
248
276
- def direct_initial_pose_cb (self , future : Future ) -> None :
277
- result = future .result ()
278
- if result is not None :
279
- res_status : CommonResponseStatus = result .status
280
- self ._direct_initial_pose_success = res_status .success
281
- self .get_logger ().info (
282
- f"direct_initial_pose_success: { self ._initial_pose_success } " ,
283
- ) # debug msg
284
- else :
285
- self .get_logger ().error (f"Exception for service: { future .exception ()} " )
286
- # free self._initial_pose_running
287
- self ._direct_initial_pose_running = False
288
-
289
249
def lookup_transform (
290
250
self ,
291
251
stamp : Stamp ,
@@ -324,67 +284,17 @@ def transform_stamped_with_euler_angle(cls, transform_stamped: TransformStamped)
324
284
}
325
285
return tf_euler
326
286
327
- def set_initial_pose (self ) -> PoseWithCovarianceStamped | None :
328
- if not hasattr (self ._scenario .Evaluation , "InitialPose" ):
329
- return None
330
- if self ._scenario .Evaluation .InitialPose is None :
331
- return None
332
- initial_pose : InitialPose = self ._scenario .Evaluation .InitialPose
333
- covariance = np .array (
334
- [
335
- 0.25 ,
336
- 0.0 ,
337
- 0.0 ,
338
- 0.0 ,
339
- 0.0 ,
340
- 0.0 ,
341
- 0.0 ,
342
- 0.25 ,
343
- 0.0 ,
344
- 0.0 ,
345
- 0.0 ,
346
- 0.0 ,
347
- 0.0 ,
348
- 0.0 ,
349
- 0.0 ,
350
- 0.0 ,
351
- 0.0 ,
352
- 0.0 ,
353
- 0.0 ,
354
- 0.0 ,
355
- 0.0 ,
356
- 0.0 ,
357
- 0.0 ,
358
- 0.0 ,
359
- 0.0 ,
360
- 0.0 ,
361
- 0.0 ,
362
- 0.0 ,
363
- 0.0 ,
364
- 0.0 ,
365
- 0.0 ,
366
- 0.0 ,
367
- 0.0 ,
368
- 0.0 ,
369
- 0.0 ,
370
- 0.06853892326654787 ,
371
- ],
372
- )
373
- pose = PoseWithCovariance (
374
- pose = Pose (
375
- position = Point (** initial_pose .position .model_dump ()),
376
- orientation = Quaternion (** initial_pose .orientation .model_dump ()),
377
- ),
378
- covariance = covariance ,
379
- )
380
- return PoseWithCovarianceStamped (header = Header (frame_id = "map" ), pose = pose )
381
-
382
- def set_direct_initial_pose (self ) -> PoseWithCovarianceStamped | None :
383
- if not hasattr (self ._scenario .Evaluation , "DirectInitialPose" ):
384
- return None
385
- if self ._scenario .Evaluation .DirectInitialPose is None :
386
- return None
387
- initial_pose : InitialPose = self ._scenario .Evaluation .DirectInitialPose
287
+ def set_initial_pose (self ) -> tuple [PoseWithCovarianceStamped | None , int | None ]:
288
+ auto_pose = getattr (self ._scenario .Evaluation , "InitialPose" , None )
289
+ direct_pose = getattr (self ._scenario .Evaluation , "DirectInitialPose" , None )
290
+ if auto_pose is None and direct_pose is None :
291
+ return None , None
292
+ if auto_pose is not None :
293
+ initial_pose : InitialPose = auto_pose
294
+ pose_method : int = InitializeLocalization .Request .AUTO
295
+ if direct_pose is not None :
296
+ initial_pose : InitialPose = direct_pose
297
+ pose_method : int = InitializeLocalization .Request .DIRECT
388
298
covariance = np .array (
389
299
[
390
300
0.25 ,
@@ -432,7 +342,7 @@ def set_direct_initial_pose(self) -> PoseWithCovarianceStamped | None:
432
342
),
433
343
covariance = covariance ,
434
344
)
435
- return PoseWithCovarianceStamped (header = Header (frame_id = "map" ), pose = pose )
345
+ return PoseWithCovarianceStamped (header = Header (frame_id = "map" ), pose = pose ), pose_method
436
346
437
347
@classmethod
438
348
def get_perception_label_str (cls , classification : ObjectClassification ) -> str :
0 commit comments