Where could I find a tutorial that goes through the Ardupilot code? I'm not new to arduino and I understand c fairly well. I am, however, new to Ardupilot and would like to have a good understanding of the code before I begin programming with it.

Views: 5980

Reply to This

Replies to This Discussion

Hello there

Can't find anything myself so far either...could anyone enlighten us?

I've been nibbling around the edges of the code for a few weeks myself.  Are you two asking about tutorials on using the code as is to get a plane flying itself, or about an overview of what does what so you can start really coding to modify arduplane or create derivative software?

The code is well commented, but well commented code to do something complex like flying a plane is still complex code... just with comments.  

I was thinking the other day that, as much for my understanding as anything, I'd like to go through all the code and make an overview...  a list of every variable in the program, with what that variable actually is and where is it modified, as well as a function by function plain text description.  That way if someone wanted to write their own code to handle a certain task they could at least get a head start on what parts would be affected by the pieces they delete or modify, as well as what to call when, and where to look for a particular bit of data.

The problem with an undertaking like that is it would have to be maintained... and the idea would be to make life EASIER on those actually doing the coding, not more difficult when they have to update the wiki every time they touch the code... so I fear it would be out of date pretty fast...


In my case I really want to learn how the code works, I want to modify it for a high altitude balloon launch attempt for a UAV to glide back home from 100,000ft.

What I was hoping for was an overview explaining the basic flow of the program, a flow diagram of the processes, what they do and what code it relates too.

EG “forgive my poor understanding of C++ but this is how I see it with my limited knowledge the main loop working”

 -------------------------Start------is the loop slower than 50Hz----Yes----Loop back to start

 |                             |No

 |              Run the Fast loop()----->

 |                             |

 |              Run the Medium Loop()----->

 |                              |

 |              Does the clock need resetting------Yes-----Reset

 |                              |No                                           |

 |------------------------Back to start-----------------------------------|


Now when I came to look at the fast loop I hit my first problem, a function is called


in this class is a number of functions, I am guessing they read the current transmitter settings but really don't find the comments much help.

I appreciate it is difficult to keep the documentation up with the code but a simple flow diagram would be great.

For my own good I would happily draw one out in Visio, but I'll need help from someone who understands the code, anyone willing to help?

PS"just found this" :0


I'm also (slowly) working on a balloon launch glider at the moment!  We definitely need to compare notes as we go forward.  There's no reason that ardupilot hardware won't work with the firmware rewritten.  Though of course, I suspect that the standard ardupilot gps units won't function above 60000 feet.  Our plan is to use a trimble lassen LP gps module.  The code outline for what we plan to run on the APM2 hardware looks like a series of loops:

