|
|
|
|
Debug Logging
Debug logging provides a method to send text from the NXT brick to the debugger.
The debugger shows the text in the debug log window.
Debug logs provide run-time status and variable value information to improve and simplify debugging, and also for data-logging.
With a little extra work debug logs can be used for charting data variations as well.
Every log message from the NXT can be up to 56 characters long.
This is the communications upper limit for a single message posed by the firmware on the NXT brick.
Messages longer then 56 characters will be truncated and only the first 56 characters will be transmitted.
In NBC source code transmitting a simple debug log message is implemented by a single
#pragma debuglog 'Hello World!'
instruction.
Debug log messages can be built up from as many as 16 segments.
Each segment can be a constant string (as in the example above), a string variable or a numeric variable.
Numeric variables will be converted to text, and the entire line will be concatenated into 1 message prior to transmission.
The following examples will log the values of a few variables:
#pragma debuglog 'X=', x, ' Y=', y
#pragma debuglog ’TODAYS DATE IS ’, nYear, ’ YEAR ’, strMonth, ’ MONTH ’, nDay
#pragma debuglog ’A=’, a, ’ B=’, b, ’C=’, c
Data Charting
In order to be able to chart the changes in a variable's value over time, you can use debug logging to output comma separated values, then load those into a spreadsheet application (like Excel).
If you choose Debugging Level 0 in the Debugger Preferences dialog, the debugger will still support debug logging, and the execution speed will not be affected by the debugger.
The following simple program uses math.nbc to calculate sine values for 0->90 degrees:
#include "math.nbc"
dseg segment
x uword
y uword
dseg ends
thread main
#pragma debuglog 'x,y'
set x, 0
loop:
SIN(x,y)
#pragma debuglog x, ',', y
add x, x, 1
brcmp LTEQ, loop, x, 180
endt
The debug log output of this program will start like this:
x,y
0,0
1,2
2,3
3,5
4,7
5,9
6,10
Use the Debuglog->"Copy Debuglog on Clipboard" menu, then paste the data into the spreadsheet application.
Make sure while importing you select comma separated values.
If you use Excel, you can import comma separated values by clicking on the "Paste Options" button after pasting the values, and choose "Use text Import Wizard...".
In the appearing dialog select "Delimited", and on the next page select "Comma". This will import the values properly.
Then use the charting feature of the program to create a graphical representation of the data you just imported.
One possible outcome with the data set from the program above will look like this:

The above chart was created using "XY (Scatter)" chart type, source data range of "Sheet1!$A$1:$B$181" and slightly modified gridline settings.
|
|
|