Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.firstinspires.ftc.teamcode;
- import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
- import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
- import com.qualcomm.robotcore.hardware.ColorSensor;
- import com.qualcomm.robotcore.hardware.DcMotor;
- import com.qualcomm.robotcore.hardware.Servo;
- import com.vuforia.Image;
- import org.firstinspires.ftc.robotcore.external.navigation.VuforiaLocalizer;
- import org.firstinspires.ftc.robotcore.external.navigation.VuforiaTrackables;
- /**
- * Created by mgandhi on 12/19/16.
- */
- @Autonomous(name = "RedAuto")
- public class NewAuto extends LinearOpMode {
- //Motors
- private DcMotor motorFrontLeft;
- private DcMotor motorFrontRight;
- private DcMotor motorBackLeft;
- private DcMotor motorBackRight;
- private DcMotor motorConveyor;
- private DcMotor motorShooterLeft;
- private DcMotor motorShooterRight;
- //Servos
- private Servo servoTopCap;
- private Servo servoBottomCap;
- //Sensors
- private ColorSensor SensorColor;
- //Voids
- private void RunToPosition() {
- motorFrontLeft.setMode(DcMotor.RunMode.RUN_TO_POSITION);
- motorFrontRight.setMode(DcMotor.RunMode.RUN_TO_POSITION);
- motorBackLeft.setMode(DcMotor.RunMode.RUN_TO_POSITION);
- motorBackRight.setMode(DcMotor.RunMode.RUN_TO_POSITION);
- }
- private void RunUsingEncoder() {
- motorFrontLeft.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
- motorFrontRight.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
- motorBackLeft.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
- motorBackRight.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
- }
- private void Reset() {
- motorFrontLeft.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
- motorFrontRight.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
- motorBackLeft.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
- motorBackRight.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
- }
- private void Brake() {
- motorFrontLeft.setPower(0);
- motorFrontRight.setPower(0);
- motorBackLeft.setPower(0);
- motorBackRight.setPower(0);
- }
- private void PowerDrive() {
- motorFrontLeft.setPower(drivePower);
- motorFrontRight.setPower(drivePower);
- motorBackRight.setPower(drivePower);
- motorBackLeft.setPower(drivePower);
- }
- private void PowerCapture() {
- motorFrontLeft.setPower(drivePower/2);
- motorFrontRight.setPower(drivePower/2);
- motorBackRight.setPower(drivePower/2);
- motorBackLeft.setPower(drivePower/2);
- }
- private void PowerStrafe() {
- motorFrontLeft.setPower(drivePower*3);
- motorFrontRight.setPower(drivePower*3);
- motorBackRight.setPower(drivePower*3);
- motorBackLeft.setPower(drivePower*3);
- }
- private void Busy() {
- while (motorFrontLeft.isBusy() && motorFrontRight.isBusy() && motorBackLeft.isBusy() && motorBackRight.isBusy())
- {
- }
- }
- //Values
- private static final double drivePower = .15;
- private static final double shooterPower = .83;
- private static final int TileDrive = (int)(1200);
- private static final int TileStrafe = (int)(2100);
- private static final int RightAngleTurn = (int)(1200);
- @Override
- public void runOpMode() throws InterruptedException {
- //Hardware Map
- {
- motorFrontLeft = hardwareMap.dcMotor.get("FLM");
- motorFrontRight = hardwareMap.dcMotor.get("FRM");
- motorBackLeft = hardwareMap.dcMotor.get("BLM");
- motorBackRight = hardwareMap.dcMotor.get("BRM");
- motorConveyor = hardwareMap.dcMotor.get("CM");
- motorShooterLeft = hardwareMap.dcMotor.get("SML");
- motorShooterRight = hardwareMap.dcMotor.get("SMR");
- servoBottomCap = hardwareMap.servo.get("LF");
- servoTopCap = hardwareMap.servo.get("RFS");
- SensorColor = hardwareMap.colorSensor.get("SensorColor");
- motorFrontLeft.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
- motorFrontRight.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
- motorBackLeft.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
- motorBackRight.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
- }
- {
- motorBackRight.setDirection(DcMotor.Direction.REVERSE);
- motorShooterLeft.setDirection(DcMotor.Direction.REVERSE);
- motorFrontRight.setDirection(DcMotor.Direction.REVERSE);
- }
- {
- Reset();
- servoTopCap.setPosition(1);
- servoBottomCap.setPosition(.55);
- SensorColor.enableLed(false);
- RunUsingEncoder();
- telemetry.addData("Say", "RoboticsAF Initiated");
- telemetry.update();
- }
- waitForStart();
- //Start Flywheels
- motorShooterLeft.setPower(-.55);
- motorShooterRight.setPower(-.55);
- //Forwards to Shooting Distance
- motorBackLeft.setTargetPosition(motorBackLeft.getCurrentPosition() - (int)(TileDrive * 1.55));
- motorBackRight.setTargetPosition(motorBackRight.getCurrentPosition() - (int)(TileDrive * 1.55));
- motorFrontLeft.setTargetPosition(motorFrontLeft.getCurrentPosition() - (int)(TileDrive * 1.55));
- motorFrontRight.setTargetPosition(motorFrontRight.getCurrentPosition() - (int)(TileDrive * 1.55));
- RunToPosition();
- PowerDrive();
- Busy();
- Brake();
- RunUsingEncoder();
- //Shoot Particles
- motorConveyor.setPower(-.8);
- sleep(3000);
- motorShooterLeft.setPower(0);
- motorShooterRight.setPower(0);
- motorConveyor.setPower(0);
- //Strafe to Avoid Cap Ball
- motorBackLeft.setTargetPosition(motorBackLeft.getCurrentPosition() - (int)(TileStrafe));
- motorBackRight.setTargetPosition(motorBackRight.getCurrentPosition() + (int)(TileStrafe));
- motorFrontLeft.setTargetPosition(motorFrontLeft.getCurrentPosition() + (int)(TileStrafe));
- motorFrontRight.setTargetPosition(motorFrontRight.getCurrentPosition() - (int)(TileStrafe));
- RunToPosition();
- PowerStrafe();
- Busy();
- Brake();
- RunUsingEncoder();
- sleep(250);
- //Forwards to Beacon 1
- motorBackLeft.setTargetPosition(motorBackLeft.getCurrentPosition() - (int)(TileDrive * 1));
- motorBackRight.setTargetPosition(motorBackRight.getCurrentPosition() - (int)(TileDrive * 1));
- motorFrontLeft.setTargetPosition(motorFrontLeft.getCurrentPosition() - (int)(TileDrive * 1));
- motorFrontRight.setTargetPosition(motorFrontRight.getCurrentPosition() - (int)(TileDrive * 1));
- RunToPosition();
- PowerDrive();
- Busy();
- Brake();
- RunUsingEncoder();
- sleep(250);
- //Adjustment Turn
- motorBackLeft.setTargetPosition(motorBackLeft.getCurrentPosition()+ (int)(RightAngleTurn/16));
- motorBackRight.setTargetPosition(motorBackRight.getCurrentPosition()- (int)(RightAngleTurn/16));
- motorFrontLeft.setTargetPosition(motorFrontLeft.getCurrentPosition()+ (int)(RightAngleTurn/16));
- motorFrontRight.setTargetPosition(motorFrontRight.getCurrentPosition()- (int)(RightAngleTurn/16));
- RunToPosition();
- PowerDrive();
- Busy();
- Brake();
- RunUsingEncoder();
- //Strafe To Beacon 1
- motorBackLeft.setTargetPosition(motorBackLeft.getCurrentPosition() - (int)(TileStrafe * 1.2));
- motorBackRight.setTargetPosition(motorBackRight.getCurrentPosition() + (int)(TileStrafe * 1.2));
- motorFrontLeft.setTargetPosition(motorFrontLeft.getCurrentPosition() + (int)(TileStrafe * 1.2));
- motorFrontRight.setTargetPosition(motorFrontRight.getCurrentPosition() - (int)(TileStrafe * 1.2));
- RunToPosition();
- PowerStrafe();
- Busy();
- Brake();
- RunUsingEncoder();
- telemetry.addData("Blue", SensorColor.blue());
- telemetry.addData("Red", SensorColor.red());
- sleep(1000);
- //Capture Beacon 1
- if (SensorColor.red() > SensorColor.blue()) {
- telemetry.addData("Red Side", SensorColor.red());
- motorBackLeft.setTargetPosition(motorBackLeft.getCurrentPosition() - (int) (TileDrive * .4));
- motorBackRight.setTargetPosition(motorBackRight.getCurrentPosition() - (int) (TileDrive * .4));
- motorFrontLeft.setTargetPosition(motorFrontLeft.getCurrentPosition() - (int) (TileDrive * .4));
- motorFrontRight.setTargetPosition(motorFrontRight.getCurrentPosition() - (int) (TileDrive * .4));
- RunToPosition();
- PowerCapture();
- Busy();
- Brake();
- RunUsingEncoder();
- motorBackLeft.setTargetPosition(motorBackLeft.getCurrentPosition() - (int) (TileStrafe * .2));
- motorBackRight.setTargetPosition(motorBackRight.getCurrentPosition() + (int) (TileStrafe * .2));
- motorFrontLeft.setTargetPosition(motorFrontLeft.getCurrentPosition() + (int) (TileStrafe * .2));
- motorFrontRight.setTargetPosition(motorFrontRight.getCurrentPosition() - (int) (TileStrafe * .2));
- RunToPosition();
- PowerStrafe();
- Busy();
- Brake();
- RunUsingEncoder();
- motorBackLeft.setTargetPosition(motorBackLeft.getCurrentPosition() + (int) (TileDrive * .4));
- motorBackRight.setTargetPosition(motorBackRight.getCurrentPosition() + (int) (TileDrive * .4));
- motorFrontLeft.setTargetPosition(motorFrontLeft.getCurrentPosition() + (int) (TileDrive * .4));
- motorFrontRight.setTargetPosition(motorFrontRight.getCurrentPosition() + (int) (TileDrive * .4));
- RunToPosition();
- PowerCapture();
- Busy();
- Brake();
- RunUsingEncoder();
- } else {
- telemetry.addData("Blue Side", SensorColor.blue());
- motorBackLeft.setTargetPosition(motorBackLeft.getCurrentPosition() + (int) (TileDrive * .4));
- motorBackRight.setTargetPosition(motorBackRight.getCurrentPosition() + (int) (TileDrive * .4));
- motorFrontLeft.setTargetPosition(motorFrontLeft.getCurrentPosition() + (int) (TileDrive * .4));
- motorFrontRight.setTargetPosition(motorFrontRight.getCurrentPosition() + (int) (TileDrive * .4));
- RunToPosition();
- PowerCapture();
- Busy();
- Brake();
- RunUsingEncoder();
- motorBackLeft.setTargetPosition(motorBackLeft.getCurrentPosition() - (int) (TileStrafe * .2));
- motorBackRight.setTargetPosition(motorBackRight.getCurrentPosition() + (int) (TileStrafe * .2));
- motorFrontLeft.setTargetPosition(motorFrontLeft.getCurrentPosition() + (int) (TileStrafe * .2));
- motorFrontRight.setTargetPosition(motorFrontRight.getCurrentPosition() - (int) (TileStrafe * .2));
- RunToPosition();
- PowerStrafe();
- Busy();
- Brake();
- RunUsingEncoder();
- motorBackLeft.setTargetPosition(motorBackLeft.getCurrentPosition() - (int) (TileDrive * .4));
- motorBackRight.setTargetPosition(motorBackRight.getCurrentPosition() - (int) (TileDrive * .4));
- motorFrontLeft.setTargetPosition(motorFrontLeft.getCurrentPosition() - (int) (TileDrive * .4));
- motorFrontRight.setTargetPosition(motorFrontRight.getCurrentPosition() - (int) (TileDrive * .4));
- RunToPosition();
- PowerCapture();
- Busy();
- Brake();
- RunUsingEncoder();
- }
- //Strafe Back
- motorBackLeft.setTargetPosition(motorBackLeft.getCurrentPosition() + (int)(TileStrafe/2));
- motorBackRight.setTargetPosition(motorBackRight.getCurrentPosition() - (int)(TileStrafe/2));
- motorFrontLeft.setTargetPosition(motorFrontLeft.getCurrentPosition() - (int)(TileStrafe/2));
- motorFrontRight.setTargetPosition(motorFrontRight.getCurrentPosition() + (int)(TileStrafe/2));
- RunToPosition();
- PowerStrafe();
- Busy();
- Brake();
- RunUsingEncoder();
- //Backwards to Corner
- motorBackLeft.setTargetPosition(motorBackLeft.getCurrentPosition() + (int)(TileDrive * 1.5));
- motorBackRight.setTargetPosition(motorBackRight.getCurrentPosition() + (int)(TileDrive * 1.5));
- motorFrontLeft.setTargetPosition(motorFrontLeft.getCurrentPosition() + (int)(TileDrive * 1.5));
- motorFrontRight.setTargetPosition(motorFrontRight.getCurrentPosition() + (int)(TileDrive * 1.5));
- RunToPosition();
- PowerDrive();
- Busy();
- Brake();
- RunUsingEncoder();
- stop();
- }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement