Cắt bỏ (~2400 dòng):
- plan_for_retry.cpp: file ROS1 legacy (ros/ros.h, tf/tf.h), không nằm trong
CMakeLists, không compile được trong stack này.
- pathway.{h,cc}, pose.cc, color.h, conversion.h: class Pathway/Edge/Point,
Pose file-IO, agv_visualization::Color, Eigen conversion — 0 nơi dùng.
- Curve_common tỉa còn đúng API đang dùng (ReadSplineInf x2,
CalculateCurvePoint); bỏ Generate_*/ShowDiscreatePoint*/Curvature* chết —
nhờ đó bỏ dependency robot_visualization_msgs, robot_nav_msgs,
robot_std_msgs khỏi CMakeLists + package.xml.
- Xoá 7 method declare-only/định nghĩa không ai gọi trong CustomPlanner
(publishStats, loadPathwayData, findNearestPoseOfPath, computeDeltaAngle,
divideSegment x2, transformFootprintToEdges, isThetaValid), member mutex_,
khối gui_path build xong không publish.
Config (trước đây planner không đọc bất kỳ param nào — toàn bộ yaml là key
SBPL copy nhầm, mọi tunable hard-code):
- CustomPlannerConfig: 11 param có default = giá trị hard-code cũ (giữ nguyên
hành vi khi yaml thiếu key), validate range + log giá trị chốt.
- Viết lại config/custom_global_params.yaml đủ key kèm đơn vị.
- FIX: NodeHandle("~/" + name) không resolve segment "~", âm thầm rơi về
root nên getParam luôn trả default. Đổi sang NodeHandle(name).
Sửa đúng đắn:
- checkYawEdgeEnd: fabs(|a|-|b|) xoá dấu — cặp góc trái dấu cùng độ lớn
(vd ±pi/2, lệch thật pi) cho delta=0, planner chọn nhầm đi tiến và robot
quay đầu thay vì lùi. Thay bằng fabs(wrapToPi(yaw_goal - angle)), ngưỡng
thành param backward_decision_angle (đồng bộ công thức với bản rb_ws).
- Bỏ new/delete thô: Spline_Inf/Curve_common thành member by-value ở cả
CustomPlanner lẫn MergePathCalc.
- Bỏ using namespace std khỏi header; EPSILON toàn cục -> kEpsilon trong
namespace; makePlan(start,goal) log qua robot::log_warning.
- package.xml viết lại (bản cũ copy nguyên metadata của tf2).
Verify:
- catkin_make --pkg custom_planner: PASS, symbol BOOST_DLL_ALIAS
CustomPlanner còn trong libcustom_planner.so.
- Smoke test nạp config: đọc đúng 11 key từ cây pnkx_nav_core/config và
Test/move_base2/config/runtime; override ăn; giá trị ngoài range bị kẹp
kèm warning.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
139 lines
4.7 KiB
C++
Executable File
139 lines
4.7 KiB
C++
Executable File
#ifndef CUSTOM_PLANNER_H
|
|
#define CUSTOM_PLANNER_H
|
|
|
|
#include <map>
|
|
#include <optional>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
// Costmap used for the map representation
|
|
#include <robot_costmap_2d/costmap_2d_robot.h>
|
|
|
|
// global planner interface
|
|
#include <robot_nav_core/base_global_planner.h>
|
|
|
|
#include <robot_geometry_msgs/PoseStamped.h>
|
|
#include <robot_protocol_msgs/Order.h>
|
|
|
|
// internal lib
|
|
#include <custom_planner/Curve_common.h>
|
|
#include <custom_planner/custom_planner_config.h>
|
|
#include <custom_planner/merge_path_calc.h>
|
|
#include <custom_planner/pose.h>
|
|
|
|
namespace custom_planner{
|
|
|
|
constexpr double kEpsilon = 1e-6;
|
|
|
|
struct OrderNode{
|
|
std::string nodeId;
|
|
uint32_t sequenceId;
|
|
double position_x;
|
|
double position_y;
|
|
double theta;
|
|
};
|
|
|
|
class CustomPlanner : public robot_nav_core::BaseGlobalPlanner{
|
|
public:
|
|
|
|
CustomPlanner();
|
|
|
|
/**
|
|
* @brief Constructor for the CustomPlanner object
|
|
* @param name The name of this planner
|
|
* @param costmap_robot A pointer to the wrapper of the costmap to use
|
|
*/
|
|
CustomPlanner(std::string name, robot_costmap_2d::Costmap2DROBOT* costmap_robot);
|
|
|
|
/**
|
|
* @brief Initialization function for the CustomPlanner object
|
|
* @param name The name of this planner
|
|
* @param costmap_robot A pointer to the wrapper of the costmap to use
|
|
*/
|
|
bool initialize(std::string name,
|
|
robot_costmap_2d::Costmap2DROBOT* costmap_robot) override;
|
|
|
|
/**
|
|
* @brief Materialize một VDA5050 Order (node/edge + NURBS) thành plan.
|
|
*/
|
|
bool makePlan(const robot_protocol_msgs::Order& msg,
|
|
const robot_geometry_msgs::PoseStamped& start,
|
|
const robot_geometry_msgs::PoseStamped& goal,
|
|
std::vector<robot_geometry_msgs::PoseStamped>& plan) override;
|
|
|
|
/**
|
|
* @brief Contract 3 tham số không được hỗ trợ: CustomPlanner là route
|
|
* materializer theo Order, không phải search planner. move_base2 sẽ rơi
|
|
* xuống backup planner khi hàm này trả false.
|
|
*/
|
|
bool makePlan(const robot_geometry_msgs::PoseStamped& start,
|
|
const robot_geometry_msgs::PoseStamped& goal,
|
|
std::vector<robot_geometry_msgs::PoseStamped>& plan) override
|
|
{
|
|
(void)start; (void)goal; (void)plan;
|
|
robot::log_warning("[custom_planner] makePlan(start, goal) is not supported — use the Order overload.");
|
|
return false;
|
|
}
|
|
|
|
~CustomPlanner() override = default;
|
|
|
|
private:
|
|
bool countRobotDirectionChangeAngle(std::vector<Pose>& savePosesOnEdge, int& total_edge);
|
|
|
|
Pose pointOnAngleBisector(Pose& A, Pose& B, Pose& C, double length);
|
|
|
|
inline bool isOppositeSign(double angleA, double angleB)
|
|
{
|
|
return (angleA > 0 && angleB < 0) || (angleA < 0 && angleB > 0);
|
|
}
|
|
|
|
bool checkYawEdgeEnd(Pose& start_edge_pose, Pose& end_edge_pose,
|
|
const robot_geometry_msgs::PoseStamped &goal);
|
|
|
|
bool makePlanWithOrder(robot_protocol_msgs::Order msg,
|
|
const robot_geometry_msgs::PoseStamped& start,
|
|
const robot_geometry_msgs::PoseStamped& goal);
|
|
|
|
bool doIntersect(const robot_geometry_msgs::Point& p1, const robot_geometry_msgs::Point& q1,
|
|
const robot_geometry_msgs::Point& p2, const robot_geometry_msgs::Point& q2);
|
|
|
|
std::optional<robot_geometry_msgs::Point> computeIntersectionPoint(const robot_geometry_msgs::Point& p1, const robot_geometry_msgs::Point& q1,
|
|
const robot_geometry_msgs::Point& p2, const robot_geometry_msgs::Point& q2);
|
|
|
|
bool calcAllYaw(const robot_geometry_msgs::PoseStamped& start,
|
|
const robot_geometry_msgs::PoseStamped& goal,
|
|
std::vector<Pose>& saveposesOnEdge,
|
|
int& total_edge);
|
|
|
|
bool curveIsValid(int degree, const std::vector<double> &knot_vector,
|
|
std::vector<Eigen::Vector3d, Eigen::aligned_allocator<Eigen::Vector3d>>& control_points);
|
|
|
|
void setYawAllPosesOnEdge(std::vector<Pose>& posesOnEdge, bool reverse);
|
|
|
|
// Vector lưu thông tin các cạnh
|
|
std::vector<InfEdge> edges_info_;
|
|
std::vector<RobotDirectionChangeAngle> RobotDirectionChangeAngle_info_;
|
|
|
|
MergePathCalc merge_path_calc_;
|
|
bool skipEdge_flag_ = false;
|
|
bool reverse_ = false;
|
|
|
|
Spline_Inf input_spline_inf_;
|
|
Curve_common CurveDesign_;
|
|
std::vector<Pose> posesOnPathWay_;
|
|
|
|
CustomPlannerConfig config_;
|
|
|
|
bool initialized_;
|
|
bool rotating_robot_plag_ = false; /**< whether the robot is rotating or not, used to determine the direction of the path */
|
|
|
|
std::string name_;
|
|
robot_costmap_2d::Costmap2DROBOT* costmap_robot_; /**< non-owning, do not cache the inner costmap pointer */
|
|
std::vector<robot_geometry_msgs::Point> footprint_;
|
|
unsigned int current_env_width_;
|
|
unsigned int current_env_height_;
|
|
};
|
|
}
|
|
|
|
#endif
|