|
1 | 1 | """Maplin USB Robot arm control. |
2 | | -Usage - |
| 2 | +Usage - |
3 | 3 | >>> import usb_arm |
4 | 4 | >>> arm = usb_arm.Arm() |
5 | 5 | >>> arm.move(usb_arm.OpenGrips) |
@@ -31,15 +31,15 @@ def __or__(self, other): |
31 | 31 | return BitPattern(self.arm | other.arm, |
32 | 32 | self.base | other.base, |
33 | 33 | self.led | other.led) |
34 | | - |
| 34 | + |
35 | 35 | def __eq__(self, other): |
36 | 36 | return self.arm == other.arm and self.base == other.base and self.led == other.led |
37 | 37 |
|
38 | 38 | def __repr__(self): |
39 | 39 | return "<BitPattern arm:%s base:%s led:%s>" % (self.arm, self.base, self.led) |
40 | 40 |
|
41 | 41 | def __str__(self): |
42 | | - return self.__repr__() |
| 42 | + return self.__repr__() |
43 | 43 |
|
44 | 44 | GripsClose = BitPattern(1, 0, 0) |
45 | 45 | CloseGrips = GripsClose |
@@ -75,42 +75,44 @@ def safe_tell(self, fn): |
75 | 75 | case of an exception""" |
76 | 76 | try: |
77 | 77 | fn() |
78 | | - except: |
| 78 | + except Exception: |
79 | 79 | self.tell(Stop) |
80 | 80 | raise |
81 | 81 |
|
82 | 82 | def move(self, pattern, time=1): |
83 | 83 | """Perform a pattern move with timing and stop""" |
84 | 84 | try: |
85 | | - self.tell(pattern) |
86 | | - sleep(time) |
| 85 | + delf.tell(pattern) |
| 86 | + sleep(time) |
87 | 87 | finally: |
88 | | - self.tell(Stop) |
| 88 | + self.tell(Stop) |
89 | 89 |
|
90 | 90 | def doActions(self, actions): |
91 | 91 | """Params: List of actions - each is a list/tuple of BitPattern and time |
92 | 92 | (defaulting to 1 if not set)""" |
93 | | - #Validate |
| 93 | + # Validate |
94 | 94 | for action in actions: |
95 | 95 | if not 1 <= len(action) <= 2: |
96 | 96 | raise ValueError("Wrong number of parameters in action %s" % |
97 | 97 | (repr(action))) |
98 | 98 | if not isinstance(action[0], BitPattern): |
99 | 99 | raise ValueError("Not a valid action") |
100 | | - #Do |
| 100 | + # Do |
101 | 101 | for action in actions: |
102 | 102 | if len(action) == 2: |
103 | 103 | time = action[1] |
104 | 104 | else: |
105 | 105 | time = 1 |
106 | 106 | self.move(action[0], time) |
107 | 107 |
|
| 108 | + |
108 | 109 | def makeGrabAndMove(baseDir): |
109 | | - return [[CloseGrips, 1.1], |
110 | | - [ShoulderUp | ElbowUp | WristDown | baseDir], |
111 | | - [baseDir, 8.5], |
112 | | - [ShoulderDown | ElbowDown | WristUp | baseDir], |
113 | | - [OpenGrips]] |
| 110 | + return [[CloseGrips, 1.1], |
| 111 | + [ShoulderUp | ElbowUp | WristDown | baseDir], |
| 112 | + [baseDir, 8.5], |
| 113 | + [ShoulderDown | ElbowDown | WristUp | baseDir], |
| 114 | + [OpenGrips]] |
| 115 | + |
114 | 116 |
|
115 | 117 | blink = [[LedOn, 0.5], [Stop, 0.5]] * 3 |
116 | 118 | block_left = makeGrabAndMove(BaseClockWise) + blink |
|
0 commit comments