velocity math: to test

This commit is contained in:
DanTheMan-byte
2025-11-18 22:47:58 -06:00
parent e5ba0947e3
commit 8d75b245e3
4 changed files with 88 additions and 199 deletions

View File

@@ -2,9 +2,12 @@ package org.firstinspires.ftc.teamcode.subsystems;
import static org.firstinspires.ftc.teamcode.tests.ShooterTest.*;
import static java.lang.Runtime.getRuntime;
import com.acmerobotics.dashboard.telemetry.MultipleTelemetry;
import com.acmerobotics.roadrunner.Pose2d;
import com.arcrobotics.ftclib.controller.PIDController;
import com.arcrobotics.ftclib.controller.PIDFController;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.hardware.DcMotorEx;
import com.qualcomm.robotcore.hardware.PIDCoefficients;
@@ -42,7 +45,7 @@ public class Shooter implements Subsystem {
private double p = 0.0003, i = 0, d = 0.00001;
private PIDController controller;
private PIDFController controller;
private double pow = 0.0;
private String shooterMode = "AUTO";
@@ -62,9 +65,9 @@ public class Shooter implements Subsystem {
fly1.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
fly1.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
controller = new PIDController(p, i, d);
controller = new PIDFController(p, i, d, f);
controller.setPID(p, i, d);
controller.setPIDF(p, i, d, f);
this.turret1 = robot.turr1;
@@ -83,11 +86,9 @@ public class Shooter implements Subsystem {
telemetry.addData("ECPR Revolutions", getECPRPosition());
telemetry.addData("MCPR Revolutions", getMCPRPosition());
telemetry.addData("TargetPosition", targetPosition);
telemetry.addData("Velocity", getVelocity(mcpr) * 60);
telemetry.addData("TargetVelocity", velocity);
telemetry.addData("hoodPos", gethoodPosition());
telemetry.addData("turretPos", getTurretPosition());
telemetry.addData("PID Coefficients", "P: %.6f, I: %.6f, D: %.6f", p, i, d);
telemetry.addData("Power Fly 1", fly1.getPower());
telemetry.addData("Power Fly 2", fly2.getPower());
telemetry.addData("Pow", pow);
@@ -106,8 +107,8 @@ public class Shooter implements Subsystem {
public void setTurretPosition(double pos) { turretPos = pos; }
public double getVelocity(double cpr) {
return 60 * (fly1.getVelocity() / (2 * cpr));
public double getVelocity(double initPos) {
return (getECPRPosition() - initPos);
}
public void setVelocity(double vel) { velocity = vel; }
@@ -122,11 +123,12 @@ public class Shooter implements Subsystem {
controller.setTolerance(tolerance);
}
public void setControllerCoefficients(double kp, double ki, double kd) {
public void setControllerCoefficients(double kp, double ki, double kd, double kf) {
p = kp;
i = ki;
d = kd;
controller.setPID(p, i, d);
f = kf;
controller.setPIDF(p, i, d, f);
}
@@ -143,11 +145,11 @@ public class Shooter implements Subsystem {
public String getTurretMode() { return turretMode; }
public double getECPRPosition() {
return (fly1.getCurrentPosition() * 720 / ecpr);
return fly1.getCurrentPosition() / (2 * ecpr);
}
public double getMCPRPosition() {
return (fly1.getCurrentPosition() * 720) / mcpr;
return fly1.getCurrentPosition() / (2 * mcpr);
}
public void setShooterMode(String mode) { shooterMode = mode; }
@@ -250,7 +252,7 @@ public class Shooter implements Subsystem {
fly1.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
fly2.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
double powPID = controller.calculate(getVelocity(mcpr) * ecpr, velocity);
double powPID = controller.calculate(fly1.getVelocity(), velocity);
fly1.setPower(powPID);
fly2.setPower(powPID);

View File

@@ -3,7 +3,6 @@ package org.firstinspires.ftc.teamcode.teleop;
import static org.firstinspires.ftc.teamcode.constants.Poses.*;
import static org.firstinspires.ftc.teamcode.constants.ServoPositions.*;
import com.acmerobotics.dashboard.FtcDashboard;
import com.acmerobotics.dashboard.config.Config;
import com.acmerobotics.dashboard.telemetry.MultipleTelemetry;
@@ -23,13 +22,11 @@ import org.firstinspires.ftc.teamcode.subsystems.Spindexer;
import org.firstinspires.ftc.teamcode.subsystems.Transfer;
import org.firstinspires.ftc.teamcode.utils.Robot;
@Config
@TeleOp
public class TeleopV1 extends LinearOpMode {
Robot robot;
Drivetrain drivetrain;
@@ -64,7 +61,6 @@ public class TeleopV1 extends LinearOpMode {
ToggleButtonReader g2Square;
ToggleButtonReader g2Triangle;
ToggleButtonReader g2RightBumper;
@@ -86,7 +82,6 @@ public class TeleopV1 extends LinearOpMode {
public double g1LeftBumperStamp = 0.0;
public double g2LeftBumperStamp = 0.0;
public static int spindexerPos = 0;
@@ -118,17 +113,11 @@ public class TeleopV1 extends LinearOpMode {
public boolean tri = false;
@Override
public void runOpMode() throws InterruptedException {
drive = new MecanumDrive(hardwareMap, teleStart);
robot = new Robot(hardwareMap);
TELE = new MultipleTelemetry(
@@ -164,7 +153,6 @@ public class TeleopV1 extends LinearOpMode {
g2, GamepadKeys.Button.RIGHT_BUMPER
);
g2LeftBumper = new ToggleButtonReader(
g2, GamepadKeys.Button.LEFT_BUMPER
);
@@ -173,7 +161,6 @@ public class TeleopV1 extends LinearOpMode {
g2, GamepadKeys.Button.DPAD_UP
);
g2DpadDown = new ToggleButtonReader(
g2, GamepadKeys.Button.DPAD_DOWN
);
@@ -182,14 +169,10 @@ public class TeleopV1 extends LinearOpMode {
g2, GamepadKeys.Button.DPAD_LEFT
);
g2DpadRight = new ToggleButtonReader(
g2, GamepadKeys.Button.DPAD_RIGHT
);
drivetrain = new Drivetrain(robot, TELE, g1);
drivetrain.setMode("Default");
@@ -202,7 +185,6 @@ public class TeleopV1 extends LinearOpMode {
transfer = new Transfer(robot);
spindexer = new Spindexer(robot, TELE);
spindexer.setTelemetryOn(true);
@@ -213,16 +195,12 @@ public class TeleopV1 extends LinearOpMode {
robot.rejecter.setPosition(rIn);
waitForStart();
if (isStopRequested()) return;
drive = new MecanumDrive(hardwareMap, teleStart);
while (opModeIsActive()) {
drive.updatePoseEstimate();
@@ -231,11 +209,9 @@ public class TeleopV1 extends LinearOpMode {
TELE.addData("heading", drive.localizer.getPose().heading.toDouble());
TELE.addData("off", offset);
robot.transferServo.setPosition(transferServoPos);
robot.hood.setPosition(pos);
g1LeftBumper.readValue();
@@ -243,8 +219,6 @@ public class TeleopV1 extends LinearOpMode {
if (g1LeftBumper.wasJustPressed()) {
g2LeftBumperStamp = getRuntime();
spindexer.intakeShake(getRuntime());
leftBumper = true;
@@ -261,9 +235,6 @@ public class TeleopV1 extends LinearOpMode {
}
intake();
drivetrain.update();
@@ -304,22 +275,10 @@ public class TeleopV1 extends LinearOpMode {
offset += 0.02;
}
TELE.addData("hood", pos);
if (Math.abs(gamepad2.right_stick_x) < 0.1 && autotrack) {
shooter.trackGoal(drive.localizer.getPose(), new Pose2d(-10, 0, 0), offset);
} else {
@@ -334,8 +293,6 @@ public class TeleopV1 extends LinearOpMode {
autotrack = true;
}
if (g2RightBumper.wasJustPressed()) {
transfer.setTransferPower(1);
transfer.transferIn();
@@ -366,7 +323,6 @@ public class TeleopV1 extends LinearOpMode {
if (scoreAll) {
double time = getRuntime() - g2LeftBumperStamp;
shooter.setManualPower(1);
TELE.addData("greenImportant", green);
@@ -378,7 +334,6 @@ public class TeleopV1 extends LinearOpMode {
if (square) {
if (time < 0.3) {
ticker = 0;
@@ -386,7 +341,6 @@ public class TeleopV1 extends LinearOpMode {
last = 0;
second = 0;
transfer.transferOut();
transfer.setTransferPower(1);
} else if (time < 2) {
@@ -407,14 +361,12 @@ public class TeleopV1 extends LinearOpMode {
ticker++;
} else if (time < 2.5) {
ticker = 0;
second = last;
transfer.transferIn();
} else if (time < 4) {
transfer.transferOut();
@@ -434,11 +386,9 @@ public class TeleopV1 extends LinearOpMode {
ticker = 0;
transfer.transferIn();
} else if (time < 6) {
transfer.transferOut();
if (ticker == 0) {
@@ -459,7 +409,6 @@ public class TeleopV1 extends LinearOpMode {
ticker = 0;
scoreAll = false;
transfer.transferOut();
@@ -468,7 +417,6 @@ public class TeleopV1 extends LinearOpMode {
}
} else if (tri) {
if (time < 0.3) {
ticker = 0;
@@ -476,7 +424,6 @@ public class TeleopV1 extends LinearOpMode {
last = 0;
second = 0;
transfer.transferOut();
transfer.setTransferPower(1);
} else if (time < 2) {
@@ -497,14 +444,12 @@ public class TeleopV1 extends LinearOpMode {
ticker++;
} else if (time < 2.5) {
ticker = 0;
second = last;
transfer.transferIn();
} else if (time < 4) {
transfer.transferOut();
@@ -524,11 +469,9 @@ public class TeleopV1 extends LinearOpMode {
ticker = 0;
transfer.transferIn();
} else if (time < 6) {
transfer.transferOut();
if (ticker == 0) {
@@ -549,7 +492,6 @@ public class TeleopV1 extends LinearOpMode {
ticker = 0;
scoreAll = false;
transfer.transferOut();
@@ -558,7 +500,6 @@ public class TeleopV1 extends LinearOpMode {
}
} else if (circle) {
if (time < 0.3) {
ticker = 0;
@@ -566,7 +507,6 @@ public class TeleopV1 extends LinearOpMode {
last = 0;
second = 0;
transfer.transferOut();
transfer.setTransferPower(1);
} else if (time < 2) {
@@ -587,14 +527,12 @@ public class TeleopV1 extends LinearOpMode {
ticker++;
} else if (time < 2.5) {
ticker = 0;
second = last;
transfer.transferIn();
} else if (time < 4) {
transfer.transferOut();
@@ -614,11 +552,9 @@ public class TeleopV1 extends LinearOpMode {
ticker = 0;
transfer.transferIn();
} else if (time < 6) {
transfer.transferOut();
if (ticker == 0) {
@@ -639,7 +575,6 @@ public class TeleopV1 extends LinearOpMode {
ticker = 0;
scoreAll = false;
transfer.transferOut();
@@ -648,7 +583,6 @@ public class TeleopV1 extends LinearOpMode {
}
} else {
if (time < 0.3) {
ticker = 0;
@@ -669,7 +603,6 @@ public class TeleopV1 extends LinearOpMode {
all = true;
}
transfer.transferOut();
transfer.setTransferPower(1);
} else if (time < 2) {
@@ -694,7 +627,6 @@ public class TeleopV1 extends LinearOpMode {
ticker++;
} else if (time < 2.5) {
ticker = 0;
@@ -711,7 +643,6 @@ public class TeleopV1 extends LinearOpMode {
all = false;
}
transfer.transferIn();
@@ -737,7 +668,6 @@ public class TeleopV1 extends LinearOpMode {
ticker = 0;
if (gamepad2.right_trigger > 0.5) {
green = false;
@@ -752,7 +682,6 @@ public class TeleopV1 extends LinearOpMode {
transfer.transferIn();
} else if (time < 6) {
transfer.transferOut();
if (ticker == 0) {
@@ -775,7 +704,6 @@ public class TeleopV1 extends LinearOpMode {
ticker = 0;
scoreAll = false;
transfer.transferOut();
@@ -783,34 +711,17 @@ public class TeleopV1 extends LinearOpMode {
}
}
}
shooter.update();
}
}
public void intake() {
g1RightBumper.readValue();
g2Circle.readValue();
@@ -823,9 +734,6 @@ public class TeleopV1 extends LinearOpMode {
notShooting = true;
if (getRuntime() - g1RightBumperStamp < 0.3) {
intake.reverse();
} else {
@@ -836,19 +744,14 @@ public class TeleopV1 extends LinearOpMode {
shooter.setManualPower(0);
}
spindexer.intake();
transfer.transferOut();
g1RightBumperStamp = getRuntime();
}
if (intake.getIntakeState() == 1 && notShooting) {
spindexer.intakeShake(getRuntime());
@@ -859,8 +762,6 @@ public class TeleopV1 extends LinearOpMode {
tri = false;
square = false;
}
if (g2Triangle.wasJustPressed()) {
@@ -881,22 +782,11 @@ public class TeleopV1 extends LinearOpMode {
square = false;
}
}
intake.update();
spindexer.update();
}
}

View File

@@ -1,8 +1,14 @@
package org.firstinspires.ftc.teamcode.tests;
import android.app.Notification;
import androidx.annotation.NonNull;
import com.acmerobotics.dashboard.FtcDashboard;
import com.acmerobotics.dashboard.config.Config;
import com.acmerobotics.dashboard.telemetry.MultipleTelemetry;
import com.acmerobotics.dashboard.telemetry.TelemetryPacket;
import com.acmerobotics.roadrunner.Action;
import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
@@ -20,12 +26,14 @@ public class ShooterTest extends LinearOpMode {
public static double pow = 0.0;
public static double vel = 0.0;
public static double mcpr = 28; // CPR of the motor
public static double mcpr = 28.0; // CPR of the motor
public static double ecpr = 1024.0; // CPR of the encoder
public static int pos = 0;
public static double posPower = 0.0;
public static double p = 0.001, i = 0, d = 0;
public static double posi = 0.5;
public static double p = 0.001, i = 0, d = 0, f = 0;
public static String flyMode = "MANUAL";
@@ -35,8 +43,18 @@ public class ShooterTest extends LinearOpMode {
public static double servoPosition = 0.501;
public double stamp = 0.0;
public double initPos = 0.0;
public static double time = 1.0;
MultipleTelemetry TELE;
public boolean wait(double time) {
return (getRuntime() - stamp) > time;
}
@Override
public void runOpMode() throws InterruptedException {
@@ -52,7 +70,7 @@ public class ShooterTest extends LinearOpMode {
shooter.setShooterMode(flyMode);
shooter.setControllerCoefficients(p, i, d);
shooter.setControllerCoefficients(p, i, d, f);
waitForStart();
@@ -60,7 +78,7 @@ public class ShooterTest extends LinearOpMode {
while (opModeIsActive()) {
shooter.setControllerCoefficients(p, i, d);
shooter.setControllerCoefficients(p, i, d, f);
shooter.setTurretMode(turrMode);
@@ -72,6 +90,8 @@ public class ShooterTest extends LinearOpMode {
shooter.setTargetPosition(pos);
shooter.setTurretPosition(posi);
shooter.setTolerance(posTolerance);
shooter.setPosPower(posPower);
@@ -80,6 +100,11 @@ public class ShooterTest extends LinearOpMode {
shooter.update();
if (wait(time)){
telemetry.addData("Velocity", shooter.getVelocity(initPos));
stamp = getRuntime();
initPos = shooter.getECPRPosition();
}
TELE.update();
}

View File

@@ -30,8 +30,6 @@ public class Robot {
public DcMotorEx transfer;
public DcMotorEx shooter1;
public DcMotorEx shooter2;
public Servo hood;
@@ -63,24 +61,10 @@ public class Robot {
public AprilTagProcessor aprilTagProcessor;
public WebcamName webcam;
public DcMotorEx shooterEncoder;
public Robot(HardwareMap hardwareMap) {
//Define components w/ hardware map
@@ -106,10 +90,6 @@ public class Robot {
shooter2.setDirection(DcMotorSimple.Direction.REVERSE);
hood = hardwareMap.get(Servo.class, "hood");
turr1 = hardwareMap.get(Servo.class, "t1");
@@ -132,11 +112,8 @@ public class Robot {
pin5 = hardwareMap.get(DigitalChannel.class, "pin5");
analogInput = hardwareMap.get(AnalogInput.class, "analog");
analogInput2 = hardwareMap.get(AnalogInput.class, "analog2");
transfer = hardwareMap.get(DcMotorEx.class, "transfer");
@@ -147,12 +124,7 @@ public class Robot {
aprilTagProcessor = AprilTagProcessor.easyCreateWithDefaults();
webcam = hardwareMap.get(WebcamName.class, "Webcam 1");
}
}