Skip to content

Debugging

Ashish Jaiswal edited this page Jul 21, 2026 · 2 revisions

Debugging.h

Debugging and monitoring functions for printing to the debug serial monitor and exposing variables to the Black Box logger.

Note: OLED functions previously listed here have moved to their own module. See Oled.h for display output.

Monitor Functions

Debug output is generated as your code runs, so Monitor_* calls typically live inside plutoLoop().

void Monitor_Print(const char *msg)

Prints a message with no trailing newline.

void plutoLoop ( void ) {
    Monitor_Print ( "System: " );
}

void Monitor_Print(const char *tag, int number)

Prints a tag followed by an integer (no newline).

void plutoLoop ( void ) {
    Monitor_Print ( "Altitude: ", 150 );
}

void Monitor_Print(const char *tag, double number, uint8_t precision)

Prints a tag followed by a floating-point value with the given decimal precision (no newline).

void plutoLoop ( void ) {
    Monitor_Print ( "Voltage: ", 12.45, 2 );   // -> Voltage: 12.45
}

void Monitor_Println(const char *msg)

Prints a message followed by a newline.

void plutoLoop ( void ) {
    Monitor_Println ( "Ready" );
}

void Monitor_Println(const char *tag, int number)

Prints a tag and integer followed by a newline.

void plutoLoop ( void ) {
    Monitor_Println ( "Loop count: ", 42 );
}

void Monitor_Println(const char *tag, double number, uint8_t precision)

Prints a tag and floating-point value (with precision) followed by a newline.

void plutoLoop ( void ) {
    Monitor_Println ( "Pitch: ", -3.14159, 3 );   // -> Pitch: -3.142
}

Black Box Functions

Only available when the firmware is built with BLACKBOX defined.

void BlackBox_setVar(char *varName, int32_t &reference)

Registers a variable with the Black Box logger so its value is recorded under varName. It is a one-time registration, so do it in onLoopStart(); the logger then samples it automatically while the loop runs.

int32_t altitude = 0;   // must outlive the call - use a global or static

void onLoopStart ( void ) {
#ifdef BLACKBOX
    BlackBox_setVar ( "alt", altitude );
#endif
}

Usage Examples

Monitor printing

Print debug output every loop from plutoLoop().

#include "PlutoPilot.h"

void plutoLoop ( void ) {
    Monitor_Print ( "System: " );
    Monitor_Println ( "Ready" );

    Monitor_Println ( "Altitude: ", 150 );      // integer
    Monitor_Println ( "Voltage: ", 12.45, 2 );  // double, 2 decimals
}

Black Box logging

Register the variable once in onLoopStart(); the logger records it automatically while plutoLoop() updates its value.

#include "PlutoPilot.h"

int32_t altitude = 0;   // global so it outlives the call

void onLoopStart ( void ) {
#ifdef BLACKBOX
    BlackBox_setVar ( "alt", altitude );
#endif
}

void plutoLoop ( void ) {
    altitude = Estimate_Get ( Position, Z );   // update the logged variable (altitude)
}

Clone this wiki locally