Welcome to DOFBOT Pro repository
5. Control All Servos
Control All Servos
1. API Introduction
The API corresponding to controlling 6 bus servos simultaneously is:
Arm_serial_servo_write6(S1, S2, S3, S4, S5, S6, time)
Function: Simultaneously control the angles to which the six servos of the robotic arm should move.
Parameter explanation:
xS1: Angle value of servo 1, range 0~180.S2: Angle value of servo 2, range 0~180.S3: Angle value of servo 3, range 0~180.S4: Angle value of servo 4, range 0~180.S5: Angle value of servo 5, range 0~270.S6: Angle value of servo 6, range 0~180.time: Control the running time of the servos. Within the effective range, for the same angle of rotation, the smaller the input running time, the faster the servos move. Input 0 for the servos to run at maximum speed.Return value: None.
2. Code Content
Code path:
xxxxxxxxxx~/dofbot_pro/dofbot_ctrl/scripts/05.ctrl_all.ipynb
xxxxxxxxxx#!/usr/bin/env python3#coding=utf-8import timefrom Arm_Lib import Arm_Device# Create robotic arm objectArm = Arm_Device()time.sleep(.1)xxxxxxxxxx# 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! ") passxxxxxxxxxxdel Arm # Release the Arm objectOpen the program file from jupyter lab, and click the "Run entire notebook" button on the jupyter lab toolbar, you can see the six servos of the robotic arm rotating simultaneously, with the robotic arm continuously changing its posture.

To exit, click the stop button on the toolbar.
