This section is for topics related to debugging ArduPilot source code.
There are three ways to easily get debug output from your code - so called “printf debugging”.
Onboard Log messages¶
The AP_Logger singleton can be used to put messages to the onboard log:
AP::logger().Write_MessageF("u-blox %d HW: %s SW: %s", state.instance+1, _version.hwVersion, _version.swVersion);
More complicated messages (with multiple fields of differing types) can be created with Log_Write:
AP::logger().Write("CTRL", "TimeUS,RMSRollP,RMSRollD,RMSPitchP,RMSPitchD,RMSYaw", "Qfffff", AP_HAL::micros64(), (double)safe_sqrt(_control_monitor.rms_roll_P), (double)safe_sqrt(_control_monitor.rms_roll_D), (double)safe_sqrt(_control_monitor.rms_pitch_P), (double)safe_sqrt(_control_monitor.rms_pitch_D), (double)safe_sqrt(_control_monitor.rms_yaw));
See AP_Logger.h for the definition of this method. Generally, it’s a 4-character name followed by a comma-separated list of column names, followed by a list of list of format specifiers for each column, followed by the data. Similar definitions allow addition of multiplier and unit information.
printf(…) and friends¶
Everybody’s favourite go-to debugging tool.
Availability and where the output of this command goes is dependent on which hardware you are running on.
In SITL you can see stderr and stdout output in the xterm Window running the ArduPilot binary - or, on Windows, in the log file created in place of that window.
On Linux this output will appear on ArduPilot’s controlling TTY - so in whatever terminal you started ArduPilot in.
The stderr and stdout file handles are not available on ChibiOS, so fprintf is not an option. However, printf(…) output is either sent to a specified serial device (see “STDOUT_SERIAL” in hwdef.dat), or to the console (the first-defined SERIAL device).
This output appears on the console. For ChibiOS-based boards this is the first-defined SERIAL device.
Catching memory overruns¶
You can place guard regions around memory areas in the code to catch overruns by configuring the build using the —-enable-malloc-guard option on “waf configure” command prior to building the code for SITL