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