feat: add a back-off pivot as the last-resort dock maneuver, with optional costmap checks
A differential robot that stood closer to the dock than the safe pivot point had no maneuver at all. Direct entry lacked curve room, the single cusp exceeded maximum_forward_extension, and straight-pivot-straight requires the vertex between the robot and the dock. Two charger dockings on the KIT robot failed this way (start 0.579/0.292 m and 0.427/0.155 m). - New shape backoff_pivot_straight, differential only. It is tried only after every existing shape failed. The robot drives straight along its current heading (no rotation at the start) until it is past the pivot vertex, then follows the existing straight-pivot-straight geometry. Its feasibility does not depend on the turning radius. - maneuver/pivot_backoff_max_distance [m]: longest allowed back-off; 0 disables the shape. - maneuver/pivot_check_costmap: rejects a pivot shape when a rotation sweep (circumscribed radius + pivot_safety_margin) or an approach-leg footprint covers a LETHAL cell. The terminal into the dock is not checked: it ends in contact with the dock by design. - Defaults keep every existing plan unchanged. Tests cover the two robot failures, unchanged plans for the existing shapes, ackermann, the gates and the costmap callbacks.
This commit is contained in:
@@ -5,7 +5,10 @@
|
||||
#include <utility>
|
||||
|
||||
#include <boost/dll/alias.hpp>
|
||||
#include <boost/thread/locks.hpp>
|
||||
#include <data_convert/data_convert.h>
|
||||
#include <robot/robot.h>
|
||||
#include <robot_costmap_2d/cost_values.h>
|
||||
|
||||
namespace dock_planner
|
||||
{
|
||||
@@ -94,6 +97,135 @@ FootprintLoadStatus loadDockFootprint(
|
||||
|
||||
DockPlanner::DockPlanner() = default;
|
||||
|
||||
bool DockPlanner::rotationClear(const robot_geometry_msgs::Pose& pose,
|
||||
double radius) const
|
||||
{
|
||||
// getCostmap() may return a replacement map after a resize. Keep this
|
||||
// pointer local to the callback and protect every read with that map's mutex.
|
||||
robot_costmap_2d::Costmap2D* costmap =
|
||||
costmap_robot_ == nullptr ? nullptr : costmap_robot_->getCostmap();
|
||||
if (costmap == nullptr || !std::isfinite(pose.position.x) ||
|
||||
!std::isfinite(pose.position.y) || !std::isfinite(radius) || radius < 0.0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
boost::unique_lock<robot_costmap_2d::Costmap2D::mutex_t> lock(
|
||||
*costmap->getMutex());
|
||||
const double resolution = costmap->getResolution();
|
||||
const unsigned int size_x = costmap->getSizeInCellsX();
|
||||
const unsigned int size_y = costmap->getSizeInCellsY();
|
||||
if (!std::isfinite(resolution) || resolution <= 0.0 || size_x == 0 || size_y == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
const double map_min_x = costmap->getOriginX();
|
||||
const double map_min_y = costmap->getOriginY();
|
||||
const double map_max_x = map_min_x + resolution * size_x;
|
||||
const double map_max_y = map_min_y + resolution * size_y;
|
||||
if (pose.position.x - radius < map_min_x ||
|
||||
pose.position.y - radius < map_min_y ||
|
||||
pose.position.x + radius >= map_max_x ||
|
||||
pose.position.y + radius >= map_max_y)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int min_mx = 0;
|
||||
int min_my = 0;
|
||||
int max_mx = 0;
|
||||
int max_my = 0;
|
||||
costmap->worldToMapNoBounds(pose.position.x - radius,
|
||||
pose.position.y - radius, min_mx, min_my);
|
||||
costmap->worldToMapNoBounds(pose.position.x + radius,
|
||||
pose.position.y + radius, max_mx, max_my);
|
||||
min_mx = std::max(0, min_mx);
|
||||
min_my = std::max(0, min_my);
|
||||
max_mx = std::min(static_cast<int>(size_x) - 1, max_mx);
|
||||
max_my = std::min(static_cast<int>(size_y) - 1, max_my);
|
||||
|
||||
const double half_cell = resolution * 0.5;
|
||||
const double radius_squared = radius * radius;
|
||||
for (int my = min_my; my <= max_my; ++my)
|
||||
{
|
||||
for (int mx = min_mx; mx <= max_mx; ++mx)
|
||||
{
|
||||
double cell_x = 0.0;
|
||||
double cell_y = 0.0;
|
||||
costmap->mapToWorld(static_cast<unsigned int>(mx),
|
||||
static_cast<unsigned int>(my), cell_x, cell_y);
|
||||
const double dx = std::max(
|
||||
std::fabs(cell_x - pose.position.x) - half_cell, 0.0);
|
||||
const double dy = std::max(
|
||||
std::fabs(cell_y - pose.position.y) - half_cell, 0.0);
|
||||
if (dx * dx + dy * dy <= radius_squared &&
|
||||
costmap->getCost(static_cast<unsigned int>(mx),
|
||||
static_cast<unsigned int>(my)) ==
|
||||
robot_costmap_2d::LETHAL_OBSTACLE)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DockPlanner::footprintClear(const robot_geometry_msgs::Pose& pose)
|
||||
{
|
||||
// As above, never retain getCostmap() across calls: the master can be
|
||||
// replaced while a planner is running.
|
||||
robot_costmap_2d::Costmap2D* costmap =
|
||||
costmap_robot_ == nullptr ? nullptr : costmap_robot_->getCostmap();
|
||||
if (costmap == nullptr || !std::isfinite(pose.position.x) ||
|
||||
!std::isfinite(pose.position.y))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto& footprint = costmap_robot_->getRobotFootprint();
|
||||
if (footprint.size() < 3)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
boost::unique_lock<robot_costmap_2d::Costmap2D::mutex_t> lock(
|
||||
*costmap->getMutex());
|
||||
footprint_map_polygon_.clear();
|
||||
footprint_map_cells_.clear();
|
||||
footprint_map_polygon_.reserve(footprint.size());
|
||||
const double yaw = data_convert::getYaw(pose.orientation);
|
||||
if (!std::isfinite(yaw))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
const double cos_yaw = std::cos(yaw);
|
||||
const double sin_yaw = std::sin(yaw);
|
||||
for (const auto& point : footprint)
|
||||
{
|
||||
const double world_x = pose.position.x +
|
||||
cos_yaw * point.x - sin_yaw * point.y;
|
||||
const double world_y = pose.position.y +
|
||||
sin_yaw * point.x + cos_yaw * point.y;
|
||||
robot_costmap_2d::MapLocation map_point;
|
||||
if (!costmap->worldToMap(world_x, world_y, map_point.x, map_point.y))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
footprint_map_polygon_.push_back(map_point);
|
||||
}
|
||||
|
||||
costmap->convexFillCells(footprint_map_polygon_, footprint_map_cells_);
|
||||
for (const auto& cell : footprint_map_cells_)
|
||||
{
|
||||
if (costmap->getCost(cell.x, cell.y) == robot_costmap_2d::LETHAL_OBSTACLE)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return !footprint_map_cells_.empty();
|
||||
}
|
||||
|
||||
bool DockPlanner::initialize(std::string name,
|
||||
robot_costmap_2d::Costmap2DROBOT* costmap_robot)
|
||||
{
|
||||
@@ -219,19 +351,31 @@ bool DockPlanner::initialize(std::string name,
|
||||
global_frame_ = costmap_robot->getGlobalFrameID();
|
||||
footprint_dock_ = std::move(loaded_footprint);
|
||||
dock_calc_.setConfig(loaded_config);
|
||||
dock_calc_.setCostmapCheckCallbacks(
|
||||
[this](const robot_geometry_msgs::Pose& pose, double radius)
|
||||
{
|
||||
return rotationClear(pose, radius);
|
||||
},
|
||||
[this](const robot_geometry_msgs::Pose& pose)
|
||||
{
|
||||
return footprintClear(pose);
|
||||
});
|
||||
initialized_ = true;
|
||||
|
||||
robot::log_info(
|
||||
"[dock_planner] Initialized dock maneuver (docking edge is derived per plan "
|
||||
"from the side the robot stands on): model=%s, TF %s -> %s, wheel_base=%.4f m, "
|
||||
"max_steering_angle=%.4f rad, minimum_turning_radius=%.4f m, "
|
||||
"pivot_fallback_extension=%.3f m, pivot_safety_margin=%.3f m.\n",
|
||||
"pivot_fallback_extension=%.3f m, pivot_safety_margin=%.3f m, "
|
||||
"pivot_backoff_max_distance=%.3f m, pivot_check_costmap=%s.\n",
|
||||
loaded_config.requiresAxleTf() ? "ackermann" : "differential",
|
||||
loaded_config.requiresAxleTf() ? loaded_config.front_axle_frame.c_str() : "-",
|
||||
loaded_config.requiresAxleTf() ? loaded_config.rear_axle_frame.c_str() : "-",
|
||||
loaded_config.wheel_base, loaded_config.max_steering_angle,
|
||||
minimum_turning_radius, loaded_config.pivot_fallback_extension,
|
||||
loaded_config.pivot_safety_margin);
|
||||
loaded_config.pivot_safety_margin,
|
||||
loaded_config.pivot_backoff_max_distance,
|
||||
loaded_config.pivot_check_costmap ? "true" : "false");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user