NXT Functions Datalog

From ROBOTC API Guide
Jump to: navigation, search


The NXT has a data logging capability similar to that found in the RCX. This capability allows you to save variable and sensor values in a log during program execution. This is useful for collecting data during measurements. It is also useful for program debugging where you may want to analyze the value of a particular variable after a program has been run. There’s room for storage of about 5,000 data points.

The data points are stored into RAM. They can be subsequently copied to a NXT flash file. They are not immediately stored into a flash file during program execution because writing to a file in the flash memory can take 3 to 6 milliseconds which could disturb performance of the user application.

There are utilities within the ROBOTC IDE to upload the datalog and display in a PC window. These can be found under the “debug display” and the “NXT -> Files Management” display.


Color Key
Function:
Variable:


AddToDatalog

void AddToDatalog(const long data)
(void) Adds an entry to the datalog.
Parameter Explanation Data Type
data An integer or long variable to print to datalog long
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
}


bHideDataFiles

word bHideDataFiles
(word) Boolean flag to indicate whether data files should be hidden or shown in the NXT GUI. Note that this is defined as a word but is treated as a bool.
bHideDataFiles = true;   // data files will be HIDDEN and NOT SHOW on NXT GUI   
bHideDataFiles = false;  // data files will be SHOWN on NXT GUI


nDatalogSize

word nDatalogSize
(word) 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'


nMaxDataFiles

word nMaxDataFiles
(word) 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")


nMaxDataFileSize

word nMaxDataFileSize
(word) 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")


nUsedDatalogBytes

const word nUsedDatalogBytes
(word) 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!)
}


SaveNxtDatalog

void SaveNxtDatalog()
(void) 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