Advertisement
Guest User

robot code 2

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