Advertisement
Alekal

Untitled

Dec 6th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.42 KB | None | 0 0
  1. # import rospy
  2. # from PiBot import PiBot
  3. #
  4. # class Robot:
  5. # """
  6. # The three primitives robotic paradigm: sense, plan, act [1].
  7. # Sense - gather information using the sensors
  8. # Plan - create a world model using all the information and plan the next move
  9. # Act - carry out the next step of the plan using actuators
  10. # [1] https://en.wikipedia.org/wiki/Robotic_paradigm
  11. # """
  12. # def __init__(self):
  13. # print("Initializing...")
  14. # self.robot = PiBot()
  15. # self.start_timestamp = rospy.get_time()
  16. # self.problem_solved = False
  17. # # self.turning = True
  18. #
  19. # def sense(self):
  20. # print('Sensing...')
  21. # middle_list = []
  22. # print('left_front: ' + str(self.robot.get_front_left_ir()))
  23. # print('middle_front: ' + str(self.robot.get_front_middle_ir()))
  24. # print('right_front: ' + str(self.robot.get_front_right_ir()))
  25. # print('left_back_side: ' + str(self.robot.get_rear_left_side_ir()))
  26. # print('right_back_side: ' + str(self.robot.get_rear_right_side_ir()))
  27. # print('left_encoder: ' + str(self.robot.get_left_wheel_encoder()))
  28. # print('right_encoder: ' + str(self.robot.get_right_wheel_encoder()))
  29. # rospy.sleep(2)
  30. # middle_list.append(self.robot.get_front_middle_ir())
  31. # return middle_list
  32. #
  33. # def plan(self, middle_dict):
  34. # turn = True
  35. # print("Planning...")
  36. # if len(middle_dict) > 0:
  37. # print('Have some data in list.')
  38. # if middle_dict[0] == 1.0:
  39. # print('Think that i should turn.')
  40. # while turn is True:
  41. # print('Turning...')
  42. # self.robot.set_left_wheel_speed(15)
  43. # self.robot.set_right_wheel_speed(-15)
  44. # if self.robot.get_left_wheel_encoder() >= 1010:
  45. # turn = False
  46. # print('Should stop here.')
  47. # self.robot.set_left_wheel_speed(0)
  48. # self.robot.set_right_wheel_speed(0)
  49. # rospy.sleep(2)
  50. # return turn
  51. #
  52. # def act(self, turn):
  53. # print("Acting...")
  54. # rospy.sleep(1)
  55. # while turn is False:
  56. # print('left_front: ' + str(self.robot.get_front_left_ir()))
  57. # print('middle_front: ' + str(self.robot.get_front_middle_ir()))
  58. # print('right_front: ' + str(self.robot.get_front_right_ir()))
  59. # rospy.sleep(2)
  60. # while self.robot.get_front_left_ir() >= 0.1 and self.robot.get_front_left_ir() <= 0.2:
  61. # print('Moving near the wall.')
  62. # print(self.robot.get_front_left_ir())
  63. # self.robot.set_wheels_speed(15)
  64. # while self.robot.get_front_right_ir() < self.robot.get_front_left_ir():
  65. # print('Lost the wall, trying to correct that.')
  66. # self.robot.set_left_wheel_speed(-15)
  67. # self.robot.set_right_wheel_speed(15)
  68. #
  69. # """Should vote(maybe left one) the wall and moving near this wall. So its like LineTracker."""
  70. # # while self.robot.get_front_left_ir() == self.robot.get_front_right_ir():
  71. # # self.robot.set_wheels_speed(15)
  72. # # print('Start moving forward.')
  73. #
  74. # # self.turning = True
  75. # # while self.turning is True:
  76. # # left_encoder = self.robot.get_left_wheel_encoder()
  77. # # self.robot.set_left_wheel_speed(20)
  78. # # self.robot.set_right_wheel_speed(-20)
  79. # # sensor = self.robot.get_front_middle_ir()
  80. # # print(left_encoder)
  81. # # if left_encoder == 1010: # instead of 2020 should be perimeter of circle, but i do not know it.
  82. # # self.robot.set_left_wheel_speed(0)
  83. # # self.robot.set_right_wheel_speed(0)
  84. # # print('HAVE TURNED')
  85. # # self.turning = False
  86. # # move = True
  87. # # while move is True:
  88. # # self.robot.set_wheels_speed(15)
  89. # # print('left_front: ' + str(self.robot.get_front_left_ir()))
  90. # # print('middle_front: ' + str(self.robot.get_front_middle_ir()))
  91. # # print('right_front: ' + str(self.robot.get_front_right_ir()))
  92. # # print('left_back: ' + str(self.robot.get_rear_left_side_ir()))
  93. # # print('right_back: ' + str(self.robot.get_rear_right_side_ir()))
  94. # # rospy.sleep(0.05)
  95. # # distance_from_object = self.robot.get_front_middle_ir()
  96. # # while distance_from_object > 0.3:
  97. # # distance_from_object = self.robot.get_front_middle_ir()
  98. # # rospy.sleep(0.05)
  99. # # move = False
  100. # # turning = True
  101. # # while turning is True:
  102. # # self.robot.set_left_wheel_speed(-15)
  103. # # self.robot.set_right_wheel_speed(15)
  104. # # if self.robot.get_left_wheel_encoder() == 1008:
  105. # # self.robot.set_left_wheel_speed(0)
  106. # # self.robot.set_right_wheel_speed(0)
  107. # # print('left_front: ' + str(self.robot.get_front_left_ir()))
  108. # # print('middle_front: ' + str(self.robot.get_front_middle_ir()))
  109. # # print('right_front: ' + str(self.robot.get_front_right_ir()))
  110. # # print('left_back: ' + str(self.robot.get_rear_left_side_ir()))
  111. # # print('right_back: ' + str(self.robot.get_rear_right_side_ir()))
  112. # # turning = False
  113. # # rospy.sleep(0.5)
  114. #
  115. # # while self.robot.get_rear_right_side_ir() > self.robot.get_rear_left_side_ir():
  116. # # """Should track the left wall."""
  117. # # self.robot.set_wheels_speed(-15)
  118. # # pass
  119. # # while self.robot.get_rear_right_side_ir() < self.robot.get_rear_left_side_ir():
  120. # # """Should track the right wall."""
  121. # # self.robot.set_wheels_speed(-15)
  122. # # pass
  123. #
  124. # def main(self):
  125. # middle_list = self.sense()
  126. # turn = self.plan(middle_list)
  127. # self.act(turn)
  128. # rospy.sleep(0.05) # 20 Hz
  129. # if self.problem_solved:
  130. # print("Solved! Good job, robot!")
  131. # else:
  132. # print("Unable to solve! :(")
  133. #
  134. #
  135. # if __name__ == "__main__":
  136. # robot = Robot()
  137. # robot.main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement