in this blog post I described how I changed the control loops for the attitude control (STABILIZE Mode) to use PID(T1) in the rate control instead of PI. For me, it was a major improvement of stability on my Tricopter.

Here I would like to discuss the attitude control structure.

From the Wiki and the code I saw that the current control structure (in AC 2.1 software) is like this:
I changed the control structure to this:

In my opinion, this is the best control structure for a attitude control with underlaying rate control that you can do with traditional PID(T1) controllers. Of cause there are other controller types, but lets stick to traditional PID(T1).

I got some questions:

  1. How was the original controller structure designed?
  2. Why is the I-term of the attitude control directly connected to the output (green ?* in first pic)?
  3. Have you tried PID loops? Are there reasons to avoid them in ArduCopter?

Maybe some people with a strong background in feedback control systems can join in. Lets find the best solution to get the stabilized mode really stable!

Regards, Igor

You need to be a member of diydrones to add comments!

Join diydrones


  • Hi All

    For control difference thrust is what is pertinent. How is differential thrust achieved with a single PID control? I am basically asking if the system is SISO of SIMO? I am recreating a controller in labview whereby a single is isolated for testing purposes. Please can someone help.


  • ArduCopter_2.2ß2XP2_PIDT1 complete set of flight test

    I´ve performed a complete set of test (7 batteries) on this code in my 1kg Quad. Really good in all.

    PID´s are close the same than my small quad (see previous post). Really easy tunning at first shot. I think this code is quite robust in terms of different platforms, since pids are close the same.



  • What happend to this thread.  Did 4 pages of posts go missing?

  • ArduCopter_2.2ß2XP2_PIDT1 code

    Reading the code I have some doubds:

    1) In a simplified view of the code, we can see that:

            get_stabilize_pitch(int32_t target_angle)

                   current_rate   = (omega.y * DEGX100);

                   rate           = g.pi_stabilize_pitch.get_p(error);  // *b*

                   error          = rate - current_rate;

                   rate           = g.pid_rate_pitch.get_pid(error, G_Dt);

    That is: we apply the new control "get_pid" to the error comming from a initial estimation done with p-term (line *b*). Is that right?

    2) At the end, we pipe i-term to the output:

                   return (int)rate + iterm;

     but I guess is alwways zero, since _kI = 0 in this pid tunning. Is that right?


  • Just tested indoor the code (Marco release) in my small Quad. After tunning (as Igor told) I´ve got:

    Rate R/P _P = 0.1, Rate R/P _D = 0.015, Rate R/P _I = 0.05              Stab_P/R P= 6, Stab_P/R I= 0

    First feeling flying is quite good. At take-off, there are some initial 5 seconds that oscillates. Then, it dissapear and goes perfect. The same effect is seen when keeping the copter by hand: initially there is a very "hard" feeling during 5 sec. After that, its "softed" and behaves normally.

    See this short video: http://vimeo.com/35586306

    Jason could identified this effect in the code:

    if ((millis() - takeoff_timer) > 5000){
    // we must be in the air by now
    takeoff_complete = true;
    land_complete = false;
    // reset these I terms to prevent awkward tipping on takeoff

    Apart of that small bug, stab looks very well. I´ll fly outdoor today.


  • I just noticed in your function block diagram, you are using the actual angular rate from the gyros, where previously we were using the angular rate which is derived from the accelerometers (rate of change of vector).  Is that right?  That's a pretty fundamental change.

  • Developer

    I'm trying to get up to speed on this thread. Is there an implementation that I can grab and fly? 

    BTW, the history of the control loop for stabilize is the NG control loop. The PI-P(rate)  loop was developed by Jose a while back. I added the second I, but we don't use it generally. The I term was re-reouted because it failed to meet the balancing tests. I hung a battery off of one arm and the loop could not compensate. The current loop can compensate very quickly and 100%.

    I added the multi-wii dampening term as an experiment. Yes, look at the code, credit was given. I wasn't in love with it in the end and it was a memory hog, so I modified it with a decimation filter. It is a little nicer now in B3/4. 

    I'm always looking for better control loops so please post a link to the new implementation.



  • I noticed something else in the code:

    The error that is feed into the controllers is limited and the output is also limited. This should be a feature of the controller, not somewhere else in the code.

    Limiting the error makes no sense to me, because you need to know the real error in the controller. Why is the error limited?

    Limiting the output is a good idea, but you have to do it inside the controller and you have to stop integrating while the output is limited because the original value is over the limit. This is called PID with "anti windup". It would be a small improvement.

    And of cause you can limit the integrated value, which is already implemented.

  • Developer

    If someone wants to try the version I leave you with the modified guidelines of Igor, follow the instructions on its own blog post.
    The package is a version of Jean-Louis 2.2ß2xp2 with the additions proposed by Igor (PIDT1, like Mikrokopter), I have eliminated many unnecessary things (multiple configuration and unused backup file).
    Make your changes to the config and get a complete backup of your parameters before install this "test release", write with Arduino and then restore your parameters... now it's time to read the "pid tuning" part in the Igor's blog post! :-)
    Unfortunately AeroSim does take its internal pid control mechanisms, then with simulator is not easy to find a good compromise, but the loiter is clearly better, with and without wind.
    For this reason I believe that you will surely have the best tests and tuning in flight, if you decide to try follow perfectly the Igor's recommendations!
    This archive is provided without any warranty, I do not assume any responsibility even if the simulator has never given any problems, so watch out and test it only with the sim (at the moment)!




  • Developer

    Hi Igor, I have applied all the changes you have suggested about "PIDT1" in AC 2.2b2xp (version revised by Jean-Louis) and I must say that loiter on the simulator is much more accurate, although it is very difficult to do a good pid tuning with the D term in the rate/stab.
    I think this thing has a reason to exist, because we're trying like crazy to keep our quad standing in loiter dropping the parameters of exasperation, and then not being able to drive them in normal flight.
    I read that Jason has something similar already implemented but not released, I hope that something comes out soon.
    In attachment the loiter recorded with AeroSim: in the first 30 seconds zero wind and no side drift or circle, then suddenly active "crosswind" and the quad recovers quickly the original point at 1:07 and keeps the position... that is, it works!
    Need better tuning and test in real flight but... welcome back "D term"! :P




This reply was deleted.


Gremsy liked Gremsy's profile
Mar 12
DIY Robocars via Twitter
RT @chr1sa: Donkeycar 4.4 released with tons of new features, including path learning (useful with GPS outdoors), better Web and Lidar supp…
Nov 27, 2022
DIY Robocars via Twitter
RT @NXP: We are already biting our nails in anticipation of the #NXPCupEMEA challenge! 😉 Did you know there are great cash prizes to be won…
Nov 24, 2022
DIY Robocars via Twitter
RT @gclue_akira: レースまであと3日。今回のコースは激ムズかも。あと一歩 #jetracer https://t.co/GKcEjImQ3t
Nov 24, 2022
DIY Robocars via Twitter
UC Berkeley's DIY robocar program https://roar.berkeley.edu/
Nov 24, 2022
DIY Robocars via Twitter
RT @chr1sa: The next @DIYRobocars autonomous car race at @circuitlaunch will be on Sat, Dec 10. Thrills, spills and a Brazilian BBQ. Fun…
Nov 24, 2022
DIY Robocars via Twitter
RT @arthiak_tc: Donkey car platform ... Still training uses behavioral cloning #TCXpo #diyrobocar @OttawaAVGroup https://t.co/PHBYwlFlnE
Nov 20, 2022
DIY Robocars via Twitter
RT @emurmur77: Points for style. @donkeycar racing in @diyrobocars at @UCSDJacobs thanks @chr1sa for taking the video. https://t.co/Y2hMyj1…
Nov 20, 2022
DIY Robocars via Twitter
RT @SmallpixelCar: Going to @diyrobocars race at @UCSDJacobs https://t.co/Rrf9vDJ8TJ
Nov 8, 2022
DIY Robocars via Twitter
RT @SmallpixelCar: Race @diyrobocars at @UCSDJacobs thanks @chr1sa for taking the video. https://t.co/kK686Hb9Ej
Nov 8, 2022
DIY Robocars via Twitter
RT @PiWarsRobotics: Presenting: the Hacky Racers Robotic Racing Series in collaboration with #PiWars. Find out more and register your inter…
Oct 23, 2022
DIY Robocars via Twitter
RT @Hacky_Racers: There will be three classes at this event: A4, A2, and Hacky Racer! A4 and A2 are based around UK paper sizing and existi…
Oct 23, 2022
DIY Robocars via Twitter
Oct 23, 2022
DIY Robocars via Twitter
Oct 19, 2022
DIY Robocars via Twitter
Oct 18, 2022
DIY Robocars via Twitter
RT @NeaveEng: Calling all UK based folks interested in @diyrobocars, @f1tenth, @donkey_car, and similar robot racing competitions! @hacky_r…
Oct 13, 2022