def turn_right_until(boolean_function, should_stop=True, *, time=c.SAFETY_TIME): m.base_turn_right() sec = seconds() + time / 1000 while seconds() < sec and not(boolean_function()): msleep(1) if should_stop: m.deactivate_motors()
def turn_right_until(boolean_function, time=c.SAFETY_TIME, should_stop=True): m.base_turn_right() 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_left(): m.base_veer_left(0.5) wait_until(isRoombaBumped) m.deactivate_motors() u.halve_speeds() m.base_turn_right() wait_until(isRoombaNotBumped) m.deactivate_motors() msleep(100) g.turn_left_gyro(4) msleep(100)
def calibrate_gyro_degrees_hard_coded(): print "Starting calibrate_gyro_degrees_hard_coded()" i = 0 #s.drive_until_black() #s.align_close() m.base_turn_right() sec = seconds() + 4 * c.RIGHT_TURN_TIME / 1000.0 while seconds() < sec: get_change_in_angle() m.deactivate_motors() c.WALLAGREES_TO_DEGREES_RATE = 360.0 / c.ROBOT_ANGLE print "Wallagree-Degree conversion rate: " + str( c.WALLAGREES_TO_DEGREES_RATE)
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 calibrate_gyro_degrees_right(): c.ROBOT_ANGLE = 0 #s.drive_until_black() #s.align_close() m.base_turn_right() while s.NotBlackFrontRight(): get_change_in_angle() while s.BlackFrontRight(): get_change_in_angle() while s.NotBlackFrontRight(): get_change_in_angle() while s.BlackFrontRight(): get_change_in_angle() while s.NotBlackFrontRight(): get_change_in_angle() m.deactivate_motors() c.WALLAGREES_TO_DEGREES_RATE = (360.0 / c.ROBOT_ANGLE) * 2 print "Wallagree-Degree conversion rate: " + str( c.WALLAGREES_TO_DEGREES_RATE)
def wfollow_left_choppy_until(boolean_function, *, time=c.SAFETY_TIME): sec = seconds() + time / 1000 while seconds() < sec and not(boolean_function()): if isRoombaBumped(): if isRightBumped(): m.backwards(100) m.turn_right() else: if c.FIRST_BUMP == True: m.deactivate_motors() u.halve_speeds() m.base_turn_right() c.FIRST_BUMP = False msleep(50) else: m.base_veer_left(0.6) c.FIRST_BUMP = True u.normalize_speeds() msleep(c.LFOLLOW_REFRESH_RATE) u.normalize_speeds() if should_stop: m.deactivate_motors()
def turn_right_until_rfcliff_senses_white(multiplier=1): print "Starting turn_right_until_rfcliff_senses_white" m.base_turn_right(multiplier) while BlackFrontRight(): pass m.deactivate_motors()
def turn_right_until_rcliff_senses_white(multiplier=1): m.base_turn_right(multiplier) while BlackRight(): pass m.deactivate_motors()
def turn_right_until_lfcliff_senses_black(multiplier=1): print "Starting turn_right_until_lfcliff_senses_black" m.base_turn_right(multiplier) while NotBlackFrontLeft(): pass m.deactivate_motors()