This repository has been archived by the owner on Dec 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from FRC3636/cliber
feat: climber system
- Loading branch information
Showing
3 changed files
with
63 additions
and
0 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
18 changes: 18 additions & 0 deletions
18
src/main/java/com/frcteam3636/frc2024/subsystems/climber/Climber.kt
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 com.frcteam3636.frc2024.subsystems.climber | ||
|
||
|
||
import edu.wpi.first.wpilibj.RobotBase | ||
import edu.wpi.first.wpilibj2.command.Subsystem | ||
|
||
class Climber: Subsystem { | ||
private var io: ClimberIO = if (RobotBase.isReal()) { | ||
ClimberIOReal() | ||
} else { | ||
TODO() | ||
} | ||
var inputs = ClimberIO.ClimberInputs() | ||
|
||
override fun periodic() { | ||
io.updateInputs(inputs) | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/main/java/com/frcteam3636/frc2024/subsystems/climber/ClimberIO.kt
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,43 @@ | ||
package com.frcteam3636.frc2024.subsystems.climber | ||
|
||
import com.frcteam3636.frc2024.can.CANSparkMax | ||
import com.frcteam3636.frc2024.can.REVMotorControllerId | ||
import com.revrobotics.CANSparkLowLevel | ||
import com.revrobotics.SparkAbsoluteEncoder | ||
import edu.wpi.first.math.geometry.Rotation2d | ||
import edu.wpi.first.math.util.Units | ||
import org.littletonrobotics.junction.AutoLog | ||
|
||
interface ClimberIO { | ||
@AutoLog | ||
class ClimberInputs { | ||
var climberPosition = Rotation2d() | ||
} | ||
|
||
fun updateInputs(inputs: ClimberInputs) | ||
|
||
fun moveClimber(speed: Double) {} | ||
} | ||
class ClimberIOReal: ClimberIO { | ||
companion object { | ||
const val CLIMBER_GEAR_RATIO = 1.0 | ||
} | ||
|
||
|
||
private var climberMotor = CANSparkMax(REVMotorControllerId.ClimberMotor, CANSparkLowLevel.MotorType.kBrushless).apply{ | ||
burnFlash() | ||
} | ||
private val climberEncoder = climberMotor.getAbsoluteEncoder(SparkAbsoluteEncoder.Type.kDutyCycle).apply { | ||
velocityConversionFactor = Units.rotationsToRadians(1.0) * CLIMBER_GEAR_RATIO / 60 | ||
positionConversionFactor = Units.rotationsToRadians(1.0) * CLIMBER_GEAR_RATIO | ||
} | ||
|
||
override fun updateInputs(inputs: ClimberIO.ClimberInputs) { | ||
inputs.climberPosition = Rotation2d(climberEncoder.position) | ||
} | ||
|
||
|
||
override fun moveClimber(speed: Double) { | ||
climberMotor.set(speed) | ||
} | ||
} |