@@ -253,6 +253,68 @@ double mean(const double a, const double b)
253
253
return (a + b) / 2.0 ;
254
254
}
255
255
256
+ /* *
257
+ * @brief compare two tracked objects motion direction is same or not
258
+ *
259
+ * @param main_obj
260
+ * @param sub_obj
261
+ * @return true
262
+ * @return false
263
+ */
264
+ bool objectsHaveSameMotionDirections (const TrackedObject & main_obj, const TrackedObject & sub_obj)
265
+ {
266
+ // get yaw
267
+ const auto main_yaw = tf2::getYaw (main_obj.kinematics .pose_with_covariance .pose .orientation );
268
+ const auto sub_yaw = tf2::getYaw (sub_obj.kinematics .pose_with_covariance .pose .orientation );
269
+ // get velocity
270
+ const auto main_vx = main_obj.kinematics .twist_with_covariance .twist .linear .x ;
271
+ const auto main_vy = main_obj.kinematics .twist_with_covariance .twist .linear .y ;
272
+ const auto sub_vx = sub_obj.kinematics .twist_with_covariance .twist .linear .x ;
273
+ const auto sub_vy = sub_obj.kinematics .twist_with_covariance .twist .linear .y ;
274
+ // calc velocity direction
275
+ const auto main_vyaw = std::atan2 (main_vy, main_vx);
276
+ const auto sub_vyaw = std::atan2 (sub_vy, sub_vx);
277
+ // get motion yaw angle
278
+ const auto main_motion_yaw = main_yaw + main_vyaw;
279
+ const auto sub_motion_yaw = sub_yaw + sub_vyaw;
280
+ // diff of motion yaw angle
281
+ const auto motion_yaw_diff = std::fabs (main_motion_yaw - sub_motion_yaw);
282
+ const auto normalized_motion_yaw_diff =
283
+ tier4_autoware_utils::normalizeRadian (motion_yaw_diff); // -pi ~ pi
284
+ // evaluate if motion yaw angle is same
285
+ constexpr double yaw_threshold = M_PI / 4.0 ; // 45 deg
286
+ if (std::abs (normalized_motion_yaw_diff) < yaw_threshold) {
287
+ return true ;
288
+ } else {
289
+ return false ;
290
+ }
291
+ }
292
+
293
+ /* *
294
+ * @brief compare two tracked objects yaw is reverted or not
295
+ *
296
+ * @param main_obj
297
+ * @param sub_obj
298
+ * @return true
299
+ * @return false
300
+ */
301
+ bool objectsYawIsReverted (const TrackedObject & main_obj, const TrackedObject & sub_obj)
302
+ {
303
+ // get yaw
304
+ const auto main_yaw = tf2::getYaw (main_obj.kinematics .pose_with_covariance .pose .orientation );
305
+ const auto sub_yaw = tf2::getYaw (sub_obj.kinematics .pose_with_covariance .pose .orientation );
306
+ // calc yaw diff
307
+ const auto yaw_diff = std::fabs (main_yaw - sub_yaw);
308
+ const auto normalized_yaw_diff = tier4_autoware_utils::normalizeRadian (yaw_diff); // -pi ~ pi
309
+ // evaluate if yaw is reverted
310
+ constexpr double yaw_threshold = M_PI / 2.0 ; // 90 deg
311
+ if (std::abs (normalized_yaw_diff) >= yaw_threshold) {
312
+ return true ;
313
+ } else {
314
+ return false ;
315
+ }
316
+ }
317
+
256
318
// object kinematics merger
257
319
// currently only support velocity fusion
258
320
autoware_auto_perception_msgs::msg::TrackedObjectKinematics objectKinematicsVXMerger (
@@ -261,18 +323,29 @@ autoware_auto_perception_msgs::msg::TrackedObjectKinematics objectKinematicsVXMe
261
323
autoware_auto_perception_msgs::msg::TrackedObjectKinematics output_kinematics;
262
324
// copy main object at first
263
325
output_kinematics = main_obj.kinematics ;
326
+ auto sub_obj_ = sub_obj;
327
+ // do not merge reverse direction objects
328
+ if (!objectsHaveSameMotionDirections (main_obj, sub_obj)) {
329
+ return output_kinematics;
330
+ } else if (objectsYawIsReverted (main_obj, sub_obj)) {
331
+ // revert velocity (revert pose is not necessary because it is not used in tracking)
332
+ sub_obj_.kinematics .twist_with_covariance .twist .linear .x *= -1.0 ;
333
+ sub_obj_.kinematics .twist_with_covariance .twist .linear .y *= -1.0 ;
334
+ }
335
+
336
+ // currently only merge vx
264
337
if (policy == MergePolicy::SKIP) {
265
338
return output_kinematics;
266
339
} else if (policy == MergePolicy::OVERWRITE) {
267
340
output_kinematics.twist_with_covariance .twist .linear .x =
268
- sub_obj .kinematics .twist_with_covariance .twist .linear .x ;
341
+ sub_obj_ .kinematics .twist_with_covariance .twist .linear .x ;
269
342
return output_kinematics;
270
343
} else if (policy == MergePolicy::FUSION) {
271
344
const auto main_vx = main_obj.kinematics .twist_with_covariance .twist .linear .x ;
272
- const auto sub_vx = sub_obj .kinematics .twist_with_covariance .twist .linear .x ;
345
+ const auto sub_vx = sub_obj_ .kinematics .twist_with_covariance .twist .linear .x ;
273
346
// inverse weight
274
347
const auto main_vx_cov = main_obj.kinematics .twist_with_covariance .covariance [0 ];
275
- const auto sub_vx_cov = sub_obj .kinematics .twist_with_covariance .covariance [0 ];
348
+ const auto sub_vx_cov = sub_obj_ .kinematics .twist_with_covariance .covariance [0 ];
276
349
double main_vx_weight, sub_vx_weight;
277
350
if (main_vx_cov == 0.0 ) {
278
351
main_vx_weight = 1.0 * 1e6 ;
@@ -380,9 +453,21 @@ autoware_auto_perception_msgs::msg::Shape shapeMerger(
380
453
381
454
void updateExceptVelocity (TrackedObject & main_obj, const TrackedObject & sub_obj)
382
455
{
383
- const auto vx_temp = main_obj.kinematics .twist_with_covariance .twist .linear .x ;
384
- main_obj = sub_obj;
385
- main_obj.kinematics .twist_with_covariance .twist .linear .x = vx_temp;
456
+ if (!objectsHaveSameMotionDirections (main_obj, sub_obj)) {
457
+ // do not update velocity
458
+ return ;
459
+ } else if (objectsYawIsReverted (main_obj, sub_obj)) {
460
+ // revert velocity (revert pose is not necessary because it is not used in tracking)
461
+ const auto vx_temp = sub_obj.kinematics .twist_with_covariance .twist .linear .x ;
462
+ main_obj = sub_obj;
463
+ main_obj.kinematics .twist_with_covariance .twist .linear .x = -vx_temp;
464
+ return ;
465
+ } else {
466
+ // update velocity
467
+ const auto vx_temp = sub_obj.kinematics .twist_with_covariance .twist .linear .x ;
468
+ main_obj = sub_obj;
469
+ main_obj.kinematics .twist_with_covariance .twist .linear .x = vx_temp;
470
+ }
386
471
}
387
472
388
473
void updateOnlyObjectVelocity (TrackedObject & main_obj, const TrackedObject & sub_obj)
@@ -397,6 +482,12 @@ void updateOnlyClassification(TrackedObject & main_obj, const TrackedObject & su
397
482
398
483
void updateWholeTrackedObject (TrackedObject & main_obj, const TrackedObject & sub_obj)
399
484
{
485
+ if (!objectsHaveSameMotionDirections (main_obj, sub_obj)) {
486
+ // warning
487
+ std::cerr << " [object_tracking_merger]: motion direction is different in "
488
+ " updateWholeTrackedObject function."
489
+ << std::endl;
490
+ }
400
491
main_obj = sub_obj;
401
492
}
402
493
0 commit comments