Skip to content

Commit 32fdb02

Browse files
authored
Merge pull request #109 from strykeforce/2024-fixes
2024.0.3 updates
2 parents f47d1e7 + facf988 commit 32fdb02

File tree

15 files changed

+859
-24
lines changed

15 files changed

+859
-24
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ plugins {
1111
}
1212

1313
group = "org.strykeforce"
14-
version = "24.0.2"
14+
version = "24.0.3"
1515

1616
sourceCompatibility = JavaVersion.VERSION_17
1717
targetCompatibility = JavaVersion.VERSION_17

src/main/java/org/strykeforce/swerve/V6TalonSwerveModule.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ public class V6TalonSwerveModule implements SwerveModule {
6868

6969
private int closedLoopSlot;
7070

71+
private boolean compensateLatency;
72+
7173
private V6TalonSwerveModule(V6Builder builder) {
7274

7375
azimuthTalon = builder.azimuthTalon;
@@ -82,6 +84,7 @@ private V6TalonSwerveModule(V6Builder builder) {
8284
units = builder.units;
8385
enableFOC = builder.enableFOC;
8486
closedLoopSlot = builder.closedLoopSlot;
87+
compensateLatency = builder.compensateLatency;
8588
resetDriveEncoder();
8689
}
8790

@@ -223,11 +226,14 @@ private double getDriveMetersPerSecond() {
223226
}
224227

225228
private double getDrivePositionMeters() {
229+
double latency = driveTalon.getPosition().getTimestamp().getLatency();
226230
double shaftPosition = driveTalon.getPosition().getValue(); // rotations
227231
double motorPosition = shaftPosition / driveCountsPerRev; // default = 1.0 for counts
228232
double wheelPosition = motorPosition * driveGearRatio;
229233
double wheelPositionMeters = wheelPosition * wheelCircumferenceMeters;
230-
return wheelPositionMeters;
234+
double velocityMetersPerSecond = getDriveMetersPerSecond();
235+
double wheelPositionMetersComp = wheelPositionMeters + latency * velocityMetersPerSecond;
236+
return compensateLatency ? wheelPositionMetersComp : wheelPositionMeters;
231237
}
232238

233239
private void setDriveClosedLoopMetersPerSecond(double metersPerSecond) {
@@ -303,6 +309,8 @@ public static class V6Builder {
303309

304310
private int closedLoopSlot = 0;
305311

312+
private boolean compensateLatency = false;
313+
306314
public V6Builder() {}
307315

308316
public V6Builder azimuthTalon(TalonSRX azimuthTalon) {
@@ -365,6 +373,11 @@ public V6Builder closedLoopSlot(int slot) {
365373
return this;
366374
}
367375

376+
public V6Builder latencyCompensation(boolean compensate) {
377+
this.compensateLatency = compensate;
378+
return this;
379+
}
380+
368381
public V6TalonSwerveModule build() {
369382
if (driveDeadbandMetersPerSecond < 0) {
370383
driveDeadbandMetersPerSecond = 0.01 * driveMaximumMetersPerSecond;

src/main/kotlin/org/strykeforce/healthcheck/Annotations.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import com.ctre.phoenix.motorcontrol.can.BaseTalon
66
annotation class HealthCheck(val order: Int = 0)
77

88
@Target(AnnotationTarget.FIELD)
9-
annotation class Position(val percentOutput: DoubleArray, val encoderChange: Int)
9+
annotation class Position(val percentOutput: DoubleArray, val encoderChange: Double)
1010

1111
@Target(AnnotationTarget.FIELD)
1212
annotation class Timed(val percentOutput: DoubleArray, val duration: Double = 5.0)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.strykeforce.healthcheck
2+
3+
interface Checkable {
4+
5+
fun getName(): String
6+
7+
8+
}

src/main/kotlin/org/strykeforce/healthcheck/HealthCheckCommand.kt

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@ package org.strykeforce.healthcheck
33
import edu.wpi.first.wpilibj2.command.Command
44
import edu.wpi.first.wpilibj2.command.Subsystem
55
import edu.wpi.first.wpilibj2.command.button.InternalButton
6+
import kotlinx.html.BUTTON
67
import mu.KotlinLogging
7-
import org.strykeforce.healthcheck.internal.DumpVisitor
8-
import org.strykeforce.healthcheck.internal.ReportServer
9-
import org.strykeforce.healthcheck.internal.RobotHealthCheck
10-
import org.strykeforce.healthcheck.internal.RobotHealthCheckBuilder
8+
import org.strykeforce.healthcheck.internal.*
119

1210
private val logger = KotlinLogging.logger {}
1311

@@ -52,5 +50,52 @@ class HealthCheckCommand(vararg subsystems: Subsystem) : Command() {
5250
isFinished = false
5351
}
5452

53+
override fun runsWhenDisabled() = true
54+
}
55+
56+
class IOHealthCheckCommand(var requirements: List<Subsystem>, vararg ios: Checkable): Command() {
57+
58+
companion object {
59+
@JvmField
60+
val BUTTON = InternalButton()
61+
}
62+
63+
private val robotHealthCheckBuilder = RobotHealCheckIOBuilder(*ios)
64+
private lateinit var robotHealthCheck: RobotIOHealthCheck
65+
66+
private var isFinished: Boolean = false
67+
68+
private var reportServer: ReportServerIO? = null
69+
70+
private val ioSet = ios.toSet()
71+
72+
private val requirementsSet = requirements.toSet()
73+
74+
override fun getRequirements() = requirementsSet
75+
76+
override fun initialize() {
77+
robotHealthCheck = robotHealthCheckBuilder.build()
78+
robotHealthCheck.initialize()
79+
BUTTON.setPressed(false)
80+
}
81+
82+
override fun execute() {
83+
if(robotHealthCheck.isFinished) {
84+
isFinished = true
85+
return
86+
}
87+
robotHealthCheck.execute()
88+
}
89+
90+
override fun isFinished() = isFinished
91+
92+
override fun end(interrupted: Boolean) {
93+
reportServer?.stop()
94+
reportServer = ReportServerIO(robotHealthCheck)
95+
96+
DumpVisitor().visit(robotHealthCheck)
97+
isFinished = false
98+
}
99+
55100
override fun runsWhenDisabled() = true
56101
}

0 commit comments

Comments
 (0)