feat(lane_route): add lane_route_core and lane_route_planner (R0 + R1)
lane_route_core plans on a precomputed coarse graph (Voronoi ridges and direction-zone lanes) and, when enabled, falls back to a weighted A* search over an SE(2) lattice that enforces forward motion, the minimum turn radius, end-only spins, the footprint gap and direction zones. - R0: route_planner.cpp split into graph search, path building and the graph tier; regress7 output identical to the previous build. - R1: lattice tier (lazy packed C-space tiles, direction-aware heuristic field, analytic Dubins and point connectors, end-gap floors counting unknown cells). Off by default (lattice_enabled = false). - lane_route_eval takes an optional tier mode and LANE_ROUTE_EVAL_SET overrides for offline tuning. Local snapshot for history only; not pushed.
This commit is contained in:
64
include/lane_route_planner/lane_route_planner.h
Normal file
64
include/lane_route_planner/lane_route_planner.h
Normal file
@@ -0,0 +1,64 @@
|
||||
#ifndef LANE_ROUTE_PLANNER_LANE_ROUTE_PLANNER_H_
|
||||
#define LANE_ROUTE_PLANNER_LANE_ROUTE_PLANNER_H_
|
||||
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <robot_nav_core/base_global_planner.h>
|
||||
#include <robot_nav_core/preemptable.h>
|
||||
|
||||
#include <lane_route_planner/lane_route_session.h>
|
||||
|
||||
namespace lane_route_planner
|
||||
{
|
||||
/** @brief Boost.DLL global planner adapter.
|
||||
* initialize(), makePlan() and setExternalGrid() are called on the planner thread. preempt()
|
||||
* may be called concurrently from another thread and only sets an atomic flag. */
|
||||
class LaneRoutePlanner : public robot_nav_core::BaseGlobalPlanner, public robot_nav_core::Preemptable
|
||||
{
|
||||
public:
|
||||
/** @brief Load and validate configuration and bind the non-owning costmap on the planner thread. */
|
||||
bool initialize(std::string name, robot_costmap_2d::Costmap2DROBOT* costmap) override;
|
||||
|
||||
/** @brief Compute a verified plan in the global frame on the planner thread. */
|
||||
bool makePlan(const robot_geometry_msgs::PoseStamped& start, const robot_geometry_msgs::PoseStamped& goal,
|
||||
std::vector<robot_geometry_msgs::PoseStamped>& plan) override;
|
||||
|
||||
/** @brief Request cancellation from another thread without locking or allocating. */
|
||||
void preempt() override
|
||||
{
|
||||
preempt_.store(true, std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
/** @brief Set a non-owning external grid on the planner thread; nullptr selects the live costmap.
|
||||
* The caller keeps the grid alive through makePlan(). */
|
||||
void setExternalGrid(const robot_costmap_2d::Costmap2D* grid)
|
||||
{
|
||||
external_grid_ = grid;
|
||||
}
|
||||
|
||||
/** @brief Create the BaseGlobalPlanner instance exported by Boost.DLL. */
|
||||
static robot_nav_core::BaseGlobalPlanner::Ptr create();
|
||||
|
||||
private:
|
||||
bool initialized_ = false;
|
||||
std::atomic<bool> preempt_{false};
|
||||
robot_costmap_2d::Costmap2DROBOT* costmap_ = nullptr;
|
||||
const robot_costmap_2d::Costmap2D* external_grid_ = nullptr;
|
||||
SessionConfig config_;
|
||||
LaneRouteSession session_;
|
||||
std::vector<robot_geometry_msgs::Point> previous_footprint_;
|
||||
bool have_state_ = false;
|
||||
robot_costmap_2d::ReferenceGraphState graph_state_ = robot_costmap_2d::ReferenceGraphState::kDisabled;
|
||||
robot_costmap_2d::DirectionFieldState direction_state_ = robot_costmap_2d::DirectionFieldState::kDisabled;
|
||||
uint64_t graph_generation_ = 0;
|
||||
uint64_t direction_generation_ = 0;
|
||||
};
|
||||
|
||||
/** @brief ExternalGrid Boost.DLL capability; invoke on the planner thread. */
|
||||
void setExternalGridOn(robot_nav_core::BaseGlobalPlanner* planner, const robot_costmap_2d::Costmap2D* grid);
|
||||
} // namespace lane_route_planner
|
||||
|
||||
#endif // LANE_ROUTE_PLANNER_LANE_ROUTE_PLANNER_H_
|
||||
142
include/lane_route_planner/lane_route_session.h
Normal file
142
include/lane_route_planner/lane_route_session.h
Normal file
@@ -0,0 +1,142 @@
|
||||
#ifndef LANE_ROUTE_PLANNER_LANE_ROUTE_SESSION_H_
|
||||
#define LANE_ROUTE_PLANNER_LANE_ROUTE_SESSION_H_
|
||||
|
||||
#include <atomic>
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <robot_costmap_2d/direction_field.h>
|
||||
#include <robot_costmap_2d/reference_graph.h>
|
||||
#include <robot_geometry_msgs/PoseStamped.h>
|
||||
|
||||
#include <lane_route_core/route_planner.h>
|
||||
|
||||
namespace lane_route_planner
|
||||
{
|
||||
/** @brief Tunable parameters; footprint and direction limit are supplied per request by the costmap. */
|
||||
struct SessionConfig
|
||||
{
|
||||
lane_route_core::PlannerConfig planner; ///< Core settings, including lengths [m] and angles [deg].
|
||||
double clearance_min_margin_m = 0.035; ///< [m] Added to inscribed radius for hard clearance.
|
||||
double clearance_preferred_margin_m = 0.30; ///< [m] Added to inscribed radius for preferred clearance.
|
||||
double collision_check_margin_m = 0.056; ///< [m] Added to the bounding rectangle's circumscribed radius.
|
||||
bool debug_plan = true; ///< Enable plan diagnostics.
|
||||
bool debug_state = true; ///< Enable state-change diagnostics.
|
||||
|
||||
/** @return Empty when valid; otherwise the invalid key and its value, or the core validation error. */
|
||||
std::string validate() const;
|
||||
};
|
||||
|
||||
/** @brief Inputs for one planner-thread query. Shared snapshots and live bytes must outlive plan(). */
|
||||
struct SessionRequest
|
||||
{
|
||||
bool initialized = false; ///< Whether the adapter completed initialization.
|
||||
lane_route_core::GridRef live; ///< Non-owning grid; resolution and origin [m].
|
||||
std::string frame; ///< Global frame for the grid and poses.
|
||||
robot_costmap_2d::ReferenceGraphSnapshot graph; ///< Coarse graph and its generation.
|
||||
robot_costmap_2d::DirectionFieldSnapshot direction; ///< Direction field with limit [rad], and its generation.
|
||||
std::vector<robot_geometry_msgs::Point> footprint; ///< Padded robot-frame footprint [m].
|
||||
double inscribed_radius_m = 0.0; ///< [m] Inscribed radius of the padded footprint.
|
||||
robot_geometry_msgs::PoseStamped start; ///< Start position [m] and quaternion in frame.
|
||||
robot_geometry_msgs::PoseStamped goal; ///< Goal position [m] and quaternion in frame.
|
||||
bool start_has_yaw = true; ///< Constrain the start yaw when true.
|
||||
bool goal_has_yaw = true; ///< Constrain the goal yaw when true.
|
||||
const std::atomic<bool>* cancel = nullptr; ///< Optional caller-owned flag, set from another thread.
|
||||
};
|
||||
|
||||
/** @brief Derive a centered bounding rectangle from a padded footprint.
|
||||
* @param footprint Robot-frame polygon [m].
|
||||
* @param half_x Output maximum absolute X [m].
|
||||
* @param half_y Output maximum absolute Y [m].
|
||||
* @param centered_rectangle True when the polygon is itself a centered rectangle.
|
||||
* @return False if the inputs are invalid or the bounds have no area. */
|
||||
bool footprintRectangle(const std::vector<robot_geometry_msgs::Point>& footprint, double* half_x, double* half_y,
|
||||
bool* centered_rectangle);
|
||||
|
||||
/** @brief Check initialization, pose, frame and snapshot state without accessing grid bytes.
|
||||
* @return Empty when valid, otherwise a distinct failure reason. */
|
||||
std::string validateState(const SessionRequest& request);
|
||||
|
||||
/** @brief Check grid geometry, snapshot data and footprint after validateState() succeeds.
|
||||
* @return Empty when valid, otherwise a distinct failure reason. */
|
||||
std::string validateGrid(const SessionRequest& request);
|
||||
|
||||
/** @brief Apply validateState() and then validateGrid().
|
||||
* @return Empty when valid, otherwise the first failure reason. */
|
||||
std::string validateRequest(const SessionRequest& request);
|
||||
|
||||
/** @brief Reusable single-planner-thread adapter. Snapshots remain owned by the request during plan().
|
||||
* The caller may set the request's atomic cancellation flag from another thread. All other methods
|
||||
* and the live cost buffer are confined to the planner thread. */
|
||||
class LaneRouteSession
|
||||
{
|
||||
public:
|
||||
/** @brief Construct a session with validated-on-use configuration. */
|
||||
explicit LaneRouteSession(const SessionConfig& config = SessionConfig()) : config_(config)
|
||||
{
|
||||
}
|
||||
|
||||
/** @brief Replace the configuration and invalidate all compiled graphs, on the planner thread. */
|
||||
void setConfig(const SessionConfig& config)
|
||||
{
|
||||
config_ = config;
|
||||
clearCache();
|
||||
}
|
||||
|
||||
/** @brief Plan on the planner thread; cancellation may be requested through request.cancel. */
|
||||
lane_route_core::PlanResult plan(const SessionRequest& request);
|
||||
|
||||
/** @brief Reusable storage for copying the live or external master bytes before plan().
|
||||
* The planner thread resizes and fills it, then points SessionRequest::live.cost at its data. */
|
||||
std::vector<uint8_t>& liveCostBuffer()
|
||||
{
|
||||
return live_cost_;
|
||||
}
|
||||
|
||||
/** @brief Number of currently cached deviation graphs, for diagnostics and tests. */
|
||||
std::size_t cachedGraphCount() const
|
||||
{
|
||||
return graphs_.size();
|
||||
}
|
||||
|
||||
/** @brief Number of graphs compiled by this session, for diagnostics and tests. */
|
||||
std::size_t compileCount() const
|
||||
{
|
||||
return compile_count_;
|
||||
}
|
||||
|
||||
/** @brief Reference graph generation used by the cache, for diagnostics and tests. */
|
||||
uint64_t cachedGeneration() const
|
||||
{
|
||||
return graph_generation_;
|
||||
}
|
||||
|
||||
/** @brief Discard cached graphs and snapshot-derived data on the planner thread. */
|
||||
void clearCache();
|
||||
|
||||
private:
|
||||
SessionConfig config_;
|
||||
std::vector<uint8_t> live_cost_;
|
||||
std::vector<uint8_t> directions_;
|
||||
std::vector<uint8_t> preferred_mask_;
|
||||
std::vector<uint8_t> changed_cells_;
|
||||
bool preferred_mask_empty_ = true;
|
||||
std::vector<int32_t> changed_stack_;
|
||||
std::size_t compile_count_ = 0;
|
||||
std::vector<uint16_t> live_clearance_;
|
||||
std::map<double, std::shared_ptr<const lane_route_core::CompiledGraph>> graphs_;
|
||||
lane_route_core::CoarseGraph coarse_;
|
||||
uint64_t graph_generation_ = 0;
|
||||
uint64_t direction_generation_ = 0;
|
||||
const robot_costmap_2d::ReferenceGraph* graph_identity_ = nullptr;
|
||||
const robot_costmap_2d::DirectionField* direction_identity_ = nullptr;
|
||||
double half_x_ = -1; ///< [m] Cached footprint half length.
|
||||
double half_y_ = -1; ///< [m] Cached footprint half width.
|
||||
double inscribed_ = -1; ///< [m] Cached inscribed radius.
|
||||
};
|
||||
} // namespace lane_route_planner
|
||||
|
||||
#endif // LANE_ROUTE_PLANNER_LANE_ROUTE_SESSION_H_
|
||||
Reference in New Issue
Block a user