def left_forwards_until_lcliff_senses_black( ): # Left motor goes forwards until left cliff senses black print "Starting left_forwards_until_lcliff_senses_black()" m.av(c.LEFT_MOTOR, c.BASE_LM_POWER) while NotBlackLeft(): pass m.deactivate_motors()
def right_forwards_until_rcliff_senses_black( ): # Right motor goes forwards until left cliff senses black print "Starting right_forwards_until_rcliff_senses_black()" m.av(c.RIGHT_MOTOR, c.BASE_RM_POWER) while NotBlackRight(): pass m.deactivate_motors()
def left_backwards_until_lcliff_senses_white( ): # Left motor goes back until the left cliff senses white print "Starting left_backwards_until_lcliff_senses_white()" m.av(c.LEFT_MOTOR, -1 * c.BASE_LM_POWER) while BlackLeft(): pass m.deactivate_motors()
def right_backwards_until_rcliff_senses_white( ): # Right motor goes back until right cliff senses white print "Starting right_backwards_until_rcliff_senses_white()" m.av(c.RIGHT_MOTOR, -1 * c.BASE_RM_POWER) while BlackRight(): pass m.deactivate_motors()
def left_front_forwards_until_white( ): # Left motor goes forwards until the left front cliff senses white print "Starting left_front_forwards_until_white()" m.av(c.LEFT_MOTOR, c.BASE_LM_POWER) while BlackFrontLeft(): pass m.deactivate_motors()
def right_front_forwards_until_white( ): # Right motor goes forwards until right front cliff senses white print "Starting right_front_forwards_until_white()" m.av(c.RIGHT_MOTOR, c.BASE_RM_POWER) while BlackFrontRight(): pass m.deactivate_motors()
def left_front_backwards_until_black( ): # Left motor goes back until left front cliff senses black print "Starting left_front_backwards_until_black()" m.av(c.LEFT_MOTOR, -1 * c.BASE_LM_POWER) while NotBlackFrontLeft(): pass m.deactivate_motors()
def right_front_backwards_until_black( ): # Right motor goes back until right front cliff senses black print "Starting right_front_backwards_until_black()" m.av(c.RIGHT_MOTOR, -1 * c.BASE_RM_POWER) while NotBlackFrontRight(): pass m.deactivate_motors()
def lfollow_left_inside_line(time, refresh_rate=c.LFOLLOW_REFRESH_RATE): sec = seconds() + time while seconds() < sec: if BlackLeft(): m.av(c.LEFT_MOTOR, c.BASE_LM_POWER) else: m.av(c.RIGHT_MOTOR, c.BASE_RM_POWER) msleep(refresh_rate) deactivate_motors()
def lfollow_choppy(self, time, mode=c.STANDARD, should_stop=True): sec = seconds() + time / 1000 while seconds() < sec: if self.senses_black(): m.av(c.RIGHT_MOTOR, c.BASE_RM_POWER * self.side * mode) elif self.senses_white(): m.av(c.LEFT_MOTOR, c.BASE_LM_POWER * self.side * mode) msleep(refresh_rate) if should_stop: m.deactivate_motors()
def lfollow_right(time, refresh_rate=c.LFOLLOW_REFRESH_RATE ): # Line follow with the right cliff for time print "Starting lfollow_right()\n" sec = seconds() + time while seconds() < sec: if BlackRight(): m.av(c.RIGHT_MOTOR, -1 * c.BASE_RM_POWER) elif not BlackRight(): m.av(c.LEFT_MOTOR, -1 * c.BASE_LM_POWER) msleep(refresh_rate) deactivate_motors()
def right_backwards_until(boolean_function, should_stop=True, *, time=c.SAFETY_TIME): # Right motor goes back until right cliff senses black m.av(c.RIGHT_MOTOR, -1 * c.BASE_RM_POWER) wait_until(boolean_function, time=time) if should_stop: m.deactivate_motors()
def left_backwards_until(boolean_function, should_stop=True, *, time=c.SAFETY_TIME): # Left motor goes backwards until left cliff senses black m.av(c.LEFT_MOTOR, -1 * c.BASE_LM_POWER) wait_until(boolean_function, time=time) if should_stop: m.deactivate_motors()