Where's main?

So, I've been digging into the ArduPilotMega (Beta 1.0) code to get a better understanding of how it works. I figure that it will help out in troubleshooting any problems I might have, but the real reason is that I'd like to modify the code to suit my own purposes. (whether this leads to my contributing to the official code, or if I take it my own direction)I'm new to the Arduino, but it looks pretty straightforward. There are just a few details that I'm missing that's holding me up, the biggest one right now is understanding where to start with the code. The ArduPilotMega.pde appears to be the main program. There are the initializing of the variables at the beginning, along with the config.h and defines.h. I can follow all of that. But then it gets down to the "Basic Initialization" section, where a number of functions are defined, including setup, loop, fast_loop, medium_loop, slow_loop, update_GPS, update_current_flight_mode, and read_AHRS.In C, you typically have a "main" function. I don't see anything equivalent here. Aside from all of the declarations I mentioned, where does the code start executing?I don't know what to call it, but I was also expecting a main program loop routine that would repeat, reading in the inputs, doing whatever calculations are required, and setting the outputs at each frame of time. I don't see that either. Are these functions called by an interrupt, or something like that, or am I looking at the wrong place in the code?I apologize in advance if these questions are obvious or if I just didn't search the forum well enough.Ryan

You need to be a member of diydrones to add comments!

Join diydrones

Email me when people reply –

Replies

  • In Arduino, when you're compiling, the *pde files are actually included into this file:

    #include <WProgram.h>

    int main(void)
    {
    init();

    setup();

    for (;;)
    loop();

    return 0;
    }

    ... so the "setup" and "loop" functions together with global defines are the closest thing to a main function in Arduino.
  • Ok, that makes sense, but I'm still hung up. In a typical C program, you'd start out with some include files, defines, and variable declarations. Then you'd see the function declarations, with a function "main" at the end which gets executed first.

    In ArduPilotMega.pde, I see the declarations etc... at the top of the file, then a bunch of function declarations (starting with the function "setup" and ending with "read_AHRS"), but there is no "main" function. So, which of these functions gets executed first?
    http://first.In/
    See related links to what you are looking for.
  • Developer
    loop is probably what you expect to be called main....
  • 3D Robotics
    The .pde file that has the same name as the folder is the "main" one. In this case, it's ArduPilotMega.pde.
This reply was deleted.

Activity