Advertisement
Guest User

avoid

a guest
Mar 24th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. enum avoidance_enum {
  2. normal, check1, turn_clockwise, turn_anticlockwise_segment_one, turn_anticlockwise_segment_two, check2, turn_anticlockwise_segment_three
  3. };
  4.  
  5.  
  6. void carAvoidance(double function_RPM, double short_distance)
  7. {
  8. switch (avoidance_state)
  9. {
  10. case normal:
  11. target_RPM = function_RPM;
  12. driveStraight();
  13. avoidance_state = check;
  14. break;
  15. case check1: //Check from going forward
  16. //distance = ultra.current_distance();
  17. rotated = false;
  18. if (short_distance <= curent_distance)
  19. {
  20. avoidance_state = turn_clockwise;
  21. }
  22. else
  23. {
  24. avoidance_state = normal;
  25. }
  26. break;
  27. case turn_clockwise:
  28. turn(0);
  29. if (rotated)
  30. {
  31. avoidance_state = check1;
  32. }
  33. case turn_anticlockwise_segment_one:
  34. turn(1);
  35. if (rotated)
  36. {
  37. avoidance_state = turn_anticlockwise_segment_two;
  38. rotated = false;
  39. }
  40. case turn_anticlockwise_segment_two:
  41. turn(1);
  42. if (rotated)
  43. {
  44. avoidance_state = check2;
  45. }
  46.  
  47. case check2: //check from going clockwise
  48. rotated = false;
  49. if (short_distance <= curent_distance)
  50. {
  51. avoidance_state = turn_anticlockwise_segment_three;
  52. }
  53. else
  54. {
  55. avoidance_state = normal;
  56. }
  57. break;
  58. case turn_anticlockwise_segment_three:
  59. turn(1);
  60. if (rotated)
  61. {
  62. avoidance_state = normal;
  63. }
  64.  
  65.  
  66. }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement