Advertisement
Guest User

Untitled

a guest
Dec 5th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.64 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.  
  55.  
  56.  
  57.  
  58.  
  59. @Override
  60.  
  61.  
  62.  
  63. public void runOpMode() throws InterruptedException {
  64.  
  65. imu = hardwareMap.get(Gyroscope.class, "imu");
  66. backLeftWheel = (DcMotorEx) hardwareMap.get(DcMotor.class, "Back_left_wheel");
  67. backRightWheel = (DcMotorEx) hardwareMap.get(DcMotor.class, "Back_right_wheel");
  68. frontLeftWheel = (DcMotorEx) hardwareMap.get(DcMotor.class, "Front_left_wheel");
  69. frontRightWheel = (DcMotorEx) hardwareMap.get(DcMotor.class, "Front_right_wheel");
  70. linearLift = (DcMotorEx) hardwareMap.get(DcMotor.class, "linearLift");
  71. CLAW = hardwareMap.servo.get("CLAW");
  72.  
  73.  
  74.  
  75. backLeftWheel.setDirection(DcMotor.Direction.REVERSE);
  76.  
  77. backRightWheel.setDirection(DcMotor.Direction.REVERSE);
  78.  
  79. frontLeftWheel.setDirection(DcMotor.Direction.REVERSE);
  80.  
  81. frontRightWheel.setDirection(DcMotor.Direction.REVERSE);
  82.  
  83. linearLift.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
  84.  
  85. linearLift.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
  86.  
  87.  
  88.  
  89. telemetry.addData("Status", "Initialized");
  90.  
  91.  
  92.  
  93. telemetry.update();
  94.  
  95.  
  96.  
  97. //Wait for the game to start (driver presses PLAY)
  98.  
  99.  
  100.  
  101. waitForStart();
  102.  
  103.  
  104.  
  105.  
  106.  
  107. //run until the end of the match (driver presses STOP)
  108.  
  109.  
  110.  
  111. double speed;
  112.  
  113.  
  114.  
  115. double rotation;
  116.  
  117.  
  118.  
  119. double strafe;
  120.  
  121.  
  122.  
  123.  
  124.  
  125. while (opModeIsActive()) {
  126.  
  127. // Drive code
  128.  
  129. speed = -this.gamepad1.left_stick_y;
  130.  
  131. rotation = this.gamepad1.left_stick_x;
  132.  
  133. strafe = -this.gamepad1.right_stick_x;
  134.  
  135.  
  136.  
  137. backLeftWheel.setPower(speed + strafe - rotation);
  138.  
  139. backRightWheel.setPower(-speed + strafe - rotation);
  140.  
  141. frontLeftWheel.setPower(speed + strafe + rotation);
  142.  
  143. frontRightWheel.setPower(-speed + strafe + rotation);
  144.  
  145.  
  146.  
  147. // CLAAAAW code
  148.  
  149. if (this.gamepad2.a) {
  150.  
  151. CLAW.setPosition(0);
  152.  
  153. } else if (this.gamepad2.y) {
  154.  
  155. CLAW.setPosition(1);
  156.  
  157. }
  158.  
  159. int currentPosition = linearLift.getCurrentPosition();
  160.  
  161. if (currentPosition > 1120){
  162. linearLift.setPower(-.5);
  163. sleep(500);
  164. linearLift.setPower(0);
  165. while ((gamepad2.left_stick_y >= 0) || (gamepad2.left_stick_y <= 0)){
  166. linearLift.setPower(0);
  167. }
  168. }else if(currentPosition < 0){
  169. linearLift.setPower(.5);
  170. sleep(500);
  171. linearLift.setPower(0);
  172. while ((gamepad2.left_stick_y >= 0) || (gamepad2.left_stick_y <= 0)){
  173. linearLift.setPower(0);
  174. }
  175. }else {
  176. linearLift.setPower(-gamepad2.left_stick_y);
  177. }
  178.  
  179. //if ((this.gamepad2.left_stick_y < 0) && !(currentPosition > 1120)) {
  180.  
  181. //How many degrees per second should it go up
  182.  
  183. // linearLift.setVelocity(90, AngleUnit.DEGREES);
  184.  
  185. //}else if ((this.gamepad2.left_stick_y > 0) && !(currentPosition < 0)) {
  186.  
  187. // How many degrees per second should it go down
  188.  
  189. // linearLift.setVelocity(-90, AngleUnit.DEGREES);
  190. //} else {
  191.  
  192. // Hold Current Position
  193.  
  194. //linearLift.setVelocity(0, AngleUnit.DEGREES);
  195.  
  196. //}
  197.  
  198.  
  199. telemetry.addData("CLAAAAAW position", CLAW.getPosition());
  200.  
  201. telemetry.addData("Target Power", speed);
  202.  
  203. telemetry.addData("Motor Power", backLeftWheel.getPower());
  204.  
  205. telemetry.addData("Status", "Running");
  206. telemetry.addData ("Linear lift height",linearLift.getCurrentPosition());
  207.  
  208. telemetry.update();
  209.  
  210.  
  211.  
  212. }
  213.  
  214.  
  215.  
  216. }
  217.  
  218. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement