@@ -70,19 +70,24 @@ PoseBroadcaster::update(const rclcpp::Time & time, const rclcpp::Duration & peri
7070 bool should_publish =
7171 (publish_elapsed_ >= publish_interval_) || (publish_interval_.nanoseconds () == 0 );
7272 if (should_publish && realtime_pose_publisher_) {
73+ geometry_msgs::msg::PoseStamped pose_msg;
74+ pose_msg.header .stamp = time;
75+ pose_msg.header .frame_id = params_.base_frame ;
76+ pose_msg.pose .position .x = current_pose.translation ()[0 ];
77+ pose_msg.pose .position .y = current_pose.translation ()[1 ];
78+ pose_msg.pose .position .z = current_pose.translation ()[2 ];
79+ pose_msg.pose .orientation .x = current_quaternion.x ();
80+ pose_msg.pose .orientation .y = current_quaternion.y ();
81+ pose_msg.pose .orientation .z = current_quaternion.z ();
82+ pose_msg.pose .orientation .w = current_quaternion.w ();
83+
84+ #if REALTIME_TOOLS_NEW_API
85+ if (realtime_pose_publisher_->try_publish (pose_msg)) {
86+ #else
7387 if (realtime_pose_publisher_->trylock ()) {
74- auto & pose_msg = realtime_pose_publisher_->msg_ ;
75- pose_msg.header .stamp = time;
76- pose_msg.header .frame_id = params_.base_frame ;
77- pose_msg.pose .position .x = current_pose.translation ()[0 ];
78- pose_msg.pose .position .y = current_pose.translation ()[1 ];
79- pose_msg.pose .position .z = current_pose.translation ()[2 ];
80- pose_msg.pose .orientation .x = current_quaternion.x ();
81- pose_msg.pose .orientation .y = current_quaternion.y ();
82- pose_msg.pose .orientation .z = current_quaternion.z ();
83- pose_msg.pose .orientation .w = current_quaternion.w ();
88+ realtime_pose_publisher_->msg_ = pose_msg;
8489 realtime_pose_publisher_->unlockAndPublish ();
85-
90+ #endif
8691 publish_elapsed_ = publish_elapsed_ - publish_interval_;
8792 // clamp to publish only 1 time even if missed multiple intervals
8893 publish_elapsed_ = std::min (publish_elapsed_, publish_interval_);
0 commit comments