MCPcopy Create free account
hub / github.com/ActiveState/code / Arm

Class Arm

recipes/Python/361168_Vpython_example/recipe-361168.py:7–115  ·  view source on GitHub ↗

Represents the robot arm

Source from the content-addressed store, hash-verified

5from Numeric import array
6
7class Arm(object):
8 """Represents the robot arm"""
9
10 def __init__(self, stacks):
11 """Pass the Stacks instance"""
12 self.stacks = stacks
13
14 def _getBlocks(self, a, b):
15 """Pass two zero based numbers and get two
16 block objects. All checking done, returns (None, None)
17 if the indexes are wrong
18 """
19 if not (0 < a < self.stacks.blockCount): return None, None
20 if not (0 < b < self.stacks.blockCount): return None, None
21 a = self.stacks.blocks[a]
22 b = self.stacks.blocks[b]
23 if a.position == b.position: return None, None
24 return a, b
25
26 def moveOnto(self, a, b):
27 """
28 Move a onto b
29
30 Where a and b are block numbers, puts block a onto block b
31 after returning any blocks that are stacked on top of blocks
32 a and b to their initial positions.
33 """
34 # Get the actual block objects
35 a, b = self._getBlocks(a, b)
36 if not a: return # Ignore bad indexes
37 # Return blocks ontop of a to original positions (in reverse order of course)
38 a.removeBlocksFromAbove()
39 # Return blocks ontop of b to original positions
40 b.removeBlocksFromAbove()
41 # Move block a on top of block b
42 a.moveTo(b.position)
43
44 def moveOver(self, a, b):
45 """
46 Move a over b
47
48 Where a and b are block numbers, puts block a onto the top of the stack
49 containing block b, after returning any blocks that are stacked on top
50 of block a to their initial positions.
51 """
52 a, b = self._getBlocks(a, b)
53 if not a: return # Ignore bad indexes
54 # Move all blocks in a's stack to their original positions
55 a.removeBlocksFromAbove()
56 # Move a to the top of b's stack
57 a.moveTo(b.position)
58
59 def pileOnto(self, a, b):
60 """
61 Pile a onto b
62
63 Where a and b are block numbers, moves the pile of blocks consisting of
64 block a, and any blocks that are stacked above block a, onto block b.

Callers 2

parseFunction · 0.85
test1Function · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected