Welcome to DOFBOT SE repository
3.Control single servo
Control Single Servo
1. API Introduction
The API for controlling a single bus servo:
Arm_serial_servo_write(id, angle, time)
Function: Control the bus servo to move to a specified angle.
Parameters:
id: The ID number of the servo to control, range is 1~6. Each ID represents a servo. The servo at the bottom has ID 1, and the IDs increase upward. The topmost servo has ID 6.
angle: The target angle for the servo to move to. Except for servo 5 (ID=5), the control range for all other servos is 0~180. Servo 5's control range is 0~270.
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 /3.ctrl_servo.ipynb
#!/usr/bin/env python3#coding=utf-8import timefrom Arm_Lib import Arm_Device# Create DOFBOT objectArm = Arm_Device()time.sleep(.1)xxxxxxxxxx# Control a single servo to move to a specific angleid = 6Arm.Arm_serial_servo_write(id, 90, 500)time.sleep(1)x# Control a servo to cycle through anglesid = 6def main(): while True: Arm.Arm_serial_servo_write(id, 120, 500) time.sleep(1) Arm.Arm_serial_servo_write(id, 50, 500) time.sleep(1) Arm.Arm_serial_servo_write(id, 120, 500) time.sleep(1) Arm.Arm_serial_servo_write(id, 180, 500) time.sleep(1)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 the DOFBOT's claw continuously changing angles.

To exit, click the Stop button on the toolbar.
