-
Notifications
You must be signed in to change notification settings - Fork 1
Chandana Aradhya Indexer PR #2
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
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8ae10db
All indexer subsystem files finished
chandaradhya 43f7e40
update to num of motors in indexeriosim file
chandaradhya 93a8f14
chore: auto-fix Spotless formatting
github-actions[bot] f12839d
The feeder wheels have moved to their own subsystem and been removed …
chandaradhya 146de7f
IndexerConstants.kt has been updated to consider for the different se…
chandaradhya de28f17
Torque Current signals and closed loop stuff were removed. Gear ratio…
chandaradhya 921c4ec
Gear ratios and moment of inertia settings were updated. fun setVeloc…
chandaradhya b8b7290
Merge branch 'master' into Indexer
00magikarp 5ebff7f
chore: auto-fix Spotless formatting
github-actions[bot] 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
Empty file.
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
66 changes: 66 additions & 0 deletions
66
src/main/kotlin/com/team4099/robot2026/config/constants/FeederConstants.kt
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,66 @@ | ||
| package com.team4099.robot2026.config.constants | ||
|
|
||
| import org.team4099.lib.units.AngularAcceleration | ||
| import org.team4099.lib.units.AngularVelocity | ||
| import org.team4099.lib.units.Velocity | ||
| import org.team4099.lib.units.base.Ampere | ||
| import org.team4099.lib.units.base.amps | ||
| import org.team4099.lib.units.base.grams | ||
| import org.team4099.lib.units.base.seconds | ||
| import org.team4099.lib.units.derived.AccelerationFeedforward | ||
| import org.team4099.lib.units.derived.DerivativeGain | ||
| import org.team4099.lib.units.derived.IntegralGain | ||
| import org.team4099.lib.units.derived.ProportionalGain | ||
| import org.team4099.lib.units.derived.Radian | ||
| import org.team4099.lib.units.derived.StaticFeedforward | ||
| import org.team4099.lib.units.derived.VelocityFeedforward | ||
| import org.team4099.lib.units.derived.Volt | ||
| import org.team4099.lib.units.derived.degrees | ||
| import org.team4099.lib.units.derived.meterSquared | ||
| import org.team4099.lib.units.derived.radians | ||
| import org.team4099.lib.units.derived.rotations | ||
| import org.team4099.lib.units.derived.volts | ||
| import org.team4099.lib.units.kilo | ||
| import org.team4099.lib.units.perMinute | ||
| import org.team4099.lib.units.perSecond | ||
|
|
||
| object FeederConstants { | ||
| const val GEAR_RATIO: Double = 18.0 / 28.0 | ||
|
|
||
| val STATOR_CURRENT_LIMIT = 40.0.amps | ||
| val SUPPLY_CURRENT_LIMIT = 40.0.amps | ||
|
|
||
| val VOLTAGE_COMPENSATION = 12.0.volts | ||
| val MOMENT_OF_INERTIA = 0.000011.kilo.grams.meterSquared | ||
| val MAX_ACCELERATION: AngularAcceleration = 0.rotations.perSecond.perSecond | ||
| val MAX_VELOCITY: AngularVelocity = 0.rotations.perSecond | ||
| val INDEXER_TOLERANCE = 0.0.rotations.perMinute | ||
|
|
||
| object VELOCITIES { | ||
| val IDLE_VELOCITY = 0.0.rotations.perSecond | ||
| val SCORE_VELOCITY = 0.0.rotations.perSecond | ||
| } | ||
|
|
||
| object PID { | ||
| val REAL_KP: ProportionalGain<Velocity<Radian>, Ampere> = 0.0.amps / 0.0.radians.perSecond | ||
| val REAL_KI: IntegralGain<Velocity<Radian>, Ampere> = | ||
| 0.0.amps / (0.0.radians.perSecond * 0.0.seconds) | ||
| val REAL_KD: DerivativeGain<Velocity<Radian>, Ampere> = | ||
| 0.0.amps / (0.0.radians.perSecond / 0.0.seconds) | ||
|
|
||
| val REAL_KS: StaticFeedforward<Ampere> = 0.0.amps | ||
| val REAL_KV: VelocityFeedforward<Radian, Ampere> = 0.0.amps / 0.0.radians.perSecond | ||
| val REAL_KA: AccelerationFeedforward<Radian, Ampere> = | ||
| 0.0.amps / 0.0.radians.perSecond.perSecond | ||
|
|
||
| val SIM_KP: ProportionalGain<Velocity<Radian>, Volt> = 0.0.volts / 0.0.degrees.perSecond | ||
| val SIM_KI: IntegralGain<Velocity<Radian>, Volt> = | ||
| 0.0.volts / (0.0.rotations.perMinute * 0.0.seconds) | ||
| val SIM_KD: DerivativeGain<Velocity<Radian>, Volt> = | ||
| 0.0.volts / (0.0.rotations.perMinute.perSecond) | ||
|
|
||
| val SIM_KS: StaticFeedforward<Volt> = 0.0.volts | ||
| val SIM_KV: VelocityFeedforward<Radian, Volt> = 0.0.volts / 0.0.degrees.perSecond | ||
| val SIM_KA: AccelerationFeedforward<Radian, Volt> = 0.0.volts / 0.0.degrees.perSecond.perSecond | ||
| } | ||
| } |
94 changes: 94 additions & 0 deletions
94
src/main/kotlin/com/team4099/robot2026/config/constants/IndexerConstants.kt
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 com.team4099.robot2026.config.constants | ||
|
|
||
| import org.team4099.lib.units.AngularAcceleration | ||
| import org.team4099.lib.units.AngularVelocity | ||
| import org.team4099.lib.units.Velocity | ||
| import org.team4099.lib.units.base.Ampere | ||
| import org.team4099.lib.units.base.amps | ||
| import org.team4099.lib.units.base.grams | ||
| import org.team4099.lib.units.base.seconds | ||
| import org.team4099.lib.units.derived.AccelerationFeedforward | ||
| import org.team4099.lib.units.derived.DerivativeGain | ||
| import org.team4099.lib.units.derived.IntegralGain | ||
| import org.team4099.lib.units.derived.ProportionalGain | ||
| import org.team4099.lib.units.derived.Radian | ||
| import org.team4099.lib.units.derived.StaticFeedforward | ||
| import org.team4099.lib.units.derived.VelocityFeedforward | ||
| import org.team4099.lib.units.derived.Volt | ||
| import org.team4099.lib.units.derived.degrees | ||
| import org.team4099.lib.units.derived.meterSquared | ||
| import org.team4099.lib.units.derived.radians | ||
| import org.team4099.lib.units.derived.rotations | ||
| import org.team4099.lib.units.derived.volts | ||
| import org.team4099.lib.units.kilo | ||
| import org.team4099.lib.units.perMinute | ||
| import org.team4099.lib.units.perSecond | ||
|
|
||
| object IndexerConstants { | ||
| object FloorConstants { | ||
| const val TOP_GEAR_RATIO: Double = (16.0 / 58.0) * (28.0 / 30.0) | ||
| const val BOTTOM_GEAR_RATIO: Double = 16.0 / 58.0 | ||
|
|
||
| val STATOR_CURRENT_LIMIT = 40.0.amps | ||
| val SUPPLY_CURRENT_LIMIT = 40.0.amps | ||
|
|
||
| val VOLTAGE_COMPENSATION = 12.0.volts | ||
| val TOP_MOMENT_OF_INERTIA = 0.000015.kilo.grams.meterSquared | ||
| val BOTTOM_MOMENT_OF_INERTIA = 0.000030.kilo.grams.meterSquared | ||
| val MAX_ACCELERATION: AngularAcceleration = 0.rotations.perSecond.perSecond | ||
| val MAX_VELOCITY: AngularVelocity = 0.rotations.perSecond | ||
| val INDEXER_TOLERANCE = 0.0.rotations.perMinute | ||
| } | ||
|
|
||
| object BeltConstants { | ||
| const val GEAR_RATIO: Double = 16.0 / 58.0 | ||
|
|
||
| val STATOR_CURRENT_LIMIT = 40.0.amps | ||
| val SUPPLY_CURRENT_LIMIT = 40.0.amps | ||
|
|
||
| val VOLTAGE_COMPENSATION = 12.0.volts | ||
| val TOP_MOMENT_OF_INERTIA = 0.0000057.kilo.grams.meterSquared | ||
| val BOTTOM_MOMENT_OF_INERTIA = 0.0000065.kilo.grams.meterSquared | ||
| val MAX_ACCELERATION: AngularAcceleration = 0.rotations.perSecond.perSecond | ||
| val MAX_VELOCITY: AngularVelocity = 0.rotations.perSecond | ||
| val INDEXER_TOLERANCE = 0.0.rotations.perMinute | ||
| } | ||
|
|
||
| object SideRollerConstants { | ||
| const val GEAR_RATIO: Double = 16.0 / 40.0 | ||
|
|
||
| val STATOR_CURRENT_LIMIT = 40.0.amps | ||
| val SUPPLY_CURRENT_LIMIT = 40.0.amps | ||
|
|
||
| val VOLTAGE_COMPENSATION = 12.0.volts | ||
| val MOMENT_OF_INERTIA = 0.0000050.kilo.grams.meterSquared | ||
| val MAX_ACCELERATION: AngularAcceleration = 0.rotations.perSecond.perSecond | ||
| val MAX_VELOCITY: AngularVelocity = 0.rotations.perSecond | ||
| val INDEXER_TOLERANCE = 0.0.rotations.perMinute | ||
| } | ||
|
|
||
| val IDLE_VELOCITY = 0.0.rotations.perSecond | ||
|
|
||
| object PID { | ||
| val REAL_KP: ProportionalGain<Velocity<Radian>, Ampere> = 0.0.amps / 0.0.radians.perSecond | ||
| val REAL_KI: IntegralGain<Velocity<Radian>, Ampere> = | ||
| 0.0.amps / (0.0.radians.perSecond * 0.0.seconds) | ||
| val REAL_KD: DerivativeGain<Velocity<Radian>, Ampere> = | ||
| 0.0.amps / (0.0.radians.perSecond / 0.0.seconds) | ||
|
|
||
| val REAL_KS: StaticFeedforward<Ampere> = 0.0.amps | ||
| val REAL_KV: VelocityFeedforward<Radian, Ampere> = 0.0.amps / 0.0.radians.perSecond | ||
| val REAL_KA: AccelerationFeedforward<Radian, Ampere> = | ||
| 0.0.amps / 0.0.radians.perSecond.perSecond | ||
|
|
||
| val SIM_KP: ProportionalGain<Velocity<Radian>, Volt> = 0.0.volts / 0.0.degrees.perSecond | ||
| val SIM_KI: IntegralGain<Velocity<Radian>, Volt> = | ||
| 0.0.volts / (0.0.rotations.perMinute * 0.0.seconds) | ||
| val SIM_KD: DerivativeGain<Velocity<Radian>, Volt> = | ||
| 0.0.volts / (0.0.rotations.perMinute.perSecond) | ||
|
|
||
| val SIM_KS: StaticFeedforward<Volt> = 0.0.volts | ||
| val SIM_KV: VelocityFeedforward<Radian, Volt> = 0.0.volts / 0.0.degrees.perSecond | ||
| val SIM_KA: AccelerationFeedforward<Radian, Volt> = 0.0.volts / 0.0.degrees.perSecond.perSecond | ||
| } | ||
| } | ||
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
63 changes: 63 additions & 0 deletions
63
src/main/kotlin/com/team4099/robot2026/subsystems/superstructure/feeder/Feeder.kt
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,63 @@ | ||
| package com.team4099.robot2026.subsystems.superstructure.feeder | ||
|
|
||
| import com.team4099.robot2026.subsystems.superstructure.Request.FeederRequest | ||
| import com.team4099.robot2026.util.ControlledByStateMachine | ||
| import com.team4099.robot2026.util.CustomLogger | ||
| import org.team4099.lib.units.derived.inVolts | ||
| import org.team4099.lib.units.derived.volts | ||
|
|
||
| class Feeder(private val io: FeederIO) : ControlledByStateMachine() { | ||
| val inputs = FeederIO.FeederInputs() | ||
|
|
||
| var targetVoltage = 0.0.volts | ||
| private set | ||
|
|
||
| var currentState: FeederState = FeederState.UNINITIALIZED | ||
| var currentRequest: FeederRequest = FeederRequest.Idle() | ||
| set(value) { | ||
| when (value) { | ||
| is FeederRequest.OpenLoop -> targetVoltage = value.voltage | ||
| else -> {} | ||
| } | ||
| } | ||
|
|
||
| override fun onLoop() { | ||
| io.updateInputs(inputs) | ||
| CustomLogger.processInputs("Feeder", inputs) | ||
|
|
||
| CustomLogger.recordOutput("Feeder/currentState", currentState) | ||
| CustomLogger.recordOutput("Feeder/currentRequest", currentRequest.javaClass.simpleName) | ||
|
|
||
| CustomLogger.recordOutput("Feeder/targetVoltageVolts", targetVoltage.inVolts) | ||
|
|
||
| var nextState = currentState | ||
| when (currentState) { | ||
| FeederState.UNINITIALIZED -> { | ||
| nextState = fromRequestToState(currentRequest) | ||
| } | ||
| FeederState.IDLE -> { | ||
| nextState = fromRequestToState(currentRequest) | ||
| } | ||
| FeederState.OPEN_LOOP -> { | ||
| io.setVoltage(targetVoltage) | ||
| nextState = fromRequestToState(currentRequest) | ||
| } | ||
| } | ||
| currentState = nextState | ||
| } | ||
|
|
||
| companion object { | ||
| enum class FeederState { | ||
| UNINITIALIZED, | ||
| IDLE, | ||
| OPEN_LOOP | ||
| } | ||
|
|
||
| inline fun fromRequestToState(request: FeederRequest): FeederState { | ||
| return when (request) { | ||
| is FeederRequest.Idle -> FeederState.IDLE | ||
| is FeederRequest.OpenLoop -> FeederState.OPEN_LOOP | ||
| } | ||
| } | ||
| } | ||
| } |
62 changes: 62 additions & 0 deletions
62
src/main/kotlin/com/team4099/robot2026/subsystems/superstructure/feeder/FeederIO.kt
|
00magikarp marked this conversation as resolved.
|
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,62 @@ | ||
| package com.team4099.robot2026.subsystems.superstructure.feeder | ||
|
|
||
| import org.littletonrobotics.junction.LogTable | ||
| import org.littletonrobotics.junction.inputs.LoggableInputs | ||
| import org.team4099.lib.units.base.amps | ||
| import org.team4099.lib.units.base.celsius | ||
| import org.team4099.lib.units.base.inAmperes | ||
| import org.team4099.lib.units.base.inCelsius | ||
| import org.team4099.lib.units.derived.ElectricalPotential | ||
| import org.team4099.lib.units.derived.inVolts | ||
| import org.team4099.lib.units.derived.rotations | ||
| import org.team4099.lib.units.derived.volts | ||
| import org.team4099.lib.units.inRotationsPerMinute | ||
| import org.team4099.lib.units.inRotationsPerMinutePerMinute | ||
| import org.team4099.lib.units.perMinute | ||
|
|
||
| interface FeederIO { | ||
| class FeederInputs : LoggableInputs { | ||
| var feederVelocity = 0.0.rotations.perMinute | ||
| var feederAcceleration = 0.0.rotations.perMinute.perMinute | ||
| var feederTemperature = 0.0.celsius | ||
| var feederAppliedVoltage = 0.0.volts | ||
| var feederSupplyCurrent = 0.0.amps | ||
| var feederStatorCurrent = 0.0.amps | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you dont need both stator and torque. convention for our team is to just use stator so use stator, remove torque |
||
|
|
||
| override fun toLog(table: LogTable) { | ||
| table.put("feederVelocityRPM", feederVelocity.inRotationsPerMinute) | ||
| table.put("feederAccelerationRPMPM", feederAcceleration.inRotationsPerMinutePerMinute) | ||
| table.put("feederSupplyCurrentAmps", feederSupplyCurrent.inAmperes) | ||
| table.put("feederStatorCurrentAmps", feederStatorCurrent.inAmperes) | ||
| table.put("feederAppliedVoltageVolts", feederAppliedVoltage.inVolts) | ||
| table.put("feederTemperatureCelsius", feederTemperature.inCelsius) | ||
| } | ||
|
|
||
| override fun fromLog(table: LogTable) { | ||
| table.get("feederVelocityRPM", feederVelocity.inRotationsPerMinute).let { | ||
| feederVelocity = it.rotations.perMinute | ||
| } | ||
| table.get("feederAccelerationRPMPM", feederAcceleration.inRotationsPerMinutePerMinute).let { | ||
| feederAcceleration = it.rotations.perMinute.perMinute | ||
| } | ||
| table.get("feederSupplyCurrentAmps", feederSupplyCurrent.inAmperes).let { | ||
| feederSupplyCurrent = it.amps | ||
| } | ||
| table.get("feederStatorCurrentAmps", feederStatorCurrent.inAmperes).let { | ||
| feederStatorCurrent = it.amps | ||
| } | ||
| table.get("feederAppliedVoltageVolts", feederAppliedVoltage.inVolts).let { | ||
| feederAppliedVoltage = it.volts | ||
| } | ||
| table.get("feederTemperatureCelsius", feederTemperature.inCelsius).let { | ||
| feederTemperature = it.celsius | ||
| } | ||
| } | ||
| } | ||
|
|
||
| fun updateInputs(inputs: FeederInputs) {} | ||
|
|
||
| fun setVoltage(voltage: ElectricalPotential) {} | ||
|
|
||
| fun setBrakeMode(brake: Boolean) {} | ||
| } | ||
47 changes: 47 additions & 0 deletions
47
src/main/kotlin/com/team4099/robot2026/subsystems/superstructure/feeder/FeederIOSim.kt
|
00magikarp marked this conversation as resolved.
|
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,47 @@ | ||
| package com.team4099.robot2026.subsystems.superstructure.feeder | ||
|
|
||
| import com.team4099.lib.math.clamp | ||
| import com.team4099.robot2026.config.constants.Constants | ||
| import com.team4099.robot2026.config.constants.FeederConstants | ||
| import edu.wpi.first.math.system.plant.DCMotor | ||
| import edu.wpi.first.math.system.plant.LinearSystemId | ||
| import edu.wpi.first.wpilibj.simulation.FlywheelSim | ||
| import org.team4099.lib.units.base.amps | ||
| import org.team4099.lib.units.base.celsius | ||
| import org.team4099.lib.units.base.inSeconds | ||
| import org.team4099.lib.units.derived.ElectricalPotential | ||
| import org.team4099.lib.units.derived.inKilogramsMeterSquared | ||
| import org.team4099.lib.units.derived.inVolts | ||
| import org.team4099.lib.units.derived.radians | ||
| import org.team4099.lib.units.derived.volts | ||
| import org.team4099.lib.units.perSecond | ||
|
|
||
| object FeederIOSim : FeederIO { | ||
| private val feederSim = | ||
| FlywheelSim( | ||
| LinearSystemId.createFlywheelSystem( | ||
| DCMotor.getKrakenX60Foc(1), | ||
| FeederConstants.MOMENT_OF_INERTIA.inKilogramsMeterSquared, | ||
| 1.0 / FeederConstants.GEAR_RATIO, | ||
| ), | ||
| DCMotor.getKrakenX60Foc(1)) | ||
|
|
||
| private var appliedVoltage = 0.0.volts | ||
|
|
||
| override fun updateInputs(inputs: FeederIO.FeederInputs) { | ||
| feederSim.update(Constants.Universal.LOOP_PERIOD_TIME.inSeconds) | ||
| inputs.feederVelocity = feederSim.angularVelocityRadPerSec.radians.perSecond | ||
| inputs.feederAcceleration = feederSim.angularAccelerationRadPerSecSq.radians.perSecond.perSecond | ||
| inputs.feederAppliedVoltage = appliedVoltage | ||
| inputs.feederSupplyCurrent = 0.0.amps | ||
| inputs.feederStatorCurrent = feederSim.currentDrawAmps.amps | ||
| inputs.feederTemperature = 0.0.celsius | ||
| } | ||
|
|
||
| override fun setVoltage(voltage: ElectricalPotential) { | ||
| val clampedVoltage = | ||
| clamp(voltage, -FeederConstants.VOLTAGE_COMPENSATION, FeederConstants.VOLTAGE_COMPENSATION) | ||
| feederSim.setInputVoltage(clampedVoltage.inVolts) | ||
| appliedVoltage = clampedVoltage | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.