混合式A星代码解析_2 规划主程序Planner.cpp

3.规划程序 Planner.cpp

在main.cpp中,起主要作用的就是:

HybridAStar::Planner hy;
hy.plan();

规划算法都是在HybridAStar::Planner这个类内部进行运算的.所以主要分析以下Planner类.

3.0 实例化的对象

在planner.h中,定义了很多对象,用于最终生成规划路径.

hybridA星生成的路径:

Path path;

用于优化路径的平滑器:

Smoother smoother;

平滑后的路径:

Path smoothedPath = Path(true);

搜索的可视化:

Visualize visualization;

障碍物检测:

CollisionDetection configurationSpace;

voronoi图:

The voronoi diagram

规划时的珊格占用点:

nav_msgs::OccupancyGrid::Ptr grid;

3.1 构造函数 Planner::Planner( )

主要是订阅和发布消息

(1)订阅消息

  • 规划起点:/initialpose
  • 规划终点:/move_base_simple/goal
  • 地图:/map

(2)发布消息

  • 规划起点:/move_base_simple/start

3.2 (核心)规划函数 plan( )

规划路径主函数

3.2.1 外围框架

采用结构的是

if (validStart && validGoal) { }
else{ }

只有当规划的起点和终点都有效时,才会规划路径.

这里就涉及到如何判断规划的起点和终点是否有效的问题.

  • 起点有效的条件有两个(有一个满足就ok):
  1. 如果是在动态地图工作模式下,如果受到了地图消息,就会在回调函数 setMap()中,对start点的有效性进行判断,此时start点会设置成机器的坐标/base_link,如果机器人的坐标位于地图范围内,则start有效.否则无效.
  2. 如果是在静态地图工作模式下,则只在回调函数setStart()中进行判断.
  • 判断终点是否有效的条件就1个,那就是只在回调函数setGoal()中进行判断

3.2.2 定义栅格的尺寸和离散的数量

// ___________________________

// LISTS ALLOWCATED ROW MAJOR ORDER

int width = grid->info.width;

int height = grid->info.height;

int depth = Constants::headings;

int length = width * height * depth;

// define list pointers and initialize lists

Node3D* nodes3D = new Node3D[length]();

Node2D* nodes2D = new Node2D[width * height]();

3.2.3 取出规划的goal和start

// ________________________

// retrieving goal position

float x = goal.pose.position.x / Constants::cellSize;

float y = goal.pose.position.y / Constants::cellSize;

float t = tf::getYaw(goal.pose.orientation);

// set theta to a value (0,2PI]

t = Helper::normalizeHeadingRad(t);

const Node3D nGoal(x, y, t, 0, 0, nullptr);
// _________________________

// retrieving start position

x = start.pose.pose.position.x / Constants::cellSize;

y = start.pose.pose.position.y / Constants::cellSize;

t = tf::getYaw(start.pose.pose.orientation);

// set theta to a value (0,2PI]

t = Helper::normalizeHeadingRad(t);

Node3D nStart(x, y, t, 0, 0, nullptr);

3.2.4 (核心)开始规划并计时

(1)计时:

ros::Time t0 = ros::Time::now();

(2)初始化

// CLEAR THE VISUALIZATION

visualization.clear();

// CLEAR THE PATH

path.clear();

smoothedPath.clear();

(3)(核心)寻找路径(hybridAstar的核心算法)
返回的是符合中goal要求的节点的指针.

// FIND THE PATH

Node3D* nSolution = Algorithm::hybridAStar(nStart, nGoal, nodes3D, nodes2D, width, height, configurationSpace, dubinsLookup, visualization);

(4)跟踪路径
根据goal节点的指针,回溯整个路径.

// TRACE THE PATH

smoother.tracePath(nSolution);

(5)更新路径

// CREATE THE UPDATED PATH

path.updatePath(smoother.getPath());

(6)平滑路径

// SMOOTH THE PATH

smoother.smoothPath(voronoiDiagram);

(7)更新路径

// CREATE THE UPDATED PATH

smoothedPath.updatePath(smoother.getPath());

(8)结束计时

ros::Time t1 = ros::Time::now();

ros::Duration d(t1 - t0);

std::cout << "TIME in ms: " << d * 1000 << std::endl;

(9)发布结果

// _________________________________

// PUBLISH THE RESULTS OF THE SEARCH

path.publishPath();

path.publishPathNodes();

path.publishPathVehicles();

smoothedPath.publishPath();

smoothedPath.publishPathNodes();

smoothedPath.publishPathVehicles();

visualization.publishNode3DCosts(nodes3D, width, height, depth);

visualization.publishNode2DCosts(nodes2D, width, height);

(10)删除节点

delete [] nodes3D;

delete [] nodes2D;

3.3 setGoal()

设置goal,同时判断是否有效.

3.4 setStart()

设置start,同时判断是否有效.

3.5 setMap()

存储地图,如果是动态地图,则判断start是否有效.

3.6 initializeLookups()

没有用到.

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
/** * @brief Callback function for dynamic reconfiguration of DWA planner parameters * * @param config Reference to the configuration object that stores the updated parameters * @param level The level of reconfiguration, unused in this function */ void DWAPlannerROS::reconfigureCB(DWAPlannerConfig &config, uint32_t level) { // If the setup has been completed and restore_defaults flag is set, restore default configuration if (setup_ && config.restore_defaults) { config = default_config_; config.restore_defaults = false; } // If setup has not been completed, store default configuration and set the setup flag to true if ( ! setup_) { default_config_ = config; setup_ = true; } // Update generic local planner parameters base_local_planner::LocalPlannerLimits limits; limits.max_vel_trans = config.max_vel_trans; limits.min_vel_trans = config.min_vel_trans; limits.max_vel_x = config.max_vel_x; limits.min_vel_x = config.min_vel_x; limits.max_vel_y = config.max_vel_y; limits.min_vel_y = config.min_vel_y; limits.max_vel_theta = config.max_vel_theta; limits.min_vel_theta = config.min_vel_theta; limits.acc_lim_x = config.acc_lim_x; limits.acc_lim_y = config.acc_lim_y; limits.acc_lim_theta = config.acc_lim_theta; limits.acc_lim_trans = config.acc_lim_trans; limits.xy_goal_tolerance = config.xy_goal_tolerance; limits.yaw_goal_tolerance = config.yaw_goal_tolerance; limits.prune_plan = config.prune_plan; limits.trans_stopped_vel = config.trans_stopped_vel; limits.theta_stopped_vel = config.theta_stopped_vel; // Call reconfigureCB function of the planner_util_ object with updated limits and restore_defaults flag planner_util_.reconfigureCB(limits, config.restore_defaults); // Call reconfigure function of the dp_ object with updated configuration dp_->reconfigure(config); }

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值