11package frc.team2767.deepspace.health
22
3- import com.ctre.phoenix.motorcontrol.ControlMode
43import com.ctre.phoenix.motorcontrol.ControlMode.PercentOutput
54import com.ctre.phoenix.motorcontrol.can.TalonSRX
5+ import edu.wpi.first.wpilibj.Timer
66import frc.team2767.deepspace.health.TalonPositionTest.State.*
77import kotlinx.html.TagConsumer
88import kotlinx.html.td
@@ -17,16 +17,16 @@ private val logger = KotlinLogging.logger {}
1717class TalonPositionTest (private val group : TalonGroup ) : Test, Reportable {
1818 override var name = " position test"
1919 var percentOutput = 0.0
20+ var warmUp = 0.25
2021 var peakVoltage = 12.0
21- var zeroGoodEnough = 5
22- var zeroTimeOutCount = 50
2322 var encoderTarget = 0
23+ var encoderGoodEnough = 5
2424 var encoderTimeOutCount = 0
25- var controlMode = ControlMode .MotionMagic
2625
2726 private var state = STARTING
27+ private var startTime = 0.0
2828 private var iteration = 0
29- private var passed = false
29+ private var startingPosition = 0
3030
3131 private lateinit var talon: TalonSRX
3232 private var currents = mutableListOf<Double >()
@@ -44,32 +44,24 @@ class TalonPositionTest(private val group: TalonGroup) : Test, Reportable {
4444 }
4545 logger.info { " $name starting" }
4646 talon = group.talons.first()
47- talon.set(controlMode, 0.0 )
48- state = ZEROING
47+ startingPosition = talon.selectedSensorPosition
48+ talon.set(PercentOutput , percentOutput)
49+ startTime = Timer .getFPGATimestamp()
50+ state = RUNNING
4951 }
5052
51- ZEROING -> {
52- if (talon.selectedSensorPosition.absoluteValue < zeroGoodEnough) {
53- logger.info { " successfully zeroed encoder" }
54- talon.set(PercentOutput , percentOutput)
55- iteration = 0
56- state = RUNNING
57- return
58- }
59- if (iteration++ > zeroTimeOutCount) {
60- logger.warn { " timed out waiting for encoder zero, encoder = ${talon.selectedSensorPosition} " }
61- state = STOPPED
62- }
53+ WARMING -> if (Timer .getFPGATimestamp() - startTime >= warmUp) {
54+ state = RUNNING
6355 }
6456
6557 RUNNING -> {
6658 currents.add(talon.outputCurrent)
6759 speeds.add(talon.selectedSensorVelocity)
6860
69- if (talon.selectedSensorPosition.absoluteValue > encoderTarget) {
61+ if (( talon.selectedSensorPosition - startingPosition) .absoluteValue > encoderTarget) {
7062 logger.info { " reached encoder target $encoderTarget " }
7163 talon.set(PercentOutput , 0.0 )
72- state = PASSED
64+ state = STOPPED
7365 return
7466 }
7567
@@ -80,17 +72,6 @@ class TalonPositionTest(private val group: TalonGroup) : Test, Reportable {
8072 }
8173 }
8274
83- PASSED -> {
84- passed = true
85- talon.set(controlMode, 0.0 )
86- state = RESETTING
87- }
88-
89- RESETTING -> {
90- if (talon.selectedSensorPosition.absoluteValue < zeroGoodEnough)
91- logger.info { " repositioned to zero, finishing test" }
92- state = STOPPED
93- }
9475
9576 STOPPED -> logger.info { " position test stopped" }
9677
@@ -124,10 +105,8 @@ class TalonPositionTest(private val group: TalonGroup) : Test, Reportable {
124105 @Suppress(" unused" )
125106 private enum class State {
126107 STARTING ,
127- ZEROING ,
108+ WARMING ,
128109 RUNNING ,
129- PASSED ,
130- RESETTING ,
131110 STOPPED
132111 }
133112}
0 commit comments