2026-05-20
p.connect(p.GUI)
p.setGravity(0, 0, -9.8)
p.loadURDF("plane.urdf")
robot = p.loadURDF(
"a1/a1.urdf",
[0, 0, 0.35],
p.getQuaternionFromEuler([0, 0, 0])
)
for i in range(p.getNumJoints(robot)):
info = p.getJointInfo(robot, i)
print(i, info[1].decode(), info[2])
phase = 2 * np.pi * freq * t
x = step_length * sin(phase)
z = step_height * sin(phase)
thigh = arctan2(x, height)
calf = -2 * thigh
roll, pitch = getBaseOrientation()
roll_correction = -0.8 * roll
pitch_correction = -0.8 * pitch
p.setJointMotorControlArray(
robot,
jointIndices,
p.POSITION_CONTROL,
targetPositions=angles,
forces=[200]*len(joints),
positionGains=[0.25]*len(joints),
velocityGains=[1.0]*len(joints)
)
while True:
controller.step(t)
p.stepSimulation()
time.sleep(1./240.)
原因:
解决方法:
原因:
解决方法:
t → gait → IK → 单关节控制
t
↓
trot gait
↓
IK计算
↓
balance()
↓
统一关节控制
| 改进内容 | 作用 |
|---|---|
| 加入 roll/pitch 修正 | 机器人倾斜时自动纠正 |
| 降低 step_height | 减少身体晃动 |
| 减小步长 | 降低冲击力 |
| 统一关节控制 | 减少关节不同步问题 |
| 相位 trot 控制 | 实现稳定对角步态 |
roll, pitch = getBaseOrientation()
roll_correction = -0.8 * roll
pitch_correction = -0.8 * pitch
angles[0] += roll_c
angles[1] += pitch_c
通过本次实验,成功实现了四足机器人在 PyBullet 中的基础 trot 步态控制,并在原始开环控制基础上加入了姿态稳定控制机制。