Skip to content

Commit

Permalink
Remove slew rate limiting from throttle map
Browse files Browse the repository at this point in the history
  • Loading branch information
viggy96 committed Dec 20, 2023
1 parent 9df0d71 commit b5f4a1e
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 13 deletions.
13 changes: 2 additions & 11 deletions src/main/java/org/lasarobotics/drive/ThrottleMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,24 @@
import org.apache.commons.math3.analysis.polynomials.PolynomialSplineFunction;

import edu.wpi.first.math.MathUtil;
import edu.wpi.first.math.filter.SlewRateLimiter;

/** Throttle map */
public class ThrottleMap {
private final double MIN_DEADBAND = 0.001;
private final double MAX_DEADBAND = 0.2;
private final double MIN_ACCELERATION_TIME = 0.1;
private final double MAX_ACCELERATION_TIME = 10.0;

private double m_deadband = 0.0;

private HashMap<Double, Double> m_throttleInputMap = new HashMap<Double, Double>();
private SlewRateLimiter m_throttleSlewLimiter;

/**
* Create an instance of ThrottleMap
* @param throttleInputCurve Spline function characterising throttle input curve
* @param deadband Deadband for controller input [+0.001, +0.2]
* @param accelerationTime Number of seconds to take to get to max velocity [+0.1, +10.0]
* @param maxLinearSpeed maximum linear speed of robot (m/s)
*/
public ThrottleMap(PolynomialSplineFunction throttleInputCurve,
double deadband, double accelerationTime, double maxLinearSpeed) {
public ThrottleMap(PolynomialSplineFunction throttleInputCurve, double deadband, double maxLinearSpeed) {
this.m_deadband = MathUtil.clamp(deadband, MIN_DEADBAND, MAX_DEADBAND);
this.m_throttleSlewLimiter = new SlewRateLimiter(
maxLinearSpeed / MathUtil.clamp(accelerationTime, MIN_ACCELERATION_TIME, MAX_ACCELERATION_TIME)
);

// Fill throttle input hashmap
for (int i = 0; i <= 1000; i++) {
Expand All @@ -58,6 +49,6 @@ public double throttleLookup(double throttleLookup) {
throttleLookup = Math.copySign(Math.floor(Math.abs(throttleLookup) * 1000) / 1000, throttleLookup) + 0.0;
throttleLookup = MathUtil.clamp(throttleLookup, -1.0, +1.0);

return m_throttleSlewLimiter.calculate(m_throttleInputMap.get(throttleLookup));
return m_throttleInputMap.get(throttleLookup);
}
}
2 changes: 0 additions & 2 deletions src/test/java/org/lasarobotics/drive/ThrottleMapTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
public class ThrottleMapTest {
private final double DELTA = 1e-5;
private final double CONTROLLER_DEADBAND = 0.10;
private final double ACCELERATION_TIME = 0.1;
private final double[] DRIVE_THROTTLE_INPUT_CURVE_X = { 0.0, 0.100, 0.200, 0.300, 0.400, 0.500, 0.600, 0.700, 0.800, 0.900, 1.000 };
private final double[] DRIVE_THROTTLE_INPUT_CURVE_Y = { 0.0, 0.200, 0.400, 0.600, 0.800, 1.000, 1.200, 1.400, 1.600, 1.800, 2.000 };
private final SplineInterpolator SPLINE_INTERPOLATOR = new SplineInterpolator();
Expand All @@ -34,7 +33,6 @@ public void setup() {
m_throttleMap = new ThrottleMap(
DRIVE_THROTTLE_INPUT_CURVE,
CONTROLLER_DEADBAND,
ACCELERATION_TIME,
DRIVE_THROTTLE_INPUT_CURVE_Y[DRIVE_THROTTLE_INPUT_CURVE_Y.length - 1]
);
}
Expand Down

0 comments on commit b5f4a1e

Please sign in to comment.