Files
blackbird/pybot/README.md
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

58 lines
2.3 KiB
Markdown
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.
# pybot
机器人 `.mt` 动作脚本解析器 —— [bot4cj](../bot4cj/)(仓颉版)的 Python 迁移版。
驱动大顺(Dashun)蜘蛛机器人(树莓派 aarch64,10 舵机 + 2 云台,
PCA9685 PWM 控制器 + MPU6050 姿态传感器)。
迁移方案与审计修复映射见
[docs/reports/bot4cj_python_migration_dev_doc.md](../docs/reports/bot4cj_python_migration_dev_doc.md)。
## 特性
- **零第三方依赖**:纯标准库(fcntl / struct / threading / wave / argparse),
树莓派上 `git pull` 即部署,无构建步骤。
- **与仓颉版逐语义对齐**:FSM 解析器、占位符递归、Servo 校准算法、
PCA9685 寄存器序列均与 bot4cj 一致(Mock 总线 journal 可逐字节 diff)。
- **Python 插件替代 Lua**:`modules/<块名>.py` 定义
`build(ctx) / call(ctx) / destroy(ctx)`,消除 JSON 深拷贝 + 五层 FFI 桥接。
- **审计修复**:bot4cj 审计 15 项发现(S01~S08 / Q01~Q07)全部修复,
详见迁移文档 §5。
## 用法
```bash
cat scripts/std.mt | ./_run.sh # 与 bot4cj 相同的管道用法
./_run.sh scripts/std.mt # 位置参数(增强)
./_run.sh --dry-run scripts/std.mt # Mock 总线,动作序列到 stdout
./_run.sh --test roundtrip in.mt out.mt # 解析↔序列化往返自检
./_run.sh --verbose scripts/std.mt # DEBUG 日志(stderr)
```
`-i` / `-o` 参数位保留(reserved),未来对接 [actpred](../actpred/) 动作预测。
## 目录
```
pybot/ # 包:parser / robot / hardvars / plugin / main
pybot/hd/ # 硬件层:i2c / spi / servo / kalman / mpu6050 / speaker
modules/ # 硬件驱动插件:PCA9685 / SPI / ADS1115 / ADS1256
scripts -> ../bot4cj/scripts # .mt 脚本与仓颉版共享
tests/ # pytest 单元测试(Mock 总线,无需硬件)
```
插件查找顺序:`$PYBOT_MODULES_PATH`(冒号分隔)→ 包内置 `modules/` → `./modules/`。
## 开发
```bash
./_set.sh # venv + pytest 全量测试
venv/bin/python -m pytest tests/ -v
```
## .mt 脚本格式
见 [bot4cj/README.md](../bot4cj/README.md) 与 `scripts/std.mt`。
格式要点:`@块名` 开块、行 0 为表头、`;` 结行、`#` 注释、
`-` 占位符(非首行取上一行同列值;首行数值列解析为 0)、`@` 收块。