Skip to content

Commit

Permalink
Finished Challenge #5 with the boys
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Wood committed Jan 5, 2024
1 parent 026056d commit d43a9e6
Show file tree
Hide file tree
Showing 9 changed files with 307 additions and 13 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id "java"
id "edu.wpi.first.GradleRIO" version "2023.4.2"
id "edu.wpi.first.GradleRIO" version "2023.4.3"
id "com.peterabeles.gversion" version "1.10"
}

Expand Down
31 changes: 21 additions & 10 deletions src/main/java/frc/robot/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@
import frc.robot.util.TunableNumber;

/**
* The Constants class provides a convenient place for teams to hold robot-wide
* numerical or boolean constants. This class should not be used for any other
* purpose. All constants should be declared globally (i.e. public static). Do
* not put anything functional in this class.
*
* <p>
* It is advised to statically import this class (or one of its inner classes)
* wherever the constants are needed, to reduce verbosity.
*/
* The Constants class provides a convenient place for teams to hold robot-wide
* numerical or boolean constants. This class should not be used for any other
* purpose. All constants should be declared globally (i.e. public static). Do
* not put anything functional in this class.
*
* <p>
* It is advised to statically import this class (or one of its inner classes)
* wherever the constants are needed, to reduce verbosity.
*/

public final class Constants {
public static final boolean tuningMode = true;
Expand Down Expand Up @@ -78,7 +78,7 @@ public static final class Setpoints {
public static final ExtendedPathPoint blueRightWallLoadingStation = new ExtendedPathPoint(
new Translation2d(15.8, 6.0),
new Rotation2d(), Rotation2d.fromDegrees(0));
// Grid is labeled first to third from edge of field without
// Grid is labeled first to third from edge of field without
public static final ExtendedPathPoint blueFirstGridLeftCone = new ExtendedPathPoint(
new Translation2d(1.84 + .4, 0.43),
new Rotation2d(), Rotation2d.fromDegrees(180));
Expand Down Expand Up @@ -152,6 +152,17 @@ public static final class LEDConstants {
public static final Color kChargedUpGold = new Color(255, 183, 0);
}

public static final class FlywheelConstants {
public static final double gearRatio = 4.0;
public static final double tolerance = 0.008;
//what is a feedforward
//not in my america
public static final TunableNumber kP = new TunableNumber("Flywheel P", 14);
public static final TunableNumber kI = new TunableNumber("Flywheel I", 1.6);
public static final TunableNumber kD = new TunableNumber("Flywheel D", 0.5);
public static final PIDController flywheelController = new PIDController(kP.get(), kI.get(), kD.get());
}

public static final class ElevatorConstants {
public static final boolean kTuningMode = true;

Expand Down
14 changes: 12 additions & 2 deletions src/main/java/frc/robot/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import frc.lib.utils.FieldGeomUtil;
import frc.robot.Constants.DriveConstants;
import frc.robot.Constants.ElevatorConstants;
import frc.robot.Constants.FlywheelConstants;
import frc.robot.Constants.IntakeConstants;
import frc.robot.Constants.Ports;
import frc.robot.Constants.RobotConstants;
Expand All @@ -58,6 +59,8 @@
import frc.robot.subsystems.elevator.Elevator;
import frc.robot.subsystems.elevator.ElevatorIONeo;
import frc.robot.subsystems.elevator.ElevatorIOSim;
import frc.robot.subsystems.flywheel.Flywheel;
import frc.robot.subsystems.flywheel.FlywheelIOSim;
import frc.robot.subsystems.intake.Intake;
import frc.robot.subsystems.intake.IntakeIONeo550;
import frc.robot.subsystems.intake.IntakeIOSim;
Expand Down Expand Up @@ -88,6 +91,7 @@ public class RobotContainer {
private LED m_LED;
private String m_curSelectedAuto = "none";
private List<PathPlannerTrajectory> m_traj;
private Flywheel m_flywheel; //im on a whole nother level im geekin
// private LED m_LED2;

// Dashboard inputs
Expand Down Expand Up @@ -212,6 +216,8 @@ private void configureSubsystems() {
m_LED = new LED(Constants.LEDConstants.kLEDPort, Constants.LEDConstants.kLEDLength);
// m_LED2 = new LED(Constants.LEDConstants.kLEDPort2, Constants.LEDConstants.kLEDLength);
m_robotState = RobotState.startInstance(m_drive, m_intake, m_elevator, m_wrist);
m_flywheel = new Flywheel(new FlywheelIOSim(), Constants.FlywheelConstants.flywheelController,
FlywheelConstants.tolerance); //RADunancy
}

}
Expand Down Expand Up @@ -349,13 +355,13 @@ private void configureButtonBindings() {

driverControls.resetFieldCentric().onTrue(m_drive.resetCommand(new Pose2d(1.81, 6.9, new Rotation2d())));
driverControls.startIntakeConeInCubeOut().whileTrue(m_intake.intakeConeCommand());
driverControls.startIntakeCubeInConeOut().whileTrue(m_intake.intakeCubeCommand());
//driverControls.startIntakeCubeInConeOut().whileTrue(m_intake.intakeCubeCommand());
driverControls.zeroElevator().onTrue(m_elevator.zeroHeightCommand());
// driverControls.setpointHighCone().onTrue(coneHighCommand);
// driverControls.setpointMidCube().onTrue(cubeMidCommand);
// driverControls.setpointHighCube().onTrue(cubeHighCommand);
driverControls.intakeTippedCone().onTrue(pickUpConeGroundCommandDriver);
driverControls.intakeVerticalCone().onTrue(pickUpConeVerticalCommandDriver);
//driverControls.intakeVerticalCone().onTrue(pickUpConeVerticalCommandDriver);
driverControls.setpointIntakeGroundCube().onTrue(pickUpCubeGroundCommandDriver);
// driverControls.intakeFromLoadingStation().onTrue(intakeFromLoadingStationCommand);
driverControls.autoIntakeCube().whileTrue(intakeCubeTeleop);
Expand All @@ -381,6 +387,10 @@ private void configureButtonBindings() {
driverControls.goToNode().whileTrue(driveToGridSetpointCommand);

driverControls.ledFlash().onTrue(m_LED.startFlash());

driverControls.flywheelOnTop().onTrue(m_flywheel.setVelocityCommand(9));

driverControls.flywheelPLEASESTOP().onTrue(m_flywheel.setVelocityCommand(0));
}

public void onEnabled() {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/frc/robot/oi/DriverControls.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,8 @@ public interface DriverControls {

public Trigger ledFlash();

public Trigger flywheelOnTop();

public Trigger flywheelPLEASESTOP();

}
10 changes: 10 additions & 0 deletions src/main/java/frc/robot/oi/DriverControlsDualFlightStick.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,14 @@ public Trigger autoIntakeCube() {
public Trigger ledFlash() {
return m_rightJoystick.button(8);
}

@Override
public Trigger flywheelOnTop() {
return m_rightJoystick.button(1);
}

@Override
public Trigger flywheelPLEASESTOP() {
return m_rightJoystick.button(2);
}
}
51 changes: 51 additions & 0 deletions src/main/java/frc/robot/subsystems/flywheel/Flywheel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package frc.robot.subsystems.flywheel;

import org.littletonrobotics.junction.Logger;

import edu.wpi.first.math.controller.PIDController;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.SubsystemBase;

public class Flywheel extends SubsystemBase {
private FlywheelIO m_io;
private PIDController m_controller;
public FlywheelInputsAutoLogged m_inputs;

public Flywheel(FlywheelIO io, PIDController controller, double tolerance) {
m_io = io;
m_controller = controller;
m_controller.setTolerance(tolerance);
m_inputs = new FlywheelInputsAutoLogged();
}

@Override
public void periodic() {
m_io.updateInputs(m_inputs);
double burblesquirp = m_controller.calculate(m_inputs.velocityMetersPerSecNo);
m_io.setVoltageNo(burblesquirp);
//CODING TOO EASY
Logger.getInstance().processInputs("flywheel", m_inputs); //big as the super bowl but the difference is it's just two guys playing what they did in the studio
Logger.getInstance().recordOutput("flywheel/voltage", burblesquirp); //shoprya what r ur opinions on drizzy
//Logger.getInstance().recordOutput();
}

public void setVelocityM(double velocity) {
m_controller.setSetpoint(velocity);
}

public void setVelocityRadS(double velocity) {
setVelocityM(velocity * m_io.getWheelLengthYes());
}

public void setRevM(double rev) {
setVelocityRadS(rev / (30 / Math.PI));
}

public boolean isRight() {
return m_controller.atSetpoint();
}

public Command setVelocityCommand(double velocityMS) {
return runOnce(() -> setVelocityM(velocityMS));
}
}
24 changes: 24 additions & 0 deletions src/main/java/frc/robot/subsystems/flywheel/FlywheelIO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package frc.robot.subsystems.flywheel; //Ash was here

import org.littletonrobotics.junction.AutoLog;

import frc.lib.advantagekit.LoggedIO;

public interface FlywheelIO extends LoggedIO<FlywheelIO.FlywheelInputs> {

@AutoLog
public class FlywheelInputs {
public double velocityMetersPerSecNo;
public double velocityRadPerSecNo;
}

public double getVelocityMetersPerSecYes();

public double getVelocityRevPerMinYes();

public double getVelocityRadPerSecYes();

public void setVoltageNo(double voltage);

public double getWheelLengthYes();
}
69 changes: 69 additions & 0 deletions src/main/java/frc/robot/subsystems/flywheel/FlywheelIOSim.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package frc.robot.subsystems.flywheel; //\int\limits_{-\infty}^{\infty} \frac{\sin(x)}{x} \, dx = \pi

import edu.wpi.first.math.system.plant.DCMotor;
import edu.wpi.first.math.util.Units;
import edu.wpi.first.wpilibj.simulation.FlywheelSim;

public class FlywheelIOSim implements FlywheelIO {
private FlywheelSim m_flywheel;
public final double m_wheelLength;

public FlywheelIOSim() {
DCMotor gearbox = DCMotor.getFalcon500(2);
double gearing = 3;
double jKgMetersSquared = 16.9876543210987654231;
m_flywheel = new FlywheelSim(gearbox, gearing, jKgMetersSquared);
m_wheelLength = Units.inchesToMeters(9);
}

public void updateInputs(FlywheelInputs inputs) {
//update the flywheel with the inputs
inputs.velocityMetersPerSecNo = getVelocityMetersPerSecYes();
inputs.velocityRadPerSecNo = getVelocityRadPerSecYes();
}

@Override
public double getVelocityMetersPerSecYes() {
return m_flywheel.getAngularVelocityRadPerSec() * m_wheelLength;
}

@Override
public double getVelocityRevPerMinYes() {
return m_flywheel.getAngularVelocityRPM();
}

@Override
public double getVelocityRadPerSecYes() {
return m_flywheel.getAngularVelocityRadPerSec();
}

@Override
public void setVoltageNo(double voltage) {
m_flywheel.setInputVoltage(voltage);
}

@Override
public double getWheelLengthYes() {
return m_wheelLength;
}
}
/*
List of songs by one of many artists worse than Carti :heart_eyes_cat:
1. Way Out
2. What's Poppin
3. Already Bestfriends
4. Denver
5. They don't love it
6. Routine
7. Sundown
8. Stop Giving Me Advice
9. I WANNA SEE SOME ASS
10. Face of My City
11. your mother
*/

/*
1.
2.
3.
*/
Loading

0 comments on commit d43a9e6

Please sign in to comment.