def __init__(self): if arduino.get_bump()[1]: self.sign = -1 elif arduino.get_bump()[0]: self.sign = 1 else: self.sign = np.sign(arduino.get_ir()[2] - arduino.get_ir()[1]) self.midtime = time.time() + constants.herp_derp_first_time
def next(self, time_left): """Superclass method to execute appropriate event handlers and actions.""" irs = arduino.get_ir() if any(arduino.get_bump()[0:2]) or irs[1] > 1 or irs[2] > 1: return self.on_block() elif any(arduino.get_bump()[2:4]) or irs[0] > 1 or irs[3] > 1: return self.on_stuck() elif time_left < constants.dump_time and kinect.yellow_walls: return self.on_yellow() elif (time_left >= constants.dump_time and kinect.balls and not variables.ignore_balls and not variables.ignore_balls_until_yellow): return self.on_ball() return self.default_action()
def __init__(self): variables.ball_attempts += 1 triggered_bump = np.where(arduino.get_bump())[0] triggered_ir = np.where(np.array(arduino.get_ir()) > constants.ir_stuck_threshold)[0] if (np.random.rand() < constants.probability_to_use_bump or not len(triggered_ir)) and len(triggered_bump): # only bump sensors are triggered, or both types are triggered and we randomly chose to look at bump choice = random.choice(triggered_bump) self.trigger_released = lambda: (not arduino.get_bump()[choice]) self.escape_angle = constants.bump_sensor_angles[choice] # randomly pick a triggered bump sensor elif len(triggered_ir): # only IR senors are triggered, or both types are triggered and we randomly chose to look at IR choice = random.choice(triggered_ir) self.trigger_released = lambda: (arduino.get_ir()[choice] < constants.ir_unstuck_threshold) self.escape_angle = constants.ir_sensor_angles[choice] # randomly pick a triggered IR sensor else: self.escape_angle = None # oops, not good style if self.escape_angle is not None: self.escape_angle += random.triangular(-constants.unstick_angle_offset_range, constants.unstick_angle_offset_range) # add some randomness self.unstick_complete = False self.stop_time = time.time() + constants.unstick_wiggle_period
def on_stuck(self): if ((time.time() - self.time_last_unstuck > constants.wall_stuck_timeout) or any(arduino.get_bump()[2:4])): # if this was called by an IR, require stricter conditions return maneuvering.Unstick() return self.follow()
def on_block(self): # ignore front top right bump sensor if arduino.get_bump()[1]: return maneuvering.HerpDerp() return self.follow()