SHARE
TWEET

Untitled

a guest Oct 23rd, 2019 87 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. """Robot finds object."""
  2.  
  3. from PiBot import PiBot
  4.  
  5. robot = PiBot()
  6.  
  7.  
  8. def wheels_speed(left, right):
  9.     """Get wheels speed."""
  10.     robot.set_left_wheel_speed(left)
  11.     robot.set_right_wheel_speed(right)
  12.  
  13.  
  14. def robot_go(sleep, left, right):
  15.     """Robot go."""
  16.     wheels_speed(left, right)
  17.     robot.sleep(sleep)
  18.  
  19.  
  20. if __name__ == '__main__':
  21.     data = []
  22.     while robot.get_rotation() <= 360:
  23.         robot_go(0.05, -10, 10)
  24.         laser = robot.get_front_middle_laser()
  25.         direction = robot.get_rotation()
  26.         data.append((direction, laser))
  27.         print(data)
  28.     wheels_speed(0, 0)
  29.    
  30.     distance = 0
  31.     difference = 0
  32.     direction = 0
  33.     for element in range(len(data) - 1):
  34.         for i in data[element]:
  35.             difference = abs(data[element][1] - data[element + 1][1])
  36.             if difference / 2 < data[element][1]:
  37.                 distance = data[element][1]
  38.                 direction = data[element][0]
  39.    
  40.     while robot.get_front_middle_laser() > distance:
  41.         robot_go(0.05, -10, 10)
  42.         print(robot.get_front_middle_laser())
  43.         print(robot.get_rotation())
  44.     wheels_speed(0, 0)
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