Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. #pragma config(Sensor, S1, wallSensor, sensorSONAR)
  2. #pragma config(Sensor, S2, ballSensor, sensorEV3_Ultrasonic)
  3. #pragma config(Sensor, S3, gyroSensor, sensorEV3_Gyro, modeEV3Gyro_Rate)
  4. #pragma config(Sensor, S4, colorSensor, sensorEV3_Color, modeEV3Color_Color)
  5. #pragma config(Motor, motorA, arm, tmotorEV3_Medium, PIDControl, encoder)
  6. #pragma config(Motor, motorB, leftWheel, tmotorEV3_Large, PIDControl, encoder)
  7. #pragma config(Motor, motorC, rightWheel, tmotorEV3_Large, PIDControl, encoder)
  8. //*!!Code automatically generated by 'ROBOTC' configuration wizard
  9.  
  10. // create a global variable to hold the heading value
  11. int heading = 0;
  12.  
  13. // separate task to calculate heading
  14. task getHeading () {
  15.  
  16. int gyroRate = 0;
  17. int sleepTime = 250; // read the heading value 4 times per second
  18. int sensorReadRate = 1000/sleepTime;
  19.  
  20. while (true) {
  21.  
  22. // get the angular velocity (degrees per second)
  23. gyroRate = SensorValue[gyroSensor];
  24. displayCenteredBigTextLine(2, "Gyro: %d", gyroRate);
  25.  
  26. // convert the angular velocity into degrees and add it
  27. // to the heading value.
  28. heading = heading + gyroRate/sensorReadRate;
  29.  
  30. // keep the heading value between 0 and 360 degrees
  31. heading = heading % 360;
  32. if (heading < 0) {
  33. heading = 360 + heading;
  34. }
  35. sleep(sleepTime);
  36. }
  37. }
  38.  
  39. task main()
  40. {
  41.  
  42. startTask(getHeading);
  43.  
  44. while(true){
  45. displayCenteredBigTextLine(10, "Heading: %d", heading);
  46. float degreesToTurn =
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement