Trees | Indices | Help |
---|
|
1 # Gear.py 2 # Remote mode 3 4 from RobotInstance import RobotInstance 5 import SharedConstants 6 7 # ------------------------ Class GearState ----------------------------------------------9 FORWARD = 0 10 BACKWARD = 1 11 STOPPED = 2 12 LEFT = 3 13 RIGHT = 4 14 LEFTARC = 5 15 RIGHTARC = 6 16 UNDEFINED = 717 18 # ------------------------ Class Gear --------------------------------------------------20 ''' 21 Class that represents the combination of two motors on an axis 22 to perform a car-like movement. 23 ''' 2413026 self.state = GearState.UNDEFINED 27 self.speed = SharedConstants.GEAR_DEFAULT_SPEED 28 self.arcRadius = 0 29 self.device = "gear" 30 robot = RobotInstance.getRobot() 31 if robot == None: # deferred registering, because Robot not yet created 32 RobotInstance._partsToRegister.append(self) 33 else: 34 self._setup(robot)3537 robot.sendCommand(self.device + ".create") 38 robot.sendCommand(self.device + ".setSpeed." + str(self.speed)) 39 self.robot = robot4042 self._checkRobot() 43 speed = int(speed) 44 if self.speed == speed: 45 return 46 self.speed = speed 47 self.robot.sendCommand(self.device + ".setSpeed." + str(speed)) 48 self.state = GearState.UNDEFINED4951 self._checkRobot() 52 if self.state == GearState.FORWARD: 53 return 54 if duration == 0: 55 self.robot.sendCommand(self.device + ".forward") 56 self.state = GearState.FORWARD 57 else: 58 self.robot.sendCommand(self.device + ".forward." + str(duration)) 59 self.state = GearState.STOPPED6062 self._checkRobot() 63 if self.state == GearState.BACKWARD: 64 return 65 if duration == 0: 66 self.robot.sendCommand(self.device + ".backward") 67 self.state = GearState.BACKWARD 68 else: 69 self.robot.sendCommand(self.device + ".backward." + str(duration)) 70 self.state = GearState.STOPPED7173 self._checkRobot() 74 if self.state == GearState.LEFT: 75 return 76 if duration == 0: 77 self.robot.sendCommand(self.device + ".left") 78 self.state = GearState.LEFT 79 else: 80 self.robot.sendCommand(self.device + ".left." + str(duration)) 81 self.state = GearState.STOPPED8284 self._checkRobot() 85 if self.state == GearState.RIGHT: 86 return 87 if duration == 0: 88 self.robot.sendCommand(self.device + ".right") 89 self.state = GearState.RIGHT 90 else: 91 self.robot.sendCommand(self.device + ".right." + str(duration)) 92 self.state = GearState.STOPPED9395 self._checkRobot() 96 radius = int(1000 * radius) 97 if duration == 0: 98 if self.state == GearState.LEFTARC and radius == self.arcRadius: 99 return 100 self.arcRadius = radius 101 self.robot.sendCommand(self.device + ".leftArcMilli." + str(radius)) 102 self.state = GearState.LEFTARC 103 else: 104 self.robot.sendCommand(self.device + ".leftArcMilli." + str(radius) + "." + str(duration)) 105 self.state = GearState.STOPPED106108 self._checkRobot() 109 radius = int(1000 * radius) 110 if duration == 0: 111 if self.state == GearState.RIGHTARC and radius == self.arcRadius: 112 return 113 self.arcRadius = radius 114 self.robot.sendCommand(self.device + ".rightArcMilli." + str(radius)) 115 self.state = GearState.RIGHTARC 116 else: 117 self.robot.sendCommand(self.device + ".rightArcMilli." + str(radius) + "." + str(duration)) 118 self.state = GearState.STOPPED119121 self._checkRobot() 122 if self.state == GearState.STOPPED: 123 return 124 self.robot.sendCommand(self.device + ".stop") 125 self.state = GearState.STOPPED126
Trees | Indices | Help |
---|
Generated by Epydoc 3.0.1 on Sun Apr 16 13:04:17 2017 | http://epydoc.sourceforge.net |