Robotc Teleop Phase


SUBMITTED BY: Guest

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

FORMAT: Text only

SIZE: 5.9 kB

HITS: 1314

  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(Sensor, S3, IRSeeker2, sensorHiTechnicIRSeeker1200)
  6. #pragma config(Motor, mtr_S1_C1_1, motor_flag, tmotorTetrix, PIDControl, encoder)
  7. #pragma config(Motor, mtr_S1_C1_2, motor_lin2, tmotorTetrix, PIDControl, encoder)
  8. #pragma config(Motor, mtr_S1_C2_1, motor_left1, tmotorTetrix, PIDControl, encoder)
  9. #pragma config(Motor, mtr_S1_C2_2, motor_left2, tmotorTetrix, PIDControl, encoder)
  10. #pragma config(Motor, mtr_S2_C1_1, motor_right1, tmotorTetrix, PIDControl, encoder)
  11. #pragma config(Motor, mtr_S2_C1_2, motor_right2, tmotorTetrix, PIDControl, encoder)
  12. #pragma config(Motor, mtr_S2_C2_1, notused, tmotorTetrix, PIDControl, encoder)
  13. #pragma config(Motor, mtr_S2_C2_2, motor_lin4, tmotorTetrix, PIDControl, encoder)
  14. #pragma config(Servo, srvo_S1_C3_1, servo1, tServoStandard)
  15. #pragma config(Servo, srvo_S1_C3_2, servo2, tServoStandard)
  16. #pragma config(Servo, srvo_S1_C3_3, servo3, tServoContinuousRotation)
  17. #pragma config(Servo, srvo_S1_C3_4, servo4, tServoNone)
  18. #pragma config(Servo, srvo_S1_C3_5, servo5, tServoNone)
  19. #pragma config(Servo, srvo_S1_C3_6, servo6, tServoNone)
  20. //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
  21. #include "JoystickDriver.c";
  22. /**
  23. * Helper function to scale analog joystick values for tetrix dc motors.
  24. */
  25. void initializeRobot() //don't touch
  26. {//absolutely nothing
  27. //Set all motor rotation counts to 0
  28. nMotorEncoder(motor_lin2) =0;//E
  29. nMotorEncoder(motor_lin4) =0;//G
  30. }
  31. int scaleForMotor(int joyValue)
  32. {
  33. const int DEADZONE = 5;
  34. const int MAX_MOTOR_VAL = 154; //don't touch
  35. const float MAX_JOY_VAL = 127;
  36. //check for deadzone
  37. if(abs(joyValue) < DEADZONE) {
  38. return 0;
  39. }
  40. //calculate scaled value
  41. int direction = joyValue / abs(joyValue); // 1 or -1
  42. float ratio = ((joyValue * joyValue) / (MAX_JOY_VAL * MAX_JOY_VAL));
  43. int scaledVal = (ratio * MAX_MOTOR_VAL) * direction; //don't touch
  44. return scaledVal;
  45. }
  46. task main()
  47. {
  48. initializeRobot();
  49. waitForStart(); //wait for field control system to start
  50. while(true)
  51. {
  52. int Dm = nMotorEncoder(motor_left1); //Save the current rotation values to integers Dm, Em, Fm, and Gm for future
  53. int Em = nMotorEncoder(motor_left2);
  54. int Fm = nMotorEncoder(motor_right1);
  55. int Gm = nMotorEncoder(motor_right2);
  56. //Display rotation values of the motors on the 1st, 2nd, 3rd, and 4th lines of the NXT display.
  57. nxtDisplayTextLine(2, "%d", nMotorEncoder(motor_lin2));
  58. nxtDisplayTextLine(4, "%d", nMotorEncoder(motor_lin4));
  59. getJoystickSettings(joystick); //receive inputs from controllers
  60. motor[motor_left1] = scaleForMotor(joystick.joy1_y1/-127*150);
  61. motor[motor_left2] = scaleForMotor(joystick.joy1_y1/-127*150);
  62. motor[motor_right1] = scaleForMotor(joystick.joy1_y2/127*150);
  63. motor[motor_right2] = scaleForMotor(joystick.joy1_y2/127*150); //tank controls
  64. if (joy2Btn(4) == 1) //controller2_Y_slide_up
  65. {
  66. motor(motor_lin2) = -60;
  67. motor(motor_lin4) = 60;
  68. nxtDisplayTextLine(1, "slide down"); //print to NXT display
  69. }
  70. else if (joy1Btn(8) == 1) //controller1_lefttrigger_sweeper_in
  71. {
  72. motor(motorA) = -60;
  73. motor(motorB) = -60;
  74. nxtDisplayTextLine(1, "sweeper in");
  75. }
  76. else if (joy1Btn(1) == 1) //controller1_Y_armdown
  77. {
  78. //servo(servo3) = 1;
  79. nxtDisplayTextLine(1, "sweeper in");
  80. }
  81. else if (joy2Btn(2) == 1) //controller2_A_slide_down
  82. {
  83. if (nMotorEncoder(motor_lin4) > -8300) //made up number for now
  84. {
  85. motor(motor_lin2) = 60;
  86. motor(motor_lin4) = -60;
  87. nxtDisplayTextLine(1, "slide up");
  88. }
  89. }
  90. else if (joy1Btn(7) == 1) //controller1_lefttrigger_Y_sweeperout
  91. {
  92. motor(motorA) = 60;
  93. motor(motorB) = 60;
  94. nxtDisplayTextLine(1, "sweeper out");
  95. }
  96. else if (joy1Btn(2) == 1) //controller1_A_bucket_down
  97. {
  98. int count = 1;
  99. while(count == 1)
  100. {
  101. servo(servo1) = 120;
  102. servo(servo2) = 136;
  103. nxtDisplayTextLine(1, "bucket down");
  104. if (joy1Btn(2) == 1)
  105. {
  106. count++;
  107. }
  108. }
  109. }
  110. else if (joy1Btn(3) == 1) //controller1_B_bucket_up
  111. {
  112. int count = 1;
  113. while(count == 1)
  114. {
  115. servo(servo1) = 86;
  116. servo(servo2) = 170;
  117. nxtDisplayTextLine(1, "bucket down");
  118. if (joy1Btn(3) == 1)
  119. {
  120. count++;
  121. }
  122. }
  123. }
  124. else if (joy1Btn(4) == 1) //controller1_Y_armmid
  125. {
  126. int count = 1;
  127. while(count == 1)
  128. {
  129. servo(servo1) = 46;
  130. servo(servo2) = 210;
  131. nxtDisplayTextLine(1, "bucket down");
  132. if (joy1Btn(4) == 1)
  133. {
  134. count++;
  135. }
  136. }
  137. }
  138. else if (joy2Btn(1) == 1)
  139. {
  140. motor(motor_flag) = 60;
  141. }
  142. else
  143. {
  144. if (joy2Btn(3) == 1)
  145. {
  146. motor(motor_flag) = -60;
  147. }
  148. else //absolutely nothing
  149. {
  150. //servo(servo1) = 255;
  151. //servo(servo2) = 1;
  152. motor(motorA) = 0; //Every motor stopped, servos back to its position
  153. motor(motorB) = 0;
  154. motor(motor_lin2) = 0;
  155. motor(motor_lin4) = 0;
  156. motor(motor_flag) = 0;
  157. nxtDisplayTextLine(1, "slide stop");
  158. nxtDisplayTextLine(1, "Nothing, bucket up");
  159. }
  160. }
  161. }
  162. }

comments powered by Disqus