< >
Home » OpenDuckMini快速入门教程 » OpenDuckMini快速入门教程-设置关节偏移

OpenDuckMini快速入门教程-设置关节偏移

文章说明

  • 本教程主要介绍如何进行设置关节偏移的操作
  • 欢迎加入我们的openduckmini交流群,微信扫描右侧二维码立即进群交流

相关设备

示例图片

前提准备

  • 使用纸箱或者支架从底部中间将鸭子架高

请输入图片描述

  • 提前了解舵机位置图

请输入图片描述

  • 将鸭子设置成直立姿势,检查舵机位置
$ cd ~/open_duck_mini_ws/Open_Duck_Mini_Runtime/scripts 
$ python check_motors.py

...
Checking if all motors are responsive...
Attempting to read position from motor 'left_hip_yaw' (ID: 20)...
✓ Motor 'left_hip_yaw' (ID: 20) is responsive. Position: -0.069
Attempting to read position from motor 'left_hip_roll' (ID: 21)...
✓ Motor 'left_hip_roll' (ID: 21) is responsive. Position: 0.083
Attempting to read position from motor 'left_hip_pitch' (ID: 22)...
✓ Motor 'left_hip_pitch' (ID: 22) is responsive. Position: -0.147
Attempting to read position from motor 'left_knee' (ID: 23)...
✓ Motor 'left_knee' (ID: 23) is responsive. Position: -0.193
Attempting to read position from motor 'left_ankle' (ID: 24)...
✓ Motor 'left_ankle' (ID: 24) is responsive. Position: 0.316
Attempting to read position from motor 'neck_pitch' (ID: 30)...
✓ Motor 'neck_pitch' (ID: 30) is responsive. Position: 0.514
Attempting to read position from motor 'head_pitch' (ID: 31)...
✓ Motor 'head_pitch' (ID: 31) is responsive. Position: -0.143
Attempting to read position from motor 'head_yaw' (ID: 32)...
✓ Motor 'head_yaw' (ID: 32) is responsive. Position: 0.316
Attempting to read position from motor 'head_roll' (ID: 33)...
✓ Motor 'head_roll' (ID: 33) is responsive. Position: -0.110
Attempting to read position from motor 'right_hip_yaw' (ID: 10)...
✓ Motor 'right_hip_yaw' (ID: 10) is responsive. Position: -0.17
Attempting to read position from motor 'right_hip_roll' (ID: 11)...
✓ Motor 'right_hip_roll' (ID: 11) is responsive. Position: 0.067
Attempting to read position from motor 'right_hip_pitch' (ID: 12)...
✓ Motor 'right_hip_pitch' (ID: 12) is responsive. Position: 0.112
Attempting to read position from motor 'right_knee' (ID: 13)...
✓ Motor 'right_knee' (ID: 13) is responsive. Position: 0.175
Attempting to read position from motor 'right_ankle' (ID: 14)...
✓ Motor 'right_ankle' (ID: 14) is responsive. Position: 0.118

当鸭子处于直立状态时,舵机的位置应该接近0

操作步骤

  • 正常组装的情况下,当鸭子处于完全直立状态时,舵机的位置应该为0

  • 组装时某些位置装得不对,比如舵盘装斜了,会导致直立时角度有偏差

  • 调整关节偏移的目的是对这些组装问题进行处理修复

  • 通常情况下,两腿应处于平行状态

  • 启动调整关节偏移的脚本

$ ~/open_duck_mini_ws/Open_Duck_Mini_Runtime/scripts
$ python find_soft_offsets.py

Warning : didn't provide a config json path, using default values
======
Warning : this script will move the robot to its zero position quiclky, make sure it is safe to do so
======

