View Single Post
  #5   Spotlight this post!  
Unread 15-02-2005, 09:28
Chris Hibner's Avatar Unsung FIRST Hero
Chris Hibner Chris Hibner is offline
Eschewing Obfuscation Since 1990
AKA: Lars Kamen's Roadie
FRC #0051 (Wings of Fire)
Team Role: Engineer
 
Join Date: May 2001
Rookie Year: 1997
Location: Canton, MI
Posts: 1,488
Chris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond repute
Re: arm-limitting gyro PD loop producing some strange results

Quote:
Originally Posted by ZZII 527
Thank you for your responses! There is definitely some stuff for me to try now. I think I need to clarify a few things, though:

1) I am still pretty sure it is not positive feedback for the reasons I explained in the first post and because I tested it with pwm01_temp + 0.01*p + 0*d and got what definitely seemed more like positive feedback. It isn't error = desired - actual, it's error = actual - desired.

2) All the variables are declared at the top of the file, which I thought made them of global scope (they will hold their values between loops) but I could definitely be very wrong there. I will try changing them to static float, etc.

3) The pwm01_temp value was intended to be adjusted a small amount each loop until it hit the correct value. It is a float, so it can store those small accumulations and then typecast to an (int) (or should it be (unsigned char)?) only when setting the real pwm01. Again, if my variables aren't global as-is than this isn't doing what I think it's doing. But based on what I saw (the arm getting faster and faster), I think it is accumulating over loops, just only in one direction for some reason.

I'm gonna fiddle around with it some today and see if I can get some better results. I'll post when (and if) I get it to work properly and let everyone know what changes fixed it. Thanks so much again everyone!


-Shane

Shane,

I looked through your code again.

1) You are correct: it is not positive feedback since you have error = actual - desired. However, this is poor control style and every control engineer (like me) will be thrown for a loop unless they read the code very carefully. Error = desired - actual is the standard style, then your control efforts are positive (not negated). I know, "it's just style", but using better style leads to faster solution of your problems (it screwed me up the first time).

2) If you declare your variables at the top of the file (outside of any function) then they are global and you don't need to declare them as static. This wasn't clear to me the first time - I thought the variables were declared at the top of the function (not the top of the file). However, this means your code has another error (see below).

If pwm01_temp is global, then you should NOT have pwm01_temp = pwm01_temp + ... This will cause your control loop to act very strange. Your control effort should NOT accumulate - it should be set new every loop. The only accumulation should be if you decide to add integral control, but that should be done separately with it's own gain. Change this line of your code to be the following:

pwm01_temp = 1.26*p + 0*d + 127;

That should solve your problems. Note that the above line assumes that you've changed to the standard style of error = desired - actual.

To add integral control, do the following:

At the top of the file, declare an integrator variable:

float integralState = 0;

In your control code:

integralState = integralState + error_new * 0.0262;

pwm01_temp = 1.26*p + I_CONSTANT*integralState + 0*d + 127;


DISCLAIMER: I also disagree with using floats in embedded code. However, it is too close to the ship date to completely change your code. For the future I would suggest doing a internet search on "fixed point math" (or come to my seminar at the Conference in Atlanta).
__________________
-
An ounce of perception is worth a pound of obscure.

Last edited by Chris Hibner : 15-02-2005 at 09:36.