Skip to content

Commit

Permalink
Corrected REV conversion factors part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel1464 committed Oct 3, 2024
1 parent e786896 commit d3b24c5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
21 changes: 14 additions & 7 deletions src/main/kotlin/frc/chargers/hardware/motorcontrol/ChargerSpark.kt
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,11 @@ open class ChargerSpark<BaseMotorType: CANSparkBase>(
override val inverted: Boolean get() = base.inverted

override fun setPositionSetpoint(position: Angle, feedforward: Voltage) {
require(positionPIDConfigured){" You must specify a positionPID value using the configure(positionPID = PIDConstants(p,i,d)) method. "}
if (!positionPIDConfigured) {
DriverStation.reportError("You must specify a positionPID value using the " +
"motor.configure(positionPID = PIDConstants(p,i,d)) method.", true)
return
}
base.pidController.setReference(
position.inUnit(rotations),
CANSparkBase.ControlType.kPosition,
Expand All @@ -125,14 +129,17 @@ open class ChargerSpark<BaseMotorType: CANSparkBase>(
}

override fun setVelocitySetpoint(velocity: AngularVelocity, feedforward: Voltage) {
require(velocityPIDConfigured){" You must specify a velocityPID value using the configure(velocityPID = PIDConstants(p,i,d)) method. "}
val velocityAsDouble = if (useAbsoluteEncoder) {
velocity.inUnit(rotations / minutes)
} else {
velocity.inUnit(rotations / seconds)
if (!velocityPIDConfigured) {
DriverStation.reportError("You must specify a positionPID value using the " +
"motor.configure(velocityPID = PIDConstants(p,i,d)) method.", true)
return
}
base.pidController.setReference(
velocityAsDouble,
if (useAbsoluteEncoder) {
velocity.inUnit(rotations / seconds)
} else {
velocity.inUnit(rotations / minutes)
},
CANSparkBase.ControlType.kVelocity,
1,
feedforward.inUnit(volts)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,23 @@ class ChargerTalonFX(
override val inverted: Boolean get() = base.inverted

override fun setPositionSetpoint(position: Angle, feedforward: Voltage) {
require(positionPIDConfigured){" You must specify a positionPID value using the configure(positionPID = PIDConstants(p,i,d)) method. "}
if (!positionPIDConfigured) {
DriverStation.reportError("You must specify a positionPID value using the " +
"motor.configure(positionPID = PIDConstants(p,i,d)) method.", true)
return
}
setPosRequest.Position = position.inUnit(rotations)
setPosRequest.FeedForward = feedforward.inUnit(volts)
base.setControl(setPosRequest)
nonTalonFXFollowers.forEach{ it.setPositionSetpoint(position, feedforward) }
}

override fun setVelocitySetpoint(velocity: AngularVelocity, feedforward: Voltage) {
require(velocityPIDConfigured){" You must specify a velocityPID value using the configure(velocityPID = PIDConstants(p,i,d)) method. "}
if (!velocityPIDConfigured) {
DriverStation.reportError("You must specify a positionPID value using the " +
"motor.configure(velocityPID = PIDConstants(p,i,d)) method.", true)
return
}
setVelRequest.Velocity = velocity.inUnit(rotations / seconds)
setVelRequest.FeedForward = feedforward.inUnit(volts)
base.setControl(setVelRequest)
Expand Down

0 comments on commit d3b24c5

Please sign in to comment.