def handle_menu_select_item(self, item): if item is None: return if isinstance(item, type) and issubclass(item, mode.Mode): start_task(self.enter_mode(item)) else: item()
def handle_event(self, event): if super().handle_event(event): return True if isinstance(event, messages.ControllerButtonMessage): if event.button == "l2": start_task(self.turn(-90)) return True elif event.button == "r2": start_task(self.turn(90)) return True return False
async def fire(self): self.angle = self.shooter.barrel.get_angle() self.aimable = False self.shooter.pump.on() self.shooter.pointer.off() # FIXME create firing solution here and implement it while True: await asyncio.sleep(0.1) if self.shooter.pressure.get_pressure() > 108000: start_task(self.load()) break
async def run(self): start_task(super().run()) self.set_state(self.off) while True: if self.joystick and self.joystick.connected: if self.aimable: y = self.joystick['ry'] if y != 0.0: self.angle += y * 20.0 print("Angle = ", self.angle) self.shooter.barrel.set_pos(self.angle) await asyncio.sleep(0.1)
def set_state(self, state): name = state.__name__.capitalize() print("Setting state to ", name) self.display.draw_text(name) if self.state_task is not None: self.state_task.cancel() self.state = state self.state_task = start_task(state())
def on_start(self): super().on_start() self.colour = Colours() self.current_col = [-10, 80, 30], [10, 255, 255] self.limits = { MIN_HUE: (-40, 180), MAX_HUE: (-40, 180), MIN_SAT: (0, 255), MIN_VAL: (0, 255) } self.mode = MIN_HUE self.image_shower = util.start_task(self.show_image())
def __init__(self, joystick, hardware): self.joystick = joystick self.drive = None self.display = None self.camera = None self.pixels = None self.grabber = None self.shooter = None self.stabber = None self.laser = None for item in self.HARDWARE: if getattr(hardware, item) is None: raise HardwareNotFoundError(item) setattr(self, item, getattr(hardware, item)) self.on_start() self.task = start_task(self.run())
async def aim(self): angle_task = start_task( asyncio.wait_for( self.shooter.barrel.set_angle(self.angle), 2.0)) while True: await asyncio.sleep(0.1) if self.shooter.pressure.get_pressure() > 105000: self.shooter.pump.on() else: self.shooter.pump.off() if angle_task and angle_task.done(): try: angle_task.result() except asyncio.TimeoutError: pass self.shooter.pointer.on() self.aimable = True self.angle = self.shooter.barrel.get_pos() angle_task = None
def __init__(self, event_queue): self.event_queue = event_queue start_task(self.monitor())