Git Product home page Git Product logo

Comments (6)

virtuald avatar virtuald commented on August 16, 2024 2

This was closed in #138, which was reverted... so I presume that this bug still exists? This should be reopened in that case.

from allwpilib.

calcmogul avatar calcmogul commented on August 16, 2024

Actually, we only need to keep a buffer of inputs. Here's some math:

a, b, c, and d are inputs. s is the setpoint. "s - a" is the error with respect to a.

Currently, we average the errors in GetAvgError():
avgError = ((s - a) + (s - b) + (s - c) + (s - d)) / 4
= (-(a - s) + -(b - s) + -(c - s) + -(d - s)) / 4
= -((a - s) + (b - s) + (c - s) + (d - s)) / 4
= -(a + b + c + d - 4 * s) / 4
= -(a + b + c + d - 4 * s) / 4
= -(a + b + c + d - 4 * s) / 4
= (4 * s - (a + b + c + d)) / 4
= s - (a + b + c + d) / 4

Therefore, GetAvgError() could instead return the current setpoint minus the input average. This would make anything using GetAvgError(), like OnTarget(), more robust to setpoint changes.

from allwpilib.

PeterMitrano avatar PeterMitrano commented on August 16, 2024

👍 for application of some basic math.

from allwpilib.

calcmogul avatar calcmogul commented on August 16, 2024

How should we go about fixing it this time? Apparently using doubles in a large FIR filter (moving average) causes rounding errors due to so many additions. We could approximate it with an IIR filter and avoid that problem. Using a cutoff frequency isn't necessarily intuitive, but it provides more tuning hints than the size of the FIR filter does. Teams would probably tune both by guessing and checking anyway.

from allwpilib.

calcmogul avatar calcmogul commented on August 16, 2024

Changing this to an IIR filter breaks the interface. If we're going to do interface breakage, I'd rather move the filter out of PIDController entirely because the state estimation should be separate from the controller. If the user does the following:

frc::Encoder encoder{1, 2};
frc::LinearDigitalFilter filter = frc::LinearDigitalFilter::SinglePoleIIR(&encoder, 0.3, 0.05);
frc::Spark motor{0};
PIDController pid{kP, kI, kD, &encoder, &motor};

the input is filtered instead of the error (which is more correct) and the user can decide what filtering would be best.

from allwpilib.

calcmogul avatar calcmogul commented on August 16, 2024

Fixed by #38.

from allwpilib.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.