Page 180 - The Unofficial Guide to Lego Mindstorms Robots
P. 180
169
only upload fifty datalog values at a time. If you have larger datalog, it must be uploaded in pieces.
The relevant Spirit.ocx function is UploadData log, which t akes a starting index and a length. The first (zero-th) item of the
datalog contains the length of the datalog. It's the first th ing SaveDatalog reads:
data = .Upload Datalog(0, 1)
length = data(2, 0) -1
T he actual data length is one l ess than the reported length, because the zeroth item is not a data point.
T he data returned from UploadDatalog is an array. Each datalog item is represented by three numbers. The first two
numbers indicate the source and number of the value; source and number have exactly the same meaning here as they do for
Poll. The third num ber is the actual value stored in the datalog.
SaveDatalog writes the source, number, and value for each datalog item out to a text file. Each line of the text file
represents one item from the datalog. On each lin e, the source, number, and value of the item are separated by commas. This
example interprets the source of each value, then converts it to a descriptive string before writing it out to the file. The output
file will look something like this (depending, of course, on the contents of the datalog):
Variable, 1, 2
Timer, 0, 543
Variable, 2, 8
Variable, 8, 368
Sensor value, 1, 33
Watch, 0, 7
A plain text file of comma-separated values is usually pretty easy to import into a spreadsheet or statistical analysis program.
You can use your robot to gather data, use this example program to upload it to your PC, and then use some other program to
analyze or graph the data. Some people have built optical scanners based on RIS using these techniques.
The example is compris ed of three parts. The SaveDatalog subroutine does most of the work. It uses the min function to
calculate a minimum and the getTypeString function to convert the datalog item source number to a descriptive string:
Sub SaveDatalog(filname As String)
Dim data As Variant
Dim index, length, stepSize As Integer
Dim line As String
With DummySpiritForm.Spirit1