PID Enhanced is finally done!
Sniper King
Posts: 221
I finished the PID Enhanced object.· Tested rigorously!· I tried to over document the header to give you an idea how to use this.· I am building another autonomous vehicle to test this on.· My big project is going to be an autonomous sailboat.· This boat will sail open ocean to any point on earth (within reason of course) utilizing HAM radio as its primary communication medium.· Possibly the Space station packet relay/email system we shall see.·
The craft itself will be a custom carbon fiber design that is 10 ft long.· It will be using a rigid wing sail design with lots and lots of sensors including a digital camera so I can prove it!·
Sensors:
Wind Speed...Duh!
Wind direction
compass
GPS
Swell size
Tilt
Water Depth
There will also be a provision for a scientific package.
·the whole design is solar powered with a pretty large battery compartment for ballast.
I am hoping for some sponsors as the hull and sail design become real.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·- Ouch, thats not suppose to be hot!··
Michael King
Application Engineer
R&D
Digital Technology Group
The craft itself will be a custom carbon fiber design that is 10 ft long.· It will be using a rigid wing sail design with lots and lots of sensors including a digital camera so I can prove it!·
Sensors:
Wind Speed...Duh!
Wind direction
compass
GPS
Swell size
Tilt
Water Depth
There will also be a provision for a scientific package.
·the whole design is solar powered with a pretty large battery compartment for ballast.
I am hoping for some sponsors as the hull and sail design become real.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·- Ouch, thats not suppose to be hot!··
Michael King
Application Engineer
R&D
Digital Technology Group
spin
11K
Comments
What is "enhanced" about your object, please elaborate ...... it seems such a very "simple" PID implementation
NB: In your code you pass a "T" parameter, yet your verbose discription at the start of the file does not
describe this parameter, is it a "time" parameter? If so, how is it used?
Oops on the T variable.· Indeed that is time and should be set to the amount of time between the pid calls.· T is in seconds.
Ps. usually people don't insult other members when talking to them.· For future reference...you know.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·- Ouch, thats not suppose to be hot!··
Michael King
Application Engineer
R&D
Digital Technology Group
Post Edited (Sniper King) : 8/26/2008 2:27:17 PM GMT
[code]
'' PID.spin (Under construction)
OBJ
f : "FloatMath"
VAR
long kp, ki, kd, sp, off, Amax, Amin
long a, tp, Ep
PUB init (_Kp, _Ki, _Kd, setPoint, offset, maxArea, minArea)
'' Set vdalues of kp, ki, etc.
longmove(@kp, @_Kp, 7)
PUB calculate(in) :out | temp, E, P, I, D, da, t, dt, Et
'' Returns PID (out)put based on (in)put and stored values.
' Calculate Δt = [noparse][[/noparse]cnt(now) - cnt(previous)] / clkfreq
t := cnt ' t(now) = cnt
dt := t - tp ' Δcnt = t - tp
dt := f.fDiv(f.FFloat(dt), f.FFloat(clkfreq)) ' Δt = Δcnt
Your sailboat project sounds cool. I don't want to rerail this thread, maybe we can start another one talking about it. Maybe you could add an air and a water temperature sensor to your mix. I love the HAM radio idea too, this way you can get regular feedback. That sure beats the let go and hope it works method.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Timothy D. Swieter, E.I.
www.brilldea.com·- Prop Blade, LED Painter, RGB LEDs, uOLED-IOC, eProto fo SunSPOT, BitScope
www.sxmicro.com - a blog·exploring the SX micro
www.tdswieter.com
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheers,
Simon
www.norfolkhelicopterclub.co.uk
You'll always have as many take-offs as landings, the trick is to be sure you can take-off again ;-)
BTW: I type as I'm thinking, so please don't take any offense at my writing style
as you can see, in the Start method you only have a gain and dt. That is why I wrote mine.· I didn't mean to offend.· I downloaded this about 3 months ago or so.
As for the sailboat idea.· I have been playing with this for some time now.· until about 3 months ago i was stuck in the Basic Stamp mode and writing a large app that would control sooooooo much expensive hardware was a little scary.· the other option was to use a laptop but the power budget went through the roof on that.· Then along comes the Propeller.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·- Ouch, thats not suppose to be hot!··
Michael King
Application Engineer
R&D
Digital Technology Group
PUB PID(KP, KI, KD , cErr, aErr , lErr,T)|PIDs
I pass the P gain,I gain,D gain, Current Error, Accumulated Error, Last error and Time
pterm = KP * errterm
P is multiplied by the Current Error
iterm = KI * AE
I is multiplied by the Accumulated error
Integral is based on the accumulated error.·
Why the stupid, hard to control I term?
Example:· UAV -in altitude control you use throttle.· As you get closer and closer to your desired altitude above you, the P term gets smaller and smaller.· Your thottle servo and the micro amount you are adjusting the carburator will start to become too small to have a change.· the I term is accumulating this error and starting to exert an ever growing force adding more throttle until you reach the target.·· If it passes the target altitude· the accumulated error will start to drop.· The force will decrease until it passes the target again.· These values will be so small that you will not see it in the engine or servo.· This will eventually flat line and just the right amount of throttle will be available to control the altitude.· You accumulated error will most likely be a positive value and will be holding steady as the aircraft is exactly where it needs to be and error is not growing or shrinking.
dterm = (KD * ((errterm - lasterr) / 0.1))
D is multiplied by the current error minus the last error and then divided by the time since last cycle
PID = pterm + dterm + iterm
sum it all up and pass it back!
I love these little routines for control. Accuracy using a computer to control something you cant is cool.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·- Ouch, thats not suppose to be hot!··
Michael King
Application Engineer
R&D
Digital Technology Group
Post Edited (Sniper King) : 8/26/2008 8:41:06 PM GMT
I don't remember insulting anyone. I was just asking, quite rightly, what was enhanced about your object, as I didn't see any
enhancements in your code compared to the PID object in the obex.
If you have taken offense with that, then I apologize, it certainly wasn't intended that way .....