Welcome to DOFBOT-Pi repository
2.Calibrate the Robotic Arm
Calibrate the Robotic Arm
This case requires starting the corresponding Docker for Dofbot to run!
I. API Introduction
- The API for turning on or off bus servo torque is: Arm_serial_set_torque(enable)
Parameter explanation:
enable: enable=0 turns off torque, the robotic arm can manually adjust the servo angle and does not receive level signals; enable=1 turns on torque, the servo receives level signals to maintain the current angle, and commands can be sent to change the angle. Return value: None.
- Arm_serial_servo_write_offset_switch(id)
Parameter explanation:
id: When id=0, clear all servo neutral position adjustments and restore defaults; id=1~6 corresponds to the six servo IDs. After receiving this command, the underlying microcontroller will read the angle data of the corresponding ID servo. If it's 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 setting neutral position deviation, state=0 means the servo was not detected; state=1 means neutral position set successfully; state=2 means the neutral position setting exceeds the range value.
II. Code Content
Code path: /root/Dofbot/2.sys_settings/2.Offset/offset.ipynb
This code cannot be executed all at once in sequence; it must be executed step by step to ensure correct adjustment. The result of the adjustment is to keep the robotic arm in an upright position.
Note: This program should only be used when adjusting the neutral position. Do not use it arbitrarily, otherwise it will cause inaccurate neutral position and affect grasping performance.
x#!/usr/bin/env python3#coding=utf-8import timefrom Arm_Lib import Arm_Device# Create robotic arm objectArm = Arm_Device()time.sleep(.1)# Make servos return to center upright positionArm.Arm_serial_servo_write6(90, 90, 90, 90, 90, 180, 1000)time.sleep(2)# Turn off torque, now you can manually adjust servo angles by handArm.Arm_serial_set_torque(0)# After adjusting the angle of a certain servo, you can individually set the neutral position deviation of that servoid = 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 !")# You can also set all servos (1-6) neutral position deviation at oncefor i in range(6):id = i + 1Arm.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)# After adjustment is complete, turn on torqueArm.Arm_serial_set_torque(1)# Clear all servo neutral position deviation settings, restore default state.# If you need to clear all servo neutral position deviations, remove the # below and run this cell#Arm.Arm_serial_servo_write_offset_switch(0)del Arm # Release the Arm object
