全部改为用Xmake,然后精简一下文档
This commit is contained in:
1 parent
d8f1e2226d
commit
970b16f17f
34 files changed
+1903
-1133
No files matched your search
@@ -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())
|
||||
Reference in new issue
Block a user