Compare commits
3 Commits
49ea9fe7f5
...
6eed3d8772
| Author | SHA1 | Date | |
|---|---|---|---|
| 6eed3d8772 | |||
| 728b65b97a | |||
| c16f846136 |
@@ -30,9 +30,6 @@ if (NOT BUILDING_WITH_CATKIN)
|
|||||||
set(CMAKE_BUILD_RPATH "${CMAKE_BINARY_DIR}")
|
set(CMAKE_BUILD_RPATH "${CMAKE_BINARY_DIR}")
|
||||||
|
|
||||||
set(PACKAGES_DIR
|
set(PACKAGES_DIR
|
||||||
robot_visualization_msgs
|
|
||||||
robot_nav_msgs
|
|
||||||
robot_std_msgs
|
|
||||||
robot_geometry_msgs
|
robot_geometry_msgs
|
||||||
tf3
|
tf3
|
||||||
robot_tf3_geometry_msgs
|
robot_tf3_geometry_msgs
|
||||||
@@ -50,9 +47,6 @@ else()
|
|||||||
# Catkin specific configuration
|
# Catkin specific configuration
|
||||||
# ========================================================
|
# ========================================================
|
||||||
find_package(catkin REQUIRED COMPONENTS
|
find_package(catkin REQUIRED COMPONENTS
|
||||||
robot_visualization_msgs
|
|
||||||
robot_nav_msgs
|
|
||||||
robot_std_msgs
|
|
||||||
robot_geometry_msgs
|
robot_geometry_msgs
|
||||||
robot_tf3_geometry_msgs
|
robot_tf3_geometry_msgs
|
||||||
robot_time
|
robot_time
|
||||||
@@ -68,7 +62,7 @@ else()
|
|||||||
catkin_package(
|
catkin_package(
|
||||||
INCLUDE_DIRS include
|
INCLUDE_DIRS include
|
||||||
LIBRARIES ${PROJECT_NAME}
|
LIBRARIES ${PROJECT_NAME}
|
||||||
CATKIN_DEPENDS robot_visualization_msgs robot_nav_msgs robot_std_msgs robot_geometry_msgs robot_tf3_geometry_msgs robot_time data_convert robot_costmap_2d robot_nav_core robot_protocol_msgs robot_cpp
|
CATKIN_DEPENDS robot_geometry_msgs robot_tf3_geometry_msgs robot_time data_convert robot_costmap_2d robot_nav_core robot_protocol_msgs robot_cpp
|
||||||
DEPENDS Eigen3 Boost
|
DEPENDS Eigen3 Boost
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -85,8 +79,7 @@ endif()
|
|||||||
# ========================================================
|
# ========================================================
|
||||||
add_library(${PROJECT_NAME} SHARED
|
add_library(${PROJECT_NAME} SHARED
|
||||||
src/custom_planner.cpp
|
src/custom_planner.cpp
|
||||||
src/pathway.cc
|
src/custom_planner_config.cpp
|
||||||
src/pose.cc
|
|
||||||
src/Curve_common.cpp
|
src/Curve_common.cpp
|
||||||
src/merge_path_calc.cpp
|
src/merge_path_calc.cpp
|
||||||
)
|
)
|
||||||
@@ -175,6 +168,6 @@ else()
|
|||||||
message(STATUS "Project: ${PROJECT_NAME}")
|
message(STATUS "Project: ${PROJECT_NAME}")
|
||||||
message(STATUS "Version: ${PROJECT_VERSION}")
|
message(STATUS "Version: ${PROJECT_VERSION}")
|
||||||
message(STATUS "C++ Standard: ${CMAKE_CXX_STANDARD}")
|
message(STATUS "C++ Standard: ${CMAKE_CXX_STANDARD}")
|
||||||
message(STATUS "Dependencies: robot_visualization_msgs, robot_nav_msgs, robot_std_msgs, robot_geometry_msgs, tf3, robot_tf3_geometry_msgs, robot_time, data_convert, robot_costmap_2d, robot_nav_core, robot_protocol_msgs, robot_cpp, Eigen3, Boost")
|
message(STATUS "Dependencies: robot_geometry_msgs, tf3, robot_tf3_geometry_msgs, robot_time, data_convert, robot_costmap_2d, robot_nav_core, robot_protocol_msgs, robot_cpp, Eigen3, Boost")
|
||||||
message(STATUS "=================================")
|
message(STATUS "=================================")
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
@@ -1,17 +1,33 @@
|
|||||||
base_global_planner: CustomPlanner
|
# custom_planner — tham số runtime, đọc qua robot::NodeHandle("CustomPlanner").
|
||||||
|
# Thiếu key nào thì dùng default trong CustomPlannerConfig (cùng giá trị ghi ở đây).
|
||||||
CustomPlanner:
|
CustomPlanner:
|
||||||
environment_type: XYThetaLattice
|
# [m] start/goal cách pathway dưới ngưỡng này thì coi là đã bám vào pathway
|
||||||
planner_type: ARAPlanner
|
# (quyết định cách nối NURBS start/goal vào tuyến).
|
||||||
allocated_time: 10.0
|
pathway_attach_distance: 0.1
|
||||||
initial_epsilon: 1.0
|
|
||||||
force_scratch_limit: 10000
|
|
||||||
forward_search: false
|
|
||||||
nominalvel_mpersecs: 0.8
|
|
||||||
timetoturn45degsinplace_secs: 1.31 # = 0.6 rad/s
|
|
||||||
allow_unknown: true
|
|
||||||
directory_to_save_paths: "/init/paths"
|
|
||||||
pathway_filename: "pathway.txt"
|
|
||||||
current_pose_topic_name: "/amcl_pose"
|
|
||||||
map_frame_id: "map"
|
|
||||||
base_frame_id: "base_link"
|
|
||||||
|
|
||||||
|
# [m] order không có node/edge (goal trần): chỉ nhận khi start-goal gần hơn
|
||||||
|
# ngưỡng này, ngược lại trả false để move_base2 dùng backup planner.
|
||||||
|
bare_goal_max_distance: 0.2
|
||||||
|
|
||||||
|
# Bước tham số u trong [0,1] khi đo chiều dài NURBS một cạnh (không phải mét).
|
||||||
|
nurbs_length_t_interval: 0.01
|
||||||
|
|
||||||
|
# [m] khoảng cách mong muốn giữa hai pose khi lấy mẫu NURBS nối start/goal.
|
||||||
|
nurbs_point_spacing: 0.05
|
||||||
|
|
||||||
|
# [rad] hai cạnh thẳng đầu gãy dưới góc này thì bỏ cạnh đầu khi tính yaw.
|
||||||
|
skip_edge_angle: 0.4712 # = 0.15*pi
|
||||||
|
|
||||||
|
# [rad] góc nối giữa hai cạnh <= tight: gãy gắt (cost 20); < wide: gãy vừa (cost 10).
|
||||||
|
cost_angle_tight: 0.3142 # = 0.1*pi
|
||||||
|
cost_angle_wide: 1.4137 # = 0.45*pi
|
||||||
|
|
||||||
|
# [rad] cửa sổ góc đổi hướng cần chèn chuỗi pose xoay tại chỗ giữa hai cạnh.
|
||||||
|
rotation_insert_min: 1.4137 # = 0.45*pi
|
||||||
|
rotation_insert_max: 2.6704 # = 0.85*pi
|
||||||
|
|
||||||
|
# [rad] bước yaw giữa hai pose xoay tại chỗ được chèn.
|
||||||
|
rotation_step: 0.1571 # = 0.05*pi
|
||||||
|
|
||||||
|
# [rad] |yaw goal - hướng cạnh cuối| vượt ngưỡng này thì đoạn cuối đi lùi.
|
||||||
|
backward_decision_angle: 1.5708 # = 0.5*pi
|
||||||
|
|||||||
@@ -1,84 +1,41 @@
|
|||||||
#ifndef CUSTOM_PLANNER_CURVE_COMMON_H_
|
#ifndef CUSTOM_PLANNER_CURVE_COMMON_H_
|
||||||
#define CUSTOM_PLANNER_CURVE_COMMON_H_
|
#define CUSTOM_PLANNER_CURVE_COMMON_H_
|
||||||
|
|
||||||
//#include "agv_path_smoothing/conversion.h"
|
#include <vector>
|
||||||
|
|
||||||
#include <Eigen/Eigen>
|
#include <Eigen/Eigen>
|
||||||
//#include <vector>
|
|
||||||
// #include <deque>
|
|
||||||
// #include <iostream>
|
|
||||||
|
|
||||||
#include <robot_nav_msgs/Path.h>
|
|
||||||
#include <robot_geometry_msgs/Point.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
|
struct Spline_Inf
|
||||||
{
|
{
|
||||||
int order;
|
int order;
|
||||||
std::vector<double> knot_vector;
|
std::vector<double> knot_vector;
|
||||||
std::vector<double> weight;
|
std::vector<double> weight;
|
||||||
//std::vector<double> N;
|
|
||||||
|
|
||||||
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
|
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
|
||||||
std::vector<Eigen::Vector3d, Eigen::aligned_allocator<Eigen::Vector3d> > control_point;
|
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> 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
|
class Curve_common
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Curve_common();
|
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);
|
/// Nạp order + control point + knot vector vào spline_inf.
|
||||||
robot_geometry_msgs::Point CalculateDerivativeCurvePoint(Spline_Inf *spline_inf, double u_data, int differential_times, 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);
|
||||||
|
|
||||||
|
/// 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);
|
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
|
#ifndef CUSTOM_PLANNER_H
|
||||||
#define CUSTOM_PLANNER_H
|
#define CUSTOM_PLANNER_H
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <vector>
|
|
||||||
#include <cmath>
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <optional>
|
||||||
using namespace std;
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
// ROS
|
|
||||||
#include <robot_geometry_msgs/PoseStamped.h>
|
|
||||||
#include <robot_visualization_msgs/Marker.h>
|
|
||||||
|
|
||||||
// Costmap used for the map representation
|
// Costmap used for the map representation
|
||||||
#include <robot_costmap_2d/costmap_2d_robot.h>
|
#include <robot_costmap_2d/costmap_2d_robot.h>
|
||||||
|
|
||||||
// global representation
|
// global planner interface
|
||||||
#include <robot_nav_core/base_global_planner.h>
|
#include <robot_nav_core/base_global_planner.h>
|
||||||
|
|
||||||
// tf
|
#include <robot_geometry_msgs/PoseStamped.h>
|
||||||
#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_protocol_msgs/Order.h>
|
#include <robot_protocol_msgs/Order.h>
|
||||||
|
|
||||||
const double EPSILON = 1e-6;
|
// internal lib
|
||||||
|
#include <custom_planner/Curve_common.h>
|
||||||
using namespace std;
|
#include <custom_planner/custom_planner_config.h>
|
||||||
|
#include <custom_planner/merge_path_calc.h>
|
||||||
|
#include <custom_planner/pose.h>
|
||||||
|
|
||||||
namespace custom_planner{
|
namespace custom_planner{
|
||||||
|
|
||||||
|
constexpr double kEpsilon = 1e-6;
|
||||||
|
|
||||||
struct OrderNode{
|
struct OrderNode{
|
||||||
string nodeId;
|
std::string nodeId;
|
||||||
uint32_t sequenceId;
|
uint32_t sequenceId;
|
||||||
double position_x;
|
double position_x;
|
||||||
double position_y;
|
double position_y;
|
||||||
@@ -49,61 +36,51 @@ struct OrderNode{
|
|||||||
class CustomPlanner : public robot_nav_core::BaseGlobalPlanner{
|
class CustomPlanner : public robot_nav_core::BaseGlobalPlanner{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Default constructor for the NavFnROS object
|
|
||||||
*/
|
|
||||||
CustomPlanner();
|
CustomPlanner();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Constructor for the CustomPlanner object
|
* @brief Constructor for the CustomPlanner object
|
||||||
* @param name The name of this planner
|
* @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);
|
CustomPlanner(std::string name, robot_costmap_2d::Costmap2DROBOT* costmap_robot);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Initialization function for the CustomPlanner object
|
* @brief Initialization function for the CustomPlanner object
|
||||||
* @param name The name of this planner
|
* @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,
|
bool initialize(std::string name,
|
||||||
robot_costmap_2d::Costmap2DROBOT* costmap_robot);
|
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
|
* @brief Materialize một VDA5050 Order (node/edge + NURBS) thành 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
|
|
||||||
*/
|
*/
|
||||||
virtual bool makePlan(const robot_geometry_msgs::PoseStamped& start,
|
bool makePlan(const robot_protocol_msgs::Order& msg,
|
||||||
const robot_geometry_msgs::PoseStamped& goal,
|
const robot_geometry_msgs::PoseStamped& start,
|
||||||
std::vector<robot_geometry_msgs::PoseStamped>& plan)
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~CustomPlanner(){};
|
~CustomPlanner() override = default;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void publishStats(int solution_cost, int solution_size,
|
bool countRobotDirectionChangeAngle(std::vector<Pose>& savePosesOnEdge, int& total_edge);
|
||||||
const robot_geometry_msgs::PoseStamped& start,
|
|
||||||
const robot_geometry_msgs::PoseStamped& goal);
|
|
||||||
|
|
||||||
static void transformFootprintToEdges(const robot_geometry_msgs::Pose& robot_pose,
|
Pose pointOnAngleBisector(Pose& A, Pose& B, Pose& C, double length);
|
||||||
const std::vector<robot_geometry_msgs::Point>& footprint,
|
|
||||||
std::vector<robot_geometry_msgs::Point>& out_footprint);
|
|
||||||
|
|
||||||
Pose pointOnAngleBisector(Pose& A, Pose& B, Pose& C, double length = 1.0);
|
|
||||||
|
|
||||||
bool countRobotDirectionChangeAngle(vector<Pose>& savePosesOnEdge, int& total_edge);
|
|
||||||
|
|
||||||
inline bool isOppositeSign(double angleA, double angleB)
|
inline bool isOppositeSign(double angleA, double angleB)
|
||||||
{
|
{
|
||||||
@@ -113,12 +90,6 @@ private:
|
|||||||
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);
|
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,
|
bool makePlanWithOrder(robot_protocol_msgs::Order msg,
|
||||||
const robot_geometry_msgs::PoseStamped& start,
|
const robot_geometry_msgs::PoseStamped& start,
|
||||||
const robot_geometry_msgs::PoseStamped& goal);
|
const robot_geometry_msgs::PoseStamped& goal);
|
||||||
@@ -131,20 +102,13 @@ private:
|
|||||||
|
|
||||||
bool calcAllYaw(const robot_geometry_msgs::PoseStamped& start,
|
bool calcAllYaw(const robot_geometry_msgs::PoseStamped& start,
|
||||||
const robot_geometry_msgs::PoseStamped& goal,
|
const robot_geometry_msgs::PoseStamped& goal,
|
||||||
vector<Pose>& saveposesOnEdge,
|
std::vector<Pose>& saveposesOnEdge,
|
||||||
int& total_edge);
|
int& total_edge);
|
||||||
|
|
||||||
bool isThetaValid(double theta);
|
|
||||||
|
|
||||||
bool curveIsValid(int degree, const std::vector<double> &knot_vector,
|
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);
|
void setYawAllPosesOnEdge(std::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);
|
|
||||||
|
|
||||||
// Vector lưu thông tin các cạnh
|
// Vector lưu thông tin các cạnh
|
||||||
std::vector<InfEdge> edges_info_;
|
std::vector<InfEdge> edges_info_;
|
||||||
@@ -154,22 +118,21 @@ private:
|
|||||||
bool skipEdge_flag_ = false;
|
bool skipEdge_flag_ = false;
|
||||||
bool reverse_ = false;
|
bool reverse_ = false;
|
||||||
|
|
||||||
Spline_Inf* input_spline_inf_;
|
Spline_Inf input_spline_inf_;
|
||||||
Curve_common* CurveDesign_;
|
Curve_common CurveDesign_;
|
||||||
vector<Pose> posesOnPathWay_;
|
std::vector<Pose> posesOnPathWay_;
|
||||||
|
|
||||||
|
CustomPlannerConfig config_;
|
||||||
|
|
||||||
bool initialized_;
|
bool initialized_;
|
||||||
bool rotating_robot_plag_ = false; /**< whether the robot is rotating or not, used to determine the direction of the path */
|
bool rotating_robot_plag_ = false; /**< whether the robot is rotating or not, used to determine the direction of the path */
|
||||||
|
|
||||||
std::string name_;
|
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_;
|
std::vector<robot_geometry_msgs::Point> footprint_;
|
||||||
unsigned int current_env_width_;
|
unsigned int current_env_width_;
|
||||||
unsigned int current_env_height_;
|
unsigned int current_env_height_;
|
||||||
|
|
||||||
boost::mutex mutex_;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,65 @@
|
|||||||
#ifndef CUSTOM_PLANNER_CONFIG_H_
|
#ifndef CUSTOM_PLANNER_CONFIG_H_
|
||||||
#define CUSTOM_PLANNER_CONFIG_H_
|
#define CUSTOM_PLANNER_CONFIG_H_
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
#include <robot/robot.h>
|
#include <robot/robot.h>
|
||||||
|
|
||||||
namespace custom_planner
|
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.
|
* 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.
|
* 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,
|
const robot_geometry_msgs::PoseStamped& start,
|
||||||
std::vector<Pose>& posesOnPathWay,
|
std::vector<Pose>& posesOnPathWay,
|
||||||
point_type type);
|
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.
|
* 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.
|
* 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 reverse);
|
||||||
|
|
||||||
bool handleEdgeIntersection(vector<Pose>& savePosesOnEdge,
|
bool handleEdgeIntersection(std::vector<Pose>& savePosesOnEdge,
|
||||||
vector<Pose>& posesOnEdge,
|
std::vector<Pose>& posesOnEdge,
|
||||||
size_t current_edge_idx);
|
size_t current_edge_idx);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -173,15 +173,15 @@ namespace custom_planner
|
|||||||
bool status_yaw_edge_end_ = true;
|
bool status_yaw_edge_end_ = true;
|
||||||
|
|
||||||
|
|
||||||
private:
|
// [m] khoảng cách mong muốn giữa hai pose khi lấy mẫu NURBS trong
|
||||||
// vector<robot_geometry_msgs::PoseStamped> control_points;
|
// calculateNURBSPath; CustomPlanner nạp từ config khi initialize.
|
||||||
|
double desired_point_spacing_ = 0.05;
|
||||||
|
|
||||||
|
private:
|
||||||
bool normal_plag = false;
|
bool normal_plag = false;
|
||||||
|
|
||||||
// CurveCommon* curve_design = nullptr;
|
Spline_Inf spline_inf;
|
||||||
// Spline_Inf* spline_inf = nullptr;
|
Curve_common curve_design;
|
||||||
Spline_Inf* spline_inf = nullptr;
|
|
||||||
Curve_common* curve_design = nullptr;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Cập nhật hướng của các Pose trong đường đi NURBS.
|
* \brief Cập nhật hướng của các Pose trong đường đi NURBS.
|
||||||
|
|||||||
@@ -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
|
#ifndef CUSTOM_PLANNER_CUSTOM_PLANNER_POSE_H
|
||||||
#define 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>
|
#include <cmath>
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
namespace custom_planner{
|
namespace custom_planner{
|
||||||
|
|
||||||
class Pose {
|
class Pose {
|
||||||
private:
|
private:
|
||||||
double x_, y_, yaw_;
|
double x_, y_, yaw_; // [m], [m], [rad] — yaw giữ trong [-pi, pi] qua modifyYaw()
|
||||||
|
|
||||||
void modifyYaw(void) {
|
void modifyYaw(void) {
|
||||||
while (yaw_ < -M_PI)
|
while (yaw_ < -M_PI)
|
||||||
@@ -30,7 +23,7 @@ public:
|
|||||||
Pose(double x, double y, double yaw):
|
Pose(double x, double y, double yaw):
|
||||||
x_(x), y_(y), yaw_(yaw) {};
|
x_(x), y_(y), yaw_(yaw) {};
|
||||||
|
|
||||||
~Pose() {};
|
~Pose() = default;
|
||||||
|
|
||||||
inline void setX(double x) { x_ = x; }
|
inline void setX(double x) { x_ = x; }
|
||||||
inline void setY(double y) { y_ = y; }
|
inline void setY(double y) { y_ = y; }
|
||||||
@@ -42,8 +35,6 @@ public:
|
|||||||
inline double getY(void) { return y_; }
|
inline double getY(void) { return y_; }
|
||||||
inline double getYaw(void) { return yaw_; }
|
inline double getYaw(void) { return yaw_; }
|
||||||
inline Pose getPose(void) { return Pose(x_, y_, yaw_); }
|
inline Pose getPose(void) { return Pose(x_, y_, yaw_); }
|
||||||
bool SavePoseAsFile(const string& file_name);
|
|
||||||
bool LoadPoseFromFile(const string& file_name);
|
|
||||||
|
|
||||||
}; // class Pose
|
}; // class Pose
|
||||||
|
|
||||||
|
|||||||
70
package.xml
70
package.xml
@@ -1,55 +1,27 @@
|
|||||||
<package>
|
<?xml version="1.0"?>
|
||||||
|
<package format="2">
|
||||||
<name>custom_planner</name>
|
<name>custom_planner</name>
|
||||||
<version>0.7.10</version>
|
<version>1.0.0</version>
|
||||||
<description>
|
<description>
|
||||||
custom_planner is the second generation of the transform library, which lets
|
Global planner materializes a VDA5050 Order (nodes/edges with NURBS
|
||||||
the user keep track of multiple coordinate frames over time. custom_planner
|
trajectories) into a dense plan for robot_nav_core. It is a route
|
||||||
maintains the relationship between coordinate frames in a tree
|
materializer, not a search planner: the plain makePlan(start, goal)
|
||||||
structure buffered in time, and lets the user transform points,
|
contract is intentionally unsupported so the runtime falls back to a
|
||||||
vectors, etc between any two coordinate frames at any desired
|
search-based backup planner for bare goals.
|
||||||
point in time.
|
|
||||||
</description>
|
</description>
|
||||||
<author>Tully Foote</author>
|
<maintainer email="xroboticdevs@gmail.com">duongtd</maintainer>
|
||||||
<author>Eitan Marder-Eppstein</author>
|
<license>Proprietary</license>
|
||||||
<author>Wim Meeussen</author>
|
|
||||||
<maintainer email="tfoote@osrfoundation.org">Tully Foote</maintainer>
|
|
||||||
<license>BSD</license>
|
|
||||||
|
|
||||||
<url type="website">http://www.ros.org/wiki/custom_planner</url>
|
<buildtool_depend>catkin</buildtool_depend>
|
||||||
|
|
||||||
<buildtool_depend version_gte="0.5.68">catkin</buildtool_depend>
|
|
||||||
|
|
||||||
<build_depend>robot_costmap_2d</build_depend>
|
|
||||||
<run_depend>robot_costmap_2d</run_depend>
|
|
||||||
|
|
||||||
<build_depend>robot_nav_core</build_depend>
|
|
||||||
<run_depend>robot_nav_core</run_depend>
|
|
||||||
|
|
||||||
<build_depend>robot_geometry_msgs</build_depend>
|
|
||||||
<run_depend>robot_geometry_msgs</run_depend>
|
|
||||||
|
|
||||||
<build_depend>robot_nav_msgs</build_depend>
|
|
||||||
<run_depend>robot_nav_msgs</run_depend>
|
|
||||||
|
|
||||||
<build_depend>robot_std_msgs</build_depend>
|
|
||||||
<run_depend>robot_std_msgs</run_depend>
|
|
||||||
|
|
||||||
<build_depend>robot_tf3_geometry_msgs</build_depend>
|
|
||||||
<run_depend>robot_tf3_geometry_msgs</run_depend>
|
|
||||||
|
|
||||||
<build_depend>robot_cpp</build_depend>
|
|
||||||
<run_depend>robot_cpp</run_depend>
|
|
||||||
|
|
||||||
<build_depend>robot_protocol_msgs</build_depend>
|
|
||||||
<run_depend>robot_protocol_msgs</run_depend>
|
|
||||||
|
|
||||||
<build_depend>robot_time</build_depend>
|
|
||||||
<run_depend>robot_time</run_depend>
|
|
||||||
|
|
||||||
<build_depend>robot_visualization_msgs</build_depend>
|
|
||||||
<run_depend>robot_visualization_msgs</run_depend>
|
|
||||||
|
|
||||||
<build_depend>data_convert</build_depend>
|
|
||||||
<run_depend>data_convert</run_depend>
|
|
||||||
|
|
||||||
|
<depend>robot_costmap_2d</depend>
|
||||||
|
<depend>robot_nav_core</depend>
|
||||||
|
<depend>robot_geometry_msgs</depend>
|
||||||
|
<depend>robot_tf3_geometry_msgs</depend>
|
||||||
|
<depend>robot_cpp</depend>
|
||||||
|
<depend>robot_protocol_msgs</depend>
|
||||||
|
<depend>robot_time</depend>
|
||||||
|
<depend>data_convert</depend>
|
||||||
|
<depend>eigen</depend>
|
||||||
|
<depend>boost</depend>
|
||||||
</package>
|
</package>
|
||||||
1131
src/Curve_common.cpp
1131
src/Curve_common.cpp
File diff suppressed because it is too large
Load Diff
@@ -1,8 +1,5 @@
|
|||||||
#include <custom_planner/custom_planner.h>
|
#include <custom_planner/custom_planner.h>
|
||||||
#include <robot_nav_msgs/Path.h>
|
|
||||||
#include <robot_geometry_msgs/Point.h>
|
#include <robot_geometry_msgs/Point.h>
|
||||||
#include <robot_costmap_2d/inflation_layer.h>
|
|
||||||
#include <tf3/LinearMath/Quaternion.h>
|
|
||||||
#include <boost/dll/alias.hpp>
|
#include <boost/dll/alias.hpp>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
@@ -10,37 +7,54 @@ using namespace std;
|
|||||||
namespace custom_planner
|
namespace custom_planner
|
||||||
{
|
{
|
||||||
CustomPlanner::CustomPlanner()
|
CustomPlanner::CustomPlanner()
|
||||||
: initialized_(false), costmap_robot_(NULL)
|
: initialized_(false),
|
||||||
|
costmap_robot_(nullptr),
|
||||||
|
current_env_width_(0),
|
||||||
|
current_env_height_(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
CustomPlanner::CustomPlanner(std::string name, robot_costmap_2d::Costmap2DROBOT* costmap_robot)
|
CustomPlanner::CustomPlanner(std::string name, robot_costmap_2d::Costmap2DROBOT* costmap_robot)
|
||||||
: initialized_(false), costmap_robot_(NULL)
|
: initialized_(false),
|
||||||
|
costmap_robot_(nullptr),
|
||||||
|
current_env_width_(0),
|
||||||
|
current_env_height_(0)
|
||||||
{
|
{
|
||||||
initialize(name, costmap_robot);
|
initialize(name, costmap_robot);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CustomPlanner::initialize(std::string name, robot_costmap_2d::Costmap2DROBOT* costmap_robot)
|
bool CustomPlanner::initialize(std::string name, robot_costmap_2d::Costmap2DROBOT* costmap_robot)
|
||||||
{
|
{
|
||||||
if (!initialized_)
|
if (initialized_)
|
||||||
{
|
{
|
||||||
robot::NodeHandle private_nh("~/" + name);
|
return false;
|
||||||
robot::NodeHandle p_nh("~");
|
|
||||||
printf("Name is %s", name.c_str());
|
|
||||||
|
|
||||||
input_spline_inf_ = new Spline_Inf();
|
|
||||||
CurveDesign_ = new Curve_common();
|
|
||||||
|
|
||||||
name_ = name;
|
|
||||||
costmap_robot_ = costmap_robot;
|
|
||||||
|
|
||||||
footprint_ = costmap_robot_->getRobotFootprint();
|
|
||||||
|
|
||||||
initialized_ = true;
|
|
||||||
printf("[custom_planner] Initialized successfully");
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
|
if (costmap_robot == nullptr || costmap_robot->getCostmap() == nullptr)
|
||||||
|
{
|
||||||
|
robot::log_error("[custom_planner] initialize() requires a valid costmap.\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// KHÔNG dùng "~/" + name: NodeHandle không resolve segment "~", âm thầm rơi
|
||||||
|
// về root và mọi getParam trả default. Namespace trần "<name>" mới khớp
|
||||||
|
// root key "CustomPlanner:" trong custom_global_params.yaml.
|
||||||
|
robot::NodeHandle private_nh(name);
|
||||||
|
robot::log_info("Name is %s", name.c_str());
|
||||||
|
|
||||||
|
config_.load(private_nh);
|
||||||
|
merge_path_calc_.desired_point_spacing_ = config_.nurbs_point_spacing;
|
||||||
|
|
||||||
|
name_ = name;
|
||||||
|
costmap_robot_ = costmap_robot;
|
||||||
|
|
||||||
|
footprint_ = costmap_robot_->getRobotFootprint();
|
||||||
|
current_env_width_ = costmap_robot_->getCostmap()->getSizeInCellsX();
|
||||||
|
current_env_height_ = costmap_robot_->getCostmap()->getSizeInCellsY();
|
||||||
|
|
||||||
|
initialized_ = true;
|
||||||
|
robot::log_info("[custom_planner] Initialized successfully");
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CustomPlanner::makePlan(const robot_protocol_msgs::Order& msg,
|
bool CustomPlanner::makePlan(const robot_protocol_msgs::Order& msg,
|
||||||
@@ -50,29 +64,35 @@ namespace custom_planner
|
|||||||
{
|
{
|
||||||
plan.clear();
|
plan.clear();
|
||||||
|
|
||||||
// Check for reinitialization needs
|
if (!initialized_ || costmap_robot_ == nullptr || costmap_robot_->getCostmap() == nullptr)
|
||||||
robot::log_error("yaw goal: %f", data_convert::getYaw(goal.pose.orientation));
|
{
|
||||||
bool do_init = false;
|
robot::log_error("[custom_planner] makePlan() called before a valid initialize().\n");
|
||||||
if(!makePlanWithOrder(msg, start, goal)) return false;
|
return false;
|
||||||
if (current_env_width_ != costmap_robot_->getCostmap()->getSizeInCellsX() ||
|
|
||||||
current_env_height_ != costmap_robot_->getCostmap()->getSizeInCellsY()) {
|
|
||||||
printf("Costmap dimensions have changed from (%d x %d) to (%d x %d), reinitializing custom_planner.",
|
|
||||||
current_env_width_, current_env_height_,
|
|
||||||
costmap_robot_->getCostmap()->getSizeInCellsX(), costmap_robot_->getCostmap()->getSizeInCellsY());
|
|
||||||
do_init = true;
|
|
||||||
} else if (footprint_ != costmap_robot_->getRobotFootprint()) {
|
|
||||||
printf("Robot footprint has changed, reinitializing custom_planner.");
|
|
||||||
do_init = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (do_init) {
|
// Size and footprint are snapshots used only to detect a runtime costmap update. They do
|
||||||
initialized_ = false;
|
// not configure Spline_Inf or Curve_common, so recreating those objects here was both
|
||||||
initialize(name_, costmap_robot_);
|
// unnecessary and leaked their previous allocations. Refresh the snapshot before planning
|
||||||
|
// so this request observes the current costmap state.
|
||||||
|
const unsigned int width = costmap_robot_->getCostmap()->getSizeInCellsX();
|
||||||
|
const unsigned int height = costmap_robot_->getCostmap()->getSizeInCellsY();
|
||||||
|
const std::vector<robot_geometry_msgs::Point> footprint =
|
||||||
|
costmap_robot_->getRobotFootprint();
|
||||||
|
if (current_env_width_ != width || current_env_height_ != height || footprint_ != footprint)
|
||||||
|
{
|
||||||
|
robot::log_info("[custom_planner] costmap snapshot changed: %u x %u -> %u x %u; "
|
||||||
|
"refreshing snapshot without reinitializing planner.\n",
|
||||||
|
current_env_width_, current_env_height_, width, height);
|
||||||
|
current_env_width_ = width;
|
||||||
|
current_env_height_ = height;
|
||||||
|
footprint_ = footprint;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!makePlanWithOrder(msg, start, goal)) return false;
|
||||||
|
|
||||||
// ===== STEP 2: VALIDATE PATHWAY =====
|
// ===== STEP 2: VALIDATE PATHWAY =====
|
||||||
if (posesOnPathWay_.empty()) {
|
if (posesOnPathWay_.empty()) {
|
||||||
printf("[custom_planner] posesOnPathWay_ is empty");
|
robot::log_info("[custom_planner] posesOnPathWay_ is empty");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,7 +100,7 @@ namespace custom_planner
|
|||||||
unsigned int mx_start, my_start, mx_end, my_end;
|
unsigned int mx_start, my_start, mx_end, my_end;
|
||||||
if (!costmap_robot_->getCostmap()->worldToMap(start.pose.position.x, start.pose.position.y, mx_start, my_start) ||
|
if (!costmap_robot_->getCostmap()->worldToMap(start.pose.position.x, start.pose.position.y, mx_start, my_start) ||
|
||||||
!costmap_robot_->getCostmap()->worldToMap(goal.pose.position.x, goal.pose.position.y, mx_end, my_end)) {
|
!costmap_robot_->getCostmap()->worldToMap(goal.pose.position.x, goal.pose.position.y, mx_end, my_end)) {
|
||||||
printf("[custom_planner] Cannot convert world coordinates to map coordinates");
|
robot::log_info("[custom_planner] Cannot convert world coordinates to map coordinates");
|
||||||
}
|
}
|
||||||
|
|
||||||
// ===== STEP 4: FIND NEAREST POINT ON PATHWAY =====
|
// ===== STEP 4: FIND NEAREST POINT ON PATHWAY =====
|
||||||
@@ -97,7 +117,7 @@ namespace custom_planner
|
|||||||
merge_path_calc_.store_start_nearest_idx_ = nearest_idx;
|
merge_path_calc_.store_start_nearest_idx_ = nearest_idx;
|
||||||
|
|
||||||
// ===== STEP 5: CALCULATE DISTANCES =====
|
// ===== STEP 5: CALCULATE DISTANCES =====
|
||||||
const double DISTANCE_THRESHOLD = 0.1;
|
const double DISTANCE_THRESHOLD = config_.pathway_attach_distance;
|
||||||
|
|
||||||
robot::Time plan_time = robot::Time::now();
|
robot::Time plan_time = robot::Time::now();
|
||||||
|
|
||||||
@@ -115,7 +135,7 @@ namespace custom_planner
|
|||||||
|
|
||||||
if (d_start_to_path <= DISTANCE_THRESHOLD && d_path_to_goal <= DISTANCE_THRESHOLD) {
|
if (d_start_to_path <= DISTANCE_THRESHOLD && d_path_to_goal <= DISTANCE_THRESHOLD) {
|
||||||
// CASE 1: Both start and goal are close to pathway - Direct path
|
// CASE 1: Both start and goal are close to pathway - Direct path
|
||||||
printf("[custom_planner] Using direct pathway");
|
robot::log_info("[custom_planner] Using direct pathway");
|
||||||
|
|
||||||
for (size_t i = nearest_idx; i < posesOnPathWay_.size(); i++) {
|
for (size_t i = nearest_idx; i < posesOnPathWay_.size(); i++) {
|
||||||
robot_geometry_msgs::PoseStamped pose;
|
robot_geometry_msgs::PoseStamped pose;
|
||||||
@@ -130,7 +150,7 @@ namespace custom_planner
|
|||||||
|
|
||||||
} else if (d_start_to_path > DISTANCE_THRESHOLD && d_path_to_goal <= DISTANCE_THRESHOLD) {
|
} else if (d_start_to_path > DISTANCE_THRESHOLD && d_path_to_goal <= DISTANCE_THRESHOLD) {
|
||||||
// CASE 2: Start is far, goal is close - NURBS from start to pathway
|
// CASE 2: Start is far, goal is close - NURBS from start to pathway
|
||||||
printf("[custom_planner] Using start NURBS path reverse_(%x)", reverse_);
|
robot::log_info("[custom_planner] Using start NURBS path reverse_(%x)", reverse_);
|
||||||
|
|
||||||
std::vector<robot_geometry_msgs::PoseStamped> start_control_points;
|
std::vector<robot_geometry_msgs::PoseStamped> start_control_points;
|
||||||
bool valid_start_nurbs = merge_path_calc_.findNURBSControlPoints(
|
bool valid_start_nurbs = merge_path_calc_.findNURBSControlPoints(
|
||||||
@@ -176,7 +196,7 @@ namespace custom_planner
|
|||||||
|
|
||||||
} else if (d_start_to_path <= DISTANCE_THRESHOLD && d_path_to_goal > DISTANCE_THRESHOLD) {
|
} else if (d_start_to_path <= DISTANCE_THRESHOLD && d_path_to_goal > DISTANCE_THRESHOLD) {
|
||||||
// CASE 3: Start is close, goal is far - NURBS from pathway to goal
|
// CASE 3: Start is close, goal is far - NURBS from pathway to goal
|
||||||
printf("[custom_planner] Using goal NURBS path");
|
robot::log_info("[custom_planner] Using goal NURBS path");
|
||||||
|
|
||||||
std::vector<robot_geometry_msgs::PoseStamped> goal_control_points;
|
std::vector<robot_geometry_msgs::PoseStamped> goal_control_points;
|
||||||
bool valid_goal_nurbs = merge_path_calc_.findNURBSControlPoints(
|
bool valid_goal_nurbs = merge_path_calc_.findNURBSControlPoints(
|
||||||
@@ -222,7 +242,7 @@ namespace custom_planner
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
// CASE 4: Both start and goal are far - Dual NURBS or special handling
|
// CASE 4: Both start and goal are far - Dual NURBS or special handling
|
||||||
printf("[custom_planner] Using dual NURBS path");
|
robot::log_info("[custom_planner] Using dual NURBS path");
|
||||||
|
|
||||||
std::vector<robot_geometry_msgs::PoseStamped> start_control_points, goal_control_points;
|
std::vector<robot_geometry_msgs::PoseStamped> start_control_points, goal_control_points;
|
||||||
bool valid_start_nurbs = merge_path_calc_.findNURBSControlPoints(
|
bool valid_start_nurbs = merge_path_calc_.findNURBSControlPoints(
|
||||||
@@ -288,7 +308,7 @@ namespace custom_planner
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Fallback: Direct pathway from nearest point
|
// Fallback: Direct pathway from nearest point
|
||||||
printf("[custom_planner] NURBS control points not found, using fallback path");
|
robot::log_info("[custom_planner] NURBS control points not found, using fallback path");
|
||||||
for (size_t i = nearest_idx; i < posesOnPathWay_.size(); i++) {
|
for (size_t i = nearest_idx; i < posesOnPathWay_.size(); i++) {
|
||||||
robot_geometry_msgs::PoseStamped pose;
|
robot_geometry_msgs::PoseStamped pose;
|
||||||
pose.header.stamp = plan_time;
|
pose.header.stamp = plan_time;
|
||||||
@@ -315,40 +335,10 @@ namespace custom_planner
|
|||||||
plan[i].header.seq = i;
|
plan[i].header.seq = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Publish plan for visualization
|
robot::log_info("[custom_planner] Generated plan with %zu waypoints", plan.size());
|
||||||
robot_nav_msgs::Path gui_path;
|
|
||||||
gui_path.header.frame_id = costmap_robot_->getGlobalFrameID();
|
|
||||||
gui_path.header.stamp = plan_time;
|
|
||||||
gui_path.poses = plan;
|
|
||||||
// plan_pub_.publish(gui_path);
|
|
||||||
|
|
||||||
printf("[custom_planner] Generated plan with %zu waypoints", plan.size());
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CustomPlanner::transformFootprintToEdges(const robot_geometry_msgs::Pose &robot_pose,
|
|
||||||
const std::vector<robot_geometry_msgs::Point> &footprint,
|
|
||||||
std::vector<robot_geometry_msgs::Point> &out_footprint)
|
|
||||||
{
|
|
||||||
out_footprint.resize(2 * footprint.size());
|
|
||||||
double yaw = data_convert::getYaw(robot_pose.orientation);
|
|
||||||
for (unsigned int i = 0; i < footprint.size(); i++)
|
|
||||||
{
|
|
||||||
out_footprint[2 * i].x = robot_pose.position.x + cos(yaw) * footprint[i].x - sin(yaw) * footprint[i].y;
|
|
||||||
out_footprint[2 * i].y = robot_pose.position.y + sin(yaw) * footprint[i].x + cos(yaw) * footprint[i].y;
|
|
||||||
if (i == 0)
|
|
||||||
{
|
|
||||||
out_footprint.back().x = out_footprint[i].x;
|
|
||||||
out_footprint.back().y = out_footprint[i].y;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
out_footprint[2 * i - 1].x = out_footprint[2 * i].x;
|
|
||||||
out_footprint[2 * i - 1].y = out_footprint[2 * i].y;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CustomPlanner::makePlanWithOrder(robot_protocol_msgs::Order msg,
|
bool CustomPlanner::makePlanWithOrder(robot_protocol_msgs::Order msg,
|
||||||
const robot_geometry_msgs::PoseStamped& start,
|
const robot_geometry_msgs::PoseStamped& start,
|
||||||
const robot_geometry_msgs::PoseStamped& goal)
|
const robot_geometry_msgs::PoseStamped& goal)
|
||||||
@@ -370,7 +360,7 @@ namespace custom_planner
|
|||||||
double delta_x = start.pose.position.x - goal.pose.position.x;
|
double delta_x = start.pose.position.x - goal.pose.position.x;
|
||||||
double delta_y = start.pose.position.y - goal.pose.position.y;
|
double delta_y = start.pose.position.y - goal.pose.position.y;
|
||||||
double distance_start_to_goal = std::hypot(delta_x, delta_y);
|
double distance_start_to_goal = std::hypot(delta_x, delta_y);
|
||||||
if(distance_start_to_goal > 0.2) {
|
if(distance_start_to_goal > config_.bare_goal_max_distance) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
posesOnPathWay_.push_back(Pose(start.pose.position.x, start.pose.position.y, data_convert::getYaw(start.pose.orientation)));
|
posesOnPathWay_.push_back(Pose(start.pose.position.x, start.pose.position.y, data_convert::getYaw(start.pose.orientation)));
|
||||||
@@ -428,18 +418,51 @@ namespace custom_planner
|
|||||||
}
|
}
|
||||||
degree = (int)msg.edges[i].trajectory.degree;
|
degree = (int)msg.edges[i].trajectory.degree;
|
||||||
|
|
||||||
|
// `trajectory` là TUỲ CHỌN theo VDA5050: master controller chỉ gửi khi muốn áp đặt một
|
||||||
|
// đường cong cụ thể. Không gửi thì edge chỉ nói "đi từ node này sang node kia" và robot tự
|
||||||
|
// lo đường — bắt buộc phải có NURBS làm mọi order không kèm trajectory fail ngay ở đây.
|
||||||
|
//
|
||||||
|
// Dựng B-spline bậc 1 với đúng hai control point là vị trí hai node: knot {0,0,1,1} cho ra
|
||||||
|
// chính xác đoạn thẳng nối chúng. Làm theo cách này thay vì sinh thẳng danh sách pose để
|
||||||
|
// toàn bộ xử lý phía dưới — tính độ dài, bước lấy mẫu thích nghi theo resolution costmap,
|
||||||
|
// né vật cản, tính góc, ghép path — dùng lại nguyên vẹn, không phải nhân đôi logic.
|
||||||
|
const bool trajectory_supplied = degree >= 1 &&
|
||||||
|
!msg.edges[i].trajectory.controlPoints.empty() &&
|
||||||
|
!msg.edges[i].trajectory.knotVector.empty();
|
||||||
|
if(!trajectory_supplied)
|
||||||
|
{
|
||||||
|
degree = 1;
|
||||||
|
control_points.clear();
|
||||||
|
knot_vector.clear();
|
||||||
|
weight_vector.clear();
|
||||||
|
|
||||||
|
control_points.push_back(Eigen::Vector3d(start_nodeId_it->second.position_x,
|
||||||
|
start_nodeId_it->second.position_y, 0));
|
||||||
|
control_points.push_back(Eigen::Vector3d(end_nodeId_it->second.position_x,
|
||||||
|
end_nodeId_it->second.position_y, 0));
|
||||||
|
weight_vector.push_back(1.0);
|
||||||
|
weight_vector.push_back(1.0);
|
||||||
|
knot_vector = {0.0, 0.0, 1.0, 1.0};
|
||||||
|
|
||||||
|
robot::log_info("[custom_planner] Edge %s khong kem trajectory - noi thang hai node "
|
||||||
|
"(%.3f, %.3f) -> (%.3f, %.3f)\n",
|
||||||
|
msg.edges[i].edgeId.c_str(),
|
||||||
|
start_nodeId_it->second.position_x, start_nodeId_it->second.position_y,
|
||||||
|
end_nodeId_it->second.position_x, end_nodeId_it->second.position_y);
|
||||||
|
}
|
||||||
|
|
||||||
if(curveIsValid(degree, knot_vector, control_points))
|
if(curveIsValid(degree, knot_vector, control_points))
|
||||||
{
|
{
|
||||||
double t_intervel = 0.01;
|
double t_intervel = config_.nurbs_length_t_interval;
|
||||||
order = degree + 1;
|
order = degree + 1;
|
||||||
input_spline_inf_->control_point.clear();
|
input_spline_inf_.control_point.clear();
|
||||||
input_spline_inf_->knot_vector.clear();
|
input_spline_inf_.knot_vector.clear();
|
||||||
input_spline_inf_->weight.clear();
|
input_spline_inf_.weight.clear();
|
||||||
CurveDesign_->ReadSplineInf(input_spline_inf_, order, control_points, knot_vector);
|
CurveDesign_.ReadSplineInf(&input_spline_inf_, order, control_points, knot_vector);
|
||||||
CurveDesign_->ReadSplineInf(input_spline_inf_, weight_vector, false);
|
CurveDesign_.ReadSplineInf(&input_spline_inf_, weight_vector, false);
|
||||||
|
|
||||||
//Tính độ dài của cạnh thứ i
|
//Tính độ dài của cạnh thứ i
|
||||||
double edge_length = merge_path_calc_.calculateNURBSLength(CurveDesign_, input_spline_inf_, t_intervel);
|
double edge_length = merge_path_calc_.calculateNURBSLength(&CurveDesign_, &input_spline_inf_, t_intervel);
|
||||||
//Tính step của cạnh thứ i
|
//Tính step của cạnh thứ i
|
||||||
if (!costmap_robot_ || !costmap_robot_->getCostmap()) {
|
if (!costmap_robot_ || !costmap_robot_->getCostmap()) {
|
||||||
return false;
|
return false;
|
||||||
@@ -452,13 +475,13 @@ namespace custom_planner
|
|||||||
for(double u_test = 0; u_test <= 1; u_test += t_intervel_new)
|
for(double u_test = 0; u_test <= 1; u_test += t_intervel_new)
|
||||||
{
|
{
|
||||||
robot_geometry_msgs::Point curve_point;
|
robot_geometry_msgs::Point curve_point;
|
||||||
curve_point = CurveDesign_->CalculateCurvePoint(input_spline_inf_, u_test, true);
|
curve_point = CurveDesign_.CalculateCurvePoint(&input_spline_inf_, u_test, true);
|
||||||
if(!std::isnan(curve_point.x)&&!std::isnan(curve_point.y))
|
if(!std::isnan(curve_point.x)&&!std::isnan(curve_point.y))
|
||||||
posesOnEdge.push_back(Pose(curve_point.x, curve_point.y, 0));
|
posesOnEdge.push_back(Pose(curve_point.x, curve_point.y, 0));
|
||||||
}
|
}
|
||||||
if ((int)posesOnEdge.size() < 3)
|
if ((int)posesOnEdge.size() < 3)
|
||||||
{
|
{
|
||||||
printf("Edge has too few poses for angle calculation");
|
robot::log_info("Edge has too few poses for angle calculation");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -473,7 +496,7 @@ namespace custom_planner
|
|||||||
double delta_angle = fabs(fabs(angle_1) - fabs(angle_2));
|
double delta_angle = fabs(fabs(angle_1) - fabs(angle_2));
|
||||||
bool found_intersection = false;
|
bool found_intersection = false;
|
||||||
if((int)edges_info_.size() > 0)
|
if((int)edges_info_.size() > 0)
|
||||||
if(edges_info_.back().isCurve || delta_angle > EPSILON)
|
if(edges_info_.back().isCurve || delta_angle > kEpsilon)
|
||||||
for (int idx_segment_A = 0; idx_segment_A + 1 < (int)savePosesOnEdge.size(); ++idx_segment_A)
|
for (int idx_segment_A = 0; idx_segment_A + 1 < (int)savePosesOnEdge.size(); ++idx_segment_A)
|
||||||
{
|
{
|
||||||
robot_geometry_msgs::Point gp1 ;
|
robot_geometry_msgs::Point gp1 ;
|
||||||
@@ -554,34 +577,34 @@ namespace custom_planner
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Gán isCurve
|
// Gán isCurve
|
||||||
edge_info.isCurve = (delta_angle >= EPSILON);
|
edge_info.isCurve = (delta_angle >= kEpsilon);
|
||||||
|
|
||||||
// Thêm vào vector
|
// Thêm vào vector
|
||||||
edges_info_.push_back(edge_info);
|
edges_info_.push_back(edge_info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
printf("Trajectory of Edge: %s, startNodeId: %s, endNodeId: %s is invalid", msg.edges[i].edgeId.c_str(),
|
robot::log_info("Trajectory of Edge: %s, startNodeId: %s, endNodeId: %s is invalid", msg.edges[i].edgeId.c_str(),
|
||||||
msg.edges[i].startNodeId.c_str(), msg.edges[i].endNodeId.c_str());
|
msg.edges[i].startNodeId.c_str(), msg.edges[i].endNodeId.c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
printf("Edge: %s not found startNodeId: %s or endNodeId: %s", msg.edges[i].edgeId.c_str(),
|
robot::log_info("Edge: %s not found startNodeId: %s or endNodeId: %s", msg.edges[i].edgeId.c_str(),
|
||||||
msg.edges[i].startNodeId.c_str(), msg.edges[i].endNodeId.c_str());
|
msg.edges[i].startNodeId.c_str(), msg.edges[i].endNodeId.c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
printf("[custom_planner][makePlanWithOrder] All nodes: %s", all_nodes.c_str());
|
robot::log_info("[custom_planner][makePlanWithOrder] All nodes: %s", all_nodes.c_str());
|
||||||
printf("[custom_planner][makePlanWithOrder] All edges: %s", all_edges.c_str());
|
robot::log_info("[custom_planner][makePlanWithOrder] All edges: %s", all_edges.c_str());
|
||||||
// printf("[custom_planner][makePlanWithOrder] savePosesOnEdge: %d", (int)savePosesOnEdge.size());
|
// robot::log_info("[custom_planner][makePlanWithOrder] savePosesOnEdge: %d", (int)savePosesOnEdge.size());
|
||||||
total_edge = (int)edges_info_.size();
|
total_edge = (int)edges_info_.size();
|
||||||
bool status_countRobotDirectionChangeAngle = countRobotDirectionChangeAngle(savePosesOnEdge, total_edge);
|
bool status_countRobotDirectionChangeAngle = countRobotDirectionChangeAngle(savePosesOnEdge, total_edge);
|
||||||
bool status_calcAllYaw = false;
|
bool status_calcAllYaw = false;
|
||||||
// printf("[custom_planner][makePlanWithOrder] DEBUG 1000 total_edge: %d", total_edge);
|
// robot::log_info("[custom_planner][makePlanWithOrder] DEBUG 1000 total_edge: %d", total_edge);
|
||||||
if(status_countRobotDirectionChangeAngle) status_calcAllYaw = calcAllYaw(start, goal, savePosesOnEdge, total_edge);
|
if(status_countRobotDirectionChangeAngle) status_calcAllYaw = calcAllYaw(start, goal, savePosesOnEdge, total_edge);
|
||||||
// printf("[custom_planner][makePlanWithOrder] DEBUG 2000");
|
// robot::log_info("[custom_planner][makePlanWithOrder] DEBUG 2000");
|
||||||
return status_calcAllYaw;
|
return status_calcAllYaw;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -658,7 +681,7 @@ namespace custom_planner
|
|||||||
if (idx0 >= 0 && idx1 >= 0 && idx2 < (int)savePosesOnEdge.size())
|
if (idx0 >= 0 && idx1 >= 0 && idx2 < (int)savePosesOnEdge.size())
|
||||||
{
|
{
|
||||||
double angle = merge_path_calc_.signedAngle(savePosesOnEdge[idx0], savePosesOnEdge[idx1], savePosesOnEdge[idx2]);
|
double angle = merge_path_calc_.signedAngle(savePosesOnEdge[idx0], savePosesOnEdge[idx1], savePosesOnEdge[idx2]);
|
||||||
skipEdge_flag_ = (fabs(angle) < 0.15 * M_PI);
|
skipEdge_flag_ = (fabs(angle) < config_.skip_edge_angle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -695,8 +718,8 @@ namespace custom_planner
|
|||||||
// Hàm phụ để tính cost
|
// Hàm phụ để tính cost
|
||||||
auto calc_cost = [&](double angle) -> int
|
auto calc_cost = [&](double angle) -> int
|
||||||
{
|
{
|
||||||
if (fabs(angle) <= (0.1 * M_PI)) return 20;
|
if (fabs(angle) <= config_.cost_angle_tight) return 20;
|
||||||
if (fabs(angle) < (0.45 * M_PI)) return 10;
|
if (fabs(angle) < config_.cost_angle_wide) return 10;
|
||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -719,7 +742,7 @@ namespace custom_planner
|
|||||||
double delta_angle_1 = fabs(angle_check_2) - fabs(angle_check_1);
|
double delta_angle_1 = fabs(angle_check_2) - fabs(angle_check_1);
|
||||||
double delta_angle_2 = fabs(angle_check_4) - fabs(angle_check_3);
|
double delta_angle_2 = fabs(angle_check_4) - fabs(angle_check_3);
|
||||||
|
|
||||||
if (delta_angle_1 > EPSILON || delta_angle_2 > EPSILON) cost += 20;
|
if (delta_angle_1 > kEpsilon || delta_angle_2 > kEpsilon) cost += 20;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Kiểm tra dấu
|
// Kiểm tra dấu
|
||||||
@@ -767,7 +790,7 @@ namespace custom_planner
|
|||||||
if (cost_start >= 30 || cost_end >= 30) i++;
|
if (cost_start >= 30 || cost_end >= 30) i++;
|
||||||
// else return false;
|
// else return false;
|
||||||
}
|
}
|
||||||
// printf("[custom_planner][countRobotDirectionChangeAngle] DEBUG: 400 count_two_curve_idx(%d)", count_two_curve_idx);
|
// robot::log_info("[custom_planner][countRobotDirectionChangeAngle] DEBUG: 400 count_two_curve_idx(%d)", count_two_curve_idx);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -777,13 +800,13 @@ namespace custom_planner
|
|||||||
int& total_edge)
|
int& total_edge)
|
||||||
{
|
{
|
||||||
int total_two_curve = (int)RobotDirectionChangeAngle_info_.size();
|
int total_two_curve = (int)RobotDirectionChangeAngle_info_.size();
|
||||||
// printf("[custom_planner][calcAllYaw] total_two_curve: %d", total_two_curve);
|
// robot::log_info("[custom_planner][calcAllYaw] total_two_curve: %d", total_two_curve);
|
||||||
vector<Pose> savePoseTMP;
|
vector<Pose> savePoseTMP;
|
||||||
if(!savePoseTMP.empty()) savePoseTMP.clear();
|
if(!savePoseTMP.empty()) savePoseTMP.clear();
|
||||||
|
|
||||||
if(savePosesOnEdge.empty())
|
if(savePosesOnEdge.empty())
|
||||||
{
|
{
|
||||||
printf("[custom_planner][calcAllYaw] savePosesOnEdge is empty!\n");
|
robot::log_info("[custom_planner][calcAllYaw] savePosesOnEdge is empty!\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -795,7 +818,7 @@ namespace custom_planner
|
|||||||
{
|
{
|
||||||
if(total_two_curve > 0)
|
if(total_two_curve > 0)
|
||||||
{
|
{
|
||||||
robot::log_warning("DEBUG 1");
|
// robot::log_warning("DEBUG 1");
|
||||||
if(total_two_curve == 1)
|
if(total_two_curve == 1)
|
||||||
{
|
{
|
||||||
vector<Pose> Pose_start_tmp;
|
vector<Pose> Pose_start_tmp;
|
||||||
@@ -885,21 +908,21 @@ namespace custom_planner
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
robot::log_warning("DEBUG 2");
|
// robot::log_warning("DEBUG 2");
|
||||||
if(merge_path_calc_.status_yaw_edge_end_)
|
if(merge_path_calc_.status_yaw_edge_end_)
|
||||||
{
|
{
|
||||||
robot::log_warning("DEBUG 2.1");
|
// robot::log_warning("DEBUG 2.1");
|
||||||
reverse_ = true;
|
reverse_ = true;
|
||||||
|
|
||||||
// printf("custom_planner][calcAllYaw] DEBUG 300");
|
// robot::log_info("custom_planner][calcAllYaw] DEBUG 300");
|
||||||
setYawAllPosesOnEdge(savePosesOnEdge,true);
|
setYawAllPosesOnEdge(savePosesOnEdge,true);
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
robot::log_warning("DEBUG 2.2");
|
// robot::log_warning("DEBUG 2.2");
|
||||||
reverse_ = false;
|
reverse_ = false;
|
||||||
// printf("custom_planner][calcAllYaw] DEBUG 310");
|
// robot::log_info("custom_planner][calcAllYaw] DEBUG 310");
|
||||||
setYawAllPosesOnEdge(savePosesOnEdge,false);
|
setYawAllPosesOnEdge(savePosesOnEdge,false);
|
||||||
}
|
}
|
||||||
savePoseTMP.insert(savePoseTMP.end(), savePosesOnEdge.begin(),savePosesOnEdge.end());
|
savePoseTMP.insert(savePoseTMP.end(), savePosesOnEdge.begin(),savePosesOnEdge.end());
|
||||||
@@ -918,7 +941,7 @@ namespace custom_planner
|
|||||||
idx_2 < 0 || idx_2 >= static_cast<int>(savePoseTMP.size()) ||
|
idx_2 < 0 || idx_2 >= static_cast<int>(savePoseTMP.size()) ||
|
||||||
idx_3 < 0 || idx_3 >= static_cast<int>(savePoseTMP.size()))
|
idx_3 < 0 || idx_3 >= static_cast<int>(savePoseTMP.size()))
|
||||||
{
|
{
|
||||||
printf("Invalid indices: %d, %d, %d", idx_1, idx_2, idx_3);
|
robot::log_info("Invalid indices: %d, %d, %d", idx_1, idx_2, idx_3);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -926,11 +949,11 @@ namespace custom_planner
|
|||||||
savePoseTMP[idx_2],
|
savePoseTMP[idx_2],
|
||||||
savePoseTMP[idx_3]);
|
savePoseTMP[idx_3]);
|
||||||
// Cần tính lại các góc quay
|
// Cần tính lại các góc quay
|
||||||
if(fabs(delta_Angle) > (0.45 * M_PI) && fabs(delta_Angle) < (0.85 * M_PI))
|
if(fabs(delta_Angle) > config_.rotation_insert_min && fabs(delta_Angle) < config_.rotation_insert_max)
|
||||||
{
|
{
|
||||||
MatrixPose[i].clear();
|
MatrixPose[i].clear();
|
||||||
|
|
||||||
int max_step = (int)((M_PI - fabs(delta_Angle)) / (0.05 * M_PI));
|
int max_step = (int)((M_PI - fabs(delta_Angle)) / config_.rotation_step);
|
||||||
for(int j = 0; j <= max_step; j++)
|
for(int j = 0; j <= max_step; j++)
|
||||||
{
|
{
|
||||||
Pose intermediate_pose;
|
Pose intermediate_pose;
|
||||||
@@ -938,11 +961,11 @@ namespace custom_planner
|
|||||||
intermediate_pose.setY(savePoseTMP[edges_info_[i].start_edge_idx].getY());
|
intermediate_pose.setY(savePoseTMP[edges_info_[i].start_edge_idx].getY());
|
||||||
if(delta_Angle < 0)
|
if(delta_Angle < 0)
|
||||||
{
|
{
|
||||||
intermediate_pose.setYaw(savePoseTMP[edges_info_[i-1].end_edge_idx].getYaw() + j * (0.05 * M_PI));
|
intermediate_pose.setYaw(savePoseTMP[edges_info_[i-1].end_edge_idx].getYaw() + j * config_.rotation_step);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
intermediate_pose.setYaw(savePoseTMP[edges_info_[i-1].end_edge_idx].getYaw() - j * (0.05 * M_PI));
|
intermediate_pose.setYaw(savePoseTMP[edges_info_[i-1].end_edge_idx].getYaw() - j * config_.rotation_step);
|
||||||
}
|
}
|
||||||
// intermediate_pose.getX(), intermediate_pose.getY(), intermediate_pose.getYaw());
|
// intermediate_pose.getX(), intermediate_pose.getY(), intermediate_pose.getYaw());
|
||||||
MatrixPose[i].push_back(intermediate_pose);
|
MatrixPose[i].push_back(intermediate_pose);
|
||||||
@@ -982,18 +1005,19 @@ namespace custom_planner
|
|||||||
savePosesOnEdge[idx_3]);
|
savePosesOnEdge[idx_3]);
|
||||||
delta_Angle = delta_Angle - M_PI;
|
delta_Angle = delta_Angle - M_PI;
|
||||||
|
|
||||||
if(fabs(delta_Angle) > (0.05 * M_PI))
|
// Chỉ chèn khi lệch quá một bước xoay — dưới đó coi như thẳng hàng.
|
||||||
|
if(fabs(delta_Angle) > config_.rotation_step)
|
||||||
{
|
{
|
||||||
MatrixPose[i].clear();
|
MatrixPose[i].clear();
|
||||||
int max_step = (int)((M_PI - fabs(delta_Angle)) / (0.05 * M_PI));
|
int max_step = (int)((M_PI - fabs(delta_Angle)) / config_.rotation_step);
|
||||||
for(int j = 0; j <= max_step; j++) {
|
for(int j = 0; j <= max_step; j++) {
|
||||||
Pose intermediate_pose;
|
Pose intermediate_pose;
|
||||||
intermediate_pose.setX(savePosesOnEdge[edges_info_[i].start_edge_idx].getX());
|
intermediate_pose.setX(savePosesOnEdge[edges_info_[i].start_edge_idx].getX());
|
||||||
intermediate_pose.setY(savePosesOnEdge[edges_info_[i].start_edge_idx].getY());
|
intermediate_pose.setY(savePosesOnEdge[edges_info_[i].start_edge_idx].getY());
|
||||||
if(delta_Angle > 0) {
|
if(delta_Angle > 0) {
|
||||||
intermediate_pose.setYaw(savePosesOnEdge[edges_info_[i-1].end_edge_idx].getYaw() + j * (0.05 * M_PI));
|
intermediate_pose.setYaw(savePosesOnEdge[edges_info_[i-1].end_edge_idx].getYaw() + j * config_.rotation_step);
|
||||||
} else {
|
} else {
|
||||||
intermediate_pose.setYaw(savePosesOnEdge[edges_info_[i-1].end_edge_idx].getYaw() - j * (0.05 * M_PI));
|
intermediate_pose.setYaw(savePosesOnEdge[edges_info_[i-1].end_edge_idx].getYaw() - j * config_.rotation_step);
|
||||||
}
|
}
|
||||||
MatrixPose[i].push_back(intermediate_pose);
|
MatrixPose[i].push_back(intermediate_pose);
|
||||||
}
|
}
|
||||||
@@ -1037,7 +1061,7 @@ namespace custom_planner
|
|||||||
merge_path_calc_.edge_back_end_idx_ = (int)posesOnPathWay_.size() - 1;
|
merge_path_calc_.edge_back_end_idx_ = (int)posesOnPathWay_.size() - 1;
|
||||||
merge_path_calc_.edge_back_start_idx_ = merge_path_calc_.edge_back_end_idx_ - total;
|
merge_path_calc_.edge_back_start_idx_ = merge_path_calc_.edge_back_end_idx_ - total;
|
||||||
// posesOnPathWay_.shrink_to_fit();
|
// posesOnPathWay_.shrink_to_fit();
|
||||||
// printf("[custom_planner][makePlanWithOrder] DEBUG: 2 posesOnPathWay_ size(%d)", (int)posesOnPathWay_.size());
|
// robot::log_info("[custom_planner][makePlanWithOrder] DEBUG: 2 posesOnPathWay_ size(%d)", (int)posesOnPathWay_.size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -1071,30 +1095,22 @@ namespace custom_planner
|
|||||||
return P;
|
return P;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CustomPlanner::isThetaValid(double theta)
|
|
||||||
{
|
|
||||||
bool result = false;
|
|
||||||
if(theta < -M_PI || theta > M_PI) result = false;
|
|
||||||
else result = true;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CustomPlanner::curveIsValid(int degree, const std::vector<double> &knot_vector,
|
bool CustomPlanner::curveIsValid(int degree, const std::vector<double> &knot_vector,
|
||||||
vector<Eigen::Vector3d, Eigen::aligned_allocator<Eigen::Vector3d>>& control_points)
|
vector<Eigen::Vector3d, Eigen::aligned_allocator<Eigen::Vector3d>>& control_points)
|
||||||
{
|
{
|
||||||
if(degree < 1 || degree > 9)
|
if(degree < 1 || degree > 9)
|
||||||
{
|
{
|
||||||
printf("degree is invalid value\n");
|
robot::log_info("degree is invalid value\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(!((knot_vector.size() - degree - 1) == control_points.size()))
|
if(!((knot_vector.size() - degree - 1) == control_points.size()))
|
||||||
{
|
{
|
||||||
printf("relation between degree, number of knots, and number of control points is invalid\n");
|
robot::log_info("relation between degree, number of knots, and number of control points is invalid\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// if(std::is_sorted(knot_vector.begin(), knot_vector.end()))
|
// if(std::is_sorted(knot_vector.begin(), knot_vector.end()))
|
||||||
// {
|
// {
|
||||||
// printf("knot vector is not monotonic");
|
// robot::log_info("knot vector is not monotonic");
|
||||||
// return false;
|
// return false;
|
||||||
// }
|
// }
|
||||||
return true;
|
return true;
|
||||||
@@ -1157,26 +1173,24 @@ namespace custom_planner
|
|||||||
double angle = merge_path_calc_.calculateAngle(start_edge_pose.getX(), start_edge_pose.getY(), end_edge_pose.getX(), end_edge_pose.getY());
|
double angle = merge_path_calc_.calculateAngle(start_edge_pose.getX(), start_edge_pose.getY(), end_edge_pose.getX(), end_edge_pose.getY());
|
||||||
|
|
||||||
double yaw_goal = data_convert::getYaw(goal.pose.orientation);
|
double yaw_goal = data_convert::getYaw(goal.pose.orientation);
|
||||||
// printf("[custom_planner] DEBUG: angle: %f; yaw_goal: %f",angle, yaw_goal);
|
|
||||||
// nomalize angle [-pi, pi] to [0, 2*pi]
|
auto wrapToPi = [](double a) {
|
||||||
auto normalizeAngle = [](double a) -> double
|
while (a > M_PI) a -= 2 * M_PI;
|
||||||
{
|
while (a < -M_PI) a += 2 * M_PI;
|
||||||
while (a > 2 * M_PI) a -= 2 * M_PI;
|
|
||||||
while (a < 0) a += 2 * M_PI;
|
|
||||||
return a;
|
return a;
|
||||||
};
|
};
|
||||||
|
|
||||||
auto wrapToPi = [](double a) -> double
|
// Lệch góc thật giữa yaw goal và hướng cạnh cuối. KHÔNG dùng
|
||||||
{
|
// fabs(|a|-|b|): nó xoá dấu nên cặp góc trái dấu cùng độ lớn (vd ±pi/2,
|
||||||
while (a > M_PI) a -= 2.0 * M_PI;
|
// lệch thật = pi) cho delta = 0 — planner chọn nhầm đi tiến và robot
|
||||||
while (a < -M_PI) a += 2.0 * M_PI;
|
// quay đầu thay vì lùi.
|
||||||
return a;
|
//
|
||||||
};
|
// Bản trên `main` chuẩn hoá cả hai góc về [0, 2pi) trước khi trừ rồi mới
|
||||||
|
// wrapToPi. Chuẩn hoá chỉ cộng bội 2pi nên kết quả sau wrapToPi y hệt —
|
||||||
double delta_angle = std::fabs(wrapToPi(normalizeAngle(yaw_goal) - normalizeAngle(angle)));
|
// giữ dạng ngắn ở đây. Ngưỡng cũng giữ nguyên trị: mặc định của
|
||||||
|
// `backward_decision_angle` là 0.5*pi, đúng con số `main` gắn cứng.
|
||||||
robot::log_warning("DEBUG 3: yaw_goal: %f, angle: %f, delta_angle: %f", yaw_goal, angle, delta_angle);
|
double delta_angle = std::fabs(wrapToPi(yaw_goal - angle));
|
||||||
return (delta_angle > (0.5 * M_PI));
|
return (delta_angle > config_.backward_decision_angle);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Export factory function
|
// Export factory function
|
||||||
|
|||||||
@@ -0,0 +1,75 @@
|
|||||||
|
#include <custom_planner/custom_planner_config.h>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
namespace custom_planner
|
||||||
|
{
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
|
||||||
|
void clampParam(double& value, double lo, double hi, const char* name)
|
||||||
|
{
|
||||||
|
if (value < lo || value > hi)
|
||||||
|
{
|
||||||
|
const double clamped = std::clamp(value, lo, hi);
|
||||||
|
robot::log_warning("[custom_planner] param %s=%.4f ngoài range [%.4f, %.4f], kẹp về %.4f",
|
||||||
|
name, value, lo, hi, clamped);
|
||||||
|
value = clamped;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
void CustomPlannerConfig::load(robot::NodeHandle& nh)
|
||||||
|
{
|
||||||
|
nh.getParam("pathway_attach_distance", pathway_attach_distance, pathway_attach_distance);
|
||||||
|
nh.getParam("bare_goal_max_distance", bare_goal_max_distance, bare_goal_max_distance);
|
||||||
|
nh.getParam("nurbs_length_t_interval", nurbs_length_t_interval, nurbs_length_t_interval);
|
||||||
|
nh.getParam("nurbs_point_spacing", nurbs_point_spacing, nurbs_point_spacing);
|
||||||
|
nh.getParam("skip_edge_angle", skip_edge_angle, skip_edge_angle);
|
||||||
|
nh.getParam("cost_angle_tight", cost_angle_tight, cost_angle_tight);
|
||||||
|
nh.getParam("cost_angle_wide", cost_angle_wide, cost_angle_wide);
|
||||||
|
nh.getParam("rotation_insert_min", rotation_insert_min, rotation_insert_min);
|
||||||
|
nh.getParam("rotation_insert_max", rotation_insert_max, rotation_insert_max);
|
||||||
|
nh.getParam("rotation_step", rotation_step, rotation_step);
|
||||||
|
nh.getParam("backward_decision_angle", backward_decision_angle, backward_decision_angle);
|
||||||
|
|
||||||
|
validate();
|
||||||
|
|
||||||
|
robot::log_info(
|
||||||
|
"[custom_planner] config: pathway_attach_distance=%.3f[m] bare_goal_max_distance=%.3f[m] "
|
||||||
|
"nurbs_length_t_interval=%.4f nurbs_point_spacing=%.3f[m] skip_edge_angle=%.4f[rad] "
|
||||||
|
"cost_angle_tight=%.4f[rad] cost_angle_wide=%.4f[rad] rotation_insert=[%.4f, %.4f][rad] "
|
||||||
|
"rotation_step=%.4f[rad] backward_decision_angle=%.4f[rad]",
|
||||||
|
pathway_attach_distance, bare_goal_max_distance, nurbs_length_t_interval,
|
||||||
|
nurbs_point_spacing, skip_edge_angle, cost_angle_tight, cost_angle_wide,
|
||||||
|
rotation_insert_min, rotation_insert_max, rotation_step, backward_decision_angle);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CustomPlannerConfig::validate()
|
||||||
|
{
|
||||||
|
clampParam(pathway_attach_distance, 0.0, 5.0, "pathway_attach_distance");
|
||||||
|
clampParam(bare_goal_max_distance, 0.0, 10.0, "bare_goal_max_distance");
|
||||||
|
clampParam(nurbs_length_t_interval, 1e-4, 0.5, "nurbs_length_t_interval");
|
||||||
|
clampParam(nurbs_point_spacing, 1e-3, 1.0, "nurbs_point_spacing");
|
||||||
|
clampParam(skip_edge_angle, 0.0, M_PI, "skip_edge_angle");
|
||||||
|
clampParam(cost_angle_tight, 0.0, M_PI, "cost_angle_tight");
|
||||||
|
clampParam(cost_angle_wide, 0.0, M_PI, "cost_angle_wide");
|
||||||
|
clampParam(rotation_insert_min, 0.0, M_PI, "rotation_insert_min");
|
||||||
|
clampParam(rotation_insert_max, 0.0, M_PI, "rotation_insert_max");
|
||||||
|
clampParam(rotation_step, 1e-3, M_PI, "rotation_step");
|
||||||
|
clampParam(backward_decision_angle, 0.0, M_PI, "backward_decision_angle");
|
||||||
|
|
||||||
|
if (cost_angle_wide < cost_angle_tight)
|
||||||
|
{
|
||||||
|
robot::log_warning("[custom_planner] cost_angle_wide < cost_angle_tight, nâng wide lên bằng tight");
|
||||||
|
cost_angle_wide = cost_angle_tight;
|
||||||
|
}
|
||||||
|
if (rotation_insert_max < rotation_insert_min)
|
||||||
|
{
|
||||||
|
robot::log_warning("[custom_planner] rotation_insert_max < rotation_insert_min, nâng max lên bằng min");
|
||||||
|
rotation_insert_max = rotation_insert_min;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace custom_planner
|
||||||
|
|||||||
@@ -1,16 +1,11 @@
|
|||||||
#include"custom_planner/merge_path_calc.h"
|
#include"custom_planner/merge_path_calc.h"
|
||||||
|
|
||||||
|
using std::vector;
|
||||||
|
|
||||||
namespace custom_planner {
|
namespace custom_planner {
|
||||||
|
|
||||||
MergePathCalc::MergePathCalc(){
|
MergePathCalc::MergePathCalc() = default;
|
||||||
curve_design = new Curve_common();
|
MergePathCalc::~MergePathCalc() = default;
|
||||||
spline_inf = new Spline_Inf();
|
|
||||||
}
|
|
||||||
MergePathCalc::~MergePathCalc(){
|
|
||||||
// Giải phóng bộ nhớ
|
|
||||||
delete curve_design;
|
|
||||||
delete spline_inf;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<robot_geometry_msgs::PoseStamped> MergePathCalc::calculateNURBSPath(vector<robot_geometry_msgs::PoseStamped>& control_points, bool reverse)
|
std::vector<robot_geometry_msgs::PoseStamped> MergePathCalc::calculateNURBSPath(vector<robot_geometry_msgs::PoseStamped>& control_points, bool reverse)
|
||||||
{
|
{
|
||||||
@@ -46,22 +41,21 @@ namespace custom_planner {
|
|||||||
// Điều chỉnh weights để tăng ảnh hưởng của các control points
|
// Điều chỉnh weights để tăng ảnh hưởng của các control points
|
||||||
std::vector<double> weights(control_points.size(), 1.0);
|
std::vector<double> weights(control_points.size(), 1.0);
|
||||||
|
|
||||||
spline_inf->knot_vector.clear();
|
spline_inf.knot_vector.clear();
|
||||||
spline_inf->control_point.clear();
|
spline_inf.control_point.clear();
|
||||||
spline_inf->weight.clear();
|
spline_inf.weight.clear();
|
||||||
|
|
||||||
// Cài đặt thông số cho spline
|
// Cài đặt thông số cho spline
|
||||||
curve_design->ReadSplineInf(spline_inf, degree + 1, eigen_control_points, knot_vector);
|
curve_design.ReadSplineInf(&spline_inf, degree + 1, eigen_control_points, knot_vector);
|
||||||
curve_design->ReadSplineInf(spline_inf, weights, false);
|
curve_design.ReadSplineInf(&spline_inf, weights, false);
|
||||||
|
|
||||||
// Tính độ dài đường cong để xác định số điểm cần lấy mẫu
|
// Tính độ dài đường cong để xác định số điểm cần lấy mẫu
|
||||||
double NURBS_length = calculateNURBSLength(curve_design, spline_inf, 0.01);
|
double NURBS_length = calculateNURBSLength(&curve_design, &spline_inf, 0.01);
|
||||||
double desired_spacing = 0.05; // Khoảng cách mong muốn giữa các điểm
|
double step = calculateAdaptiveStep(NURBS_length, desired_point_spacing_);
|
||||||
double step = calculateAdaptiveStep(NURBS_length, desired_spacing);
|
|
||||||
|
|
||||||
for(double t = 0.0; t <= 1.0; t += step)
|
for(double t = 0.0; t <= 1.0; t += step)
|
||||||
{
|
{
|
||||||
robot_geometry_msgs::Point point = curve_design->CalculateCurvePoint(spline_inf, t, true);
|
robot_geometry_msgs::Point point = curve_design.CalculateCurvePoint(&spline_inf, t, true);
|
||||||
if(!std::isnan(point.x) && !std::isnan(point.y))
|
if(!std::isnan(point.x) && !std::isnan(point.y))
|
||||||
{
|
{
|
||||||
robot_geometry_msgs::PoseStamped pose;
|
robot_geometry_msgs::PoseStamped pose;
|
||||||
|
|||||||
291
src/pathway.cc
291
src/pathway.cc
@@ -1,291 +0,0 @@
|
|||||||
#include "custom_planner/pathway.h"
|
|
||||||
|
|
||||||
using namespace custom_planner;
|
|
||||||
|
|
||||||
bool Pathway::onSegment(Pose p, Pose q, Pose r)
|
|
||||||
{
|
|
||||||
if (q.getX() <= max(p.getX(), r.getX()) && q.getX() >= min(p.getX(), r.getX()) &&
|
|
||||||
q.getY() <= max(p.getY(), r.getY()) && q.getY() >= min(p.getY(), r.getY()))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
int Pathway::orientation(Pose p, Pose q, Pose r)
|
|
||||||
{
|
|
||||||
int val = (q.getY() - p.getY()) * (r.getX() - q.getX()) -
|
|
||||||
(q.getX() - p.getX()) * (r.getY() - q.getY());
|
|
||||||
|
|
||||||
if (val == 0) return 0; // collinear
|
|
||||||
|
|
||||||
return (val > 0)? 1: 2; // clock or counterclock wise
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Pathway::doIntersect(Pose p1, Pose q1, Pose p2, Pose q2)
|
|
||||||
{
|
|
||||||
// Find the four orientations needed for general and
|
|
||||||
// special cases
|
|
||||||
int o1 = orientation(p1, q1, p2);
|
|
||||||
int o2 = orientation(p1, q1, q2);
|
|
||||||
int o3 = orientation(p2, q2, p1);
|
|
||||||
int o4 = orientation(p2, q2, q1);
|
|
||||||
|
|
||||||
// General case
|
|
||||||
if (o1 != o2 && o3 != o4)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
// Special Cases
|
|
||||||
// p1, q1 and p2 are collinear and p2 lies on segment p1q1
|
|
||||||
if (o1 == 0 && onSegment(p1, p2, q1)) return true;
|
|
||||||
|
|
||||||
// p1, q1 and q2 are collinear and q2 lies on segment p1q1
|
|
||||||
if (o2 == 0 && onSegment(p1, q2, q1)) return true;
|
|
||||||
|
|
||||||
// p2, q2 and p1 are collinear and p1 lies on segment p2q2
|
|
||||||
if (o3 == 0 && onSegment(p2, p1, q2)) return true;
|
|
||||||
|
|
||||||
// p2, q2 and q1 are collinear and q1 lies on segment p2q2
|
|
||||||
if (o4 == 0 && onSegment(p2, q1, q2)) return true;
|
|
||||||
|
|
||||||
return false; // Doesn't fall in any of the above cases
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Pathway::isIntersect(Edge L) {
|
|
||||||
for (auto& segment : path_) {
|
|
||||||
if (doIntersect(L.getP1(), L.getP2(), segment.getP1(), segment.getP2())) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
bool Pathway::isPoseExisted(Pose p)
|
|
||||||
{
|
|
||||||
for(auto& pose : posesOnPath_)
|
|
||||||
{
|
|
||||||
if(p.getX()==pose.getX() && p.getY()==pose.getY()) return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
double Pathway::calculateAngle(Pose p1, Pose p2, Pose p3)
|
|
||||||
{
|
|
||||||
// Tính vector 1
|
|
||||||
double vector1x = p2.getX() - p1.getX();
|
|
||||||
double vector1y = p2.getY() - p1.getY();
|
|
||||||
|
|
||||||
// Tính vector 2
|
|
||||||
double vector2x = p3.getX() - p2.getX();
|
|
||||||
double vector2y = p3.getY() - p2.getY();
|
|
||||||
|
|
||||||
// Tính độ dài của hai vector
|
|
||||||
double lengthVector1 = sqrt(vector1x * vector1x + vector1y * vector1y);
|
|
||||||
double lengthVector2 = sqrt(vector2x * vector2x + vector2y * vector2y);
|
|
||||||
|
|
||||||
// Tính góc giữa hai vector
|
|
||||||
double dotProduct = vector1x * vector2x + vector1y * vector2y;
|
|
||||||
double cosTheta = dotProduct / (lengthVector1 * lengthVector2);
|
|
||||||
if(cosTheta>1) cosTheta = 1;
|
|
||||||
else if(cosTheta<(-1)) cosTheta = -1;
|
|
||||||
// Đổi radian sang độ
|
|
||||||
double angle = acos(cosTheta) * 180.0 / M_PI;
|
|
||||||
|
|
||||||
return angle;
|
|
||||||
}
|
|
||||||
void Pathway::RecordPath(Pose startPose, Pose currentPose, double delta_angle_th, double InitialSegmentLengthMin, double SegmentLengthMin)
|
|
||||||
{
|
|
||||||
if(!isPathInitilized_)
|
|
||||||
{
|
|
||||||
double InitialSegmentLength = sqrt(pow(currentPose.getX() - startPose.getX(), 2) + pow(currentPose.getY() - startPose.getY(), 2));
|
|
||||||
if(InitialSegmentLength>=InitialSegmentLengthMin)
|
|
||||||
{
|
|
||||||
addEdge(startPose, currentPose);
|
|
||||||
isPathInitilized_ = true;
|
|
||||||
printf("path is initialized\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
if(!path_.empty())
|
|
||||||
{
|
|
||||||
double distanceCheck = sqrt(pow(currentPose.getX() - path_.back().getP2().getX(), 2) + pow(currentPose.getY() - path_.back().getP2().getY(), 2));
|
|
||||||
if(distanceCheck>=SegmentLengthMin)
|
|
||||||
{
|
|
||||||
if(isNewPoseOnEdge(currentPose, delta_angle_th)){
|
|
||||||
setP2LastEdgeOnPath(currentPose);
|
|
||||||
printf("add new pose on segment into path\n");
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
addEdge(currentPose);
|
|
||||||
printf("add new segment into path\n");
|
|
||||||
}
|
|
||||||
printf("Number of segment on path: %d\n",(int)path_.size());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void Pathway::ResetAndRecordPath(Pose startPose, Pose currentPose, double delta_angle_th, double InitialSegmentLengthMin, double SegmentLengthMin)
|
|
||||||
{
|
|
||||||
if(!isPathClear_){
|
|
||||||
path_.clear();
|
|
||||||
isPathClear_ = true;
|
|
||||||
}
|
|
||||||
RecordPath(startPose, currentPose, delta_angle_th, InitialSegmentLengthMin, SegmentLengthMin);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Pathway::isNewPoseOnEdge(Pose p, double delta_angle_th)
|
|
||||||
{
|
|
||||||
if(!path_.empty())
|
|
||||||
{
|
|
||||||
double deltaAngle = calculateAngle(path_.back().getP1(), path_.back().getP2(), p);
|
|
||||||
// ROS_WARN("deltaAngle: %f",deltaAngle);
|
|
||||||
if(deltaAngle<=delta_angle_th) return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Pathway::setEdgeOnPath(uint32_t line_index, Pose p1, Pose p2){
|
|
||||||
if(!path_.empty()&&line_index<=path_.size())
|
|
||||||
{
|
|
||||||
path_.at(line_index).setEdge(p1, p2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Pathway::syncPosesAndPath()
|
|
||||||
{
|
|
||||||
if(!path_.empty())
|
|
||||||
{
|
|
||||||
posesOnPath_.clear();
|
|
||||||
for(auto& edge : path_)
|
|
||||||
{
|
|
||||||
if(!isPoseExisted(edge.getP1())) posesOnPath_.push_back(edge.getP1());
|
|
||||||
if(!isPoseExisted(edge.getP2())) posesOnPath_.push_back(edge.getP2());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else posesOnPath_.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Pathway::SavePathAsFile(const string& file_name)
|
|
||||||
{
|
|
||||||
ofstream file(file_name);
|
|
||||||
|
|
||||||
if (file.is_open())
|
|
||||||
{
|
|
||||||
for (auto &edge : path_)
|
|
||||||
{
|
|
||||||
file << edge.getP1().getX() << " " << edge.getP1().getY() << " " << edge.getP1().getYaw()
|
|
||||||
<< edge.getP2().getX() << " " << edge.getP2().getY() << " " << edge.getP2().getYaw() << "\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
file.close();
|
|
||||||
cout << "Pathway saved to file: " <<file_name<< endl;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
cerr << "Unable to open file for saving: "<<file_name<< endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Pathway::LoadPathFromFile(const string& file_name)
|
|
||||||
{
|
|
||||||
ifstream file(file_name);
|
|
||||||
|
|
||||||
if (file.is_open())
|
|
||||||
{
|
|
||||||
path_.clear();
|
|
||||||
|
|
||||||
double x1, y1, x2, y2, yaw1, yaw2;
|
|
||||||
|
|
||||||
while (file >> x1 >> y1 >> yaw1 >> x2 >> y2 >> yaw2)
|
|
||||||
{
|
|
||||||
Pose p1(x1, y1, yaw1);
|
|
||||||
Pose p2(x2, y2, yaw2);
|
|
||||||
|
|
||||||
addEdge(p1, p2);
|
|
||||||
}
|
|
||||||
|
|
||||||
file.close();
|
|
||||||
cout << "Pathway loaded from file: " <<file_name<< endl;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
cerr << "Unable to open file for loading: " <<file_name<< endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Pathway::findIntersection(Edge L1, Edge L2, Point* resultPoint)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
A = (x1, y1)
|
|
||||||
B = (x2, y2)
|
|
||||||
C = (x3, y3)
|
|
||||||
D = (x4, y4)
|
|
||||||
AB = (x2 - x1, y2 - y1)
|
|
||||||
CD = (x4 - x3, y4 - y3)
|
|
||||||
A + αAB = C + βCD
|
|
||||||
α = ((x4 - x3)*(y3 - y1) - (y4 - y3)*(x3 - x1)) / ((x4 - x3)*(y2 - y1) - (y4 - y3)*(x2 - x1)) = a / b
|
|
||||||
β = ((x2 - x1)*(y3 - y1) - (y2 - y1)*(x3 - x1)) / ((x4 - x3)*(y2 - y1) - (y4 - y3)*(x2 - x1)) = c / b
|
|
||||||
P = (x0, y0)
|
|
||||||
x0 = x1 + α*(x2 - x1) = x3 + β*(x4 - x3)
|
|
||||||
y0 = y1 + α*(y2 - y1) = y3 + β*(y4 - y3)
|
|
||||||
*/
|
|
||||||
double x1 = L1.getP1().getX();
|
|
||||||
double y1 = L1.getP1().getY();
|
|
||||||
double x2 = L1.getP2().getX();
|
|
||||||
double y2 = L1.getP2().getY();
|
|
||||||
double x3 = L2.getP1().getX();
|
|
||||||
double y3 = L2.getP1().getY();
|
|
||||||
double x4 = L2.getP2().getX();
|
|
||||||
double y4 = L2.getP2().getY();
|
|
||||||
double a = (x4 - x3)*(y3 - y1) - (y4 - y3)*(x3 - x1);
|
|
||||||
double b = (x4 - x3)*(y2 - y1) - (y4 - y3)*(x2 - x1);
|
|
||||||
double c = (x2 - x1)*(y3 - y1) - (y2 - y1)*(x3 - x1);
|
|
||||||
double alpha = a/b;
|
|
||||||
double beta = c/b;
|
|
||||||
if(b==0) return false;
|
|
||||||
if(a==0&&b==0) return false;
|
|
||||||
else if(alpha>=0&&alpha<=1&&beta>=0&&beta<=1)
|
|
||||||
{
|
|
||||||
double x0 = x1 + alpha*(x2 - x1);
|
|
||||||
double y0 = y1 + alpha*(y2 - y1);
|
|
||||||
resultPoint->setPoint(x0,y0);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
vector<Point> Pathway::findIntersections(Edge L) {
|
|
||||||
vector<Point> intersectionPoints;
|
|
||||||
if(!path_.empty()){
|
|
||||||
for (auto& segment : path_){
|
|
||||||
Point result;
|
|
||||||
if(findIntersection(L,segment,&result)==true)
|
|
||||||
{
|
|
||||||
intersectionPoints.push_back(result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return intersectionPoints;
|
|
||||||
}
|
|
||||||
|
|
||||||
vector<vector<Point>> Pathway::findIntersections(Edge L1, Edge L2) {
|
|
||||||
vector<vector<Point>> intersectionPoints;
|
|
||||||
vector<Point> intersectionPointsL1;
|
|
||||||
vector<Point> intersectionPointsL2;
|
|
||||||
if(!path_.empty()){
|
|
||||||
for (auto& segment : path_) {
|
|
||||||
Point result1;
|
|
||||||
if(findIntersection(L1,segment,&result1)==true)
|
|
||||||
{
|
|
||||||
intersectionPointsL1.push_back(result1);
|
|
||||||
}
|
|
||||||
Point result2;
|
|
||||||
if(findIntersection(L2,segment,&result2)==true)
|
|
||||||
{
|
|
||||||
intersectionPointsL2.push_back(result2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
intersectionPoints.push_back(intersectionPointsL1);
|
|
||||||
intersectionPoints.push_back(intersectionPointsL2);
|
|
||||||
|
|
||||||
return intersectionPoints;
|
|
||||||
}
|
|
||||||
@@ -1,686 +0,0 @@
|
|||||||
#include <iostream>
|
|
||||||
#include <vector>
|
|
||||||
#include <cmath>
|
|
||||||
#include <string>
|
|
||||||
#include <ros/ros.h>
|
|
||||||
#include <tf/tf.h>
|
|
||||||
#include <tf/transform_listener.h>
|
|
||||||
#include <tf2_ros/transform_listener.h>
|
|
||||||
#include <tf2/convert.h>
|
|
||||||
#include <tf2_ros/buffer.h>
|
|
||||||
|
|
||||||
#include <robot_geometry_msgs/PoseStamped.h>
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
inline double calculateAngle(double xA, double yA, double xB, double yB) {
|
|
||||||
double deltaX = xB - xA;
|
|
||||||
double deltaY = yB - yA;
|
|
||||||
double angleRad = 0;
|
|
||||||
if(deltaX!=0)
|
|
||||||
{
|
|
||||||
angleRad = atan2(deltaY, deltaX);
|
|
||||||
// double angleDeg = angleRad * 180.0 / M_PI;
|
|
||||||
}
|
|
||||||
return angleRad;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline double getYaw(double x, double y, double z, double w){
|
|
||||||
// yaw (z-axis rotation)
|
|
||||||
double siny_cosp = 2 * (w * z + x * y);
|
|
||||||
double cosy_cosp = 1 - 2 * (y * y + z * z);
|
|
||||||
double yaw = std::atan2(siny_cosp, cosy_cosp);
|
|
||||||
return yaw;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isThetaValid(double theta)
|
|
||||||
{
|
|
||||||
bool result = false;
|
|
||||||
if(theta < -M_PI || theta > M_PI) result = false;
|
|
||||||
else result = true;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
double computeDeltaAngleStartOfPlan(double theta, robot_geometry_msgs::Pose& startPose, robot_geometry_msgs::Pose& next_Pose)
|
|
||||||
{
|
|
||||||
double delta_angle = 0;
|
|
||||||
if(isThetaValid(theta))
|
|
||||||
{
|
|
||||||
double xAB = next_Pose.position.x - startPose.position.x;
|
|
||||||
double yAB = next_Pose.position.y - startPose.position.y;
|
|
||||||
double d = sqrt(xAB*xAB + yAB*yAB);
|
|
||||||
double xC = startPose.position.x + d*cos(theta);
|
|
||||||
double yC = startPose.position.y + d*sin(theta);
|
|
||||||
double xAC = xC-startPose.position.x;
|
|
||||||
double yAC = yC-startPose.position.y;
|
|
||||||
double dAB = sqrt(xAB*xAB + yAB*yAB);
|
|
||||||
double cos_a = (xAB*xAC + yAB*yAC)/(dAB*d);
|
|
||||||
if(cos_a>1) cos_a = 1;
|
|
||||||
else if(cos_a<(-1)) cos_a = -1;
|
|
||||||
delta_angle = acos(cos_a);
|
|
||||||
// delta_angle = delta_angle*180/M_PI;
|
|
||||||
// ROS_WARN("xC: %f, yC: %f", xC, yC);
|
|
||||||
// ROS_WARN("dAB: %f", dAB);
|
|
||||||
// ROS_WARN("delta_angle: %f", delta_angle);
|
|
||||||
}
|
|
||||||
return delta_angle;
|
|
||||||
}
|
|
||||||
|
|
||||||
double computeDeltaAngleEndOfPlan(double theta, robot_geometry_msgs::Pose& endPose, robot_geometry_msgs::Pose& prev_Pose)
|
|
||||||
{
|
|
||||||
double delta_angle = 0;
|
|
||||||
if(isThetaValid(theta))
|
|
||||||
{
|
|
||||||
double xAB =endPose.position.x-prev_Pose.position.x;
|
|
||||||
double yAB = endPose.position.y-prev_Pose.position.y;
|
|
||||||
double d = sqrt(xAB*xAB + yAB*yAB);
|
|
||||||
double xC =endPose.position.x + d*cos(theta);
|
|
||||||
double yC = endPose.position.y + d*sin(theta);
|
|
||||||
double xBC = xC-endPose.position.x;
|
|
||||||
double yBC = yC-endPose.position.y;
|
|
||||||
double dAB = sqrt(xAB*xAB + yAB*yAB);
|
|
||||||
double cos_a = (xAB*xBC + yAB*yBC)/(dAB*d);
|
|
||||||
if(cos_a>1) cos_a = 1;
|
|
||||||
else if(cos_a<(-1)) cos_a = -1;
|
|
||||||
delta_angle = acos(cos_a);
|
|
||||||
// delta_angle = delta_angle*180/M_PI;
|
|
||||||
// ROS_WARN("xC: %f, yC: %f", xC, yC);
|
|
||||||
// ROS_WARN("dAB: %f", dAB);
|
|
||||||
// ROS_WARN("delta_angle: %f", delta_angle);
|
|
||||||
}
|
|
||||||
return delta_angle;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Hàm chia đoạn thẳng AB thành các đoạn có độ dài d
|
|
||||||
std::vector<robot_geometry_msgs::PoseStamped> divideSegment(robot_geometry_msgs::PoseStamped& A, robot_geometry_msgs::PoseStamped& B, double d) {
|
|
||||||
std::vector<robot_geometry_msgs::PoseStamped> Poses;
|
|
||||||
double xAB = B.pose.position.x - A.pose.position.x;
|
|
||||||
double yAB = B.pose.position.y - A.pose.position.y;
|
|
||||||
double length = sqrt(xAB*xAB + yAB*yAB);
|
|
||||||
if(length > d)
|
|
||||||
{
|
|
||||||
Poses.push_back(A); // Thêm điểm A vào vector trước khi chia
|
|
||||||
|
|
||||||
int segments = length / d;
|
|
||||||
|
|
||||||
// Tính toán tọa độ của các điểm trên đoạn AB
|
|
||||||
double ratio = d / length;
|
|
||||||
for (int i = 1; i <= segments; ++i) {
|
|
||||||
robot_geometry_msgs::PoseStamped p;
|
|
||||||
double p_x = A.pose.position.x + (B.pose.position.x - A.pose.position.x) * ratio * i;
|
|
||||||
double p_y = A.pose.position.y + (B.pose.position.y - A.pose.position.y) * ratio * i;
|
|
||||||
p.pose.position.x = p_x;
|
|
||||||
p.pose.position.y = p_y;
|
|
||||||
Poses.push_back(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!Poses.empty()&&(Poses.back().pose.position.x!=B.pose.position.x || Poses.back().pose.position.y!=B.pose.position.y))
|
|
||||||
{
|
|
||||||
Poses.push_back(B); // Thêm điểm B vào vector sau khi chia
|
|
||||||
}
|
|
||||||
|
|
||||||
// Tính góc cho từng pose trên đoạn AB
|
|
||||||
if(//computeDeltaAngleStartOfPlan(getYaw(A.pose.orientation.x, A.pose.orientation.y, A.pose.orientation.z, A.pose.orientation.w),
|
|
||||||
//Poses.front().pose, Poses[1].pose) <= 0.872664626 &&
|
|
||||||
computeDeltaAngleEndOfPlan(getYaw(B.pose.orientation.x, B.pose.orientation.y, B.pose.orientation.z, B.pose.orientation.w),
|
|
||||||
Poses.back().pose, Poses[Poses.size() - 2].pose) <= 1.3962634016) // <= 80 degree
|
|
||||||
{
|
|
||||||
double theta_tmp = 0;
|
|
||||||
for(int i = 0; i<((int)Poses.size()-1); i++)
|
|
||||||
{
|
|
||||||
if(Poses[i].pose.position.x!=Poses[i+1].pose.position.x)
|
|
||||||
{
|
|
||||||
double theta = calculateAngle(Poses[i].pose.position.x, Poses[i].pose.position.y,
|
|
||||||
Poses[i+1].pose.position.x, Poses[i+1].pose.position.y);
|
|
||||||
Poses[i].pose.orientation = tf::createQuaternionMsgFromYaw(theta);
|
|
||||||
theta_tmp = theta;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Poses[i].pose.orientation = tf::createQuaternionMsgFromYaw(theta_tmp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Poses.back().pose.orientation = B.pose.orientation;
|
|
||||||
}
|
|
||||||
else if(//computeDeltaAngleStartOfPlan(getYaw(A.pose.orientation.x, A.pose.orientation.y, A.pose.orientation.z, A.pose.orientation.w),
|
|
||||||
//Poses.front().pose, Poses[1].pose) >= 2.2689280276 &&
|
|
||||||
computeDeltaAngleEndOfPlan(getYaw(B.pose.orientation.x, B.pose.orientation.y, B.pose.orientation.z, B.pose.orientation.w),
|
|
||||||
Poses.back().pose, Poses[Poses.size() - 2].pose) >= 1.7453292526) // >= 100 degree
|
|
||||||
{
|
|
||||||
double theta_tmp = 0;
|
|
||||||
for(int i = (int)Poses.size() -1; i>0; i--)
|
|
||||||
{
|
|
||||||
if(Poses[i].pose.position.x!=Poses[i-1].pose.position.x)
|
|
||||||
{
|
|
||||||
double theta = calculateAngle(Poses[i].pose.position.x, Poses[i].pose.position.y,
|
|
||||||
Poses[i-1].pose.position.x, Poses[i-1].pose.position.y);
|
|
||||||
Poses[i].pose.orientation = tf::createQuaternionMsgFromYaw(theta);
|
|
||||||
theta_tmp = theta;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Poses[i].pose.orientation = tf::createQuaternionMsgFromYaw(theta_tmp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Poses.front().pose.orientation = A.pose.orientation;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Poses.push_back(A);
|
|
||||||
Poses.push_back(B);
|
|
||||||
}
|
|
||||||
return Poses;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Hàm gọi make plan : tạo tuyến đường đi quay lại điểm retry có trong plan hiện tại và đi tới điểm goal mới theo cung tròn.
|
|
||||||
// khi tạo thành công plan thì hàm trả về True, không thành công thì trả về False và có hiện cảnh báo nguyên nhân.
|
|
||||||
// current_plan: vector chứa plan hiện tại
|
|
||||||
// pose_A: điểm quay lại để retry
|
|
||||||
// pose_B: điểm goal mới, có hướng thẳng với palet hiện tại
|
|
||||||
// pose_C: tâm của cung tròn AB
|
|
||||||
// result_plan: vector chứa plan kết quả
|
|
||||||
|
|
||||||
bool makePlanForRetry(std::vector<robot_geometry_msgs::PoseStamped>& current_plan,
|
|
||||||
int indexOfPoseA, robot_geometry_msgs::PoseStamped& pose_B, robot_geometry_msgs::PoseStamped& pose_B_behind,
|
|
||||||
robot_geometry_msgs::PoseStamped& pose_C, std::vector<robot_geometry_msgs::PoseStamped>& result_plan)
|
|
||||||
{
|
|
||||||
bool result = false;
|
|
||||||
std::vector<robot_geometry_msgs::PoseStamped> PlanRetry_1;
|
|
||||||
std::vector<robot_geometry_msgs::PoseStamped> PlanRetry_2;
|
|
||||||
std::vector<robot_geometry_msgs::PoseStamped> PlanRetry_3;
|
|
||||||
|
|
||||||
if(current_plan.empty()||current_plan.size()<2)
|
|
||||||
{
|
|
||||||
ROS_WARN("current_plan is empty");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
robot_geometry_msgs::PoseStamped pose_A;
|
|
||||||
pose_A = current_plan[indexOfPoseA];
|
|
||||||
|
|
||||||
// Tính ra PlanRetry_1 điểm retry tại Pose_A
|
|
||||||
|
|
||||||
PlanRetry_1.assign(current_plan.begin()+indexOfPoseA, current_plan.end());
|
|
||||||
|
|
||||||
if(!PlanRetry_1.empty()){
|
|
||||||
std::reverse(PlanRetry_1.begin(), PlanRetry_1.end());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Tính ra PlanRetry_2 với biên dạng cung tròn đi qua pose_A và pose_B, có tâm tại pose_C
|
|
||||||
|
|
||||||
double xAB = pose_B.pose.position.x - pose_A.pose.position.x;
|
|
||||||
double yAB = pose_B.pose.position.y - pose_A.pose.position.y;
|
|
||||||
double d_AB = sqrt(xAB*xAB + yAB*yAB);
|
|
||||||
if(d_AB<=0.1)
|
|
||||||
{
|
|
||||||
ROS_WARN("Curve AB is too short, cannot compute plan");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// nếu hướng của vector AB và hướng của pose_B tạo với nhau một góc ~0 độ hoặc ~180 độ -> cung tròn AB sẽ gần như là một đọan thẳng
|
|
||||||
if((computeDeltaAngleEndOfPlan(getYaw(pose_B.pose.orientation.x, pose_B.pose.orientation.y, pose_B.pose.orientation.z, pose_B.pose.orientation.w),
|
|
||||||
pose_B.pose, pose_A.pose) >= 3.13 &&
|
|
||||||
computeDeltaAngleEndOfPlan(getYaw(pose_B.pose.orientation.x, pose_B.pose.orientation.y, pose_B.pose.orientation.z, pose_B.pose.orientation.w),
|
|
||||||
pose_B.pose, pose_A.pose) <= M_PI) ||
|
|
||||||
(computeDeltaAngleEndOfPlan(getYaw(pose_B.pose.orientation.x, pose_B.pose.orientation.y, pose_B.pose.orientation.z, pose_B.pose.orientation.w),
|
|
||||||
pose_B.pose, pose_A.pose) <= 0.1745 &&
|
|
||||||
computeDeltaAngleEndOfPlan(getYaw(pose_B.pose.orientation.x, pose_B.pose.orientation.y, pose_B.pose.orientation.z, pose_B.pose.orientation.w),
|
|
||||||
pose_B.pose, pose_A.pose) >= 0))
|
|
||||||
{
|
|
||||||
std::vector<robot_geometry_msgs::PoseStamped> planSegment_AB;
|
|
||||||
planSegment_AB = divideSegment(pose_A, pose_B, 0.1);
|
|
||||||
PlanRetry_2.assign(planSegment_AB.begin(), planSegment_AB.end());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
double xCA = pose_A.pose.position.x - pose_C.pose.position.x;
|
|
||||||
double yCA = pose_A.pose.position.y - pose_C.pose.position.y;
|
|
||||||
double xCB = pose_B.pose.position.x - pose_C.pose.position.x;
|
|
||||||
double yCB = pose_B.pose.position.y - pose_C.pose.position.y;
|
|
||||||
double rCA = sqrt(xCA*xCA + yCA*yCA);
|
|
||||||
double rCB = sqrt(xCB*xCB + yCB*yCB);
|
|
||||||
if(abs(rCA-rCB)>0.008)
|
|
||||||
{
|
|
||||||
ROS_WARN("pose_C is not Center of Curve AB");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
double cos_ACB = (xCA*xCB + yCA*yCB)/(rCA*rCB);
|
|
||||||
if(cos_ACB>1) cos_ACB = 1;
|
|
||||||
else if(cos_ACB<(-1)) cos_ACB = -1;
|
|
||||||
double angleACB = acos(cos_ACB);
|
|
||||||
double angle_interval = 0.005;
|
|
||||||
// tính góc của vector CA:
|
|
||||||
double angleCA = atan2(yCA, xCA);
|
|
||||||
|
|
||||||
// check thử xem chiều góc quét từ A -> B thì angleCA + delta_angle hay angleCA - delta_angle
|
|
||||||
bool is_increase_angle = false;
|
|
||||||
double check_angle = angleCA + 50*angle_interval*angleACB;
|
|
||||||
double xA1 = pose_C.pose.position.x + rCA*cos(check_angle);
|
|
||||||
double yA1 = pose_C.pose.position.y + rCA*sin(check_angle);
|
|
||||||
double xCA1 = xA1 - pose_C.pose.position.x;
|
|
||||||
double yCA1 = yA1 - pose_C.pose.position.y;
|
|
||||||
double cos_A1CB = (xCA1*xCB + yCA1*yCB)/(rCA*rCB);
|
|
||||||
if(cos_A1CB>1) cos_A1CB = 1;
|
|
||||||
else if(cos_A1CB<(-1)) cos_A1CB = -1;
|
|
||||||
double angleA1CB = acos(cos_A1CB);
|
|
||||||
if(angleA1CB>angleACB)
|
|
||||||
{
|
|
||||||
is_increase_angle = false;
|
|
||||||
}
|
|
||||||
else if(angleA1CB<angleACB)
|
|
||||||
{
|
|
||||||
is_increase_angle = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ROS_WARN("Curve AB is too short, cannot compute plan");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if(is_increase_angle)
|
|
||||||
{
|
|
||||||
for(double i = 0; i<=1; i+= angle_interval)
|
|
||||||
{
|
|
||||||
double angle_tmp = angleCA + angleACB*i;
|
|
||||||
double xP = pose_C.pose.position.x + rCA*cos(angle_tmp);
|
|
||||||
double yP = pose_C.pose.position.y + rCA*sin(angle_tmp);
|
|
||||||
robot_geometry_msgs::PoseStamped p;
|
|
||||||
p.pose.position.x = xP;
|
|
||||||
p.pose.position.y = yP;
|
|
||||||
p.pose.position.z = 0;
|
|
||||||
PlanRetry_2.push_back(p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
for(double i = 0; i<=1; i+= angle_interval)
|
|
||||||
{
|
|
||||||
double angle_tmp = angleCA - angleACB*i;
|
|
||||||
double xP = pose_C.pose.position.x + rCA*cos(angle_tmp);
|
|
||||||
double yP = pose_C.pose.position.y + rCA*sin(angle_tmp);
|
|
||||||
robot_geometry_msgs::PoseStamped p;
|
|
||||||
p.pose.position.x = xP;
|
|
||||||
p.pose.position.y = yP;
|
|
||||||
p.pose.position.z = 0;
|
|
||||||
PlanRetry_2.push_back(p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(!PlanRetry_2.empty()&&PlanRetry_2.size()>2)
|
|
||||||
{
|
|
||||||
for(int i = 0 ; i < PlanRetry_2.size(); i++)
|
|
||||||
{
|
|
||||||
ROS_INFO("Pose %d in PlanRetry : %f, %f", i, PlanRetry_2[i].pose.position.x, PlanRetry_2[i].pose.position.y);
|
|
||||||
}
|
|
||||||
if(/*computeDeltaAngleStartOfPlan(getYaw(pose_A.pose.orientation.x, pose_A.pose.orientation.y, pose_A.pose.orientation.z, pose_A.pose.orientation.w),
|
|
||||||
PlanRetry_2.front().pose, PlanRetry_2[1].pose) <= 1.3962634016 &&*/
|
|
||||||
computeDeltaAngleEndOfPlan(getYaw(pose_B.pose.orientation.x, pose_B.pose.orientation.y, pose_B.pose.orientation.z, pose_B.pose.orientation.w),
|
|
||||||
PlanRetry_2.back().pose, PlanRetry_2[PlanRetry_2.size() - 2].pose) <= 1.3962634016
|
|
||||||
) // <= 80 degree
|
|
||||||
{
|
|
||||||
double theta_tmp = 0;
|
|
||||||
for(int i = 0; i<((int)PlanRetry_2.size()-1); i++)
|
|
||||||
{
|
|
||||||
if(PlanRetry_2[i].pose.position.x!=PlanRetry_2[i+1].pose.position.x)
|
|
||||||
{
|
|
||||||
double theta = calculateAngle(PlanRetry_2[i].pose.position.x, PlanRetry_2[i].pose.position.y,
|
|
||||||
PlanRetry_2[i+1].pose.position.x, PlanRetry_2[i+1].pose.position.y);
|
|
||||||
PlanRetry_2[i].pose.orientation = tf::createQuaternionMsgFromYaw(theta);
|
|
||||||
theta_tmp = theta;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
PlanRetry_2[i].pose.orientation = tf::createQuaternionMsgFromYaw(theta_tmp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
PlanRetry_2.back().pose.orientation = pose_B.pose.orientation;
|
|
||||||
}
|
|
||||||
else if(/*computeDeltaAngleStartOfPlan(getYaw(pose_A.pose.orientation.x, pose_A.pose.orientation.y, pose_A.pose.orientation.z, pose_A.pose.orientation.w),
|
|
||||||
PlanRetry_2.front().pose, PlanRetry_2[1].pose) >= 1.745329252 &&*/
|
|
||||||
computeDeltaAngleEndOfPlan(getYaw(pose_B.pose.orientation.x, pose_B.pose.orientation.y, pose_B.pose.orientation.z, pose_B.pose.orientation.w),
|
|
||||||
PlanRetry_2.back().pose, PlanRetry_2[PlanRetry_2.size() - 2].pose) >= 1.745329252) // >= 100 degree
|
|
||||||
{
|
|
||||||
double theta_tmp = 0;
|
|
||||||
for(int i = (int)PlanRetry_2.size() -1; i>0; i--)
|
|
||||||
{
|
|
||||||
if(PlanRetry_2[i].pose.position.x!=PlanRetry_2[i-1].pose.position.x)
|
|
||||||
{
|
|
||||||
double theta = calculateAngle(PlanRetry_2[i].pose.position.x, PlanRetry_2[i].pose.position.y,
|
|
||||||
PlanRetry_2[i-1].pose.position.x, PlanRetry_2[i-1].pose.position.y);
|
|
||||||
PlanRetry_2[i].pose.orientation = tf::createQuaternionMsgFromYaw(theta);
|
|
||||||
theta_tmp = theta;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
PlanRetry_2[i].pose.orientation = tf::createQuaternionMsgFromYaw(theta_tmp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
PlanRetry_2.front().pose.orientation = PlanRetry_2[1].pose.orientation;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ROS_WARN("Pose_A yaw or Pose_B yaw is invalid value");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ROS_WARN("Curve AB is too short, cannot compute plan");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Tạo đoạn đường từ poseB -> poseB_behind
|
|
||||||
PlanRetry_3 = divideSegment(pose_B, pose_B_behind, 0.1);
|
|
||||||
|
|
||||||
ros::Time plan_time = ros::Time::now();
|
|
||||||
if(!PlanRetry_1.empty()&&!PlanRetry_2.empty()&&!PlanRetry_3.empty())
|
|
||||||
{
|
|
||||||
for(int i = 0; i < (int)PlanRetry_1.size(); i++)
|
|
||||||
{
|
|
||||||
PlanRetry_1[i].header.stamp = plan_time;
|
|
||||||
result_plan.push_back(PlanRetry_1[i]);
|
|
||||||
}
|
|
||||||
for(int i = 0; i < (int)PlanRetry_2.size(); i++)
|
|
||||||
{
|
|
||||||
PlanRetry_2[i].header.stamp = plan_time;
|
|
||||||
PlanRetry_2[i].header.frame_id = PlanRetry_1.front().header.frame_id;
|
|
||||||
result_plan.push_back(PlanRetry_2[i]);
|
|
||||||
}
|
|
||||||
for(int i = 0; i < (int)PlanRetry_3.size(); i++)
|
|
||||||
{
|
|
||||||
PlanRetry_3[i].header.stamp = plan_time;
|
|
||||||
PlanRetry_3[i].header.frame_id = PlanRetry_1.front().header.frame_id;
|
|
||||||
result_plan.push_back(PlanRetry_3[i]);
|
|
||||||
}
|
|
||||||
result = true;
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
if(PlanRetry_3.empty())
|
|
||||||
{
|
|
||||||
ROS_WARN("PlanRetry_3 is empty");
|
|
||||||
}
|
|
||||||
if(PlanRetry_2.empty())
|
|
||||||
{
|
|
||||||
ROS_WARN("PlanRetry_2 is empty");
|
|
||||||
}
|
|
||||||
if(PlanRetry_1.empty())
|
|
||||||
{
|
|
||||||
ROS_WARN("PlanRetry_1 is empty");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Hàm gọi make plan : tạo tuyến đường đi quay lại điểm retry có trong plan hiện tại và đi tới điểm goal mới theo cung tròn.
|
|
||||||
// khi tạo thành công plan thì hàm trả về True, không thành công thì trả về False và có hiện cảnh báo nguyên nhân.
|
|
||||||
// current_plan: vector chứa plan hiện tại
|
|
||||||
// pose_A: điểm quay lại để retry
|
|
||||||
// pose_B: điểm goal mới, có hướng thẳng với palet hiện tại
|
|
||||||
// pose_C: tâm của cung tròn AB
|
|
||||||
// result_plan: vector chứa plan kết quả
|
|
||||||
|
|
||||||
bool makePlanForRetry(robot_geometry_msgs::PoseStamped& pose_A, robot_geometry_msgs::PoseStamped& pose_B, robot_geometry_msgs::PoseStamped& pose_B_behind,
|
|
||||||
robot_geometry_msgs::PoseStamped& pose_C, std::vector<robot_geometry_msgs::PoseStamped>& result_plan)
|
|
||||||
{
|
|
||||||
bool result = false;
|
|
||||||
std::vector<robot_geometry_msgs::PoseStamped> PlanRetry_1;
|
|
||||||
std::vector<robot_geometry_msgs::PoseStamped> PlanRetry_2;
|
|
||||||
std::vector<robot_geometry_msgs::PoseStamped> PlanRetry_3;
|
|
||||||
|
|
||||||
ROS_INFO("[makePlanForRetry] pose_A: %f, %f, %f pose_B: %f, %f, %f pose_C: %f, %f",
|
|
||||||
pose_A.pose.position.x, pose_A.pose.position.y,
|
|
||||||
getYaw(pose_A.pose.orientation.x, pose_A.pose.orientation.y, pose_A.pose.orientation.z, pose_A.pose.orientation.w),
|
|
||||||
pose_B.pose.position.x, pose_B.pose.position.y,
|
|
||||||
getYaw(pose_B.pose.orientation.x, pose_B.pose.orientation.y, pose_B.pose.orientation.z, pose_B.pose.orientation.w));
|
|
||||||
|
|
||||||
// Tính ra PlanRetry_1 điểm retry tại Pose_A
|
|
||||||
|
|
||||||
PlanRetry_1 = divideSegment(pose_B, pose_A, 0.1);
|
|
||||||
|
|
||||||
// Tính ra PlanRetry_2 với biên dạng cung tròn đi qua pose_A và pose_B, có tâm tại pose_C
|
|
||||||
|
|
||||||
double xAB = pose_B.pose.position.x - pose_A.pose.position.x;
|
|
||||||
double yAB = pose_B.pose.position.y - pose_A.pose.position.y;
|
|
||||||
double d_AB = sqrt(xAB*xAB + yAB*yAB);
|
|
||||||
if(d_AB<=0.1)
|
|
||||||
{
|
|
||||||
ROS_WARN("Curve AB is too short, cannot compute plan");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// nếu hướng của vector AB và hướng của pose_B tạo với nhau một góc ~0 độ hoặc ~180 độ -> cung tròn AB sẽ gần như là một đọan thẳng
|
|
||||||
if((computeDeltaAngleEndOfPlan(getYaw(pose_B.pose.orientation.x, pose_B.pose.orientation.y, pose_B.pose.orientation.z, pose_B.pose.orientation.w),
|
|
||||||
pose_B.pose, pose_A.pose) >= 3.13 &&
|
|
||||||
computeDeltaAngleEndOfPlan(getYaw(pose_B.pose.orientation.x, pose_B.pose.orientation.y, pose_B.pose.orientation.z, pose_B.pose.orientation.w),
|
|
||||||
pose_B.pose, pose_A.pose) <= M_PI) ||
|
|
||||||
(computeDeltaAngleEndOfPlan(getYaw(pose_B.pose.orientation.x, pose_B.pose.orientation.y, pose_B.pose.orientation.z, pose_B.pose.orientation.w),
|
|
||||||
pose_B.pose, pose_A.pose) <= 0.1745 &&
|
|
||||||
computeDeltaAngleEndOfPlan(getYaw(pose_B.pose.orientation.x, pose_B.pose.orientation.y, pose_B.pose.orientation.z, pose_B.pose.orientation.w),
|
|
||||||
pose_B.pose, pose_A.pose) >= 0))
|
|
||||||
{
|
|
||||||
std::vector<robot_geometry_msgs::PoseStamped> planSegment_AB;
|
|
||||||
planSegment_AB = divideSegment(pose_A, pose_B, 0.1);
|
|
||||||
PlanRetry_2.assign(planSegment_AB.begin(), planSegment_AB.end());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
double xCA = pose_A.pose.position.x - pose_C.pose.position.x;
|
|
||||||
double yCA = pose_A.pose.position.y - pose_C.pose.position.y;
|
|
||||||
double xCB = pose_B.pose.position.x - pose_C.pose.position.x;
|
|
||||||
double yCB = pose_B.pose.position.y - pose_C.pose.position.y;
|
|
||||||
double rCA = sqrt(xCA*xCA + yCA*yCA);
|
|
||||||
double rCB = sqrt(xCB*xCB + yCB*yCB);
|
|
||||||
if(abs(rCA-rCB)>0.008)
|
|
||||||
{
|
|
||||||
ROS_WARN("pose_C is not Center of Curve AB");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
double cos_ACB = (xCA*xCB + yCA*yCB)/(rCA*rCB);
|
|
||||||
if(cos_ACB>1) cos_ACB = 1;
|
|
||||||
else if(cos_ACB<(-1)) cos_ACB = -1;
|
|
||||||
double angleACB = acos(cos_ACB);
|
|
||||||
double angle_interval = 0.005;
|
|
||||||
// tính góc của vector CA:
|
|
||||||
double angleCA = atan2(yCA, xCA);
|
|
||||||
|
|
||||||
// check thử xem chiều góc quét từ A -> B thì angleCA + delta_angle hay angleCA - delta_angle
|
|
||||||
bool is_increase_angle = false;
|
|
||||||
double check_angle = angleCA + 50*angle_interval*angleACB;
|
|
||||||
double xA1 = pose_C.pose.position.x + rCA*cos(check_angle);
|
|
||||||
double yA1 = pose_C.pose.position.y + rCA*sin(check_angle);
|
|
||||||
double xCA1 = xA1 - pose_C.pose.position.x;
|
|
||||||
double yCA1 = yA1 - pose_C.pose.position.y;
|
|
||||||
double cos_A1CB = (xCA1*xCB + yCA1*yCB)/(rCA*rCB);
|
|
||||||
if(cos_A1CB>1) cos_A1CB = 1;
|
|
||||||
else if(cos_A1CB<(-1)) cos_A1CB = -1;
|
|
||||||
double angleA1CB = acos(cos_A1CB);
|
|
||||||
if(angleA1CB>angleACB)
|
|
||||||
{
|
|
||||||
is_increase_angle = false;
|
|
||||||
}
|
|
||||||
else if(angleA1CB<angleACB)
|
|
||||||
{
|
|
||||||
is_increase_angle = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ROS_WARN("Curve AB is too short, cannot compute plan");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if(is_increase_angle)
|
|
||||||
{
|
|
||||||
for(double i = 0; i<=1; i+= angle_interval)
|
|
||||||
{
|
|
||||||
double angle_tmp = angleCA + angleACB*i;
|
|
||||||
double xP = pose_C.pose.position.x + rCA*cos(angle_tmp);
|
|
||||||
double yP = pose_C.pose.position.y + rCA*sin(angle_tmp);
|
|
||||||
robot_geometry_msgs::PoseStamped p;
|
|
||||||
p.pose.position.x = xP;
|
|
||||||
p.pose.position.y = yP;
|
|
||||||
p.pose.position.z = 0;
|
|
||||||
PlanRetry_2.push_back(p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
for(double i = 0; i<=1; i+= angle_interval)
|
|
||||||
{
|
|
||||||
double angle_tmp = angleCA - angleACB*i;
|
|
||||||
double xP = pose_C.pose.position.x + rCA*cos(angle_tmp);
|
|
||||||
double yP = pose_C.pose.position.y + rCA*sin(angle_tmp);
|
|
||||||
robot_geometry_msgs::PoseStamped p;
|
|
||||||
p.pose.position.x = xP;
|
|
||||||
p.pose.position.y = yP;
|
|
||||||
p.pose.position.z = 0;
|
|
||||||
PlanRetry_2.push_back(p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(!PlanRetry_2.empty()&&PlanRetry_2.size()>2)
|
|
||||||
{
|
|
||||||
for(int i = 0 ; i < PlanRetry_2.size(); i++)
|
|
||||||
{
|
|
||||||
ROS_INFO("Pose %d in PlanRetry : %f, %f", i, PlanRetry_2[i].pose.position.x, PlanRetry_2[i].pose.position.y);
|
|
||||||
}
|
|
||||||
if(/*computeDeltaAngleStartOfPlan(getYaw(pose_A.pose.orientation.x, pose_A.pose.orientation.y, pose_A.pose.orientation.z, pose_A.pose.orientation.w),
|
|
||||||
PlanRetry_2.front().pose, PlanRetry_2[1].pose) <= 1.3962634016 &&*/
|
|
||||||
computeDeltaAngleEndOfPlan(getYaw(pose_B.pose.orientation.x, pose_B.pose.orientation.y, pose_B.pose.orientation.z, pose_B.pose.orientation.w),
|
|
||||||
PlanRetry_2.back().pose, PlanRetry_2[PlanRetry_2.size() - 2].pose) <= 1.3962634016
|
|
||||||
) // <= 80 degree
|
|
||||||
{
|
|
||||||
double theta_tmp = 0;
|
|
||||||
for(int i = 0; i<((int)PlanRetry_2.size()-1); i++)
|
|
||||||
{
|
|
||||||
if(PlanRetry_2[i].pose.position.x!=PlanRetry_2[i+1].pose.position.x)
|
|
||||||
{
|
|
||||||
double theta = calculateAngle(PlanRetry_2[i].pose.position.x, PlanRetry_2[i].pose.position.y,
|
|
||||||
PlanRetry_2[i+1].pose.position.x, PlanRetry_2[i+1].pose.position.y);
|
|
||||||
PlanRetry_2[i].pose.orientation = tf::createQuaternionMsgFromYaw(theta);
|
|
||||||
theta_tmp = theta;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
PlanRetry_2[i].pose.orientation = tf::createQuaternionMsgFromYaw(theta_tmp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
PlanRetry_2.back().pose.orientation = pose_B.pose.orientation;
|
|
||||||
}
|
|
||||||
else if(/*computeDeltaAngleStartOfPlan(getYaw(pose_A.pose.orientation.x, pose_A.pose.orientation.y, pose_A.pose.orientation.z, pose_A.pose.orientation.w),
|
|
||||||
PlanRetry_2.front().pose, PlanRetry_2[1].pose) >= 1.745329252 &&*/
|
|
||||||
computeDeltaAngleEndOfPlan(getYaw(pose_B.pose.orientation.x, pose_B.pose.orientation.y, pose_B.pose.orientation.z, pose_B.pose.orientation.w),
|
|
||||||
PlanRetry_2.back().pose, PlanRetry_2[PlanRetry_2.size() - 2].pose) >= 1.745329252) // >= 100 degree
|
|
||||||
{
|
|
||||||
double theta_tmp = 0;
|
|
||||||
for(int i = (int)PlanRetry_2.size() -1; i>0; i--)
|
|
||||||
{
|
|
||||||
if(PlanRetry_2[i].pose.position.x!=PlanRetry_2[i-1].pose.position.x)
|
|
||||||
{
|
|
||||||
double theta = calculateAngle(PlanRetry_2[i].pose.position.x, PlanRetry_2[i].pose.position.y,
|
|
||||||
PlanRetry_2[i-1].pose.position.x, PlanRetry_2[i-1].pose.position.y);
|
|
||||||
PlanRetry_2[i].pose.orientation = tf::createQuaternionMsgFromYaw(theta);
|
|
||||||
theta_tmp = theta;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
PlanRetry_2[i].pose.orientation = tf::createQuaternionMsgFromYaw(theta_tmp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
PlanRetry_2.front().pose.orientation = PlanRetry_2[1].pose.orientation;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ROS_WARN("Pose_A yaw or Pose_B yaw is invalid value");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ROS_WARN("Curve AB is too short, cannot compute plan");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Tạo đoạn đường từ poseB -> poseB_behind
|
|
||||||
PlanRetry_3 = divideSegment(pose_B, pose_B_behind, 0.1);
|
|
||||||
|
|
||||||
ros::Time plan_time = ros::Time::now();
|
|
||||||
if(!PlanRetry_1.empty()&&!PlanRetry_2.empty()&&!PlanRetry_3.empty())
|
|
||||||
{
|
|
||||||
for(int i = 0; i < (int)PlanRetry_1.size(); i++)
|
|
||||||
{
|
|
||||||
PlanRetry_1[i].header.stamp = plan_time;
|
|
||||||
result_plan.push_back(PlanRetry_1[i]);
|
|
||||||
}
|
|
||||||
for(int i = 0; i < (int)PlanRetry_2.size(); i++)
|
|
||||||
{
|
|
||||||
PlanRetry_2[i].header.stamp = plan_time;
|
|
||||||
PlanRetry_2[i].header.frame_id = PlanRetry_1.front().header.frame_id;
|
|
||||||
result_plan.push_back(PlanRetry_2[i]);
|
|
||||||
}
|
|
||||||
for(int i = 0; i < (int)PlanRetry_3.size(); i++)
|
|
||||||
{
|
|
||||||
PlanRetry_3[i].header.stamp = plan_time;
|
|
||||||
PlanRetry_3[i].header.frame_id = PlanRetry_1.front().header.frame_id;
|
|
||||||
result_plan.push_back(PlanRetry_3[i]);
|
|
||||||
}
|
|
||||||
result = true;
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
if(PlanRetry_3.empty())
|
|
||||||
{
|
|
||||||
ROS_WARN("PlanRetry_3 is empty");
|
|
||||||
}
|
|
||||||
if(PlanRetry_2.empty())
|
|
||||||
{
|
|
||||||
ROS_WARN("PlanRetry_2 is empty");
|
|
||||||
}
|
|
||||||
if(PlanRetry_1.empty())
|
|
||||||
{
|
|
||||||
ROS_WARN("PlanRetry_1 is empty");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Hàm Tìm tâm C của cung tròn AB khi biết Pose tại điểm B: khi tìm thành công điểm C thì hàm trả về True
|
|
||||||
// pose_A: điểm start của cung tròn
|
|
||||||
// pose_B: điểm đích trên cung tròn
|
|
||||||
// pose_C: tâm của cung tròn AB (kết quả)
|
|
||||||
|
|
||||||
bool findCenterOfCurve(robot_geometry_msgs::PoseStamped& pose_A, robot_geometry_msgs::PoseStamped& pose_B, robot_geometry_msgs::PoseStamped& pose_C)
|
|
||||||
{
|
|
||||||
// nếu hướng của vector AB và hướng của pose_B tạo với nhau một góc ~0 độ hoặc ~180 độ -> điểm C sẽ gần xấp xỉ với trung điểm của đoạn thẳng AB.
|
|
||||||
if((computeDeltaAngleEndOfPlan(getYaw(pose_B.pose.orientation.x, pose_B.pose.orientation.y, pose_B.pose.orientation.z, pose_B.pose.orientation.w),
|
|
||||||
pose_B.pose, pose_A.pose) >= 3.13 &&
|
|
||||||
computeDeltaAngleEndOfPlan(getYaw(pose_B.pose.orientation.x, pose_B.pose.orientation.y, pose_B.pose.orientation.z, pose_B.pose.orientation.w),
|
|
||||||
pose_B.pose, pose_A.pose) <= M_PI) ||
|
|
||||||
(computeDeltaAngleEndOfPlan(getYaw(pose_B.pose.orientation.x, pose_B.pose.orientation.y, pose_B.pose.orientation.z, pose_B.pose.orientation.w),
|
|
||||||
pose_B.pose, pose_A.pose) <= 0.1745 &&
|
|
||||||
computeDeltaAngleEndOfPlan(getYaw(pose_B.pose.orientation.x, pose_B.pose.orientation.y, pose_B.pose.orientation.z, pose_B.pose.orientation.w),
|
|
||||||
pose_B.pose, pose_A.pose) >= 0))
|
|
||||||
{
|
|
||||||
pose_C.pose.position.x = (pose_A.pose.position.x + pose_B.pose.position.x)/2;
|
|
||||||
pose_C.pose.position.y = (pose_A.pose.position.y + pose_B.pose.position.y)/2;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
double x_R = pose_A.pose.position.x;
|
|
||||||
double y_R = pose_A.pose.position.y;
|
|
||||||
double x_G = pose_B.pose.position.x;
|
|
||||||
double y_G = pose_B.pose.position.y;
|
|
||||||
double phi_vG = getYaw(pose_B.pose.orientation.x, pose_B.pose.orientation.y, pose_B.pose.orientation.z, pose_B.pose.orientation.w);
|
|
||||||
double x_H = (x_R+x_G)/2;
|
|
||||||
double y_H = (y_R+y_G)/2;
|
|
||||||
double m_vG = tan(phi_vG);
|
|
||||||
double m_G_n_vG = -1/m_vG;
|
|
||||||
double b_G_n_vG = y_G-m_G_n_vG*x_G;
|
|
||||||
double m_RG =(y_G-y_R)/(x_G-x_R);
|
|
||||||
double b_RG = y_R-m_RG*x_R;
|
|
||||||
double m_H_n_RG = -1/m_RG;
|
|
||||||
double b_H_n_RG = y_H-m_H_n_RG*x_H;
|
|
||||||
pose_C.pose.position.x = (b_H_n_RG-b_G_n_vG)/(m_G_n_vG-m_H_n_RG);
|
|
||||||
pose_C.pose.position.y = (b_H_n_RG*m_G_n_vG-b_G_n_vG*m_H_n_RG)/(m_G_n_vG-m_H_n_RG);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
42
src/pose.cc
42
src/pose.cc
@@ -1,42 +0,0 @@
|
|||||||
#include <custom_planner/pose.h>
|
|
||||||
|
|
||||||
namespace custom_planner
|
|
||||||
{
|
|
||||||
|
|
||||||
bool Pose::SavePoseAsFile(const string& file_name)
|
|
||||||
{
|
|
||||||
bool result = false;
|
|
||||||
ofstream file(file_name);
|
|
||||||
if (file.is_open())
|
|
||||||
{
|
|
||||||
file << x_ << " " << y_ << " "<< yaw_ << "\n";
|
|
||||||
file.close();
|
|
||||||
result = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
result = false;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Pose::LoadPoseFromFile(const string& file_name)
|
|
||||||
{
|
|
||||||
bool result = false;
|
|
||||||
ifstream file(file_name);
|
|
||||||
if (file.is_open())
|
|
||||||
{
|
|
||||||
double x, y, yaw;
|
|
||||||
file >> x >> y >> yaw;
|
|
||||||
setPose(x, y, yaw);
|
|
||||||
file.close();
|
|
||||||
result = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
result = false;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user