Welcome to DOFBOT SE repository
2.Calibrate the Robotic Arm
Mid-Position Adjustment
1. API Introduction
- The API to open or close the bus servo torque is: Arm_serial_set_torque(enable)
Parameter explanation:
enable: enable=0 closes the torque, the robotic arm can be manually adjusted by掰动 the servo angle, and does not receive level signals; enable=1 opens the torque, the servo receives level signals to maintain the current angle, and commands are required to change the angle.
Return value: None.
- Arm_serial_servo_write_offset_switch(id)
Parameter explanation:
id: When id=0, clear all servo mid-position adjustments and restore to default; id=1~6 corresponds to the IDs of the six servos. After receiving this command, the underlying microcontroller will read the angle data of the servo with the corresponding ID. If the data is within a reasonable range, it will be saved. If it exceeds the range or the servo ID cannot be found, it will not be saved.
Return value: None.
- Arm_serial_servo_write_offset_state()
Parameter explanation:
Return value: Returns the state of the mid-position offset setting. state=0 indicates the servo was not detected; state=1 indicates the mid-position was set successfully; state=2 indicates the setting exceeded the mid-position range value.
2. Code Content
Code path: /home/yahboom/Dofbot/2.sys_settings/Offset/offset.ipynb
This code cannot be executed all at once in order. It must be executed step by step to ensure proper adjustment. The result of the adjustment is to keep the robotic arm in an upright state.
Note: This program should only be used when mid-position adjustment is needed. Do not use it arbitrarily, otherwise incorrect mid-position will affect the gripping效果.
x#!/usr/bin/env python3#coding=utf-8import timefrom Arm_Lib import Arm_Device# Create robotic arm objectArm = Arm_Device()time.sleep(.1)xxxxxxxxxx#Center and upright the servo stateArm.Arm_serial_servo_write6(90,90, 90, 90, 90, 180, 1000)time.sleep(2)xxxxxxxxxx# Close torque, now you can manually adjust servo angle by handArm.Arm_serial_set_torque(0)xxxxxxxxxx# After adjusting the angle of a specific servo, you can set the mid-position offset for that servo individuallyid = 6Arm.Arm_serial_servo_write_offset_switch(id)time.sleep(.1)state = Arm.Arm_serial_servo_write_offset_state()if state == 1: print("set offset ok!")elif state == 2: print("error! set offset overrun !")elif state == 0: print("error! set offset error !")xxxxxxxxxx# You can also set the mid-position offset for all servos (1-6) at oncefor i in range(6): id = i + 1 Arm.Arm_serial_servo_write_offset_switch(id) time.sleep(.1) state = Arm.Arm_serial_servo_write_offset_state() if state == 1: print("id:%d set offset ok!" % id) elif state == 2: print("error!id:%d set offset overrun !" % id) elif state == 0: print("error!id:%d set offset error !" % id)xxxxxxxxxx# After adjustment is complete, open the torqueArm.Arm_serial_set_torque(1)xxxxxxxxxx# Clear all servo mid-position offset settings and restore to default state.# If you need to clear the mid-position offset for all servos, remove the # below and run this cell#Arm.Arm_serial_servo_write_offset_switch(0)xxxxxxxxxxdel Arm # Release the Arm object