def runMission(self): """Internal function for running the mission in a separate thread""" drc = 0 speed = 100 newDrc = 0 for move in self.moves: if self.missionStopEv.is_set(): return command = move['command'] wait_time = move['delay'] # deal with the special commands if command == "LIGHTON": self.robot.setLight(1) elif command == "LIGHTOFF": self.robot.setLight(0) elif command == "S": # deal with the speed change speed = int(move['speed']) self.robot.go(speed, drc) else: newDrc = RobotHelper.getDirection(command) # Try and get the directions from the command # if we manage to parse the command, send it to the robot otherwise stop it if not newDrc == None: drc = newDrc self.robot.go(speed, drc) else: self.robot.stop() # wait while still listening for the stop event self.missionStopEv.wait(wait_time / 1000.0)
def getDirection(self, keys): """find the direction from the key configuration""" if keys == [0, 0, 0, 0]: return None direction = "" if keys[0] == 1: direction += "F" elif keys[2] == 1: direction += "B" if keys[1] == 1: direction += "L" elif keys[3] == 1: direction += "R" return RobotHelper.getDirection(direction)