全部改为用Xmake,然后精简一下文档
This commit is contained in:
1 parent
d8f1e2226d
commit
970b16f17f
34 files changed
+1903
-1133
No files matched your search
+11
-9
@@ -1,6 +1,6 @@
|
||||
# tools/
|
||||
|
||||
模型转换、调试、演示用的小工具(都是独立脚本,不参与 colcon 构建)。
|
||||
模型转换、调试、演示用的小工具(都是独立脚本,不参与构建)。
|
||||
|
||||
## 模型相关
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|---|---|
|
||||
| `build_vehicle.py` | **整车装配体 STL → 仿真网格 + 布局 json**(主力工具) |
|
||||
| `decimate.py` | 顶点聚类减面(纯 numpy,不依赖 MeshLab/Blender) |
|
||||
| `gen_sdf.sh` | URDF(xacro) → Gazebo 的 `models/sentry/model.sdf` |
|
||||
| `gen_sdf.sh` | URDF(xacro) → `models/sentry/model.sdf` + `generated/sentry.urdf` |
|
||||
| `build_meshes.py` | 旧版:只处理「底盘」导出(已被 `build_vehicle.py` 取代) |
|
||||
| `build_gimbal.py` | 旧版:只处理「云台」导出(已被取代) |
|
||||
|
||||
@@ -24,17 +24,19 @@
|
||||
| `probe_all.py` | 检查 `/clock /odom /scan /tf` 有没有数据 |
|
||||
| `probe_cmd.py` / `probe_cmd2.py` / `cmd_probe_all.py` | 统计各级 `/cmd_vel` 消息数 |
|
||||
| `probe_sub.py` | 最小订阅示例 |
|
||||
| `smoke_probe.py` | 全栈冒烟:等 Nav2 激活 → 收点云 → 发目标点验结果 |
|
||||
| `check_stack.py` | ★ **只读体检**:生命周期状态 + 5 个话题有没有数据 + TF,一条命令问清"现在这套栈健康吗" |
|
||||
|
||||
## 构建 / 编辑器
|
||||
|
||||
| 脚本 | 用途 |
|
||||
|---|---|
|
||||
| `gen_compdb.sh` | ★ 重新生成工作区根的 `compile_commands.json`(clangd / VS Code 智能感知的数据源) |
|
||||
**这里已经没有构建相关的脚本了。**
|
||||
|
||||
> **改了 CMakeLists、增删 `.cpp`、或改了 include 目录之后必须重跑 `gen_compdb.sh`**,
|
||||
> 否则 VS Code 会报 `xxx.hpp file not found` + `Too many errors emitted`。
|
||||
> 跑完还要在 VS Code 里 `Ctrl+Shift+P → clangd: Restart language server`。
|
||||
> 详见 `../.vscode/README.md`。
|
||||
`compile_commands.json` 由 xmake 在**每次构建后自动重写**
|
||||
(根 `xmake.lua` 里的 `plugin.compile_commands.autoupdate` 规则),
|
||||
以前那个 `gen_compdb.sh`(合并 colcon 分包产物)已随去 colcon 一起删除。
|
||||
|
||||
改了源码结构后只要跑一次 `xmake`,再在 VS Code 里
|
||||
`Ctrl+Shift+P → clangd: Restart language server`。详见 `../.vscode/README.md`。
|
||||
|
||||
## 典型用法
|
||||
|
||||
|
||||
@@ -0,0 +1,157 @@
|
||||
#!/usr/bin/env python3
|
||||
"""只读体检:看当前跑着的这套仿真栈处于什么状态。
|
||||
|
||||
不发布任何指令、不改任何参数,只读话题/服务/TF。
|
||||
**这脚本自己不会干扰仿真**,随便在另一个终端跑。
|
||||
|
||||
python3 tools/check_stack.py
|
||||
|
||||
退出码 0 = 一切正常;非 0 = 有东西没起来(逐条原因见输出)。
|
||||
"""
|
||||
import sys
|
||||
import time
|
||||
|
||||
import rclpy
|
||||
import rclpy.time
|
||||
from rclpy.duration import Duration
|
||||
from rclpy.node import Node
|
||||
from rclpy.parameter import Parameter
|
||||
from rclpy.qos import (QoSProfile, ReliabilityPolicy, DurabilityPolicy,
|
||||
HistoryPolicy)
|
||||
from lifecycle_msgs.msg import State
|
||||
from lifecycle_msgs.srv import GetState
|
||||
from sensor_msgs.msg import PointCloud2, LaserScan
|
||||
from nav_msgs.msg import Odometry, OccupancyGrid
|
||||
from tf2_ros import Buffer, TransformListener
|
||||
|
||||
|
||||
# 期望处于 ACTIVE 的节点(缺了哪个,导航就会缺一块能力)
|
||||
EXPECTED_ACTIVE = [
|
||||
'map_server',
|
||||
'controller_server',
|
||||
'planner_server',
|
||||
'bt_navigator',
|
||||
'behavior_server',
|
||||
'velocity_smoother',
|
||||
'collision_monitor',
|
||||
]
|
||||
|
||||
# map_server 发的 /map 是 **latched**(TRANSIENT_LOCAL)。
|
||||
# 订阅端必须也是 TRANSIENT_LOCAL,否则 QoS 不兼容,一条都收不到 —— 最容易误判的一条。
|
||||
MAP_QOS = QoSProfile(
|
||||
depth=1,
|
||||
history=HistoryPolicy.KEEP_LAST,
|
||||
reliability=ReliabilityPolicy.RELIABLE,
|
||||
durability=DurabilityPolicy.TRANSIENT_LOCAL,
|
||||
)
|
||||
# 传感器数据:仿真里都是 BEST_EFFORT
|
||||
SENSOR_QOS = QoSProfile(depth=1, reliability=ReliabilityPolicy.BEST_EFFORT)
|
||||
|
||||
|
||||
def main():
|
||||
rclpy.init()
|
||||
# 整套栈都是 use_sim_time:=true,探针也必须一致,否则时间戳比较会出错
|
||||
node = Node('check_stack',
|
||||
parameter_overrides=[Parameter('use_sim_time',
|
||||
Parameter.Type.BOOL, True)])
|
||||
problems = []
|
||||
|
||||
def active(name):
|
||||
cli = node.create_client(GetState, f'/{name}/get_state')
|
||||
if not cli.wait_for_service(timeout_sec=3.0):
|
||||
return None, '服务不存在'
|
||||
fut = cli.call_async(GetState.Request())
|
||||
rclpy.spin_until_future_complete(node, fut, timeout_sec=5.0)
|
||||
if not fut.done() or fut.result() is None:
|
||||
return None, '调用超时'
|
||||
return fut.result().current_state, None
|
||||
|
||||
# ---------- 1. 生命周期 ----------
|
||||
print('=== 1. 生命周期状态 ===')
|
||||
for name in EXPECTED_ACTIVE:
|
||||
st, err = active(name)
|
||||
if st is None:
|
||||
print(' %-20s ❌ %s' % (name, err))
|
||||
problems.append(f'{name} 不可达({err})')
|
||||
elif st.id == State.PRIMARY_STATE_ACTIVE:
|
||||
print(' %-20s ✅ ACTIVE' % name)
|
||||
else:
|
||||
print(' %-20s ⚠️ %s' % (name, st.label))
|
||||
problems.append(f'{name} 是 {st.label},不是 ACTIVE')
|
||||
|
||||
# ---------- 2. 话题有没有数据 ----------
|
||||
print('\n=== 2. 话题数据(各收 1 条,最多 8 秒)===')
|
||||
seen = {}
|
||||
|
||||
def waiter(key):
|
||||
def cb(_msg):
|
||||
seen[key] = seen.get(key, 0) + 1
|
||||
return cb
|
||||
|
||||
node.create_subscription(PointCloud2, '/scan/points', waiter('scan/points'), SENSOR_QOS)
|
||||
node.create_subscription(PointCloud2, '/scan/points_filtered',
|
||||
waiter('scan/points_filtered'), SENSOR_QOS)
|
||||
node.create_subscription(LaserScan, '/scan', waiter('scan'), SENSOR_QOS)
|
||||
node.create_subscription(Odometry, '/odom', waiter('odom'), 10)
|
||||
node.create_subscription(OccupancyGrid, '/map', waiter('map'), MAP_QOS)
|
||||
|
||||
deadline = time.time() + 8.0
|
||||
while time.time() < deadline and len(seen) < 5:
|
||||
rclpy.spin_once(node, timeout_sec=0.2)
|
||||
|
||||
for key in ('map', 'odom', 'scan', 'scan/points', 'scan/points_filtered'):
|
||||
ok = key in seen
|
||||
note = '(latched,订阅端 QoS 必须 TRANSIENT_LOCAL)' if key == 'map' else ''
|
||||
print(' /%-22s %s %s' % (key, '✅ 有数据' if ok else '❌ 没收到', note))
|
||||
if not ok:
|
||||
problems.append(f'话题 /{key} 没有数据')
|
||||
|
||||
# ---------- 3. TF 链 ----------
|
||||
print('\n=== 3. TF 链 ===')
|
||||
buf = Buffer()
|
||||
TransformListener(buf, node)
|
||||
|
||||
deadline = time.time() + 8.0
|
||||
while time.time() < deadline:
|
||||
rclpy.spin_once(node, timeout_sec=0.2)
|
||||
|
||||
for target, source in (('map', 'odom'), ('odom', 'base_link'),
|
||||
('map', 'base_link')):
|
||||
got = None
|
||||
deadline = time.time() + 5.0
|
||||
while time.time() < deadline:
|
||||
rclpy.spin_once(node, timeout_sec=0.1)
|
||||
try:
|
||||
got = buf.lookup_transform(target, source, rclpy.time.Time(),
|
||||
Duration(seconds=0.5))
|
||||
break
|
||||
except Exception:
|
||||
pass
|
||||
if got is None:
|
||||
print(' %-18s ❌ 不存在' % f'{target} -> {source}')
|
||||
problems.append(f'TF {target}->{source} 不存在')
|
||||
else:
|
||||
t = got.transform.translation
|
||||
print(' %-18s ✅ (%.3f, %.3f, %.3f)'
|
||||
% (f'{target} -> {source}', t.x, t.y, t.z))
|
||||
|
||||
if hasattr(buf, 'all_frames_as_yaml'):
|
||||
print('\n TF 里出现过的 frame:')
|
||||
for line in buf.all_frames_as_yaml().splitlines():
|
||||
print(' ' + line)
|
||||
|
||||
# ---------- 汇总 ----------
|
||||
print('\n=== 汇总 ===')
|
||||
if problems:
|
||||
print(' ❌ 有 %d 个问题:' % len(problems))
|
||||
for p in problems:
|
||||
print(' · ' + p)
|
||||
rclpy.shutdown()
|
||||
return 1
|
||||
print(' ✅ 全栈正常,可以发导航目标')
|
||||
rclpy.shutdown()
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main())
|
||||
+6
-1
@@ -7,13 +7,18 @@ import rclpy
|
||||
from nav2_msgs.action import NavigateToPose
|
||||
from rclpy.action import ActionClient
|
||||
from rclpy.node import Node
|
||||
from rclpy.parameter import Parameter
|
||||
from tf2_ros import Buffer, TransformListener
|
||||
|
||||
gx = float(sys.argv[1]) if len(sys.argv) > 1 else 2.0
|
||||
gy = float(sys.argv[2]) if len(sys.argv) > 2 else 2.0
|
||||
|
||||
rclpy.init()
|
||||
node = Node('nav_client')
|
||||
# 整套栈都是 use_sim_time:=true(Gazebo 时钟),客户端必须一致,
|
||||
# 否则本节点算出的时间戳跟 TF 里的仿真时间对不上。
|
||||
node = Node('nav_client',
|
||||
parameter_overrides=[
|
||||
Parameter('use_sim_time', Parameter.Type.BOOL, True)])
|
||||
tf_buffer = Buffer()
|
||||
TransformListener(tf_buffer, node)
|
||||
client = ActionClient(node, NavigateToPose, 'navigate_to_pose')
|
||||
|
||||
+52
-18
@@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env python3
|
||||
"""冒烟探针:等 Nav2 就绪 → 收几帧过滤后的点云 → 发一个导航目标并等结果。"""
|
||||
"""冒烟探针:等 Nav2 完全激活 → 收几帧过滤后的点云 → 发导航目标并等结果。"""
|
||||
import sys
|
||||
import time
|
||||
|
||||
@@ -10,11 +10,15 @@ from rclpy.qos import QoSProfile, ReliabilityPolicy
|
||||
from sensor_msgs.msg import PointCloud2
|
||||
from geometry_msgs.msg import PoseStamped
|
||||
from nav2_msgs.action import NavigateToPose
|
||||
from lifecycle_msgs.srv import GetState
|
||||
from lifecycle_msgs.msg import State
|
||||
|
||||
rclpy.init()
|
||||
node = Node('smoke_probe')
|
||||
node = Node('smoke_probe', parameter_overrides=[])
|
||||
node.set_parameters([rclpy.parameter.Parameter('use_sim_time',
|
||||
rclpy.Parameter.Type.BOOL, True)])
|
||||
|
||||
got = {'cloud': 0, 'pts': 0, 'minz': None}
|
||||
got = {'cloud': 0, 'pts': 0}
|
||||
|
||||
|
||||
def on_cloud(msg):
|
||||
@@ -25,14 +29,36 @@ def on_cloud(msg):
|
||||
qos = QoSProfile(depth=3, reliability=ReliabilityPolicy.BEST_EFFORT)
|
||||
node.create_subscription(PointCloud2, '/scan/points_filtered', on_cloud, qos)
|
||||
|
||||
|
||||
def wait_active(name, timeout):
|
||||
"""等某个 lifecycle 节点进入 ACTIVE(id=3)。"""
|
||||
cli = node.create_client(GetState, f'/{name}/get_state')
|
||||
if not cli.wait_for_service(timeout_sec=10.0):
|
||||
return f'服务 /{name}/get_state 不存在'
|
||||
deadline = time.time() + timeout
|
||||
while time.time() < deadline:
|
||||
fut = cli.call_async(GetState.Request())
|
||||
rclpy.spin_until_future_complete(node, fut, timeout_sec=5.0)
|
||||
if fut.done() and fut.result() is not None:
|
||||
st = fut.result().current_state
|
||||
if st.id == State.PRIMARY_STATE_ACTIVE:
|
||||
return None
|
||||
print('[probe] %s = %s,继续等…' % (name, st.label))
|
||||
time.sleep(2)
|
||||
return f'{name} {timeout} 秒内没到 ACTIVE'
|
||||
|
||||
|
||||
print('[probe] 等 Nav2 生命周期节点激活…')
|
||||
for name in ('bt_navigator', 'planner_server', 'controller_server'):
|
||||
err = wait_active(name, 180)
|
||||
if err:
|
||||
print('[probe] ❌', err)
|
||||
sys.exit(2)
|
||||
print('[probe] ✅ %s ACTIVE' % name)
|
||||
|
||||
AC = ActionClient(node, NavigateToPose, 'navigate_to_pose')
|
||||
print('[probe] 等 navigate_to_pose 动作服务器…')
|
||||
for _ in range(90):
|
||||
if AC.wait_for_server(timeout_sec=2.0):
|
||||
break
|
||||
print('[probe] 还没起来')
|
||||
else:
|
||||
print('[probe] ❌ 动作服务器 180 秒没起来')
|
||||
if not AC.wait_for_server(timeout_sec=30.0):
|
||||
print('[probe] ❌ navigate_to_pose 动作服务器不存在')
|
||||
sys.exit(2)
|
||||
print('[probe] ✅ 动作服务器就绪')
|
||||
|
||||
@@ -51,18 +77,26 @@ goal.pose.pose.position.y = 2.0
|
||||
goal.pose.pose.orientation.w = 1.0
|
||||
|
||||
print('[probe] 发导航目标 (2.0, 2.0) …')
|
||||
send = AC.send_goal_async(goal)
|
||||
rclpy.spin_until_future_complete(node, send, timeout_sec=30)
|
||||
handle = send.result()
|
||||
if handle is None or not handle.accepted:
|
||||
print('[probe] ❌ 目标被拒绝')
|
||||
handle = None
|
||||
for attempt in range(1, 13):
|
||||
send = AC.send_goal_async(goal)
|
||||
rclpy.spin_until_future_complete(node, send, timeout_sec=30)
|
||||
handle = send.result()
|
||||
if handle is not None and handle.accepted:
|
||||
print('[probe] 目标已接受(第 %d 次尝试)' % attempt)
|
||||
break
|
||||
print('[probe] 第 %d 次被拒绝,5 秒后重试…' % attempt)
|
||||
time.sleep(5)
|
||||
handle = None
|
||||
|
||||
if handle is None:
|
||||
print('[probe] ❌ 目标始终被拒绝')
|
||||
sys.exit(3)
|
||||
print('[probe] 目标已接受,等结果…')
|
||||
|
||||
res = handle.get_result_async()
|
||||
rclpy.spin_until_future_complete(node, res, timeout_sec=240)
|
||||
rclpy.spin_until_future_complete(node, res, timeout_sec=300)
|
||||
if not res.done():
|
||||
print('[probe] ❌ 240 秒内没拿到结果')
|
||||
print('[probe] ❌ 300 秒内没拿到结果')
|
||||
sys.exit(4)
|
||||
status = res.result().status
|
||||
print('[probe] ★ NavigateToPose status = %d (%s)'
|
||||
|
||||
Reference in new issue
Block a user