-
Notifications
You must be signed in to change notification settings - Fork 0
Lintake #46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Lintake #46
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
7ee8cf4
Linear Slide IO
SCool62 90c641a
Linear slide io sim
SCool62 1322331
Base impl of lintake subsystem
SCool62 28aad47
Spotless
SCool62 fd5840d
Constants from CAD
SCool62 9ebf40b
Rack talon config
SCool62 1cb3361
Rename slide to rack
SCool62 5b11938
Linear rack sim constants from CAD
SCool62 6d65339
Roller config
SCool62 35529d8
Spotless
SCool62 aca4771
Instantiate new lintake in constructor
SCool62 5a00e24
CAN range
SCool62 e848cd4
Merge branch 'main' into subsystem/lintake
SCool62 34e0b99
Merge branch 'main' into subsystem/lintake
SCool62 65759a3
Can ids
SCool62 6652844
Impl beambreak method
SCool62 c3bacc8
Remove unused method in intake subsystem
SCool62 3921e2a
Osciliate when outtaking
SCool62 f4a5e67
Scale oscilation to be reasonable
SCool62 a799802
Spotless
SCool62 08bfa82
Add current zeroing
SCool62 c818d0f
Actually zero rack by extending
SCool62 f73c8d9
Spotless
SCool62 413024a
Make extension not negative lol
SCool62 b3247dd
Zeroing is a run once
SCool62 07aba7e
Lower current limit to make it more springy hopefully (needs tuning irl)
SCool62 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
94 changes: 94 additions & 0 deletions
94
src/main/java/frc/robot/subsystems/intake/LinearRackIO.java
This file contains hidden or 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,94 @@ | ||
| package frc.robot.subsystems.intake; | ||
|
|
||
| import com.ctre.phoenix6.BaseStatusSignal; | ||
| import com.ctre.phoenix6.CANBus; | ||
| import com.ctre.phoenix6.StatusSignal; | ||
| import com.ctre.phoenix6.configs.TalonFXConfiguration; | ||
| import com.ctre.phoenix6.controls.MotionMagicVoltage; | ||
| import com.ctre.phoenix6.controls.VoltageOut; | ||
| import com.ctre.phoenix6.hardware.TalonFX; | ||
| import edu.wpi.first.units.measure.Angle; | ||
| import edu.wpi.first.units.measure.AngularVelocity; | ||
| import edu.wpi.first.units.measure.Current; | ||
| import edu.wpi.first.units.measure.Temperature; | ||
| import edu.wpi.first.units.measure.Voltage; | ||
| import org.littletonrobotics.junction.AutoLog; | ||
|
|
||
| public class LinearRackIO { | ||
|
|
||
| @AutoLog | ||
| public static class LinearRackIOInputs { | ||
| public double positionMeters = 0.0; | ||
| public double velocityMetersPerSecond = 0.0; | ||
| public double voltage = 0.0; | ||
| public double statorCurrentAmps = 0.0; | ||
| public double supplyCurrentAmps = 0.0; | ||
| public double temperatureC = 0.0; | ||
| } | ||
|
|
||
| protected final TalonFX motor; | ||
|
|
||
| // Technically, these measure angle, but the conversion from angle to linear movement happens in | ||
| // the sensor-to-mechanism ratio | ||
| private final StatusSignal<Angle> positionMeters; | ||
| private final StatusSignal<AngularVelocity> velocityMetersPerSecond; | ||
| private final StatusSignal<Voltage> voltage; | ||
| private final StatusSignal<Current> statorCurrent; | ||
| private final StatusSignal<Current> supplyCurrent; | ||
| private final StatusSignal<Temperature> temperature; | ||
|
|
||
| private VoltageOut voltageOut = new VoltageOut(0.0).withEnableFOC(true); | ||
| // I think we might want to motion profile this so i'm using motion magic | ||
| private MotionMagicVoltage motionMagicVoltage = new MotionMagicVoltage(0.0).withEnableFOC(true); | ||
|
|
||
| private double setpointMeters = 0.0; | ||
|
|
||
| public LinearRackIO(int motorID, CANBus canBus, TalonFXConfiguration config) { | ||
| this.motor = new TalonFX(motorID, canBus); | ||
|
|
||
| positionMeters = motor.getPosition(); | ||
| velocityMetersPerSecond = motor.getVelocity(); | ||
| voltage = motor.getMotorVoltage(); | ||
| statorCurrent = motor.getStatorCurrent(); | ||
| supplyCurrent = motor.getSupplyCurrent(); | ||
| temperature = motor.getDeviceTemp(); | ||
|
|
||
| BaseStatusSignal.setUpdateFrequencyForAll( | ||
| 50.0, | ||
| positionMeters, | ||
| velocityMetersPerSecond, | ||
| voltage, | ||
| statorCurrent, | ||
| supplyCurrent, | ||
| temperature); | ||
| motor.optimizeBusUtilization(); | ||
|
|
||
| motor.getConfigurator().apply(config); | ||
| } | ||
|
|
||
| public void updateInputs(LinearRackIOInputs inputs) { | ||
| inputs.positionMeters = positionMeters.getValueAsDouble(); | ||
| inputs.velocityMetersPerSecond = velocityMetersPerSecond.getValueAsDouble(); | ||
| inputs.voltage = voltage.getValueAsDouble(); | ||
| inputs.statorCurrentAmps = statorCurrent.getValueAsDouble(); | ||
| inputs.supplyCurrentAmps = supplyCurrent.getValueAsDouble(); | ||
| inputs.temperatureC = temperature.getValueAsDouble(); | ||
| } | ||
|
|
||
| public void setVoltage(double volts) { | ||
| motor.setControl(voltageOut.withOutput(volts)); | ||
| } | ||
|
|
||
| public void setPositionSetpoint(double setpointMeters) { | ||
| this.setpointMeters = setpointMeters; | ||
| motor.setControl(motionMagicVoltage.withPosition(setpointMeters)); | ||
| } | ||
|
|
||
| public double getSetpointMeters() { | ||
| return setpointMeters; | ||
| } | ||
|
|
||
| public void resetEncoder(double positionMeters) { | ||
| motor.setPosition(positionMeters); | ||
| } | ||
| } | ||
68 changes: 68 additions & 0 deletions
68
src/main/java/frc/robot/subsystems/intake/LinearRackIOSim.java
This file contains hidden or 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,68 @@ | ||
| package frc.robot.subsystems.intake; | ||
|
|
||
| import com.ctre.phoenix6.CANBus; | ||
| import com.ctre.phoenix6.Utils; | ||
| import com.ctre.phoenix6.configs.TalonFXConfiguration; | ||
| import com.ctre.phoenix6.sim.ChassisReference; | ||
| import com.ctre.phoenix6.sim.TalonFXSimState; | ||
| import com.ctre.phoenix6.sim.TalonFXSimState.MotorType; | ||
| import edu.wpi.first.math.system.plant.DCMotor; | ||
| import edu.wpi.first.math.system.plant.LinearSystemId; | ||
| import edu.wpi.first.math.util.Units; | ||
| import edu.wpi.first.wpilibj.Notifier; | ||
| import edu.wpi.first.wpilibj.RobotController; | ||
| import edu.wpi.first.wpilibj.simulation.ElevatorSim; | ||
|
|
||
| public class LinearRackIOSim extends LinearRackIO { | ||
| // TODO: SHOULD THIS BE AN ELEVATOR? | ||
| ElevatorSim physicsSim = | ||
| new ElevatorSim( | ||
| LinearSystemId.createElevatorSystem( | ||
| DCMotor.getKrakenX44Foc(1), | ||
| Units.lbsToKilograms(10.0), | ||
| LintakeSubsystem.RACK_PINION_DIAMETER_METERS / 2, | ||
| LintakeSubsystem.RACK_GEAR_RATIO), | ||
| DCMotor.getKrakenX44Foc(1), | ||
| 0.0, | ||
| LintakeSubsystem.MAX_EXTENSION_METERS, | ||
| false, | ||
| 0.0); | ||
|
|
||
| private static final double SIM_LOOP_PERIOD = 0.002; // 2 ms | ||
| private Notifier notifier; | ||
| private TalonFXSimState talonSim; | ||
| private double lastLoopTime = 0.0; | ||
|
|
||
| public LinearRackIOSim(int motorId, CANBus canBus, TalonFXConfiguration config) { | ||
| super(motorId, canBus, config); | ||
|
|
||
| this.talonSim = motor.getSimState(); | ||
| // Maybe try to make have these passed in? Maybe not needed tho | ||
| this.talonSim.setMotorType(MotorType.KrakenX44); | ||
| this.talonSim.Orientation = ChassisReference.Clockwise_Positive; // TODO | ||
|
|
||
| notifier = | ||
| new Notifier( | ||
| () -> { | ||
| double deltaTime = (Utils.getCurrentTimeSeconds() - lastLoopTime); | ||
| lastLoopTime = Utils.getCurrentTimeSeconds(); | ||
|
|
||
| talonSim.setSupplyVoltage(RobotController.getBatteryVoltage()); | ||
|
|
||
| physicsSim.setInputVoltage(talonSim.getMotorVoltage()); | ||
| physicsSim.update(deltaTime); | ||
|
|
||
| // I think these should be multiplied? | ||
| talonSim.setRawRotorPosition( | ||
| physicsSim.getPositionMeters() | ||
| * (LintakeSubsystem.RACK_GEAR_RATIO | ||
| * (Math.PI * LintakeSubsystem.RACK_PINION_DIAMETER_METERS))); | ||
| talonSim.setRotorVelocity( | ||
| physicsSim.getVelocityMetersPerSecond() | ||
| * (LintakeSubsystem.RACK_GEAR_RATIO | ||
| * (Math.PI * LintakeSubsystem.RACK_PINION_DIAMETER_METERS))); | ||
| }); | ||
|
|
||
| notifier.startPeriodic(SIM_LOOP_PERIOD); | ||
| } | ||
| } |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.