fredag 4 april 2014

Multiwii GPS Airplane

                     updated 2016-07-06 (Updated links)

This is a addon to the
How to setup a Multiwii Airplane

Download the stable 2.3 Version of FixedWing Nav code
Recommended for Flight controllers based on ProMini.(Atmega 328P)

Or the experimental Waypoint version.
Recommended for Flight controllers based on Mega processors.
MultiWii_FW_150431 with failsafe fix
Use with WinGui from EosBandi for setting waypoints.

What to expect from a MWii GPS plane?

The code supports.RTH & GPS-Hold.With the simplest FlightController and a Gps. Perfect for exploring the surroundings with your FPV plane.

A good presentation of RTH mode borrowed from Spencer Trejo

Connection Diagram


Can only be enabled With AUX switch.
Check both Angle mode and GPS Hold in Gui.
When GPS-Hold is activated The position is saved in a 3D Waypoint.
The plane will Navigate and try to "hit" the WP continuously and maintaining altitude.
No pattern is programmed and the plane fly the shortest way back.
Often in a circle or figure eight.

RTH (Return to home)

Can be enabled With AUX switch or by Failsafe.
Check both Angle mode and RTH in Gui.

When RTH is activated the plane will start Climb to reach safe Altitude.
If RTH is enabled Higher than set altitude it will start navigation and keep that altitude.
If altitude is safe the plane will start to Navigate to home Position.

Only use Angle/Horizon + Gps Home/Hold together.
Do NOT Activate BARO Or MAG for navigation.
It will interfere with the navigation code.

When the plane reaches SAFE_DECSCEND_ZONE the plane will begin descending to correct altitude.
The plane will keep flying in hold mode and continuously pass home.

If Failsafe is active at return The plane will Disarm motor and descend to a "Landing"

PID settings is made in Gui.
ALT & NavR.

Return Altitude can be set with
PosR D-parameter.
Scale is in km...
50m is set as defaut.
250m is Max.

This settings is done  in  Config.h .

#define MAXTHROTTLE 2000 
Because you  want Full Power sometimes!

Select your GpsType

In My case
#define GPS_PROMINI_SERIAL    115200
#define NMEA
#define I2C_GPS

Failsafe function

#define FAILSAFE
The obvious reason to have GPS in a plane!
FAILSAFE can take over the plane and fly it to Launch point if the Radio is lost.
When Home is reached the plane will stop motor and attempt to make a "Landing"

If Transmitter sends commands below 980µs Mwii will enable Failsafe!
Angle and GPS_HOME become activated.

If you can program failsafe function
on your Receiver Program throttle
To Below 980µs
Or set the switches for RTH.

Safety settings...

Give you the chance to Cut motor off with the Throttle Stick.
If Throttle is lowered to zero motor will stop.
Nice when doing preflight checks

If you stop motor during Navigation the plane Will most likely Stall!
There is a small protection programmed but it might not be enough.
(Common Aviation Physics...)

This settings is temporarily  in  Gps.h .
The following settings controls the behavior of the plane during Navigation.
Default settings gives quite soft characteristics.

This values can be set to Zero if Ex Rudder is not used.
#define GPS_MAXCORR    20  // Degrees banking Allowed by GPS
.#define GPS_RUDDER        15  // Maximum Rudder

#define GPS_MAXCORR    35  // Is Suitable for Flying Wing.

#define GPS_MAXCLIMB   15     // Max allowed Degrees climbing . To much can stall the plane.
#define GPS_MAXDIVE      15     // Diving . To much can overspeed the plane.

A Flying Wing usually need  around 30 - 40 degrees Maxcorr to tighten the turns.

#define CRUICETHROTTLE    1600
The vale  Throttle keeps when Altitude is correct for "Long Distance".
Should be set to a comfortable speed well over Stall Speed.

#define IDLE_THROTTLE      1300
When the plane is descending this is the lowest allowed Throttle.

#define SAFE_NAV_ALT        20  // Meters
To avoid  trees & buildings etc The plane will make a climb straight forward before Navigation starts.

#define SAFE_DECSCEND_ZONE  50 // Meters
 Radius around home where descending is OK

Note!...Don't forget the pre launch check!...

After takeoff, test RTH to ensure Home is set correctly before Going on a FPV mission

