Advertisement
roll11226

TELEOP

Jan 24th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.45 KB | None | 0 0
  1. package org.firstinspires.ftc.teamcode;
  2.  
  3. import com.qualcomm.robotcore.hardware.DcMotor;
  4. import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
  5. import com.qualcomm.robotcore.util.ElapsedTime;
  6. import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
  7. import com.qualcomm.robotcore.hardware.Gamepad;
  8. import com.qualcomm.robotcore.hardware.Servo;
  9.  
  10.  
  11.  
  12. /**
  13.  * Created by some1 on 12/18/2017.
  14.  */
  15.  
  16. @TeleOp(name="Mechanum2.0", group="tests")
  17.  
  18. public class Mechanum2 extends LinearOpMode
  19. {
  20.     private ElapsedTime runtime = new ElapsedTime();
  21.     private DcMotor leftFrontDrive = null;
  22.     private DcMotor rightFrontDrive = null;
  23.     private DcMotor leftBackDrive = null;
  24.     private DcMotor rightBackDrive = null;
  25.     private DcMotor elevator = null;
  26.     private Servo rightServo = null;
  27.     private Servo leftServo = null;
  28.     private final double BACKDRIVEMUL = 0.86;
  29.     private final double LFRONTDRIVEMUL = 0.9;
  30.  
  31.     @Override
  32.     public void runOpMode()
  33.     {
  34.  
  35.         telemetry.addData("Status", "Initialized");
  36.         telemetry.update();
  37.  
  38.         leftFrontDrive  = hardwareMap.get(DcMotor.class, "left_front_drive");
  39.         leftBackDrive  = hardwareMap.get(DcMotor.class, "left_back_drive");
  40.         rightFrontDrive = hardwareMap.get(DcMotor.class, "right_front_drive");
  41.         rightBackDrive = hardwareMap.get(DcMotor.class, "right_back_drive");
  42.         elevator = hardwareMap.get(DcMotor.class,"elevator");
  43.         rightServo = hardwareMap.get(Servo.class, "right_servo");
  44.         leftServo = hardwareMap.get(Servo.class, "left_servo");
  45.  
  46.         leftFrontDrive.setDirection(DcMotor.Direction.FORWARD);
  47.         leftBackDrive.setDirection(DcMotor.Direction.FORWARD);
  48.         rightFrontDrive.setDirection(DcMotor.Direction.REVERSE);
  49.         rightBackDrive.setDirection(DcMotor.Direction.REVERSE);
  50.  
  51.         waitForStart();
  52.         runtime.reset();
  53.  
  54.         while (opModeIsActive())
  55.         {
  56.  
  57.             mechAndPickup();
  58.             telemetry.addData("right front:\t", rightFrontDrive.getCurrentPosition());
  59.             telemetry.addData("left front:\t", leftFrontDrive.getCurrentPosition());
  60.             telemetry.update();
  61.  
  62.  
  63.         }
  64.     }
  65.  
  66.     public void mechAndPickup()
  67.     {
  68.         double powerLeft = gamepad1.left_stick_y;
  69.         double powerRight = gamepad1.right_stick_y;
  70.         double powerSlideLeft = gamepad1.left_trigger;
  71.         double powerSlideRight = gamepad1.right_trigger;
  72.         boolean elevatorPowUp = gamepad2.x;
  73.         boolean elevatorPowDown = gamepad2.b;
  74.         boolean open = true;
  75.  
  76. //elevator and servo
  77.         if(gamepad2.a)
  78.         {
  79.             open = !open;
  80.         }
  81.  
  82.         if(!open)
  83.         {
  84.             leftServo.setPosition(0.6);
  85.             rightServo.setPosition(0.4);
  86.         }
  87.         else
  88.         {
  89.             leftServo.setPosition(1);
  90.             rightServo.setPosition(0.07);
  91.         }
  92.  
  93.  
  94.         if(elevatorPowDown)
  95.         {
  96.             elevator.setPower(0.6);
  97.         }
  98.         else if(elevatorPowUp)
  99.         {
  100.             elevator.setPower(-0.5);
  101.         }
  102.         else
  103.         {
  104.             elevator.setPower(0);
  105.         }
  106.  
  107.  
  108.         if ((powerLeft > 0.2 || powerLeft < -0.2 || powerRight > 0.2 || powerRight < -0.2) && powerSlideLeft == 0 && powerSlideRight == 0)
  109.         {
  110.             leftFrontDrive.setPower(LFRONTDRIVEMUL * powerLeft);
  111.             leftBackDrive.setPower(BACKDRIVEMUL * powerLeft);
  112.             rightFrontDrive.setPower(powerRight);
  113.             rightBackDrive.setPower(BACKDRIVEMUL * powerRight);
  114.         }/*
  115.         else if ((powerSlideLeft > 0.2 || powerSlideLeft < -0.2) && powerLeft == 0 && powerRight == 0)
  116.         {
  117.             leftFrontDrive.setPower(LFRONTDRIVEMUL * powerSlideLeft);
  118.             leftBackDrive.setPower(-BACKDRIVEMUL * powerSlideLeft);
  119.             rightFrontDrive.setPower(-powerSlideLeft);
  120.             rightBackDrive.setPower(BACKDRIVEMUL * powerSlideLeft);
  121.         }
  122.         else if ((powerSlideRight > 0.2 || powerSlideRight < -0.2) && powerLeft == 0 && powerRight == 0)
  123.         {
  124.             leftFrontDrive.setPower(-powerSlideRight);
  125.             leftBackDrive.setPower(powerSlideRight);
  126.             rightFrontDrive.setPower(powerSlideRight);
  127.             rightBackDrive.setPower(-powerSlideRight);
  128.         }*/
  129.         else
  130.         {
  131.             leftFrontDrive.setPower(0);
  132.             leftBackDrive.setPower(0);
  133.             rightFrontDrive.setPower(0);
  134.             rightBackDrive.setPower(0);
  135.         }
  136.     }
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement