Welcome to DOFBOT-Ultra repository
5. Control All Servos
Control All 6 Servos
1. API Introduction
The API for controlling all 6 bus servos simultaneously is:
Arm_serial_servo_write6(S1, S2, S3, S4, S5, S6, time)
Function: Simultaneously controls the target angles of the six servos of the robotic arm.
Parameter Description:
S1: Angle value for servo 1, 0~180.
S2: Angle value for servo 2, 0~180.
S3: Angle value for servo 3, 0~180.
S4: Angle value for servo 4, 0~180.
S5: Angle value for servo 5, 0~270.
S6: Angle value for servo 6, 0~180.
time: The runtime for servo movement. Within the valid range, for the same rotation angle, a smaller time value results in faster servo movement. Input 0 for maximum speed.
Return value: None.
2. Code
Code path:
~/dofbot_ctrl/scripts/05.ctrl_all.ipynb
x
#!/usr/bin/env python3#coding=utf-8import timefrom Arm_Lib import Arm_Device# Create robotic arm objectArm = Arm_Device()time.sleep(.1)x
# Control six servos simultaneously, 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 # Let the servos return 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! ") passx
del Arm # Release the Arm objectOpen the program file from Jupyter Lab and click the "Run All Cells" button on the Jupyter Lab toolbar. You will see all six servos rotate simultaneously, and the robotic arm continuously changes its posture.

To exit, click the stop button on the toolbar.
