-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
James and I wrote Flywheel and edited Constants (Very functional)
- Loading branch information
Showing
6 changed files
with
137 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
18
src/main/java/frc/robot/subsystems/flywheel/FlywheelIO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
50
src/main/java/frc/robot/subsystems/flywheel/FlywheelIOSim.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters