This is a work in progress. I've tried to address some fine tuning and performance issues.

Denny R. had made a comment about the inertia of bigger props causing issues. I've added a low pass filter to smooth the positive acceleration of the props to see if we can get at this issue. It may require tuning up Rate_P for a few folks, but I saw little issue in multiple flights.

Crosstrack had a small math error that decreased the resolution of it. I've fixed that and upped the default gains to get better tracking. 

Made WP hit radius 1 by default. even 3m is too much for quads. (If you pass a WP you will move on to the next)

The Loiter method is tuned a little better by default, and now uses GPS offsets when flying less than 1.5m/s. Code experimentation will continue on this front. Thanks to Emile and afernan for their help!

A fix in the Z Accel startup was added to get an averaged result.

Added the ability to enter Loiter with Optflow enabled. - still a work in progress, not for everyday use just yet.

This alpha is on GIT now and is for user's who want to test code. As always, you need to use the "relaxpatch" version of Arduino you can find in the downloads section

Update: We've found and patched some small type bugs in the latest and updated some GPS drivers in the Library. Be sure to pull the latest code and check for the status of each build run against the SIL sim server.

Update r3:

I pushed a version on to GIT that addresses a number of issues.

- the low speed GPS XY calculations were incorrect and have been fixed

- Nav_Rate I term has been removed in loiter control - it's too easy to get two iterms working out of phase

- A second derivative has been added to Roll and Pitch. I found it removed wobbles nicely - Can be adjusted in the planner as STAB_D with a default of .25 (just enough)

- Smoothing has been applied to the motor commands in a way that really quiets down the alt hold pulsing without much effect on latency

- Yaw now has a dynamic constraint and I've upped the yaw gain.

- The motors output now have an LP filter on them so that the accelerate just a tad slower than the deceleration. This is a test to see if it helps big Octo's and Hexa's

- The Rate_I term is now zero'd for first five seconds after takeoff to keep balance.

- Loiter gains are lightened up a bit

- Nav_Rate_P is lower to remove back and forth sped related hunting in loiter

- Compass is enabled by default

- New I2C Library now included which should solve I2C related lockouts

- optflow is still a work in progress.

Update R4:

This update is based on flights today in a very windy environment.

It occurred to me that we're handling the WP nav I terms incorrectly and I reworked the WP navigation to share the same I terms from the Loiter. Even though they use different error input, etc, they turn out to both deal with wind in the same way. I have not Flown WPs with this new code, but heavily tested it in the sim and It's really rocking in hard wind. Transitions from Loiter flight and Nav flight are very smooth. Please let me know if you have luck.

Update R5:

This is a quick patch based on a bad crash Marco had. My theory was an I term that built up during wind that needed to be reset, but wasn't. It's a corner case but It bit Marco pretty bad. Please re-pull if you have R4 running to go to R5. And please, please be careful. This is alpha code not for general testing, but for development. Don't fly it on anything you would feel bad about crashing. 


Update R6:

Includes fix for Acro mode reset bug.
I went through all of the global variables and gave them lengthy descriptions. It's worth a read if you want to learn more how the internals work. I'll be doing some more organization like this as we move forward with an architectural redesign for 3.0 \
This version is mostly clean-up, but does include 1 interesting performance enhancement. It's disabled by default because It's fairly untested. The idea is that the wind compensation created by the Iterms for lat and lon in Loiter and Navigation are carried over into Stabilize. This unifies all of the modes so that when you switch modes, you don't get a small, but fast change in pitch or roll. This is only noticeable in high wind environment. 
To get this to work, I look for near zero velocity and start moving the pitch and roll into the wind control items. This takes a  transformation from copter frame to world frame, but the result is the copter will hold the position against the wind with the sticks in the center of the controller. If you fly around the wind compensation will bleed off slowly - about 30 seconds.
Again, this is off by default and needs significant testing, preferably in the HIL sim first.JNL has already started and flown this version for real.
The feature may be off by default for another version or two, but just letting you know it's there.
I think it will go a long way to making the mode changes feel seamless.

Update R7:

Added an auto-land timer for RTL. If you don't change modes for 20s after the copter arrives at home, it will begin to auto-land. If you have failsafe and no GPS, you will immediately begin auto-landing.
Failsafe RTL now goes 10M up as it RTLs to avoid obstructions.
Added SIL test for failsafe. 

