File tree 3 files changed +31
-1
lines changed
src/main/java/frc/team4373/swerve 3 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ plugins {
14
14
}
15
15
16
16
group ' frc.team4373'
17
- version ' 2.0.1 '
17
+ version ' 2.1.0 '
18
18
19
19
sourceCompatibility = 1.11
20
20
Original file line number Diff line number Diff line change @@ -291,6 +291,18 @@ public BrakeMode getBrakeMode() {
291
291
return this .brakeMode ;
292
292
}
293
293
294
+
295
+ /**
296
+ * Sets the max acceleration for each wheel.
297
+ * @param maxAccel the maximum acceleration.
298
+ */
299
+ public void setMaxWheelAcceleration (double maxAccel ) {
300
+ right1 .setMaxWheelAcceleration (maxAccel );
301
+ right2 .setMaxWheelAcceleration (maxAccel );
302
+ left1 .setMaxWheelAcceleration (maxAccel );
303
+ left2 .setMaxWheelAcceleration (maxAccel );
304
+ }
305
+
294
306
/**
295
307
* Gets the swerve wheel with the specified ID.
296
308
* @param wheelID the ID of the wheel to fetch.
Original file line number Diff line number Diff line change @@ -17,6 +17,10 @@ class SwerveWheel {
17
17
18
18
private boolean isInverted = false ;
19
19
20
+ private double maxAcceleration = 2 ;
21
+
22
+ private double lastSetSpeed = 0 ;
23
+
20
24
/**
21
25
* Constructs a new swerve wheel for the specified wheel.
22
26
* @param driveMotorConfig the config for the drive motor.
@@ -90,6 +94,16 @@ class SwerveWheel {
90
94
*/
91
95
void set (double speed , double heading ) {
92
96
97
+ double acceleration = speed - lastSetSpeed ;
98
+
99
+ if (acceleration > maxAcceleration ) {
100
+ speed = lastSetSpeed + maxAcceleration ;
101
+ } else if (acceleration < -maxAcceleration ) {
102
+ speed = lastSetSpeed - maxAcceleration ;
103
+ }
104
+
105
+ lastSetSpeed = speed ;
106
+
93
107
heading *= SwerveConstants .DEGREES_TO_ENCODER_UNITS ;
94
108
95
109
double currentRotation = rotatorMotor .getSelectedSensorPosition ();
@@ -235,4 +249,8 @@ void resetAbsoluteEncoder() {
235
249
double getRotatorMotorVelocity () {
236
250
return rotatorMotor .getSelectedSensorVelocity ();
237
251
}
252
+
253
+ void setMaxWheelAcceleration (double maxAccel ) {
254
+ maxAcceleration = maxAccel ;
255
+ }
238
256
}
You can’t perform that action at this time.
0 commit comments