diff --git a/.idea/misc.xml b/.idea/misc.xml index e837843..481db9d 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,3 @@ - diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 1928482..231fba9 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -4,9 +4,8 @@ - + - @@ -57,7 +57,7 @@ } { "selectedUrlAndAccountId": { - "url": "https://github.com/Evolution2626/17070-revolution-2025.git", + "url": "https://github.com/Thierry-Lachance/17070-revolution-2025.git", "accountId": "142d07db-c560-4dca-9ea5-5ea9b1b05c52" } } @@ -80,8 +80,13 @@ "git-widget-placeholder": "main", "ignore.virus.scanning.warn.message": "true", "kotlin-language-version-configured": "true", - "last_opened_file_path": "C:/Users/thier/OneDrive/Documents/17070-revolution-2025", + "last_opened_file_path": "C:/Users/thier/cache-dumb-1", "settings.editor.selected.configurable": "preferences.pluginManager" + }, + "keyToStringList": { + "kotlin-gradle-user-dirs": [ + "C:\\Users\\thier\\cache-dumb-1" + ] } } @@ -169,11 +174,28 @@ - \ No newline at end of file diff --git a/TeamCode/build.gradle b/TeamCode/build.gradle index 878287a..bb92b7f 100644 --- a/TeamCode/build.gradle +++ b/TeamCode/build.gradle @@ -14,9 +14,13 @@ // Include common definitions from above. apply from: '../build.common.gradle' apply from: '../build.dependencies.gradle' +apply plugin: 'org.jetbrains.kotlin.android' android { namespace = 'org.firstinspires.ftc.teamcode' + kotlinOptions { + jvmTarget = '1.8' + } packagingOptions { jniLibs.useLegacyPackaging true @@ -25,4 +29,5 @@ android { dependencies { implementation project(':FtcRobotController') + implementation 'androidx.core:core-ktx:1.13.1' } diff --git a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/ArmFunction.kt b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/ArmFunction.kt new file mode 100644 index 0000000..763efc0 --- /dev/null +++ b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/ArmFunction.kt @@ -0,0 +1,14 @@ +package org.firstinspires.ftc.teamcode + +import com.qualcomm.robotcore.hardware.AnalogInput + +class ArmFunction { + companion object { + @JvmStatic + fun moveArm(power: Double, armSensor: AnalogInput): Double { + return if (power >= 0 && armSensor.voltage < 0.75) power + else if (power >= 0 && armSensor.voltage > 2.55) power + else 0.0 + } + } +} \ No newline at end of file diff --git a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/DrivetrainFunction.kt b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/DrivetrainFunction.kt new file mode 100644 index 0000000..770219f --- /dev/null +++ b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/DrivetrainFunction.kt @@ -0,0 +1,30 @@ +package org.firstinspires.ftc.teamcode + +import kotlin.math.abs + +class DrivetrainFunction { + + companion object { + @JvmStatic + fun calculateTicks(Cm: Double): Double { + + val COUNTS_PER_MOTOR_REV = 536.6 + + val WHEEL_DIAMETER_CM = 10.0 + + val COUNTS_PER_Cm = COUNTS_PER_MOTOR_REV / (WHEEL_DIAMETER_CM * 3.1415) + return COUNTS_PER_Cm * Cm + } + + @JvmStatic + fun calculatePower(targetPos: Double, currentPos: Double): Double { + return if (abs(targetPos - currentPos) > 50) { + if (abs(currentPos - targetPos) < 100) 0.25 + else if (abs(currentPos - targetPos) < 500) 0.50 + else if (abs(currentPos - targetPos) < 1000) 0.75 + else 1.0 + } else 0.0 + + } + } +} diff --git a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/ElevatorFunction.kt b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/ElevatorFunction.kt new file mode 100644 index 0000000..b41e131 --- /dev/null +++ b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/ElevatorFunction.kt @@ -0,0 +1,18 @@ +package org.firstinspires.ftc.teamcode + +import com.qualcomm.robotcore.hardware.DigitalChannel + +class ElevatorFunction { + companion object { + @JvmStatic + fun moveElevator( + power: Double, + elevatorIn: DigitalChannel, + elevatorOut: DigitalChannel + ): Double { + return if (elevatorIn.state && power >= 0) power + else if (elevatorOut.state && power >= 0) power + else 0.0 + } + } +} \ No newline at end of file diff --git a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/TeleOp.java b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/TeleOp.java index d346748..6960631 100644 --- a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/TeleOp.java +++ b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/TeleOp.java @@ -12,11 +12,6 @@ @com.qualcomm.robotcore.eventloop.opmode.TeleOp public class TeleOp extends LinearOpMode { - double flEncoderPos; - double frEncoderPos; - double blEncoderPos; - double brEncoderPos; - double armOutPos; double armInPos; double elevatorInPos; @@ -25,6 +20,7 @@ public class TeleOp extends LinearOpMode { Servo servo1; Servo servo2; + @Override public void runOpMode() throws InterruptedException { @@ -40,11 +36,6 @@ public void runOpMode() throws InterruptedException { DigitalChannel elevatorOut = hardwareMap.digitalChannel.get("elevatorOut"); AnalogInput armSensor = hardwareMap.analogInput.get("armSensor"); - double flEncoder = frontLeftMotor.getCurrentPosition(); - double frEncoder = frontRightMotor.getCurrentPosition(); - double blEncoder = backLeftMotor.getCurrentPosition(); - double brEncoder = backRightMotor.getCurrentPosition(); - frontRightMotor.setDirection(DcMotorSimple.Direction.REVERSE); backRightMotor.setDirection(DcMotorSimple.Direction.REVERSE); @@ -65,11 +56,6 @@ public void runOpMode() throws InterruptedException { armMotor.setMode(DcMotor.RunMode.RUN_USING_ENCODER); elevatorMotor.setMode(DcMotor.RunMode.RUN_USING_ENCODER); - flEncoderPos = flEncoder; - frEncoderPos = frEncoder; - blEncoderPos = blEncoder; - brEncoderPos = brEncoder; - elevatorInPos = elevatorMotor.getCurrentPosition(); armInPos = armMotor.getCurrentPosition(); @@ -90,21 +76,21 @@ public void runOpMode() throws InterruptedException { double backLeftPower = (y - x + rx) / denominator; double frontRightPower = (y - x - rx) / denominator; double backRightPower = (y + x - rx) / denominator; - if(gamepad1.x){ + if (gamepad1.x) { servo1.setPosition(0.25); servo2.setPosition(0.75); } - if(gamepad1.y){ + if (gamepad1.y) { servo1.setPosition(0.75); servo2.setPosition(0.25); } - if(gamepad1.a){ - moveElevator(1.0, elevatorMotor, elevatorIn, elevatorOut); - } - if(gamepad1.b){ - moveElevator(-1.0, elevatorMotor, elevatorIn, elevatorOut); - } + if (gamepad1.a) elevatorMotor.setPower(ElevatorFunction.moveElevator(1.0, elevatorIn, elevatorOut)); + + if (gamepad1.b) elevatorMotor.setPower(ElevatorFunction.moveElevator(-1.0, elevatorIn, elevatorOut)); + + if (gamepad1.left_bumper) armMotor.setPower(ArmFunction.moveArm(1.0, armSensor)); + if (gamepad1.right_bumper) armMotor.setPower(ArmFunction.moveArm(-1.0, armSensor)); frontLeftMotor.setPower(frontLeftPower); backLeftMotor.setPower(backLeftPower); @@ -112,28 +98,6 @@ public void runOpMode() throws InterruptedException { backRightMotor.setPower(backRightPower); } } - public void moveArm(double power, DcMotor armMotor, AnalogInput armSensor){ - if(power >= 0 && armSensor.getVoltage() < 0.75){ - armMotor.setPower(power); - } - if(power >= 0 && armSensor.getVoltage() > 2.55){ - armMotor.setPower(power); - } - else{ - armMotor.setPower(0.0); - } - } - public void moveElevator(double power, DcMotor elevatorMotor, DigitalChannel elevatorIn, DigitalChannel elevatorOut){ - if(elevatorIn.getState() && power >= 0){ - elevatorMotor.setPower(power); - } - if(elevatorOut.getState() && power >= 0){ - elevatorMotor.setPower(power); - } - else{ - elevatorMotor.setPower(0.0); - } - } } diff --git a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/autoTemplate.java b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/autoTemplate.java new file mode 100644 index 0000000..acb563f --- /dev/null +++ b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/autoTemplate.java @@ -0,0 +1,65 @@ +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; +import com.qualcomm.robotcore.hardware.DcMotorSimple; + + +@Autonomous +public class autoTemplate extends LinearOpMode { + + DcMotor frontLeftMotor; + DcMotor backLeftMotor; + DcMotor frontRightMotor; + DcMotor backRightMotor; + + @Override + public void runOpMode() throws InterruptedException { + frontLeftMotor = hardwareMap.dcMotor.get("frontLeft"); + backLeftMotor = hardwareMap.dcMotor.get("backLeft"); + frontRightMotor = hardwareMap.dcMotor.get("frontRight"); + backRightMotor = hardwareMap.dcMotor.get("backRight"); + + + frontRightMotor.setDirection(DcMotorSimple.Direction.REVERSE); + backRightMotor.setDirection(DcMotorSimple.Direction.REVERSE); + + frontLeftMotor.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER); + frontLeftMotor.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER); + frontRightMotor.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER); + frontRightMotor.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER); + backLeftMotor.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER); + backLeftMotor.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER); + backRightMotor.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER); + backRightMotor.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER); + + waitForStart(); + + while (opModeIsActive()) { + double targetFL = DrivetrainFunction.calculateTicks(60.0); + double targetFR = DrivetrainFunction.calculateTicks(60.0); + double targetBL = DrivetrainFunction.calculateTicks(60.0); + double targetBR = DrivetrainFunction.calculateTicks(60.0); + encoderDrive(targetFL, targetFR, targetBL, targetBR); + + } + } + + public void encoderDrive(double targetFL, double targetFR, double targetBL, double targetBR) { + while (DrivetrainFunction.calculatePower(targetFL, frontLeftMotor.getCurrentPosition()) != 0 + && DrivetrainFunction.calculatePower(targetFR, frontRightMotor.getCurrentPosition()) != 0 + && DrivetrainFunction.calculatePower(targetBL, backLeftMotor.getCurrentPosition()) != 0 + && DrivetrainFunction.calculatePower(targetBR, backRightMotor.getCurrentPosition()) != 0) { + frontLeftMotor.setPower(DrivetrainFunction.calculatePower(targetFL, frontLeftMotor.getCurrentPosition())); + frontRightMotor.setPower(DrivetrainFunction.calculatePower(targetFR, frontRightMotor.getCurrentPosition())); + backLeftMotor.setPower(DrivetrainFunction.calculatePower(targetBL, backLeftMotor.getCurrentPosition())); + backRightMotor.setPower(DrivetrainFunction.calculatePower(targetBR, backRightMotor.getCurrentPosition())); + } + + + } + + +} + diff --git a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/autoTest.java b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/autoTest.java index 4549927..4bceb7b 100644 --- a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/autoTest.java +++ b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/autoTest.java @@ -1,13 +1,14 @@ package org.firstinspires.ftc.teamcode; import com.qualcomm.robotcore.eventloop.opmode.Autonomous; +import com.qualcomm.robotcore.eventloop.opmode.Disabled; import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode; import com.qualcomm.robotcore.hardware.DcMotor; import com.qualcomm.robotcore.hardware.DcMotorSimple; - +@Disabled @Autonomous public class autoTest extends LinearOpMode { diff --git a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/autoTest2.java b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/autoTest2.java deleted file mode 100644 index af7fa1a..0000000 --- a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/autoTest2.java +++ /dev/null @@ -1,82 +0,0 @@ -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; -import com.qualcomm.robotcore.hardware.DcMotorSimple; - - - - -@Autonomous -public class autoTest2 extends LinearOpMode { - - - - static final double COUNTS_PER_MOTOR_REV = 536.6 ; - static final double WHEEL_DIAMETER_CM = 10.0 ; - static final double COUNTS_PER_Cm = COUNTS_PER_MOTOR_REV / (WHEEL_DIAMETER_CM * 3.1415); - - DcMotor frontLeftMotor; - DcMotor backLeftMotor; - DcMotor frontRightMotor; - DcMotor backRightMotor; - - @Override - public void runOpMode() throws InterruptedException { - frontLeftMotor = hardwareMap.dcMotor.get("frontLeft"); - backLeftMotor = hardwareMap.dcMotor.get("backLeft"); - frontRightMotor = hardwareMap.dcMotor.get("frontRight"); - backRightMotor = hardwareMap.dcMotor.get("backRight"); - - - - frontRightMotor.setDirection(DcMotorSimple.Direction.REVERSE); - backRightMotor.setDirection(DcMotorSimple.Direction.REVERSE); - - frontLeftMotor.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER); - frontLeftMotor.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER); - frontRightMotor.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER); - frontRightMotor.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER); - backLeftMotor.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER); - backLeftMotor.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER); - backRightMotor.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER); - backRightMotor.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER); - - waitForStart(); - - encoderDrive(30.0, 30.0, 30.0, 30.0); - encoderDrive(30.0, 30.0, 30.0, 30.0); - encoderDrive(30.0, -30.0, 30.0, -30.0); - } - public void encoderDrive( - double flCm, double frCm, double blCm, double brCm) { - double newflTarget = 0.0; - double newfrTarget = 0.0; - double newblTarget = 0.0; - double newbrTarget = 0.0; - - - if (opModeIsActive()) { - - newflTarget = frontLeftMotor.getCurrentPosition() + (flCm * COUNTS_PER_Cm); - newfrTarget = frontRightMotor.getCurrentPosition() + (frCm * COUNTS_PER_Cm); - newblTarget = backLeftMotor.getCurrentPosition() + (blCm * COUNTS_PER_Cm); - newbrTarget = backRightMotor.getCurrentPosition() + (brCm * COUNTS_PER_Cm); - - frontLeftMotor.setTargetPosition((int) newflTarget); - frontRightMotor.setTargetPosition((int)newfrTarget); - backLeftMotor.setTargetPosition((int)newblTarget); - backRightMotor.setTargetPosition((int)newbrTarget); - - - while (opModeIsActive() && - - (frontLeftMotor.isBusy() || frontRightMotor.isBusy() || backLeftMotor.isBusy() || backRightMotor.isBusy())){ - } - - - } - - } -} diff --git a/build.gradle b/build.gradle index 8969a41..683e499 100644 --- a/build.gradle +++ b/build.gradle @@ -5,6 +5,9 @@ */ buildscript { + ext { + kotlin_version = '2.0.21' + } repositories { mavenCentral() google() @@ -12,6 +15,7 @@ buildscript { dependencies { // Note for FTC Teams: Do not modify this yourself. classpath 'com.android.tools.build:gradle:7.2.0' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } }