diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..badf2b0 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + 1692405701251 + + + + diff --git a/FtcRobotController-8.2/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/Schedule.java b/FtcRobotController-8.2/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/Schedule.java new file mode 100644 index 0000000..73b58a1 --- /dev/null +++ b/FtcRobotController-8.2/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/Schedule.java @@ -0,0 +1,20 @@ +package org.firstinspires.ftc.teamcode; + +import androidx.annotation.NonNull; + +import java.util.ArrayList; +import java.util.List; + +public class Schedule { + List CommandList = new ArrayList(); + + public void Scheduler() { + } + public void add(String Command){ + CommandList.add(Command); + } + + public void update(){ + + } +} \ No newline at end of file diff --git a/FtcRobotController-8.2/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/ServoControlExample.java b/FtcRobotController-8.2/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/ServoControlExample.java new file mode 100644 index 0000000..854f17e --- /dev/null +++ b/FtcRobotController-8.2/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/ServoControlExample.java @@ -0,0 +1,54 @@ +package org.firstinspires.ftc.teamcode;// Import necessary classes from the FTC SDK +import com.qualcomm.robotcore.eventloop.opmode.TeleOp; +import com.qualcomm.robotcore.hardware.Servo; +import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode; +import com.qualcomm.robotcore.util.ElapsedTime; +import com.qualcomm.robotcore.util.Range; + +import org.firstinspires.ftc.robotcore.external.Telemetry; + +// Define your custom OpMode class +@TeleOp(name = "ServoControlExample", group = "FTC") +public class ServoControlExample extends LinearOpMode { + + // Declare servo and other variables + + private ElapsedTime runtime = new ElapsedTime(); + Servo servo1; + + @Override + public void runOpMode() { + + // Initialize servo + servo1 = hardwareMap.get(Servo.class, "servo1"); + + // Wait for the start button to be pressed on the driver station + waitForStart(); + + // Main loop + while (opModeIsActive()) { + + // Control the servo position + + + { + + // Add telemetry to display servo position on the driver station + while (opModeIsActive()) { + if(gamepad1.x) { + double targetPosition = 1; // Adjust this value as needed + servo1.setPosition(1.0); + } + telemetry.addData("Servo Position", servo1.getPosition()); + telemetry.addData("Status", "Initialized"); + servo1 = hardwareMap.servo.get("servo1"); + telemetry.addData("Status", "Run Time: " + runtime.toString()); + telemetry.update(); + + // Sleep for a short period to avoid continuous servo movement + sleep(1); // Adjust the sleep time as needed + } + } + } + } + } diff --git a/FtcRobotController-8.2/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/Test.java b/FtcRobotController-8.2/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/Test.java new file mode 100644 index 0000000..04b609b --- /dev/null +++ b/FtcRobotController-8.2/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/Test.java @@ -0,0 +1,104 @@ +package org.firstinspires.ftc.teamcode; + +import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode; + +import com.qualcomm.robotcore.eventloop.opmode.TeleOp; + +import com.qualcomm.robotcore.hardware.DcMotor; + + +@TeleOp + +public class Test extends LinearOpMode { + +//Initialise motors, classes, and sensors here + + private DcMotor Arm1; + //private DcMotor Left_Front; + //private DcMotor Right_Front; + //private DcMotor Left_Back; + //private DcMotor Right_Back; + + PID1 PID = new PID1(1,1,1); + + + @Override + + public void runOpMode() throws InterruptedException { + //Left_Front = hardwareMap.dcMotor.get("Left_Front"); + //Right_Front = hardwareMap.dcMotor.get("Right_Front"); + //Left_Back = hardwareMap.dcMotor.get("Left_Back"); + //Right_Back = hardwareMap.dcMotor.get("Right_Back"); + Arm1 = hardwareMap.dcMotor.get("Arm1"); + + // Wait for the game to start (driver presses PLAY) + + waitForStart(); + + // run until the end of the match (driver presses STOP) + + while (opModeIsActive()) { + //stuff + double speed; + /*double vertical; + //double horizontal; + //double pivot; + //vertical = -gamepad1.left_stick_y; + //horizontal = gamepad1.left_stick_x; + pivot = -gamepad1.right_stick_x; + */ + + speed = (Arm1.getCurrentPosition()-Arm1.getCurrentPosition())/(time-time); + + //Mecanum drive + + /*Right_Front.setPower(pivot + (-vertical + horizontal)); + //Right_Back.setPower(pivot + (-vertical - horizontal)); + //Left_Back.setPower(pivot + (vertical - horizontal)); + Left_Front.setPower(pivot + (vertical + horizontal)); + */ + waitForStart(); + + + //Code for arm + + while (opModeIsActive()) { + PID.setPID(.0001,.0 ,.0); + Arm1.setTargetPosition(PID.getSetPoint()); + Arm1.setMode(DcMotor.RunMode.RUN_TO_POSITION); + if (gamepad1.b) { + PID.setSetPoint(100); + Arm1.setPower(1); + + } + if (gamepad1.x) { + PID.setSetPoint(100); + PID.updatePID(Arm1.getCurrentPosition()); + Arm1.setPower(PID.getResult()); + telemetry.addData("speed",speed); + } + else { + Arm1.setPower(0); + } resetRuntime(); + Arm1.getCurrentPosition(); + + } + + //adding data + telemetry.addData("speed",speed); + telemetry.addData("Arm Encode", Arm1.getCurrentPosition()); + telemetry.addData("Arm Inches", ticksToInches(Arm1.getCurrentPosition())); + telemetry.addData("PID Result", PID.getResult()); + telemetry.update(); + } + + } + + //units for stuff + + public double ticksToInches(double ticks) { + double inches = ticks / 52; + return inches; + } + + } \ No newline at end of file diff --git a/FtcRobotController-8.2/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/grab/DriveWithGripper.java b/FtcRobotController-8.2/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/grab/DriveWithGripper.java new file mode 100644 index 0000000..501d514 --- /dev/null +++ b/FtcRobotController-8.2/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/grab/DriveWithGripper.java @@ -0,0 +1,60 @@ +package org.firstinspires.ftc.teamcode.grab; +import com.qualcomm.robotcore.eventloop.opmode.TeleOp; +import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode; +import com.qualcomm.robotcore.hardware.DcMotor; +import com.qualcomm.robotcore.hardware.Servo; +import com.qualcomm.robotcore.hardware.CRServo; +import com.qualcomm.robotcore.util.Range; + +import org.firstinspires.ftc.teamcode.PID1; + + +@TeleOp(name = "Drive Gripper", group = "Exercises") +//@Disabled + public class DriveWithGripper extends LinearOpMode { + + + CRServo contServo; + float leftY, rightY; + double armPosition, gripPosition, contPower; + double MIN_POSITION = 0, MAX_POSITION = 1; + //PID1 PID = new PID1(1,1,0); + // called when init button is pressed. + @Override + public void runOpMode() throws InterruptedException { + contServo = hardwareMap.crservo.get("contServo"); + + telemetry.addData("Mode", "waiting"); + telemetry.update(); + + // wait for start button. + + waitForStart(); + + armPosition = .5; // set arm to half way up. + gripPosition = MAX_POSITION; // set grip to full open. + + while (opModeIsActive()) { + + + ; + telemetry.addData("Mode", "running"); + + //PID.setPID(.01,.0 ,.0); + if (gamepad1.x) { + + contPower =1; + } + else if (gamepad1.b) + contPower = -1; + else + contPower = 0.0; + + + contServo.setPower(contPower); + + telemetry.update(); + idle(); + } + } + } diff --git a/FtcRobotController-8.2/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/servo.java b/FtcRobotController-8.2/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/servo.java new file mode 100644 index 0000000..e69de29 diff --git a/FtcRobotController-8.2/unnamed.patch b/FtcRobotController-8.2/unnamed.patch new file mode 100644 index 0000000..a5e4589 --- /dev/null +++ b/FtcRobotController-8.2/unnamed.patch @@ -0,0 +1,101 @@ +Index: FtcRobotController-8.2/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/grab/DriveWithGripper.java +IDEA additional info: +Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP +<+>UTF-8 +=================================================================== +diff --git a/FtcRobotController-8.2/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/grab/DriveWithGripper.java b/FtcRobotController-8.2/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/grab/DriveWithGripper.java +new file mode 100644 +--- /dev/null (revision 348911fb2dc443f65a972dc058199c8661fcbc06) ++++ b/FtcRobotController-8.2/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/grab/DriveWithGripper.java (revision 348911fb2dc443f65a972dc058199c8661fcbc06) +@@ -0,0 +1,91 @@ ++package org.firstinspires.ftc.teamcode.grab; ++import com.qualcomm.robotcore.eventloop.opmode.TeleOp; ++import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode; ++import com.qualcomm.robotcore.hardware.DcMotor; ++import com.qualcomm.robotcore.hardware.Servo; ++import com.qualcomm.robotcore.hardware.CRServo; ++import com.qualcomm.robotcore.util.Range; ++ ++import org.firstinspires.ftc.teamcode.PID1; ++ ++ ++@TeleOp(name = "Drive Gripper", group = "Exercises") ++//@Disabled ++ public class DriveWithGripper extends LinearOpMode { ++ ++ ++ CRServo contServo; ++ float leftY, rightY; ++ double armPosition, gripPosition, contPower; ++ double MIN_POSITION = 0, MAX_POSITION = 1; ++ PID1 PID = new PID1(); ++ // called when init button is pressed. ++ @Override ++ public void runOpMode() throws InterruptedException { ++ ++ ++ ++ contServo = hardwareMap.crservo.get("contServo"); ++ ++ telemetry.addData("Mode", "waiting"); ++ telemetry.update(); ++ ++ // wait for start button. ++ ++ waitForStart(); ++ ++ armPosition = .5; // set arm to half way up. ++ gripPosition = MAX_POSITION; // set grip to full open. ++ ++ while (opModeIsActive()) { ++ ++ ++ ; ++ telemetry.addData("Mode", "running"); ++ ++ // check the gamepad buttons and if pressed, increment the appropriate position ++ // variable to change the servo location. ++ ++ // move arm down on A button if not already at lowest position. ++ if (gamepad1.a && armPosition > MIN_POSITION) armPosition -= .01; ++ ++ // move arm up on B button if not already at the highest position. ++ if (gamepad1.b && armPosition < MAX_POSITION) armPosition += .01; ++ ++ // open the gripper on X button if not already at most open position. ++ if (gamepad1.x && gripPosition < MAX_POSITION) gripPosition = gripPosition + .01; ++ ++ // close the gripper on Y button if not already at the closed position. ++ if (gamepad1.y && gripPosition > MIN_POSITION) gripPosition = gripPosition - .01; ++ ++ // Set continuous servo power level and direction. ++ PID.setPID(.01,.0 ,.0); ++ if (gamepad1.x) { ++ ++ contPower =1; ++ } ++ else if (gamepad1.b) ++ contPower = -1; ++ else ++ contPower = 0.0; ++ ++ // set the servo position/power values as we have computed them. ++ ++ contServo.setPower(contPower); ++ ++ ++ //telemetry.addData("arm servo", String.format("position=%.2f actual=%.2f", armPosition, ++ // armServo.getPosition())); ++ ++ //telemetry.addData("grip servo", String.format("position=%.2f actual=%.2f", gripPosition, ++ // gripServo.getPosition())); ++ ++ //telemetry.addData("arm servo", "position=%.2f actual=%.2f", armPosition, armServo.getPosition()); ++ ++ //telemetry.addData("grip servo", "position=%.2f actual=%.2f", gripPosition, gripServo.getPosition()); ++ ++ telemetry.update(); ++ idle(); ++ } ++ } ++ }