Welcome to DOFBOT-Ultra repository
3. Control Single Servo
Control Single Servo
1. API Introduction
The API for controlling a single bus servo is:
Arm_serial_servo_write(id, angle, time)
Function: Controls the target angle of the bus servo.
Parameter Description:
id: The ID number of the servo to control, range 1~6. Each ID represents a servo. The lowest servo has ID 1, increasing upward, with the topmost servo having ID 6.
angle: The target angle for the servo. Except for servo 5 (ID=5), the control range for all servos is 0~180. The control range for servo 5 is 0~270.
time: The runtime for the 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/03.ctrl_servo.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 a single servo to move to a certain angleid = 6Arm.Arm_serial_servo_write(id, 90, 500)time.sleep(1)xxxxxxxxxx# 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 the Arm objectOpen the program file from Jupyter Lab and click the "Run All Cells" button on the Jupyter Lab toolbar. You will see the robotic arm's gripper continuously changing angles.

To exit, click the stop button on the toolbar.
