Refactor: cắt dead code, khai báo config đầy đủ, sửa quyết định tiến/lùi
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>
This commit is contained in:
@@ -1,84 +1,41 @@
|
||||
#ifndef CUSTOM_PLANNER_CURVE_COMMON_H_
|
||||
#define CUSTOM_PLANNER_CURVE_COMMON_H_
|
||||
|
||||
//#include "agv_path_smoothing/conversion.h"
|
||||
#include <vector>
|
||||
|
||||
#include <Eigen/Eigen>
|
||||
//#include <vector>
|
||||
// #include <deque>
|
||||
// #include <iostream>
|
||||
|
||||
#include <robot_nav_msgs/Path.h>
|
||||
#include <robot_geometry_msgs/Point.h>
|
||||
#include <robot_visualization_msgs/Marker.h>
|
||||
#include "custom_planner/color.h"
|
||||
|
||||
// Thông tin NURBS/B-spline: knot vector, control point, weight và buffer basis
|
||||
// function dùng lại giữa các lần CalculateCurvePoint trên cùng một cạnh.
|
||||
struct Spline_Inf
|
||||
{
|
||||
int order;
|
||||
std::vector<double> knot_vector;
|
||||
std::vector<double> weight;
|
||||
//std::vector<double> N;
|
||||
|
||||
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
|
||||
std::vector<Eigen::Vector3d, Eigen::aligned_allocator<Eigen::Vector3d> > control_point;
|
||||
std::vector<Eigen::VectorXd, Eigen::aligned_allocator<Eigen::VectorXd> > N;
|
||||
std::vector<Eigen::VectorXd, Eigen::aligned_allocator<Eigen::VectorXd> > dN;
|
||||
std::vector<Eigen::VectorXd, Eigen::aligned_allocator<Eigen::VectorXd> > ddN;
|
||||
std::vector<double> N_double_vec;
|
||||
std::vector<double> R_double_vec;
|
||||
std::vector<double> dR_double_vec;
|
||||
std::vector<double> ddR_double_vec;
|
||||
// std::vector<double> ddN_double_vec;
|
||||
//Eigen::Matrix<Eigen::VectorXd, Eigen::Dynamic, Eigen::Dynamic> N; //bsaic function
|
||||
Eigen::MatrixXd curvefit_N;
|
||||
|
||||
};
|
||||
|
||||
struct EigenTrajectoryPoint
|
||||
{
|
||||
typedef std::vector<EigenTrajectoryPoint, Eigen::aligned_allocator<EigenTrajectoryPoint> > Vector;
|
||||
double u_data;
|
||||
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
|
||||
Eigen::Vector3d position;
|
||||
//Eigen::VectorXd u_data;
|
||||
};
|
||||
|
||||
class Curve_common
|
||||
{
|
||||
public:
|
||||
Curve_common();
|
||||
robot_nav_msgs::Path Generate_Line(robot_geometry_msgs::Point start_point, robot_geometry_msgs::Point end_point, double t_intervel, std::string frame_id);
|
||||
robot_nav_msgs::Path Generate_BezierCurve(EigenTrajectoryPoint::Vector control_point, double t_intervel, std::string frame_id);
|
||||
robot_nav_msgs::Path Generate_BsplineCurve(Spline_Inf bspline_inf, double t_intervel, std::string frame_id);
|
||||
robot_nav_msgs::Path Generate_NURBSCurve(Spline_Inf spline_inf, double t_intervel, std::string frame_id);
|
||||
robot_nav_msgs::Path Generate_DerivativeBsplineCurve(Spline_Inf bspline_inf, int differential_times, double t_intervel, std::string frame_id);
|
||||
robot_nav_msgs::Path Generate_DerivativeBasisFuncCurve(Spline_Inf bspline_inf, int differential_times, int index, double t_intervel, std::string frame_id);
|
||||
|
||||
void CalculateDerivativeBasisFunc(Spline_Inf *spline_inf, double u_data, int differential_times);
|
||||
robot_geometry_msgs::Point CalculateDerivativeCurvePoint(Spline_Inf *spline_inf, double u_data, int differential_times, bool UsingNURBS);
|
||||
/// Nạp order + control point + knot vector vào spline_inf.
|
||||
void ReadSplineInf(Spline_Inf *bspline_inf, int order,
|
||||
std::vector<Eigen::Vector3d, Eigen::aligned_allocator<Eigen::Vector3d> > control_point,
|
||||
std::vector<double> knot_vector);
|
||||
|
||||
/// Nạp weight vector (bắt buộc trước khi tính NURBS với UsingNURBS=true).
|
||||
void ReadSplineInf(Spline_Inf *bspline_inf, std::vector<double> weight_vector,
|
||||
bool use_limit_derivative_fitting);
|
||||
|
||||
/// Tính điểm trên đường cong tại tham số u_data trong [0, 1].
|
||||
robot_geometry_msgs::Point CalculateCurvePoint(Spline_Inf *spline_inf, double u_data, bool UsingNURBS);
|
||||
double CalculateCurvature(Spline_Inf spline_inf, double u_data, bool UsingNURBS);
|
||||
double CalculateSignedCurvature(Spline_Inf spline_inf, double u_data, bool UsingNURBS);
|
||||
Eigen::Vector3d CalculateCurvatureDirectionVector(Spline_Inf spline_inf, double u_data, bool UsingNURBS);
|
||||
double CalculateCurvatureRadius(Spline_Inf spline_inf, double u_data, bool UsingNURBS);
|
||||
double CalculateCurveLength(Spline_Inf spline_inf, double start_u, double end_u, int sub_intervals, bool UsingNURBS);
|
||||
|
||||
void ReadSplineInf(Spline_Inf *bspline_inf, int order, std::vector<Eigen::Vector3d, Eigen::aligned_allocator<Eigen::Vector3d> > control_point, std::vector<double> knot_vector);
|
||||
void ReadSplineInf(Spline_Inf *bspline_inf, std::vector<double> weight_vector, bool use_limit_derivative_fitting);
|
||||
void ReadDiscreate2DPointFromLaunch(EigenTrajectoryPoint::Vector *input_point, std::vector<double> file_discreate_point);
|
||||
void ReadDiscreate2DPointFromLaunch(std::vector<Eigen::Vector3d, Eigen::aligned_allocator<Eigen::Vector3d> > *input_point, std::vector<double> file_discreate_point);
|
||||
void ShowDiscreatePoint(robot_visualization_msgs::Marker *points, EigenTrajectoryPoint::Vector discreate_point);
|
||||
void ShowDiscreatePoint(robot_visualization_msgs::Marker *points, std::vector<Eigen::Vector3d, Eigen::aligned_allocator<Eigen::Vector3d> > discreate_point);
|
||||
|
||||
//TODO: move relate visualize function to new vislization.h
|
||||
int print();
|
||||
robot_visualization_msgs::Marker ShowDiscreatePoint(EigenTrajectoryPoint::Vector& discreate_point, const std::string& frame_id, const std::string& name, double scale);
|
||||
robot_visualization_msgs::Marker ShowDiscreatePoint2(EigenTrajectoryPoint::Vector& discreate_point, const std::string& frame_id, robot_std_msgs::ColorRGBA point_color, const std::string& name, double scale);
|
||||
robot_visualization_msgs::Marker ShowDiscreatePoint(std::vector<Eigen::Vector3d, Eigen::aligned_allocator<Eigen::Vector3d> > discreate_point, const std::string& frame_id, const std::string& name, double scale);
|
||||
robot_visualization_msgs::Marker ShowDiscreatePoint2(std::vector<Eigen::Vector3d, Eigen::aligned_allocator<Eigen::Vector3d> > discreate_point, const std::string& frame_id, robot_std_msgs::ColorRGBA point_color, const std::string& name, double scale);
|
||||
private:
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif //CUSTOM_PLANNER_CURVE_COMMON_H_
|
||||
#endif //CUSTOM_PLANNER_CURVE_COMMON_H_
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
#ifndef CUSTOM_PLANNER_COLOR_H_
|
||||
#define CUSTOM_PLANNER_COLOR_H_
|
||||
|
||||
#include <robot_std_msgs/ColorRGBA.h>
|
||||
|
||||
namespace agv_visualization
|
||||
{
|
||||
class Color : public robot_std_msgs::ColorRGBA
|
||||
{
|
||||
public:
|
||||
Color() : robot_std_msgs::ColorRGBA() {}
|
||||
Color(double red, double green, double blue) : Color(red, green, blue, 1.0) {}
|
||||
Color(double red, double green, double blue, double alpha) : Color() {
|
||||
r = red;
|
||||
g = green;
|
||||
b = blue;
|
||||
a = alpha;
|
||||
}
|
||||
|
||||
static const Color White() { return Color(1.0, 1.0, 1.0); }
|
||||
static const Color Black() { return Color(0.0, 0.0, 0.0); }
|
||||
static const Color Gray() { return Color(0.5, 0.5, 0.5); }
|
||||
static const Color Red() { return Color(1.0, 0.0, 0.0); }
|
||||
static const Color Green() { return Color(0.0, 1.0, 0.0); }
|
||||
static const Color Blue() { return Color(0.0, 0.0, 1.0); }
|
||||
static const Color Yellow() { return Color(1.0, 1.0, 0.0); }
|
||||
static const Color Orange() { return Color(1.0, 0.5, 0.0); }
|
||||
static const Color Purple() { return Color(0.5, 0.0, 1.0); }
|
||||
static const Color Chartreuse() { return Color(0.5, 1.0, 0.0); }
|
||||
static const Color Teal() { return Color(0.0, 1.0, 1.0); }
|
||||
static const Color Pink() { return Color(1.0, 0.0, 0.5); }
|
||||
};
|
||||
}
|
||||
#endif //CUSTOM_PLANNER_COLOR_H_
|
||||
@@ -1,43 +0,0 @@
|
||||
#ifndef CUSTOM_PLANNER_CONVERSION_H_
|
||||
#define CUSTOM_PLANNER_CONVERSION_H_
|
||||
#include "custom_planner/Curve_common.h"
|
||||
|
||||
#include <Eigen/Geometry>
|
||||
#include <robot_geometry_msgs/Point.h>
|
||||
#include <robot_geometry_msgs/Quaternion.h>
|
||||
|
||||
inline Eigen::Vector3d EigenVecter3dFromPointMsg(const robot_geometry_msgs::Point& msg) {
|
||||
return Eigen::Vector3d(msg.x, msg.y, msg.z);
|
||||
}
|
||||
|
||||
inline EigenTrajectoryPoint::Vector EigenTrajectoryVectorFromVector(const std::vector<robot_geometry_msgs::PoseStamped> &plan)
|
||||
{
|
||||
EigenTrajectoryPoint::Vector eigen_trajectory_point_vec;
|
||||
EigenTrajectoryPoint eigen_trajectory_point;
|
||||
|
||||
for(int i = 0; i < static_cast<int>(plan.size()); i++)
|
||||
{
|
||||
eigen_trajectory_point.position(0) = plan.at(i).pose.position.x;
|
||||
eigen_trajectory_point.position(1) = plan.at(i).pose.position.y;
|
||||
eigen_trajectory_point_vec.push_back(eigen_trajectory_point);
|
||||
}
|
||||
|
||||
return eigen_trajectory_point_vec;
|
||||
}
|
||||
|
||||
inline EigenTrajectoryPoint::Vector EigenTrajectoryVectorFromVector(const std::vector<robot_geometry_msgs::Point> &discreate_point_vec)
|
||||
{
|
||||
EigenTrajectoryPoint::Vector eigen_trajectory_point_vec;
|
||||
EigenTrajectoryPoint eigen_trajectory_point;
|
||||
|
||||
for(int i = 0; i < static_cast<int>(discreate_point_vec.size()); i++)
|
||||
{
|
||||
eigen_trajectory_point.position(0) = discreate_point_vec.at(i).x;
|
||||
eigen_trajectory_point.position(1) = discreate_point_vec.at(i).y;
|
||||
eigen_trajectory_point_vec.push_back(eigen_trajectory_point);
|
||||
}
|
||||
|
||||
return eigen_trajectory_point_vec;
|
||||
}
|
||||
|
||||
#endif //CUSTOM_PLANNER_CONVERSION_H_
|
||||
@@ -1,45 +1,32 @@
|
||||
#ifndef CUSTOM_PLANNER_H
|
||||
#define CUSTOM_PLANNER_H
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <cmath>
|
||||
#include <map>
|
||||
|
||||
using namespace std;
|
||||
|
||||
// ROS
|
||||
#include <robot_geometry_msgs/PoseStamped.h>
|
||||
#include <robot_visualization_msgs/Marker.h>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
// Costmap used for the map representation
|
||||
#include <robot_costmap_2d/costmap_2d_robot.h>
|
||||
|
||||
// global representation
|
||||
// global planner interface
|
||||
#include <robot_nav_core/base_global_planner.h>
|
||||
|
||||
// tf
|
||||
#include <tf3/convert.h>
|
||||
#include <tf3/buffer_core.h>
|
||||
|
||||
// internal lib
|
||||
#include <custom_planner/pose.h>
|
||||
#include <custom_planner/pathway.h>
|
||||
#include "custom_planner/Curve_common.h"
|
||||
#include "custom_planner/conversion.h"
|
||||
#include "custom_planner/merge_path_calc.h"
|
||||
|
||||
#include <robot_geometry_msgs/PoseArray.h>
|
||||
#include <robot_geometry_msgs/PoseStamped.h>
|
||||
#include <robot_protocol_msgs/Order.h>
|
||||
|
||||
const double EPSILON = 1e-6;
|
||||
|
||||
using namespace std;
|
||||
// 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{
|
||||
string nodeId;
|
||||
std::string nodeId;
|
||||
uint32_t sequenceId;
|
||||
double position_x;
|
||||
double position_y;
|
||||
@@ -48,126 +35,103 @@ struct OrderNode{
|
||||
|
||||
class CustomPlanner : public robot_nav_core::BaseGlobalPlanner{
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief Default constructor for the NavFnROS object
|
||||
*/
|
||||
|
||||
CustomPlanner();
|
||||
|
||||
|
||||
/**
|
||||
* @brief Constructor for the CustomPlanner object
|
||||
* @param name The name of this planner
|
||||
* @param costmap_ros A pointer to the ROS wrapper of the costmap to use
|
||||
* @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_ros A pointer to the ROS wrapper of the costmap to use
|
||||
* @param costmap_robot A pointer to the wrapper of the costmap to use
|
||||
*/
|
||||
virtual bool initialize(std::string name,
|
||||
robot_costmap_2d::Costmap2DROBOT* costmap_robot);
|
||||
bool initialize(std::string name,
|
||||
robot_costmap_2d::Costmap2DROBOT* costmap_robot) override;
|
||||
|
||||
virtual 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);
|
||||
/**
|
||||
* @brief Given a goal pose in the world, compute a plan
|
||||
* @param start The start pose
|
||||
* @param goal The goal pose
|
||||
* @param plan The plan... filled by the planner
|
||||
* @return True if a valid plan was found, false otherwise
|
||||
* @brief Materialize một VDA5050 Order (node/edge + NURBS) thành plan.
|
||||
*/
|
||||
virtual bool makePlan(const robot_geometry_msgs::PoseStamped& start,
|
||||
const robot_geometry_msgs::PoseStamped& goal,
|
||||
std::vector<robot_geometry_msgs::PoseStamped>& 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
|
||||
{
|
||||
printf("[%s:%d] This function is not available!",__FILE__,__LINE__);
|
||||
(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;
|
||||
~CustomPlanner() override = default;
|
||||
|
||||
private:
|
||||
void publishStats(int solution_cost, int solution_size,
|
||||
const robot_geometry_msgs::PoseStamped& start,
|
||||
const robot_geometry_msgs::PoseStamped& goal);
|
||||
|
||||
static void transformFootprintToEdges(const robot_geometry_msgs::Pose& robot_pose,
|
||||
const std::vector<robot_geometry_msgs::Point>& footprint,
|
||||
std::vector<robot_geometry_msgs::Point>& out_footprint);
|
||||
|
||||
bool countRobotDirectionChangeAngle(vector<Pose>& savePosesOnEdge, int& total_edge);
|
||||
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)
|
||||
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,
|
||||
bool checkYawEdgeEnd(Pose& start_edge_pose, Pose& end_edge_pose,
|
||||
const robot_geometry_msgs::PoseStamped &goal);
|
||||
|
||||
bool loadPathwayData(const string& filename);
|
||||
|
||||
bool findNearestPoseOfPath(vector<Pose>& posesOnPathWay, Pose& PoseToCheck, Pose& PoseResult);
|
||||
|
||||
// void order_msg_handle(const vda5050_msgs::Order::ConstPtr& msg);
|
||||
|
||||
bool makePlanWithOrder(robot_protocol_msgs::Order msg,
|
||||
const robot_geometry_msgs::PoseStamped& start,
|
||||
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,
|
||||
|
||||
bool calcAllYaw(const robot_geometry_msgs::PoseStamped& start,
|
||||
const robot_geometry_msgs::PoseStamped& goal,
|
||||
vector<Pose>& saveposesOnEdge,
|
||||
std::vector<Pose>& saveposesOnEdge,
|
||||
int& total_edge);
|
||||
|
||||
bool isThetaValid(double theta);
|
||||
|
||||
bool curveIsValid(int degree, const std::vector<double> &knot_vector,
|
||||
vector<Eigen::Vector3d, Eigen::aligned_allocator<Eigen::Vector3d>>& control_points);
|
||||
std::vector<Eigen::Vector3d, Eigen::aligned_allocator<Eigen::Vector3d>>& control_points);
|
||||
|
||||
void setYawAllPosesOnEdge(vector<Pose>& posesOnEdge, bool reverse);
|
||||
|
||||
double computeDeltaAngle(Pose& Pose1, Pose& Pose2);
|
||||
|
||||
vector<Pose> divideSegment(Pose& A, Pose& B, double d);
|
||||
vector<robot_geometry_msgs::PoseStamped> divideSegment(robot_geometry_msgs::PoseStamped& A, robot_geometry_msgs::PoseStamped& B, double d);
|
||||
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<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_;
|
||||
vector<Pose> posesOnPathWay_;
|
||||
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_; /**< manages the cost map for us */
|
||||
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_;
|
||||
|
||||
boost::mutex mutex_;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,65 @@
|
||||
#ifndef CUSTOM_PLANNER_CONFIG_H_
|
||||
#define CUSTOM_PLANNER_CONFIG_H_
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include <robot/robot.h>
|
||||
|
||||
namespace custom_planner
|
||||
{
|
||||
// struct
|
||||
|
||||
}
|
||||
/**
|
||||
* @brief Tham số runtime của CustomPlanner, nạp từ YAML qua robot::NodeHandle.
|
||||
*
|
||||
* Mọi default giữ nguyên giá trị đã hard-code trước refactor để không đổi
|
||||
* hành vi khi YAML thiếu key. Đơn vị ghi ngay tại từng field.
|
||||
*/
|
||||
struct CustomPlannerConfig
|
||||
{
|
||||
// [m] start/goal cách pathway dưới ngưỡng này thì coi là đã bám vào pathway
|
||||
// (quyết định 1 trong 4 cách nối NURBS start/goal vào tuyến).
|
||||
double pathway_attach_distance = 0.1;
|
||||
|
||||
#endif // CUSTOM_PLANNER_CONFIG_H_
|
||||
// [m] order không có node/edge (goal trần): chỉ chấp nhận khi start-goal
|
||||
// gần hơn ngưỡng này, ngược lại trả false để move_base2 rơi xuống backup planner.
|
||||
double bare_goal_max_distance = 0.2;
|
||||
|
||||
// Bước tham số u trong [0,1] khi đo chiều dài NURBS của một cạnh
|
||||
// (không phải mét; nhỏ hơn = đo chính xác hơn, chậm hơn).
|
||||
double nurbs_length_t_interval = 0.01;
|
||||
|
||||
// [m] khoảng cách mong muốn giữa hai pose liên tiếp khi lấy mẫu NURBS
|
||||
// trong calculateNURBSPath (nhánh nối start/goal vào pathway).
|
||||
double nurbs_point_spacing = 0.05;
|
||||
|
||||
// [rad] hai cạnh thẳng đầu tiên gãy dưới góc này thì bỏ cạnh đầu khi tính yaw
|
||||
// (robot xuất phát giữa khúc gãy ngắn, đi thẳng luôn sang cạnh sau).
|
||||
double skip_edge_angle = 0.15 * M_PI;
|
||||
|
||||
// [rad] góc nối giữa hai cạnh <= ngưỡng này: gãy gắt (cost 20).
|
||||
double cost_angle_tight = 0.1 * M_PI;
|
||||
|
||||
// [rad] góc nối < ngưỡng này (và > tight): gãy vừa (cost 10).
|
||||
double cost_angle_wide = 0.45 * M_PI;
|
||||
|
||||
// [rad] cửa sổ góc đổi hướng (min, max) mà planner chèn chuỗi pose xoay
|
||||
// tại chỗ giữa hai cạnh thay vì đi cong liền mạch.
|
||||
double rotation_insert_min = 0.45 * M_PI;
|
||||
double rotation_insert_max = 0.85 * M_PI;
|
||||
|
||||
// [rad] bước yaw giữa hai pose xoay tại chỗ được chèn.
|
||||
double rotation_step = 0.05 * M_PI;
|
||||
|
||||
// [rad] |yaw goal - hướng cạnh cuối| vượt ngưỡng này thì đoạn cuối đi lùi.
|
||||
double backward_decision_angle = 0.5 * M_PI;
|
||||
|
||||
/// Nạp param từ nh (thiếu key giữ default), validate range rồi log giá trị chốt.
|
||||
void load(robot::NodeHandle& nh);
|
||||
|
||||
/// Kẹp giá trị về range hợp lệ; log warning mỗi lần phải sửa.
|
||||
void validate();
|
||||
};
|
||||
|
||||
} // namespace custom_planner
|
||||
|
||||
#endif // CUSTOM_PLANNER_CONFIG_H_
|
||||
|
||||
@@ -96,7 +96,7 @@ namespace custom_planner
|
||||
* Hàm này tìm các điểm điều khiển NURBS dựa trên vị trí bắt đầu, kết thúc và các điểm trên đường đi.
|
||||
* Nó sử dụng bậc của đường cong NURBS để xác định số lượng điểm điều khiển cần thiết.
|
||||
*/
|
||||
bool findNURBSControlPoints(vector<robot_geometry_msgs::PoseStamped>& control_points,
|
||||
bool findNURBSControlPoints(std::vector<robot_geometry_msgs::PoseStamped>& control_points,
|
||||
const robot_geometry_msgs::PoseStamped& start,
|
||||
std::vector<Pose>& posesOnPathWay,
|
||||
point_type type);
|
||||
@@ -109,11 +109,11 @@ namespace custom_planner
|
||||
* Hàm này sẽ tính toán đường đi NURBS dựa trên các điểm điều khiển đã tìm được.
|
||||
* Nó sẽ sử dụng các hàm từ CurveCommon và Spline_Inf để tính toán các điểm trên đường cong.
|
||||
*/
|
||||
std::vector<robot_geometry_msgs::PoseStamped> calculateNURBSPath(vector<robot_geometry_msgs::PoseStamped>& control_points,
|
||||
std::vector<robot_geometry_msgs::PoseStamped> calculateNURBSPath(std::vector<robot_geometry_msgs::PoseStamped>& control_points,
|
||||
bool reverse);
|
||||
|
||||
bool handleEdgeIntersection(vector<Pose>& savePosesOnEdge,
|
||||
vector<Pose>& posesOnEdge,
|
||||
bool handleEdgeIntersection(std::vector<Pose>& savePosesOnEdge,
|
||||
std::vector<Pose>& posesOnEdge,
|
||||
size_t current_edge_idx);
|
||||
|
||||
/**
|
||||
@@ -173,16 +173,16 @@ namespace custom_planner
|
||||
bool status_yaw_edge_end_ = true;
|
||||
|
||||
|
||||
// [m] khoảng cách mong muốn giữa hai pose khi lấy mẫu NURBS trong
|
||||
// calculateNURBSPath; CustomPlanner nạp từ config khi initialize.
|
||||
double desired_point_spacing_ = 0.05;
|
||||
|
||||
private:
|
||||
// vector<robot_geometry_msgs::PoseStamped> control_points;
|
||||
|
||||
bool normal_plag = false;
|
||||
|
||||
// CurveCommon* curve_design = nullptr;
|
||||
// Spline_Inf* spline_inf = nullptr;
|
||||
Spline_Inf* spline_inf = nullptr;
|
||||
Curve_common* curve_design = nullptr;
|
||||
|
||||
Spline_Inf spline_inf;
|
||||
Curve_common curve_design;
|
||||
|
||||
/**
|
||||
* \brief Cập nhật hướng của các Pose trong đường đi NURBS.
|
||||
* \param saved_poses Vector chứa các Pose đã lưu.
|
||||
|
||||
@@ -1,150 +0,0 @@
|
||||
#ifndef CUSTOM_PLANNER_CUSTOM_PLANNER_PATHWAY_H
|
||||
#define CUSTOM_PLANNER_CUSTOM_PLANNER_PATHWAY_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <vector>
|
||||
#include <fstream>
|
||||
#include <filesystem>
|
||||
#include <math.h>
|
||||
#include <cmath>
|
||||
#include <custom_planner/pose.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace custom_planner
|
||||
{
|
||||
|
||||
class Point {
|
||||
private:
|
||||
double x_, y_;
|
||||
|
||||
public:
|
||||
Point():
|
||||
x_(0.0), y_(0.0) {};
|
||||
|
||||
Point(double x, double y):
|
||||
x_(x), y_(y) {};
|
||||
|
||||
~Point() {};
|
||||
|
||||
inline void setX(double x) { x_ = x; }
|
||||
inline void setY(double y) { y_ = y; }
|
||||
inline void setPoint(double x, double y) { x_ = x, y_ = y; }
|
||||
inline void setPoint(Point p) { x_ = p.x_, y_ = p.y_; }
|
||||
|
||||
inline double getX(void) { return x_; }
|
||||
inline double getY(void) { return y_; }
|
||||
inline Point getPoint(void) { return Point(x_, y_); }
|
||||
|
||||
}; // class Point
|
||||
|
||||
class Edge {
|
||||
private:
|
||||
Pose p1_;
|
||||
Pose p2_;
|
||||
public:
|
||||
Edge(void):
|
||||
p1_(Pose(0.0, 0.0, 0.0)),
|
||||
p2_(Pose(0.0, 0.0, 0.0)) {}
|
||||
Edge(Pose p1, Pose p2):
|
||||
p1_(p1),
|
||||
p2_(p2) {}
|
||||
inline void setEdge(Pose p1, Pose p2){
|
||||
p1_ = p1; p2_ = p2;
|
||||
}
|
||||
~Edge() {}
|
||||
inline void setP1(Pose p1){p1_ = p1;}
|
||||
inline void setP2(Pose p2){p2_ = p2;}
|
||||
inline Pose getP1(void){return p1_;}
|
||||
inline Pose getP2(void){return p2_;}
|
||||
};
|
||||
|
||||
class Pathway {
|
||||
private:
|
||||
std::vector<Edge> path_;
|
||||
vector<Pose> posesOnPath_;
|
||||
Pose startPoseOfPath;
|
||||
// Given three collinear poses p, q, r, the function checks if
|
||||
// pose q lies on edge 'pr'
|
||||
bool onSegment(Pose p, Pose q, Pose r);
|
||||
|
||||
//To find orientation of ordered triplet (p, q, r)
|
||||
// The function returns following values
|
||||
// 0 --> p, q and r are collinear
|
||||
// 1 --> Clockwise
|
||||
// 2 --> Counterclockwise
|
||||
int orientation(Pose p, Pose q, Pose r);
|
||||
|
||||
bool doIntersect(Pose p1, Pose q1, Pose p2, Pose q2);
|
||||
|
||||
bool isIntersect(Edge L);
|
||||
|
||||
bool isPoseExisted(Pose p);
|
||||
|
||||
double calculateAngle(Pose p1, Pose p2, Pose p3);
|
||||
|
||||
bool findIntersection(Edge L1, Edge L2, Point* resultPoint);
|
||||
|
||||
public:
|
||||
bool isPathInitilized_;
|
||||
bool isPathClear_;
|
||||
Pathway():isPathInitilized_(false),isPathClear_(false)
|
||||
{
|
||||
|
||||
// startPointOfPath = Pose()
|
||||
|
||||
}
|
||||
~Pathway(){
|
||||
path_.clear();
|
||||
posesOnPath_.clear();
|
||||
}
|
||||
void RecordPath(Pose startPose, Pose currentPose, double delta_angle_th, double InitialSegmentLengthMin, double SegmentLengthMin);
|
||||
void ResetAndRecordPath(Pose startPose, Pose currentPose, double delta_angle_th, double InitialSegmentLengthMin, double SegmentLengthMin);
|
||||
inline void clear(){path_.clear();}
|
||||
inline bool isPathEmpty(){return path_.empty();}
|
||||
inline void addEdge(Pose p1, Pose p2) {path_.push_back(Edge(p1, p2));}
|
||||
inline void addEdge(Edge Edge) {path_.push_back(Edge);}
|
||||
inline void addEdge(Pose p2) {if(!path_.empty()&&!isPoseExisted(p2))
|
||||
path_.push_back(Edge(path_.back().getP2(),p2));}
|
||||
|
||||
bool isNewPoseOnEdge(Pose p, double delta_angle_th);
|
||||
|
||||
inline void setP2LastEdgeOnPath(Pose p2)
|
||||
{
|
||||
path_.back().setP2(p2);
|
||||
}
|
||||
|
||||
void setEdgeOnPath(uint32_t line_index, Pose p1, Pose p2);
|
||||
|
||||
inline vector<Pose> getPosesOnPath(){return posesOnPath_;}
|
||||
|
||||
void syncPosesAndPath();
|
||||
|
||||
void SavePathAsFile(const string& file_name);
|
||||
|
||||
void LoadPathFromFile(const string& file_name);
|
||||
|
||||
vector<Point> findIntersections(Edge L);
|
||||
|
||||
vector<vector<Point>> findIntersections(Edge L1, Edge L2);
|
||||
|
||||
void testprint()
|
||||
{
|
||||
if(!path_.empty()){
|
||||
int i =0;
|
||||
for(auto &edge : path_)
|
||||
{
|
||||
cout<<"edge "<<i<<": "<<edge.getP1().getX()
|
||||
<<","<<edge.getP1().getY()<<","<<edge.getP1().getYaw()<<" "
|
||||
<<edge.getP2().getX()<<","<<edge.getP2().getY()<<","<<edge.getP2().getYaw()<<endl;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
} // namespace custom_planner
|
||||
|
||||
#endif // CUSTOM_PLANNER_CUSTOM_PLANNER_PATHWAY_H
|
||||
@@ -1,20 +1,13 @@
|
||||
#ifndef CUSTOM_PLANNER_CUSTOM_PLANNER_POSE_H
|
||||
#define CUSTOM_PLANNER_CUSTOM_PLANNER_POSE_H
|
||||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <vector>
|
||||
#include <fstream>
|
||||
#include <math.h>
|
||||
|
||||
#include <cmath>
|
||||
|
||||
using namespace std;
|
||||
namespace custom_planner{
|
||||
|
||||
class Pose {
|
||||
private:
|
||||
double x_, y_, yaw_;
|
||||
double x_, y_, yaw_; // [m], [m], [rad] — yaw giữ trong [-pi, pi] qua modifyYaw()
|
||||
|
||||
void modifyYaw(void) {
|
||||
while (yaw_ < -M_PI)
|
||||
@@ -30,7 +23,7 @@ public:
|
||||
Pose(double x, double y, double yaw):
|
||||
x_(x), y_(y), yaw_(yaw) {};
|
||||
|
||||
~Pose() {};
|
||||
~Pose() = default;
|
||||
|
||||
inline void setX(double x) { x_ = x; }
|
||||
inline void setY(double y) { y_ = y; }
|
||||
@@ -41,12 +34,10 @@ public:
|
||||
inline double getX(void) { return x_; }
|
||||
inline double getY(void) { return y_; }
|
||||
inline double getYaw(void) { return yaw_; }
|
||||
inline Pose getPose(void) { return Pose(x_, y_, yaw_); }
|
||||
bool SavePoseAsFile(const string& file_name);
|
||||
bool LoadPoseFromFile(const string& file_name);
|
||||
inline Pose getPose(void) { return Pose(x_, y_, yaw_); }
|
||||
|
||||
}; // class Pose
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user