Update R8:

Minor tweaks and cleanup

Update R9:

Made climb rate controller for landing universal for all altitude changes

Update R10:

Updated Loiter controller - Works great in the sim, thanks Afernan.



Views: 42946

Reply to This

Replies to This Discussion


My experience with Stab P = 4.6 on my 3DR is that it's somewhat "sporty". If you are flying in stabilize mode it's nice and responsive, but with some quickly damped oscillation on step inputs from the sticks.

I use 3.6 - the response is slowed noticeably but not seriously - you can still get out of trouble manually if you have to. Even lower is probably OK too.

However, you can see how fast it wanders in Loiter. It's generally a lot slower than the response you'd expect from bad stabilize settings.

Let it fly in Stabilize with your hands off the cyclic control. Does it stay level and just drift with the wind? Bump it with your hand while it's flying - does it return to level smoothly and without undue delay?

I was using an APM1 and now I on an APM2. I didn't notice any change in stability when I changed. If tthe gyro and accel gains are similar this is what you'd expect. There may be some second order effects due to the relative frequency response of APM1 & 2 gyros and accels.

Navigation is a layer above the stability loops, so should be independent of the HW to a large extent.

Phil, thanks for the suggestion. I am keen to get camera stabilisation working, which does not look possible on an APM 2 board until February, so I am probably going to swap my boards over tonight and give 2.2 a go in the morning. If I can get similar performance to that which I obtained at dusk, plus camera stab, I will be a happy man. If not, I will revert to my APM 2, give your suggestion a try, and borrow an FY30A to separately stabilise my camera mount. Cheers, Bill


Just connected the + from one lipo cell to the + IN sonar for a quick test to eliminate ESC 5V power problem.

And behold, it works great!!!!!

Log attached. Sonar is 99,5% smooth just one or two spikes that I didn't even notice during flight.

So the problem is certainly the ESCpower. I need to get a BEC soon ;-)

One question though. If I am in AH and push the THR up or down, the quad will change height untill I center the THR stick. Does the quad have to stay at the new altitude or go back to the firts AH height when selected.

If you checked the logyou can see that it returns.

Or is this a SF setting????


So you supplied it with only 3.7V and it worked?  Interesting.  Maybe it's actually running off 3.3V instead of 5...

Anyway, good news.

Datasheet says it has to be between 3,3 and 5V.


Whats your view on the AH change with THR?

I'm not positive on the AH.  I believe it's supposed to hold the new altitude setpoint, at least that's what mine seemed to do.  I haven't used it much though.  And I don't know if there's a setting.

Real Flight test with 2.1.1r10

No wind
Small custom quad 650gr rtf

good behavior in general. I' ve needed to low Loiter_P to 1.5 and Loiter_I to 0.01. Higher values produce oscillation not damped. I need more D factor for this small copter: to be tested.

Autoland. Still the problem of final cut down. Stays kissing the ground without landing. I do propose the R7 approach.

Simple mode does not work properly


I'm curious that the PID is so high as default when I read on the forums that most are resetting it from 4.600 to lower around  P 3.600 for Stab Roll and Pitch.  What variables of the craft should be taken into consideration whether the settings are higher or lower? I would assume weight and power and their ratio relatively? 

For example mine is Coaxial X8 and flight weight about 2.3kgs . I calculated max thrust to about 7.5kg with the current motor/prop config so have put the optimum flight weight at about 4kg max. 

For higher power to weight ratio is it better to have  a lower PID for Pitch and Roll for a medium response?

One to also add for all electronic is to make sure that if you mount them onto a carbon fiber frame to make sure there is good insulation between the boards and wires and the frame. The frame is conductive and it can short out you boards etc if strapped directly to the frame without any insulation.

Hi Roberto and Marco,

Do you have a fix for explicitly defining which GPS to use? I tried changing the rx buffer size to 256, but as Marco said, that didn't allow the specification- only auto seems to work. However, it does work while connected to USB. More ideas?


This is awesome!! thanks!!

Reply to Discussion


© 2019   Created by Chris Anderson.   Powered by

Badges  |  Report an Issue  |  Terms of Service