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:
@@ -0,0 +1,22 @@
|
||||
cmake_minimum_required(VERSION 3.8)
|
||||
project(step_blocker)
|
||||
|
||||
# 纯 Python 节点,但用 ament_cmake 安装脚本。
|
||||
#
|
||||
# 2026-10-19 实测:用 ament_python 装完,ros2 pkg / ros2 launch 报 "package not found",
|
||||
# 因为 install/<pkg>/share/<pkg>/hook/ 里只有 pythonpath.*,缺 ament_prefix_path.*,
|
||||
# 前缀没进 AMENT_PREFIX_PATH。改成 ament_cmake 由 ament_package() 生成环境钩子后正常,
|
||||
# 且不再依赖 colcon 的 ament_python 实现(不同 colcon 版本行为不一致)。
|
||||
#
|
||||
# 注意:install(PROGRAMS) 需要脚本带 shebang 且有可执行位。
|
||||
|
||||
find_package(ament_cmake REQUIRED)
|
||||
|
||||
install(PROGRAMS step_blocker/step_blocker_node.py
|
||||
DESTINATION lib/${PROJECT_NAME}
|
||||
RENAME step_blocker)
|
||||
|
||||
install(DIRECTORY config launch
|
||||
DESTINATION share/${PROJECT_NAME})
|
||||
|
||||
ament_package()
|
||||
@@ -0,0 +1,31 @@
|
||||
# 台阶封堵节点参数。
|
||||
#
|
||||
# regions 是**世界系**(Point-LIO 的 camera_init)下的矩形,格式:
|
||||
# "xmin,xmax,ymin,ymax" 一块
|
||||
# "xmin,xmax,ymin,ymax; xmin,... " 多块,分号分隔
|
||||
#
|
||||
# 怎么标:
|
||||
# 1) 起驱动 + LIO,在 RViz 里看 /cloud_registered;
|
||||
# 2) 用 "Publish Point" 工具点台阶区域的**两个对角**,读 /clicked_point 的 x/y;
|
||||
# 3) 把两组 x/y 填进来(顺序无所谓,节点会自动排序)。
|
||||
#
|
||||
# 区域要**盖住台阶的整个投影**,稍微外扩 10~20 cm,避免边缘漏过去。
|
||||
# 墙从 z_min 一直填到 wall_height,所以斜坡不要落进矩形里。
|
||||
#
|
||||
# 验证:ros2 topic echo /cloud_registered_for_scan --once --no-arr
|
||||
# 台阶区域应出现密集点阵;也可在 RViz 里直接看这堵墙。
|
||||
|
||||
step_blocker:
|
||||
ros__parameters:
|
||||
input_topic: /cloud_registered
|
||||
output_topic: /cloud_registered_for_scan
|
||||
|
||||
# ⚠️ 默认空 = 纯透传(不封堵)。先填上你们场地的台阶矩形。
|
||||
regions: ""
|
||||
|
||||
wall_height: 2.0 # 墙的高度 [m],要高于车体 + 规划余量
|
||||
cell_size: 0.10 # 点阵间距 [m];越小越密、越耗 CPU
|
||||
z_min: 0.0 # 墙的起始高度 [m]
|
||||
|
||||
# 输入点云超过这个数就等间隔抽稀,避免 Python 端跟不上
|
||||
max_input_points: 200000
|
||||
@@ -0,0 +1,53 @@
|
||||
"""启动台阶封堵节点。
|
||||
|
||||
ros2 launch step_blocker step_blocker.launch.py
|
||||
# 临时换区域,不改 yaml
|
||||
ros2 launch step_blocker step_blocker.launch.py regions:="1.0,2.5,-1.0,1.0"
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from ament_index_python.packages import get_package_share_directory
|
||||
from launch import LaunchDescription
|
||||
from launch.actions import DeclareLaunchArgument
|
||||
from launch.substitutions import LaunchConfiguration
|
||||
from launch_ros.actions import Node
|
||||
|
||||
|
||||
def _yaml_default(params_file, name, fallback=''):
|
||||
try:
|
||||
import yaml
|
||||
with open(params_file, 'r') as f:
|
||||
p = yaml.safe_load(f)['step_blocker']['ros__parameters']
|
||||
return str(p[name])
|
||||
except Exception:
|
||||
return fallback
|
||||
|
||||
|
||||
def generate_launch_description():
|
||||
share = get_package_share_directory('step_blocker')
|
||||
default_params = os.path.join(share, 'config', 'step_blocker.yaml')
|
||||
|
||||
declared = [
|
||||
DeclareLaunchArgument(
|
||||
'params_file', default_value=default_params,
|
||||
description='参数文件(install 里是拷贝,改了 src 那份要重建;'
|
||||
'或把这里指向 src)'),
|
||||
DeclareLaunchArgument(
|
||||
'regions',
|
||||
default_value=_yaml_default(default_params, 'regions', ''),
|
||||
description='台阶矩形,世界系 "xmin,xmax,ymin,ymax[; ...]"'),
|
||||
]
|
||||
|
||||
node = Node(
|
||||
package='step_blocker',
|
||||
executable='step_blocker',
|
||||
name='step_blocker',
|
||||
output='screen',
|
||||
parameters=[
|
||||
LaunchConfiguration('params_file'),
|
||||
{'regions': LaunchConfiguration('regions')},
|
||||
],
|
||||
)
|
||||
|
||||
return LaunchDescription(declared + [node])
|
||||
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0"?>
|
||||
<package format="3">
|
||||
<name>step_blocker</name>
|
||||
<version>0.1.0</version>
|
||||
<description>Block the stair region in the input point cloud so SCAN only plans via the ramp.</description>
|
||||
<maintainer email="[email protected]">kevin</maintainer>
|
||||
<license>Apache-2.0</license>
|
||||
|
||||
<buildtool_depend>ament_cmake</buildtool_depend>
|
||||
|
||||
<exec_depend>rclpy</exec_depend>
|
||||
<exec_depend>sensor_msgs</exec_depend>
|
||||
<exec_depend>sensor_msgs_py</exec_depend>
|
||||
<exec_depend>python3-numpy</exec_depend>
|
||||
<exec_depend>launch</exec_depend>
|
||||
<exec_depend>launch_ros</exec_depend>
|
||||
<exec_depend>ament_index_python</exec_depend>
|
||||
|
||||
<export>
|
||||
<build_type>ament_cmake</build_type>
|
||||
</export>
|
||||
</package>
|
||||
@@ -0,0 +1,146 @@
|
||||
#!/usr/bin/env python3
|
||||
"""把场地的台阶区域“堵死”:输入点云 → 输出点云。
|
||||
|
||||
用途:SCAN 的碰撞检测是单点判定(``grid_map.h:371``),它分不清“斜坡”和“台阶”,
|
||||
只要 3D 体素连通就会规划过去。轮式车爬不上台阶,所以这里在点云进入 SCAN 之前,
|
||||
把台阶所在的矩形区域填成一堵从地面到 ``wall_height`` 的实心点阵墙。
|
||||
|
||||
- 区域外的点原样透传;
|
||||
- 区域内**额外**插入规则网格点(不删除原点),保证墙是实心的、不会因点云稀疏漏洞;
|
||||
- 输出只保留 x/y/z 三个字段(SCAN 的 grid_map 只用 xyz)。
|
||||
|
||||
区域在**世界系**(Point-LIO 的 camera_init)里定义。因为起点固定、台阶固定,
|
||||
标一次即可;若以后换场地,改 yaml 里的 ``regions``。
|
||||
|
||||
regions 格式(字符串,避免 ROS 2 不支持二维数组参数)::
|
||||
|
||||
regions: "1.0,2.5,-1.0,1.0; 5.0,6.0,0.0,2.0"
|
||||
└ xmin,xmax,ymin,ymax ┘ └ 第二块 ┘
|
||||
|
||||
查看当前点云坐标来标区域::
|
||||
|
||||
ros2 topic echo /cloud_registered --once --no-arr | head -20
|
||||
# 或在 RViz 里用 Publish Point 工具点台阶的两个角,读 /clicked_point
|
||||
"""
|
||||
|
||||
import numpy as np
|
||||
import rclpy
|
||||
from rclpy.node import Node
|
||||
from rclpy.qos import qos_profile_sensor_data
|
||||
from sensor_msgs.msg import PointCloud2
|
||||
from sensor_msgs_py import point_cloud2 as pc2
|
||||
|
||||
|
||||
def _parse_regions(text):
|
||||
"""'x0,x1,y0,y1; x0,x1,y0,y1' -> [(x0,x1,y0,y1), ...]"""
|
||||
regions = []
|
||||
if not text or not text.strip():
|
||||
return regions
|
||||
for block in text.split(';'):
|
||||
block = block.strip()
|
||||
if not block:
|
||||
continue
|
||||
parts = [p.strip() for p in block.split(',')]
|
||||
if len(parts) != 4:
|
||||
raise ValueError(
|
||||
f"Bad region '{block}': need xmin,xmax,ymin,ymax (4 numbers)")
|
||||
x0, x1, y0, y1 = (float(p) for p in parts)
|
||||
if x1 < x0:
|
||||
x0, x1 = x1, x0
|
||||
if y1 < y0:
|
||||
y0, y1 = y1, y0
|
||||
regions.append((x0, x1, y0, y1))
|
||||
return regions
|
||||
|
||||
|
||||
class StepBlocker(Node):
|
||||
def __init__(self):
|
||||
super().__init__('step_blocker')
|
||||
|
||||
self.declare_parameter('input_topic', '/cloud_registered')
|
||||
self.declare_parameter('output_topic', '/cloud_registered_for_scan')
|
||||
self.declare_parameter('regions', '')
|
||||
self.declare_parameter('wall_height', 2.0)
|
||||
self.declare_parameter('cell_size', 0.10)
|
||||
self.declare_parameter('z_min', 0.0)
|
||||
self.declare_parameter('max_input_points', 200000)
|
||||
|
||||
in_topic = self.get_parameter('input_topic').value
|
||||
out_topic = self.get_parameter('output_topic').value
|
||||
self.wall_height = float(self.get_parameter('wall_height').value)
|
||||
self.cell = float(self.get_parameter('cell_size').value)
|
||||
self.z_min = float(self.get_parameter('z_min').value)
|
||||
self.max_pts = int(self.get_parameter('max_input_points').value)
|
||||
self.regions = _parse_regions(self.get_parameter('regions').value)
|
||||
|
||||
self._grids = self._build_walls()
|
||||
total = sum(g.shape[0] for g in self._grids)
|
||||
if self.regions:
|
||||
self.get_logger().info(
|
||||
f'step_blocker: {len(self.regions)} region(s), '
|
||||
f'{total} wall points, wall_height={self.wall_height} m')
|
||||
for i, (x0, x1, y0, y1) in enumerate(self.regions, 1):
|
||||
self.get_logger().info(
|
||||
f' region {i}: x[{x0}, {x1}] y[{y0}, {y1}]')
|
||||
else:
|
||||
self.get_logger().warn(
|
||||
'step_blocker: regions is empty -> pure passthrough. '
|
||||
'Set config/step_blocker.yaml before use.')
|
||||
|
||||
self.pub = self.create_publisher(PointCloud2, out_topic,
|
||||
qos_profile_sensor_data)
|
||||
self.sub = self.create_subscription(
|
||||
PointCloud2, in_topic, self._cb, qos_profile_sensor_data)
|
||||
self.get_logger().info(f'{in_topic} -> {out_topic}')
|
||||
|
||||
def _build_walls(self):
|
||||
"""预生成每块区域的规则点阵,运行时只做拼接。"""
|
||||
grids = []
|
||||
if self.cell <= 0.0:
|
||||
raise ValueError('cell_size must be > 0')
|
||||
for (x0, x1, y0, y1) in self.regions:
|
||||
xs = np.arange(x0, x1 + 1e-9, self.cell, dtype=np.float32)
|
||||
ys = np.arange(y0, y1 + 1e-9, self.cell, dtype=np.float32)
|
||||
zs = np.arange(self.z_min, self.wall_height + 1e-9,
|
||||
self.cell, dtype=np.float32)
|
||||
if xs.size == 0 or ys.size == 0 or zs.size == 0:
|
||||
continue
|
||||
gx, gy, gz = np.meshgrid(xs, ys, zs, indexing='ij')
|
||||
grids.append(np.stack(
|
||||
[gx.reshape(-1), gy.reshape(-1), gz.reshape(-1)], axis=1))
|
||||
return grids
|
||||
|
||||
def _cb(self, msg):
|
||||
raw = pc2.read_points(msg, field_names=('x', 'y', 'z'), skip_nans=True)
|
||||
pts = np.asarray(list(raw), dtype=np.float32)
|
||||
if pts.size == 0:
|
||||
pts = np.zeros((0, 3), dtype=np.float32)
|
||||
elif pts.ndim == 1:
|
||||
pts = pts.reshape(-1, 3)
|
||||
|
||||
if pts.shape[0] > self.max_pts:
|
||||
step = max(1, pts.shape[0] // self.max_pts)
|
||||
pts = pts[::step]
|
||||
|
||||
if self._grids:
|
||||
pts = np.vstack([pts] + self._grids)
|
||||
|
||||
out = pc2.create_cloud_xyz32(msg.header, pts)
|
||||
self.pub.publish(out)
|
||||
|
||||
|
||||
def main(args=None):
|
||||
rclpy.init(args=args)
|
||||
node = StepBlocker()
|
||||
try:
|
||||
rclpy.spin(node)
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
finally:
|
||||
node.destroy_node()
|
||||
if rclpy.ok():
|
||||
rclpy.shutdown()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user