归档 legacy/:stereo_yolo/stereo_ranger/target_tracker 三包 + 175 条测试 + demo/配置/权重/三份规格;运行链路不再依赖,默认 pytest 446 条,归档测试按需运行。 目标有效性第二判据改为 LOS 运动学一致性(pod_bridge/los_consistency.py),删除 require_vision;pod_locked() 叠加该判据,状态机随之后退重搜。 自定义返航(task_runner/return_home.py):保持转场高度回起飞点 → 恢复初始航向 → 垂直降落,不再爬 RTL_RETURN_ALT;未起飞/无起飞点/超时/异常仍退回 PX4 原生 RTL。 任务链安全兜底:主循环异常→紧急返航、stop 幂等、landing_stop 保留遥测、in_air 流复用+超时、解锁/起飞与吊舱识别仅执行一次、rtl_timeout 上限。 入口共享件拆到 utils/sitl_support.py;pod_sitl_test.py→l1_sitl_test.py;删除旧架构 test.py;相机脚本移入 tools/。 新增 .gitignore 并剔除历史误跟踪的 59 个 .pyc;requirements 按实际依赖重写;文档全面对齐,新增 legacy/README.md 与 tools/README.md。
75 lines
2.3 KiB
Python
75 lines
2.3 KiB
Python
"""pod_control_test.py —— 吊舱目标识别/锁定控制器单元测试。
|
|
|
|
覆盖:arm_detection 发 0x07(识别,目标类型)+0x0F(自动锁定)、
|
|
stop_tracking 发 0x0E(停止)+0x08(识别关)、地面站手动命令
|
|
stop_track(0x0E)/auto_lock(0x0F+0x10)/center(0x2B)。
|
|
"""
|
|
|
|
from pod_bridge.protocol import ControlCode
|
|
from task_runner.pod_control import PodController
|
|
|
|
|
|
class FakeBridge:
|
|
def __init__(self):
|
|
self.sent = []
|
|
|
|
def send_control(self, cmd):
|
|
self.sent.append(cmd)
|
|
|
|
|
|
def test_arm_detection_sends_detect_and_autolock():
|
|
bridge = FakeBridge()
|
|
pc = PodController(bridge, target_type=1)
|
|
pc.arm_detection()
|
|
|
|
assert len(bridge.sent) == 2
|
|
assert bridge.sent[0].code == ControlCode.TARGET_DETECT_ON
|
|
assert bridge.sent[0].param_x == 1 # 目标类型 1 = 无人机
|
|
assert bridge.sent[1].code == ControlCode.AUTO_LOCK_ON_FOUND
|
|
|
|
|
|
def test_arm_detection_default_target_type_is_person_vehicle():
|
|
bridge = FakeBridge()
|
|
pc = PodController(bridge) # 默认 target_type=0 = 人/车
|
|
pc.arm_detection()
|
|
assert bridge.sent[0].code == ControlCode.TARGET_DETECT_ON
|
|
assert bridge.sent[0].param_x == 0
|
|
|
|
|
|
def test_stop_tracking_sends_stop_and_detect_off():
|
|
bridge = FakeBridge()
|
|
pc = PodController(bridge)
|
|
pc.stop_tracking()
|
|
|
|
assert len(bridge.sent) == 2
|
|
assert bridge.sent[0].code == ControlCode.STOP_TRACK
|
|
assert bridge.sent[1].code == ControlCode.TARGET_DETECT_OFF
|
|
|
|
|
|
def test_stop_track_sends_only_stop():
|
|
"""地面站「停跟踪」= 只发 0x0E(0x0F 常驻自动锁定仍生效,对齐按键 u)。"""
|
|
bridge = FakeBridge()
|
|
pc = PodController(bridge)
|
|
pc.stop_track()
|
|
|
|
assert [c.code for c in bridge.sent] == [ControlCode.STOP_TRACK]
|
|
|
|
|
|
def test_auto_lock_sends_autolock_and_detect_to_track():
|
|
"""地面站「自动锁定」= 0x0F + 0x10(对齐按键 a)。"""
|
|
bridge = FakeBridge()
|
|
pc = PodController(bridge)
|
|
pc.auto_lock()
|
|
|
|
assert [c.code for c in bridge.sent] == [ControlCode.AUTO_LOCK_ON_FOUND,
|
|
ControlCode.DETECT_TO_TRACK]
|
|
|
|
|
|
def test_center_sends_center():
|
|
"""地面站「归中」= 0x2B(对齐按键 c)。"""
|
|
bridge = FakeBridge()
|
|
pc = PodController(bridge)
|
|
pc.center()
|
|
|
|
assert [c.code for c in bridge.sent] == [ControlCode.CENTER]
|