feat(minco_ws): MID360 + Point-LIO + SCAN/MINCO 导航工作区(19 个包)

- scan/: SCAN 无图局部规划(6 包)+ step_blocker(台阶封堵)+ body_odom(雷达→车体中心)
- navigation/: MINCO + Nav2 有图方案;perception/: Livox 驱动 + Point-LIO + rog_map
- chassis/: R2 底盘串口桥
- docs/: QUICKSTART(上机流程)/ SCAN_VEHICLE(方案与限制)/ DEPLOY_ROBOT(双机部署)
- scripts/: setup_deps.sh(依赖体检/安装)+ deploy_to_robot.sh(rsync 同步/远程编译)

排除 build/ install/ log/、PCD 地图(155 MB,单独 rsync)。
This commit is contained in:
2026-10-20 10:51:18 +08:00
parent eba4570f4e
commit a2947065b3
829 changed files with 272495 additions and 1 deletions
@@ -0,0 +1,26 @@
cmake_minimum_required(VERSION 3.8)
project(path_searching)
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17)
endif()
add_compile_options(-Wall -Wextra -Wpedantic)
find_package(ament_cmake REQUIRED)
find_package(Eigen3 REQUIRED)
find_package(plan_env REQUIRED)
find_package(rclcpp REQUIRED)
add_library(path_searching src/dyn_a_star.cpp)
target_include_directories(path_searching PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
ament_target_dependencies(path_searching plan_env rclcpp)
target_link_libraries(path_searching Eigen3::Eigen)
install(TARGETS path_searching EXPORT export_path_searching
ARCHIVE DESTINATION lib LIBRARY DESTINATION lib RUNTIME DESTINATION bin)
install(DIRECTORY include/ DESTINATION include)
ament_export_targets(export_path_searching HAS_LIBRARY_TARGET)
ament_export_dependencies(Eigen3 plan_env rclcpp)
ament_package()
@@ -0,0 +1,122 @@
#ifndef _DYN_A_STAR_H_
#define _DYN_A_STAR_H_
#include <iostream>
#include <rclcpp/rclcpp.hpp>
#include <Eigen/Eigen>
#include <plan_env/grid_map.h>
#include <queue>
constexpr double inf = 1 >> 20;
struct GridNode;
typedef GridNode *GridNodePtr;
enum ASTAR_RET
{
SUCCESS,
INIT_ERR,
SEARCH_ERR
};
struct GridNode
{
enum enum_state
{
OPENSET = 1,
CLOSEDSET = 2,
UNDEFINED = 3
};
int rounds{0}; // Distinguish every call
enum enum_state state
{
UNDEFINED
};
Eigen::Vector3i index;
double gScore{inf}, fScore{inf};
GridNodePtr cameFrom{NULL};
};
class NodeComparator
{
public:
bool operator()(GridNodePtr node1, GridNodePtr node2)
{
return node1->fScore > node2->fScore;
}
};
class AStar
{
private:
GridMap::Ptr grid_map_;
inline void coord2gridIndexFast(const double x, const double y, const double z, int &id_x, int &id_y, int &id_z);
double getDiagHeu(GridNodePtr node1, GridNodePtr node2);
double getManhHeu(GridNodePtr node1, GridNodePtr node2);
double getEuclHeu(GridNodePtr node1, GridNodePtr node2);
inline double getHeu(GridNodePtr node1, GridNodePtr node2);
bool ConvertToIndexAndAdjustStartEndPoints(const Eigen::Vector3d start_pt, const Eigen::Vector3d end_pt, Eigen::Vector3i &start_idx, Eigen::Vector3i &end_idx);
inline Eigen::Vector3d Index2Coord(const Eigen::Vector3i &index) const;
inline bool Coord2Index(const Eigen::Vector3d &pt, Eigen::Vector3i &idx) const;
//bool (*checkOccupancyPtr)( const Eigen::Vector3d &pos );
inline int checkOccupancy(const Eigen::Vector3d &pos, const double yaw) { return grid_map_->getInflateOccupancy(pos, yaw); }
std::vector<GridNodePtr> retrievePath(GridNodePtr current);
double step_size_, inv_step_size_;
Eigen::Vector3d center_;
Eigen::Vector3i CENTER_IDX_, POOL_SIZE_;
const double tie_breaker_ = 1.0 + 1.0 / 10000;
std::vector<GridNodePtr> gridPath_;
GridNodePtr ***GridNodeMap_;
std::priority_queue<GridNodePtr, std::vector<GridNodePtr>, NodeComparator> openSet_;
int rounds_{0};
public:
typedef std::shared_ptr<AStar> Ptr;
AStar(){};
~AStar();
void initGridMap(GridMap::Ptr occ_map, const Eigen::Vector3i pool_size);
ASTAR_RET AstarSearch(const double step_size, Eigen::Vector3d start_pt, Eigen::Vector3d end_pt);
std::vector<Eigen::Vector3d> getPath();
};
inline double AStar::getHeu(GridNodePtr node1, GridNodePtr node2)
{
return tie_breaker_ * getDiagHeu(node1, node2);
}
inline Eigen::Vector3d AStar::Index2Coord(const Eigen::Vector3i &index) const
{
return ((index - CENTER_IDX_).cast<double>() * step_size_) + center_;
};
inline bool AStar::Coord2Index(const Eigen::Vector3d &pt, Eigen::Vector3i &idx) const
{
idx = ((pt - center_) * inv_step_size_ + Eigen::Vector3d(0.5, 0.5, 0.5)).cast<int>() + CENTER_IDX_;
if (idx(0) < 0 || idx(0) >= POOL_SIZE_(0) || idx(1) < 0 || idx(1) >= POOL_SIZE_(1) || idx(2) < 0 || idx(2) >= POOL_SIZE_(2))
{
RCLCPP_ERROR(rclcpp::get_logger("path_searching"),
"Ran out of pool, index=%d %d %d", idx(0), idx(1), idx(2));
return false;
}
return true;
};
#endif
@@ -0,0 +1,13 @@
<?xml version="1.0"?>
<package format="3">
<name>path_searching</name>
<version>0.1.0</version>
<description>Dynamic A-star path search for SCAN-Planner.</description>
<maintainer email="[email protected]">SCAN-Planner maintainers</maintainer>
<license>Apache-2.0</license>
<buildtool_depend>ament_cmake</buildtool_depend>
<depend>eigen</depend>
<depend>plan_env</depend>
<depend>rclcpp</depend>
<export><build_type>ament_cmake</build_type></export>
</package>
@@ -0,0 +1,309 @@
#include "path_searching/dyn_a_star.h"
#include <algorithm>
#include <chrono>
#include <cmath>
using namespace std;
using namespace Eigen;
AStar::~AStar()
{
for (int i = 0; i < POOL_SIZE_(0); i++)
for (int j = 0; j < POOL_SIZE_(1); j++)
for (int k = 0; k < POOL_SIZE_(2); k++)
delete GridNodeMap_[i][j][k];
}
void AStar::initGridMap(GridMap::Ptr occ_map, const Eigen::Vector3i pool_size)
{
POOL_SIZE_ = pool_size;
CENTER_IDX_ = pool_size / 2;
GridNodeMap_ = new GridNodePtr **[POOL_SIZE_(0)];
for (int i = 0; i < POOL_SIZE_(0); i++)
{
GridNodeMap_[i] = new GridNodePtr *[POOL_SIZE_(1)];
for (int j = 0; j < POOL_SIZE_(1); j++)
{
GridNodeMap_[i][j] = new GridNodePtr[POOL_SIZE_(2)];
for (int k = 0; k < POOL_SIZE_(2); k++)
{
GridNodeMap_[i][j][k] = new GridNode;
}
}
}
grid_map_ = occ_map;
}
double AStar::getDiagHeu(GridNodePtr node1, GridNodePtr node2)
{
double dx = abs(node1->index(0) - node2->index(0));
double dy = abs(node1->index(1) - node2->index(1));
double dz = abs(node1->index(2) - node2->index(2));
double h = 0.0;
int diag = min(min(dx, dy), dz);
dx -= diag;
dy -= diag;
dz -= diag;
if (dx == 0)
{
h = 1.0 * sqrt(3.0) * diag + sqrt(2.0) * min(dy, dz) + 1.0 * abs(dy - dz);
}
if (dy == 0)
{
h = 1.0 * sqrt(3.0) * diag + sqrt(2.0) * min(dx, dz) + 1.0 * abs(dx - dz);
}
if (dz == 0)
{
h = 1.0 * sqrt(3.0) * diag + sqrt(2.0) * min(dx, dy) + 1.0 * abs(dx - dy);
}
return h;
}
double AStar::getManhHeu(GridNodePtr node1, GridNodePtr node2)
{
double dx = abs(node1->index(0) - node2->index(0));
double dy = abs(node1->index(1) - node2->index(1));
double dz = abs(node1->index(2) - node2->index(2));
return dx + dy + dz;
}
double AStar::getEuclHeu(GridNodePtr node1, GridNodePtr node2)
{
return (node2->index - node1->index).norm();
}
vector<GridNodePtr> AStar::retrievePath(GridNodePtr current)
{
vector<GridNodePtr> path;
path.push_back(current);
while (current->cameFrom != NULL)
{
current = current->cameFrom;
path.push_back(current);
}
return path;
}
bool AStar::ConvertToIndexAndAdjustStartEndPoints(Vector3d start_pt, Vector3d end_pt, Vector3i &start_idx, Vector3i &end_idx)
{
if (!Coord2Index(start_pt, start_idx) || !Coord2Index(end_pt, end_idx))
return false;
Eigen::Vector3d start_to_end = end_pt - start_pt;
if (start_to_end.norm() < 1e-6)
return false;
const double path_yaw = std::atan2(start_to_end(1), start_to_end(0));
start_to_end.normalize();
int occ = checkOccupancy(Index2Coord(start_idx), path_yaw);
if (occ)
{
//ROS_WARN("Start point is insdide an obstacle.");
do
{
start_pt -= start_to_end * step_size_;
if (!Coord2Index(start_pt, start_idx))
return false;
occ = checkOccupancy(Index2Coord(start_idx), path_yaw);
if (occ == -1)
{
RCLCPP_WARN(rclcpp::get_logger("path_searching"), "[Astar] Start point outside the map region.");
return false;
}
} while (occ);
}
occ = checkOccupancy(Index2Coord(end_idx), path_yaw);
if (occ)
{
//ROS_WARN("End point is insdide an obstacle.");
do
{
end_pt += start_to_end * step_size_;
if (!Coord2Index(end_pt, end_idx))
return false;
occ = checkOccupancy(Index2Coord(end_idx), path_yaw);
if (occ == -1)
{
RCLCPP_WARN(rclcpp::get_logger("path_searching"), "[Astar] End point outside the map region.");
return false;
}
} while (occ);
}
return true;
}
ASTAR_RET AStar::AstarSearch(const double step_size, Vector3d start_pt, Vector3d end_pt)
{
const auto time_1 = std::chrono::steady_clock::now();
++rounds_;
step_size_ = step_size;
inv_step_size_ = 1 / step_size;
center_ = (start_pt + end_pt) / 2;
Vector3i start_idx, end_idx;
if (!ConvertToIndexAndAdjustStartEndPoints(start_pt, end_pt, start_idx, end_idx))
{
RCLCPP_ERROR(rclcpp::get_logger("path_searching"),
"Unable to handle the initial or end point, force return!");
return ASTAR_RET::INIT_ERR;
}
const Eigen::Vector3d search_start = Index2Coord(start_idx);
const Eigen::Vector3d search_end = Index2Coord(end_idx);
const Eigen::Vector2d search_start_xy = search_start.head<2>();
const Eigen::Vector2d search_xy_delta = search_end.head<2>() - search_start_xy;
const double search_xy_len2 = search_xy_delta.squaredNorm();
auto interpolateZIndexOnSearchPlane = [&](const int x_idx, const int y_idx) -> int {
if (search_xy_len2 < 1e-8)
return start_idx(2);
Eigen::Vector3i sample_idx(x_idx, y_idx, start_idx(2));
const Eigen::Vector2d sample_xy = Index2Coord(sample_idx).head<2>();
double ratio = (sample_xy - search_start_xy).dot(search_xy_delta) / search_xy_len2;
ratio = std::max(0.0, std::min(1.0, ratio));
const double z = search_start(2) + ratio * (search_end(2) - search_start(2));
return static_cast<int>((z - center_(2)) * inv_step_size_ + 0.5) + CENTER_IDX_(2);
};
// if ( start_pt(0) > -1 && start_pt(0) < 0 )
// cout << "start_pt=" << start_pt.transpose() << " end_pt=" << end_pt.transpose() << endl;
GridNodePtr startPtr = GridNodeMap_[start_idx(0)][start_idx(1)][start_idx(2)];
GridNodePtr endPtr = GridNodeMap_[end_idx(0)][end_idx(1)][end_idx(2)];
std::priority_queue<GridNodePtr, std::vector<GridNodePtr>, NodeComparator> empty;
openSet_.swap(empty);
GridNodePtr neighborPtr = NULL;
GridNodePtr current = NULL;
endPtr->index = end_idx;
startPtr->index = start_idx;
startPtr->rounds = rounds_;
startPtr->gScore = 0;
startPtr->fScore = getHeu(startPtr, endPtr);
startPtr->state = GridNode::OPENSET; //put start node in open set
startPtr->cameFrom = NULL;
openSet_.push(startPtr); //put start in open set
double tentative_gScore;
int num_iter = 0;
while (!openSet_.empty())
{
num_iter++;
current = openSet_.top();
openSet_.pop();
// if ( num_iter < 10000 )
// cout << "current=" << current->index.transpose() << endl;
if (current->index(0) == endPtr->index(0) && current->index(1) == endPtr->index(1) && current->index(2) == endPtr->index(2))
{
// ros::Time time_2 = ros::Time::now();
// printf("\033[34mA star iter:%d, time:%.3f\033[0m\n",num_iter, (time_2 - time_1).toSec()*1000);
// if((time_2 - time_1).toSec() > 0.1)
// ROS_WARN("Time consume in A star path finding is %f", (time_2 - time_1).toSec() );
gridPath_ = retrievePath(current);
return ASTAR_RET::SUCCESS;
}
current->state = GridNode::CLOSEDSET; //move current node from open set to closed set.
for (int dx = -1; dx <= 1; dx++)
for (int dy = -1; dy <= 1; dy++)
{
if (dx == 0 && dy == 0)
continue;
Vector3i neighborIdx;
neighborIdx(0) = (current->index)(0) + dx;
neighborIdx(1) = (current->index)(1) + dy;
neighborIdx(2) = interpolateZIndexOnSearchPlane(neighborIdx(0), neighborIdx(1));
if (neighborIdx(0) < 1 || neighborIdx(0) >= POOL_SIZE_(0) - 1 || neighborIdx(1) < 1 || neighborIdx(1) >= POOL_SIZE_(1) - 1 || neighborIdx(2) < 1 || neighborIdx(2) >= POOL_SIZE_(2) - 1)
{
continue;
}
neighborPtr = GridNodeMap_[neighborIdx(0)][neighborIdx(1)][neighborIdx(2)];
neighborPtr->index = neighborIdx;
bool flag_explored = neighborPtr->rounds == rounds_;
if (flag_explored && neighborPtr->state == GridNode::CLOSEDSET)
{
continue; //in closed set.
}
neighborPtr->rounds = rounds_;
const double neighbor_yaw = std::atan2(static_cast<double>(dy), static_cast<double>(dx));
if (checkOccupancy(Index2Coord(neighborPtr->index), neighbor_yaw))
{
continue;
}
const int dz = neighborIdx(2) - current->index(2);
double static_cost = sqrt(dx * dx + dy * dy + dz * dz);
tentative_gScore = current->gScore + static_cost;
if (!flag_explored)
{
//discover a new node
neighborPtr->state = GridNode::OPENSET;
neighborPtr->cameFrom = current;
neighborPtr->gScore = tentative_gScore;
neighborPtr->fScore = tentative_gScore + getHeu(neighborPtr, endPtr);
openSet_.push(neighborPtr); //put neighbor in open set and record it.
}
else if (tentative_gScore < neighborPtr->gScore)
{ //in open set and need update
neighborPtr->cameFrom = current;
neighborPtr->gScore = tentative_gScore;
neighborPtr->fScore = tentative_gScore + getHeu(neighborPtr, endPtr);
}
}
const auto time_2 = std::chrono::steady_clock::now();
if (std::chrono::duration<double>(time_2 - time_1).count() > 0.2)
{
RCLCPP_WARN(rclcpp::get_logger("path_searching"),
"Failed in A-star path search: 0.2 second time limit exceeded");
return ASTAR_RET::SEARCH_ERR;
}
}
const auto time_2 = std::chrono::steady_clock::now();
const double elapsed = std::chrono::duration<double>(time_2 - time_1).count();
if (elapsed > 0.1)
RCLCPP_WARN(rclcpp::get_logger("path_searching"),
"A-star path search took %.3fs, iter=%d", elapsed, num_iter);
return ASTAR_RET::SEARCH_ERR;
}
vector<Vector3d> AStar::getPath()
{
vector<Vector3d> path;
for (auto ptr : gridPath_)
path.push_back(Index2Coord(ptr->index));
reverse(path.begin(), path.end());
return path;
}