class SensorListener(Thread): def __init__(self, sensors, timestep=0.1, threshold=300): Thread.__init__(self) self.daemon = True self.signal = Signal() self.getter = sensors.obstacle self.timestep = timestep self.stop = Event() self.threshold = threshold self.error = 0 self.start() self.run_event = Event() self.run_event.set() def enable(self): self.run_event.set() def disable(self): self.run_event.clear() def get_dist(self): return self.getter(self.threshold) def run(self): while not self.stop.is_set(): time.sleep(self.timestep) if not self.run_event.is_set(): self.run_event.wait() try: obstacle = self.getter(self.threshold) except TimeoutError: continue if obstacle: self.signal.ping()
def __init__(self, front_getter, left_getter, right_getter, timestep=0.1, threshold=220): Thread.__init__(self) self.daemon = True # Sensors list self.sensors_list = [self.LEFT, self.FRONT, self.RIGHT] # Signals for each sensors self.__setattr__("signal" + str(self.FRONT), Signal()) self.__setattr__("signal" + str(self.LEFT), Signal()) self.__setattr__("signal" + str(self.RIGHT), Signal()) # Sensors getter self.__setattr__("getter" + str(self.FRONT), front_getter) self.__setattr__("getter" + str(self.LEFT), left_getter) self.__setattr__("getter" + str(self.RIGHT), left_getter) # Timestep self.timestep = timestep # Stopping event self.stop = Event() # Position threshold self.threshold = threshold # Atomatically start self.start()
def __init__(self, getter, timestep=0.1, threshold=220): Thread.__init__(self) self.daemon = True self.signal = Signal() self.getter = getter self.timestep = timestep self.stop = Event() self.threshold = threshold self.error = 0 self.start()
def __init__(self, getter, timestep=0.1, threshold=10): Thread.__init__(self) self.signal = Signal() self.getter = getter self.timestep = timestep self.stop = Event() self.threshold = threshold self.error = 0 self.position = (-1000, -1000) # self.getter() self.start()
def __init__(self, sensors, timestep=0.1, threshold=300): Thread.__init__(self) self.daemon = True self.signal = Signal() self.getter = sensors.obstacle self.timestep = timestep self.stop = Event() self.threshold = threshold self.error = 0 self.start() self.run_event = Event() self.run_event.set()
class SensorListener(Thread): def __init__(self, getter, timestep=0.1, threshold=220): Thread.__init__(self) self.daemon = True self.signal = Signal() self.getter = getter self.timestep = timestep self.stop = Event() self.threshold = threshold self.error = 0 self.start() def run(self): while not self.stop.is_set(): sleep(self.timestep) try: left, right = self.getter() except TimeoutError: continue if left < self.threshold or right < self.threshold: self.signal.ping()
def __init__(self, brother_getter, opponents_getter, timestep=0.5, threshold=10): Thread.__init__(self) self.daemon = True # Robots list self.robots_list = [self.BROTHER, self.OPPONENTA, self.OPPONENTB] # Signals for each robots self.__setattr__("signal"+str(self.BROTHER), Signal()) self.__setattr__("signal"+str(self.OPPONENTA), Signal()) self.__setattr__("signal"+str(self.OPPONENTB), Signal()) # Brother and opponents getter self.__setattr__("getter"+str(self.BROTHER), brother_getter) self.__setattr__("getter"+str(self.OPPONENTA), lambda: opponents_getter()[0]) self.__setattr__("getter"+str(self.OPPONENTB), lambda: opponents_getter()[1]) self.__setattr__("position"+str(self.BROTHER), (-1000, -1000)) self.__setattr__("position"+str(self.OPPONENTA), (-1000, -1000)) self.__setattr__("position"+str(self.OPPONENTB), (-1000, -1000)) # Timestep self.timestep = timestep # Stopping event self.stop = Event() # Position threshold self.threshold = threshold # Position error self.error = 0 self.pos = (-1000, -1000) # Atomatically start self.start()
class PositionListener(Thread): def __init__(self, getter, timestep=0.1, threshold=10): Thread.__init__(self) self.signal = Signal() self.getter = getter self.timestep = timestep self.stop = Event() self.threshold = threshold self.error = 0 self.position = (-1000, -1000) # self.getter() self.start() def run(self): while not self.stop.is_set(): sleep(self.timestep) x, y = self.getter() if (hypot(y - self.position[1], x - self.position[0]) + self.error) > self.threshold: self.signal.ping() self.error = 0 else: self.error += hypot(y - self.position[1], x - self.position[0]) self.position = (x, y)
def __init__(self, match_time=100, timestep=0.1): Thread.__init__(self) self.daemon = True # End Game action list self.end_game_action_list = [ self.END_GAME_ACTION, self.FUNNY_ACTION, self.HARBOUR_ACTION ] for action in self.end_game_action_list: self.__setattr__("signal" + str(action), Signal()) self.__setattr__("timeout" + str(action), match_time) self.__setattr__("event" + str(action), Event()) # Timestep self.timestep = timestep # Stopping eventc self.stop = Event()