Welcome to DOFBOT SE repository
5.Control all servo
Control All Servo
1. API Introduction
The API for controlling 6 bus servos at once:
Arm_serial_servo_write6(S1, S2, S3, S4, S5, S6, time)
Function: Simultaneously control all six servos of the DOFBOT to move to specified angles.
Parameters:
S1: Angle value for servo 1, range 0~180.
S2: Angle value for servo 2, range 0~180.
S3: Angle value for servo 3, range 0~180.
S4: Angle value for servo 4, range 0~180.
S5: Angle value for servo 5, range 0~270.
S6: Angle value for servo 6, range 0~180.
time: The time for the servo to run. Within the valid range, for the same rotation angle, a smaller time value means faster servo movement. Input 0 for the fastest speed.
Return value: None.
2. Code Content
Code path: /home/yahboom/Dofbot/3.ctrl_Arm/5.ctrl_all.ipynb
#!/usr/bin/env python3#coding=utf-8import timefrom Arm_Lib import Arm_Device# Create DOFBOT objectArm = Arm_Device()time.sleep(.1)x# Simultaneously control six servos to move, gradually changing angles.def ctrl_all_servo(angle, s_time = 500): Arm.Arm_serial_servo_write6(angle, 180-angle, angle, angle, angle, angle, s_time) time.sleep(s_time/1000)def main(): dir_state = 1 angle = 90 # Reset servos to center position Arm.Arm_serial_servo_write6(90, 90, 90, 90, 90, 90, 500) time.sleep(1) while True: if dir_state == 1: angle += 1 if angle >= 180: dir_state = 0 else: angle -= 1 if angle <= 0: dir_state = 1 ctrl_all_servo(angle, 10) time.sleep(10/1000)# print(angle)try : main()except KeyboardInterrupt: print(" Program closed! ") passxxxxxxxxxxdel Arm # Release Arm objectOpen the program file from jupyter lab, and click the "Run All" button on the jupyter lab toolbar to see all six servos of the DOFBOT rotating simultaneously, with the DOFBOT continuously changing its posture.

To exit, click the Stop button on the toolbar.
