From 80c29131ad2771146196607285431e7cb21251e2 Mon Sep 17 00:00:00 2001 From: GZod01 Date: Sat, 13 Jul 2024 15:23:33 +0200 Subject: [PATCH] hell --- MaxSpeed.java | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 MaxSpeed.java diff --git a/MaxSpeed.java b/MaxSpeed.java new file mode 100644 index 0000000..2e9c6fc --- /dev/null +++ b/MaxSpeed.java @@ -0,0 +1,72 @@ +package org.firstinspires.ftc.teamcode; +import java.io.File; // Import the File class +import java.io.IOException; // Import the IOException class to handle errors +import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode; +import org.firstinspires.ftc.robotcore.external.Telemetry; +import com.qualcomm.robotcore.robot.Robot; +import com.qualcomm.robotcore.hardware.DcMotorEx; + + +@TeleOp +public class MaxVelocityTest extends LinearOpMode { + DcMotorEx motor; + double currentVelocity; + double maxVelocity = 0.0; + + + @Override + public void runOpMode() { + motor = hardwareMap.get(DcMotorEx.class, "elv1"); + motor.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER); + motor.setPower(1); + waitForStart(); + + + while (opModeIsActive()) { + currentVelocity = motor.getVelocity(); + + if (currentVelocity > maxVelocity) { + maxVelocity = currentVelocity; + } + + telemetry.addData("current velocity", currentVelocity); + telemetry.addData("maximum velocity", maxVelocity); + telemetry.update(); + } + } + private void writeFile(String filename, String content){ + File file = getFile(filename); + FileOutputStream stream = new FileOutputStream(file); + try { + stream.write(content.getBytes()); + } finally { + stream.close(); + } + } + private File getFile(String filename){ + File file = new File(filename); + try{ + file.createNewFile(); + } + return file; + } + + private String readFile(String filename){ + File file = getFile(filename); + int length = (int) file.length(); + + byte[] bytes = new byte[length]; + + FileInputStream in = new FileInputStream(file); + try { + in.read(bytes); + } finally { + in.close(); + } + + String contents = new String(bytes); + return contents; + } + +} +