Skip to content

Commit 2b4035f

Browse files
committed
Clean up - remove the part finished stuff. Needs rethinking.
1 parent c9fa467 commit 2b4035f

File tree

1 file changed

+22
-29
lines changed

1 file changed

+22
-29
lines changed

usb_arm.py

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
"""Maplin USB Robot arm control"""
22
import os
3-
os.environ['DYLD_LIBRARY_PATH']='/opt/local/lib'
3+
os.environ['DYLD_LIBRARY_PATH'] = '/opt/local/lib'
44
import usb.core
55
from time import sleep
66

77

88
class BitPattern(object):
9-
"""A bitpattern to send to a robot arm"""
9+
"""A bit pattern to send to a robot arm"""
1010
__slots__ = ['arm', 'base', 'led']
1111

1212
def __init__(self, arm, base, led):
@@ -22,29 +22,29 @@ def __getitem__(self, item):
2222

2323
def __or__(self, other):
2424
return BitPattern(self.arm | other.arm,
25-
self.base | other.base,
26-
self.led | other.led)
25+
self.base | other.base,
26+
self.led | other.led)
2727

2828
CloseGrips = BitPattern(1, 0, 0)
2929
OpenGrips = BitPattern(2, 0, 0)
3030
Stop = BitPattern(0, 0, 0)
31-
WristUp = BitPattern(0x4, 0, 0)
32-
WristDown = BitPattern(0x8, 0, 0)
33-
ElbowUp = BitPattern(0x10, 0, 0)
34-
ElbowDown = BitPattern(0x20, 0, 0)
35-
ShoulderUp = BitPattern(0x40, 0, 0)
36-
ShoulderDown = BitPattern(0x80, 0, 0)
31+
WristUp = BitPattern(0x4, 0, 0)
32+
WristDown = BitPattern(0x8, 0, 0)
33+
ElbowUp = BitPattern(0x10, 0, 0)
34+
ElbowDown = BitPattern(0x20, 0, 0)
35+
ShoulderUp = BitPattern(0x40, 0, 0)
36+
ShoulderDown = BitPattern(0x80, 0, 0)
3737
BaseClockWise = BitPattern(0, 1, 0)
3838
BaseCtrClockWise = BitPattern(0, 2, 0)
39-
LedOn = BitPattern(0, 0, 1)
39+
LedOn = BitPattern(0, 0, 1)
4040

4141

4242
class Arm(object):
4343
"""Arm interface"""
4444
__slots__ = ['dev']
4545

4646
def __init__(self):
47-
self.dev = usb.core.find(idVendor = 0x1267)
47+
self.dev = usb.core.find(idVendor=0x1267)
4848
self.dev.set_configuration()
4949

5050
def tell(self, msg):
@@ -61,18 +61,20 @@ def safe_tell(self, fn):
6161
self.tell(Stop)
6262
raise
6363

64-
def move(self, pattern, time = 1):
64+
def move(self, pattern, time=1):
6565
"""Perform a pattern move with timing and stop"""
6666
self.tell(pattern)
6767
sleep(time)
6868
self.tell(Stop)
6969

7070
def doActions(self, actions):
71-
"""Params: List of actions - each is a list/tuple of BitPattern and time (defaulting to 1 if not set)"""
71+
"""Params: List of actions - each is a list/tuple of BitPattern and time
72+
(defaulting to 1 if not set)"""
7273
#Validate
7374
for action in actions:
7475
if not 1 <= len(action) <= 2:
75-
raise ValueError("Wrong number of parameters in action %s" % (repr(action)))
76+
raise ValueError("Wrong number of parameters in action %s" %
77+
(repr(action)))
7678
if not isinstance(action[0], BitPattern):
7779
raise ValueError("Not a valid action")
7880
#Do
@@ -89,19 +91,10 @@ def doActions(self, actions):
8991

9092

9193
block_left = [[ShoulderDown], [CloseGrips, 0.4], [ShoulderUp],
92-
[BaseClockWise, 10.2], [ShoulderDown], [OpenGrips, 0.4], [ShoulderUp, 1.2]]
93-
block_right = [[ShoulderDown], [CloseGrips, 0.4], [ShoulderUp], [BaseCtrClockWise, 10.2],
94-
[ShoulderDown], [OpenGrips, 0.4], [ShoulderUp, 1.2]]
94+
[BaseClockWise, 10.2], [ShoulderDown],
95+
[OpenGrips, 0.4], [ShoulderUp, 1.2]]
96+
block_right = [[ShoulderDown], [CloseGrips, 0.4], [ShoulderUp],
97+
[BaseCtrClockWise, 10.2], [ShoulderDown],
98+
[OpenGrips, 0.4], [ShoulderUp, 1.2]]
9599
left_and_blink = list(block_left)
96100
left_and_blink.extend([[LedOn, 0.5], [Stop, 0.5]] * 3)
97-
98-
99-
#def make_stack_action(source_blocks, dest_blocks, base_dir):
100-
# """The block counts suggest how high we should be taking up blocks from.
101-
# Starting point is over the source stack. Elbow should be 3 seconds from horizontal, shoulder vertical, grippers open"""
102-
# if base_dir = BitPatterns.BaseClockWise:
103-
# ctr_dir = BitPatterns.BaseCtrClockWise
104-
# else:
105-
# ctr_dir = BitPatterns.BaseClockWise
106-
# cmds = [[ElbowDown, 3 - source_blocks * 0.4]]
107-
# cmds = [[ShoulderDown], [CloseGrips, 0.4], [ShoulderUp], [BaseClockWise, 10.2], [ShoulderDown], [OpenGrips, 0.4], [ShoulderUp, 1.2]]

0 commit comments

Comments
 (0)