Skip to content

Commit 1c098d5

Browse files
committed
allow to use latest time to get transforms
1 parent e8913ca commit 1c098d5

3 files changed

Lines changed: 12 additions & 6 deletions

File tree

nav2_controller/src/controller_server.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ bool ControllerServer::isGoalReached()
794794
bool ControllerServer::getRobotPose(geometry_msgs::msg::PoseStamped & pose)
795795
{
796796
geometry_msgs::msg::PoseStamped current_pose;
797-
if (!costmap_ros_->getRobotPose(current_pose)) {
797+
if (!costmap_ros_->getRobotPose(current_pose, true)) {
798798
return false;
799799
}
800800
pose = current_pose;

nav2_costmap_2d/include/nav2_costmap_2d/costmap_2d_ros.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ class Costmap2DROS : public nav2_util::LifecycleNode
192192
* @param global_pose Will be set to the pose of the robot in the global frame of the costmap
193193
* @return True if the pose was set successfully, false otherwise
194194
*/
195-
bool getRobotPose(geometry_msgs::msg::PoseStamped & global_pose);
195+
bool getRobotPose(geometry_msgs::msg::PoseStamped & global_pose, bool use_latest_time = false);
196196

197197
/**
198198
* @brief Transform the input_pose in the global frame of the costmap

nav2_costmap_2d/src/costmap_2d_ros.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -692,11 +692,17 @@ Costmap2DROS::resetLayers()
692692
}
693693

694694
bool
695-
Costmap2DROS::getRobotPose(geometry_msgs::msg::PoseStamped & global_pose)
695+
Costmap2DROS::getRobotPose(geometry_msgs::msg::PoseStamped & global_pose, bool use_latest_time)
696696
{
697-
return nav2_util::getCurrentPose(
698-
global_pose, *tf_buffer_,
699-
global_frame_, robot_base_frame_, transform_tolerance_);
697+
if (use_latest_time) {
698+
return nav2_util::getCurrentPose(
699+
global_pose, *tf_buffer_,
700+
global_frame_, robot_base_frame_, transform_tolerance_, now());
701+
} else {
702+
return nav2_util::getCurrentPose(
703+
global_pose, *tf_buffer_,
704+
global_frame_, robot_base_frame_, transform_tolerance_);
705+
}
700706
}
701707

702708
bool

0 commit comments

Comments
 (0)