doc:add comment

master
邱棚 2024-07-15 16:52:25 +08:00
parent 3b8e1e5c73
commit ff7117c075
1 changed files with 145 additions and 148 deletions

View File

@ -72,8 +72,8 @@ namespace mpc_local_planner {
/**
* @class MpcLocalPlannerROS
* @brief Implements both nav_core::BaseLocalPlanner and mbf_costmap_core::CostmapController abstract
* interfaces, so the teb_local_planner plugin can be used both in move_base and move_base_flex (MBF).
* @brief nav_core::BaseLocalPlanner mbf_costmap_core::CostmapController
* 使 teb_local_planner move_base move_base_flex (MBF) 使
* @todo Escape behavior, more efficient obstacle handling
*/
class MpcLocalPlannerROS : public nav_core::BaseLocalPlanner, public mbf_costmap_core::CostmapController
@ -92,47 +92,47 @@ class MpcLocalPlannerROS : public nav_core::BaseLocalPlanner, public mbf_costmap
public:
/**
* @brief Default constructor of the plugin
* @brief
*/
MpcLocalPlannerROS();
/**
* @brief Destructor of the plugin
* @brief
*/
~MpcLocalPlannerROS();
/**
* @brief Initializes the teb plugin
* @param name The name of the instance
* @param tf Pointer to a tf buffer
* @param costmap_ros Cost map representing occupied and free space
* @brief teb
* @param name
* @param tf tf
* @param costmap_ros
*/
void initialize(std::string name, tf2_ros::Buffer* tf, costmap_2d::Costmap2DROS* costmap_ros);
/**
* @brief Set the plan that the teb local planner is following
* @param orig_global_plan The plan to pass to the local planner
* @return True if the plan was updated successfully, false otherwise
* @brief teb
* @param orig_global_plan
* @return true false
*/
bool setPlan(const std::vector<geometry_msgs::PoseStamped>& orig_global_plan);
/**
* @brief Given the current position, orientation, and velocity of the robot, compute velocity commands to send to the base
* @param cmd_vel Will be filled with the velocity command to be passed to the robot base
* @return True if a valid trajectory was found, false otherwise
* @brief
* @param cmd_vel
* @return true false
*/
bool computeVelocityCommands(geometry_msgs::Twist& cmd_vel);
/**
* @brief Given the current position, orientation, and velocity of the robot, compute velocity commands to send to the base.
* @brief
* @remark Extended version for MBF API
* @param pose the current pose of the robot.
* @param velocity the current velocity of the robot.
* @param cmd_vel Will be filled with the velocity command to be passed to the robot base.
* @param message Optional more detailed outcome as a string
* @return Result code as described on ExePath action result:
* @param pose .
* @param velocity .
* @param cmd_vel .
* @param message
* @return ExePath :
* SUCCESS = 0
* 1..9 are reserved as plugin specific non-error results
* FAILURE = 100 Unspecified failure, only used for old, non-mfb_core based plugins
* 1..9
* FAILURE = 100 mfb_core
* CANCELED = 101
* NO_VALID_CMD = 102
* PAT_EXCEEDED = 103
@ -147,17 +147,17 @@ class MpcLocalPlannerROS : public nav_core::BaseLocalPlanner, public mbf_costmap
* NOT_INITIALIZED = 112
* INVALID_PLUGIN = 113
* INTERNAL_ERROR = 114
* 121..149 are reserved as plugin specific errors
* 121..149
*/
uint32_t computeVelocityCommands(const geometry_msgs::PoseStamped& pose, const geometry_msgs::TwistStamped& velocity,
geometry_msgs::TwistStamped& cmd_vel, std::string& message);
/**
* @brief Check if the goal pose has been achieved
* @brief
*
* The actual check is performed in computeVelocityCommands().
* Only the status flag is checked here.
* @return True if achieved, false otherwise
* computeVelocityCommands()
*
* @return true false
*/
bool isGoalReached();
@ -167,41 +167,41 @@ class MpcLocalPlannerROS : public nav_core::BaseLocalPlanner, public mbf_costmap
bool isGoalReached(double xy_tolerance, double yaw_tolerance) { return isGoalReached(); };
/**
* @brief Requests the planner to cancel, e.g. if it takes too much time
* @brief
* @remark New on MBF API
* @return True if a cancel has been successfully requested, false if not implemented.
* @return true false
*/
bool cancel() { return false; };
/** @name Public utility functions/methods */
/** @name 公共实用函数/方法 */
//@{
/**
* @brief Transform a tf::Pose type into a Eigen::Vector2d containing the translational and angular velocities.
* @brief tf::Pose Eigen::Vector2d
*
* Translational velocities (x- and y-coordinates) are combined into a single translational velocity (first component).
* @param tf_vel tf::Pose message containing a 1D or 2D translational velocity (x,y) and an angular velocity (yaw-angle)
* @return Translational and angular velocity combined into an Eigen::Vector2d
* x y
* @param tf_vel 1D 2D x, y tf::Pose
* @return Eigen::Vector2d
*/
static Eigen::Vector2d tfPoseToEigenVector2dTransRot(const tf::Pose& tf_vel);
/**
* @brief Get the current robot footprint/contour model
* @brief /
* @param nh const reference to the local ros::NodeHandle
* @param costmap_ros pointer to an intialized instance of costmap_2d::Costmap2dROS
* @return Robot footprint model used for optimization
* @return
*/
static RobotFootprintModelPtr getRobotFootprintFromParamServer(const ros::NodeHandle& nh, costmap_2d::Costmap2DROS* costmap_ros = nullptr);
/**
* @brief Get the current robot footprint/contour model
* @brief
* @param costmap_ros reference to an intialized instance of costmap_2d::Costmap2dROS
* @return Robot footprint model used for optimization
* @return /
*/
static RobotFootprintModelPtr getRobotFootprintFromCostmap2d(costmap_2d::Costmap2DROS& costmap_ros);
/**
* @brief Set the footprint from the given XmlRpcValue.
* @brief XmlRpcValue
* @remarks This method is copied from costmap_2d/footprint.h, since it is not declared public in all ros distros
* @remarks It is modified in order to return a container of Eigen::Vector2d instead of geometry_msgs::Point
* @param footprint_xmlrpc should be an array of arrays, where the top-level array should have 3 or more elements, and the
@ -213,7 +213,7 @@ class MpcLocalPlannerROS : public nav_core::BaseLocalPlanner, public mbf_costmap
static Point2dContainer makeFootprintFromXMLRPC(XmlRpc::XmlRpcValue& footprint_xmlrpc, const std::string& full_param_name);
/**
* @brief Get a number from the given XmlRpcValue.
* @brief XmlRpcValue
* @remarks This method is copied from costmap_2d/footprint.h, since it is not declared public in all ros distros
* @remarks It is modified in order to return a container of Eigen::Vector2d instead of geometry_msgs::Point
* @param value double value type
@ -224,7 +224,7 @@ class MpcLocalPlannerROS : public nav_core::BaseLocalPlanner, public mbf_costmap
static double getNumberFromXMLRPC(XmlRpc::XmlRpcValue& value, const std::string& full_param_name);
/**
* @brief Return the internal config mutex
* @brief
*/
boost::mutex& configMutex() { return config_mutex_; }
@ -232,112 +232,110 @@ class MpcLocalPlannerROS : public nav_core::BaseLocalPlanner, public mbf_costmap
protected:
/**
* @brief Update internal obstacle vector based on occupied costmap cells
* @remarks All occupied cells will be added as point obstacles.
* @remarks All previous obstacles are cleared.
* @brief
* @remarks
* @remarks
* @sa updateObstacleContainerWithCostmapConverter
* @todo Include temporal coherence among obstacle msgs (id vector)
* @todo Include properties for dynamic obstacles (e.g. using constant velocity model)
* @todo id
* @todo 使
*/
void updateObstacleContainerWithCostmap();
/**
* @brief Update internal obstacle vector based on polygons provided by a costmap_converter plugin
* @remarks Requires a loaded costmap_converter plugin.
* @remarks All previous obstacles are cleared.
* @brief
* @remarks
* @remarks
* @sa updateObstacleContainerWithCostmap
*/
void updateObstacleContainerWithCostmapConverter();
/**
* @brief Update internal obstacle vector based on custom messages received via subscriber
* @remarks All previous obstacles are NOT cleared. Call this method after other update methods.
* @brief
* @remarks
* @sa updateObstacleContainerWithCostmap, updateObstacleContainerWithCostmapConverter
*/
void updateObstacleContainerWithCustomObstacles();
/**
* @brief Update internal via-point container based on the current reference plan
* @remarks All previous via-points will be cleared.
* @param transformed_plan (local) portion of the global plan (which is already transformed to the planning frame)
* @param min_separation minimum separation between two consecutive via-points
* @brief
* @remarks
* @param transformed_plan
* @param min_separation
*/
void updateViaPointsContainer(const std::vector<geometry_msgs::PoseStamped>& transformed_plan, double min_separation);
/**
* @brief Callback for the dynamic_reconfigure controller node.
* @brief
*
* This callback allows to modify parameters dynamically at runtime without restarting the node
* @param config Reference to the dynamic reconfigure config
* @param level Dynamic reconfigure level
*
* @param config
* @param level
*/
void reconfigureControllerCB(ControllerReconfigureConfig& config, uint32_t level);
/**
* @brief Callback for the dynamic_reconfigure collision node.
* @brief
*
* This callback allows to modify parameters dynamically at runtime without restarting the node
* @param config Reference to the dynamic reconfigure config
* @param level Dynamic reconfigure level
*
* @param config
* @param level
*/
void reconfigureCollisionCB(CollisionReconfigureConfig& config, uint32_t level);
/**
* @brief Callback for the dynamic_reconfigure footprint collision node.
* @brief
*
* This callback allows to modify parameters dynamically at runtime without restarting the node
* @param config Reference to the dynamic reconfigure config
* @param level Dynamic reconfigure level
*
* @param config
* @param level
*/
void reconfigureFootprintCB(FootprintReconfigureConfig& config, uint32_t level);
/**
* @brief Callback for custom obstacles that are not obtained from the costmap
* @param obst_msg pointer to the message containing a list of polygon shaped obstacles
* @brief
* @param obst_msg
*/
void customObstacleCB(const costmap_converter::ObstacleArrayMsg::ConstPtr& obst_msg);
/**
* @brief Callback for custom via-points
* @param via_points_msg pointer to the message containing a list of via-points
* @brief
* @param via_points_msg
*/
void customViaPointsCB(const nav_msgs::Path::ConstPtr& via_points_msg);
/**
* @brief Prune global plan such that already passed poses are cut off
* @brief 使姿
*
* The pose of the robot is transformed into the frame of the global plan by taking the most recent tf transform.
* If no valid transformation can be found, the method returns \c false.
* The global plan is pruned until the distance to the robot is at least \c dist_behind_robot.
* If no pose within the specified treshold \c dist_behind_robot can be found,
* nothing will be pruned and the method returns \c false.
* @remarks Do not choose \c dist_behind_robot too small (not smaller the cellsize of the map), otherwise nothing will be pruned.
* @param tf A reference to a tf buffer
* @param global_pose The global pose of the robot
* @param[in,out] global_plan The plan to be transformed
* @param dist_behind_robot Distance behind the robot that should be kept [meters]
* @return \c true if the plan is pruned, \c false in case of a transform exception or if no pose cannot be found inside the threshold
* tf 姿
* \c false.
* \c dist_behind_robot.
* \c dist_behind_robot 姿
* \c false.
* @remarks \c dist_behind_robot
* @param tf tf
* @param global_pose 姿
* @param[in,out] global_plan
* @param dist_behind_robot
* @return \c true姿 \c false
*/
bool pruneGlobalPlan(const tf2_ros::Buffer& tf, const geometry_msgs::PoseStamped& global_pose,
std::vector<geometry_msgs::PoseStamped>& global_plan, double dist_behind_robot = 1);
/**
* @brief Transforms the global plan of the robot from the planner frame to the local frame (modified).
* @brief .
*
* The method replaces transformGlobalPlan as defined in base_local_planner/goal_functions.h
* such that the index of the current goal pose is returned as well as
* the transformation between the global plan and the planning frame.
* @param tf A reference to a tf buffer
* @param global_plan The plan to be transformed
* @param global_pose The global pose of the robot
* @param costmap A reference to the costmap being used so the window size for transforming can be computed
* @param global_frame The frame to transform the plan to
* @param max_plan_length Specify maximum length (cumulative Euclidean distances) of the transformed plan [if <=0: disabled; the length is also
* bounded by the local costmap size!]
* @param[out] transformed_plan Populated with the transformed plan
* @param[out] current_goal_idx Index of the current (local) goal pose in the global plan
* @param[out] tf_plan_to_global Transformation between the global plan and the global planning frame
* @return \c true if the global plan is transformed, \c false otherwise
* base_local_planner/goal_functions.h transformGlobalPlan
* 姿
* @param tf tf
* @param global_plan
* @param global_pose 姿
* @param costmap
* @param global_frame
* @param max_plan_length [ <=0]
* @param[out] transformed_plan
* @param[out] current_goal_idx 姿
* @param[out] tf_plan_to_global
* @return \c true \c false
*/
bool transformGlobalPlan(const tf2_ros::Buffer& tf, const std::vector<geometry_msgs::PoseStamped>& global_plan,
const geometry_msgs::PoseStamped& global_pose, const costmap_2d::Costmap2D& costmap, const std::string& global_frame,
@ -345,94 +343,93 @@ class MpcLocalPlannerROS : public nav_core::BaseLocalPlanner, public mbf_costmap
geometry_msgs::TransformStamped* tf_plan_to_global = NULL) const;
/**
* @brief Estimate the orientation of a pose from the global_plan that is treated as a local goal for the local planner.
* @brief 姿
*
* If the current (local) goal point is not the final one (global)
* substitute the goal orientation by the angle of the direction vector between
* the local goal and the subsequent pose of the global plan.
* This is often helpful, if the global planner does not consider orientations. \n
* A moving average filter is utilized to smooth the orientation.
* @param global_plan The global plan
* @param local_goal Current local goal
* @param current_goal_idx Index of the current (local) goal pose in the global plan
* @param[out] tf_plan_to_global Transformation between the global plan and the global planning frame
* @param moving_average_length number of future poses of the global plan to be taken into account
* @return orientation (yaw-angle) estimate
*
* 姿
* \n
* 使
* @param global_plan
* @param local_goal
* @param current_goal_idx 姿
* @param[out] tf_plan_to_global
* @param moving_average_length 姿
* @return
*/
double estimateLocalGoalOrientation(const std::vector<geometry_msgs::PoseStamped>& global_plan, const geometry_msgs::PoseStamped& local_goal,
int current_goal_idx, const geometry_msgs::TransformStamped& tf_plan_to_global,
int moving_average_length = 3) const;
/**
* @brief Validate current parameter values of the footprint for optimization, obstacle distance and the costmap footprint
* @brief V
*
* This method prints warnings if validation fails.
* @remarks Currently, we only validate the inscribed radius of the footprints
* @param opt_inscribed_radius Inscribed radius of the RobotFootprintModel for optimization
* @param costmap_inscribed_radius Inscribed radius of the footprint model used for the costmap
* @param min_obst_dist desired distance to obstacles
*
* @remarks
* @param opt_inscribed_radius RobotFootprintModel
* @param costmap_inscribed_radius RobotFootprintModel
* @param min_obst_dist
*/
void validateFootprints(double opt_inscribed_radius, double costmap_inscribed_radius, double min_obst_dist);
private:
// Definition of member variables
// external objects (store weak pointers)
costmap_2d::Costmap2DROS* _costmap_ros; //!< Pointer to the costmap ros wrapper, received from the navigation stack
costmap_2d::Costmap2D* _costmap; //!< Pointer to the 2d costmap (obtained from the costmap ros wrapper)
tf2_ros::Buffer* _tf; //!< pointer to tf buffer
// 外部对象(存储弱指针)
costmap_2d::Costmap2DROS* _costmap_ros; //!< 指向从导航栈接收的代价地图 ros 包装器的指针
costmap_2d::Costmap2D* _costmap; //!< 指向 2D 代价地图的指针(从代价地图 ros 包装器获取)
tf2_ros::Buffer* _tf; //!< tf 缓冲区的指针
// internal objects
// 内部对象
Controller _controller;
ObstContainer _obstacles; //!< Obstacle vector that should be considered during local trajectory optimization
ObstContainer _obstacles; //!< 局部轨迹优化期间应考虑的障碍物向量
Publisher _publisher;
std::shared_ptr<base_local_planner::CostmapModel> _costmap_model;
corbo::TimeSeries::Ptr _x_seq = std::make_shared<corbo::TimeSeries>();
corbo::TimeSeries::Ptr _u_seq = std::make_shared<corbo::TimeSeries>();
std::vector<geometry_msgs::PoseStamped> _global_plan; //!< Store the current global plan
std::vector<geometry_msgs::PoseStamped> _global_plan; //!< 存储当前的全局计划
base_local_planner::OdometryHelperRos _odom_helper; //!< Provides an interface to receive the current velocity from the robot
base_local_planner::OdometryHelperRos _odom_helper; //!< 提供从机器人接收当前速度的接口
pluginlib::ClassLoader<costmap_converter::BaseCostmapToPolygons> _costmap_converter_loader; //!< Load costmap converter plugins at runtime
boost::shared_ptr<costmap_converter::BaseCostmapToPolygons> _costmap_converter; //!< Store the current costmap_converter
pluginlib::ClassLoader<costmap_converter::BaseCostmapToPolygons> _costmap_converter_loader; //!< 在运行时加载代价地图转换器插件
boost::shared_ptr<costmap_converter::BaseCostmapToPolygons> _costmap_converter; //!< 存储当前的代价地图转换器
boost::shared_ptr<dynamic_reconfigure::Server<ControllerReconfigureConfig>>
dynamic_controller_recfg_; //!< Dynamic reconfigure server to allow config modifications at runtime
dynamic_controller_recfg_; //!< 动态重配置服务器,允许在运行时修改配置
boost::shared_ptr<dynamic_reconfigure::Server<CollisionReconfigureConfig>>
dynamic_collision_recfg_; //!< Dynamic reconfigure server to allow config modifications at runtime
dynamic_collision_recfg_; //!< 动态重配置服务器,允许在运行时修改配置
boost::shared_ptr<dynamic_reconfigure::Server<FootprintReconfigureConfig>>
dynamic_footprint_recfg_; //!< Dynamic reconfigure server to allow config modifications at runtime
ros::Subscriber _custom_obst_sub; //!< Subscriber for custom obstacles received via a ObstacleMsg.
std::mutex _custom_obst_mutex; //!< Mutex that locks the obstacle array (multi-threaded)
costmap_converter::ObstacleArrayMsg _custom_obstacle_msg; //!< Copy of the most recent obstacle message
dynamic_footprint_recfg_; //!< 动态重配置服务器,允许在运行时修改配置
ros::Subscriber _custom_obst_sub; //!< 订阅通过 ObstacleMsg 接收的自定义障碍物。
std::mutex _custom_obst_mutex; //!< 锁定障碍物数组的互斥锁(多线程)
costmap_converter::ObstacleArrayMsg _custom_obstacle_msg; //!< 最近一次障碍物消息的副本
ViaPointContainer _via_points;
ros::Subscriber _via_points_sub; //!< Subscriber for custom via-points received via a Path msg.
bool _custom_via_points_active = false; //!< Keep track whether valid via-points have been received from via_points_sub_
std::mutex _via_point_mutex; //!< Mutex that locks the via_points container (multi-threaded)
ros::Subscriber _via_points_sub; //!< 订阅通过 Path 消息接收的自定义路径点。
bool _custom_via_points_active = false; //!< 跟踪是否从 via_points_sub_ 收到有效的路径点
std::mutex _via_point_mutex; //!< 锁定路径点容器的互斥锁(多线程)
PoseSE2 _robot_pose; //!< Store current robot pose
PoseSE2 _robot_goal; //!< Store current robot goal
geometry_msgs::Twist _robot_vel; //!< Store current robot translational and angular velocity (vx, vy, omega)
bool _goal_reached = false; //!< store whether the goal is reached or not
ros::Time _time_last_infeasible_plan; //!< Store at which time stamp the last infeasible plan was detected
int _no_infeasible_plans = 0; //!< Store how many times in a row the planner failed to find a feasible plan.
geometry_msgs::Twist _last_cmd; //!< Store the last control command generated in computeVelocityCommands()
PoseSE2 _robot_pose; //!< 存储当前的机器人位姿
PoseSE2 _robot_goal; //!< 存储当前的机器人目标
geometry_msgs::Twist _robot_vel; //!< 存储当前的机器人平移和角速度vx, vy, omega
bool _goal_reached = false; //!< 存储目标是否达到
ros::Time _time_last_infeasible_plan; //!< 存储上次检测到不可行计划的时间戳
int _no_infeasible_plans = 0; //!< 存储连续失败的计划次数。
geometry_msgs::Twist _last_cmd; //!< 存储 computeVelocityCommands() 中生成的最后一个控制命令
ros::Time _time_last_cmd;
RobotFootprintModelPtr _robot_model;
std::vector<geometry_msgs::Point> _footprint_spec; //!< Store the footprint of the robot
double _robot_inscribed_radius; //!< The radius of the inscribed circle of the robot (collision possible)
double _robot_circumscribed_radius; //!< The radius of the circumscribed circle of the robot
std::vector<geometry_msgs::Point> _footprint_spec; //!< 存储机器人的足迹
double _robot_inscribed_radius; //!< 机器人的内切圆半径(可能发生碰撞)
double _robot_circumscribed_radius; //!< 机器人的外接圆半径
std::string _global_frame; //!< The frame in which the controller will run
std::string _robot_base_frame; //!< Used as the base frame id of the robot
// flags
bool _initialized; //!< Keeps track about the correct initialization of this class
bool _initialized; //!< 跟踪此类的正确初始化
struct Parameters
{
@ -452,7 +449,7 @@ class MpcLocalPlannerROS : public nav_core::BaseLocalPlanner, public mbf_costmap
} _params;
boost::mutex config_mutex_; //!< Mutex for config accesses and changes
boost::mutex config_mutex_; //!< 用于配置访问和更改的互斥锁
struct CostmapConverterPlugin
{