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 builtin_interfaces .msg import Time as Stamp
24
23
from geometry_msgs .msg import Point
44
43
from tf2_ros import TransformException
45
44
from tf2_ros import TransformListener
46
45
from tf_transformations import euler_from_quaternion
46
+ from tier4_localization_msgs .srv import InitializeLocalization
47
47
from tier4_localization_msgs .srv import PoseWithCovarianceStamped as PoseWithCovarianceStampedSrv
48
48
import yaml
49
49
53
53
from driving_log_replayer .scenario import load_scenario
54
54
55
55
if TYPE_CHECKING :
56
- from autoware_adapi_v1_msgs .msg import ResponseStatus
56
+ from autoware_common_msgs .msg import ResponseStatus
57
57
58
58
59
59
class DLREvaluator (Node ):
@@ -107,9 +107,10 @@ def __init__(self, name: str, scenario_class: Callable, result_class: Callable)
107
107
self ._tf_buffer = Buffer ()
108
108
self ._tf_listener = TransformListener (self ._tf_buffer , self , spin_thread = True )
109
109
110
+ # initial pose estimation
110
111
self ._initial_pose_running : bool = False
111
112
self ._initial_pose_success : bool = False
112
- self ._initial_pose = self .set_initial_pose ()
113
+ self ._initial_pose , self . _initial_pose_method = self .set_initial_pose ()
113
114
self .start_initialpose_service ()
114
115
115
116
self ._current_time = Time ().to_msg ()
@@ -174,17 +175,20 @@ def start_initialpose_service(self) -> None:
174
175
return
175
176
self ._initial_pose_client = self .create_client (
176
177
InitializeLocalization ,
177
- "/api/ localization/initialize" ,
178
+ "/localization/initialize" ,
178
179
)
179
- self ._map_fit_client = self .create_client (
180
- PoseWithCovarianceStampedSrv ,
181
- "/map/map_height_fitter/service" ,
182
- )
183
-
184
180
while not self ._initial_pose_client .wait_for_service (timeout_sec = 1.0 ):
185
181
self .get_logger ().warning ("initial pose service not available, waiting again..." )
186
- while not self ._map_fit_client .wait_for_service (timeout_sec = 1.0 ):
187
- self .get_logger ().warning ("map height fitter service not available, waiting again..." )
182
+
183
+ if self ._initial_pose_method == InitializeLocalization .Request .AUTO :
184
+ self ._map_fit_client = self .create_client (
185
+ PoseWithCovarianceStampedSrv ,
186
+ "/map/map_height_fitter/service" ,
187
+ )
188
+ while not self ._map_fit_client .wait_for_service (timeout_sec = 1.0 ):
189
+ self .get_logger ().warning (
190
+ "map height fitter service not available, waiting again..." ,
191
+ )
188
192
189
193
def call_initialpose_service (self ) -> None :
190
194
if self ._initial_pose is None or self ._initial_pose_success or self ._initial_pose_running :
@@ -194,17 +198,29 @@ def call_initialpose_service(self) -> None:
194
198
)
195
199
self ._initial_pose_running = True
196
200
self ._initial_pose .header .stamp = self ._current_time
197
- future_map_fit = self ._map_fit_client .call_async (
198
- PoseWithCovarianceStampedSrv .Request (pose_with_covariance = self ._initial_pose ),
199
- )
200
- future_map_fit .add_done_callback (self .map_fit_cb )
201
+ if self ._initial_pose_method == InitializeLocalization .Request .AUTO :
202
+ future_map_fit = self ._map_fit_client .call_async (
203
+ PoseWithCovarianceStampedSrv .Request (pose_with_covariance = self ._initial_pose ),
204
+ )
205
+ future_map_fit .add_done_callback (self .map_fit_cb )
206
+ else :
207
+ future_direct_init_pose = self ._initial_pose_client .call_async (
208
+ InitializeLocalization .Request (
209
+ method = self ._initial_pose_method ,
210
+ pose_with_covariance = [self ._initial_pose ],
211
+ ),
212
+ )
213
+ future_direct_init_pose .add_done_callback (self .initial_pose_cb )
201
214
202
215
def map_fit_cb (self , future : Future ) -> None :
203
216
result = future .result ()
204
217
if result is not None :
205
218
if result .success :
206
219
future_init_pose = self ._initial_pose_client .call_async (
207
- InitializeLocalization .Request (pose = [result .pose_with_covariance ]),
220
+ InitializeLocalization .Request (
221
+ method = self ._initial_pose_method ,
222
+ pose_with_covariance = [result .pose_with_covariance ],
223
+ ),
208
224
)
209
225
future_init_pose .add_done_callback (self .initial_pose_cb )
210
226
else :
@@ -267,12 +283,17 @@ def transform_stamped_with_euler_angle(cls, transform_stamped: TransformStamped)
267
283
}
268
284
return tf_euler
269
285
270
- def set_initial_pose (self ) -> PoseWithCovarianceStamped | None :
271
- if not hasattr (self ._scenario .Evaluation , "InitialPose" ):
272
- return None
273
- if self ._scenario .Evaluation .InitialPose is None :
274
- return None
275
- initial_pose : InitialPose = self ._scenario .Evaluation .InitialPose
286
+ def set_initial_pose (self ) -> tuple [PoseWithCovarianceStamped | None , int | None ]:
287
+ auto_pose = getattr (self ._scenario .Evaluation , "InitialPose" , None )
288
+ direct_pose = getattr (self ._scenario .Evaluation , "DirectInitialPose" , None )
289
+ if auto_pose is None and direct_pose is None :
290
+ return None , None
291
+ if auto_pose is not None :
292
+ initial_pose : InitialPose = auto_pose
293
+ pose_method : int = InitializeLocalization .Request .AUTO
294
+ if direct_pose is not None :
295
+ initial_pose : InitialPose = direct_pose
296
+ pose_method : int = InitializeLocalization .Request .DIRECT
276
297
covariance = np .array (
277
298
[
278
299
0.25 ,
@@ -320,7 +341,7 @@ def set_initial_pose(self) -> PoseWithCovarianceStamped | None:
320
341
),
321
342
covariance = covariance ,
322
343
)
323
- return PoseWithCovarianceStamped (header = Header (frame_id = "map" ), pose = pose )
344
+ return PoseWithCovarianceStamped (header = Header (frame_id = "map" ), pose = pose ), pose_method
324
345
325
346
@classmethod
326
347
def get_perception_label_str (cls , classification : ObjectClassification ) -> str :
0 commit comments