Press any key to start. The robot will move to its zero position. Make sure it is safe to do so. At any time, press ctrl+c to stop, the motors will be turned off.
d_coefficient: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
turn on : low KPS set
turn on : init pos set
d_coefficient: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
turn on : high kps

 === Setting up left_hip_yaw === (Y/(s)kip : y
left_hip_yaw is now turned off. Move it to the desired zero position and press any key to confirm the offset
 ---> Offset is -0.1
Press any key to move the motor to its zero position with offset taken into account
Is that ok ? (Y/n)y
Ok, setting offset
------
Current offsets :
left_hip_yaw : -0.1
left_hip_roll : -0.0
left_hip_pitch : -0.0
left_knee : -0.0
left_ankle : -0.0
neck_pitch : 0.0
head_pitch : 0.0
head_yaw : 0.0
head_roll : 0.0
right_hip_yaw : 0.0
right_hip_roll : 0.0
right_hip_pitch : 0.0
right_knee : 0.0
right_ankle : -0.0
------
  • 首先设置left_hip_roll舵机的零位,按y键进入设置,s键跳过设置
  • 进入设置后舵机会处于解除扭矩状态,你可以随意转动舵机到目标零位的位置,然后按任意键确定
  • 此时终端会输出当前舵机的偏移值---> Offset is -0.1
  • 再按任意键后,舵机会移动到应用偏移量后的零点位置
  • 最后确认是否满意当前舵机的位置,按y键继续下个设置,n键返回
  • 将得出的偏移值保存在根目录下duck_config.json文件上
测试
  • 运行turn_on脚本
$ cd ~/open_duck_mini_ws/Open_Duck_Mini_Runtime/scripts
$ python turn_on.py
  • 启动脚本后,鸭子应处于舵机扭矩锁定的曲腿姿态

请输入图片描述

  • 解除舵机扭矩锁定
$ cd ~/open_duck_mini_ws/Open_Duck_Mini_Runtime/scripts
$ python turn_off.py

FAQ

问题一:运行find_soft_offsets.py时,大腿呈水平姿态

  • 类似这样

请输入图片描述

  • 问题原因可能为: 组装没有横置安装22或者12号舵机,此时舵机的位置约为-1.57
解决方法

第一种方法

  • 直接在find_soft_offsets.py下调整偏移量

第二种方法

  • 松开舵机主舵盘的4颗螺丝,让整条腿处于松动姿态

请输入图片描述

  • 然后新建一个设置舵机回到中位的脚本
$ cd ~/open_duck_mini_ws/Open_Duck_Mini_Runtime/scripts
$ vim set_servo_mid.py
from mini_bdx_runtime.rustypot_position_hwi import HWI
from mini_bdx_runtime.duck_config import DuckConfig
import argparse
import time
import traceback

def zero_motor(hwi, joint_id, tol=0.02, timeout=5.0):
    """
    Move motor to 0 rad and wait until reached.
    """
    print(f"Zeroing motor ID {joint_id} to 0 rad")

    try:
        current_pos = hwi.io.read_present_position([joint_id])[0]
        print(f"Current position: {current_pos:.3f} rad")

        # Command zero position (rad)
        hwi.io.write_goal_position([joint_id], [0.0])

        start_time = time.time()
        while True:
            pos = hwi.io.read_present_position([joint_id])[0]
            err = abs(pos)

            print(f"  pos={pos:.3f} rad, err={err:.3f}")

            if err < tol:
                print("✓ Zero position reached")
                return True

            if time.time() - start_time > timeout:
                print("✗ Timeout while zeroing motor")
                return False

            time.sleep(0.05)

    except Exception as e:
        print(f"✗ Error zeroing motor ID {joint_id}: {e}")
        print(traceback.format_exc())
        return False

def main():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "--id",
        type=int,
        required=True,
        help="Motor ID to zero (rad = 0)",
    )
    args = parser.parse_args()

    print("Initializing hardware interface...")
    try:
        duck_config = DuckConfig()
        hwi = HWI(duck_config=duck_config)
        print("Successfully connected to hardware")
    except Exception as e:
        print(f"Error initializing HWI: {e}")
        print(traceback.format_exc())
        return

    # Zero motor
    zero_motor(hwi, args.id)

    # Disable torque after zeroing (safety)
    try:
        hwi.io.disable_torque([args.id])
        print(f"Torque disabled for motor ID {args.id}")
    except Exception:
        pass

if __name__ == "__main__":
    main()
  • 然后运行它,指顶需要配置的舵机回到中位
$ python set_servo_mid.py --id 12
Initializing hardware interface...
Successfully connected to hardware
Zeroing motor ID 22 to 0 rad
Current position: -3.086 rad
  pos=-3.086 rad, err=3.086
  pos=-3.086 rad, err=3.086
  pos=-3.086 rad, err=3.086
...
✗ Timeout while zeroing motor
Torque disabled for motor ID 22
  • 此时舵盘应该会转动起来,转完之后,再安装直立姿态固定好四颗螺丝就可以了

纠错,疑问,交流: 请进入讨论区点击加入Q群

获取最新文章: 扫一扫右上角的二维码加入“创客智造”公众号


标签: openduckmini