
Page 142
Finally, as an added bonus, the average value is shown on the RCX's display:
threshold @ showValue
The average value,
threshold
, is used in the
seek
word to find a dark object to pick up.
seek
drives forward until the light sensor returns a reading that is 3 less than the average:
BEGIN 2 sensorValue threshold @ 3 - < UNTIL
Debugging
When you're writing your own programs, there are two things you should keep in mind when you are debugging:
1. The interactive nature of the pbFORTH interpreter can really help. You can, for example, make changes in a word by redefining it. With legOS (see Chapter 10), by contrast, you'd have to
compile and download a whole new version of your software. With pbFORTH, you can simply make new definitions for the words that aren't working.
∗
Furthermore, you can interactively test every word in your program. This makes it easy to drill down from the higher layers to the lower layers of your program to identify problems. Any
word that is defined can be interactively tested. This is powerful medicine indeed.
2. On the other hand, you need to be very careful about endless loops. If you do get stuck executing an endless loop, there's no way to stop pbFORTH short of removing the batteries. In this case,
you will have to use your firmware download utility to reload pbFORTH.
If you entered all of the Minerva source code, you can interactively test any of its words. For example, to show a number on the display, do something like this:
RCX_INIT
ok
42 showValue
ok
To pause for half a second, you could do this:
5 sleep
ok
To test out the
calibrate
word, try this:
initialize
ok
∗
Interestingly, new definitions don't replace the old ones, they just mask them out. If you want to return to an earlier definition, You should use the
MARKER
word. See the pbFORTH web site for details.
Содержание 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 ...