Welcome to DOFBOT-Pi repository
5.Control all servo
Control All Servos
I. API Introduction
The corresponding API for 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: The time for the servo to run. Within the effective range, for the same angle of rotation, the smaller the input time, the faster the servo movement. Input 0 for the servo to run at maximum speed.Return value: None.
II. Start Docker
After entering the main board desktop, open a terminal and run the following command to start the corresponding Dofbot container:
xxxxxxxxxx./Docker_Ros.sh
Then enter the following command in the Docker terminal to start jupyter-lab,
xxxxxxxxxxcdjupyter-lab --allow-root
Then enter the main board's IP address followed by :9999 in the browser,
xxxxxxxxxxIP:9999 // Example: 192.168.1.11:9999
III. Code Content
Code path: /root/Dofbot/3.ctrl_Arm/5.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# 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 the Arm object
xxxxxxxxxxOpen the program file from jupyter lab, and click the "run entire notebook" button on the jupyter lab toolbar, you will see the six servos of the robotic arm move simultaneously, with the robotic arm continuously changing its posture.

xxxxxxxxxxTo exit, click the stop button on the toolbar.
