コード例 #1
0
ファイル: test.py プロジェクト: rdspring1/comp551
def light_diff():
    # student code start
    light_fl = rone.light_sensor_get_value('fl')
    light_fr = rone.light_sensor_get_value('fr')
    diff = light_fl - light_fr
    # student code end
    return diff
コード例 #2
0
ファイル: winter.py プロジェクト: va17/THBCP
def self_in_light():
    any_in_light = False
    for sensor_dir in BRIGHTNESS_THRESHOLDS.keys():
        this_one_in_light = (rone.light_sensor_get_value(sensor_dir) >
                             BRIGHTNESS_THRESHOLDS[sensor_dir])
        any_in_light = any_in_light or this_one_in_light
    return any_in_light
コード例 #3
0
ファイル: winter.py プロジェクト: va17/THBCP
def winter():
    beh.init(0.22, 40, 0.5, 0.1)

    state = STATE_IDLE

    manual_control = False

    while True:
        # run the system updates
        new_nbrs = beh.update()

        nbr_list = neighbors.get_neighbors()

        beh_out = beh.BEH_INACTIVE

        # this is the main finite-state machine
        if state == STATE_IDLE:
            leds.set_pattern('r', 'circle', LED_BRIGHTNESS)
            if new_nbrs:
                print "idle"

            if rone.button_get_value('r'):
                ##### This is one way to find a cutoff for being in light.
                ##### Make sure you press the 'r' button when the robot is
                ##### in the light!
                global BRIGHTNESS_THRESHOLDS
                for sensor_dir in BRIGHTNESS_THRESHOLDS.keys():
                    BRIGHTNESS_THRESHOLDS[
                        sensor_dir] = 0.85 * rone.light_sensor_get_value(
                            sensor_dir)
                #####
                initial_time = sys.time()
                state = STATE_LIGHT

        elif state == STATE_LIGHT:
            leds.set_pattern('g', 'circle', LED_BRIGHTNESS)
            if manual_control:
                leds.set_pattern('gr', 'group', LED_BRIGHTNESS)
            nbr_in_dark = get_nearest_nbr_in_dark(nbr_list)
            if nbr_in_dark != None:
                bearing = neighbors.get_nbr_bearing(nbr_in_dark)
                bearing = bearing - math.pi
                bearing = math2.normalize_angle(bearing)
                beh_out = move_in_dir(bearing)

            if not manual_control:
                if not self_in_light():
                    dark_start_time = sys.time()
                    state = STATE_DARK

            if rone.button_get_value('b'):
                manual_control = True
                dark_start_time = sys.time()
                state = STATE_DARK
            elif rone.button_get_value('r'):
                manual_control = False
                state = STATE_IDLE

        elif state == STATE_DARK:
            leds.set_pattern('b', 'circle', LED_BRIGHTNESS)
            if manual_control:
                leds.set_pattern('br', 'group', LED_BRIGHTNESS)
            nbrs_in_light = get_nbrs_in_light()
            nbrs_in_dark = get_nbrs_in_dark()
            if len(nbrs_in_light) > 0:
                bearing = get_avg_bearing_to_nbrs(nbrs_in_light)
                beh_out = move_in_dir(bearing)
            elif len(nbrs_in_dark) > 0:
                bearing = get_avg_bearing_to_nbrs(nbrs_in_dark)
                beh_out = move_in_dir(bearing)

            if not manual_control:
                if self_in_light():
                    state = STATE_LIGHT
                elif sys.time() - dark_start_time > LIFESPAN:
                    score_time = hba.winter_time_keeper(initial_time)
                    hba.winter_score_calc(score_time, LED_BRIGHTNESS)
                    state = STATE_DEAD
            if rone.button_get_value('g'):
                manual_control = True
                state = STATE_LIGHT
            elif rone.button_get_value('r'):
                manual_control = False
                state = STATE_IDLE

        elif state == STATE_DEAD:
            pass

        # end of the FSM

##        bump_beh_out = beh.bump_beh(MOTION_TV)
##        beh_out = beh.subsume([beh_out, bump_beh_out])

# set the beh velocities
        beh.motion_set(beh_out)

        #set the HBA message
        msg = [0, 0, 0]
        msg[MSG_IDX_STATE] = state
        hba.set_msg(msg[0], msg[1], msg[2])