@@ -510,6 +510,27 @@ void LaserScanMatcher::processScan(LDP& curr_ldp_scan, const ros::Time& time)
510510
511511 // **** publish
512512
513+ Eigen::Matrix2f xy_cov = Eigen::Matrix2f::Zero ();
514+ float yaw_cov = 0.0 ;
515+ if (input_.do_compute_covariance )
516+ {
517+ // get covariance from ICP
518+ xy_cov (0 , 0 ) = gsl_matrix_get (output_.cov_x_m , 0 , 0 );
519+ xy_cov (0 , 1 ) = gsl_matrix_get (output_.cov_x_m , 0 , 1 );
520+ xy_cov (1 , 0 ) = gsl_matrix_get (output_.cov_x_m , 1 , 0 );
521+ xy_cov (1 , 1 ) = gsl_matrix_get (output_.cov_x_m , 1 , 1 );
522+ yaw_cov = gsl_matrix_get (output_.cov_x_m , 2 , 2 );
523+
524+ // rotate xy covariance from the keyframe into odom frame
525+ auto rotation = getLaserRotation (f2b_kf_);
526+ xy_cov = rotation * xy_cov * rotation.transpose ();
527+ }
528+ else {
529+ xy_cov (0 , 0 ) = position_covariance_[0 ];
530+ xy_cov (1 , 1 ) = position_covariance_[1 ];
531+ yaw_cov = orientation_covariance_[2 ];
532+ }
533+
513534 if (publish_pose_)
514535 {
515536 // unstamped Pose2D message
@@ -540,26 +561,13 @@ void LaserScanMatcher::processScan(LDP& curr_ldp_scan, const ros::Time& time)
540561 pose_with_covariance_msg = boost::make_shared<geometry_msgs::PoseWithCovariance>();
541562 tf::poseTFToMsg (last_base_in_fixed_, pose_with_covariance_msg->pose );
542563
543- if (input_.do_compute_covariance )
544- {
545- pose_with_covariance_msg->covariance = boost::assign::list_of
546- (gsl_matrix_get (output_.cov_x_m , 0 , 0 )) (0 ) (0 ) (0 ) (0 ) (0 )
547- (0 ) (gsl_matrix_get (output_.cov_x_m , 0 , 1 )) (0 ) (0 ) (0 ) (0 )
548- (0 ) (0 ) (static_cast <double >(position_covariance_[2 ])) (0 ) (0 ) (0 )
549- (0 ) (0 ) (0 ) (static_cast <double >(orientation_covariance_[0 ])) (0 ) (0 )
550- (0 ) (0 ) (0 ) (0 ) (static_cast <double >(orientation_covariance_[1 ])) (0 )
551- (0 ) (0 ) (0 ) (0 ) (0 ) (gsl_matrix_get (output_.cov_x_m , 0 , 2 ));
552- }
553- else
554- {
555- pose_with_covariance_msg->covariance = boost::assign::list_of
556- (static_cast <double >(position_covariance_[0 ])) (0 ) (0 ) (0 ) (0 ) (0 )
557- (0 ) (static_cast <double >(position_covariance_[1 ])) (0 ) (0 ) (0 ) (0 )
558- (0 ) (0 ) (static_cast <double >(position_covariance_[2 ])) (0 ) (0 ) (0 )
559- (0 ) (0 ) (0 ) (static_cast <double >(orientation_covariance_[0 ])) (0 ) (0 )
560- (0 ) (0 ) (0 ) (0 ) (static_cast <double >(orientation_covariance_[1 ])) (0 )
561- (0 ) (0 ) (0 ) (0 ) (0 ) (static_cast <double >(orientation_covariance_[2 ]));
562- }
564+ pose_with_covariance_msg->covariance = boost::assign::list_of
565+ (xy_cov (0 , 0 )) (xy_cov (0 , 1 )) (0 ) (0 ) (0 ) (0 )
566+ (xy_cov (1 , 0 )) (xy_cov (1 , 1 )) (0 ) (0 ) (0 ) (0 )
567+ (0 ) (0 ) (0 ) (0 ) (0 ) (0 )
568+ (0 ) (0 ) (0 ) (0 ) (0 ) (0 )
569+ (0 ) (0 ) (0 ) (0 ) (0 ) (0 )
570+ (0 ) (0 ) (0 ) (0 ) (0 ) (yaw_cov);
563571
564572 pose_with_covariance_publisher_.publish (pose_with_covariance_msg);
565573 }
@@ -574,26 +582,13 @@ void LaserScanMatcher::processScan(LDP& curr_ldp_scan, const ros::Time& time)
574582
575583 tf::poseTFToMsg (last_base_in_fixed_, pose_with_covariance_stamped_msg->pose .pose );
576584
577- if (input_.do_compute_covariance )
578- {
579- pose_with_covariance_stamped_msg->pose .covariance = boost::assign::list_of
580- (gsl_matrix_get (output_.cov_x_m , 0 , 0 )) (0 ) (0 ) (0 ) (0 ) (0 )
581- (0 ) (gsl_matrix_get (output_.cov_x_m , 0 , 1 )) (0 ) (0 ) (0 ) (0 )
582- (0 ) (0 ) (static_cast <double >(position_covariance_[2 ])) (0 ) (0 ) (0 )
583- (0 ) (0 ) (0 ) (static_cast <double >(orientation_covariance_[0 ])) (0 ) (0 )
584- (0 ) (0 ) (0 ) (0 ) (static_cast <double >(orientation_covariance_[1 ])) (0 )
585- (0 ) (0 ) (0 ) (0 ) (0 ) (gsl_matrix_get (output_.cov_x_m , 0 , 2 ));
586- }
587- else
588- {
589- pose_with_covariance_stamped_msg->pose .covariance = boost::assign::list_of
590- (static_cast <double >(position_covariance_[0 ])) (0 ) (0 ) (0 ) (0 ) (0 )
591- (0 ) (static_cast <double >(position_covariance_[1 ])) (0 ) (0 ) (0 ) (0 )
592- (0 ) (0 ) (static_cast <double >(position_covariance_[2 ])) (0 ) (0 ) (0 )
593- (0 ) (0 ) (0 ) (static_cast <double >(orientation_covariance_[0 ])) (0 ) (0 )
594- (0 ) (0 ) (0 ) (0 ) (static_cast <double >(orientation_covariance_[1 ])) (0 )
595- (0 ) (0 ) (0 ) (0 ) (0 ) (static_cast <double >(orientation_covariance_[2 ]));
596- }
585+ pose_with_covariance_stamped_msg->pose .covariance = boost::assign::list_of
586+ (xy_cov (0 , 0 )) (xy_cov (0 , 1 )) (0 ) (0 ) (0 ) (0 )
587+ (xy_cov (1 , 0 )) (xy_cov (1 , 1 )) (0 ) (0 ) (0 ) (0 )
588+ (0 ) (0 ) (0 ) (0 ) (0 ) (0 )
589+ (0 ) (0 ) (0 ) (0 ) (0 ) (0 )
590+ (0 ) (0 ) (0 ) (0 ) (0 ) (0 )
591+ (0 ) (0 ) (0 ) (0 ) (0 ) (yaw_cov);
597592
598593 pose_with_covariance_stamped_publisher_.publish (pose_with_covariance_stamped_msg);
599594 }
@@ -863,4 +858,13 @@ void LaserScanMatcher::createTfFromXYTheta(
863858 t.setRotation (q);
864859}
865860
861+ Eigen::Matrix2f LaserScanMatcher::getLaserRotation (const tf::Transform& odom_pose) const {
862+ tf::Transform laser_in_fixed = odom_pose * laser_to_base_;
863+ tf::Matrix3x3 fixed_from_laser_rot (laser_in_fixed.getRotation ());
864+ double r,p,y;
865+ fixed_from_laser_rot.getRPY (r, p, y);
866+ Eigen::Rotation2Df t (y);
867+ return t.toRotationMatrix ();
868+ }
869+
866870} // namespace scan_tools
0 commit comments