@@ -95,7 +95,7 @@ void SlamGmapping::startLiveSlam() {
9595 entropy_publisher_ = this ->create_publisher <std_msgs::msg::Float64>(" entropy" );
9696 sst_ = this ->create_publisher <nav_msgs::msg::OccupancyGrid>(" map" );
9797 sstm_ = this ->create_publisher <nav_msgs::msg::MapMetaData>(" map_metadata" );
98- pose_publisher_ = this ->create_publisher <geometry_msgs::PoseWithCovarianceStamped>(" pose" );
98+ pose_publisher_ = this ->create_publisher <geometry_msgs::msg:: PoseWithCovarianceStamped>(" pose" );
9999 scan_filter_sub_ = std::make_shared<message_filters::Subscriber<sensor_msgs::msg::LaserScan>>
100100 (node_, " scan" );
101101 scan_filter_ = std::make_shared<tf2_ros::MessageFilter<sensor_msgs::msg::LaserScan>>
@@ -366,19 +366,22 @@ void SlamGmapping::laserCallback(sensor_msgs::msg::LaserScan::ConstSharedPtr sca
366366 q.setRPY (0 , 0 , mpose.theta );
367367 tf2::Transform laser_to_map = tf2::Transform (q, tf2::Vector3 (mpose.x , mpose.y , 0.0 )).inverse ();
368368
369- // publish latest pose with regards to map frame
369+ // update latest pose with regards to map frame
370370 {
371- PoseWithCovarianceStamped p;
371+ std::lock_guard<std::mutex> g (map_to_odom_mutex_);
372+ geometry_msgs::msg::PoseWithCovarianceStamped& p = latestPose_;
372373 p.header .stamp = now ();
373374 p.header .frame_id = map_frame_;
374375
375- p.pose .position .x = mpose.x
376- p.pose .position .y = mpose.y
377- p.pose .position .z = 0.0 ;
376+ p.pose .pose . position .x = mpose.x ;
377+ p.pose .pose . position .y = mpose.y ;
378+ p.pose .pose . position .z = 0.0 ;
378379
379- p.pose .orientation = q;
380-
381- pose_publisher_->publish (p);
380+ const auto v = q.getAxis ();
381+ p.pose .pose .orientation .x = v[0 ];
382+ p.pose .pose .orientation .y = v[1 ];
383+ p.pose .pose .orientation .z = v[2 ];
384+ p.pose .pose .orientation .w = q.getW ();
382385 }
383386
384387
@@ -524,6 +527,10 @@ void SlamGmapping::updateMap(const sensor_msgs::msg::LaserScan::ConstSharedPtr s
524527void SlamGmapping::publishTransform ()
525528{
526529 map_to_odom_mutex_.lock ();
530+
531+ // publish the latest pose
532+ pose_publisher_->publish (latestPose_);
533+
527534 rclcpp::Time tf_expiration = get_clock ()->now () + rclcpp::Duration (
528535 static_cast <int32_t >(static_cast <rcl_duration_value_t >(tf_delay_)), 0 );
529536 geometry_msgs::msg::TransformStamped transform;
0 commit comments