Welcome to DOFBOT-JetsonNANO repository
4.Read servo angle
Read Servo Angle
I. API Introduction
The corresponding API for reading the angle of a single bus servo 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 bottom-most servo having ID 1, increasing upward, and the top-most servo having ID 6.
Return value: The current angle of the corresponding ID servo. When ID=5, the angle range is 0~270, all others are 0~180.
II. Start Docker
After entering the main board desktop, open a terminal and run the following command to start the corresponding Dofbot container:
./Docker_Ros.sh
Then enter the following command in the Docker terminal to start jupyter-lab,
xxxxxxxxxxcdjupyter-lab --allow-root
Then enter the main board's IP address followed by :9999 in the browser,
xxxxxxxxxxIP:9999 // Example: 192.168.1.11:9999
III. Code Content
Code path: /root/Dofbot/3.ctrl_Arm/4.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# After individually controlling a 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.
