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

51 lines
1.5 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.
# jump.py —— jump.mt 的 mtc DSL 源码(新格式)
# 跳跃:四腿 1 号关节(s2/s4/s6/s8)快速下蹲 10°→20°→30°(各 20ms)后 200ms 弹回站立。
# 编译:cd mtc && python -m mtc ../bot4cj/scripts/jump.py -o ../bot4cj/scripts/jump.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)
# 名 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)
_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)
# ---- 动作序列(200 + 3×20 + 200,T=460ms) ----
stand()
Beep(10, 460) # spk.F=10 贯穿全程
Delay(200)
for _ang in (10, 20, 30):
for _dev in ("s2", "s4", "s6", "s8"):
SetTo(_dev, _ang, 20)
Delay(20)
stand(200) # 弹回站立
Delay(200)