fix(nav_2d): xoá UB trong TwoPointsPlanner và pointer hoang trong tf_help
Sửa tay theo commit 37e44eb (T800_ws pnkx_nav_core, branch
dev_recovery_and_manager_mission) thay vì cherry-pick, theo yêu cầu.
- two_points_planner.cpp: nhánh suy biến (start == goal, ca quay tại chỗ)
đọc theta chưa khởi tạo trước khi dùng trong cos()/sin(). Khởi tạo bằng
yaw hiện tại của start.
- tf_help.cpp: canTransform() nhận std::string *error_msg chưa khởi tạo —
tf3 ghi qua con trỏ đó khi transform thất bại, tức ghi vào vùng nhớ bất
kỳ. Đổi sang std::string thật + log tên hai frame khi thất bại.
- tf_help.cpp: transformPose() gọi transform() rồi return true vô điều
kiện ở cả nhánh chính lẫn nhánh ExtrapolationException — lookup hỏng để
lại out_pose mặc định (yaw 0) mà vẫn báo thành công. Trả thẳng kết quả
của transform().
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -190,21 +190,37 @@ namespace two_points_planner
|
||||
const double dx = goal.pose.position.x - start.pose.position.x;
|
||||
const double dy = goal.pose.position.y - start.pose.position.y;
|
||||
const double distance = std::sqrt(dx * dx + dy * dy);
|
||||
double theta;
|
||||
// Travel heading of the plan. Seeded with the CURRENT robot yaw, not left
|
||||
// uninitialised: an in-place rotation leg (profile `rotate`) asks for a goal
|
||||
// whose position is the robot's own, so dx = dy = 0 and the branch below
|
||||
// never assigns theta. Reading it then was undefined behaviour, and the
|
||||
// degenerate branch fed cos()/sin() of that garbage into the first plan pose.
|
||||
// The robot's own heading is the only reference frame that leg carries.
|
||||
double theta = start_2d.pose.theta;
|
||||
// Lấy độ phân giải của costmap
|
||||
double resolution = costmap_robot_->getCostmap()->getResolution();
|
||||
|
||||
|
||||
if(fabs(dx) > 1e-9 || fabs(dy) > 1e-9)
|
||||
{
|
||||
theta = std::atan2(dy, dx);
|
||||
// tf3::Quaternion goal_quat(goal.pose.orientation.x, goal.pose.orientation.y,
|
||||
// tf3::Quaternion goal_quat(goal.pose.orientation.x, goal.pose.orientation.y,
|
||||
// goal.pose.orientation.z, goal.pose.orientation.w);
|
||||
// double goal_theta = tf3::getYaw(goal_quat);
|
||||
double goal_theta = robot_nav_2d_utils::poseStampedToPose2D(goal).pose.theta;
|
||||
if(cos(goal_theta - theta) < 0) theta += M_PI;
|
||||
}
|
||||
else
|
||||
{
|
||||
else
|
||||
{
|
||||
// Start and goal share a position: nothing to interpolate. This is the
|
||||
// in-place rotation case. Emit two poses so the plan is never empty
|
||||
// (ControllerRunner rejects an empty plan before the local planner is even
|
||||
// called) and so the LAST pose stays `goal` — the controller takes
|
||||
// plan.back() as the goal pose handed to setGoalPose(), which is what
|
||||
// carries the requested heading.
|
||||
//
|
||||
// The first pose is offset one cell along the robot's current heading
|
||||
// rather than being a copy of `start`: consecutive identical poses make
|
||||
// any consumer that derives a direction from them compute atan2(0, 0).
|
||||
robot_geometry_msgs::PoseStamped pose = start;
|
||||
pose.pose.position.x += resolution * cos(theta);
|
||||
pose.pose.position.y += resolution * sin(theta);
|
||||
|
||||
Reference in New Issue
Block a user