Advertisement
Guest User

Untitled

a guest
Feb 27th, 2020
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. #pragma config(Sensor, S1, FrontSensor, sensorEV3_Color)
  2. #pragma config(Sensor, S2, Gyroscope, sensorEV3_Gyro)
  3. #pragma config(Motor, motorA, ArmMotor, tmotorEV3_Medium, PIDControl, encoder)
  4. #pragma config(Motor, motorB, LeftMotor, tmotorEV3_Large, PIDControl, driveLeft, encoder)
  5. #pragma config(Motor, motorD, RightMotor, tmotorEV3_Large, PIDControl, driveRight, encoder)
  6. //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
  7.  
  8. void Wander();
  9. void PushEggIntoNest();
  10. long nest = 1;
  11. task main()
  12. {
  13. //resetGyro(Gyroscope);
  14. nest = getGyroDegrees(Gyroscope);
  15.  
  16. short currentColour;
  17. Wander();
  18. //PushEggIntoNest();
  19. }
  20. void PushEggIntoNest() {
  21. //turn until towards nest
  22. repeatUntil(fabs( getGyroDegrees(Gyroscope)-nest) <10){
  23. //turn counter clockwise if needed
  24. if (nest < getGyroDegrees(Gyroscope)) {
  25. setMotorSpeed(LeftMotor, 0);
  26. setMotorSpeed(RightMotor, 30);
  27. }
  28. //turn clockwise if needed
  29. else {
  30. setMotorSpeed(LeftMotor, 30);
  31. setMotorSpeed(RightMotor, 0);
  32. }
  33. displayTextLine(3, "%d", getGyroDegrees(Gyroscope));
  34. }
  35.  
  36. displayTextLine(7, "facing nest");
  37. //look for black tape
  38. while (SensorValue[FrontSensor] > 20){
  39. setMotorSpeed(LeftMotor, 20);
  40. setMotorSpeed(RightMotor, 20);
  41. displayTextLine(5, "%d", SensorValue[FrontSensor]);
  42. }
  43. //found nest/black tape
  44. //dip in to nest
  45. displayTextLine(6, "found nest");
  46. setMotorSpeed(LeftMotor, 50);
  47. setMotorSpeed(RightMotor, 50);
  48. sleep(200);
  49. //back out
  50. setMotorSpeed(LeftMotor, -30);
  51. setMotorSpeed(RightMotor, -30);
  52. sleep(750);
  53. //stop
  54. setMotorSpeed(LeftMotor, 0);
  55. setMotorSpeed(RightMotor, 0);
  56. }
  57. void Wander() {
  58. while (true)
  59. {
  60. setMotorSpeed(LeftMotor, 30); //Set the leftMotor (motor1) to half power (50)
  61. setMotorSpeed(RightMotor, 30); //Set the rightMotor (motor6) to half power (50)
  62. sleep(2000);
  63. if (random[2]==1) {
  64. setMotorSpeed(LeftMotor, 0); //Set the leftMotor (motor1) to Off
  65. setMotorSpeed(RightMotor, 100); //Set the rightMotor (motor6) to full power forward (100)
  66. } else {
  67. setMotorSpeed(LeftMotor, 100); //Set the leftMotor (motor1) to full power forward (100)
  68. setMotorSpeed(RightMotor, 0); //Set the rightMotor (motor6) to full power reverse (-100)
  69. }
  70. sleep(800);
  71. }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement