def freightMode(self): if self.mode.name != "SPAWN" and self.mode.name != "GUIDE": if self.mode.name != "FREIGHT": if self.mode.time is not None: dt = self.mode.time - self.modeTimer self.modeStack.push(Mode(name=self.mode.name, time=dt)) else: self.modeStack.push(Mode(name=self.mode.name)) self.mode = Mode("FREIGHT", time=7, speedMult=0.5) self.modeTimer = 0 else: self.mode = Mode("FREIGHT", time=7, speedMult=0.5) self.modeTimer = 0 self.reverseDirection()
def freight_mode(self): if self.mode.name != "SPAWN": if self.mode.name != "FREIGHT": if self.mode.time is not None: dt = self.mode.time - self.modeTimer self.modeStack.push(Mode(name=self.mode.name, time=dt)) else: self.modeStack.push(Mode(name=self.mode.name)) self.mode = Mode("FREIGHT", time=7, speedmult=0.5) self.modeTimer = 0 self.animateName = "freight" self.animate.set_animation(self.animateName, 0) else: self.mode = Mode("FREIGHT", time=7, speedmult=0.5) self.modeTimer = 0
def freightMode(self): if self.released: #self.reverseDirection()####### #print("FREIGHT")######### if self.mode.name != "SPAWN": if self.mode.name != "FREIGHT": #In SCATTER, CHASE, or GUIDE if self.mode.name != "GUIDE": self.reverseDirection() if self.mode.time is not None: dt = self.mode.time - self.modeTimer self.modeStack.push(Mode(name=self.mode.name, time=dt)) else: self.modeStack.push(Mode(name=self.mode.name)) self.mode = Mode("FREIGHT", time=7, speedMult=0.5) self.modeTimer = 0 else: #already in FREIGHT mode, so just reset the mode self.mode = Mode("FREIGHT", time=7, speedMult=0.5) self.modeTimer = 0
def setupModeStack(self): modes = Stack() modes.push(Mode(name="CHASE")) modes.push(Mode(name="SCATTER", time=5)) modes.push(Mode(name="CHASE", time=20)) modes.push(Mode(name="SCATTER", time=7)) modes.push(Mode(name="CHASE", time=20)) modes.push(Mode(name="SCATTER", time=7)) modes.push(Mode(name="CHASE", time=20)) modes.push(Mode(name="SCATTER", time=7)) return modes
def test_teturs_true_if_method_returns_merged_list_of_announcements(self): #ARRANGE team = Team("Elephant", "Tony", "Tanya") hand_one = [Card(7, 1), Card(8, 1), Card(9, 1), Card(10, 2), Card(11, 3), Card(12, 4), Card(13, 4)] hand_two = [Card(7, 2), Card(8, 2), Card(9, 3), Card(10, 3), Card(11, 3), Card(12, 3), Card(13, 3)] mode = Mode(4) #ACT result = [str(x) for x in team.announce(mode, hand_one, hand_two)] #ASSERT self.assertEqual(result, ["belote", "tierce from 7", "quinte from 9"])
def move_by_self(self): if self.overshot_target(): self.node = self.target self.portal() valid_directions = self.get_valid_directions() self.direction = self.get_closest_direction(valid_directions) self.target = self.node.neighbors[self.direction] self.set_position() if self.mode.name == "SPAWN": if self.position == self.goal: # self.mode = self.modeStack.pop() self.mode = Mode("GUIDE", speedmult=0.2) if self.mode.name == "GUIDE": if self.guide.is_empty(): self.mode = self.modeStack.pop() self.set_guide_stack() self.started = True else: self.direction = self.guide.pop() self.target = self.node.neighbors[self.direction] self.set_position()
def getPacemakerMode(self): if self._startSerial(): code = -1 params = {} binary = b"\x16\x22" + b"\x00" * (calcsize(self.dataBuffer) + 1) ser.write(binary) sleep(0.1) buffer = '=' + UINT_8 + DOUBLE + \ DOUBLE + UINT_16 + SINGLE + UINT_8 + self.dataBuffer[1:] data = ser.read(calcsize(buffer)) if data: data = unpack(buffer, data)[5:] code, data = data[0], data[1:] params.update(ranges) for p in params: params[p], data = data[0], data[1:] mode = Mode('current', code, params) self._endSerial() return mode self._endSerial() return 0
def moveBySelf(self): if self.overshotTarget(): self.node = self.target self.portal() validDirections = self.getValidDirections() self.direction = self.getClosestDirection(validDirections) self.target = self.node.neighbors[self.direction] self.setPosition() if self.mode.name == "SPAWN": if self.node.homeEntrance: print("GOING TOWARDS MY HOMIE") if self.position == self.goal: self.mode = Mode("GUIDE", speedMult=0.5) if self.mode.name == "GUIDE": if self.guide.isEmpty(): self.mode = self.modeStack.pop() self.setGuideStack() self.free = True else: self.direction = self.guide.pop() self.target = self.node.neighbors[self.direction] self.setPosition()
def spawnMode(self, speed=1): self.mode = Mode("SPAWN", speedMult=speed) self.modeTimer = 0 for d in self.guide: self.modeStack.push(Mode("GUIDE", speedMult=0.5, direction=d))
def spawn_mode(self): self.mode = Mode("SPAWN", speedmult=2) self.modeTimer = 0 self.set_spawn_images()
class VoiceAssistant: def __init__(self): print("Initialising") if len(sys.argv) > 1: os.system("sudo /home/pi/PiBits/ServoBlaster/user/./servod") os.system("sudo pigpiod") def speak(self,m): os.system("espeak -s 135 -v en -p 50 '" + str(m) + "' --stdout | aplay -c1 -D plughw:1,0") #os.system("espeak -s 135 -v en -p 50 '" + str('hi') + "'") def welcome(self): hour = datetime.now().hour if(hour < 12): self.speak("Good morning, how can I help?") if(hour < 16 & hour > 12): self.speak("Good afternoon, how can I help?") if (hour >= 16): self.speak("Good evening, how can I help?") def process_event(self,event): """Pretty prints events. Prints all events that occur with two spaces between each new conversation and a single space between turns of a conversation. Args: event(event.Event): The current event to process. """ if event.type == EventType.ON_CONVERSATION_TURN_STARTED: print() if event.type == EventType.ON_RESPONDING_STARTED or EventType.ON_RESPONDING_FINISHED: print(event.type) if (event.type == EventType.ON_RECOGNIZING_SPEECH_FINISHED and event.args): c = event.args['text'] self.actions.checkCommand(c, "goog") if (event.type == EventType.ON_RENDER_RESPONSE and event.args): resp = event.args['text'] #try: #self.speak(resp) #except: #self.speak('Sorry, there was an error') if (event.type == EventType.ON_CONVERSATION_TURN_FINISHED and event.args and not event.args['with_follow_on_turn']): print() if event.type == EventType.ON_DEVICE_ACTION: for command, params in event.actions: print('Do command', command, 'with params', str(params)) def main(self): parser = argparse.ArgumentParser( formatter_class=argparse.RawTextHelpFormatter) parser.add_argument('--device-model-id', '--device_model_id', type=str, metavar='DEVICE_MODEL_ID',default="abcdefghi", required=False, help='the device model ID registered with Google') parser.add_argument('--project-id', '--project_id', type=str, metavar='PROJECT_ID',default="finalassistant", required=False, help='the project ID used to register this device') parser.add_argument('--device-config', type=str, metavar='DEVICE_CONFIG_FILE', default=os.path.join( os.path.expanduser('~/.config'), 'googlesamples-assistant', 'device_config_library.json' ), help='path to store and read device configuration') parser.add_argument('--credentials', type=existing_file, metavar='OAUTH2_CREDENTIALS_FILE', default=os.path.join( os.path.expanduser('~/.config'), 'google-oauthlib-tool', 'credentials.json' ), help='path to store and read OAuth2 credentials') parser.add_argument('-v', '--version', action='version', version='%(prog)s ' + Assistant.__version_str__()) parser.add_argument('-x','--abcd') args = parser.parse_args() with open(args.credentials, 'r') as f: credentials = google.oauth2.credentials.Credentials(token=None, **json.load(f)) device_model_id = None last_device_id = None try: with open(args.device_config) as f: device_config = json.load(f) device_model_id = device_config['model_id'] last_device_id = device_config.get('last_device_id', None) except FileNotFoundError: pass if not args.device_model_id and not device_model_id: raise Exception('Missing --device-model-id option') # Re-register if "device_model_id" is given by the user and it differs # from what we previously registered with. should_register = ( args.device_model_id and args.device_model_id != device_model_id) device_model_id = args.device_model_id or device_model_id with Assistant(credentials, device_model_id) as assistant: self.assistant = assistant self.actions = Actions(self.assistant) events = self.assistant.start() device_id = assistant.device_id print('device_model_id:', device_model_id) print('device_id:', device_id + '\n') # Re-register if "device_id" is different from the last "device_id": if should_register or (device_id != last_device_id): if args.project_id: register_device(args.project_id, credentials, device_model_id, device_id) pathlib.Path(os.path.dirname(args.device_config)).mkdir( exist_ok=True) with open(args.device_config, 'w') as f: json.dump({ 'last_device_id': device_id, 'model_id': device_model_id, }, f) else: print(WARNING_NOT_REGISTERED) self.m = Mode(self) #x = threading.Thread(target=m.start) #x.daemon = True #x.start() for event in events: self.process_event(event) self.m.changeVoiceMode(event)
def main(self): parser = argparse.ArgumentParser( formatter_class=argparse.RawTextHelpFormatter) parser.add_argument('--device-model-id', '--device_model_id', type=str, metavar='DEVICE_MODEL_ID',default="abcdefghi", required=False, help='the device model ID registered with Google') parser.add_argument('--project-id', '--project_id', type=str, metavar='PROJECT_ID',default="finalassistant", required=False, help='the project ID used to register this device') parser.add_argument('--device-config', type=str, metavar='DEVICE_CONFIG_FILE', default=os.path.join( os.path.expanduser('~/.config'), 'googlesamples-assistant', 'device_config_library.json' ), help='path to store and read device configuration') parser.add_argument('--credentials', type=existing_file, metavar='OAUTH2_CREDENTIALS_FILE', default=os.path.join( os.path.expanduser('~/.config'), 'google-oauthlib-tool', 'credentials.json' ), help='path to store and read OAuth2 credentials') parser.add_argument('-v', '--version', action='version', version='%(prog)s ' + Assistant.__version_str__()) parser.add_argument('-x','--abcd') args = parser.parse_args() with open(args.credentials, 'r') as f: credentials = google.oauth2.credentials.Credentials(token=None, **json.load(f)) device_model_id = None last_device_id = None try: with open(args.device_config) as f: device_config = json.load(f) device_model_id = device_config['model_id'] last_device_id = device_config.get('last_device_id', None) except FileNotFoundError: pass if not args.device_model_id and not device_model_id: raise Exception('Missing --device-model-id option') # Re-register if "device_model_id" is given by the user and it differs # from what we previously registered with. should_register = ( args.device_model_id and args.device_model_id != device_model_id) device_model_id = args.device_model_id or device_model_id with Assistant(credentials, device_model_id) as assistant: self.assistant = assistant self.actions = Actions(self.assistant) events = self.assistant.start() device_id = assistant.device_id print('device_model_id:', device_model_id) print('device_id:', device_id + '\n') # Re-register if "device_id" is different from the last "device_id": if should_register or (device_id != last_device_id): if args.project_id: register_device(args.project_id, credentials, device_model_id, device_id) pathlib.Path(os.path.dirname(args.device_config)).mkdir( exist_ok=True) with open(args.device_config, 'w') as f: json.dump({ 'last_device_id': device_id, 'model_id': device_model_id, }, f) else: print(WARNING_NOT_REGISTERED) self.m = Mode(self) #x = threading.Thread(target=m.start) #x.daemon = True #x.start() for event in events: self.process_event(event) self.m.changeVoiceMode(event)
def spawnMode(self): self.mode = Mode("SPAWN", speedMult=2) self.modeTimer = 0