Go to Post Saying that something cannot be done, is always good inspiration for someone to find a way to do it. - Josh Hambright [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #6   Spotlight this post!  
Unread 07-04-2007, 22:09
meatmanek meatmanek is offline
Programmer/physicist/mathematician
FRC #0868 (TechHounds)
Team Role: Programmer
 
Join Date: Mar 2004
Rookie Year: 2004
Location: Carmel, Indiana
Posts: 142
meatmanek is a splendid one to beholdmeatmanek is a splendid one to beholdmeatmanek is a splendid one to beholdmeatmanek is a splendid one to beholdmeatmanek is a splendid one to beholdmeatmanek is a splendid one to beholdmeatmanek is a splendid one to behold
Re: PID Control

Quote:
Originally Posted by The Lucas View Post
Also be careful reversing direction of motors in code (for simplicity I just swap wires)
Ahh, if only that were legal.
I can't quote a rule number, but I recall having trouble with inspection in 2004 due to that.

Anyway, there's another technique to have your I term go to 0 - integrate over time, rather than indefinitely. Keep a queue of error values and sum them every loop, or sum them as you go along and subtract values before you overwrite. This creates a term which is a hybrid of I and P. This will help overcome friction, but will not overcome gravity, springs, or other forces which are present when the system is at rest.

Code:
// Disclaimer: This code has not been tested. Read and think about it.
#define I_TIME 39
//I_TIME is the number of loops to integrate over
int iQPos = 0;
int iQueue[I_TIME]; // declare the queue

...
// Inside your initialization routine
for (iQPos=0; iQPos<I_TIME; iQPos++)
  iQueue[iQPos] = 0; // Initialize all to 0.

...
// inside of your PID code
I += error;
iQPos = (iQPos+1)%I_TIME; // Increment and loop if we get to the end.
I -= iQueue[iQPos];
iQueue[iQPos] = error;
__________________
Real programmers use vim.
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Generic PID control code Uberbots Programming 3 26-02-2007 16:59
PID Control Chris Bright Programming 9 26-03-2005 19:44
(Experimental) PID Control System jdong Programming 14 18-06-2004 15:55
PID control loop/Encoder question Zee Programming 18 30-01-2004 23:14
PID Control Loops ttedrow Programming 7 05-12-2002 12:03


All times are GMT -5. The time now is 14:07.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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