Beispiel #1
0
def turn_left_until_rfcliff_senses_white(multiplier=1):
    print "Starting turn_left_until_rfcliff_senses_white"
    m.base_turn_left(multiplier)
    while BlackFrontRight():
        pass
    m.base_turn_left(multiplier)
    m.deactivate_motors()
def turn_left_until(boolean_function, should_stop=True, *, time=c.SAFETY_TIME):
    m.base_turn_left()
    sec = seconds() + time / 1000
    while seconds() < sec and not(boolean_function()):
        msleep(1)
    if should_stop:
        m.deactivate_motors()
Beispiel #3
0
def turn_left_until(boolean_function, time=c.SAFETY_TIME, should_stop=True):
    m.base_turn_left()
    if time == 0:
        should_stop = False
        time = c.SAFETY_TIME
    wait_until(boolean_function, time)
    if should_stop:
        m.deactivate_motors()
def turn_gyro(target_degrees=90, speed_multiplier=1):
    c.ROBOT_ANGLE = 0
    if target_degrees < 0:  # Left turn code is different than right turn. Positive degrees are left.
        m.base_turn_left(speed_multiplier)
        while c.ROBOT_ANGLE * c.WALLAGREES_TO_DEGREES_RATE > target_degrees:
            get_change_in_angle()
    else:
        m.base_turn_right(speed_multiplier)
        while c.ROBOT_ANGLE * c.WALLAGREES_TO_DEGREES_RATE < target_degrees:
            get_change_in_angle()
    m.deactivate_motors()
def align_on_wall_right():
    m.base_veer_right(0.5)
    wait_until(isRoombaBumped)
    m.deactivate_motors()
    u.halve_speeds()
    m.base_turn_left()
    wait_until(isRoombaNotBumped)
    m.deactivate_motors()
    msleep(100)
    g.turn_right_gyro(4)
    msleep(100)
Beispiel #6
0
def turn_gyro(degrees, time=c.SAFETY_TIME):
    angle = 0
    target_angle = degrees * c.DEGREE_CONVERSION_RATE
    if target_angle > 0:
        m.base_turn_left()
        sec = seconds() + time
        while angle < target_angle and seconds() < sec:
            msleep(10)
            angle += (gyro_z() - bias) * 10
    else:
        m.base_turn_right()
        sec = seconds() + time
        while angle > target_angle and seconds() < sec:
            msleep(10)
            angle += (gyro_z() - bias) * 10
    m.deactivate_motors()
def turn_gyro(degrees, should_stop=True):
    angle = 0
    target_angle = degrees * c.DEGREE_CONVERSION_RATE
    if target_angle > 0:
        m.base_turn_left()
        sec = seconds().time + c.SAFETY_TIME
        while angle < target_angle and seconds.time() < sec:
            msleep(10)
            angle += (get_change_in_angle() - u.gyro_bias) * 10
    else:
        m.base_turn_right()
        sec = seconds().time + c.SAFETY_TIME
        while angle > target_angle and seconds.time() < sec:
            msleep(10)
            angle += (get_change_in_angle() - u.gyro_bias) * 10
    if should_stop:
        m.deactivate_motors()
def wfollow_right_choppy_until(boolean_function, *, time=c.SAFETY_TIME):
    sec = seconds() + time / 1000
    while seconds() < sec and not(boolean_function()):
        if isRoombaBumped():
            if isLeftBumped():
                m.backwards(100)
                m.turn_left()
            else:
                if c.FIRST_BUMP == True:
                    m.deactivate_motors()
                u.halve_speeds()
                m.base_turn_left()
                c.FIRST_BUMP = False
        else:
            m.base_veer_right(0.6)
            c.FIRST_BUMP = True
        u.normalize_speeds()
        msleep(c.LFOLLOW_REFRESH_RATE)
    u.normalize_speeds()
    if should_stop:
        m.deactivate_motors()
def wfollow_right_choppy(time):
    sec = seconds() + time / 1000
    while seconds() < sec:
        if isRoombaBumped():
            if isLeftBumped():
                m.backwards(100)
                m.turn_left()
            else:
                if c.FIRST_BUMP == True:
                    m.deactivate_motors()
                u.halve_speeds()
                m.base_turn_left()
                c.FIRST_BUMP = False
        else:
            m.base_veer_right(0.6)
            c.FIRST_BUMP = True
        u.normalize_speeds()
        msleep(c.LFOLLOW_REFRESH_RATE)
    u.normalize_speeds()
    if should_stop:
        m.deactivate_motors()
def calibrate_gyro_degrees():
    print "Starting calibrate_gyro_degrees()"
    c.ROBOT_ANGLE = 0
    #s.drive_until_black()
    #s.align_close()
    sec = seconds()
    m.base_turn_left()
    while s.NotBlackFrontLeft():
        get_change_in_angle()
    while s.BlackFrontLeft():
        get_change_in_angle()
    while s.NotBlackFrontLeft():
        get_change_in_angle()
    while s.BlackFrontLeft():
        get_change_in_angle()
    while s.NotBlackFrontLeft():
        get_change_in_angle()
    c.RIGHT_TURN_TIME = int((seconds() - sec) * 1000 / 4.0) - 30
    c.LEFT_TURN_TIME = int((seconds() - sec) * 1000 / 4.0) - 30
    m.deactivate_motors()
    c.WALLAGREES_TO_DEGREES_RATE = (360.0 / c.ROBOT_ANGLE * -1) / 2
    print "Finished calibrating.\nWallagree-Degree conversion rate: " + str(
        c.WALLAGREES_TO_DEGREES_RATE)
    print "Right turn time: " + str(c.RIGHT_TURN_TIME)
Beispiel #11
0
def turn_left_until_rcliff_senses_white(multiplier=1):
    m.base_turn_left(multiplier)
    while BlackRight():
        pass
    m.deactivate_motors()
Beispiel #12
0
def turn_left_until_lcliff_senses_white(multiplier=1):
    print "Starting turn_left_until_lcliff_senses_white()"
    m.base_turn_left(multiplier)
    while BlackLeft():
        pass
    m.deactivate_motors()
Beispiel #13
0
def turn_left_until_lfcliff_senses_black(multiplier=1):
    print "Starting turn_left_until_lfcliff_senses_black"
    m.base_turn_left(multiplier)
    while NotBlackFrontLeft():
        pass
    m.deactivate_motors()