Advertisement
Guest User

Untitled

a guest
Dec 10th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.61 KB | None | 0 0
  1. package org.firstinspires.ftc.teamcode;
  2.  
  3.  
  4.  
  5. import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
  6.  
  7. import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
  8.  
  9. import com.qualcomm.robotcore.hardware.DcMotor;
  10.  
  11. import com.qualcomm.robotcore.hardware.DcMotorEx;
  12.  
  13. import com.qualcomm.robotcore.hardware.Gyroscope;
  14.  
  15. import com.qualcomm.robotcore.hardware.Servo;
  16.  
  17.  
  18.  
  19. import org.firstinspires.ftc.robotcore.external.navigation.AngleUnit;
  20.  
  21.  
  22.  
  23.  
  24.  
  25. /**
  26.  
  27.  
  28.  
  29. * Created by Boen on 10-10-19
  30.  
  31.  
  32.  
  33. */
  34.  
  35.  
  36.  
  37. @TeleOp(name = "Skystone op mode",group = "competition modes")
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45. public class upDownMode extends LinearOpMode {
  46.  
  47. private Gyroscope imu;
  48.  
  49. private DcMotorEx backLeftWheel, backRightWheel, frontLeftWheel, frontRightWheel;
  50.  
  51. private DcMotor linearLift;
  52.  
  53. private Servo CLAW;
  54. double startPosition;
  55.  
  56.  
  57.  
  58.  
  59.  
  60. @Override
  61.  
  62.  
  63.  
  64. public void runOpMode() throws InterruptedException {
  65.  
  66. imu = hardwareMap.get(Gyroscope.class, "imu");
  67. backLeftWheel = (DcMotorEx) hardwareMap.get(DcMotor.class, "Back_left_wheel");
  68. backRightWheel = (DcMotorEx) hardwareMap.get(DcMotor.class, "Back_right_wheel");
  69. frontLeftWheel = (DcMotorEx) hardwareMap.get(DcMotor.class, "Front_left_wheel");
  70. frontRightWheel = (DcMotorEx) hardwareMap.get(DcMotor.class, "Front_right_wheel");
  71. linearLift = (DcMotor) hardwareMap.get(DcMotor.class, "linearLift");
  72. CLAW = hardwareMap.servo.get("CLAW");
  73.  
  74.  
  75.  
  76. backLeftWheel.setDirection(DcMotor.Direction.REVERSE);
  77.  
  78. backRightWheel.setDirection(DcMotor.Direction.REVERSE);
  79.  
  80. frontLeftWheel.setDirection(DcMotor.Direction.REVERSE);
  81.  
  82. frontRightWheel.setDirection(DcMotor.Direction.REVERSE);
  83.  
  84. linearLift.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
  85.  
  86.  
  87.  
  88. telemetry.addData("Status", "Initialized");
  89.  
  90.  
  91. startPosition = linearLift.getCurrentPosition();
  92.  
  93.  
  94. telemetry.update();
  95.  
  96.  
  97.  
  98. //Wait for the game to start (driver presses PLAY)
  99.  
  100.  
  101.  
  102. waitForStart();
  103.  
  104.  
  105.  
  106.  
  107.  
  108. //run until the end of the match (driver presses STOP)
  109.  
  110.  
  111.  
  112. double speed;
  113. double rotation;
  114. double strafe;
  115. double multiplier = 0;
  116.  
  117. while (opModeIsActive()) {
  118.  
  119. // Drive code
  120.  
  121. speed = -this.gamepad1.left_stick_y * multiplier;
  122.  
  123. rotation = this.gamepad1.left_stick_x * multiplier;
  124.  
  125. strafe = -this.gamepad1.right_stick_x * multiplier;
  126.  
  127.  
  128. backLeftWheel.setPower(speed + strafe - rotation);
  129.  
  130. backRightWheel.setPower(-speed + strafe - rotation);
  131.  
  132. frontLeftWheel.setPower(speed + strafe + rotation);
  133.  
  134. frontRightWheel.setPower(-speed + strafe + rotation);
  135.  
  136. if (gamepad1.left_trigger > .5){
  137. multiplier = .4;
  138. } else{
  139. multiplier = 1;
  140. }
  141.  
  142. // CLAAAAW code
  143. if (this.gamepad2.a) {
  144.  
  145. CLAW.setPosition(0);
  146.  
  147. } else if (this.gamepad2.y) {
  148.  
  149. CLAW.setPosition(1);
  150.  
  151. }
  152.  
  153.  
  154. int currentPosition = linearLift.getCurrentPosition();
  155.  
  156.  
  157. if (currentPosition >= (1120 + startPosition) ) {
  158. if(gamepad2.left_trigger > .5) {
  159. linearLift.setPower(-0.5);
  160. } else {
  161. linearLift.setPower(0);
  162. }
  163. }
  164. else if (currentPosition < (0 + startPosition) ) {
  165. if(gamepad2.right_trigger > 0.5) {
  166. linearLift.setPower(0.5);
  167. } else {
  168. linearLift.setPower(0);
  169.  
  170. }
  171. }
  172. else{
  173. if(gamepad2.right_trigger > 0.5) {
  174. linearLift.setPower(0.5);
  175. } else if(gamepad2.left_trigger > 0.5) {
  176. linearLift.setPower(-0.5);
  177. } else {
  178. linearLift.setPower(0);
  179. }
  180. }
  181.  
  182. if(gamepad2.x) {
  183. linearLift.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
  184. } else {
  185. linearLift.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
  186.  
  187. }
  188.  
  189. telemetry.addData("CLAAAAAW position", CLAW.getPosition());
  190. telemetry.addData("Target Power", speed);
  191. telemetry.addData("Motor Power", backLeftWheel.getPower());
  192. telemetry.addData("Status", "Running");
  193. telemetry.addData ("Linear lift height", currentPosition);
  194.  
  195. telemetry.update();
  196.  
  197.  
  198.  
  199. }
  200.  
  201.  
  202.  
  203. }
  204.  
  205. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement