Files
blackbird/pybot/tests/test_servo.py
T
qing bba7ee3eb4 feat(pybot): bot4cj 的 Python 迁移版(.mt 解析 + 硬件驱动 + 插件系统)
- parser: FSM 解析器与仓颉版逐语义对齐,修 S01/S02/S04/Q05
- robot/hardvars: 六类硬件变量工厂,修 r.cj:911 重名 FIXME、Q07 倒序释放
- plugin: Python 插件替代 Lua 桥接,修 S07 三级路径查找
- hd: i2c(每fd锁 Q03/S06)/spi/servo/kalman/mpu6050(S05/Q06)/speaker(S03 实声)
- modules: PCA9685 与 Lua 版逐字节对齐;ADS1115 重写(experimental);ADS1256 空桩
- tests: 42 项 pytest 全绿(Mock 总线 journal 断言)
- CLI: --dry-run / --test roundtrip / --verbose;运行时零第三方依赖
2026-08-09 18:57:03 +00:00

48 lines
1.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Servo 校准算法测试:正装/反装/漂移/钳位(与 Servo.cj 语义逐项对齐)"""
from pybot.hd.servo import Servo
def make(max_a, min_a, offset):
sent = []
servo = Servo(max_a, min_a, offset, sent.append)
return servo, sent
def test_normal_install():
servo, sent = make(90.0, 0.0, 0.0)
servo.set_angle(45.0)
assert sent == [45.0]
def test_clamp_max():
servo, sent = make(90.0, 0.0, 0.0)
servo.set_angle(120.0)
assert sent == [90.0]
def test_clamp_min():
servo, sent = make(180.0, 30.0, 0.0)
servo.set_angle(10.0)
assert sent == [30.0]
def test_offset():
servo, sent = make(180.0, 0.0, 5.0)
servo.set_angle(40.0)
assert sent == [45.0]
def test_inverted_install():
"""负 max 表示反装:a = 180 - a(std.mt 的 s3 max=-90,45° → 135°)"""
servo, sent = make(-90.0, 0.0, 0.0)
servo.set_angle(45.0)
assert sent == [180.0 - 45.0]
def test_inverted_clamp_uses_abs():
"""反装钳位用 |max|:-90 装机 100° → 钳到 90 → 翻转 90"""
servo, sent = make(-90.0, 0.0, 0.0)
servo.set_angle(100.0)
assert sent == [90.0]