SHARE
TWEET

Untitled

a guest Nov 13th, 2019 94 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. """I hate robots."""
  2. from PiBot import PiBot
  3.  
  4. robot = PiBot()
  5.  
  6.  
  7. def find_object():
  8.     """Find object pls work."""
  9.     front = robot.get_front_left_laser()
  10.     action = 0
  11.     print(front)
  12.     while True:
  13.         if action == 0:
  14.             left_middle_front = robot.get_front_middle_laser()
  15.             robot.set_left_wheel_speed(8)
  16.             robot.set_right_wheel_speed(-8)
  17.             robot.sleep(0.07)
  18.  
  19.             left_middle_front1 = robot.get_front_middle_laser()
  20.  
  21.             print(f"Lasers: {robot.get_front_lasers()}")
  22.  
  23.             difference = 0
  24.             if left_middle_front < 2.0 or left_middle_front1 < 2.0:
  25.                 difference = left_middle_front - left_middle_front1
  26.                 print(difference)
  27.  
  28.             if abs(difference) > 0.21:
  29.                 robot.set_wheels_speed(0)
  30.                 robot.sleep(1)
  31.                 # action = 1
  32.                 print("Here you are!")
  33.                 return move_by_encoders()
  34.  
  35.  
  36. def move_by_encoders():
  37.     """Move by encoders."""
  38.     robot.set_wheels_speed(0)
  39.     robot.sleep(1)
  40.     encoders = [abs(robot.get_right_wheel_encoder()), abs(robot.get_left_wheel_encoder())]
  41.  
  42.     print(f"Right encoder: {robot.get_right_wheel_encoder()}")
  43.     print(f"Left encoder: {robot.get_left_wheel_encoder()}")
  44.  
  45.     if encoders[0] > encoders[1]:
  46.         print("Right encoder has bigger value.")
  47.         while abs(robot.get_right_wheel_encoder()) != abs(robot.get_left_wheel_encoder()):
  48.             print(abs(robot.get_right_wheel_encoder()), abs(robot.get_left_wheel_encoder()))
  49.             robot.set_right_wheel_speed(8)
  50.             robot.sleep(0.05)
  51.  
  52.     elif encoders[0] < encoders[1]:
  53.         print("Left encoder has bigger value.")
  54.         while abs(robot.get_right_wheel_encoder()) != abs(robot.get_left_wheel_encoder()):
  55.             print(abs(robot.get_right_wheel_encoder()), abs(robot.get_left_wheel_encoder()))
  56.             robot.set_left_wheel_speed(-8)
  57.             robot.sleep(0.05)
  58.  
  59.         print("All good.")
  60.         print(abs(robot.get_right_wheel_encoder()), abs(robot.get_left_wheel_encoder()))
  61.         robot.set_wheels_speed(0)
  62.     robot.get_front_middle_laser()
  63.     stop = robot.get_front_middle_laser()
  64.     if stop > 0.09:
  65.         while not 0.105 > stop > 0.09:
  66.             robot.get_front_middle_laser()
  67.             stop = robot.get_front_middle_laser()
  68.             print(stop)
  69.             robot.set_left_wheel_speed(9)
  70.             robot.set_right_wheel_speed(9)
  71.             robot.sleep(0.1)
  72.  
  73.     robot.set_wheels_speed(0)
  74.     return False
  75.  
  76.  
  77. if __name__ == '__main__':
  78.     find_object()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top