1- """Maplin USB Robot arm control"""
2- import os
3- os .environ ['DYLD_LIBRARY_PATH' ] = '/opt/local/lib'
1+ """Maplin USB Robot arm control.
2+ Usage -
3+ >>> import usb_arm
4+ >>> arm = usb_arm.Arm()
5+ >>> arm.move(usb_arm.OpenGrips)
6+ >>> arm.doActions(block_left) # WARNING - ARM SHOULD BE ALL THE WAY RIGHT BEFORE TRYING THIS
7+
8+ Trouble:
9+ "NO back end found" - you need to install a libusb driver on your system.
10+ """
411import usb .core
512from time import sleep
613
@@ -74,9 +81,11 @@ def safe_tell(self, fn):
7481
7582 def move (self , pattern , time = 1 ):
7683 """Perform a pattern move with timing and stop"""
77- self .tell (pattern )
78- sleep (time )
79- self .tell (Stop )
84+ try :
85+ self .tell (pattern )
86+ sleep (time )
87+ finally :
88+ self .tell (Stop )
8089
8190 def doActions (self , actions ):
8291 """Params: List of actions - each is a list/tuple of BitPattern and time
@@ -96,16 +105,16 @@ def doActions(self, actions):
96105 else :
97106 time = 1
98107 self .move (action [0 ], time )
99- except :
108+ finally :
100109 self .move (Stop )
101- raise
102110
111+ def makeGrabAndMove (baseDir ):
112+ return [[CloseGrips , 1.1 ],
113+ [ShoulderUp | ElbowUp | WristDown | baseDir ],
114+ [baseDir , 8.5 ],
115+ [ShoulderDown | ElbowDown | WristUp | baseDir ],
116+ [OpenGrips ]]
103117
104- block_left = [[ShoulderDown ], [GripsClose , 0.4 ], [ShoulderUp ],
105- [BaseClockWise , 10.2 ], [ShoulderDown ],
106- [GripsOpen , 0.4 ], [ShoulderUp , 1.2 ]]
107- block_right = [[ShoulderDown ], [GripsClose , 0.4 ], [ShoulderUp ],
108- [BaseCtrClockWise , 10.2 ], [ShoulderDown ],
109- [GripsOpen , 0.4 ], [ShoulderUp , 1.2 ]]
110- left_and_blink = list (block_left )
111- left_and_blink .extend ([[LedOn , 0.5 ], [Stop , 0.5 ]] * 3 )
118+ blink = [[LedOn , 0.5 ], [Stop , 0.5 ]] * 3
119+ block_left = makeGrabAndMove (BaseClockWise , 0.4 ) + blink
120+ block_right = makeGrabAndMove (BaseCtrClockWise , 0.4 ) + blink
0 commit comments