Advertisement
Guest User

Untitled

a guest
Nov 16th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. """Objects bronze."""
  2. import math
  3.  
  4. import rospy
  5. from PiBot import PiBot
  6.  
  7. robot = PiBot()
  8.  
  9. ROBOT_DIAMETER = 0.14
  10. WHEEL_DIAMETER = 0.025
  11.  
  12. TURNING_CONSTANT = 1
  13.  
  14.  
  15. def turn(degrees):
  16. """Turn left [degrees] degrees on spot."""
  17. # degrees %= 360
  18. wheel_rotation = ROBOT_DIAMETER * math.pi / (WHEEL_DIAMETER * math.pi) * TURNING_CONSTANT * degrees
  19. left_enc = robot.get_left_wheel_encoder() + wheel_rotation
  20. right_enc = robot.get_right_wheel_encoder() - wheel_rotation
  21. robot.set_left_wheel_speed(20)
  22. robot.set_right_wheel_speed(-20)
  23. while robot.get_left_wheel_encoder() < left_enc or robot.get_right_wheel_encoder() > right_enc:
  24. rospy.sleep(0.01)
  25. robot.set_wheels_speed(0)
  26.  
  27.  
  28. def go_meters_before_object(distance, front_or_back):
  29. """Go straight until you're [distance] meters away from object."""
  30. distance_with_front = robot.get_front_middle_ir()
  31. distance_with_rear = robot.get_rear_right_straight_ir()
  32.  
  33. robot.set_wheels_speed(25)
  34. if front_or_back == 'front':
  35. while distance_with_front > distance:
  36. distance_with_front = robot.get_front_middle_ir()
  37. print(distance_with_front)
  38. rospy.sleep(0.01)
  39. if front_or_back == 'back':
  40. while distance_with_rear > distance:
  41. distance_with_rear = robot.get_rear_right_straight_ir()
  42. print(distance_with_rear)
  43. rospy.sleep(0.01)
  44.  
  45. robot.set_wheels_speed(0)
  46.  
  47.  
  48. def mdea():
  49. """
  50. 340 deg/s with speed 15
  51. 3.4 deg/0.01s
  52. """
  53.  
  54.  
  55.  
  56. def scan():
  57. objects = []
  58. a = robot.get_front_middle_ir()
  59. while turn(360):
  60. objects.append(a)
  61. rospy.sleep(0.01)
  62. print(objects)
  63.  
  64.  
  65. if __name__ == '__main__':
  66. mdea()
  67. print("finished")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement