Skip to content

Issue with D component #9

@maksoff

Description

@maksoff

Code now (bi-linear transform):

pid->differentiator = -(2.0f * pid->Kd * (measurement - pid->prevMeasurement)
                        + (2.0f * pid->tau - pid->T) * pid->differentiator)
                        / (2.0f * pid->tau + pid->T);

if you assume tau = 0, e[n] - e[n-1] = 0, then you'll get: D[n] = D[n-1], so it keeps always the previous value (and doesn't go to 0).
if you assume tau >>T, e[n] - e[n-1] = 0, then you'll get: D[n] = -1*D[n-1], so it keeps oscillating (and doesn't go to zero).

After reviewing other sources, I suggest using Backward-Euler transform s→(z-1)/z, then you'll get:

D[n] = K[d]/(tau + T)*(e[n] - e[n-1]) + tau/(tau + T)*D[n-1] // classical form
D[n] = K[d]/(tau + T)*(measurement[n-1] - measurement[n]) + tau/(tau + T)*D[n-1] // derivative on measurement

in this case it works as expected, for both "test cases" from above, if e[n] - e[n-1] = 0 then D[n] = 0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions