实现预定流程全链路: 任务状态机 + 编排器 + 地面站 + 真机/SITL入口

- utils/task_runner: 6态状态机(WAIT→ARM_TAKEOFF→GOTO(L2)→TRACK(L1)→APPROACH→RTL)
  + 编排器(快照采集/状态动作) + 双层日志(事件JSONL/遥测CSV) + 吊舱控制指令(0x07/0x0F/0x0E/0x08)
- pod_bridge: ground_link 地面坐标UDP注入(超龄判无效,无激光替代表4);
  set_heading_servo_enabled() 运行时L1/L2切换(切换即reset清积分防输出跳变);
  pod_locked 提为公共门控; config 新增 ground_inject 段
- virtual_pod 模拟吊舱(无电机语义) + verify_px4 增量④仅飞控验证 +
  pod_sitl_test L1 SITL全流程(飞行编排不塞进 run_bridge, 保持纯offboard闭环入口)
- 入口: task_runner_sitl(VirtualPod+虚拟目标, SITL端到端跑通约1m24s) /
  task_runner_real(真串口+UDP注入+吊舱控制)
- 地面站 ground_station: 坐标注入 + 状态可视化(Flask)
- S1标定回填(2026-10-09): beta_sign=+1 / alpha_sign=-1, 加标定回归测试守护
- 新增测试: task_runner x4 + ground_link/virtual_pod*/bridge/px4_gateway 增量; 全量 483 passed
- 文档: 预定流程(需求) + 预定流程-操作指南(操作/待办) + L1方案补S1结论与实现状态
This commit is contained in:
keita
2026-10-13 15:50:32 +08:00
parent 5a944af4f5
commit ded17d7995
30 changed files with 3552 additions and 27 deletions
@@ -0,0 +1,94 @@
"""ground_link_test.py —— 地面坐标注入通道单元测试。
覆盖:parse_payload 解析(合法/缺字段/非法 JSON/非对象/类型错误)、
is_valid 新鲜度判定(未注入/新鲜/超龄边界)。
"""
import pytest
from pod_bridge.ground_link import GroundInjectConfig, GroundLink, GroundTarget
# --- parse_payload ----------------------------------------------------------
def test_parse_valid_payload():
t = GroundLink.parse_payload(
b'{"lat": 39.9042, "lon": 116.4074, "alt": 50.0}')
assert t is not None
assert t.latitude_deg == pytest.approx(39.9042)
assert t.longitude_deg == pytest.approx(116.4074)
assert t.abs_alt_m == pytest.approx(50.0)
assert t.time_ms == 0 # 打戳由接收方(run)负责
def test_parse_default_alt_is_zero():
t = GroundLink.parse_payload(b'{"lat": 1.0, "lon": 2.0}')
assert t is not None
assert t.abs_alt_m == 0.0
def test_parse_missing_lat_returns_none():
assert GroundLink.parse_payload(b'{"lon": 2.0}') is None
def test_parse_missing_lon_returns_none():
assert GroundLink.parse_payload(b'{"lat": 1.0}') is None
def test_parse_invalid_json_returns_none():
assert GroundLink.parse_payload(b'not json') is None
def test_parse_non_object_returns_none():
assert GroundLink.parse_payload(b'[1, 2, 3]') is None
def test_parse_string_coords_returns_none():
assert GroundLink.parse_payload(b'{"lat": "x", "lon": 2.0}') is None
def test_parse_bool_coords_returns_none():
# True 是 bool 不是数值 → 拒绝
assert GroundLink.parse_payload(b'{"lat": true, "lon": 2.0}') is None
def test_parse_ignores_ts_field():
"""ts 字段仅诊断,不参与解析(新鲜度用本地接收时刻)。"""
t = GroundLink.parse_payload(b'{"lat": 1.0, "lon": 2.0, "ts": 999}')
assert t is not None
assert t.latitude_deg == pytest.approx(1.0)
# --- is_valid ---------------------------------------------------------------
def _link(timeout_ms=5000):
return GroundLink(GroundInjectConfig(timeout_ms=timeout_ms),
now_ms_fn=lambda: 0)
def _inject(link, time_ms):
link._target = GroundTarget(latitude_deg=1.0, longitude_deg=2.0,
time_ms=time_ms)
def test_is_valid_false_when_never_injected():
assert _link().is_valid(1000) is False
def test_is_valid_true_when_fresh():
link = _link(timeout_ms=5000)
_inject(link, 1000)
assert link.is_valid(1000) is True
assert link.is_valid(4000) is True
def test_is_valid_timeout_boundary():
link = _link(timeout_ms=5000)
_inject(link, 1000)
assert link.is_valid(6000) is True # 恰好 5000ms,未超龄
assert link.is_valid(6001) is False # 5001ms,超龄
def test_latest_returns_injected_target():
link = _link()
_inject(link, 1000)
assert link.latest().latitude_deg == pytest.approx(1.0)
assert link.latest().time_ms == 1000