Shop OBEX P1 Docs P2 Docs Learn Events
PID Enhanced is finally done! — Parallax Forums

PID Enhanced is finally done!

Sniper KingSniper King Posts: 221
edited 2008-08-27 04:53 in Propeller 1
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!tongue.gif·

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
1059 x 826 - 30K

Comments

  • bmentinkbmentink Posts: 107
    edited 2008-08-26 02:31
    Ok, so what is wrong with the PID.spin object already in obex? cool.gif

    What is "enhanced" about your object, please elaborate ...... it seems such a very "simple" PID implementation rolleyes.gif

    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?
  • Sniper KingSniper King Posts: 221
    edited 2008-08-26 14:13
    The PID in OBEX· does not allow for total control of the PID routine.· You have gain, and integral time. control.· A complete PID loop has control over proportional, integral and derivative gains.· The original PID routine just had gain which translated to all of the terms (P.I.D.)

    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
  • grasshoppergrasshopper Posts: 438
    edited 2008-08-26 14:52
    I am a bit confused Sniper King. I use the P.I.D. object and have complete control as far as I know. Can you explain more on your version vs the current version. Perhaps you had the wrong P.I.D. routine starting out, I think I got mine from Andy. I list it below
    [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
  • Timothy D. SwieterTimothy D. Swieter Posts: 1,613
    edited 2008-08-26 16:10
    Sniper King -

    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
  • simonlsimonl Posts: 866
    edited 2008-08-26 19:34
    Agreed - that project sounds great Sniper King. I hope you'll keep us updated on it smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    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 smile.gif
  • Sniper KingSniper King Posts: 221
    edited 2008-08-26 20:21
    The pid Routine in the code is way different than the object I downloaded which follows

    PID.spin, v1.1, Craig Weber
    ┌──────────────────────────────────────────┐
    │ Copyright (c) 2008 Craig Weber           │               
    │     See end of file for terms of use.    │               
    └──────────────────────────────────────────┘
    }}
    VAR
    long cur_pos        'Real Position
    long set_pos        'Set Point
    long K              'PID Gain
    long cur_error      'Current Error
    long pre_error      'Previous Error
    long output         'PID Output
    long stack[noparse][[/noparse]30]      'COG Stack
    byte cog            'cog number
    long dt             'Integral Time
    PUB Start(Current_Addr, Set_Addr, Gain, Integral_Time, Output_Addr) 
    ''Starts PID controller.  Starts a new cog to run in.
               ''Current_Addr  = Address of Long Variable holding actual position
               ''Set_Addr      = Address of Long Variable holding set point
               ''Gain          = PID Algorithm Gain, ie: large gain = large changes faster, though less precise overall
               ''Integral_Time = PID Algorithm Integral_Time
               ''Output_Addr   = Address of Long Variable wich holds output of PID algorithm
    cur_pos := Current_Addr
    set_pos := Set_Addr
    K := Gain
    dt := Integral_Time
    output := Output_Addr
    pre_error := 0
    cur_error := 0
    cog := cognew(Loop, @stack)
    PUB Stop
    ''Stops the Cog and the PID controller
    cogstop(cog)
    PRI Loop | e, P, I, D
    repeat
      long[noparse][[/noparse]cur_error] := long[noparse][[/noparse]set_pos] - long[noparse][[/noparse]cur_pos]
      P := K * long[noparse][[/noparse]cur_error]
      
      I := I + K * long[noparse][[/noparse]cur_error] * dt
      
      e := long[noparse][[/noparse]cur_error] - long[noparse][[/noparse]pre_error]
      D := K * e / dt
      long[noparse][[/noparse]output] := P + I + D
     
    



    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
  • Sniper KingSniper King Posts: 221
    edited 2008-08-26 20:29
    Ok again on the new PIDEnhanced object. I pass all of the variables to the PID routine to allow for multiple PIDs to run.

    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
  • bmentinkbmentink Posts: 107
    edited 2008-08-27 04:53
    Sniper King said...

    Ps. usually people don't insult other members when talking to them. For future reference...you know.

    I don't remember insulting anyone. nono.gif 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 ..... blush.gif
Sign In or Register to comment.