def measure():
    global blind_steps
    blind_steps = 0
    measurement = make_measurement(bot, grid, variance=1)
    particle_filter.measure(measurement, measurement_likelihood)
    ui.draw_bots(canvas, bot, particle_filter.particles)
    ui.draw_measurement(canvas, bot, measurement)
def move():
    ui.clear_measurement(canvas)
    global bot, blind_steps, should_filter_reset
    blind_steps += 1
    direction = vote()
    bot = movement_model(bot, direction, .1, 0)
    particle_filter.move(direction, movement_model)
    ui.draw_bots(canvas, bot, particle_filter.particles)
    measurement = make_measurement(bot, grid, variance=1)
    if min(measurement) <= SAFETY_BUFFER:
        instructions_text.set("I'm awfully close to a wall. Lemme reset the filter.")
        should_filter_reset = True
def on_click(event):
    location = int(event.y / 3), int(event.x / 3)
    global bot, setting_goal, plan, setting_bot, goal
    if setting_goal:
        goal = location
        setting_goal = False
        setting_bot = True
        ui.draw_goal(canvas, goal)
        instructions_text.set("Click to set bot location (hold while nav is computed)")
    elif setting_bot:
        bot = location
        setting_bot = False
        plan = nav.process_grid(goal, grid.occupancy, grid.danger, danger_weight=100)
        # grid.preprocess()
        instructions_text.set("Click the step button or press S to get started!")
        reset_filter(None)
def reset_filter(event):
    global particle_filter
    particle_filter = pf.ParticleFilter(prior_distribution, particle_count=1000)
    ui.draw_bots(canvas, bot, particle_filter.particles)
def reset_goal(event):
    ui.clear_all(canvas)
    global setting_goal, done
    done = False
    setting_goal = True
    instructions_text.set("Click to set the goal location")