Files
blackbird/bot4cj/scripts/stdd.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

53 lines
1.9 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.
# stdd.py —— stdd.mt 的 mtc DSL 源码(新格式)
# 站立 → 四腿 1 号关节(s2/s4/s6/s8)10°→20°→30°→20°→10° 渐摆 → 收回站立。
# 编译:cd mtc && python -m mtc ../bot4cj/scripts/stdd.py -o ../bot4cj/scripts/stdd.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", "0x69")
# MPU6050_BIND("mpu6050-1", "i2c-1", "0x68")
# MPU6050_BIND("mpu6050-2", "i2c-0", "0x68")
# MPU6050_BIND("mpu6050-3", "i2c-0", "0x69")
Speaker("spk", 2, 48000, 0.6, 5000, 0) # min_f 原为占位符(首行解析为 0)
# 名 max ch rb=右后 lb=左后 lf=左前 rf=右前 cam=云台
_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)
_STAND = [45, 0, 45, 0, 45, 0, 45, 0, 90, 90]
def stand(dur=10):
"""全体回站立姿态(dur ms 线性到位);首行用默认 10ms = 瞬时跳变"""
for _i, _ang in enumerate(_STAND, 1):
SetTo(f"s{_i}", _ang, dur)
# ---- 动作序列(对应原 @Action 7 行:200 + 5×50 + 200,T=650ms) ----
stand() # 首行瞬时到位(原首行分解为恒等微步)
Beep(10, 650) # spk.F=10 贯穿全程(原各行占位符继承首行)
Delay(200)
for _ang in (10, 20, 30, 20, 10):
for _dev in ("s2", "s4", "s6", "s8"):
SetTo(_dev, _ang, 50)
Delay(50)
for _dev in ("s2", "s4", "s6", "s8"):
SetTo(_dev, 0, 200) # 收回站立
Delay(200)