Skip to content

Commit 276e05c

Browse files
committed
Add velocity scalars for DT
1 parent d6ed458 commit 276e05c

File tree

2 files changed

+43
-8
lines changed

2 files changed

+43
-8
lines changed

src/main/java/frc/robot/commands/DriveCommands.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import frc.robot.subsystems.drive.DriveBase;
1616
import frc.robot.subsystems.drive.DriveConstants;
1717
import frc.robot.util.AllianceFlipUtil;
18+
import frc.robot.util.LoggedTunableNumber;
1819
import java.text.DecimalFormat;
1920
import java.text.NumberFormat;
2021
import java.util.LinkedList;
@@ -25,6 +26,12 @@
2526
public class DriveCommands {
2627
// Drive
2728
private static final double DEADBAND = 0.1;
29+
30+
private static final LoggedTunableNumber LINEAR_VELOCITY_SCALAR =
31+
new LoggedTunableNumber("TeleopDrive/LinearVelocityScalar", 1.0, true);
32+
private static final LoggedTunableNumber ANGULAR_VELOCITY_SCALAR =
33+
new LoggedTunableNumber("TeleopDrive/AngularVelocityScalar", 1.0, true);
34+
2835
private static final double ANGLE_KP = 5.0;
2936
private static final double ANGLE_KD = 0.4;
3037
private static final double ANGLE_MAX_VELOCITY = 8.0;
@@ -57,11 +64,13 @@ public static Command joystickDrive(
5764
omega = Math.copySign(Math.pow(omega, 2), omega);
5865

5966
// Generate robot relative speeds
67+
double linearVelocityScalar = LINEAR_VELOCITY_SCALAR.get();
68+
double angularVelocityScalar = ANGULAR_VELOCITY_SCALAR.get();
6069
var speeds =
6170
new ChassisSpeeds(
62-
x * DriveConstants.maxLinearVelocityMetersPerSec,
63-
y * DriveConstants.maxLinearVelocityMetersPerSec,
64-
omega * DriveConstants.maxAngularVelocityRadPerSec);
71+
x * DriveConstants.maxLinearVelocityMetersPerSec * linearVelocityScalar,
72+
y * DriveConstants.maxLinearVelocityMetersPerSec * linearVelocityScalar,
73+
omega * DriveConstants.maxAngularVelocityRadPerSec * angularVelocityScalar);
6574

6675
// Convert to field relative
6776
Rotation2d rotation = RobotState.getInstance().getRotation();
@@ -109,10 +118,11 @@ public static Command joystickDriveAtAngle(
109118
rotation.getRadians(), rotationSupplier.get().getRadians());
110119

111120
// Generate robot relative speeds
121+
double linearVelocityScalar = LINEAR_VELOCITY_SCALAR.get();
112122
var speeds =
113123
new ChassisSpeeds(
114-
x * DriveConstants.maxLinearVelocityMetersPerSec,
115-
y * DriveConstants.maxLinearVelocityMetersPerSec,
124+
x * DriveConstants.maxLinearVelocityMetersPerSec * linearVelocityScalar,
125+
y * DriveConstants.maxLinearVelocityMetersPerSec * linearVelocityScalar,
116126
omega);
117127

118128
// Convert to field relative

src/main/java/frc/robot/util/LoggedTunableNumber.java

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,38 @@ public class LoggedTunableNumber {
2020

2121
private LoggedNetworkNumber dashboardNumber;
2222

23+
private final boolean ntPubEnabled;
24+
2325
/**
2426
* Create a new LoggedTunableNumber
2527
*
2628
* @param dashboardKey Key on dashboard
29+
* @param alwaysEnabled Always publish modifiers to NT, even if not in Tuning Mode
2730
*/
28-
public LoggedTunableNumber(String dashboardKey) {
31+
public LoggedTunableNumber(String dashboardKey, boolean alwaysEnabled) {
2932
this.key = tableKey + "/" + dashboardKey;
33+
this.ntPubEnabled = alwaysEnabled;
34+
}
35+
36+
/**
37+
* Create a new LoggedTunableNumber
38+
*
39+
* @param dashboardKey Key on dashboard
40+
*/
41+
public LoggedTunableNumber(String dashboardKey) {
42+
this(dashboardKey, Constants.TUNING_MODE);
43+
}
44+
45+
/**
46+
* Create a new LoggedTunableNumber with the default value
47+
*
48+
* @param dashboardKey Key on dashboard
49+
* @param defaultValue Default value
50+
* @param alwaysEnabled Always publish modifiers to NT, even if not in Tuning Mode
51+
*/
52+
public LoggedTunableNumber(String dashboardKey, double defaultValue, boolean alwaysEnabled) {
53+
this(dashboardKey, alwaysEnabled);
54+
initDefault(defaultValue);
3055
}
3156

3257
/**
@@ -55,7 +80,7 @@ public void initDefault(double defaultValue) {
5580
}
5681

5782
this.defaultValue = defaultValue;
58-
if (Constants.TUNING_MODE) {
83+
if (ntPubEnabled) {
5984
dashboardNumber = new LoggedNetworkNumber(key, defaultValue);
6085
}
6186
}
@@ -74,7 +99,7 @@ public double get() {
7499
key));
75100
}
76101

77-
return Constants.TUNING_MODE ? dashboardNumber.get() : defaultValue;
102+
return ntPubEnabled ? dashboardNumber.get() : defaultValue;
78103
}
79104

80105
/**

0 commit comments

Comments
 (0)