Welcome to DOFBOT SE repository
4.Read servo angle
Read Servo Angle
1. API Introduction
The API for reading a single bus servo's angle:
Arm_serial_servo_read(id)
Function: Read the current angle value of the bus servo.
Parameters:
id: The ID number of the servo to read, 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.
Return value: The current angle of the servo with the corresponding ID. When ID=5, the angle range is 0~270; all others are 0~180.
2. Code Content
Code path: /home/yahboom/Dofbot/3.ctrl_Arm/4.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# Read all servo angles 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! ") passxxxxxxxxxx# After controlling a single servo to move, 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)xxxxxxxxxxdel Arm # Release Arm objectOpen the program file from jupyter lab, and click the "Run All" 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.
