PDA

View Full Version : Wind River WPI library submission for bug fixes?


JamesTerm
09-08-2011, 10:43 AM
Can someone tell me who I can talk to if I find an issue or bug in the WPI library code?

The issue is in PIDController.cpp line 117 (in the version that has been released to the public). How can I get latest version of this file?

I have details of the issue, along with the fix here
http://www.termstech.com/articles/PID_Kalman.html

But in short the symptom is a case where if the error is too large it is possible that the total error will cease to move in the opposite direction causing the robot to lock up. The fix I offer will address this case.

AustinSchuh
09-08-2011, 12:53 PM
Can you post your proposed change to WPILib here? I'm interested to see how you implemented it and what assumptions you made.

JamesTerm
09-08-2011, 02:29 PM
Can you post your proposed change to WPILib here? I'm interested to see how you implemented it and what assumptions you made.

Ok here is the fix:
//Note: here is the original code, which is correct but incomplete;
//if (((m_totalError + m_error) * m_I < m_maximumOutput) && ((m_totalError + m_error) * m_I > m_minimumOutput))
// m_totalError += m_error;

double TotalErrorCheck=(m_totalError + m_error) * m_I;
if (TotalErrorCheck < m_maximumOutput)
{
....if (TotalErrorCheck > m_minimumOutput)
........m_totalError += m_error;
....else //less than the minimum output
....{
........//accumulate by an error which would equal the minimum output
........double MinError=(m_minimumOutput - ( m_I * m_totalError)) / m_I;
........m_totalError += MinError;
....}
}
else //greater than the maximum output
{
....//accumulate by an error which would equal the maximum output
....double MaxError=(m_maximumOutput - ( m_I * m_totalError)) / m_I;
....m_totalError += MaxError;
}


This number run (of the robot moving using encoders) tells the story:
Check this http://www.termstech.com/articles/PID110901_1.txt
for complete number run

