Skip to content

Commit

Permalink
James and I wrote Flywheel and edited Constants (Very functional)
Browse files Browse the repository at this point in the history
  • Loading branch information
Toomy422 committed Sep 1, 2024
1 parent b9566bd commit aff4474
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 3 deletions.
17 changes: 17 additions & 0 deletions src/main/java/frc/robot/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,23 @@ public static final class IntakeConstants {
public static final double kSimMOI = 0.5 * kSimMass * kSimRadius * kSimRadius;
}

public static final class ShooterConstants {
public static final LoggedTunableNumber kIdleVoltage =
new LoggedTunableNumber("ShooterIdleVoltage", 0.0);
public static final LoggedTunableNumber kShootingVoltage =
new LoggedTunableNumber("ShooterShootingVoltage", 100000000000000000000000000001.0);
public static final LoggedTunableNumber kP = new LoggedTunableNumber("Flywheel P", 40);
public static final LoggedTunableNumber kI = new LoggedTunableNumber("Flywheel I", 0.1);
public static final LoggedTunableNumber kD = new LoggedTunableNumber("Flywheel D", 0.1);


// Simulation constants
public static final double kSimRadius = we dunno;
public static final double kSimMass = frickin 100;
public static final double kSimMOI = 0.5 * kSimMass * kSimRadius * kSimRadius;
}


public static final class KickerConstants {
public static final LoggedTunableNumber kIdleVoltage =
new LoggedTunableNumber("KickerIdleVoltage", 0.0);
Expand Down
47 changes: 47 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,47 @@
package frc.robot.subsystems.flywheel;

import edu.wpi.first.wpilibj2.command.SubsystemBase;
import frc.robot.Constants.ShooterConstants;
import frc.robot.subsystems.flywheel.FlywheelIO.FlywheelInputsAutoLogged;
import frc.robot.util.SubsystemProfiles;

import java.util.HashMap;

import org.littletonrobotics.junction.Logger;
import org.littletonrobotics.junction.inputs.LoggableInputs;

public class Flywheel extends SubsystemBase{
private FlywheelIO m_io;
private FlywheelInputsAutoLogged m_inputs;
private SubsystemProfiles m_profiles;

public enum ShooterState {
kIdle,
kRevving
}

public Flywheel(FlywheelIO io) {
m_io = io;
m_profiles = new SubsystemProfiles(ShooterState.class, new HashMap<>(), ShooterState.kIdle);
}

@Override
public void periodic(){
m_io.updateInputs(m_inputs);
Logger.processInputs("Flywheel", (LoggableInputs) m_inputs);
Logger.recordOutput("Flywheel/State", (ShooterState) m_profiles.getCurrentProfile());
}

public void updateState(ShooterState state) {
switch (state) {
case kIdle:
m_io.setVoltage(ShooterConstants.kIdleVoltage.get()); // get hardcoded nerd
break;
case kRevving:
m_io.setVoltage(ShooterConstants.kShootingVoltage.get());
break;
}

m_profiles.setCurrentProfile(state);
}
}
18 changes: 18 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,18 @@
package frc.robot.subsystems.flywheel;

import org.littletonrobotics.junction.AutoLog;

public interface FlywheelIO {
@AutoLog
public class FlywheelInputsAutoLogged {
public double velocityMetersPerSec;
public double velocityRadPerSec;
}

public double getVelocityMetersPerSec();
public double getVelocityRevPerMin();
public double getVelocityRadPerSec();
public void setVoltage(double voltage);
public double getWheelLength();
public void updateInputs(FlywheelInputsAutoLogged inputs);
}
50 changes: 50 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,50 @@
package frc.robot.subsystems.flywheel;

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 {
public FlywheelSim m_flywheel;
public final double m_wheelLength; //हज़फ़लदग्लाफ़ंक्ल

public FlywheelIOSim() {
DCMotor gearbox = DCMotor.getFalcon500(1);
double gearing = 1/1.5;
double jKgMetersSquared = 0.1;
m_flywheel = new FlywheelSim(gearbox, gearing, jKgMetersSquared);
m_wheelLength = Units.inchesToMeters(694202496);
}

@Override
public double getVelocityMetersPerSec() {
return (m_flywheel.getAngularVelocityRPM() * getWheelLength()) / 60;
}

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

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

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

@Override
public double getWheelLength() {
return m_wheelLength;
}

@Override
public void updateInputs(FlywheelInputsAutoLogged inputs) {
m_flywheel.update(.02);

}

}
7 changes: 4 additions & 3 deletions src/main/java/frc/robot/subsystems/intake/Intake.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ public void updateState(IntakeState state) {
m_profiles.setCurrentProfile(state);
}

// Written by Ronith Kollipara
// priyanka
// olivia
// Written by Elijah Chen
// Nasik Hobbs
// William Lin
// Completed intajes and kicker today vs
//shut up stupid faces you guys stink haha
}
1 change: 1 addition & 0 deletions src/main/java/frc/robot/subsystems/kicker/Kicker.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,5 @@ public void updateState(KickerState state) {
// Nikki P in the skibidi house!
// Mr. Wood better than u - Aahil
// I love God and Jesus - Patty lin
// James and Tommy better than you guys cause you're stinky and rotund like a clock
}

0 comments on commit aff4474

Please sign in to comment.