Advertisement
Guest User

robot code

a guest
Jan 16th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. // Global Variables //
  2. bool obstacle_found = false;
  3. const int color_breakpoint = 20;
  4. int LightInt; // Used to display and keep track of the color detected by the sensor
  5.  
  6. // Functions //
  7. void set_drive_speed(int left_speed, int right_speed) // Sets the speed of the car based on user input
  8. {
  9. setMotorSpeed(left_motor, left_speed);
  10. setMotorSpeed(right_motor, right_speed);
  11. }
  12. void display_light_value() //displays colour value on brick screen
  13. {
  14. LightInt = getColorReflected(color_sensor);
  15. displayCenteredBigTextLine(4, "%d", LightInt);
  16. }
  17.  
  18. void line_tracking()
  19. {
  20. if (LightInt > color_breakpoint) { // If line is not found
  21. set_drive_speed(20, 10);
  22. } else if (LightInt <= color_breakpoint) { // if line is found
  23. set_drive_speed(10, 20);
  24. }
  25. } // line_tracking
  26. /*
  27.  
  28. void obstacle_avoidance()
  29. {
  30.  
  31. // set obstacle_found to false
  32. } // obstacle_avoidance
  33.  
  34. void obstacle_check()
  35. {
  36.  
  37. // if the distance sensor reads something, and is below a certain threshold, set obstacle_found to true
  38. } // obstacle_check
  39.  
  40. */
  41. // Main //
  42. task main()
  43. {
  44. while(true) {
  45. display_light_value();
  46. line_tracking();
  47. }
  48. /*
  49. while (true) { // Loop that runs the whole time the program is running
  50. // check for obstacle
  51. obstacle_check();
  52.  
  53. if (obstacle_found) {
  54. obstacle_avoidance(); // Function that takes over when the obstacle is found.
  55. } else {
  56. line_tracking(); // Normal funcition for tracking the line and moving
  57. } // if
  58. } // for
  59. */
  60. } // main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement