Welcome to DOFBOT Pro repository
4. Read Servo Angle
Read Servo Angle
1. API Introduction
The API corresponding to reading a single bus servo angle is:
Arm_serial_servo_read(id)
Function: Read the current angle value of the bus servo.
Parameter explanation:
id: The ID number of the servo to read, 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.
Return value: The current angle of the corresponding ID servo. When ID=5, the angle range is 0~270, others are 0~180.
2. Code Content
Code path:
~/dofbot_pro/dofbot_ctrl/scripts/04.read_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# 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! ") passxxxxxxxxxx# 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)xxxxxxxxxxdel Arm # Release the Arm objectOpen the program file from jupyter lab, and click the "Run entire notebook" button on the jupyter lab toolbar, jupyter lab will print out the current angle values of the six servos of the robotic arm.

To exit, click the stop button on the toolbar.
