Skip to content

Should PoE and PoM have independent kP values?  #30

@halmos

Description

@halmos

Sorry to make so many issues here - this one is more of a question / discussion / observation about the rational of the pOn implementation than it is a bug report:

When using mix of pOnM and pOnE, the two parameters share a single pK value, but track independent inputs: The pOnM is proportion to the relative change in input since that last reading (dInput). Since we are measuring the time base in microseconds, the pmTerm value is likely to be small, or at least, proportional to the sample time. The pOnE is an absolute measurement of the error without a time scale.

I believe that, maybe, it is necessary for kP to be split into two separate parameters for a mixed pOn value to work in most cases. It’s a bit complicated to try to explain the reasoning in prose, but I’ve written out an example below in which the error is proportionally much larger than the dInput to illustrate how a single kP is unable to produce workable values for both the pOnE and pOnM.

// SetTunings input values
void PID::SetTunings(double Kp, double Ki, double Kd, int POn) {
Kp = 10;
Ki = 1;
Kd = 0;
POn = .5;
DOn = 0;
sampleTimeUs = 100000;
outMax = 2000;
outMin = 0;

// SetTunings Output values
SampleTimeSec = .1; 100000 / 1000000;
Kp = 10;
Ki = 1; // 10 * .1 
Kd = 0;
Kpe = 5; // 10 x .5;
Kpm = 5; //  10 x (1 - .5)
}
…

// Compute
bool PID::Compute() {
input = 1000;
lastInput = 999;
setPoint = 1100;
outputSum = 100;

dInput = 1; // 1000 - 999
error = 100; // 1100 - 1000

pmTerm = 5; // 5 * 1; (kpm * dInput)
peTerm = 500; // 5* 100 (kpe * error)
iTerm = 100; // 1 * 100 (ki * 100)
dmTerm = 0;
deTerm = 0;

// accumulate i
outputSum += iTerm // outputSum = 100 + 100 = 200

// acculate pOnM
outputSum = outputSum - pmTerm; // outputSum = 200 - 5 = 195;

output = outputSum + 500 + 0 - 0 // outputSum = 195 + 500 = 695
}

In the above, you can see that the peTerm significantly out-ways the pmTerm in the final output.

I realize that the solution that has been implemented is what brettbeauregard proposed in his proposed "Setpoint Weighting" in the blog post on pOnM. However, I’m not sure that their solution was fully resolved.

I believe that for the pOn "Setpoint Weighting" to be practical, there would need to be separate parameters for the kP: one for the error and one for the measurement. eg. kPm and kPe. The pOn value would then serve as the proportional mix of those two values.

Input tuning values: 
Kpm = 100
Kpe = 10
pOn = .5

Output tuning values:
Kpm = 100 * .5 = 50;
Kpe = 10 * (1-.5) = 5;
…

Otherwise the two kP inputs (measurement and error) need to be on the same scale to work. This might happen in a few rare instance, but I believe that in most situations, those two values are most likely to be measured independently.

And again, many thanks for creating and maintaining this library!

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