Hey all, I (very recently) began working with APM2 in a quad platform mainly for the purpose of learning how to work these types of controllers (and hopefully to contribute as time goes on). So far, I have not been able to venture into the actual code, I have working to tune and control my quad using only the mission planner (I have successfully achieved stable flight, stable altitude hold, and stable loiter). In the future, I imagine there will be a lot of things I would like to try, but I think I need better C++ capabilities to make them work.
I have some experience with C programming, Basic, and experience working in Matlab; however, I have no experience with C++ (and certainly no experience with anything on this type of scale). My first plan was to understand C++ on a "hello world" kind of scale, but I'd also like to study the APM2 software to understand how it all works (hopefully, this gives you an idea of my current level of programming ability) and to give myself some direction.
Can anyone in this group offer some good starting points for reaching my goals for coding? My first attempt was to simply read the .txt files from the APM download (this may be another good indicator of my "skill" level) but I can't seem to get around the formatting... everything just looks like a mess. Not to mention there are so many files that I honestly can't figure out which one to try to read first.
Anyway, so that you know I'm not a complete lost cause, several years ago I was able to write some scripts using Matlab that read and analyzed metallurgical images to determine average crystal sizes, and, since then, I've developed several other analytic tools. I just simply don't know to begin with this, so any advice would be super helpful.
Replies
Hey Mark,
If you're looking to learn C++ I would definitely recommend C++ Primer Plus by Stephen Prata. It's an incredible book and you can probably get a used copy for under 20 bucks. I'd start programming for a normal computer though, not an Arduino. It'll be easier to debug and there's more support for it (and the examples in the book will work). You can get a good compiler for free on the interned. Visual Studio express edition will probably be the easiest for you to set up and start working with.
Once you're more comfortable with that try picking up one of the cheaper Arduinos just to mess around with. I have an Uno sitting on my desk that I use perpetually to try out new things. The example code on the Arduino web page is a great starting point.
Once you're comfortable with both C++ and Arduino, take a deep breath and dive into the ArduCopter code. Arducopter.ino (may be .pde for you) is the place to start. Any time you see a function or variable in there you don't understand, find where it is and read it. I'd strongly recommend a full featured IDE like Eclipse. Don't worry about getting your code to compile in it though. The right click -> open declaration feature is really the only part you need. If you're familiar with grep to it'll help track down where things are referenced too.
Be prepared to spend a fair amount of time on it before anything makes since. It was my full time job for 3 months to read the code (lucky me!) and figure it out, and I still don't understand everything.
Best of luck,
~Nate
P.S. A interesting 'feature' of the Arduino compiler. All files that end with either .ino or .pde are concatinated into 1 mega file before compiling. So any identifier with file scope in a .pde or .ino will be accessable in any .pde or .ino file (normal C++ does not work that way). Took forever to figure that one out.