Welcome to DOFBOT Pro repository
3. Control Single Servo
Control Single Servo
1. API Introduction
The API corresponding to controlling a single bus servo is:
Arm_serial_servo_write(id, angle, time)
Function: Control the angle to which the bus servo should run.
Parameter explanation:
xid: The ID number of the servo to control, range is 1~6. Each ID number represents a servo, with the servo at the bottom having ID 1, increasing upwards, and the top servo having ID 6.angle: Control the angle to which the servo should run. Except for servo 5 (ID=5), the control range for other servos is 0~180. The control range for servo 5 is 0~270.time: Control the running time of the servo. Within the effective range, for the same angle of rotation, the smaller the input running time, the faster the servo moves. Input 0 for the servo to run at maximum speed.Return value: None.
2. Code Content
Code path:
xxxxxxxxxx~/dofbot_pro/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 entire notebook" button on the jupyter lab toolbar, you can see the robotic arm's gripper continuously changing angles.

To exit, click the stop button on the toolbar.
