Debug Stream

Revision as of 23:25, 20 December 2011 by Bfeher (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Main >> NXT >> Functions >> Debug Stream

“Traditional” Debugging Techniques

Debugging a program – finding the errors and correcting them – can be a slow process in solutions without a run-time debugger. Without a debugger you may have to resort to different techniques like:

  • There’s no way to determine if your program is executing the intended logic. So you add code to play different tones/sounds to your program as it executes different “blocks” of code. You determine from the sound what is being executed within your program.
  • If your robot platform supports a display device (which could be a serial link to your PC or an LCD display on the robot) then you would have to add “print” statements to your program code at various points in your program. By examining the display, you can (hopefully) determine what’s happened in your program's execution by the display.

Both of the above techniques are available in ROBOTC. However, a real-time debugger eliminates the need to resort to them. There’s no need to add code for debugging to your program. A built-in debugger provides better functionality without ever having to modify your source code!

There is also a built-in Debug Stream that you can use to keep track of your program from behind the scenes. For example, you could print a message to the Debug Stream when you enter and exit loops, functions, etc. Then you can view the cached Debug Stream to help in the debugging process.


void AddToDatalog(const long data)
Adds an entry to the datalog.

Parameter Explanation
data An integer or long variable to print to datalog

int i;               // create variable 'i'
for(i=0; i<10; i++)  // cycle through "for loop" ten times (0-9), incrementing 'i' with each iteration:
  AddToDatalog(i);     // add variable 'i' to the datalog with each iteration of the loop


word bHideDataFiles
Boolean flag to indicate whether data files should be hidden or shown in the NXT GUI.

bHideDataFiles = true;   // data files will be HIDDEN and NOT SHOW on NXT GUI   
bHideDataFiles = false;  // data files will be SHOWN on NXT GUI


word nDatalogSize
The current size allocated to the datalog.

const int size = 2000;  // a constant int variable 'size' of size 2000    
nDatalogSize = size;    // create a new Datalog of size, 'size'


word nMaxDataFiles
Maximum number of saved datalog files (DATAnnnn.RDT) allowed on a NXT.

nMaxDataFiles = 15;                                     // allow up to 15 Datalog files on one NXT   
nxtDisplayCenteredTextLine(3, "Max Datalog Files:");    // display on a centered textline on line 3 
nxtDisplayCenteredBigTextLine(4, "%d", nMaxDataFiles);  // (will display, "15")


word nMaxDataFileSize
Maximum size (in 100 byte units) of all datalog files saved on the NXT.

nMaxDataFileSize = 10;                                     // 10*100 = 1000 = roughly 1 kilobyte   
nxtDisplayCenteredTextLine(3, "Max Datalog Files:");       // display on a centered textline on line 3 
nxtDisplayCenteredBigTextLine(4, "%d", nMaxDataFileSize);  // (will display, "1000")


const word nUsedDatalogBytes
The number of bytes currently containing data in the datalog.

nMaxDataFileSize = 10;                           // 10*100 = 1000 = roughly 1 kilobyte  
while(nMaxDataFileSize - nUsedDatalogBytes > 0)  // while there are still bytes left (0 < bytes < size):
  AddToDatalog(data);                              // write to datalog (fill it up!)


void SaveNxtDatalog()
Saves the existing datalog from RAM memory into a NXT file named "DATAnnnn.rdt" where 'nnnn' is numeric and increases by one on every save.

SaveNxtDatalog();  // saves the Datalog