Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.75 KB | None | 0 0
  1. package org.firstinspires.ftc.teamcode;
  2.  
  3. import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
  4. import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
  5. import com.qualcomm.robotcore.hardware.DcMotor;
  6. import com.qualcomm.robotcore.hardware.DcMotorSimple;
  7. import com.qualcomm.robotcore.hardware.Servo;
  8.  
  9. @Autonomous(name = "RedBridgeMain (Blocks to Java)", group = "")
  10. public class RedBridgeMain extends LinearOpMode {
  11.  
  12. private DcMotor rightMotorFront;
  13. private DcMotor rightMotorBack;
  14. private DcMotor leftMotorFront;
  15. private DcMotor leftMotorBack;
  16. private Servo armServo;
  17.  
  18. /**
  19. * Describe this function...
  20. */
  21. private void Right_Strafe() {
  22. rightMotorFront.setDirection(DcMotorSimple.Direction.REVERSE);
  23. rightMotorBack.setDirection(DcMotorSimple.Direction.FORWARD);
  24. leftMotorFront.setDirection(DcMotorSimple.Direction.REVERSE);
  25. leftMotorBack.setDirection(DcMotorSimple.Direction.FORWARD);
  26. Half_Power();
  27. }
  28.  
  29. /**
  30. * Describe this function...
  31. */
  32. private void Backwards() {
  33. rightMotorFront.setDirection(DcMotorSimple.Direction.REVERSE);
  34. rightMotorBack.setDirection(DcMotorSimple.Direction.REVERSE);
  35. leftMotorFront.setDirection(DcMotorSimple.Direction.FORWARD);
  36. leftMotorBack.setDirection(DcMotorSimple.Direction.FORWARD);
  37. }
  38.  
  39. /**
  40. * Describe this function...
  41. */
  42. private void Half_Power() {
  43. leftMotorBack.setPower(0.5);
  44. leftMotorFront.setPower(0.5);
  45. rightMotorFront.setPower(0.5);
  46. rightMotorBack.setPower(0.5);
  47. }
  48.  
  49. /**
  50. * Describe this function...
  51. */
  52. private void Forward() {
  53. rightMotorFront.setDirection(DcMotorSimple.Direction.FORWARD);
  54. rightMotorBack.setDirection(DcMotorSimple.Direction.FORWARD);
  55. leftMotorFront.setDirection(DcMotorSimple.Direction.REVERSE);
  56. leftMotorBack.setDirection(DcMotorSimple.Direction.REVERSE);
  57. }
  58.  
  59. /**
  60. * Describe this function...
  61. */
  62. private void Reset() {
  63. rightMotorFront.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
  64. rightMotorBack.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
  65. leftMotorFront.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
  66. leftMotorBack.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
  67. leftMotorFront.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
  68. leftMotorBack.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
  69. rightMotorFront.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
  70. rightMotorBack.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
  71. }
  72.  
  73. /**
  74. * Describe this function...
  75. */
  76. private void Left_Strafe() {
  77. rightMotorFront.setDirection(DcMotorSimple.Direction.FORWARD);
  78. rightMotorBack.setDirection(DcMotorSimple.Direction.REVERSE);
  79. leftMotorFront.setDirection(DcMotorSimple.Direction.FORWARD);
  80. leftMotorBack.setDirection(DcMotorSimple.Direction.REVERSE);
  81. Half_Power();
  82. }
  83.  
  84. /**
  85. * This function is executed when this Op Mode is selected from the Driver Station.
  86. */
  87. @Override
  88. public void runOpMode() {
  89. rightMotorFront = hardwareMap.dcMotor.get("rightMotorFront");
  90. rightMotorBack = hardwareMap.dcMotor.get("rightMotorBack");
  91. leftMotorFront = hardwareMap.dcMotor.get("leftMotorFront");
  92. leftMotorBack = hardwareMap.dcMotor.get("leftMotorBack");
  93. armServo = hardwareMap.servo.get("armServo");
  94.  
  95. // Put initialization blocks here.
  96. Forward();
  97. Reset();
  98. waitForStart();
  99. if (opModeIsActive()) {
  100. // Put run blocks here.
  101. while (opModeIsActive()) {
  102. // Put loop blocks here.
  103. while (!(leftMotorBack.getCurrentPosition() >= 2.5 * 1120 || isStopRequested())) {
  104. Right_Strafe();
  105. }
  106. Reset();
  107. armServo.setPosition(0.99);
  108. Zero_Power();
  109. sleep(2500);
  110. while (!(leftMotorBack.getCurrentPosition() >= 1.3 * 1120 || isStopRequested())) {
  111. Left_Strafe();
  112. }
  113. Reset();
  114. while (!(leftMotorBack.getCurrentPosition() >= 3 * 1120 || isStopRequested())) {
  115. Half_Power();
  116. Backwards();
  117. }
  118. Zero_Power();
  119. armServo.setPosition(0);
  120. sleep(2500);
  121. Reset();
  122. while (!(leftMotorBack.getCurrentPosition() >= 0.4 * 1120 || isStopRequested())) {
  123. Full_Power();
  124. Forward();
  125. }
  126. while (!isStopRequested()) {
  127. Zero_Power();
  128. }
  129. }
  130. }
  131. }
  132.  
  133. /**
  134. * Describe this function...
  135. */
  136. private void Full_Power() {
  137. leftMotorFront.setPower(1);
  138. leftMotorBack.setPower(1);
  139. rightMotorFront.setPower(1);
  140. rightMotorBack.setPower(1);
  141. }
  142.  
  143. /**
  144. * Describe this function...
  145. */
  146. private void Zero_Power() {
  147. leftMotorFront.setPower(0);
  148. leftMotorBack.setPower(0);
  149. rightMotorFront.setPower(0);
  150. rightMotorBack.setPower(0);
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement