User Tools

Site Tools


motors-test-1

This is a simple python code to test the responsiveness and speed of two servo motors connected to an arduino. One motor is a linear servo actuator with 100mm stroke length. The other is a regular servo motor with a 180° rotation angle.

#the 2 motors program

#import the lib
from arduino import Arduino, Servo

import glob, time

#get the active port
portz=glob.glob("/dev/ttyUSB*")[0]
#print portz

#specify the port as an argument
my_board = Arduino(portz)

#declare output pins as a list/tuple
my_board.output([9,11])
linear=my_board.attachServo(9)
rotational=my_board.attachServo(11)

#perform operations
print "servo.read:",linear.read(),rotational.read()
linear.write(40)
rotational.write(80)
print "putting servos to sleep. positions: 40, 80"
time.sleep(12)
i=1
while(i<180):
    j=40+(i*0.64)
    print "linear:", int(j)
    linear.write(int(j))
    print "rotational:", i
    rotational.write(i)
    time.sleep(1)
    i+=10
motors-test-1.txt · Last modified: 2012/08/01 15:05 by 46.57.71.90