@@ -16,6 +16,8 @@ public class TeleopDrive extends Command {
1616 Drivetrain dt ;
1717 Joystick leftJoy , rightJoy ;
1818
19+ double prevSpeed = 0 , prevLeft = 0 , prevRight = 0 ;
20+
1921 /**
2022 * Handles all the teleoperated driving functionality
2123 *
@@ -27,6 +29,10 @@ public TeleopDrive(Drivetrain dt, Joystick leftJoy, Joystick rightJoy) {
2729 this .dt = dt ;
2830 this .leftJoy = leftJoy ;
2931 this .rightJoy = rightJoy ;
32+
33+ if (!SmartDashboard .containsKey ("Gradual Drive Max dV" )) {
34+ SmartDashboard .putNumber ("Gradual Drive Max dV" , 0.5 ); // between zero (no movement) to 2 (any movement)
35+ }
3036 }
3137
3238 @ Override
@@ -56,6 +62,14 @@ private void arcadeDrive() {
5662 rot *= SmartDashboard .getNumber ("Rotation Slow Ratio" , 0.35 );
5763 }
5864
65+ if (SmartDashboard .getBoolean ("Gradual Drive" , false )) {
66+ double dV = SmartDashboard .getNumber ("Gradual Drive Max dV" , 0.5 );
67+ if (Math .abs (speed - prevSpeed ) > dV ) {
68+ speed = prevSpeed + dV * Math .signum (speed - prevSpeed );
69+ }
70+ }
71+ prevSpeed = speed ;
72+
5973 double left , right ;
6074
6175 // double maxInput = Math.copySign(Math.max(Math.abs(speed), Math.abs(rot)),
@@ -107,6 +121,18 @@ private void tankDrive() {
107121 right *= SmartDashboard .getNumber ("Speed Slow Ratio" , 0.5 );
108122 }
109123
124+ if (SmartDashboard .getBoolean ("Gradual Drive" , false )) {
125+ double dV = SmartDashboard .getNumber ("Gradual Drive Max dV" , 0.5 );
126+ if (Math .abs (left - prevLeft ) > dV ) {
127+ left = prevLeft + dV * Math .signum (left - prevLeft );
128+ }
129+ if (Math .abs (right - prevRight ) > dV ) {
130+ right = prevRight + dV * Math .signum (right - prevRight );
131+ }
132+ }
133+ prevLeft = left ;
134+ prevRight = right ;
135+
110136 if (SmartDashboard .getBoolean ("Characterized Drive" , true )) {
111137 charDrive (left , right );
112138 } else {
0 commit comments