ArduPilot Hello World printf and the Console Port in the Pixhawk

Trying to document this before I forget and also collect my notes to update the ardupilot wiki

As a noob in any new programming endeavor I always good to have a Hello World to make sure that I can make changes and see the results.    Also the printf or equivalent is the venerable simple way to get information out of a program to see the how it operating.    In the ArduPilot there are various ways to debug and do printf as shown here.

Coming in to this on my own I was confused about where the output of the data was and how to get it.  There’s various UART ports, a console port, and MAVlink streams.  In particular there is this:

void Copter::userhook_SuperSlowLoop()
    // put your 1Hz code here
  static int ticker = 0;
  if (++ticker > 10) {
    ticker = 0;
    hal.console->printf("printf HAL\n"); // no
    fprintf(stderr, "printf stderr\n"); // yes
    gcs().send_text(MAV_SEVERITY_WARNING, "gcs send text"); // yes on Mission Planner display

To get the simple Hello World running I did the following:

  1. In APM_config.h enable USERHOOK_SUPERSLOWLOOP to enable the function to be called once a second.
  2. Add the code in the previous snippet to the function as shown in UserCode.cpp.  I added a ticker to only display every 10 seconds so it doesn’t get too busy.
  3. Connect a “FTDI” or other USB/serial converter to the CONS port (on the PixHawk2 anyway as shown).
  4. Use putty or other terminal program on your computer to open the USB serial you just attached at 57600, n 8 1.
  5. Compile and run!

This works great and gets into the NuttX Shell (NSH)  for what that is worth. (This link shows how to connect on an earlier PixHawk and more info on NSH)

So while this works and I can now add prints to my code to view on it’s own terminal and also in Mission Planner from MAVlink there are some things I still don’t understand.  Like where is the HAL message?

More on the debug and UARTS:



Leave a Reply