Advertisement
roll11226

DRIVE

Jan 24th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.77 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.util.ElapsedTime;
  7.  
  8.  
  9.  
  10.     @Autonomous(name="Basic: Linear OpMode", group="Linear Opmode")
  11.     public class DRIVE extends LinearOpMode {
  12.  
  13.         private DcMotor leftFrontDrive = null;
  14.         private DcMotor rightFrontDrive = null;
  15.         private DcMotor leftBackDrive = null;
  16.         private DcMotor rightBackDrive = null;
  17.         private final double Perimeter = 12.56;
  18.         private final double RotationP = 43.806;
  19.         private final double BACKDRIVEMUL = 0.86;
  20.         private final double LFRONTDRIVEMUL = 0.9;
  21.         private final double deviation = 1.6444444;
  22.  
  23.         @Override
  24.         public void runOpMode() {
  25.  
  26.             leftFrontDrive.setDirection(DcMotor.Direction.REVERSE);
  27.             leftBackDrive.setDirection(DcMotor.Direction.REVERSE);
  28.             rightFrontDrive.setDirection(DcMotor.Direction.FORWARD);
  29.             rightBackDrive.setDirection(DcMotor.Direction.FORWARD);
  30.  
  31.             rightBackDrive.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
  32.             leftBackDrive.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
  33.             rightFrontDrive.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
  34.             leftFrontDrive.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
  35.  
  36.             rightFrontDrive.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
  37.             leftFrontDrive.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
  38.             rightBackDrive.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
  39.             leftBackDrive.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
  40.  
  41.             leftFrontDrive = hardwareMap.get(DcMotor.class, "left_front_drive");
  42.             leftBackDrive = hardwareMap.get(DcMotor.class, "left_back_drive");
  43.             rightFrontDrive = hardwareMap.get(DcMotor.class, "right_front_drive");
  44.             rightBackDrive = hardwareMap.get(DcMotor.class, "right_back_drive");
  45.  
  46.         }
  47.         public void driveForward(int distance_inch, double speed) {
  48.  
  49.             int distance_degrees = (int) (1120 * (distance_inch + 5) / Perimeter);
  50.  
  51.             rightFrontDrive.setTargetPosition(distance_degrees);
  52.             leftFrontDrive.setTargetPosition(distance_degrees);
  53.             rightBackDrive.setTargetPosition(distance_degrees);
  54.             leftBackDrive.setTargetPosition(distance_degrees);
  55.  
  56.             rightFrontDrive.setMode(DcMotor.RunMode.RUN_TO_POSITION);
  57.             leftFrontDrive.setMode(DcMotor.RunMode.RUN_TO_POSITION);
  58.             rightBackDrive.setMode(DcMotor.RunMode.RUN_TO_POSITION);
  59.             leftBackDrive.setMode(DcMotor.RunMode.RUN_TO_POSITION);
  60.  
  61.             rightBackDrive.setPower(0);
  62.             leftBackDrive.setPower(0);
  63.             rightFrontDrive.setPower(0);
  64.             leftFrontDrive.setPower(0);
  65.             telemetry.addData("Status", "out of busy");
  66.             telemetry.update();
  67.             beginF();
  68.         }
  69.         public void turnDegrees(int degrees, double speed) {
  70.  
  71.             int turn_degrees = (int) (1120 * ((RotationP / 360 * degrees) / Perimeter) * deviation);
  72.  
  73.             rightFrontDrive.setTargetPosition(turn_degrees);
  74.             leftFrontDrive.setTargetPosition(-turn_degrees);
  75.             rightBackDrive.setTargetPosition(turn_degrees);
  76.             leftBackDrive.setTargetPosition(-turn_degrees);
  77.  
  78.             rightFrontDrive.setMode(DcMotor.RunMode.RUN_TO_POSITION);
  79.             leftFrontDrive.setMode(DcMotor.RunMode.RUN_TO_POSITION);
  80.             rightBackDrive.setMode(DcMotor.RunMode.RUN_TO_POSITION);
  81.             leftBackDrive.setMode(DcMotor.RunMode.RUN_TO_POSITION);
  82.  
  83.             rightFrontDrive.setPower(speed);
  84.             leftFrontDrive.setPower(-(LFRONTDRIVEMUL * speed));
  85.             rightBackDrive.setPower(BACKDRIVEMUL * speed);
  86.             leftBackDrive.setPower(-(BACKDRIVEMUL * speed));
  87.  
  88.             rightBackDrive.setPower(0);
  89.             leftBackDrive.setPower(0);
  90.             rightFrontDrive.setPower(0);
  91.             leftFrontDrive.setPower(0);
  92.             beginF();
  93.         }
  94.         public void beginF(){
  95.  
  96.             rightBackDrive.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
  97.             leftBackDrive.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
  98.             rightFrontDrive.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
  99.             leftFrontDrive.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
  100.  
  101.             rightFrontDrive.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
  102.             leftFrontDrive.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
  103.             rightBackDrive.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
  104.             leftBackDrive.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
  105.         }
  106.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement