Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. """Joonejärgija."""
  2. from PiBot import PiBot
  3. from math import pi
  4. robot = PiBot()
  5.  
  6.  
  7. speed = 13
  8. sleep = 0.05
  9. robot.set_grabber_height(100)
  10. wheel_d = robot.WHEEL_DIAMETER
  11. robot_d = robot.AXIS_LENGTH
  12.  
  13.  
  14. """
  15. get_front_left_laser()
  16. get_front_middle_laser()
  17. get_front_right_laser()
  18. get_front_lasers()
  19. """
  20.  
  21.  
  22. def left():
  23. print("left")
  24. global speed
  25. """Robot spins/ turns left."""
  26. robot.set_left_wheel_speed(0)
  27. robot.set_right_wheel_speed(speed)
  28. robot.sleep(sleep)
  29.  
  30.  
  31. def right():
  32. print("right")
  33. global speed
  34. """Robot spins/ turns right."""
  35. robot.set_right_wheel_speed(0)
  36. robot.set_left_wheel_speed(speed)
  37. robot.sleep(sleep)
  38.  
  39.  
  40. def straight():
  41. print("straight")
  42. """Robot moves straight."""
  43. robot.set_wheels_speed(speed)
  44.  
  45.  
  46. def find_encoder(wheel_d, robot_d):
  47. return 360 * ((pi * wheel_d) / (2 * pi * robot_d))
  48.  
  49.  
  50. def find_closest():
  51. encoder = find_encoder()
  52.  
  53.  
  54. def find_object():
  55. print("finding")
  56. """Robot spins until finds object."""
  57. while robot.get_front_middle_laser() > 0.1 and robot.get_front_left_laser() < 2 and robot.get_front_right_laser() < 2:
  58. print("doing stuff")
  59. left()
  60.  
  61.  
  62. def moves_to_object():
  63. """Robot goes to object and corrects itself."""
  64. print("moving")
  65. while robot.get_front_left_laser() == robot.get_front_right_laser():
  66. straight()
  67. while robot.get_front_left_laser() < robot.get_front_right_laser():
  68. left()
  69. while robot.get_front_left_laser() > robot.get_front_right_laser():
  70. right()
  71.  
  72.  
  73. while True:
  74. print("start")
  75. while robot.get_front_middle_laser() > 0.1 and robot.get_front_left_laser() < 2 and robot.get_front_right_laser() < 2:
  76. print("läks kuskile")
  77. moves_to_object()
  78. robot.set_wheels_speed(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement