def testForwardsMovement(self): # Stop the machine self.machine.stop() # Set the range to far away but outside of the radius self.ai.data['lastLightEvent'] = vision.RedLightEvent(0.8, 0.8) self.ai.data['lastLightEvent'].range = 10 # Restart the machine and make sure it does nothing self.machine.start(light.Recover) self.assertCurrentMotion(type(None)) self.assertAlmostEqual(self.controller.getSpeed(), 0, 5) self.assertAlmostEqual(self.controller.getSidewaysSpeed(), 0, 5) self.assertAlmostEqual(0, self.controller.yawChange, 5) # Now stop the machine and give it a valid value self.machine.stop() self.ai.data['lastLightEvent'] = vision.RedLightEvent() self.ai.data['lastLightEvent'].range = 10 # Star the machine again self.machine.start(light.Recover) self.assertCurrentMotion(motion.basic.MoveDirection) self.assertAlmostEqual(self.controller.getSpeed(), 1, 5) self.assertAlmostEqual(self.controller.getSidewaysSpeed(), 0, 5) # Test that we find it self.injectEvent(vision.EventType.LIGHT_FOUND, vision.RedLightEvent, 0, 0) self.qeventHub.publishEvents() self.assertCurrentState(light.Align)
def testTimeout(self): self.assertCurrentState(light.FindAttempt) # For Recover self.ai.data['lastLightEvent'] = vision.RedLightEvent(0, 0) self.releaseTimer(state.FindAttempt.TIMEOUT) self.assertCurrentState(light.Recover)
def testOutsideRadius(self): # Stop the machine self.machine.stop() # Set the light event to outside the radius but not in the inner range self.ai.data['lastLightEvent'] = vision.RedLightEvent(0.8, 0.8) self.ai.data['lastLightEvent'].range = 7 # Restart the machine self.machine.start(light.Recover) self.assertCurrentMotion(motion.basic.RateChangeDepth) self.assertLessThan(self.controller.yawChange, 0) # Stop the machine and set the last light event to the opposite side self.machine.stop() self.ai.data['lastLightEvent'].x = -0.8 self.ai.data['lastLightEvent'].y = 0.0 # Restart the machine self.machine.start(light.Recover) self.assertCurrentMotion(motion.basic.RateChangeDepth) self.assertGreaterThan(self.controller.yawChange, 0) # Test that we find it self.injectEvent(vision.EventType.LIGHT_FOUND, vision.RedLightEvent, 0, 0) self.qeventHub.publishEvents() self.assertCurrentState(light.Align) # Stop the state machine self.machine.stop() # Set the light event to outside the radius and outside the far range self.ai.data['lastLightEvent'] = vision.RedLightEvent(0.8, 0.8) self.ai.data['lastLightEvent'].range = 9 # Make sure this does NOTHING self.machine.start(light.Recover) self.assertCurrentMotion(type(None)) self.assertAlmostEqual(0, self.controller.speed, 5) self.assertAlmostEqual(0, self.controller.sidewaysSpeed, 5) self.assertAlmostEqual(0, self.controller.yawChange, 5)
def testLightLost(self): """Make sure losing the light goes back to search""" # Add a lastLightEvent for FindAttempt self.ai.data['lastLightEvent'] = vision.RedLightEvent() self.injectEvent(vision.EventType.LIGHT_LOST) self.assertCurrentState(light.FindAttemptSeek) # Test that it reenters Seek when it's refound self.injectEvent(vision.EventType.LIGHT_FOUND, vision.RedLightEvent, 0, 0) self.assertCurrentState(light.Seek)
def update(self, timestep): if not self._sendEvents: return self._currentTime += timestep sinVal = math.sin(self._currentTime) eventLight = vision.RedLightEvent(sinVal, sinVal) eventTarget = vision.TargetEvent(sinVal, sinVal * -1, sinVal * -2, sinVal * -3) eventBarbedWire = vision.BarbedWireEvent(sinVal, sinVal * -1, sinVal * -2, sinVal * -3, sinVal * -4, sinVal * -5) if sinVal >= 0: self.publish(vision.EventType.LIGHT_FOUND, eventLight) self.publish(vision.EventType.TARGET_LOST, eventTarget) self.publish(vision.EventType.BARBED_WIRE_FOUND, eventBarbedWire) else: self.publish(vision.EventType.LIGHT_LOST, eventLight) self.publish(vision.EventType.TARGET_FOUND, eventTarget) self.publish(vision.EventType.BARBED_WIRE_LOST, eventBarbedWire)
def setUp(self): support.AITestCase.setUp(self) self.ai.data['lastLightEvent'] = vision.RedLightEvent() self.machine.start(light.Recover)