Ground loop (test all sensors and motors, wait for serial commands to set the return point (if other than the current location) watch the gps to detect steady altitude increase, and when you get it go to:

Ascent loop (shut off power to the servos to conserve battery (using an IO pin to switch a mosfet), log and transmit gps position every 30 seconds, along with additional sensors.  Trigger camera shutter on an interval  Watch for descending gps signal, or for steadily decreasing altitude from barometric altimeter, if you see either of those conditions, go to the descent loop)

Descent loop (log and transmit gps position, if we've got it.  Trigger camera on interval.  If the GPS or barometric altimeter hit 40,000 feetish, go to Flight mode)

Flight Loop (power up the servos and begin stabilization. On a 50hz loop, check the magnetic compass to adjust heading towards the landing site and adjust rudder  on a 1 second loop, check the gps and update the intended heading to landing site. also log and transmit location on 1 second loop.  If we're within 250' of the landing site, circle.  Otherwise keep trucking.  If we get within 1000' of the ground go to the landing loop.)

Landing loop (Check for RC input - if we've got it let the RC transmitter take over.  If we don't have RC signal, continue circling until we land, or heading towards the landing site if we're not within 250'.  Activate superbright leds and audible alarm to help with locating.  Check if we've stopped.  If so, go to the landed loop)

landed loop (disable the servos again.  The xbee goes into an intermittent powered mode where it gets turned on for one minute out of every 5 to attempt to broadcast location.  The leds flash on for 1 second out of every 10. The siren sounds for 5 seconds out of every 30. This mode is designed to keep the thing powered up and aiding recovery as long as possible if it landed off target.)

We're also putting a spot tracker on board to make really sure we find it...   At the moment we're looking at a medium aspect ratio flying wing with pretty heavy wing loading and a fairly foward CG to try to make the thing survive the tumble back from no atmosphere, and then assume a nose down attitude as early in the fall as possible before the control surfaces are turned on.

As to your question about the read radio function, it looks like it does the following....

the first bit reads the pitch and roll from the radio and either passes them straight into the right variables, or mixes them (for elevon or vtail aircraft) and then sticks the mixed values in the right place.

This bit :

for (int y = 2; y < 8; y++) radio_in[y] = APM_RC.InputCh(y);

reads in the values for the other channels 

it reverse the throttle channel if it's been configured to, then calls throttle_failsafe to check if the throttle channel is being set at the failsafe level by your radio receiver (indicating loss of radio contact)

Then it uses two lines to figure out what percentage of the maximum configured throttle setting your throttle setting is currently... and stores that percentage, instead of the raw value

the last bit,( airspeed nudge and throttle nudge) I don't get yet...  but when I figure them out I'll let you know!

All in all... it's a really big coding project if you're not comfortable coding...  Another suggestion for you might be this - fly an APM running the stock software with no modification (but configured for you airframe, of course) AND an arduino...  and have the arduino flip a relay on the servo power when it detects a certain altitude so the APM can't actually mess with anything until you're back inside the atmosphere.  You don't want to shut off the APM completely, as it needs to calibrate on the ground...  but you could shut off the servo power so it didn't burn battery or servos trying to fly when it was dangling from a balloon.  A second brain just to turn on the servo power is a little silly, but if it saves you from having to do a major recode on the APM firmware, it could be worth it?  And the basic arduino you're using for that could be programmed with whatever additional logic you needed to add to the thing (cutdown charges? parachute deployment?  Recovery beacons?  Etc.)


Hi Art

Fascinating, great to hear someone else is busy with what I would term a COOL project.

Mine started out as an education based project when I worked with in a local education centre for students of all ages. Every summer I would run summer schools with students age 9 -13 on exciting subjects. One year I decided to include a glider launched on a balloon to take photo's of the earth curvature, this proved much more extensive than I first envisaged :)

We were using a commercial solution www.gpsboomerang.com from New Zealand. It is a very clever system but had some serious weight restrictions. The payload was a max of 350g and after some effort I included some sensors and camera. The weight was down to 318g including an Arduino control for the camera and radio beacon to send telemetry.

Sadly on the first test flight to 500m the wing appeared to fail, I tried contacting the company but it was not long after the earthquake (there based Christchurch) and I think Synco has lost interest.

Hence here I am...so it would be great to compare notes :)

Thank you for the run down, I have started a Visio flow chart which I have added those functions into. I’ll keep adding to it as I learn and if others are interested post them on the web.

On the airspeed_nudge it appears to check if an airspeed sensor is active, if it is I think it adjusts the throttle to compensate?

The throttle nudge I think is checking that your not flat out and knocks it back based upon whatever maximum throttle setting you have specified in the initial setup?

I know its a big challenge but I have learnt from the boomerang project and I think its better to learn every aspect of the project from the ground up. We tried to buy a quick fix and not understanding the underlying systems just caused me to make mistakes.

As you say additional hardware is a waste and I have so many great ideas for this project I am going to make sure the fundamentals are stable to build upon, it easier in the long run.

Do you have a project page? or something I can see your progress on? I did have one but need to get my new basic design up and running now as a priority first. My progress this last year has been very slow due to the local economics,

My airframe is still very much in progress, but I have decided upon a Nitro planes RQ11 Raven copy for testing. It’s sturdy and has the all important ability to fly to a test height (rather than rely upon balloon launches) then dropped in glider mode.


Hey Natha,

I am working with Art on the project. We haven't created a project page yet but should have something up soon. We plan to start a youtube channel documenting the project once we get a little further along.

I am intrigued by your experience with the boomerang and am excited to share ideas!


any luck on doing or finding some 'manual' for the code? (besides mark's)

I am very interested in it myself

Art -- I too am working on a balloon glider launch.  Please reply and let me know how you are doing with it.  --David  (Aerospace Education Officer, Civil Air Patrol)

Nathan --  I too am working on a balloon glider launch.  Please reply and let me know how you are doing with it.  --David  (Aerospace Education Officer, Civil Air Patrol)

Hi Prahas

I am just getting back into this project, I'd be most interested in hearing your plans, I am afraid I had some aero issue with my first glider and some other issues that got in the way.
 Would be happy to hear what your doing especially as its education based, which country are you based? just working on my prototype test frame at the minute, its slow going but I keep monving forward.

drop me a line :)

Hi Nathan,

I'm in the USA.  Where are you?

Right now, the plan is to drop around 35k feet.  I'm doing elaborate winds calculations, so that we can estimate where the balloon will drift, so we know the release point.  And then on the way down, we can plan RC gilder trajectories so as to minimize the horizontal distance we need to travel for launch.  

Haven't decided on flying wing vs. sturdy glider yet...  Hope your frame continues to move along.

What I really need is an ArduPilot guru, who I can bounce many questions off of.  I've been doing lots of simming, and learning slowly, but I have many questions.  I used to program in Pascal, but know no Arduino, so I'm trying to do it all with commands and parameter settings.

Are you, by any chance, an Ardu guru???  ;-)

Looking forward to your reply.

--Prahas David

I am in the UK, you sound like you have a whole team? Are you working with students? The Arduino is C++ really I am afraid I am no expert, just learning bit by bit. You find the forums are very helpful and if you know Pascal you'll be fine,the issue is understanding the Math or least it is for me :)

I am using a Niro RQ-11 replica for my testing but hope to move on to a strong delta wing for the big drop.

It would be great to keep in touch will you have a project page on the web?

I have a lot of interest here and support (I used to work in education until our useless goverment cut all funding after saving the banks) even the RAF was supportuve but funding was always lacking. I have spent two years getting back on an even keel, like most people have experienced its tough times. Progress is slow for me it is progress :)

My aim has and always was to share the education experience with all.

Reply to Discussion



Season Two of the Trust Time Trial (T3) Contest 
A list of all T3 contests is here. The current round, the Vertical Horizontal one, is here

© 2020   Created by Chris Anderson.   Powered by

Badges  |  Report an Issue  |  Terms of Service