Skip to content
This repository has been archived by the owner on Dec 19, 2024. It is now read-only.

Commit

Permalink
Asserts and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Craftzman7 committed Nov 17, 2024
1 parent ffb0412 commit 6f4b6b8
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 37 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ deploy {
// getTargetTypeClass is a shortcut to get the class type using a string

frcJava(getArtifactTypeClass('FRCJavaArtifact')) {
jvmArgs.add("-ea") // Remove this flag during comp to disable asserts
}

// Static files artifact
Expand Down
7 changes: 2 additions & 5 deletions src/main/java/com/frcteam3636/frc2024/CAN.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,9 @@ enum class REVMotorControllerId(val num: Int) {
BackRightDrivingMotor(3),
FrontRightDrivingMotor(4),

LeftShooterFlywheel(11),
RightShooterFlywheel(12),
Indexer(13),
AmpMech(14),
IndexerMotor(13),

UnderTheBumperIntakeRoller(21),
IntakeMotor(21),
}

fun CANSparkMax(id: REVMotorControllerId, type: CANSparkLowLevel.MotorType) =
Expand Down
18 changes: 14 additions & 4 deletions src/main/java/com/frcteam3636/frc2024/Robot.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.ctre.phoenix6.StatusSignal
import com.frcteam3636.frc2024.subsystems.drivetrain.Drivetrain
import com.frcteam3636.frc2024.subsystems.indexer.Indexer
import com.frcteam3636.frc2024.subsystems.intake.Intake
import com.frcteam3636.frc2024.subsystems.wrist.Wrist
import edu.wpi.first.hal.FRCNetComm.tInstances
import edu.wpi.first.hal.FRCNetComm.tResourceType
import edu.wpi.first.hal.HAL
Expand Down Expand Up @@ -79,9 +80,16 @@ object Robot : LoggedRobot() {
if (isReal()) {
Logger.addDataReceiver(WPILOGWriter()) // Log to a USB stick
Logger.addDataReceiver(NT4Publisher()) // Publish data to NetworkTables
PowerDistribution(
1, PowerDistribution.ModuleType.kRev
) // Enables power distribution logging
// Enables power distribution logging
if (model == Model.COMPETITION) {
PowerDistribution(
1, PowerDistribution.ModuleType.kRev
)
} else {
PowerDistribution(
1, PowerDistribution.ModuleType.kCTRE
)
}
} else {
val logPath = try {
// Pull the replay log from AdvantageScope (or prompt the user)
Expand Down Expand Up @@ -109,6 +117,8 @@ object Robot : LoggedRobot() {
private fun configureSubsystems() {
Drivetrain.register()
Indexer.register()
Intake.register()
Wrist.register()
}

/** Expose commands for autonomous routines to use and display an auto picker in Shuffleboard. */
Expand Down Expand Up @@ -187,7 +197,7 @@ object Robot : LoggedRobot() {
when (val key = Preferences.getString("Model", "competition")) {
"competition" -> Model.COMPETITION
"prototype" -> Model.PROTOTYPE
else -> throw Exception("invalid model found in preferences: $key")
else -> throw AssertionError("Invalid model found in preferences: $key")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import org.littletonrobotics.junction.Logger
object Indexer: Subsystem {
private var io: IndexerIO = IndexerIOReal()

var inputs = IndexerIO.IndexerInputs()
var inputs = IndexerIO.Inputs()

override fun periodic() {
io.updateInputs(inputs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public enum class BalloonState {
None
}

interface IndexerIO{
class IndexerInputs : LoggableInputs {
interface IndexerIO {
class Inputs : LoggableInputs {
var indexerVelocity = Rotation2d()
var indexerCurrent: Double = 0.0
var balloonState: BalloonState = BalloonState.None
Expand All @@ -32,38 +32,39 @@ interface IndexerIO{
balloonState = table.get("Balloon Color", balloonState)
}
}
fun updateInputs(inputs: IndexerInputs)
fun updateInputs(inputs: Inputs)

fun setSpinSpeed(speed: Double)
// percent of full speed
}

class IndexerIOReal: IndexerIO{
class IndexerIOReal : IndexerIO{
companion object Constants {
const val RED_CLASS = "red";
const val BLUE_CLASS = "blue";
const val NONE_CLASS = "none";
}

private var indexerWheel =
private var indexerMotor =
CANSparkFlex(
REVMotorControllerId.UnderTheBumperIntakeRoller,
REVMotorControllerId.IndexerMotor,
CANSparkLowLevel.MotorType.kBrushless
)

override fun updateInputs(inputs: IndexerIO.IndexerInputs) {
inputs.indexerVelocity = Rotation2d(indexerWheel.encoder.velocity)
inputs.indexerCurrent = indexerWheel.outputCurrent
override fun updateInputs(inputs: IndexerIO.Inputs) {
inputs.indexerVelocity = Rotation2d(indexerMotor.encoder.velocity)
inputs.indexerCurrent = indexerMotor.outputCurrent

val colorClass = LimelightHelpers.getClassifierClass("limelight");
when (colorClass) {
when (val colorClass = LimelightHelpers.getClassifierClass("limelight-sensor")) {
RED_CLASS -> inputs.balloonState = BalloonState.Red;
BLUE_CLASS -> inputs.balloonState = BalloonState.Blue;
NONE_CLASS -> inputs.balloonState = BalloonState.None;
else -> throw AssertionError("Unknown balloon class: $colorClass")
}
}

override fun setSpinSpeed(speed: Double) {
indexerWheel.set(speed)
assert(speed in -1.0..1.0)
indexerMotor.set(speed)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ object Intake: Subsystem {
Robot.Model.PROTOTYPE -> IntakeIO.IntakeIOSim()
}

var inputs = IntakeIO.IntakeInputs()
var inputs = IntakeIO.Inputs()

override fun periodic() {
Logger.processInputs("Intake", inputs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,33 @@ import org.littletonrobotics.junction.inputs.LoggableInputs


interface IntakeIO {
class IntakeInputs : LoggableInputs{
class Inputs : LoggableInputs {
var rollerVelocity = Rotation2d()
var current: Double = 0.0
var hasBalloon: Boolean = false
var balloonIsBlue: Boolean = false

override fun toLog(table: LogTable) {
table.put("UTB Roller Velocity", rollerVelocity)
table.put("UTB Current", current)
table.put("Has balloon", hasBalloon)
table.put("Balloon color", balloonIsBlue)
table.put("Intake Velocity", rollerVelocity)
table.put("Intake Current", current)
}

override fun fromLog(table: LogTable) {
rollerVelocity = table.get("UTB Roller Velocity", rollerVelocity)!![0]
current = table.get("UTB Current", current)
hasBalloon = table.get("Has balloon", hasBalloon)
balloonIsBlue = table.get("Balloon color", balloonIsBlue)
rollerVelocity = table.get("Intake Velocity", rollerVelocity)!![0]
current = table.get("Intake Current", current)
}


}

fun setSpeed(percent: Double)

class IntakeIOReal: IntakeIO {
private var motor =
CANSparkFlex(
REVMotorControllerId.UnderTheBumperIntakeRoller,
REVMotorControllerId.IntakeMotor,
CANSparkLowLevel.MotorType.kBrushless
)

override fun setSpeed(percent: Double) {
assert(percent in -1.0..1.0)
motor.set(percent)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import org.littletonrobotics.junction.Logger
object Wrist: Subsystem {
private var io: WristIO = WristIO.WristIOKraken()

var inputs = IntakeIO.IntakeInputs()
var inputs = WristIO.Inputs()

override fun periodic() {
Logger.processInputs("Wrist", inputs)
Expand Down

0 comments on commit 6f4b6b8

Please sign in to comment.