ArduCopter: "PIDT1" code and hex files to try...

Hi all,

a while ago, I wrote about control structure and started a discussion. Now the discussion about PIDT1 is going on also in the "Arducopter 2.2 beta" thread.

I decided to publish the exactly code I fly on my Tricopter here, also with a hex file for tricopters and a untested hex file for quadrotors.

Important notes bevore you use this:

  1. It is experimental, use at your own risk, no warranty at all, for me it works.
  2. You have to tune the controll loops to get good results.
  3. Do not ise ans I term for the stabilize control (leave them zero), just use stabilize P
  4. Please post your videos and write your impressions on stability and control reaction.

Download: ArduCopter_2.1_Igors_mod.zip

There is also a hex file that I fly on my Tricopter.
I also compiled a hex for quadrocopters, but it is untested yet!



The modifications (starting from AC 2.1) are:


  1. Blinking LEDs with Relay if main Battery voltage goes down
  2. configure via mavlink: IN_VOLT_DIVR   LOW_VOLT   LOW_VOLT_PRE
  3. YAW Servo in moddle position on power on
  4. YAW Servo Reverse with mavlink command RC7_REV = -1
  5. Camera NICK: Lowpassing pilots input for smooth Camera motion
  6. Fixed minor Bug in BATTERY_VOLTAGE(x) and CURRENT_AMPS(x) Macros
  7. Switched to faster PIDT1 Algorithm
    Saved some floatingpoint operations in PID_fast::get_pid:
    2 x division /
    4 x multipl. *
  8. Extend usable throttle range from 80% to 90%

For me it flies well. Bevore compiling, make your settings in
APM_Config.h not only copy yours, because I added some new lines.
If you use the hex: The relay switch will switch on low battery!

Testing and tuning (as already mentioned here):

Be really carefull, propellers are dangerous!  I do the tuning of the control loops while I hold the copter in my hand and try if it compensates the disturbances without overshot or oscillation. You should decide for yourself if cou can hold your copter in one hand while you throttle up and test the stability. Even small propellers can harm your fingers! If you want to proceed, I do it like this:

  1. Reload your last setup and level the copter.
  2. Set all parameters for stabilize STB_***_P and STB_***_I to zero.
  3. Set all parameters for rate control RATE_***_P, RATE_***_I and RATE_***_D to zero.
  4. Hold the copter with one hand, throttle up until it becomes weightless, then turn it. Nothing should happen, because all control loop parameters are zero. You have just manual throttle control.
  5. Increase the D-Terms and test again while holding the copter in your hand. Remember, it can't fly with most parameters set to zero. Increase the D-Term and test again, until you got some oscillation. Let's call the value you found 100 percent. Now reduce it to 50..70 percent. Do this for ROLL and PITCH.
  6. Proceed with the P-Terms. Increase and test until it gets unstable. Then reduce it to 50..70 percent of the original value.
  7. Set the I-Terms to 30..50 percent of the P-Terms. Test again. If it is unstable, reduce P and I and maybe D a little bit.
  8. Now go to the STABILIZE control parameters. Increase the P-Term. Now the copter should return to level position automatically. Increasing of the P-Term will lead to a faster return to level position after disturbance or also to a fast respond to the desired angle by pilot input. Find a value where the copter returns fast from a disturbance without overshot or oscillation.
  9. Always leave the STABILIZE I-Term STB_***_I zero in this controller configuration!
  10. For YAW you can leave the D-Term zero and use your previous settings for STABILIZE and RATE control. Or you tune it, but I didn't try it at YAW yet.
  11. If everything works well and the copter returns to level position after disturbance or pilot input without overshot or oscillation, then you can try to hover and fly carefully. Not before!



That is of cause only one posibility to tune. It works for me. Keep in mind that each feedback control loop can cause bad results like overshod and oscillation (or just minor performance) if you don't tune the parameters well.

Regards, Igor

E-mail me when people leave their comments –

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

Join diydrones

Comments

  • Hi Igor, I'm a newbie to apm. I have a tricopter with an apm2. I seem to be having difficulties getting it stable (worked perfect with Kk board)I have hovered it but it was very unstable
    and twitchy like it was fighting itself (motors pulsing not smooth). I read your thread but am very apprehensive about my capabilities to write the hex file being so new to all this. I did attempt to zero all the loop settings in the mission planner and follow your instructions to set it up. With all tabs set to zero, in aero mode I had manual throttle and no reaction to movement. In stabilize still with all tabs set to zero I had it reacting to movement but reacting the wrong way. I'm confused but it seems as if I aero and stabilize are conflicting with each other! Did you come across any issues like these on your travels?
    Alex
  • Hi Randy, I know GIT, I already work with it. In the future I will do it like this, if I stay on this platform.
  • Developer

    Igor,

         Maybe it's a mute point because most of your changes are in the latest code (I think) but I was wondering what do you think in the future of setting up a git branch and having people pull the code directly from there?  This would allow them to always pick up your latest version and remove confusion as to what's the latest, what's been tested, etc?  We have some instructions on this wiki page although they might need a little more work.

  • Good news Don! Just finished the wiring of a new ECU, the last one did not provide the same power as the other two and I had some nice flips :-)

      

  • hey Tobias, just an FYI in case you missed it, but 2.2b6 actually incorporates Igor's changes. No need to do all the work, unless of course, you want to!

  • Igor, I'll try your code in the next days; I might add your stuff into 2.2.4 or 2.2.5 - thanks for the work!

     

    -Tobias 

  • :-)

    i did throw my small tri in the air and it worked!

    for the rear motor i use multiplicator of 1.33.

    for large tri's the standard output might work but i used the wii mixer settings for the tri

    and it works better.

    in the end i touched down with a broken propellor - left over from previous testings :)

    and after 3 months of not flying a real nice success!

  • The flybar makes my heli inherently stable, no gyros needed to control it.  I really just need self-leveling.  I probably don't need PIDT1.  But the flybarless Heli guys would probably really benefit, same as the quads. 

  • I dont fly traditional helis. You can try all combinations StabP->RatePI->YourHeliPD by setting the coresponding parameters to zero. If you leave my RATE_***_D zero, its just as bevore a P->PI. 

  • Hey Igor, do you have any idea if this would work for a traditional heli?  (obviously assuming the code specific to tradition heli servo control works, which it does).

    One of my main questions is because I have a flybar.  The flybar acts like an automatic, perfectly tuned rate PD damper.  What will happen if your rate PIDT1 code has to work with a flybar?  It'll be like StabiliseP==>RatePIDT1==>FlybarPD

    Maybe the answer is just that I don't need it.  The heli seems to fly fine with StabilizeP==>RateP==>FlybarPD right now.  I'm just wondering if it's worth trying.

This reply was deleted.