A bonus feature With RTH (Autolaunch)

If you enable RTH on the ground before Takeoff.
The plane will perform a full RTH cykle.
Climb, return and start circle....

Odd behavior on Rudder

Rudder have a tendency to try to hold the heading during Aileron/Elevator turns.
It can make the plane fly Sideways and other strange phenomena.
The cure is to Set YAW_I = Zero.


A example for a simple setup for RTH

FlightController  < $25
GPS module      < $20

A complete AutoPilot capable to save your plane  under 50$
I'm sure you can find even cheaper setups if you search on Ebay.


62 kommentarer:

Thomas Pabst sa...

Hi Patrick.
Can you plz explain which versions from
can be used for planes ?
I am searching for a version that can be used without GPS, too..



Patrik sa...

Hi Tom,
Latest "Stable" version is the one linked to in the top of this page.
In this RTH and PosHold works good.

There is also a Ver of EOS_b7.(Needs a Mega2560 Board)
This one have support for waypoint navigation.
It can navigate thru the wp-List.
But the PID's is not perfect and needs some tuning.

Both versions Have working RTH and is safe to use.
All versions works without Gps.
If you enable #FAILSAFE.
The plane will descend in a circle if you loose Signal.

Thomas Pabst sa...

Hi Patrik,
Thank you very much for your quick and detailled answer, i started testing already :)


Albert Sjoberg sa...

Hello Patrick

Thank you for this, I love what you have done with this project.

I am however struggling to get my aileron servos.
I have the Hobbyking Multiwii pro.
I have identified the outputs for Rudder, Elevator and throttle and flaps. The ailerons do not appear to be on any of the remaining outputs.

The Multiwii config shows the ailerons in and displays the output along with reactions because of movement.

Can you help? Is there a simple way to define the aileron (Roll) output to D9/D10 or D44/D45?

Thank you for your help

Patrik sa...

Hello Albert.
This guide is a complement to the
Where this is explained.

If you use a Mega Board you need to comment
Then you will move Ailerons on
D6 & D7 witch is available on most boards.

Take a look at the first part of the guide for more instuctions on
Setting up the plane for first flights without Gps.
Good luck

Albert Sjoberg sa...

Hello Patrick.

Thank you very much... that solved the problem.
Such a quick reply. Thank you.

Roger Zhong sa...

I am using this version and it works for my Hobby People Super Lightning with GPS, all default PID parameters. I am wondering if the author can add 6 mode aux switch code, similar to arduplane, so I can have one spare channel to control the servo gimbal on a nano-board.

Roger Zhong sa...

The 6 mode aux switch is present in the latest Navi version from Eosbandi, as discussed at

So hopefully the change will be migrated to Patrick's code too

Patrik sa...

Hi Roger,

I have a version based on Eosbandi b7 code.
It's based on the last update before it was merged to MWii branch.
I think the 6 pos switch is included in it (Not sure).

Navigation works but PID's isn't perfect for Missions yet.
I have only flown missions wohin LOS (5 WP circle <150m radius) but it might work better with longer distances.
RTH and PH works fine.
Feel free to test it.

Roger Zhong sa...

Hi, Patrik:

Thanks. I actually plug Eosbandi’s 6 mode AUX code into your code over the weekend and then test flight, it works. My code is at

If I had checked your site more frequently, I would not waste this effort. Great to see your new version, and will test it soon.

With this 6 mode AUX code, I can spare AUX2 to control the servo gimbal tilt. Except the gimbal is configured using multwii 2.3 java GUI, others must be configured using the GUI from Eosbandi’s web site.

I had to hard-coded the following change to let AUX2 works for the gimbal tilt.

In Output.cpp
#if defined(SERVO_TILT)
//servo[0] = get_middle(0);
servo[0] = get_middle(0) + rcData[AUX1+1] - 1500;
servo[1] = get_middle(1);

Roger Zhong sa...

As your indicated, EOS_b7 needs a Mega2560 Board. The 6 mode AUX change I made still works on a 328 nano board. Thanks.

fly_to_the_sky sa...

Hi Patrik,first of all, all the best for the new year and thank you for your great job on airplane code. But, let me ask you: does your latest version of code support flyingwing too, with all the features you have done for airplanes?
Thank`s Mario

Roger Zhong sa...

Hi, Patrick: I am testing your "The New Version with Waypoins Based on MultiWii 2.4". The FC is Cirus SE 2.5. Even though the plane is not moving on ground, the mag heading is slowly and constantly drifting, as shown in the GUI. Is that normal? The mag heading does not drift in your old version.


Roger Zhong sa...

Besides, I am still using i2c GPS. Should the firmware for I2CNAV use your patched I2C_GPS_v2_2 in your old version

Patrik sa...

V2.4 version uses Gyro to estimate heading.
Your Gyro may drift a little.

When You connect GPS it will overwrite the Heading when it moves.

I'm not sure about I2CGPS but i think the modified is better to use.

Jhayr Rodriguez sa...

Hello Sir Patrik,

Thank you for this great work,.Im very excited to have this on my bixler.

I started setting up on my multiwii megapirate 2560 FC,.My clarification;
1. Is the latest version of code above can be used on my FC(Mega 2560)?
2.I noticed also that once I trigger the arm via Aux switch, the motor starts, is this normal?

Hoping for your positive response. Thank you.

Patrik sa...

Hi Jhayr,
You can run the code on your FC.
It can even run on a 328 FC.

If you want the motor to stop at Minthrottle.
#define MOTOR_STOP

Jhayr Rodriguez sa...

Hello Patrik,

Thank you very much, really appreciate the information.

Jhayr Rodriguez sa...

Another question sir, Sorry Im so new to this. How the FC identify the Home point?Is it automatically set once we power-up the plane or the FC? or we need a separate aux switch to set for home point? Thank you very much!

Roger Zhong sa...

I have test both GPS hold and GPS Home in my Hobbypeople Super Lightning and old Zagi flying-wing. Both work. The FC in Zagi is Multiwii SE 3.0 with only MPU6050, plus I2C GPS.

Gel KGB sa...

Hi Patrick, thanks for all your job!
I allready tested the 2.3 version on a bixler with full success on the RTH on failsafe, and since a few day I test the 2.4, but plane doesn't seem to RTH... It's on south of the home point (correctly placed on minimOSD), and allways go est.... I noticed in the config.h that :
When in original code it's 1.
I don't understand the purpose of this variable, could you please help me! Thanks!

Gel KGB sa...

I use MultiWii_FWnav_150331

Gel KGB sa...

Another cloud I discover today... I install 2.3 back, and I arm/disarm via aux channel, and failsafe was desarming plane if throttle was 0%, plane was in RTH mode, but without motor....

Patrik sa...

NAV_TAKEOVER_BARO is for copters.
But maybe it can affect planes too.
Set it to 1.
It's also available from WinGui.

If the plane disarmed your throttle channel triggered FAILSAFE_DETECT_TRESHOLD.

If you enabled #define MOTOR_STOP
The motor will stop if throttle is zero but starts again when throttle is opened.

Gel KGB sa...

Hi Patrick, thanks a lot for your answer!
Tomorrow I will test if all is ok with 2.3, and this time I set failsafe aux channel to arm the plane, so it will not disarm when throttle go to 0
when i switch off the tx in 2.3, plane go in rth and if throttle go to 0%, it disarm plane so motor cannot restart, but plane try to "glide" in rth (I see all that on minimOSD recorded)
If all is nice with 2.3, I will maybe retry the 2.4 version if you confirm me that rth works for you, may be that in 2.4 version if plane is "disarmed" in failsafe rth, navigation will not engage?

C Vogel sa...

Hi Patrick thanks a lot for the program I'm using it with a MultiWii Pro in a flinging wing and it works perfect. Hope you get the final version for nase soon thank you so much

Gel KGB sa...

Patrick sayd: "If the plane disarmed your throttle channel triggered FAILSAFE_DETECT_TRESHOLD."
I will try to explain, it not disarm via thr, all is nice trimmed, but when I switched off tx, aux channel for arming failsafe was set to 0 and was desarming the plane, but the plane will not disarm of thr > 0, so when thr reach 0, plane disarm itself only when tx is switched off, I re-binded my tx to set the aux channel failsafe to max, so plane should not disarm anymore.
And this is may be why in 2.4 my plane was never going home, cause I did not notice this "self-disarming" in OSD and MW 2.4

Gel KGB sa...

Hi Patrick, I tested 2.4 today... And crashed my bixler, but this a pilot fault... :)
I tested RTH with a switch, and this was succesful. I tried it by using failsafe and turning off my tx, plane goes to est in straight line, I tried with faisafe settings activating the switch RTH, and plane go to est in straight line. But with tx on and switch RTH, it fly back to home...
When I use 2.3, all is nice except my problem with switch-arming, but resolved, and when I switch off tx, plane fly back to home, without any aux rth box checked in gui...
The only way to have faisafe working on 2.4 for me is desactivating failsafe in config.h, and programming all failsafe settings in tx, or keep the 2.3 version.
My tx is a devo 10 with deviation-tx, binded in spektrum 1024 on an orange 620 which I put the sbus in a rmitech to have ppm in a crius 2.5, don't know if it could help.

Patrik sa...

It sounds to me Failsafe isn't detected by MWii.
Somehow The RX sets it in Acc mode only.
How does your RX react if failsafe?
Optimal is if you can force it to send PPM.
Next best if to program it to drop Throttle below fs detect threshold.
Last alternative is to program RX to set switched RTH in failsafe.
But i don't recommend that!..

Gel KGB sa...

Yes FS is detected by multiwii, in 2.3 it works nice, I've already programmed my tx to send 980 us in throttle in FS.
And you're right, the only way to have working in 2.4 for me is to "set switched RTH in failsafe" AND desactivate failsafe in config.h (I tried to put throttle failsafe to 1080 and FS still detected), else the plane go est.... Or staying on the 2.3.
In 2.3 failsafe was only detected by throttle to 980 us, but it seems that in 2.4 it detects it in ppm signal.

Oh, I've got video footage of all of this with my minimOSD, and when I turn off tx with 2.4, the minimOSD indicates that plane is in "AUTO-RTH" mode, but does not go home...

brooks shield sa...

hi patrik,

very nice to see your tutorial for multiwii fixed wing with rth function.very helpful and very informative.

just want to ask if you have any other tutorial for flying wing setup? or any other links that could help us to setup the parameters for multiwii flying wing.also any good PID setting that we could start to?


Patrik sa...

Gyro P 1.5 is a good starting point.
You need more aggressive settings for navigation too.
#define GPS_MAXCORR 35

Otherwise you can follow the tutorial.

Saku Sell sa...

Hej Patrik,

I have your settings on Teksumo flying wing and really enjoy doing fpv. However I cannot find the #define GPS_MAXCORR anywhere in the code. I would like to increase the value.

Thanks for your work,

Patrik sa...

Hi Saku

You can find the settings in GPS.h.

Saku Sell sa...

Thanks Patrik. Had too many multiwii version folders on my laptop and got confused about the right folder.


Asparuh Nestorov sa...

Hi Patrick, You have done a great job. I just test your version and RTH works great. However when fail-safe is activated it goes in straight line toward east. I can confirm the the fail-safe triggers as it switch to RTH. I am a programmer and wish to help solving that issue. I allowed using barometer to determine altitude as I can not trust GPS altitude accuracy.

Patrik sa...

What version and controller (Mini/Mega) do you use?
I have seen some issues like this when i run the Waypoint version on ProMini.
Probably caused by low memory.
Because i have had some successful failsafe RTH in the beginning of the flight.
After some 15 minutes flight it started to behave like you described.

The version without Waypoints is well tested on Promini's.
And recommended to use for the small FC's

Asparuh Nestorov sa...

Hi, its a 328p Arduino Nano board loaded with your 2.4 based version + I2C GPS board. I have disabled Waypoints as I enabled the use of barometer. Rolling back my memories I think my that the first 1-2 tests the plane was executing RTH correctly after failsafe and the next 5-6 tests were not successful. I also disabled disarming after failsafe so that I can take over control of the plane after TX/RX communication is re-established. I am interested in fixing that so if you want we can exchange our emails and work together.

Asparuh Nestorov sa...

Just to mention , I am using a modified by me official 2.4 version of MW (using 97% of program space and 86% memory) where I made it start RTH in case of failsafe and have more than 30 successful failsafe RTHs and seems works reliably. However your new GPS functions make the flight smoother and well better controlled. I am now trying to understand the entire MW code and see if I can found why it do like that. One more think I just remembered : while in failsafe and RTH the model flies away but when I switch back on the TX, same RTH starts to execute properly. Any thought? I am excited about further developments. Thanks

Frederic Laurent sa...

Hi Patrick

thanks for the wonderfull job you did for mw airplane...

everythink works fine on my hk bix3 with crius AIO v2, and the 2.4 version ... except failsafe...
when i turn off the TX, the plane says "RTH" but flies away.... and it's hard to take control again...!!! : i had to disarm and re arm in flight!!!

i must add that "standard" RTH switched by AUX, works nice ...

i suppose i have the same problem as Asparuh Nestorov (previous post)

what can i do?


Patrik sa...

For a reliable Falsafe RTH Use the "Stable" version in top of the page.

Actually i have not really put much testing in thr Failsafe RTH on the 2.4 version.
I looked thru the code and saw i left a TODO note i made about fixing it in the MWii.cpp file.

If you want a safe option run the older Stable version.
It's well tested.

The new is still experimental and i have put most work on getting the Waypoint navigation right.

Apparently i need to take another round with the Failsafe.

I tried to contact mr Asparuh Nestorov via Facebook Messenger bit maybe my message was sorted as junkmail or something.

If he checks his inbox folders he might find my message.
I need all help i can get on debugging.
He is welcome to contact me on the options i left in the message.

Frederic Laurent sa...

Hi Patrik

thanks for your answer....

I told Asparuh Nestorov you tried to contact him...

I'm not an informed programmer... but if I can help, looking at the code or beta trying, it will be with pleasure...

Frederic Laurent sa...

Hi Patrik,

is it possible to do waypoint missions with 2.3 version?

Patrik sa...

The 2.3 version only supports RTH and Pos hold.

You must use the New 2.4 Nav version for waypoints.
I have made some corrections in it and it should be safe to use now.

I also update the link in the top of the page.

Frederic Laurent sa...

many thanks...

I did some nice WP missions with 2.4...

but radio failsafe failure frightened me...!!! (didn't try to go father than 600 meters )

I'll be glad and proud to test FWnav151120.... as soon as weather will allow it... ;-)

did you have news from Asparuh Nestorov who seemed to be very interested in mw development... ?

have a nice day


Frederic Laurent sa...

Hi again Patrik,

What about #define STAY_IN_MISSION ..? in v2.4

if commented, failsafe did not recognise radio turn off...

if uncommented, failsafe switched on when tx was turned off but plane flied away as you already know....

Patrik sa...

I Fredric,

I have Added Asparuh Nestorov on FB.
Hopefully he will participate.

The Failsafe issue is fixed in the 151120 version.

STAY_IN_MISSION is experimental.
If Failsafe is detected during a mission it should continue the mission.

In normal flight if don't have any function.
I have only bench tested the STAY_IN_MISSION but it seems to work as intended.

But test short radius missions before longrange.

Winter have made the entrance here and i don't have many days of flying..
Bench simulation is great but i want to fly!..

Frederic Laurent sa...

I'll be proud to test and fly for you and inform you of results... if winter lets me take off !!!!!
perhaps one of these days...

I'll comment //#define STAY_IN_MISSION.. and fly.... before uncommenting it...

I hope failsafe will do its job...

I'll keep you informed of my trials

see you


Frederic Laurent sa...

Hi Patrik

Here is what works in MultiWii_FW_15043:

-RTH switched by AUX does its job: plane returns home and when reached, Holds position.

-Missions are fine even with RTH as last Waypoint.

-As you already know, Failsafe doesn't work.

I've been out this morning to test MultiWii_FWnav_151120:

the plane is still nicely stable in angle mode.

-when I switch on RTH by AUX, the plane says RTH but flies away....

-when I switch on Mission, the plane says" Mission is on, going to waypoint "... but flies away in another direction than waypoint...

-I didn't dare to switch TX off to test Failsafe...

Hope this will help...

if you want to, I can send you my config.h

best regards


Patrik sa...

Hi Frederic,

Sounds strange.
Did you use the same config file as with the 150431 version?
The configs is compatible so you could use same in both.

I took the old version and modified it.
The changes is in gps.cpp and you should be able to just swap the file.

Frederic Laurent sa...

Hi Patrik

thanks for your answer

just verified my config.h's...

they are the same: the only difference is that I uncommented #define STAY_IN_MISSION in 150431, (if commented TX turnoff was not detected and failsafe couldn't swich on )
while I let it commented in 151120 ....

yes that's strange...

I'll be glad to try 150431FSFix and let you know....

Frederic Laurent sa...

Hi Patrik,

I just tested 150431FSFix, swapping gps.cpp as you told me to.

- RTH works nice stiched by AUX or Fence Distance...

- Mission works nice too, even with RTH as last waypoint...

- when I turn TX off, the plane says RTH but still flies away... so I turn TX on again and it executes "real" RTH... but when I want to take control again, RTH continues even after RTH on-off switch by AUX....
So... no other way to take control again than desarm-rearm in flight ;-)

It's the same behaviour as previous version....

Could it be possible to code a "simple" RTH routine (like the one that works fine) when failsafe is detected?

Hope this will help..

see you


Patrik sa...

I just tested 150431FSFix, swapping gps.cpp as you told me to.

The 150431FSFix version contains the fix already!.
I hope you didn't swap it for the 150431 gps.cpp because it have the error..

You can Reuse the Config file and GPS.h from old version but not gps.c

About the continuing RTH after Failsafe..
You can toggle GPS mode to disable it.
It's there to avoid disabling by mistake.(Original MWii code)

Failsafe triggers the normal RTH function and should behave the same way.
But I need to check what else is triggered by Failsafe to.

Frederic Laurent sa...

Hi Patrik,

I hope I wasn't wrong, swapping gps.cpp files....

anyway, to remove any doubt, I'LL use your last 150431FSFix version, reusing config.h , gps.h, and def.h only ....!!

"" Failsafe triggers the normal RTH function and should behave the same way.""

In my trial, failsafe didn't switch RTH on ...(plane said RTH but flew away) : true RTH was striggered on, only when I turned TX on again...

about RTH after failsafe, what do you mean by "toggle GPS mode" ?

as I told you: ""but when I want to take control again, RTH continues even after "RTH on-off" switch by AUX.... "" seems the same as "toggle" isn't it??

sorry for my poor English... but let's keep on moving forward... if you still want to.. ;-)


Frederic Laurent sa...

Hi Patrik

just tested 150431FSFix using your last version, reusing only my config.h , gps.h, and def.h , as we said yesterday..

RTH and Mission still work nice,

but Failsafe still behaves the same way:

when I turn off TX, the plane says RTH but flies away........I wait some time executes RTH only when I turn on TX again...

toggling RTH on-off doesn't allow to take control again... and the plane continues RTH....
I had to desarm-rearm in flight to take control...and land.. (anyway, I'm not as frightened as the first time ;-) )

Can you please tell me in what file(s) I can have a look at Failsafe routines?



Patrik sa...

Hi Frederic,

The failsafe is spread over several files.
You can search in all files for.

Then you will find all appearances.

Chatting here don't feel right.
It would be easier to move the discussion to another place.
Skype, FB messenger or Hangouts,
I have sent a Hangout request to you.

Michael Ananyev sa...

Hi, Patrik!
Can't understand what i did wrong.
When i cheking the i2c_gps code i have an error:
Arduino: 1.6.8 (Windows 10),
PIDCtrl.h:87: error: 'constexpr' needed for in-class initialization of static data member 'const float PIDCtrl::_filter' of non-integral type [-fpermissive]

static const float _filter = 7.9577e-3; // Set to "1 / ( 2 * PI * f_cut )";


exit status 1
'constexpr' needed for in-class initialization of static data member 'const float PIDCtrl::_filter' of non-integral type [-fpermissive]

Patrik sa...

Some news in the newer versions of Ardiono IDE!..

Remove (static const) from the line in PIDCtrl.h
static const float _filter = 7.9577e-3; // Set to "1 / ( 2 * PI * f_cut )";
Then it should compile.

Michael Ananyev sa...

It's work!

AlexN sa...

Hello PatrikE,
Could you please update the link for your code as it no longer seems to work.

Patrik sa...

Updated the links

владимир труновский sa...

Hi, Patrick!
Gathered on your schedule v 2.3
Compiles CRIUS_LITE board
and other fees, is not compiled
Board CRIUS_SE v.2.0
Why? Thank you!
collect2.exe:error:Id returned 5 exit status