
Page 193
your source code.
∗
For example, if you saved the source code above in a file called
/projects/HellolegOS.c
you would edit the
Makefile's
TARGET
like this:
TARGET=/projects/HellolegOS
Then type
make
at the command line. If everything is installed correctly, you'll end up with a
HellolegOS.srec
file in the same directory as the source file.
Trouble with Make
If you can't make
HellolegOS.c,
and you're starting to curse at your computer, take a deep
breath. legOS has a strong online community; people will help if you ask. The "Online
Resources" section of this chapter has pointers to helpful sites. One of the best things you
can do is look at LUGNET,
,
and search through the discussion
group archives for the particular problem you're having. There are at least as many
messages about configuring the legOS development tools as there are about actually
programming in legOS.
If you're using one of the online compilers,just copy the source into the web page and press the compile button. If there are no errors, you will get back an
.srec
file representing your compiled
legOS program.
Regardless of how the source file is compiled, you will then need to download the
.srec
file to the RCX, using either
nqc
or
firmdl
.
When the download is complete, your RCX will display the string "legOS" to indicate that legOS is running. To actually run the program you just wrote, press the
Run
button. The display will
show "Hello" for a second or so, then show two zeros. The left number shows the result returned from our
main()
function. Control has now returned to legOS; you can use the
On-Off
button
to switch the RCX off and on. When the RCX is on, you can press
Run
again to see the "Hello'' message again. Show your friends and family; they will be awed and inspired.
Function Reference
Once you've seen one RCX development environment, you've seen them all—to some degree, at least. If you've been reading through this book in order, you've probably noticed that NQC and
pbFORTH have similar commands but different syntax. Likewise, legOS has a set of functions that looks a lot like pbFORTH and
∗
Make sure you've edited
Makefile.common.
The
TOOLPREFIX
and
LEGOS_ROOT
lines should point to the appropriate directories on your system, as described in the comments. Make sure you put
a trailing slash on the
LEGOS_ROOT
directory.
Page 194
NQC, but the syntax and usage is slightly different. In this section, I'll describe the important functions of legOS and demonstrate how they are used.
There are, of course, different levels at which you can use legOS. I'll describe the "user-level" functions, meaning the functions you can call without knowing much about what's inside legOS. If
you're looking for even more power, the full source code of legOS is freely available; you can read it, debug it, or reprogram it as much as you'd like.
∗
Using the Display
legOS is surprisingly capable when it comes to managing the display on the RCX. Aside from just displaying numbers, you can ask legOS to approximate a text string using the display, as we did
in the
HellolegOS.c
example.
Numbers and symbols (rom/lcd.h)
Most of the useful display functions are defined in
rom/lcd.h.
The first function you should learn is
lcd_refresh()
:
void lcd_refresh(void)
This is the function that makes it all happen. After you call any other display function, you must call
lcd_refresh()
: to actually update the display.
Содержание 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 ...