Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Manual Velocity PID, anyone successful? (http://www.chiefdelphi.com/forums/showthread.php?t=42152)

Tom Bottiglieri 31-01-2006 10:51

Re: Manual Velocity PID, anyone successful?
 
For anyone who has utilized a differential term in their control loop, did you use the timing of the default routine or set up an timed interrupt driven differential calculation?

I know the default code loops at ~26ms, but is its rate of repitition constant enough to house the differential term calculation?

Jared Russell 31-01-2006 11:12

Re: Manual Velocity PID, anyone successful?
 
I find that the default 39Hz main loop is fast enough for any feedback applications in FIRST, and it is fairly well timed as long as you don't go overboard on the interrupts.

Besides, the closer together your differential term calculations are, the less resolution you have in them (i.e. you couldget 5-10 "ticks" difference on a 100Hz loop but the same rate would produce 12-25 on 39Hz).

Joel J 31-01-2006 12:50

Re: Manual Velocity PID, anyone successful?
 
Quote:

Originally Posted by Abwehr
You can replace the line:

control /= 4;

with:

control >> 2;

But that's about it - otherwise it works.

if control can be negative, then a right shift can have a disastrous effect! mcc18 v2.4 does NOT shift in 1's for a negative number. Instead, it treats all numbers as unsigned.

For example,

int control = -16;
control = control >> 2;

After that snippet, you'd expect control to be -4, but in actuality its 16380. Quite different.

kaszeta 31-01-2006 13:27

Re: Manual Velocity PID, anyone successful?
 
Quote:

Originally Posted by Joel J.
if control can be negative, then a right shift can have a disastrous effect! mcc18 v2.4 does NOT shift in 1's for a negative number. Instead, it treats all numbers as unsigned.

For example,

int control = -16;
control = control >> 2;

After that snippet, you'd expect control to be -4, but in actuality its 16380. Quite different.

Indeed, our team learned that lesson the hard way....

Jared Russell 31-01-2006 15:34

Re: Manual Velocity PID, anyone successful?
 
Quote:

Originally Posted by Joel J.
if control can be negative, then a right shift can have a disastrous effect! mcc18 v2.4 does NOT shift in 1's for a negative number. Instead, it treats all numbers as unsigned.

For example,

int control = -16;
control = control >> 2;

After that snippet, you'd expect control to be -4, but in actuality its 16380. Quite different.

Wow - I definately would have thought that a shift would extend the sign.

I guess I should have RTFM. ;)

Astronouth7303 31-01-2006 20:51

Re: Manual Velocity PID, anyone successful?
 
Quote:

Originally Posted by Rick TYler
Yeah, but, writing PID from scratch is hard. Does anyone have some sample code I could show to our student programmers?

The Navigation code Kevin made for last year's robot has PID in it.

And it's pretty easy.
Code:

error = current - target
integral += error
derivative = error - prevError
output = Kp * error + Ki * integral + Kd * derivative
prevError = error

(The implementation details are left to the reader ;) )


All times are GMT -5. The time now is 15:32.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi