Skip to content

Commit 0bab73d

Browse files
authored
Merge branch 'master' into jhh/migrating-to-yaml-syntax
2 parents 95b313d + f867df3 commit 0bab73d

File tree

5 files changed

+102
-6
lines changed

5 files changed

+102
-6
lines changed

src/main/java/frc/team2767/deepspace/command/TeleOpDriveCommand.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import frc.team2767.deepspace.control.DriverControls;
88
import frc.team2767.deepspace.subsystem.DriveSubsystem;
99
import frc.team2767.deepspace.subsystem.VisionSubsystem;
10+
import frc.team2767.deepspace.util.VectorRateLimit;
1011
import org.slf4j.Logger;
1112
import org.slf4j.LoggerFactory;
1213
import org.strykeforce.thirdcoast.util.ExpoScale;
@@ -18,18 +19,21 @@ public final class TeleOpDriveCommand extends Command {
1819
private static final double DEADBAND = 0.05;
1920
private static final double YAW_EXPO = 0.65; // 0.5
2021
private static final double DRIVE_EXPO = 0.65; // 0.5
22+
private static final double VECTOR_LIMIT = 0.05;
2123
private static final double kP = 0.1;
2224
private static final double MAX_FWD_STR = 0.7;
2325
private static final double MAX_YAW = 0.6;
2426
private static DriverControls controls;
2527
private final Logger logger = LoggerFactory.getLogger(this.getClass());
2628
private final ExpoScale yawExpo;
2729
private final ExpoScale driveExpo;
30+
private final VectorRateLimit vectorLimit;
2831

2932
public TeleOpDriveCommand() {
3033
requires(DRIVE);
3134
this.yawExpo = new ExpoScale(DEADBAND, YAW_EXPO);
3235
this.driveExpo = new ExpoScale(DEADBAND, DRIVE_EXPO);
36+
this.vectorLimit = new VectorRateLimit(VECTOR_LIMIT);
3337
}
3438

3539
@Override
@@ -46,11 +50,16 @@ protected void execute() {
4650
double forward = driveExpo.apply(controls.getForward());
4751
double strafe = driveExpo.apply(controls.getStrafe());
4852

53+
// double forward = controls.getForward();
54+
// double strafe = controls.getStrafe();
55+
4956
forward = maximum(forward, MAX_FWD_STR);
5057
strafe = maximum(strafe, MAX_FWD_STR);
5158
yaw = maximum(yaw, MAX_YAW);
5259

53-
DRIVE.drive(forward, strafe, yaw);
60+
double[] output = vectorLimit.apply(forward, strafe);
61+
62+
DRIVE.drive(output[0], output[1], yaw);
5463
}
5564

5665
@Override

src/main/java/frc/team2767/deepspace/subsystem/VisionSubsystem.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ public class VisionSubsystem extends Subsystem implements Measurable {
2929
private static final double CAMERA_X = 3.5;
3030
private static final double CAMERA_Y_LEFT = -13.5;
3131
private static final double CAMERA_Y_RIGHT = 13.5;
32-
private static final double GLUE_CORRECTION_FACTOR_RIGHT = -1.8181; // -2.21
33-
private static final double GLUE_CORRECTION_FACTOR_LEFT = 0.8556; // 0.6417
32+
private static final double GLUE_CORRECTION_FACTOR_RIGHT = -1.9251; // -1.8181
33+
private static final double GLUE_CORRECTION_FACTOR_LEFT = 0.9625; // 0.8556
3434
private static final double CAMERA_DEGREES_PER_PIXEL_ADJUSTMENT_RIGHT =
3535
1.0; // 1.0 is zero value 0.85
3636
private static final double CAMERA_DEGREES_PER_PIXEL_ADJUSTMENT_LEFT =
@@ -41,10 +41,10 @@ public class VisionSubsystem extends Subsystem implements Measurable {
4141
private static final double CAMERA_RANGE_OFFSET_RIGHT = -5.7751; // -5.02
4242
private static final double CAMERA_RANGE_SLOPE_LEFT = 1.0437; // 1.061
4343
private static final double CAMERA_RANGE_OFFSET_LEFT = -4.3828; // -4.92
44-
// NEGATIVE = TOWARDS FIELD LEFT (this one was negative)
44+
// NEGATIVE = TOWARDS FIELD LEFT (this one was negative) from driver station perspective
4545
private static final double STRAFE_CORRECTION_RIGHT =
46-
-0.5; // -1.0 // NEGATIVE TO FIELD LEFT FOR THIS ONE?
47-
private static final double STRAFE_CORRECTION_LEFT = 0.5; // was positive
46+
-0.75; // -1.0 // NEGATIVE TO FIELD LEFT FOR THIS ONE
47+
private static final double STRAFE_CORRECTION_LEFT = 0; // was positive
4848
private static final String RANGE = "RANGE";
4949
private static final String CORRECTED_BEARING = "CORRECTED_BEARING";
5050
private static final String LIGHT_STATE = "LIGHT_STATE";
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package frc.team2767.deepspace.util;
2+
3+
public class VectorRateLimit {
4+
private static final Double CLOSE_ENOUGH = 0.0001;
5+
private final double rateLimit;
6+
7+
private double maxFwdStp;
8+
private double maxStrStp;
9+
10+
private double curVel;
11+
12+
private double[] output = {0, 0};
13+
14+
public VectorRateLimit(double rateLimit) {
15+
this.rateLimit = rateLimit;
16+
}
17+
18+
public double[] apply(double forward, double strafe) {
19+
curVel = Math.hypot(forward, strafe);
20+
21+
// Calculate Steps
22+
maxFwdStp = Math.sin(Math.atan2(forward, strafe));
23+
maxStrStp = Math.cos(Math.atan2(forward, strafe));
24+
25+
if (Math.abs(maxFwdStp - 0) < CLOSE_ENOUGH) {
26+
maxFwdStp = rateLimit * (maxFwdStp - Math.sin(Math.atan2(output[0], output[1])));
27+
} else maxFwdStp = rateLimit * maxFwdStp;
28+
29+
if (Math.abs(maxStrStp - 0) < CLOSE_ENOUGH) {
30+
maxStrStp = rateLimit * (maxStrStp - Math.cos(Math.atan2(output[0], output[1])));
31+
} else maxStrStp = rateLimit * maxStrStp;
32+
33+
// Calculate Forward Component
34+
if (Math.abs(forward - output[0]) > Math.abs(maxFwdStp)) {
35+
output[0] = output[0] + Math.copySign(maxFwdStp, forward - output[0]);
36+
} else output[0] = forward;
37+
38+
// Calculate Strafe Component
39+
if (Math.abs(strafe - output[1]) > Math.abs(maxStrStp)) {
40+
output[1] = output[1] + Math.copySign(maxStrStp, strafe - output[1]);
41+
} else output[1] = strafe;
42+
43+
return output;
44+
}
45+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package frc.team2767.deepspace.util;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
5+
import org.assertj.core.data.Percentage;
6+
import org.junit.jupiter.params.ParameterizedTest;
7+
import org.junit.jupiter.params.provider.CsvFileSource;
8+
9+
class VectorRateLimitTest {
10+
11+
private static double[] fwdOutput;
12+
private static double[] strOutput;
13+
private static final double TOLERANCE = 1;
14+
15+
@ParameterizedTest
16+
@CsvFileSource(resources = "/sticks.csv", numLinesToSkip = 1)
17+
void getFwd(
18+
double rateLimit, double forward, double strafe, double expectedFwd, double expectedStr) {
19+
VectorRateLimit vectorLimit = new VectorRateLimit(rateLimit);
20+
21+
fwdOutput = vectorLimit.apply(forward, strafe);
22+
23+
assertThat(fwdOutput[0]).isCloseTo(expectedFwd, Percentage.withPercentage(TOLERANCE));
24+
}
25+
26+
@ParameterizedTest
27+
@CsvFileSource(resources = "/sticks.csv", numLinesToSkip = 1)
28+
void getStr(
29+
double rateLimit, double forward, double strafe, double expectedFwd, double expectedStr) {
30+
VectorRateLimit vectorRateLimit = new VectorRateLimit(rateLimit);
31+
32+
strOutput = vectorRateLimit.apply(forward, strafe);
33+
34+
assertThat(strOutput[1]).isCloseTo(expectedStr, Percentage.withPercentage(TOLERANCE));
35+
}
36+
}

src/test/resources/sticks.csv

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
rateLimit,forward,strafe,expectedFwd,expectedStr
2+
0.4,1,0,0.4,0
3+
0.2,1,1,0.1414,0.1414
4+
0.2,1,0.2,0.1961,0.0392
5+
0.2,-1,0,-0.2,0
6+
0.2,-1,0.5,-0.1789,0.0894

0 commit comments

Comments
 (0)