Use pose relative to map form simple_move

This commit is contained in:
2026-03-04 16:11:51 +01:00
parent a35ac1cfcf
commit 5f39a2622f

View File

@@ -37,7 +37,6 @@ public:
odom_sub_ = node->create_subscription<nav_msgs::msg::Odometry>( odom_sub_ = node->create_subscription<nav_msgs::msg::Odometry>(
odom_topic_name, 1, [&](nav_msgs::msg::Odometry msg) { odom_topic_name, 1, [&](nav_msgs::msg::Odometry msg) {
std::lock_guard lock(mut_); std::lock_guard lock(mut_);
current_pose_ = msg.pose.pose;
current_vel_ = msg.twist.twist; current_vel_ = msg.twist.twist;
}); });
control_duration_ = 1.0 / this->cycle_frequency_; control_duration_ = 1.0 / this->cycle_frequency_;
@@ -65,28 +64,40 @@ public:
nav2_behaviors::ResultStatus onRun( nav2_behaviors::ResultStatus onRun(
const std::shared_ptr<const typename ActionT::Goal> command) override const std::shared_ptr<const typename ActionT::Goal> command) override
{ {
geometry_msgs::msg::Pose pose; geometry_msgs::msg::PoseStamped pose;
geometry_msgs::msg::Twist vel; geometry_msgs::msg::Twist vel;
{ {
std::lock_guard lock(mut_); std::lock_guard lock(mut_);
pose = current_pose_;
vel = current_vel_; vel = current_vel_;
} }
return onStart(command, pose, vel);
if (!nav2_util::getCurrentPose(
pose, *this->tf_, this->local_frame_, this->robot_base_frame_,
this->transform_tolerance_)) {
return nav2_behaviors::ResultStatus{nav2_behaviors::Status::FAILED};
}
return onStart(command, pose.pose, vel);
} }
nav2_behaviors::ResultStatus onCycleUpdate() override nav2_behaviors::ResultStatus onCycleUpdate() override
{ {
geometry_msgs::msg::Pose pose; geometry_msgs::msg::PoseStamped pose;
geometry_msgs::msg::Twist vel; geometry_msgs::msg::Twist vel;
geometry_msgs::msg::Twist out_vel; geometry_msgs::msg::Twist out_vel;
auto vel_p = std::make_unique<geometry_msgs::msg::TwistStamped>(); auto vel_p = std::make_unique<geometry_msgs::msg::TwistStamped>();
{ {
std::lock_guard lock(mut_); std::lock_guard lock(mut_);
pose = current_pose_;
vel = current_vel_; vel = current_vel_;
} }
nav2_behaviors::ResultStatus r = updateVel(pose, vel, out_vel);
if (!nav2_util::getCurrentPose(
pose, *this->tf_, this->local_frame_, this->robot_base_frame_,
this->transform_tolerance_)) {
return nav2_behaviors::ResultStatus{nav2_behaviors::Status::FAILED};
}
nav2_behaviors::ResultStatus r = updateVel(pose.pose, vel, out_vel);
vel_p->twist = out_vel; vel_p->twist = out_vel;
vel_p->header.stamp = this->clock_->now(); vel_p->header.stamp = this->clock_->now();
vel_p->header.frame_id = this->robot_base_frame_; vel_p->header.frame_id = this->robot_base_frame_;