RV -0.040647 dzk=1 y=4.037800 p=-0.106089 e=0.000000 d=0.106089 cs=156.624764
RV -0.041011 dzk=1 y=4.037800 p=-0.164875 e=0.000000 d=0.164875 cs=155.246980
RV -0.041390 dzk=1 y=4.037800 p=-0.224818 e=0.000000 d=0.224818 cs=153.388493
RV -0.041762 dzk=1 y=4.037800 p=-0.281590 e=0.000000 d=0.281590 cs=151.078999
RV -0.042159 dzk=1 y=4.037800 p=-0.339745 e=0.000000 d=0.339745 cs=148.302881
RV -0.042555 dzk=1 y=4.037800 p=-0.394746 e=0.000000 d=0.394746 cs=145.089912
RV -0.042976 dzk=1 y=4.037800 p=-0.449805 e=0.000000 d=0.449805 cs=141.436411
RV -0.043426 dzk=1 y=4.037800 p=-0.504680 e=0.000000 d=0.504680 cs=137.344099
RV -0.043912 dzk=1 y=4.037800 p=-0.559629 e=0.000000 d=0.559629 cs=132.812116
RV -0.044461 dzk=1 y=4.037800 p=-0.617131 e=0.000000 d=0.617131 cs=127.817566
RV -0.045068 dzk=1 y=4.037800 p=-0.674717 e=0.000000 d=0.674717 cs=122.362240
RV -0.045724 dzk=1 y=4.037800 p=-0.729541 e=0.000000 d=0.729541 cs=116.471092
RV -0.046475 dzk=1 y=4.037800 p=-0.785583 e=0.000000 d=0.785583 cs=110.130384
RV -0.047354 dzk=1 y=4.037800 p=-0.843600 e=0.000000 d=0.843600 cs=103.323566
RV -0.048349 dzk=1 y=4.037800 p=-0.898565 e=0.000000 d=0.898565 cs=96.080081
RV -0.049589 dzk=1 y=4.037800 p=-0.959747 e=0.000000 d=0.959747 cs=88.340925
RV -0.051123 dzk=1 y=4.037800 p=-1.023518 e=0.000000 d=1.023518 cs=80.089011
RV -0.000181 dzk=0 y=4.037800 p=-1.078485 e=0.000000 d=1.078485 cs=71.406161
RV -0.000254 dzk=0 y=4.037800 p=-1.137607 e=0.000000 d=1.137607 cs=62.246183
RV -0.000368 dzk=0 y=4.037800 p=-1.193409 e=0.000000 d=1.193409 cs=52.643109
RV -0.000562 dzk=0 y=4.037800 p=-1.248351 e=0.000000 d=1.248351 cs=42.601356
RV -0.000940 dzk=0 y=4.037800 p=-1.306309 e=0.000000 d=1.306309 cs=32.092931
RV -0.001805 dzk=0 y=4.037800 p=-1.363300 e=0.000000 d=1.363300 cs=21.129539
RV -0.004537 dzk=0 y=4.037800 p=-1.423268 e=0.000000 d=1.423268 cs=9.683424
RV -0.023463 dzk=0 y=4.037800 p=-1.483272 e=0.000000 d=1.483272 cs=9.623420
RV -0.025549 dzk=0 y=4.037800 p=-1.538204 e=0.000000 d=1.538204 cs=9.568488
RV -0.027726 dzk=0 y=4.037800 p=-1.593264 e=0.000000 d=1.593264 cs=9.513428
RV -0.030380 dzk=0 y=4.037800 p=-1.658186 e=0.000000 d=1.658186 cs=9.448506
RV -0.032875 dzk=0 y=4.037800 p=-1.713146 e=0.000000 d=1.713146 cs=9.393546
RV -0.035743 dzk=0 y=4.037800 p=-1.775916 e=0.000000 d=1.775916 cs=9.330776
RV -0.038595 dzk=0 y=4.037800 p=-1.833086 e=0.000000 d=1.833086 cs=9.273606
RV -0.041451 dzk=0 y=4.037800 p=-1.888056 e=0.000000 d=1.888056 cs=9.218636
RV -0.044703 dzk=0 y=4.037800 p=-1.949114 e=-0.000581 d=1.948532 cs=9.158160
RV -0.048075 dzk=0 y=4.037793 p=-2.008029 e=-0.000581 d=2.007448 cs=9.099244
RV -0.051399 dzk=0 y=4.037787 p=-2.062929 e=-0.000581 d=2.062347 cs=9.044345
RV -0.055096 dzk=0 y=4.037780 p=-2.122942 e=-0.001017 d=2.121925 cs=8.984767
RV -0.058758 dzk=0 y=4.037768 p=-2.177911 e=-0.010360 d=2.167551 cs=8.939142

Key:
RV- thie is the applied voltage
dsk- dead zone skip (ignore this one for now)
y- the distance traveled
p- the desired velocity
e- the actual velocity (velocity is in meters per second)
d- the current error difference between the velocities
c- calibrated scaler or the actual PID result
The last variable cs= is the PID where I *was* set high to 8, and my range *was* high on positive end and could go down to 0.364500. This is the value presented for the final voltage by division, so the higher the number the lower the voltage would be. What happened in this run is that I accumulated enough error which caused the if check to fail and then cs was stuck to 9.x applying 0.05 voltage (which is not enough to move). The assumption is that the total error can still occur and stay within the bounds of the range specified, and this number could dwindle back down to 0.364500. So I started with the equation (TE + ERR) * I = maxoutput, and solved for ERR. The result is that total error could continue to dwindle and stay within the specified range. I hope this makes sense... this took me the entire day to work out, and I checked the math to ensure it submits the correct value.

Joe Ross
09-08-2011, 03:22 PM
The place to submit bugs and patches is the WPILIB tracker http://firstforge.wpi.edu/sf/tracker/do/listTrackers/projects.wpilib/tracker. You'll need to create a firstforge account.

JamesTerm
09-08-2011, 04:02 PM
The place to submit bugs and patches is the WPILIB tracker http://firstforge.wpi.edu/sf/tracker/do/listTrackers/projects.wpilib/tracker. You'll need to create a firstforge account.

Thanks so much... I have added a case with a reference to this link.

JamesTerm
10-28-2011, 03:15 PM
The fix has been applied. Yay. :)