Advertisement
roll11226

Main_teleop_27.2

Feb 27th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.74 KB | None | 0 0
  1. package org.firstinspires.ftc.teamcode;
  2.  
  3. import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
  4. import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
  5. import com.qualcomm.robotcore.hardware.DcMotor;
  6. import com.qualcomm.robotcore.hardware.DcMotorSimple;
  7. import com.qualcomm.robotcore.util.ElapsedTime;
  8.  
  9. @TeleOp(name = "Teleop")
  10. public class Main_Teleop extends LinearOpMode {
  11. private HardWare11226 m_hardware = new HardWare11226();
  12. private boolean m_shootingbool = false;
  13. private boolean m_driveboolean = false;
  14. private ElapsedTime m_shootingtime = new ElapsedTime();
  15.  
  16. private enum shootingstate
  17. {
  18. sStop,
  19. sWarming,
  20. sShooting
  21. }
  22.  
  23. private enum capballstate
  24. {
  25. sLock,
  26. sLift
  27. }
  28. private shootingstate m_shootingstate;
  29. private capballstate m_capballstate;
  30. private double left_Power, right_Power, cap_Power;
  31. @Override
  32. public void runOpMode() throws InterruptedException {
  33.  
  34.  
  35. m_hardware.init(hardwareMap);
  36. m_hardware.capBallMotor.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
  37. m_hardware.shootingServo.setPosition(0.2);
  38. m_hardware.capBallServo.setPosition(0.5);
  39.  
  40.  
  41. waitForStart();
  42.  
  43. while (opModeIsActive())
  44. {
  45. left_Power = gamepad1.left_stick_y;
  46. right_Power = gamepad1.right_stick_y;
  47. cap_Power = gamepad2.right_stick_y;
  48. if (!gamepad1.left_bumper && !gamepad1.right_bumper)
  49. {
  50. driving(left_Power, right_Power);
  51. }
  52. else
  53. {
  54. straightdriving();
  55. }
  56. collect();
  57. shooting();
  58. capball();
  59. changedirection();
  60. }
  61.  
  62. }
  63.  
  64. private void driving(double p_left, double p_right)
  65. {
  66. if (p_left > 0.2 || p_left < -0.2)
  67. {
  68. m_hardware.leftMotor.setPower(p_left);
  69. }
  70. else
  71. {
  72. m_hardware.leftMotor.setPower(0);
  73. }
  74. if (p_right > 0.2 || p_right < -0.2)
  75. {
  76. m_hardware.rightMotor.setPower(p_right);
  77. }
  78. else
  79. {
  80. m_hardware.rightMotor.setPower(0);
  81. }
  82. }
  83.  
  84. private void collect()
  85. {
  86. if (gamepad2.left_bumper && !gamepad2.right_bumper)
  87. {
  88. m_hardware.collectMotor.setPower(-1);
  89. }
  90. else if(!gamepad2.left_bumper && gamepad2.right_bumper)
  91. {
  92. m_hardware.collectMotor.setPower(1);
  93. }
  94. else
  95. {
  96. m_hardware.collectMotor.setPower(0);
  97. }
  98.  
  99. }
  100.  
  101. private void straightdriving()
  102. {
  103. if (gamepad1.right_bumper)
  104. {
  105. m_hardware.leftMotor.setPower(0.5);
  106. m_hardware.rightMotor.setPower(0.5);
  107. }
  108. else if (gamepad1.left_bumper)
  109. {
  110. m_hardware.leftMotor.setPower(-0.5);
  111. m_hardware.rightMotor.setPower(-0.5);
  112. }
  113.  
  114. }
  115.  
  116. private void shooting()
  117. {
  118. if (gamepad2.b)
  119. {
  120. m_shootingbool = !m_shootingbool;
  121. if (m_shootingbool == true)
  122. {
  123. m_shootingstate = m_shootingstate.sWarming;
  124. }
  125.  
  126. else
  127. {
  128. m_shootingstate = m_shootingstate.sStop;
  129. }
  130.  
  131. }
  132.  
  133. switch (m_shootingstate)
  134. {
  135. case sStop:
  136. sfStop();
  137. break;
  138. case sWarming:
  139. sfWarming();
  140. break;
  141. case sShooting:
  142. sfShooting();
  143. break;
  144. }
  145. }
  146.  
  147. private void capball()
  148. {
  149. if(gamepad1.y)
  150. {
  151. m_capballstate = m_capballstate.sLock;
  152. }
  153. switch (m_capballstate)
  154. {
  155. case sLock:
  156. sfLock();
  157. break;
  158. case sLift:
  159. sfLift(cap_Power);
  160. break;
  161.  
  162. }
  163. }
  164.  
  165. private void movingball()
  166. {
  167. if (gamepad2.y)
  168. {
  169.  
  170. m_hardware.shootingServo.setPosition(0);
  171. }
  172. else
  173. {
  174. m_hardware.shootingServo.setPosition(1);
  175. }
  176. }
  177.  
  178. private void changedirection()
  179. {
  180. if (gamepad1.left_bumper)
  181. {
  182. m_driveboolean = !m_driveboolean;
  183. if (m_driveboolean = false)
  184. {
  185. m_hardware.leftMotor.setDirection(DcMotor.Direction.REVERSE);
  186. m_hardware.rightMotor.setDirection(DcMotor.Direction.FORWARD);
  187. }
  188. else
  189. {
  190. m_hardware.leftMotor.setDirection(DcMotor.Direction.FORWARD);
  191. m_hardware.rightMotor.setDirection(DcMotor.Direction.REVERSE);
  192. }
  193. }
  194. }
  195.  
  196. private void sfStop()
  197. {
  198. m_hardware.shootingMotor.setPower(0);
  199. }
  200.  
  201. private void sfWarming()
  202. {
  203. m_hardware.shootingMotor.setPower(-1);
  204. m_hardware.shootingMotor.setPower(0);
  205. m_hardware.shootingMotor.setPower(1);
  206. m_shootingtime.reset();
  207. m_shootingtime.startTime();
  208. if (m_shootingtime.milliseconds() > 1000)
  209. {
  210. m_shootingstate = m_shootingstate.sShooting;
  211. }
  212. }
  213.  
  214. private void sfShooting()
  215. {
  216. movingball();
  217. }
  218.  
  219.  
  220.  
  221. private void sfLock()
  222. {
  223. m_hardware.capBallServo.setPosition(0);
  224. m_capballstate = m_capballstate.sLift;
  225. }
  226.  
  227. private void sfLift(double p_cap_power)
  228. {
  229. if (p_cap_power > 0.4 || p_cap_power < -0.2)
  230. {
  231. m_hardware.capBallMotor.setPower(p_cap_power);
  232. }
  233.  
  234. }
  235. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement