Skip to content

Commit c5e9f9b

Browse files
committed
Allow position test to run from arbitrary pos
1 parent 2caa194 commit c5e9f9b

File tree

2 files changed

+18
-39
lines changed

2 files changed

+18
-39
lines changed

src/main/kotlin/frc/team2767/deepspace/command/HealthCheckCommand.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class HealthCheckCommand : Command() {
9393
percentOutput = 0.2
9494
encoderTarget = 10_000
9595
encoderTimeOutCount = 5000
96-
zeroGoodEnough = 1500
96+
encoderGoodEnough = 1500
9797
}
9898

9999
positionTalon {
@@ -109,7 +109,7 @@ class HealthCheckCommand : Command() {
109109

110110
positionTest {
111111
percentOutput = 0.2
112-
zeroGoodEnough = 200
112+
encoderGoodEnough = 200
113113
encoderTarget = 2500
114114
encoderTimeOutCount = 500
115115
}
@@ -121,14 +121,14 @@ class HealthCheckCommand : Command() {
121121

122122
positionTest {
123123
percentOutput = 0.2
124-
zeroGoodEnough = 50
124+
encoderGoodEnough = 50
125125
encoderTarget = 3000
126126
encoderTimeOutCount = 500
127127
}
128128

129129
positionTest {
130130
percentOutput = -0.2
131-
zeroGoodEnough = 50
131+
encoderGoodEnough = 50
132132
encoderTarget = 3000
133133
encoderTimeOutCount = 250
134134
}

src/main/kotlin/frc/team2767/deepspace/health/TalonPositionTest.kt

Lines changed: 14 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package frc.team2767.deepspace.health
22

3-
import com.ctre.phoenix.motorcontrol.ControlMode
43
import com.ctre.phoenix.motorcontrol.ControlMode.PercentOutput
54
import com.ctre.phoenix.motorcontrol.can.TalonSRX
5+
import edu.wpi.first.wpilibj.Timer
66
import frc.team2767.deepspace.health.TalonPositionTest.State.*
77
import kotlinx.html.TagConsumer
88
import kotlinx.html.td
@@ -17,16 +17,16 @@ private val logger = KotlinLogging.logger {}
1717
class 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

Comments
 (0)