Apply heading velocity correction in localizer
This commit is contained in:
@ -34,6 +34,8 @@ public final class TwoDeadWheelLocalizer implements Localizer {
|
||||
|
||||
private final double inPerTick;
|
||||
|
||||
private double lastRawHeadingVel, headingVelOffset;
|
||||
|
||||
public TwoDeadWheelLocalizer(HardwareMap hardwareMap, IMU imu, double inPerTick) {
|
||||
par = new OverflowEncoder(new RawEncoder(hardwareMap.get(DcMotorEx.class, "par")));
|
||||
perp = new OverflowEncoder(new RawEncoder(hardwareMap.get(DcMotorEx.class, "perp")));
|
||||
@ -48,6 +50,16 @@ public final class TwoDeadWheelLocalizer implements Localizer {
|
||||
FlightRecorder.write("TWO_DEAD_WHEEL_PARAMS", PARAMS);
|
||||
}
|
||||
|
||||
// see https://github.com/FIRST-Tech-Challenge/FtcRobotController/issues/617
|
||||
private double getHeadingVelocity() {
|
||||
double rawHeadingVel = imu.getRobotAngularVelocity(AngleUnit.RADIANS).zRotationRate;
|
||||
if (Math.abs(rawHeadingVel - lastRawHeadingVel) > Math.PI) {
|
||||
headingVelOffset -= Math.signum(rawHeadingVel) * 2 * Math.PI;
|
||||
}
|
||||
lastRawHeadingVel = rawHeadingVel;
|
||||
return headingVelOffset + rawHeadingVel;
|
||||
}
|
||||
|
||||
public Twist2dDual<Time> update() {
|
||||
PositionVelocityPair parPosVel = par.getPositionAndVelocity();
|
||||
PositionVelocityPair perpPosVel = perp.getPositionAndVelocity();
|
||||
@ -57,7 +69,7 @@ public final class TwoDeadWheelLocalizer implements Localizer {
|
||||
int perpPosDelta = perpPosVel.position - lastPerpPos;
|
||||
double headingDelta = heading.minus(lastHeading);
|
||||
|
||||
double headingVel = imu.getRobotAngularVelocity(AngleUnit.RADIANS).zRotationRate;
|
||||
double headingVel = getHeadingVelocity();
|
||||
|
||||
Twist2dDual<Time> twist = new Twist2dDual<>(
|
||||
new Vector2dDual<>(
|
||||
|
Reference in New Issue
Block a user