
Page 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
UploadDatalog
, which takes a starting index and a length. The first (zero-th) item of the datalog contains the length of the datalog. It's the first thing
SaveDatalog
reads:
data = .UploadDatalog(0, 1)
length = data(2, 0) -1
The actual data length is one less than the reported length, because the zeroth item is not a data point.
The 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 number 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 line, 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 comprised 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
Page 170
' Open the output file.
out = FreeFile
open filename For Output As #out
.InitComm
' First get item zero, which describes the length of the datalog.
data = .UploadDatalog(0, 1)
length = data(2, 0) - 1
' Now upload 50 items at a time.
index = 0
While (index < length)
' Find the smaller of the remaining items or 50.
stepSize = min(length - index, 50)
Summary of Contents for MINDSTORMS Robots
Page 22: ...Page 18 The back tread wheels are anchored to the shafts with the 16t gears ...
Page 23: ...Page 19 Page 20 Next start building support for the drive motors ...
Page 26: ...Page 23 The touch sensors are attached only by the shaft that runs through them ...
Page 41: ...Page 41 ...
Page 43: ...Next build the support for the light sensor ...
Page 80: ...Page 85 Make sure the bump on the long pin is up against the 4u beam ...
Page 82: ......
Page 84: ...Page 89 ...
Page 85: ...Step 14 is similar to Step 11 take a deep breath and go slowly ...
Page 87: ...Page 91 ...
Page 88: ...Page 92 Make sure that the two sides are at the same angle They should mirror each other ...
Page 89: ...Page 93 Page 94 ...
Page 90: ...Structural Support Page 95 ...
Page 91: ...Idler Wheel Page 96 ...
Page 92: ...Page 97 Drive Motor ...
Page 93: ...While you re putting the motor in hold on to the worm gear so it doesn t slip off Page 98 ...
Page 94: ...Grabber Arm Motor ...
Page 95: ...Page 99 ...
Page 96: ...Page 100 RCX Attach the RCX on both sides as shown Page 101 ...
Page 158: ......
Page 159: ...Page 175 The 16t gears are nestled inside the tread wheels ...
Page 160: ...Page 176 ...
Page 161: ...Page 177 Attach the motors to output A and output C as shown Page 178 ...