go away spammer

Author Topic: Issue with PID and dT  (Read 2575 times)

0 Members and 1 Guest are viewing this topic.

Offline TheBadgerTopic starter

  • Jr. Member
  • **
  • Posts: 33
  • Helpful? 0
Issue with PID and dT
« on: April 08, 2011, 03:27:46 AM »
So I have the algorithm up and running on my robot, white line follower with 5 digital sensor inputs from schmitt trigger and photo transistors.

But I was told that because I was sampling in a constant loop, as apposed to interrupt driven sampling that I could not include the dT part of the derivative and integral calculations,

But I am thinking now I want to include them but just don't really understand how they are going to work.

For example say my loop is

loop start
start timer
calculate proportional
read timer and store in dT
calculate derivative using dT
calculate integral using dT
loop end

every time it goes through the loop dT will be the same as the timer is restarted, however if I am meant to keep the timer running then I don't really understand that either.

Please could someone provide me with some psudocode on how dT works or something.

Thanks a lot


Offline mstacho

  • Supreme Robot
  • *****
  • Posts: 376
  • Helpful? 10
Re: Issue with PID and dT
« Reply #1 on: April 11, 2011, 07:21:45 AM »
Two options:

1) don't bother with dT, just let it get consumed in the gain for Kd and Ki.  This is not popular, since it's possible that your dt might change, but unless you're looking for absurd accuracy this will do.

2) You seem to have a timer, which is driven by the uC's timer hardware anyway, so you appear to already be using interrupt driven sampling?  I don't understand why you keep restarting the timer in the loop...since you should have access to dT always once you start the timer OUTSIDE the loop, unless you wrote your own?

3) Don't ever use Ki unless you have steady state errors (errors that never go away even if you're just following a straight line).  It'll just make the controller oscillate for a bit.
Current project: tactile sensing systems for multifingered robot hands

Offline TheBadgerTopic starter

  • Jr. Member
  • **
  • Posts: 33
  • Helpful? 0
Re: Issue with PID and dT
« Reply #2 on: April 11, 2011, 07:33:07 AM »
Thanks for the reply but now I am confused even more:(

I don't have interrupt driven sampling, I could do that and I know how to if that is what is needed,

I did it the way of just letting dT be consumed by the gains as you put it, but now I really want to introduce dT just so I know how to do it in future even if it is not needed here.

Could you provide me with some psudocode of how you would do this loop including dT if you were doing a line follower yourself.

Thanks again

Offline mstacho

  • Supreme Robot
  • *****
  • Posts: 376
  • Helpful? 10
Re: Issue with PID and dT
« Reply #3 on: April 11, 2011, 07:52:17 AM »
Well, I use an Axon, and I'm not sure what you're using, but something like this:

initialize the timer OUTSIDE the loop (on the Axon, the timer also keeps track of how often it overflows.  Let's call that variable TOver, and let's say I'm using an 8-bit timer, so it counts to 255 before overflowing).  Then:

int newT = 0;
int oldT = 0;
int dT = 0;
initTimer(); //however you do this in your uC

LOOP
//switch the times
oldT = newT
TOver = getTimerOverflowCount(); //this is not a real function, but it does what it says :-P Your uC should have //something similar
newT = TOver*255 + timerCount;

dT = newT - oldT;

Do all your computations using dT

END LOOP

So really the only thing I do differently is put the timer outside the loop.  You seem to initialize your timer inside the loop, which is odd, unless you're not using the uC's native timer?
Current project: tactile sensing systems for multifingered robot hands

Offline TheBadgerTopic starter

  • Jr. Member
  • **
  • Posts: 33
  • Helpful? 0
Re: Issue with PID and dT
« Reply #4 on: April 11, 2011, 09:19:18 AM »
EXACTLY what I was after Thanks a lot!

I was confusing myself with the roll over bit,

 


Get Your Ad Here

data_list