NXT Debugging

RobotC has very powerful interactive real-time capabilities for debugging user application programs from the RobotC IDE on the PC. The PC-based debugger connects to the NXT either via a USB connection or via a BLuetooth connection.

 

debugPrint(format, parm1, parm2

debugPrintLine(format, parm1, parm2)

These are two powerful functions that you can use in your program to create a messages about your program execution on a PC window.The first function formats a text string according to the format specifier and parameters. The formated characters are added to the debug "stream" file. The second function is the same as the first except that it also starts a new text in the debug "stream" file.

 

The debug "stream" is implemented as a large circular buffer of characters in the NXT firmware. Every time "debugPrint" is called, the appropriate characters are added to the end of the buffer.

 

Meanwhile, if the RobotC debugger is in an active polling mode on the PC and the "Debug Stream" window has been opened, then RobotC will continually poll the NXT firmware to retrieve any existing characters from the start of the circular buffer and add them to the end of the text in the "Debug Stream" window.

 

The end result is that any characters you "print" or "write" to the debug stream appear in a Window on the PC screen.

 

If a user application program is running and writing text to the debug 'stream' but the RobotC debugger is not active on the PC then the circular buffer will eventually overflow and the oldest characters will be dropped.

 

Having added "debugPrint" statements to your program, it's likely that the programmer want the capability to turn on or off whether your program is generating  text for the debug stream. This is very easy to handle in RobotC. RobotC has a simple menu command to select whether the compiler should generate code for a "Debug" version or "Release" version. When this toggle is set to "Debug" then 'debugPrint will generate the trace text; when it is set to "Release" then the 'debugPrint' function call will do nothing and not incur any overhead for your program.