The API corresponding to 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 be read, ranging from 1 to 6. Each ID number represents a servo. The ID of the bottom servo is 1 and increases upwards. The ID of the top servo is 6.
Return value: The current angle of the corresponding ID servo. When ID=5, the angle range is 0~270, and otherwise it is 0~180.
After entering the Raspberry Pi 5 desktop, open a terminal and run the following command to start the container corresponding to Dofbot:
xxxxxxxxxx
./Docker_Ros.sh
Access Jupyter Lab within Docker:
xxxxxxxxxx
IP:9999 // Example: 192.168.1.11:9999
Code path:/root/Dofbot/3.ctrl_Arm/4.read_servo.ipynb
#!/usr/bin/env python3
#coding=utf-8
import time
from Arm_Lib import Arm_Device
#Create a robotic arm object
Arm = Arm_Device()
time.sleep(.1)
xxxxxxxxxx
# Read the angles of all servos and print them out in a loop
def 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! ")
pass
xxxxxxxxxx
# After controlling the movement of a servo separately, read its angle
id=6
angle = 150
Arm.Arm_serial_servo_write(id, angle, 500)
time.sleep(1)
aa = Arm.Arm_serial_servo_read(id)
print(aa)
time.sleep(.5)
xxxxxxxxxx
del Arm # Release the Arm object
Open the program file from jupyter lab and click the Run entire notebook button on the jupyter lab toolbar. Jupyter lab will print out the angle values of the six servos of the current robotic arm.
To exit, click the Stop button on the toolbar.