I have been using the MicroMeastro six version for a long time, but am now experiencing a bit of a problem. Sometimes when I run my code the unit flashes the LED red and then stops communicating. Here is the code:
#!/usr/bin/python
import serial
import time
class PololuMicroMaestro(object):
def __init__(self, port= "/dev/ttyACM0"):
self.ser = serial.Serial(port = port)
def setAngle(self, channel, angle):
minAngle = 0.0
maxAngle = 180.0
minTarget = 256.0
maxTarget = 13120.0
scaledValue = int((angle / ((maxAngle - minAngle) / (maxTarget - minTar\
get))) + minTarget)
commandByte = chr(0x84)
channelByte = chr(channel)
lowTargetByte = chr(scaledValue & 0x7F)
highTargetByte = chr((scaledValue >> 7) & 0x7F)
command = commandByte + channelByte + lowTargetByte + highTargetByte
self.ser.write(command)
self.ser.flush()
def close(self):
self.ser.close()
if __name__=="__main__":
robot = PololuMicroMaestro()
#home position
robot.setAngle(0,80)
robot.setAngle(1,80)
robot.setAngle(2,80)
robot.setAngle(3,75)
time.sleep(1)
#Lean Right
print "Leaning Right"
robot.setAngle(2,90)
robot.setAngle(0,110)
time.sleep(1)