Advanced Topics and Random Thoughts

Floating Point Emulation

Floating point arithmetic is expensive. brickOS has built in support for it, so just use float as you normally would, but keep in mind that floating point math will often take 50 percent longer than integer math that would achieve the same results.

Don't be afraid of rough numbers. If you've attached a rotation sensor to your wheels and want to calculate velocity, then use integer math and forget about precision unless you absolutely need it. If you want to do a fine-grained division, or multiply by a fraction, then multiply the number first and then divide.

Random Number Generation

random() and srandom(int x) are available in brickOS. To use them, just call srandom(int x) at some point during your program startup. x is a "seed", which allows you to get the same sequence of numbers if you so desire (by passing the same seed) or to generate more truly "random" numbers by feeding in, for example, LIGHT_1. Be aware: unlike the "standard" implementation of these two functions, there is no "default" seed, so if you don't call srandom() at least once, random() will return the same number over and over again.

Brick information

When no programs are running, press the view button on your RCX to get a list of information. Each time you press view, you will get something. This is what you will see

Math

ints and such may be slightly smaller than you are used to in "real" programming. In specific, an int is only 16 bits long, so it will overflow at around 32K if signed and around 64K if unsigned.

Available Memory

Not that this means much until you've actually compiled code, but there is 32K available for the entire system. brickOS consumes about 19K of that, leaving you with about 13k.  This should be enough for most of your programs.

XEmacs

Make working at home exactly like working in the Sun Lab. Download XEmacs for Windows!

The Official brickOS

Once again, check out the Official LegOS HOWTO and the Official brickOS web site for more information.

There is a newsgroup dedicated to discussion of brickOS. It is available at
news://news.lugnet.com/lugnet.robotics.rcx.legos