Welcome to DOFBOT-JetsonNANO repository
3.Control single servo
Control Single Servo
I. API Introduction
The corresponding API for controlling a single bus servo is:
Arm_serial_servo_write(id, angle, time)
Function: Control the angle to which the bus servo should run.
Parameter explanation:
xid: The ID number of the servo to control, 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.angle: The angle to which the servo should run. Except for servo 5 (ID=5), all other servos have a control range of 0~180. Servo 5 has a control range of 0~270.time: The time for the servo to run. Within the effective range, for the same angle of rotation, the smaller the input time, the faster the servo movement. Input 0 for the servo to run at maximum speed.Return value: None.
II. Start Docker
After entering the main board desktop, open a terminal and run the following command to start the corresponding Dofbot container:
xxxxxxxxxx./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/3.ctrl_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# Individually control a servo to move to a specific angleid = 6Arm.Arm_serial_servo_write(id, 90, 500)time.sleep(1)xxxxxxxxxx# Control a servo to cycle through anglesid = 6def main(): while True: Arm.Arm_serial_servo_write(id, 120, 500) time.sleep(1) Arm.Arm_serial_servo_write(id, 50, 500) time.sleep(1) Arm.Arm_serial_servo_write(id, 120, 500) time.sleep(1) Arm.Arm_serial_servo_write(id, 180, 500) time.sleep(1) try : main()except KeyboardInterrupt: print(" Program closed! ") passxxxxxxxxxxdel Arm # Release the Arm objectOpen the program file from jupyter lab, and click the "run entire notebook" button on the jupyter lab toolbar, you will see the robotic arm's gripper continuously changing angles.

To exit, click the stop button on the toolbar.
