diff --git a/.idea/misc.xml b/.idea/misc.xml index 2a4d5b5..bdd9278 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,5 +1,6 @@ + diff --git a/README.md b/README.md index e69de29..d2d4ef8 100644 --- a/README.md +++ b/README.md @@ -0,0 +1 @@ +This is the code for 2021-2022 FreeOfCharge team. \ No newline at end of file diff --git a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/AutoModeTest.java b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/AutoModeTest.java new file mode 100644 index 0000000..95b48e8 --- /dev/null +++ b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/AutoModeTest.java @@ -0,0 +1,37 @@ +package org.firstinspires.ftc.teamcode; + + +import com.qualcomm.robotcore.eventloop.opmode.Autonomous; +import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode; +import com.qualcomm.robotcore.hardware.DcMotor; + +@Autonomous +public class AutoModeTest extends LinearOpMode { + private DcMotor frontRight, frontLeft, rearRight, rearLeft; + private double drive, strafe, turn; + private double driveMult = 0.25; + + @Override + public void runOpMode(){ + initParts(); + + } + + + public void initParts(){ + frontRight = hardwareMap.get(DcMotor.class, "frontRight"); + frontLeft = hardwareMap.get(DcMotor.class, "frontLeft"); + rearRight = hardwareMap.get(DcMotor.class, "rearRight"); + rearLeft = hardwareMap.get(DcMotor.class, "rearLeft"); + + // turns on encoders + frontRight.setMode(DcMotor.RunMode.RUN_USING_ENCODER); + frontLeft.setMode(DcMotor.RunMode.RUN_USING_ENCODER); + rearRight.setMode(DcMotor.RunMode.RUN_USING_ENCODER); + rearLeft.setMode(DcMotor.RunMode.RUN_USING_ENCODER); + + // telemetry messages + telemetry.addData("Status", "Initialized"); + telemetry.update(); + } +} diff --git a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/MotorControl.java b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/MotorControl.java new file mode 100644 index 0000000..228fc54 --- /dev/null +++ b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/MotorControl.java @@ -0,0 +1,71 @@ +package org.firstinspires.ftc.teamcode; + +import static org.firstinspires.ftc.robotcore.external.BlocksOpModeCompanion.hardwareMap; + + +import com.qualcomm.robotcore.hardware.DcMotor; + + +public class MotorControl { + private DcMotor frontRight, frontLeft, rearRight, rearLeft; + private double frontRightPower, frontLeftPower, rearRightPower, rearLeftPower; + + public MotorControl(){ + init(); + } + private void calcDrive(double yDrive, double xDrive){ + frontRightPower = yDrive - xDrive; + frontLeftPower = yDrive + xDrive; + rearRightPower = yDrive + xDrive; + rearLeftPower = yDrive - xDrive; + + } + + private void addTurn(double turn){ + if (turn > 0) { + frontRightPower *= (1 - turn); + rearRightPower *= (1 - turn); + } + if (turn < 0) { + frontLeftPower *= (1 + turn); + rearLeftPower *= (1 + turn); + } + } + + + public void drive(double yDrive, double xDrive, double speed, double turn){ + calcDrive(yDrive, xDrive); + if (turn != 0) { + addTurn(turn); + } + frontRightPower*=speed; + frontLeftPower*=speed; + rearRightPower*=speed; + rearLeftPower*=speed; + + frontRight.setPower(-1*frontRightPower); + frontLeft.setPower(frontLeftPower); + rearRight.setPower(-1*rearRightPower); + rearLeft.setPower(rearLeftPower); + } + + private void init(){ + frontRight = hardwareMap.get(DcMotor.class, "frontRight"); + frontLeft = hardwareMap.get(DcMotor.class, "frontLeft"); + rearRight = hardwareMap.get(DcMotor.class, "rearRight"); + rearLeft = hardwareMap.get(DcMotor.class, "rearLeft"); + + // stops and resets encoders + frontRight.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER); + frontLeft.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER); + rearRight.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER); + rearLeft.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER); + + // turns on encoders + frontRight.setMode(DcMotor.RunMode.RUN_USING_ENCODER); + frontLeft.setMode(DcMotor.RunMode.RUN_USING_ENCODER); + rearRight.setMode(DcMotor.RunMode.RUN_USING_ENCODER); + rearLeft.setMode(DcMotor.RunMode.RUN_USING_ENCODER); + + } +} diff --git a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/MyFIRSTJavaOpMode.java b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/MyFIRSTJavaOpMode.java index 2c98b72..5b0e159 100644 --- a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/MyFIRSTJavaOpMode.java +++ b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/MyFIRSTJavaOpMode.java @@ -1,5 +1,6 @@ package org.firstinspires.ftc.teamcode; +import com.qualcomm.robotcore.eventloop.opmode.Disabled; import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode; import com.qualcomm.robotcore.eventloop.opmode.TeleOp; import com.qualcomm.robotcore.hardware.DcMotor; @@ -9,7 +10,7 @@ import com.qualcomm.robotcore.hardware.Gyroscope; import com.qualcomm.robotcore.hardware.Servo; @TeleOp - +@Disabled public class MyFIRSTJavaOpMode extends LinearOpMode { private Gyroscope imu; private DcMotor frontRight; diff --git a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/controllerOpMode.java b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/controllerOpMode.java index 63dae97..338487b 100644 --- a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/controllerOpMode.java +++ b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/controllerOpMode.java @@ -8,41 +8,43 @@ import com.qualcomm.robotcore.hardware.DcMotor; public class controllerOpMode extends OpMode { private DcMotor frontRight, frontLeft, rearRight, rearLeft; private double drive,strafe, turn; - private double driveMult = 0.25; - public void init(){ - frontRight = hardwareMap.get(DcMotor.class, "frontRight"); - frontLeft = hardwareMap.get(DcMotor.class, "frontLeft"); - rearRight = hardwareMap.get(DcMotor.class, "rearRight"); - rearLeft = hardwareMap.get(DcMotor.class, "rearLeft"); - telemetry.addData("Status", "Initialized"); - telemetry.update(); - } + private double speed; + MotorControl driveMotors; + + + + public void loop() { - strafe = gamepad1.left_stick_x; + + detectSpeedChange(); + drive = gamepad1.left_stick_y; + strafe = gamepad1.left_stick_x; turn = gamepad1.right_stick_x; + telemetry.addData("Speed", "Current Speed = " + Math.round(speed*100)); + telemetry.update(); + driveMotors.drive(drive, strafe, turn, speed); + + } + + public void init(){ + driveMotors = new MotorControl(); + speed = 0.25; + } + + public void detectSpeedChange(){ if (gamepad1.dpad_up){ - if (driveMult<=1) { - driveMult += 0.0005; + if (speed <= 1) { + speed += 0.0005; } } if (gamepad1.dpad_down){ - if (driveMult>=0) { - driveMult -= 0.0005; + if (speed >= 0) { + speed -= 0.0005; } } - - telemetry.addData("Speed", "Current Speed = " + Math.round(driveMult*100)); - telemetry.update(); - - - frontRight.setPower(driveMult*(drive - strafe - turn)); - rearRight.setPower(driveMult*(drive + strafe - turn)); - frontLeft.setPower(-1*driveMult*(drive + strafe + turn)); - rearLeft.setPower(-1*driveMult*(drive - strafe + turn)); } - }