1 # for more Pololu Micro Maestro interface code 2 # see http://afflator.ontopoeticmachines.org/post/9 3 4 def setpos(cha,uS): 5 """maestro uses is 0.25us increments 6 """ 7 pos=int(uS) 8 pos=pos*4 9 low=pos&0x7f 10 high=pos>>7 11 #print low,high 12 # cmd, chan, low, high 13 s.write(chr(0x84)+chr(cha)+chr(low)+chr(high)) 14 15 def setpos0(uS): 16 setpos(0,uS) 17 18 def setpos1(uS): 19 setpos(1,uS) 20 21 def setpos2(uS): 22 setpos(2,uS) 23 24 def setpos3(uS): 25 setpos(3,uS) 26 27 def setpos4(uS): 28 setpos(4,uS) 29 30 from Tkinter import * 31 import serial 32 s=serial.Serial() 33 34 # this /dev/tty.usbmodem device is for my particular system 35 # do ls /dev/tty.usbmodem* to figure out yours 36 # in Dual USB mode, lower number is the command port 37 38 s.port="/dev/tty.usbmodem00049671" 39 s.baudrate=115200 40 s.timeout=1 41 s.open() 42 43 44 master = Tk() 45 46 w0 = Scale(master,command=setpos0,from_=500,to=2500,length=500) 47 w0.grid(row=0,column=0) 48 w0.set(1500) 49 50 w1 = Scale(master,command=setpos1,from_=500,to=2500,length=500) 51 w1.grid(row=0,column=1) 52 w1.set(1500) 53 54 w2 = Scale(master,command=setpos2,from_=500,to=2500,length=500) 55 w2.grid(row=0,column=2) 56 w2.set(1500) 57 58 w3 = Scale(master,command=setpos3,from_=500,to=2500,length=500) 59 w3.grid(row=0,column=3) 60 w3.set(2000) 61 62 w4 = Scale(master,command=setpos4,from_=500,to=2500,length=500) 63 w4.grid(row=0,column=4) 64 w4.set(1500) 65 66 #note that the initial servo values may differ slightly between arms 67 68 setpos(0,1500) 69 setpos(1,1500) 70 setpos(2,1500) 71 setpos(3,2000) 72 setpos(4,1500) 73 74 master.mainloop()