@@ -232,6 +232,17 @@ void EKFLocalizer::timerCallback()
232
232
}
233
233
twist_no_update_count_ = twist_is_updated ? 0 : (twist_no_update_count_ + 1 );
234
234
235
+ const geometry_msgs::msg::PoseStamped current_ekf_pose = getCurrentEKFPose (false );
236
+ const geometry_msgs::msg::PoseStamped current_biased_ekf_pose = getCurrentEKFPose (true );
237
+ const geometry_msgs::msg::TwistStamped current_ekf_twist = getCurrentEKFTwist ();
238
+
239
+ /* publish ekf result */
240
+ publishEstimateResult (current_ekf_pose, current_biased_ekf_pose, current_ekf_twist);
241
+ publishDiagnostics ();
242
+ }
243
+
244
+ geometry_msgs::msg::PoseStamped EKFLocalizer::getCurrentEKFPose (bool get_biased_yaw) const
245
+ {
235
246
const double x = ekf_.getXelement (IDX::X);
236
247
const double y = ekf_.getXelement (IDX::Y);
237
248
const double z = z_filter_.get_x ();
@@ -242,27 +253,32 @@ void EKFLocalizer::timerCallback()
242
253
const double roll = roll_filter_.get_x ();
243
254
const double pitch = pitch_filter_.get_x ();
244
255
const double yaw = biased_yaw + yaw_bias;
245
- const double vx = ekf_.getXelement (IDX::VX);
246
- const double wz = ekf_.getXelement (IDX::WZ);
247
-
248
- current_ekf_pose_.header .frame_id = params_.pose_frame_id ;
249
- current_ekf_pose_.header .stamp = this ->now ();
250
- current_ekf_pose_.pose .position = tier4_autoware_utils::createPoint (x, y, z);
251
- current_ekf_pose_.pose .orientation =
252
- tier4_autoware_utils::createQuaternionFromRPY (roll, pitch, yaw);
253
256
254
- current_biased_ekf_pose_ = current_ekf_pose_;
255
- current_biased_ekf_pose_.pose .orientation =
256
- tier4_autoware_utils::createQuaternionFromRPY (roll, pitch, biased_yaw);
257
+ geometry_msgs::msg::PoseStamped current_ekf_pose;
258
+ current_ekf_pose.header .frame_id = params_.pose_frame_id ;
259
+ current_ekf_pose.header .stamp = this ->now ();
260
+ current_ekf_pose.pose .position = tier4_autoware_utils::createPoint (x, y, z);
261
+ if (get_biased_yaw) {
262
+ current_ekf_pose.pose .orientation =
263
+ tier4_autoware_utils::createQuaternionFromRPY (roll, pitch, biased_yaw);
264
+ } else {
265
+ current_ekf_pose.pose .orientation =
266
+ tier4_autoware_utils::createQuaternionFromRPY (roll, pitch, yaw);
267
+ }
268
+ return current_ekf_pose;
269
+ }
257
270
258
- current_ekf_twist_. header . frame_id = " base_link " ;
259
- current_ekf_twist_. header . stamp = this -> now ();
260
- current_ekf_twist_. twist . linear . x = vx;
261
- current_ekf_twist_. twist . angular . z = wz;
271
+ geometry_msgs::msg::TwistStamped EKFLocalizer::getCurrentEKFTwist () const
272
+ {
273
+ const double vx = ekf_. getXelement (IDX::VX) ;
274
+ const double wz = ekf_. getXelement (IDX::WZ) ;
262
275
263
- /* publish ekf result */
264
- publishEstimateResult ();
265
- publishDiagnostics ();
276
+ geometry_msgs::msg::TwistStamped current_ekf_twist;
277
+ current_ekf_twist.header .frame_id = " base_link" ;
278
+ current_ekf_twist.header .stamp = this ->now ();
279
+ current_ekf_twist.twist .linear .x = vx;
280
+ current_ekf_twist.twist .angular .z = wz;
281
+ return current_ekf_twist;
266
282
}
267
283
268
284
void EKFLocalizer::showCurrentX ()
@@ -282,12 +298,12 @@ void EKFLocalizer::timerTFCallback()
282
298
return ;
283
299
}
284
300
285
- if (current_ekf_pose_. header . frame_id == " " ) {
301
+ if (params_. pose_frame_id == " " ) {
286
302
return ;
287
303
}
288
304
289
305
geometry_msgs::msg::TransformStamped transform_stamped;
290
- transform_stamped = tier4_autoware_utils::pose2transform (current_ekf_pose_ , " base_link" );
306
+ transform_stamped = tier4_autoware_utils::pose2transform (getCurrentEKFPose ( false ) , " base_link" );
291
307
transform_stamped.header .stamp = this ->now ();
292
308
tf_br_->sendTransform (transform_stamped);
293
309
}
@@ -338,8 +354,6 @@ void EKFLocalizer::callbackInitialPose(
338
354
339
355
X (IDX::X) = initialpose->pose .pose .position .x + transform.transform .translation .x ;
340
356
X (IDX::Y) = initialpose->pose .pose .position .y + transform.transform .translation .y ;
341
- current_ekf_pose_.pose .position .z =
342
- initialpose->pose .pose .position .z + transform.transform .translation .z ;
343
357
X (IDX::YAW) =
344
358
tf2::getYaw (initialpose->pose .pose .orientation ) + tf2::getYaw (transform.transform .rotation );
345
359
X (IDX::YAWB) = 0.0 ;
@@ -488,7 +502,7 @@ bool EKFLocalizer::measurementUpdatePose(const geometry_msgs::msg::PoseWithCovar
488
502
489
503
// Considering change of z value due to measurement pose delay
490
504
const auto rpy = tier4_autoware_utils::getRPY (pose.pose .pose .orientation );
491
- const double dz_delay = current_ekf_twist_. twist . linear . x * delay_time * std::sin (-rpy.y );
505
+ const double dz_delay = ekf_. getXelement (IDX::VX) * delay_time * std::sin (-rpy.y );
492
506
geometry_msgs::msg::PoseWithCovarianceStamped pose_with_z_delay;
493
507
pose_with_z_delay = pose;
494
508
pose_with_z_delay.pose .pose .position .z += dz_delay;
@@ -586,36 +600,39 @@ bool EKFLocalizer::measurementUpdateTwist(
586
600
/*
587
601
* publishEstimateResult
588
602
*/
589
- void EKFLocalizer::publishEstimateResult ()
603
+ void EKFLocalizer::publishEstimateResult (
604
+ const geometry_msgs::msg::PoseStamped & current_ekf_pose,
605
+ const geometry_msgs::msg::PoseStamped & current_biased_ekf_pose,
606
+ const geometry_msgs::msg::TwistStamped & current_ekf_twist)
590
607
{
591
608
rclcpp::Time current_time = this ->now ();
592
609
const Eigen::MatrixXd X = ekf_.getLatestX ();
593
610
const Eigen::MatrixXd P = ekf_.getLatestP ();
594
611
595
612
/* publish latest pose */
596
- pub_pose_->publish (current_ekf_pose_ );
597
- pub_biased_pose_->publish (current_biased_ekf_pose_ );
613
+ pub_pose_->publish (current_ekf_pose );
614
+ pub_biased_pose_->publish (current_biased_ekf_pose );
598
615
599
616
/* publish latest pose with covariance */
600
617
geometry_msgs::msg::PoseWithCovarianceStamped pose_cov;
601
618
pose_cov.header .stamp = current_time;
602
- pose_cov.header .frame_id = current_ekf_pose_ .header .frame_id ;
603
- pose_cov.pose .pose = current_ekf_pose_ .pose ;
619
+ pose_cov.header .frame_id = current_ekf_pose .header .frame_id ;
620
+ pose_cov.pose .pose = current_ekf_pose .pose ;
604
621
pose_cov.pose .covariance = ekfCovarianceToPoseMessageCovariance (P);
605
622
pub_pose_cov_->publish (pose_cov);
606
623
607
624
geometry_msgs::msg::PoseWithCovarianceStamped biased_pose_cov = pose_cov;
608
- biased_pose_cov.pose .pose = current_biased_ekf_pose_ .pose ;
625
+ biased_pose_cov.pose .pose = current_biased_ekf_pose .pose ;
609
626
pub_biased_pose_cov_->publish (biased_pose_cov);
610
627
611
628
/* publish latest twist */
612
- pub_twist_->publish (current_ekf_twist_ );
629
+ pub_twist_->publish (current_ekf_twist );
613
630
614
631
/* publish latest twist with covariance */
615
632
geometry_msgs::msg::TwistWithCovarianceStamped twist_cov;
616
633
twist_cov.header .stamp = current_time;
617
- twist_cov.header .frame_id = current_ekf_twist_ .header .frame_id ;
618
- twist_cov.twist .twist = current_ekf_twist_ .twist ;
634
+ twist_cov.header .frame_id = current_ekf_twist .header .frame_id ;
635
+ twist_cov.twist .twist = current_ekf_twist .twist ;
619
636
twist_cov.twist .covariance = ekfCovarianceToTwistMessageCovariance (P);
620
637
pub_twist_cov_->publish (twist_cov);
621
638
@@ -628,7 +645,7 @@ void EKFLocalizer::publishEstimateResult()
628
645
/* publish latest odometry */
629
646
nav_msgs::msg::Odometry odometry;
630
647
odometry.header .stamp = current_time;
631
- odometry.header .frame_id = current_ekf_pose_ .header .frame_id ;
648
+ odometry.header .frame_id = current_ekf_pose .header .frame_id ;
632
649
odometry.child_frame_id = " base_link" ;
633
650
odometry.pose = pose_cov.pose ;
634
651
odometry.twist = twist_cov.twist ;
0 commit comments