Controlling Servo Motors

Follow along: Controlling Servo Motors

The program launching process along with parameter settings are all simplified and set up on the Jupyter Notebook Environment.
This example shows us how to control multiple different servos at the same time.
  • Open the 05_03_ctrl_all.ipynb Jupyter Notebook.
  • Load Arm_Lib module and register the robot arm as an object.
  • Follow and Execute the example codes.
(The Jetson Board used for these examples are => Jetson Nano)

  • 05_03_ctrl_all.ipynb

  • Running the cell code.
    Ctrl + Enter
  • To control the robot arm from code, don’t forget to shut down the docker container. See here.

  • Load Arm_Lib module and register the robot arm as an object.

import time
from Arm_Lib import Arm_Device

# Register robot arm object.
Arm = Arm_Device()
time.sleep(.1)
  • Arm_serial_servo_write (motor number, angle, time)

  • Increase and decrease all servo motor angles by 1˚ using a while statement.

# Gradually changes the angle while controlling 6 servos at the same time.
def ctrl_all_servo(angle, s_time = 500):
    Arm.Arm_serial_servo_write6(angle, 180-angle, angle, angle, angle, angle, s_time)
    time.sleep(0.1)


def main():
    dir_state = 1
    angle = 90

    Arm.Arm_serial_servo_write6(90, 90, 90, 90, 90, 90, 500)
    time.sleep(1)


    while True:
        if dir_state == 1:
            angle += 1
            if angle >= 180:
                dir_state = 0
        else:
            angle -= 1
            if angle <= 0:
                dir_state = 1

        ctrl_all_servo(angle, 700)
        time.sleep(10/1000)
#         print(angle)


try :
    main()
except KeyboardInterrupt:
    print(" Program closed! ")
    pass
  • Move the robot arm to initial position and remove the robot arm object.

Arm.Arm_serial_servo_write6(90, 90, 90, 90, 90, 90, 500)
del Arm  # Remove robot arm object.