1. Do not share user accounts! Any account that is shared by another person will be blocked and closed. This means: we will close not only the account that is shared, but also the main account of the user who uses another person's account. We have the ability to detect account sharing, so please do not try to cheat the system. This action will take place on 04/18/2023. Read all forum rules.
    Dismiss Notice
  2. For downloading SimTools plugins you need a Download Package. Get it with virtual coins that you receive for forum activity or Buy Download Package - We have a zero Spam tolerance so read our forum rules first.

    Buy Now a Download Plan!
  3. Do not try to cheat our system and do not post an unnecessary amount of useless posts only to earn credits here. We have a zero spam tolerance policy and this will cause a ban of your user account. Otherwise we wish you a pleasant stay here! Read the forum rules
  4. We have a few rules which you need to read and accept before posting anything here! Following these rules will keep the forum clean and your stay pleasant. Do not follow these rules can lead to permanent exclusion from this website: Read the forum rules.
    Are you a company? Read our company rules

PID tuning with microcontroller

Discussion in 'Motor actuators and drivers' started by bobbyorr, Sep 26, 2009.

  1. bobbyorr

    bobbyorr New Member

    Joined:
    Sep 2, 2009
    Messages:
    10
    Balance:
    0Coins
    Ratings:
    +0 / 0 / -0
    Hi,

    I'm trying to implement a pid controller in my microcontroller. Everything seems to work fine so far. I've managed to get the control working with a simple P-control so far. My question is about the I-factor in the control.
    In the tutorial made by thanos he states that I-factor should be calculated as following

    ' Calculate integral term.
    error(Accumulator) = error(Accumulator) + error(Current)
    i = Ki * error(Accumulator)

    ....
    and the output then as following
    ....

    'Calculate output.
    drive = p + i + d

    .....

    But why the i-factor should include all the history data of the tuning. See the enclosed photo (very simple paint-powered picture to give an idea). If the set point goes as the red line in the photo and the measured value follows as the blue line. The blue area is the integrated i-error i.e sum-error. Doesn't that, in this case, mean that the integral-factor will never go to zero.
    Which part I didn't understand? Should that i-factor be forced to zero in some case e.g. the p-error goes to zero?

    I'd be very grateful if some one could help me a bit.

    I will continue testing and tuning later today.

    Thanks fellas!!

    -bobbyorr

    Attached Files:

  2. bobbyorr

    bobbyorr New Member

    Joined:
    Sep 2, 2009
    Messages:
    10
    Balance:
    0Coins
    Ratings:
    +0 / 0 / -0
    No answers. Is this in the wrong section. If yes, could someone tell me the correct one.
    Anyway..

    I now got the arduino to control my wipermotors with all proportional, integral and derivative terms. And it seems to work quite nicely. The response is fast and I can reach the setpoint with almost fullspeed with minimal overshooting. I still don't fully understand the meaning of integrating the whole history of the error. I read a bit theory and I understood that I should try to vary the integration time. At the moment my PID-controller uses the whole history and it works. Ki-variable only changes the weight of the integral term. There might be some blank spots in my comprehension :) The whole truth of my controller's ability won't be revealed until I get it working in a full size simular and with realistic loads. But afterall everything seems to progress quite well.


    -bobbyorr
  3. tronicgr

    tronicgr

    Balance:
    Coins
    Ratings:
    +0 / 0 / -0
    You don't need to work with zero values. With microcontroller you can use only positive values with an offset in place of zero!!! This solves any math problems!!!


    Regards, Thanos
  4. bobbyorr

    bobbyorr New Member

    Joined:
    Sep 2, 2009
    Messages:
    10
    Balance:
    0Coins
    Ratings:
    +0 / 0 / -0
    Thank you Thanos for your reply.
    I didn't quite understand your answer. How is this ”working with zero values” related to integrating the error? I calculate the output with both positive and negative values and I output to DC-driver the modulo of the output (limited to max pwm 100% duty value) and the direction to a different pins.

    Furthermore I was lying about the status of my controller. I didn’t get the integral term into a output because of a typo in the code. ;P Now when I’ve corrected the typo the integral-term makes the control quite unstable if Ki > 0.2. (approx) And this is only with a minimal load. With the more realistic load I guess the steady state error will be more crucial and the control-loop will be more unstable due the inertia.

    So I think the calculation algorithm of integral-term is somehow a bit bad or I’ve implemented it incorrectly.

    br
    bobbyorr
    his
  5. tronicgr

    tronicgr

    Balance:
    Coins
    Ratings:
    +0 / 0 / -0
    That's what I wanted to point... You don't need to work with fraction values! instead of 0.2 you could multiply it to get a 200 value for example and also multiply by same number (this is called offset) the rest of the terms in equation. Then you can just scale back the result to your needs.

    This will make your calculations produce much smooth results instead of having the mC round the fraction values to the nearest integer.

    Regards, Thanos
  6. bobbyorr

    bobbyorr New Member

    Joined:
    Sep 2, 2009
    Messages:
    10
    Balance:
    0Coins
    Ratings:
    +0 / 0 / -0
    Ok,

    Now I get your point. I try this out later today. Thank you for your guidance.
    I also had some delays (left overs from earlier development phase) in the code. I also try to get rid of those to make the loop more efficient.
    Let's see how it turns out to be...

    Thanks thanos!

    -bobbyorr