PID-filter routine (2nd try).


Closed Thread
Results 1 to 40 of 132

Hybrid View

  1. #1
    Join Date
    Nov 2008
    Posts
    19


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by daan.joubert View Post
    Hi Henrik,
    Is it possible to use portion of the code on a RC servo which is connected to an externat 10k potentiometer.?
    My existing circuit is driving an RC servo in the range of 1mS to 2mS, the servo pulls a throtle of an engine, to keep revolutions at 1500 RPM (50Hz). The engine is directly coupled to an alternator. The position of the servo is controlled by a voltage (F/V), form the alternator frequency and a 10k setpoint potentiometer. I use analog inputs on 16f88 to convert volt to value. I then subtract values from each other and send the difference to the servo. (simple calculation)
    My problem is that the voltage conversion is not linear to the servo movement. The result is that servo movement is always too litlle in comparison of the set speed needed.
    I was wondering whether I can use feedback in order to counteract the non-linear characteristic of the servo.
    I have used a magnetic pickup on the fly wheel in the past, adc this to a stepper motor, incorporate the feedback once you get to the stage of engine hunting, then set your fine tuning (gain etc).

  2. #2
    Join Date
    Aug 2009
    Posts
    7


    Did you find this post helpful? Yes | No

    Default Hi Henrik

    I have many trys to solve my problem but fail.Actually i want to control GAS engine speed.I am using AGB130 LINEAR ELECTRIC ACTUATOR to drive BUTTERFLY VALVE.I am using MAGNETIC PICKUP UNIT located on flyweel to sense engine speed.After F/V conversion i have 0-5000Hz to 0-5V.
    Problem is that ACTUATOR drive only forward direction through given voltage
    and reverse direction through SPRING located inside.
    ACTUATOR always needed some voltage to remain in a position to maintain speed.But INCPID routine gives 0 output when no error found.
    I am giving some examples in atachements which will help to identify problem.
    Best regards
    IFTIKHAR AHMAD
    Attached Images Attached Images   

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default

    Hi,
    Don't really know how the spring return will work here...Can't really see why it wouldn't work....

    The 0V at 0 error isn't really true.... When the error is 0 output from the P- and D-term is indeed 0 (the D-term might not be 0 but for this discussion let's say it is). But the output from the I-term is whatever was needed to bring the error to 0. (It might be 0 but not necessarily).

    Think of the car analogy, you're trying to keep the speed at 50mph and you're starting to climb a steep hill, if you simply keep the gas-pedal at the exact same position the speed will start to drop. The P-term adds a little effort based on the error but not enough since the load now is larger (we're climbing a hill). The I-term starts adding a little effort (giving some gas) and soon the velocity is back at 50mph. Now the P term is 0 (since there is no error) the D-term is 0 since there is no error but the I-term is not zero - if it were the speed would start to drop again.

    With that said, simply add a little to the output of the PID-filter rto overcome the force of the spring - if that's what you want. This is often called feed-forward and means that for a particular speed, torque, position or whatever you have like a "starting point" for the "drive" - the PID filter then takes it from there.

    /Henrik.

  4. #4
    Join Date
    May 2007
    Posts
    65


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by hadiengg View Post
    I have many trys to solve my problem but fail.Actually i want to control GAS engine speed.I am using AGB130 LINEAR ELECTRIC ACTUATOR to drive BUTTERFLY VALVE.I am using MAGNETIC PICKUP UNIT located on flyweel to sense engine speed.After F/V conversion i have 0-5000Hz to 0-5V.
    Problem is that ACTUATOR drive only forward direction through given voltage
    and reverse direction through SPRING located inside.
    ACTUATOR always needed some voltage to remain in a position to maintain speed.But INCPID routine gives 0 output when no error found.
    I am giving some examples in atachements which will help to identify problem.
    Best regards
    IFTIKHAR AHMAD
    PID is a loop. If spring moves something, PID will detect it and it will correct it immediatly. Don't confuse error variable with PWM value. In my project it works fine and it responds to dynamic loads and it correct it as it should (read above post of my project). Sorry for answering you, as you only refer to Henrik.
    "Beethoven had his critics too, see if you can name 3 of them"

  5. #5
    Join Date
    Nov 2008
    Posts
    19


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by hadiengg View Post
    I have many trys to solve my problem but fail.Actually i want to control GAS engine speed.I am using AGB130 LINEAR ELECTRIC ACTUATOR to drive BUTTERFLY VALVE.I am using MAGNETIC PICKUP UNIT located on flyweel to sense engine speed.After F/V conversion i have 0-5000Hz to 0-5V.
    Problem is that ACTUATOR drive only forward direction through given voltage
    and reverse direction through SPRING located inside.
    ACTUATOR always needed some voltage to remain in a position to maintain speed.But INCPID routine gives 0 output when no error found.
    I am giving some examples in atachements which will help to identify problem.
    Best regards
    IFTIKHAR AHMAD
    You will need to find the required pwm to output 1500 rpm (1.5v) from your engine,(you will need this on startup to have your engine idling at no load) this you will use as your setpoint after adc. Anything above it will generate a negative P substracting from setpoint,slowing the engine down, above it adding to the setpoint,speeding up the engine. The gains of each part of p.i.d will be from the variable resistors via adcs. Have these initially set to one, set the p then p gain etc the idea is to have the engine fairly responsive to load change and the fine settings of the gains will limit the droop and overshoot.
    Last edited by anonymouse; - 3rd September 2009 at 22:11.

  6. #6
    Join Date
    Feb 2009
    Posts
    10


    Did you find this post helpful? Yes | No

    Smile PID for servo

    Hi Alain and others,
    Thank you all for info given, it is much appreciated.

    Alain, regarding the linear problem - I have tested the actual distance travel of the servo arm by connecting a ruler to the arm.
    To test I then adjusted the speed voltage, taking voltage readings and distance readings as I go along.
    The distance values on Excel graph showed a non linear line in comparison to the linear nature of the voltage.
    /Daan Joubert

  7. #7
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Wink

    Quote Originally Posted by daan.joubert View Post
    Hi Alain

    The distance values on Excel graph showed a non linear line in comparison to the linear nature of the voltage.
    /Daan Joubert
    Hi, Daan

    I hope you've considered the rotation angle of the arm is linear to the signal ...

    But, whatever your transmission system ... only rack and pinion or cable and pulley can give a linear travel !!!

    You could use a LOOKUP Table to correct your output ... but, once more, if it is a real PID controller, it will compensate for non-linearities ...

    Or try to use ... FUZZY LOGIC !!!

    Or find an old LINEAR R/C servo ( Kraft, Robbe, Varioprop, Lextronic ... produced some in the 70-80's )


    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  8. #8
    Join Date
    Nov 2008
    Posts
    19


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by daan.joubert View Post
    Hi Alain and others,
    Thank you all for info given, it is much appreciated.

    Alain, regarding the linear problem - I have tested the actual distance travel of the servo arm by connecting a ruler to the arm.
    To test I then adjusted the speed voltage, taking voltage readings and distance readings as I go along.
    The distance values on Excel graph showed a non linear line in comparison to the linear nature of the voltage.
    /Daan Joubert
    Your gains might need to be fractional all the way up to 20 times and more via your vresistors via adc. Example engine running no load 1500 rpm, adc 1.5/5 * 256 = 77. setpoint = 77,unknown but say pwm 25, all gains apart from p set to zero. 25% load applied engine droops to 500rpm,adc 0.5/5 * 256 = 26. 77-26= 51, pwm output 51. If output to much p gain * 0.8 etc,to little * 1.5 etc. You should get to the stage of engine hunting turn the gain slightly below this. This is then where the data from i and d comes into play and slightly tweaking each one results in a reactive genset regardless of load.

  9. #9
    Join Date
    Aug 2009
    Posts
    7


    Did you find this post helpful? Yes | No

    Default Motor Speed Control

    Thanks Mr Henrik,Mr RodSTAR and Mr Anonymouse for help.
    I succesfully run the motor at constant speed.Motor speed also change through given speed refrence.
    Now one problem that i face is motor overshoot in slow speed refrence whenever i turn on the power.Its overshoot cycle comes down when i increase speed refrence.At full speed refrence it get exact speed never overshoot.I am using same PID gains used in original file.I think i must change the GAIN value to overcome this problem.
    And also i am using variable for 0-5V to 0-1023 value through ADC.How i use this value to put the gain as used under.
    pid_Kp = $0700 'Set Kp to 7.0
    Please give some code to convert the value.

  10. #10
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default

    Hello,
    I thought I explained that in post #16 above. I'll simply quote myself:
    Regarding the pots, you can set the PID gains in any number system you like. The reason I show it in hex is that it is easier IMO. You can simply do pid_Kp = myADResult if you like.

    1023 in decimal is the same as $03FF which, in the PID filter, is treated as 3.996 basically. See, 03 is the number on the left side of the decimalpoint and FF is on the right side. FF represents 1/256*255 or 0.996. If you'd feed it 102 from the ADConverter it would be the same as $0066 or a gain of 0.258.

    If you need more gain than 1023 then simply multiply your ADResult, pid_KP=myADResult*2, now you get a gain of 0-2046 or $0000-$07FE or 0.0-7.992
    I don't really know how to explain it in any other way but let me know if doesn't make sense and I'll try, or perhaps someone else can attack it from another angle.

    /Henrik.

Similar Threads

  1. Darrel's latest 16 bit averaging routine?
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 17th October 2009, 01:57
  2. 2nd order Low-pass passive RC filter on PWM
    By munromh in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 29th January 2009, 19:03
  3. Atod Digital Filter
    By GeoJoe in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 2nd April 2008, 17:04
  4. PID controller in 16F737
    By joeri in forum mel PIC BASIC
    Replies: 8
    Last Post: - 24th June 2006, 11:39
  5. 2nd Order Digital Filter for 24-bit
    By sefayil in forum mel PIC BASIC
    Replies: 0
    Last Post: - 2nd December 2005, 21:55

Members who have read this thread : 2

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts