Robotc Red Position 2 Attack Autonomous


SUBMITTED BY: Guest

DATE: Jan. 26, 2014, 7:47 p.m.

FORMAT: Text only

SIZE: 4.0 kB

HITS: 1159

  1. #pragma config(Hubs, S1, HTMotor, HTMotor, HTServo, none)
  2. #pragma config(Hubs, S2, HTMotor, HTMotor, none, none)
  3. #pragma config(Sensor, S1, , sensorI2CMuxController)
  4. #pragma config(Sensor, S2, , sensorI2CMuxController)
  5. #pragma config(Motor, motorA, , tmotorNXT, openLoop)
  6. #pragma config(Motor, motorB, , tmotorNXT, openLoop)
  7. #pragma config(Motor, mtr_S1_C1_1, notused, tmotorTetrix, openLoop)
  8. #pragma config(Motor, mtr_S1_C1_2, notused1, tmotorTetrix, openLoop)
  9. #pragma config(Motor, mtr_S1_C2_1, motorD, tmotorTetrix, PIDControl, encoder)
  10. #pragma config(Motor, mtr_S1_C2_2, motorF, tmotorTetrix, PIDControl, encoder)
  11. #pragma config(Motor, mtr_S2_C1_1, motorE, tmotorTetrix, PIDControl, encoder)
  12. #pragma config(Motor, mtr_S2_C1_2, motorG, tmotorTetrix, PIDControl, encoder)
  13. #pragma config(Motor, mtr_S2_C2_1, notused2, tmotorTetrix, openLoop)
  14. #pragma config(Motor, mtr_S2_C2_2, notused3, tmotorTetrix, openLoop)
  15. #pragma config(Servo, srvo_S1_C3_1, servo1, tServoNone)
  16. #pragma config(Servo, srvo_S1_C3_2, servo2, tServoNone)
  17. #pragma config(Servo, srvo_S1_C3_3, servo3, tServoNone)
  18. #pragma config(Servo, srvo_S1_C3_4, servo4, tServoNone)
  19. #pragma config(Servo, srvo_S1_C3_5, servo5, tServoNone)
  20. #pragma config(Servo, srvo_S1_C3_6, servo6, tServoNone)
  21. //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
  22. #include "JoystickDriver.c";
  23. void initializeRobot(){
  24. nMotorEncoder(motorD) =0;
  25. nMotorEncoder(motorE) =0;
  26. nMotorEncoder(motorF) =0;
  27. nMotorEncoder(motorG) =0;
  28. return;
  29. }
  30. void move(int direction, float revs);
  31. void turn(int direction, float revs);
  32. int fullrev = 1440;
  33. task main()
  34. {
  35. initializeRobot();
  36. waitForStart();
  37. move(0,7.9);
  38. turn(1,1.6);
  39. move(1,1.2);
  40. turn(0,0.6);
  41. move(1,4.6);
  42. }
  43. //This function is for turning. The "int" is actually a boolean. Use 0 for a left turn, 1 for a right turn.
  44. void turn(int direction, float revs)
  45. {
  46. nMotorEncoder(motorD) =0;
  47. nMotorEncoder(motorE) =0;
  48. nMotorEncoder(motorF) =0;
  49. nMotorEncoder(motorG) =0;
  50. if (direction==0)
  51. {
  52. while(nMotorEncoder(motorD) > -(fullrev*revs) & nMotorEncoder(motorE) > -(fullrev*revs) & nMotorEncoder(motorF) > -(fullrev*revs) & nMotorEncoder(motorG) > -(fullrev*revs))
  53. {
  54. motor(motorD) = -60;
  55. motor(motorE) = -60;
  56. motor(motorF) = -60;
  57. motor(motorG) = -60;
  58. }
  59. }
  60. else
  61. {
  62. while(nMotorEncoder(motorD) < (fullrev*revs) & nMotorEncoder(motorE) < (fullrev*revs) & nMotorEncoder(motorF) < (fullrev*revs) & nMotorEncoder(motorG) < (fullrev*revs))
  63. {
  64. motor(motorD) = 60;
  65. motor(motorE) = 60;
  66. motor(motorF) = 60;
  67. motor(motorG) = 60;
  68. }
  69. }
  70. }
  71. //This function is for moving. The "int" is actually a boolean. Use 0 for forward, 1 for backward.
  72. void move(int direction, float revs)
  73. {
  74. nMotorEncoder(motorD) =0;
  75. nMotorEncoder(motorE) =0;
  76. nMotorEncoder(motorF) =0;
  77. nMotorEncoder(motorG) =0;
  78. if (direction==0)
  79. {
  80. while(nMotorEncoder(motorD) > -(fullrev*revs) & nMotorEncoder(motorE) < (fullrev*revs) & nMotorEncoder(motorF) > -(fullrev*revs) & nMotorEncoder(motorG) < (fullrev*revs))
  81. {
  82. motor(motorD) = -60;
  83. motor(motorE) = 60;
  84. motor(motorF) = -60;
  85. motor(motorG) = 60;
  86. }
  87. }
  88. else
  89. {
  90. while(nMotorEncoder(motorD) < (fullrev*revs) & nMotorEncoder(motorE) > -(fullrev*revs) & nMotorEncoder(motorF) < (fullrev*revs) & nMotorEncoder(motorG) > -(fullrev*revs))
  91. {
  92. motor(motorD) = 60;
  93. motor(motorE) = -60;
  94. motor(motorF) = 60;
  95. motor(motorG) = -60;
  96. }
  97. }
  98. }

comments powered by Disqus