Advertisement
roll11226

main_teleop

Feb 25th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.64 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. private void driving(double p_left, double p_right)
  64. {
  65. if (p_left > 0.2 || p_left < -0.2)
  66. {
  67. m_hardware.leftMotor.setPower(p_left);
  68. }
  69. else
  70. {
  71. m_hardware.leftMotor.setPower(0);
  72. }
  73. if (p_right > 0.2 || p_right < -0.2)
  74. {
  75. m_hardware.rightMotor.setPower(p_right);
  76. }
  77. else
  78. {
  79. m_hardware.rightMotor.setPower(0);
  80. }
  81. }
  82.  
  83. private void collect()
  84. {
  85. if (gamepad2.left_bumper && !gamepad2.right_bumper)
  86. {
  87. m_hardware.collectMotor.setPower(-1);
  88. }
  89. else if(gamepad2.right_bumper && !gamepad2.left_bumper)
  90. {
  91. m_hardware.collectMotor.setPower(0.4);
  92. }
  93. else
  94. {
  95. m_hardware.collectMotor.setPower(0);
  96. }
  97.  
  98. }
  99.  
  100. private void straightdriving()
  101. {
  102. if (gamepad1.right_bumper)
  103. {
  104. m_hardware.leftMotor.setPower(0.5);
  105. m_hardware.rightMotor.setPower(0.5);
  106. }
  107. else if (gamepad1.left_bumper)
  108. {
  109. m_hardware.leftMotor.setPower(-0.5);
  110. m_hardware.rightMotor.setPower(-0.5);
  111. }
  112.  
  113. }
  114.  
  115. private void shooting()
  116. {
  117. if (gamepad2.b)
  118. {
  119. m_shootingbool = !m_shootingbool;
  120. if (m_shootingbool == true)
  121. {
  122. m_shootingstate = m_shootingstate.sWarming;
  123. }
  124.  
  125. else
  126. {
  127. m_shootingstate = m_shootingstate.sStop;
  128. }
  129.  
  130. }
  131.  
  132. switch (m_shootingstate)
  133. {
  134. case sStop:
  135. sfStop();
  136. break;
  137. case sWarming:
  138. sfWarming();
  139. break;
  140. case sShooting:
  141. sfShooting();
  142. break;
  143. }
  144. }
  145.  
  146. private void capball()
  147. {
  148. if(gamepad1.y)
  149. {
  150. m_capballstate = m_capballstate.sLock;
  151. }
  152. switch (m_capballstate)
  153. {
  154. case sLock:
  155. sfLock();
  156. break;
  157. case sLift:
  158. sfLift(cap_Power);
  159. break;
  160.  
  161. }
  162. }
  163.  
  164. private void movingball()
  165. {
  166. if (gamepad2.y)
  167. {
  168.  
  169. m_hardware.shootingServo.setPosition(0);
  170. }
  171. else
  172. {
  173. m_hardware.shootingServo.setPosition(0.2);
  174. }
  175. }
  176.  
  177. private void changedirection()
  178. {
  179. if (gamepad1.left_bumper)
  180. {
  181. m_driveboolean = !m_driveboolean;
  182. if (m_driveboolean = false)
  183. {
  184. m_hardware.leftMotor.setDirection(DcMotor.Direction.REVERSE);
  185. m_hardware.rightMotor.setDirection(DcMotor.Direction.FORWARD);
  186. }
  187. else
  188. {
  189. m_hardware.leftMotor.setDirection(DcMotor.Direction.FORWARD);
  190. m_hardware.rightMotor.setDirection(DcMotor.Direction.REVERSE);
  191. }
  192. }
  193. }
  194.  
  195. private void sfStop()
  196. {
  197. m_hardware.shootingMotor.setPower(0);
  198. }
  199.  
  200. private void sfWarming()
  201. {
  202. m_hardware.shootingMotor.setPower(1);
  203. m_shootingtime.reset();
  204. m_shootingtime.startTime();
  205. if (m_shootingtime.milliseconds() > 1000)
  206. {
  207. m_shootingstate = m_shootingstate.sShooting;
  208. }
  209. }
  210.  
  211. private void sfShooting()
  212. {
  213. movingball();
  214. }
  215.  
  216.  
  217.  
  218. private void sfLock()
  219. {
  220. m_hardware.capBallServo.setPosition(0);
  221. m_capballstate = m_capballstate.sLift;
  222. }
  223.  
  224. private void sfLift(double p_cap_power)
  225. {
  226. if (p_cap_power > 0.4 || p_cap_power < -0.2)
  227. {
  228. m_hardware.capBallMotor.setPower(p_cap_power);
  229. }
  230.  
  231. }
  232. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement