Welcome to DOFBOT-Ultra repository
4. Read Servo Angle
Read Servo Angle
1. API Introduction
The API for reading a single bus servo angle is:
Arm_serial_servo_read(id)
Function: Reads the current angle of the bus servo.
Parameter Description:
id: The ID number of the servo to read, range 1~6. Each ID represents a servo. The lowest servo has ID 1, increasing upward, with the topmost servo having ID 6.
Return value: The current angle of the specified servo. When ID=5, the angle range is 0~270; for others, it is 0~180.
2. Code
Code path:
~/dofbot_ctrl/scripts/04.read_servo.ipynb
x
#!/usr/bin/env python3#coding=utf-8import timefrom Arm_Lib import Arm_Device# Create robotic arm objectArm = Arm_Device()time.sleep(.1)x
# Read the angles of all servos and print them in a loopdef main(): while True: for i in range(6): aa = Arm.Arm_serial_servo_read(i+1) print(aa) time.sleep(.01) time.sleep(.5) print(" END OF LINE! ")try : main()except KeyboardInterrupt: print(" Program closed! ") passx
# Control a single servo to move, then read its angleid = 6angle = 150Arm.Arm_serial_servo_write(id, angle, 500)time.sleep(1)aa = Arm.Arm_serial_servo_read(id)print(aa)time.sleep(.5)x
del Arm # Release the Arm objectOpen the program file from Jupyter Lab and click the "Run All Cells" button on the Jupyter Lab toolbar. Jupyter Lab will print the current angle values of the six servos.

To exit, click the stop button on the toolbar.
