Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. from PiBot import PiBot
  2. import rospy
  3.  
  4. # Create a robot instance
  5. robot = PiBot()
  6.  
  7. # Get distance from object using the front middle IR sensor
  8.  
  9. # Drive towards object
  10.  
  11. print("turning around now")
  12.  
  13. def rotate_and_search():
  14. robot.set_wheels_speed(0) #stop robot
  15. rospy.sleep(0.5)
  16. robot.set_left_wheel_speed(17)
  17. robot.set_right_wheel_speed(-17)
  18.  
  19. while True:
  20. distance_from_object = robot.get_front_middle_ir()
  21. if distance_from_object < 0.5:
  22. robot.set_wheels_speed(0)
  23. print("Object detected")
  24. return
  25.  
  26. def move_forward_to_object_and_stop():
  27. rospy.sleep(0.5)
  28. robot.set_wheels_speed(17)
  29. print('Moving forward')
  30. while True:
  31. distance_from_object = robot.get_front_middle_ir()
  32.  
  33. if distance_from_object < 0.2:
  34. print('Stopping near object.')
  35. robot.set_wheels_speed(0)
  36. return
  37.  
  38.  
  39. rotate_and_search()
  40. move_forward_to_object_and_stop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement