
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)
Содержание MINDSTORMS Robots
Страница 22: ...Page 18 The back tread wheels are anchored to the shafts with the 16t gears ...
Страница 23: ...Page 19 Page 20 Next start building support for the drive motors ...
Страница 25: ...Page 22 Attach the motor wires to output A and output C Next build the platform for the front bumpers ...
Страница 26: ...Page 23 The touch sensors are attached only by the shaft that runs through them ...
Страница 41: ...Page 41 ...
Страница 43: ...Next build the support for the light sensor ...
Страница 80: ...Page 85 Make sure the bump on the long pin is up against the 4u beam ...
Страница 82: ......
Страница 84: ...Page 89 ...
Страница 85: ...Step 14 is similar to Step 11 take a deep breath and go slowly ...
Страница 86: ...Page 90 Grabber Arm In Step 17 the half bushings go between the center block and the cams pear shaped pieces ...
Страница 87: ...Page 91 ...
Страница 88: ...Page 92 Make sure that the two sides are at the same angle They should mirror each other ...
Страница 89: ...Page 93 Page 94 ...
Страница 90: ...Structural Support Page 95 ...
Страница 91: ...Idler Wheel Page 96 ...
Страница 92: ...Page 97 Drive Motor ...
Страница 93: ...While you re putting the motor in hold on to the worm gear so it doesn t slip off Page 98 ...
Страница 94: ...Grabber Arm Motor ...
Страница 95: ...Page 99 ...
Страница 96: ...Page 100 RCX Attach the RCX on both sides as shown Page 101 ...
Страница 158: ......
Страница 159: ...Page 175 The 16t gears are nestled inside the tread wheels ...
Страница 160: ...Page 176 ...
Страница 161: ...Page 177 Attach the motors to output A and output C as shown Page 178 ...
Страница 162: ...The light sensor which is mounted on the bumper is attached to input 2 The touch sensor goes on input 1 Page 179 ...