Skip to content
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

Add elevator code #1

Merged
merged 506 commits into from
Jan 19, 2025
Merged
Show file tree
Hide file tree
Changes from 137 commits
Commits
Show all changes
506 commits
Select commit Hold shift + click to select a range
009cb3e
Merge pull request #57 from Galaxia5987/feature/gripper/sim
rakrakon Jan 18, 2025
65cb808
Update src/main/kotlin/frc/robot/subsystems/intake/roller/RollerIORea…
rakrakon Jan 18, 2025
5c913e2
Change ElevatorIOReal to use MotionMagicTorqueCurrentFOC
rakrakon Jan 18, 2025
ccace07
Remove enabling FOC in the init
Emma03L Jan 18, 2025
494a16c
Add setPower and updateInputs
Emma03L Jan 18, 2025
0785ab8
Change position setpoint to be private
rakrakon Jan 18, 2025
b7c2392
Add RollerIO
Emma03L Jan 14, 2025
63f52cc
Add RollerConstants
Emma03L Jan 14, 2025
d6818a2
Add Roller subsystem
Emma03L Jan 14, 2025
bdd343d
Remove unnecessary return types
Emma03L Jan 15, 2025
0515f2b
Remove companion object from subsystem
Emma03L Jan 15, 2025
0504863
Update inputs in periodic
Emma03L Jan 15, 2025
7fde0fe
Create geometry factories file
katzuv Jan 18, 2025
95325bb
Remove unnecessary return type
Emma03L Jan 15, 2025
91058e0
Process inputs
Emma03L Jan 15, 2025
4fd7e59
Add return type and change to runOnce
Emma03L Jan 15, 2025
9962e77
Use this::class.simpleName
Emma03L Jan 15, 2025
7d76833
Reformat setPower function
Emma03L Jan 16, 2025
586adb6
Log Roller inputs inside an intake file
Emma03L Jan 16, 2025
72864ff
Merge remote-tracking branch 'origin/feature/intake/roller/subsystem-…
Emma03L Jan 18, 2025
0916ea4
Apply spotless
Emma03L Jan 18, 2025
6ff4a10
Add mechanism2d
rakrakon Jan 18, 2025
1415eb8
Use zero() in RollerInputs
Emma03L Jan 18, 2025
4964372
Add moment of inertia constant
Emma03L Jan 14, 2025
24b7702
Add RollerIOSim
Emma03L Jan 14, 2025
1698b2e
Apply spotless
Emma03L Jan 14, 2025
e657a8a
Turn moment of inertia to a measure
Emma03L Jan 15, 2025
658a4a7
Update motor in io sim
Emma03L Jan 16, 2025
56f5ee0
Merge remote-tracking branch 'origin/feature/intake/roller/io-sim' in…
Emma03L Jan 18, 2025
1eb0224
Apply spotless
Emma03L Jan 18, 2025
1bb4b5c
Add `Translation2d` factories
katzuv Jan 18, 2025
53a6493
Add `Rotation2d` factories
katzuv Jan 18, 2025
9c3a2f6
Add `Pose2d` factories
katzuv Jan 18, 2025
648423e
Add `Translation3d` factories
katzuv Jan 18, 2025
f15c6f2
Add `Rotation3d` factories
katzuv Jan 18, 2025
531dcda
Add `Pose3d` factories
katzuv Jan 18, 2025
0ba9b79
Remove `Pose2d` to `Pose3d` extension function because a WPILib alter…
katzuv Jan 18, 2025
99e7126
Create visualizer first parameters
katzuv Jan 17, 2025
a57cd5a
Add function that returns the elevator poses
katzuv Jan 17, 2025
7608234
Add function that returns the wrist pose
katzuv Jan 17, 2025
96db87b
Add climber angle getter parameter
katzuv Jan 17, 2025
541558f
Calculate climber pose
katzuv Jan 17, 2025
ea6c69b
`@AutoLogOutput` visualize function
katzuv Jan 17, 2025
0a80987
Add gripper Coral rollers angle getter parameter
katzuv Jan 18, 2025
bc40d03
Calculate Coral rollers poses
katzuv Jan 18, 2025
ba7b9d5
Add Algae remover angle getter parameter
katzuv Jan 18, 2025
88c22bd
Calculate Algae remove poses
katzuv Jan 18, 2025
684d8c5
Add intake roller pose
katzuv Jan 18, 2025
d59c2a6
Rearrange parameters
katzuv Jan 18, 2025
ddd7e84
Remove `getWristPose()` function
katzuv Jan 18, 2025
52fead9
Move climber pose calculation to end of function
katzuv Jan 18, 2025
00585c6
Take code out of class and rearrange array creation
katzuv Jan 18, 2025
9a9652d
Add BlockBot CAD files
katzuv Jan 18, 2025
29260c4
Add preliminary robot CAD files
katzuv Jan 18, 2025
7d57417
Bring back class
katzuv Jan 18, 2025
4d55e3a
Merge pull request #54 from Galaxia5987/feature/intake/roller/io-sim
Emma03L Jan 18, 2025
b919e1a
Merge pull request #69 from Galaxia5987/feature/intake/roller/io-real
Emma03L Jan 18, 2025
dc8b7cd
Change setPower to a runEnd command
Emma03L Jan 18, 2025
fe5508d
Add command names
Emma03L Jan 18, 2025
ba7a21e
Apply spotless
Emma03L Jan 18, 2025
30f28cc
Change setPower to a startEnd command
Emma03L Jan 18, 2025
e4a180c
Merge pull request #53 from Galaxia5987/feature/intake/roller/subsyst…
Emma03L Jan 18, 2025
d4cc1bd
Refactor atSetpoint trigger to ues `setpointValue` instead of `setpoi…
rakrakon Jan 19, 2025
73cbf97
Rename elevator mechanism to elevatorLigament
rakrakon Jan 19, 2025
6f845a5
Delete CAD files
rakrakon Jan 19, 2025
9b4fafa
Add Second Elevator Motor
rakrakon Jan 19, 2025
42239a2
Merge pull request #60 from Galaxia5987/feature/wrist/subsystem-io
rakrakon Jan 19, 2025
cc90409
Spotless
rakrakon Jan 19, 2025
61fff57
Fix `isConnected` input in VisionIOLimelight
rakrakon Jan 19, 2025
68ffdc5
Add ChoreoLib-2025.0.1.json
rakrakon Jan 19, 2025
4f1ec3c
Update PathplannerLib.json
rakrakon Jan 19, 2025
e7e08e7
Merge pull request #75 from Galaxia5987/feature/vis
rakrakon Jan 19, 2025
f07ffa4
Update vendor deps
Emma03L Jan 19, 2025
a60f71c
Update ModuleIOTalonFX
Emma03L Jan 19, 2025
0f2eda1
Apply spotless
Emma03L Jan 19, 2025
cf5d4ba
Revert "Fix `isConnected` input in VisionIOLimelight"
Emma03L Jan 19, 2025
6591477
Merge pull request #73 from Galaxia5987/update-versions
Emma03L Jan 19, 2025
6421d79
Merge pull request #74 from Galaxia5987/feature/geometry-classes-fact…
katzuv Jan 19, 2025
3c31898
Change setHeight parameter name to height
Emma03L Jan 19, 2025
197280f
Change aux motor to not oppose the main motor
Emma03L Jan 19, 2025
3d45715
Remove second control request
Emma03L Jan 19, 2025
f6599e1
Create build.yml
katzuv Jan 19, 2025
bd45f1b
Rename `.GitHub` directory to `.github`
katzuv Jan 19, 2025
9c9e2d2
Merge pull request #77 from Galaxia5987/feature/ci
katzuv Jan 19, 2025
8071cfc
Fix wrist compilation error
rakrakon Jan 19, 2025
5f22422
Spotless
rakrakon Jan 19, 2025
0af58d4
Add command to remove algae
rakrakon Jan 19, 2025
ac77b1c
Merge pull request #78 from Galaxia5987/hotfix/compile
rakrakon Jan 19, 2025
5c440c0
Fix `removeAlgae` command
rakrakon Jan 19, 2025
94dc8ae
Change `setPower`to `setVoltage`
rakrakon Jan 19, 2025
7e4ddbd
Change `setVoltage` Command to be `startEnd`
rakrakon Jan 19, 2025
aca8b9f
Merge pull request #56 from Galaxia5987/feature/gripper/subsystem-io
rakrakon Jan 19, 2025
46e74f7
Use timeConversionFactor in the extension functions
Emma03L Jan 19, 2025
d473d91
Apply spotless
Emma03L Jan 19, 2025
f87f2c5
Merge pull request #79 from Galaxia5987/feature/better-measure-extens…
Emma03L Jan 19, 2025
5a70e14
Fix typo
rakrakon Jan 19, 2025
e594d2f
Use correct variable for second stage height
katzuv Jan 19, 2025
96718bf
Rename "carriage" to "second stage"
katzuv Jan 19, 2025
b3db87e
Fix comment location
katzuv Jan 19, 2025
b70ce84
Use new geometry classes
katzuv Jan 19, 2025
691419b
Spotless
katzuv Jan 19, 2025
b50cd5c
Add logging to setpoint
rakrakon Jan 19, 2025
9563335
Fix typo in ENCODER_OFFSET
rakrakon Jan 19, 2025
b526e91
Add `motor.update()` in ElevatorIOSim
rakrakon Jan 19, 2025
fdc7f85
Fix elevator simulation
rakrakon Jan 19, 2025
ec688cb
Spotless
rakrakon Jan 19, 2025
64bc1e9
Change `numMotors` in simulation to 2
rakrakon Jan 19, 2025
61fbf1c
Add command for each position
rakrakon Jan 19, 2025
0a7bbc0
Merge pull request #80 from Galaxia5987/hotfix/use-new-geometry-facto…
Emma03L Jan 19, 2025
47cdd6b
Add elevator
Noga18 Dec 17, 2024
39bfddd
Fix TunerConstants
Emma03L Dec 19, 2024
b8fa92f
Change setHeight to use Distance instead of a double
Emma03L Dec 19, 2024
1ed4f47
Add heightSetpoint input
Emma03L Dec 19, 2024
a54f970
Apply motor configs
Emma03L Dec 19, 2024
c25617c
Change setPower to use the .set() function
Emma03L Dec 19, 2024
3c9707c
Fix units when updating carriageHeight and add SPROCKET_RADIUS constant
Emma03L Dec 19, 2024
6a43550
Update motor id
Emma03L Dec 19, 2024
0afe7d8
Turn functions in subsystem to commands and change their parameter types
Emma03L Dec 19, 2024
2354681
Add kD
Emma03L Dec 20, 2024
afb6274
Change SPROCKET_RADIUS to Double
Emma03L Dec 20, 2024
2f5de76
Add imports
Emma03L Dec 20, 2024
2d3fada
Delete SensorToMechanismRatio
Emma03L Dec 20, 2024
c03f4d8
Change setPosition to Commands run
Emma03L Dec 20, 2024
aa272f7
spotlessApply
Noga18 Dec 31, 2024
de5afb5
Add setHeight
Noga18 Dec 31, 2024
192d6bb
Add updateInputs
Noga18 Dec 31, 2024
32151cd
Delete reset
Noga18 Dec 31, 2024
804e22f
Add setPower
Noga18 Dec 31, 2024
5a0c513
Add motor TalonFXSim
Noga18 Dec 31, 2024
e685b82
Add motorPosititonRequest
Noga18 Dec 31, 2024
5b2fb91
spotlessApply
Noga18 Dec 31, 2024
8f2b5b1
Remove comment
Noga18 Dec 31, 2024
0509e4a
Add ROTATIONS_TO_CENTIMETER
Noga18 Dec 31, 2024
d442663
SpotlessApply
Noga18 Dec 31, 2024
d9af7d7
Change class name
Noga18 Dec 31, 2024
aa5e4f4
Change Commands.run to run
Noga18 Dec 31, 2024
4e55514
SpotlessApply
Noga18 Dec 31, 2024
4bec4aa
Change Commands.run to run
Noga18 Jan 6, 2025
c19c395
change fun reset
Noga18 Jan 6, 2025
ffaa35e
change fun reset again
Noga18 Jan 14, 2025
99e6140
Change fun reset again
Noga18 Jan 14, 2025
34b3640
Change SPROCKET_RADIUS to private
Noga18 Jan 14, 2025
beb5f87
Delete lines
Noga18 Jan 14, 2025
8ffc260
Rename from carriageHeight to Height
Noga18 Jan 14, 2025
d49bf30
Delete Redundant whitespace
Noga18 Jan 14, 2025
7395a67
Rename heightSetPoint to SetPoint
Noga18 Jan 14, 2025
9d524f2
Change fun reset
Noga18 Jan 15, 2025
f1a818f
Delete line
Noga18 Jan 15, 2025
a79f47c
Added CAD models (No rollers yet) with config.json for AS
DavidMasin Jan 15, 2025
6f626f4
Delete reset
Noga18 Jan 15, 2025
92c4f50
Rename height
Noga18 Jan 15, 2025
204b898
Rename from position to height
Noga18 Jan 15, 2025
35f8c85
log setpoint
Noga18 Jan 15, 2025
a5d1825
Change MAX_HEIGHT
Noga18 Jan 15, 2025
bb2a74d
Delete companion object
Noga18 Jan 15, 2025
5cd7167
Add var positionSetpoint
Noga18 Jan 15, 2025
3f408b2
Add line
Noga18 Jan 15, 2025
57e960d
Add AutoLog
Noga18 Jan 15, 2025
ef66e5a
Add WEIGHT
Noga18 Jan 15, 2025
a79b59e
Add talonFXsim
Noga18 Jan 15, 2025
ac841d1
Rename from reset to resetAbsoluteEncoder
Noga18 Jan 15, 2025
586fc8c
Add const val ENCODER_OFSET
Noga18 Jan 15, 2025
75035d3
Add var noOffsetAbsoluteEncoderPosition and var absoluteEncoderHeight
Noga18 Jan 15, 2025
fbd4633
Add encoder and motorPositionRequest
Noga18 Jan 15, 2025
d3a3ccb
Add encoderConfig
Noga18 Jan 15, 2025
ef00848
Add inputs to updateInputs
Noga18 Jan 15, 2025
35928d0
Add const val ENCODER_ID
Noga18 Jan 15, 2025
7c70e8c
Rename reset to resetAbsoluteEncoder
Noga18 Jan 15, 2025
c185d16
Add elevator
Noga18 Dec 17, 2024
4e5ab25
Change setHeight to use Distance instead of a double
Emma03L Dec 19, 2024
558d11d
Add heightSetpoint input
Emma03L Dec 19, 2024
1d91990
Apply motor configs
Emma03L Dec 19, 2024
b87f991
Change setPower to use the .set() function
Emma03L Dec 19, 2024
068c664
Fix units when updating carriageHeight and add SPROCKET_RADIUS constant
Emma03L Dec 19, 2024
fe28310
Update motor id
Emma03L Dec 19, 2024
8c5f997
Turn functions in subsystem to commands and change their parameter types
Emma03L Dec 19, 2024
3f8c5c5
Add kD
Emma03L Dec 20, 2024
0b9ccce
Change SPROCKET_RADIUS to Double
Emma03L Dec 20, 2024
820ad03
Add imports
Emma03L Dec 20, 2024
3ff92cd
Delete SensorToMechanismRatio
Emma03L Dec 20, 2024
c1ab949
Change setPosition to Commands run
Emma03L Dec 20, 2024
92be26e
spotlessApply
Noga18 Dec 31, 2024
a4c334c
Add setHeight
Noga18 Dec 31, 2024
bcafc81
Add updateInputs
Noga18 Dec 31, 2024
8fc6085
Delete reset
Noga18 Dec 31, 2024
c842d37
Add setPower
Noga18 Dec 31, 2024
9279795
Add motor TalonFXSim
Noga18 Dec 31, 2024
d251d27
Add motorPosititonRequest
Noga18 Dec 31, 2024
b6f73bd
spotlessApply
Noga18 Dec 31, 2024
1a25f91
Remove comment
Noga18 Dec 31, 2024
d201e72
Calibrate PID
Emma03L Dec 20, 2024
ae19365
Add ROTATIONS_TO_CENTIMETER
Noga18 Dec 31, 2024
045ea19
SpotlessApply
Noga18 Dec 31, 2024
31547af
Change class name
Noga18 Dec 31, 2024
81bc6d1
Change Commands.run to run
Noga18 Dec 31, 2024
2ffae7a
SpotlessApply
Noga18 Dec 31, 2024
7beed94
Change Commands.run to run
Noga18 Jan 6, 2025
7950985
change fun reset
Noga18 Jan 6, 2025
d99957a
change fun reset again
Noga18 Jan 14, 2025
280c1a5
Change fun reset again
Noga18 Jan 14, 2025
ca08b77
Change SPROCKET_RADIUS to private
Noga18 Jan 14, 2025
c875474
Delete lines
Noga18 Jan 14, 2025
e8bdf38
Rename from carriageHeight to Height
Noga18 Jan 14, 2025
0444a08
Delete Redundant whitespace
Noga18 Jan 14, 2025
0f14545
Rename heightSetPoint to SetPoint
Noga18 Jan 14, 2025
6043533
Change fun reset
Noga18 Jan 15, 2025
803e5b6
Delete line
Noga18 Jan 15, 2025
9009e78
Delete reset
Noga18 Jan 15, 2025
a947446
Rename height
Noga18 Jan 15, 2025
95651ad
Rename from position to height
Noga18 Jan 15, 2025
9c9469d
log setpoint
Noga18 Jan 15, 2025
f6245b1
Change MAX_HEIGHT
Noga18 Jan 15, 2025
c6ca799
Delete companion object
Noga18 Jan 15, 2025
b511de6
Add var positionSetpoint
Noga18 Jan 15, 2025
8718c5f
Add line
Noga18 Jan 15, 2025
37492f5
Add AutoLog
Noga18 Jan 15, 2025
07bc929
Add WEIGHT
Noga18 Jan 15, 2025
4c1396e
Add talonFXsim
Noga18 Jan 15, 2025
846df73
Rename from reset to resetAbsoluteEncoder
Noga18 Jan 15, 2025
11bde05
Update usage of TalonFXSim
Noga18 Jan 15, 2025
4261e59
Apply spotless
Noga18 Jan 15, 2025
bebcb9c
Fix typo in applied voltage + spotless
rakrakon Jan 18, 2025
a6e2e30
Relieved the garbage collect :)
rakrakon Jan 18, 2025
95b8967
Move lambda argument out of parenthesis
rakrakon Jan 18, 2025
8a2cbe4
Refactor `setPower` & `setPosition` to be more concise
rakrakon Jan 18, 2025
389fadc
Add `apply` to encoder config
rakrakon Jan 18, 2025
2b2683b
Remove measure object creation in ElevatorPeriodic
rakrakon Jan 18, 2025
6bd6c8f
Spotless
rakrakon Jan 18, 2025
4598b30
Change ElevatorIOReal to use MotionMagicTorqueCurrentFOC
rakrakon Jan 18, 2025
8ac8f8b
Change position setpoint to be private
rakrakon Jan 18, 2025
4205cd4
Add mechanism2d
rakrakon Jan 18, 2025
e25e751
Rename elevator mechanism to elevatorLigament
rakrakon Jan 19, 2025
58846ae
Delete CAD files
rakrakon Jan 19, 2025
35bfcf6
Add Second Elevator Motor
rakrakon Jan 19, 2025
d86ed3e
Spotless
rakrakon Jan 19, 2025
3bd95d8
Change setHeight parameter name to height
Emma03L Jan 19, 2025
91c7bac
Change aux motor to not oppose the main motor
Emma03L Jan 19, 2025
a529672
Remove second control request
Emma03L Jan 19, 2025
66a8620
Fix typo
rakrakon Jan 19, 2025
f01ea9a
Add logging to setpoint
rakrakon Jan 19, 2025
81370c0
Fix typo in ENCODER_OFFSET
rakrakon Jan 19, 2025
9b0db1b
Add `motor.update()` in ElevatorIOSim
rakrakon Jan 19, 2025
de05cb1
Fix elevator simulation
rakrakon Jan 19, 2025
9fcb589
Spotless
rakrakon Jan 19, 2025
034ce4f
Change `numMotors` in simulation to 2
rakrakon Jan 19, 2025
d646913
Add command for each position
rakrakon Jan 19, 2025
d8fbf46
Merge remote-tracking branch 'origin/feature/elevator' into feature/e…
rakrakon Jan 19, 2025
e09fbb2
Spotless
rakrakon Jan 19, 2025
08a53db
Use extension functions
rakrakon Jan 19, 2025
afe2d3e
Spotless
rakrakon Jan 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ annotation/build/
# Simulation GUI and other tools window save file
*-window.json

.\src\main\kotlin\frc\robot\BuildConstants.java
/src/main/kotlin/frc/robot/BuildConstants.java

simgui*
networktables.json
Expand Down
119 changes: 119 additions & 0 deletions files/cad/config.json
katzuv marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
{
"name":"Andromeda",
"rotations": [
{
"axis": "x",
"degrees": 90
},
{
"axis": "z",
"degrees": -90
}
],
"position": [
-0.651,
0,
0
],
"cameras":[],
"components":[
{
"zeroedRotations":[
{
"axis": "x",
"degrees": 90
},
{
"axis": "z",
"degrees": -90
}
],
"zeroedPosition":[
-0.61,
0,
0
]
},
{
"zeroedRotations":[
{
"axis": "y",
"degrees": -90
},
{
"axis": "x",
"degrees": -90
}
],
"zeroedPosition":[
-0.44,
0,
0.265
]
},
{
"zeroedRotations":[
{
"axis": "x",
"degrees": -90
},
{
"axis": "z",
"degrees": -90
},
{
"axis": "y",
"degrees": 180
}
],
"zeroedPosition":[
-0.80,
0,
-0.12
]
},
{
"zeroedRotations":[
{
"axis": "x",
"degrees": -90
},
{
"axis": "z",
"degrees": -90
},
{
"axis": "y",
"degrees": 180
}
],
"zeroedPosition":[
-0.80,
0,
-0.15
]
},
{
"zeroedRotations":[
{
"axis": "x",
"degrees": -90
},
{
"axis": "z",
"degrees": -90
},
{
"axis": "y",
"degrees": 180
}
],
"zeroedPosition":[
-0.80,
0,
-0.80
]
}

]
}
Binary file added files/cad/model.glb
Binary file not shown.
Binary file added files/cad/model_0.glb
Binary file not shown.
Binary file added files/cad/model_1.glb
Binary file not shown.
Binary file added files/cad/model_2.glb
Binary file not shown.
Binary file added files/cad/model_3.glb
Binary file not shown.
Binary file added files/cad/model_4.glb
Binary file not shown.
1 change: 1 addition & 0 deletions src/main/kotlin/frc/robot/generated/TunerConstants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

37 changes: 37 additions & 0 deletions src/main/kotlin/frc/robot/subsystems/elevator/Elevator.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package frc.robot.subsystems.elevator

import edu.wpi.first.units.Units
import edu.wpi.first.units.measure.Distance
import edu.wpi.first.wpilibj2.command.Command
import edu.wpi.first.wpilibj2.command.SubsystemBase
import java.util.function.DoubleSupplier
import org.littletonrobotics.junction.AutoLogOutput
import org.littletonrobotics.junction.Logger
import org.littletonrobotics.junction.mechanism.LoggedMechanism2d
import org.littletonrobotics.junction.mechanism.LoggedMechanismLigament2d

class Elevator(private val io: ElevatorIO) : SubsystemBase() {
katzuv marked this conversation as resolved.
Show resolved Hide resolved
private val mechanism = LoggedMechanism2d(3.0, 3.0)
private val root = mechanism.getRoot("Elevator", 2.0, 0.0)
private val elevator = root.append(LoggedMechanismLigament2d("ElevatorLigament", 1.0, 90.0))
@AutoLogOutput private var positionSetpoint: Distance = Units.Millimeters.of(0.0)

fun setPosition(position: Distance): Command = runOnce {
positionSetpoint = position
io.setHeight(position)
}

fun setPower(percentOutput: DoubleSupplier): Command = run {
io.setPower(percentOutput.asDouble)
}

fun resetAbsoluteEncoder(): Command = runOnce(io::resetAbsoluteEncoder)

override fun periodic() {
io.updateInputs()
Logger.processInputs(this.name, io.inputs)
Logger.recordOutput("Elevator/Mechanism2d", mechanism)

elevator.length = io.inputs.height.`in`(Units.Meters)
katzuv marked this conversation as resolved.
Show resolved Hide resolved
}
}
24 changes: 24 additions & 0 deletions src/main/kotlin/frc/robot/subsystems/elevator/ElevatorConstants.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package frc.robot.subsystems.elevator

import edu.wpi.first.units.*
import edu.wpi.first.units.measure.Distance
import frc.robot.lib.Gains
import frc.robot.lib.selectGainsBasedOnMode
import kotlin.math.PI

val MAX_HEIGHT: Distance = Units.Meters.of(1.3)
const val GEAR_RATIO = (1.0 / 12.0) * (42.0 / 48.0)
katzuv marked this conversation as resolved.
Show resolved Hide resolved
const val FIRST_STAGE_RATIO = 2.0
const val WEIGHT = 0.0
const val ENCODER_OFSET = 0.0
private val SPROCKET_RADIUS: Distance = Units.Millimeters.of(36.4 / 2)
private val ROTATIONS_TO_CENTIMETERS_RATIO =
GEAR_RATIO *
FIRST_STAGE_RATIO *
(SPROCKET_RADIUS.`in`(Units.Centimeter) * 2 * PI)
val ROTATIONS_TO_CENTIMETER: Measure<out PerUnit<DistanceUnit, AngleUnit>> =
Units.Centimeters.per(Units.Rotations).of(ROTATIONS_TO_CENTIMETERS_RATIO)
val CENTIMETERS_TO_ROTATIONS: Measure<out PerUnit<AngleUnit, DistanceUnit>> =
Units.Rotations.per(Units.Centimeter).of(1 / ROTATIONS_TO_CENTIMETERS_RATIO)

val GAINS = selectGainsBasedOnMode(Gains(kP = 20.0, kD = 1.0), Gains())
28 changes: 28 additions & 0 deletions src/main/kotlin/frc/robot/subsystems/elevator/ElevatorIO.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package frc.robot.subsystems.elevator

import edu.wpi.first.units.Units
import edu.wpi.first.units.measure.Angle
import edu.wpi.first.units.measure.Distance
import edu.wpi.first.units.measure.Voltage
import org.team9432.annotation.Logged

interface ElevatorIO {
val inputs: LoggedElevatorInputs

fun setHeight(position: Distance) {}

fun setPower(percentOutput: Double) {}

fun resetAbsoluteEncoder() {}

fun updateInputs() {}

@Logged
open class ElevatorInputs {
var height: Distance = Units.Meters.of(0.0)
var setpoint: Distance = Units.Meters.of(0.0)
var appliedVoltage: Voltage = Units.Volts.of(0.0)
var noOffsetAbsoluteEncoderPosition: Angle = Units.Rotations.of(0.0)
var absoluteEncoderHeight: Distance = Units.Meters.of(0.0)
}
}
79 changes: 79 additions & 0 deletions src/main/kotlin/frc/robot/subsystems/elevator/ElevatorIOReal.kt
Noga18 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package frc.robot.subsystems.elevator

import ENCODER_ID
import MOTOR_ID
import com.ctre.phoenix6.configs.*
import com.ctre.phoenix6.controls.MotionMagicTorqueCurrentFOC
import com.ctre.phoenix6.controls.PositionVoltage
import com.ctre.phoenix6.hardware.CANcoder
import com.ctre.phoenix6.hardware.TalonFX
import com.ctre.phoenix6.signals.InvertedValue
import com.ctre.phoenix6.signals.NeutralModeValue
import edu.wpi.first.units.measure.Distance

class ElevatorIOReal : ElevatorIO {
override val inputs = LoggedElevatorInputs()
private val motor = TalonFX(MOTOR_ID)
rakrakon marked this conversation as resolved.
Show resolved Hide resolved
private val encoder = CANcoder(ENCODER_ID)
private val motorPositionRequest = MotionMagicTorqueCurrentFOC(0.0)

init {
val motorConfig =
TalonFXConfiguration().apply {
MotorOutput =
MotorOutputConfigs().apply {
NeutralMode = NeutralModeValue.Brake
Inverted = InvertedValue.Clockwise_Positive
}
Feedback = FeedbackConfigs().apply { RotorToSensorRatio = 1.0 }
Slot0 =
Slot0Configs().apply {
kP = GAINS.kP
kI = GAINS.kI
kD = GAINS.kD
}
CurrentLimits =
CurrentLimitsConfigs().apply {
StatorCurrentLimitEnable = true
SupplyCurrentLimitEnable = true
StatorCurrentLimit = 80.0
SupplyCurrentLimit = 40.0
}
}
motor.configurator.apply(motorConfig)

val encoderConfig =
CANcoderConfiguration().apply {
MagnetSensor.MagnetOffset = ENCODER_OFSET
}

encoder.configurator.apply(encoderConfig)
}

override fun setHeight(height: Distance) {
motor.setControl(
motorPositionRequest.withPosition(
height.timesConversionFactor(CENTIMETERS_TO_ROTATIONS)
)
)
}

override fun setPower(percentOutput: Double) {
motor.set(percentOutput)
}

override fun resetAbsoluteEncoder() {
motor.setPosition(0.0)
}

override fun updateInputs() {
inputs.appliedVoltage = motor.motorVoltage.value
inputs.height =
motor.position.value.timesConversionFactor(ROTATIONS_TO_CENTIMETER)
inputs.noOffsetAbsoluteEncoderPosition = encoder.absolutePosition.value
inputs.absoluteEncoderHeight =
encoder.position.value.timesConversionFactor(
ROTATIONS_TO_CENTIMETER
)
}
}
48 changes: 48 additions & 0 deletions src/main/kotlin/frc/robot/subsystems/elevator/ElevatorIOSim.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package frc.robot.subsystems.elevator

import com.ctre.phoenix6.controls.DutyCycleOut
import com.ctre.phoenix6.controls.PositionVoltage
import edu.wpi.first.math.system.plant.DCMotor
import edu.wpi.first.math.system.plant.LinearSystemId
import edu.wpi.first.units.Units
import edu.wpi.first.units.measure.Distance
import frc.robot.lib.motors.TalonFXSim
import frc.robot.lib.motors.TalonType

class ElevatorIOSim : ElevatorIO {
override val inputs = LoggedElevatorInputs()
private val motorPosititonRequest = PositionVoltage(0.0)
private val dutyCycleRequest = DutyCycleOut(0.0)
private val motor =
TalonFXSim(
LinearSystemId.createElevatorSystem(
DCMotor.getKrakenX60(2),
WEIGHT,
36.4 / 2,
GEAR_RATIO
),
2,
GEAR_RATIO,
1.0,
TalonType.KRAKEN
)

override fun setHeight(position: Distance) {
motor.setControl(
motorPosititonRequest.withPosition(
position.timesConversionFactor(CENTIMETERS_TO_ROTATIONS)
)
)
}

override fun setPower(percentOutput: Double) {
motor.setControl(dutyCycleRequest.withOutput(percentOutput))
}

override fun updateInputs() {
inputs.appliedVoltage = Units.Volts.of(motor.appliedVoltage)
inputs.height =
Units.Rotations.of(motor.position)
.timesConversionFactor(ROTATIONS_TO_CENTIMETER)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const val MOTOR_ID = 12

Check notice on line 1 in src/main/kotlin/frc/robot/subsystems/elevator/ElevatorPorts.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Package name does not match containing directory

Package directive does not match the file location
const val ENCODER_ID = 21
Loading