Skip to content

Commit 3db2c09

Browse files
committed
Update WPILib, only check angle once when setting module angle
1 parent 5daed21 commit 3db2c09

File tree

4 files changed

+9
-6
lines changed

4 files changed

+9
-6
lines changed

examples/mk3-minibot/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
plugins {
22
id 'application'
33
id 'com.github.johnrengelman.shadow'
4-
id 'edu.wpi.first.GradleRIO' version "2024.1.1"
4+
id 'edu.wpi.first.GradleRIO' version "2024.2.1"
55
}
66

77
application {

examples/mk3-testchassis/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
plugins {
22
id 'application'
33
id 'com.github.johnrengelman.shadow'
4-
id 'edu.wpi.first.GradleRIO' version "2024.1.1"
4+
id 'edu.wpi.first.GradleRIO' version "2024.2.1"
55
}
66

77
application {

gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
org.gradle.warning.mode=all
22

33
# dependency versions
4-
wpilib_version = 2024.1.1
4+
wpilib_version = 2024.2.1
55
ctre_phoenix_version = 24.1.0
66
revlib_version = 2024.2.0

src/main/java/com/swervedrivespecialties/swervelib/SwerveModuleFactory.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,17 @@ public void set(double driveVoltage, double steerAngle) {
127127
steerAngle += 2.0 * Math.PI;
128128
}
129129

130-
double difference = steerAngle - getSteerAngle();
131-
// Change the target angle so the difference is in the range [-pi, pi) instead of [0, 2pi)
130+
double currentAngle = getSteerAngle();
131+
132+
// [0, 2pi) - [0, 2pi) = (-2pi, 2pi)
133+
double difference = steerAngle - currentAngle;
134+
// Change the target angle so the difference is in the range [-pi, pi) instead of (-2pi, 2pi)
132135
if (difference >= Math.PI) {
133136
steerAngle -= 2.0 * Math.PI;
134137
} else if (difference < -Math.PI) {
135138
steerAngle += 2.0 * Math.PI;
136139
}
137-
difference = steerAngle - getSteerAngle(); // Recalculate difference
140+
difference = steerAngle - currentAngle; // Recalculate difference
138141

139142
// If the difference is greater than 90 deg or less than -90 deg the drive can be inverted so the total
140143
// movement of the module is less than 90 deg

0 commit comments

Comments
 (0)