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:
- It is experimental, use at your own risk, no warranty at all, for me it works.
- You have to tune the controll loops to get good results.
- Do not ise ans I term for the stabilize control (leave them zero), just use stabilize P
- Please post your videos and write your impressions on stability and control reaction.
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:
- Blinking LEDs with Relay if main Battery voltage goes down
- configure via mavlink: IN_VOLT_DIVR LOW_VOLT LOW_VOLT_PRE
- YAW Servo in moddle position on power on
- YAW Servo Reverse with mavlink command RC7_REV = -1
- Camera NICK: Lowpassing pilots input for smooth Camera motion
- Fixed minor Bug in BATTERY_VOLTAGE(x) and CURRENT_AMPS(x) Macros
- Switched to faster PIDT1 Algorithm
Saved some floatingpoint operations in PID_fast::get_pid:
2 x division /
4 x multipl. *
- 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:
- Reload your last setup and level the copter.
- Set all parameters for stabilize STB_***_P and STB_***_I to zero.
- Set all parameters for rate control RATE_***_P, RATE_***_I and RATE_***_D to zero.
- 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.
- 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.
- Proceed with the P-Terms. Increase and test until it gets unstable. Then reduce it to 50..70 percent of the original value.
- 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.
- 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.
- Always leave the STABILIZE I-Term STB_***_I zero in this controller configuration!
- 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.
- 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.