Files
blackbird/bot4cj/scripts/record_stand.py
T
qing 0be9e5d0d2 feat(bot4cj/scripts): 13 个 .mt 脚本的 mtc DSL 源码(新格式)
std/stdd/tilt-r/l/f/b/lie-down/jump/rght-hand/left-hand/left-turn/t0/record_stand 全部转为 Python DSL(mtc 编译器输入),与原 .mt 执行级等价:经 RobotStruct dry-run + EpisodeRecorder 验证,actions.npy 形状一致且逐元素相等,record_stand 的 imu.npy (100,8) 形状一致,编译零告警。

关键语义依据:pybot 微步对舵机列线性插值、对 spk.F 列不插值(行级阶跃),分别对应 SetTo 斜坡段与 Beep 恒值段;首行 delay=200 恒等分解对应 stand() 的 10ms 瞬时到位段。原 .mt 保留未动,可用各文件头注释中的编译命令重新生成。
2026-08-15 14:25:59 +08:00

50 lines
1.7 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.
# record_stand.py —— record_stand.mt 的 mtc DSL 源码(新格式)
# 录制用:stand → s1/s3/s5/s7 依次到 60°/45°/30°/45° 姿态序列(各 200ms),
# 含 @Camera(合成帧)与激活的 @MPU6050_BIND(imu.npy 录制)。
# 编译:cd mtc && python -m mtc ../bot4cj/scripts/record_stand.py -o ../bot4cj/scripts/record_stand.mt
Alias("A", "angle")
Alias("F", "frequency")
I2C("i2c-0", "/dev/i2c-0")
I2C("i2c-1", "/dev/i2c-1")
PCA9685("pca9685-0", "i2c-1", "0x40")
MPU6050_BIND("mpu6050-0", "i2c-1", "0x68")
Speaker("spk", 2, 48000, 0.6, 5000, 0) # min_f 原为占位符(首行解析为 0)
# 名 max ch
_SERVOS = [("s1", 90, 0), # rb0
("s2", 180, 1), # rb1
("s3", -90, 2), # lb0
("s4", -180, 3), # lb1
("s5", 90, 4), # lf0
("s6", 180, 5), # lf1
("s7", -90, 6), # rf0
("s8", -180, 7), # rf1
("s9", 180, 8), # cam0
("s10", 180, 9)] # cam1
for _name, _max, _ch in _SERVOS:
Servo(_name, _max, 0, 0, "pca9685-0", _ch)
Camera("cam0", 640, 480, 30, 8)
_STAND = [45, 0, 45, 0, 45, 0, 45, 0, 90, 90]
def stand(dur=10):
for _i, _ang in enumerate(_STAND, 1):
SetTo(f"s{_i}", _ang, dur)
# ---- 动作序列(5×200,T=1000ms → 100 栅格行) ----
# 注:原文件注释「首行不分解,共 81 步」已过时——99c1bc1 起首行也分解为
# 20 个恒等微步,原版/编译版在现行 pybot 语义下均为 100 步且逐元素相等。
stand()
Beep(10, 1000) # spk.F=10 贯穿全程(r2-r5 占位符继承首行)
Delay(200)
for _ang in (60, 45, 30, 45):
for _dev in ("s1", "s3", "s5", "s7"):
SetTo(_dev, _ang, 200)
Delay(200)