Page 215 - The Unofficial Guide to Lego Mindstorms Robots
P. 215
204
In string.h
There are also functions for working with text strings:
char∗ st rcpy(char ∗dest, const char ∗src)
int strlen(const char ∗s)
int strcmp(const char ∗s1, const char ∗s2)
These are the standard string copy, length, and compare functions.
In time.h
You can retrieve the number of milliseconds since the RCX was powere d up using the sys_time variable. It's got a limited
range; the count res ets once every 49.7 days.
In rom/system.h
Your programs have tremendous power in legOS. You can turn the RC X off or even obliterate legOS and your program from
memory, using these functions:
void power_off(void)
This function puts t he RCX into its low power consumption "off" m ode.
void rom_reset(void)
This fun ctions resets the RCX to its out-of-the-box state, essentially blowing away legOS and your program. This is really only
l
usefu if you want to load some new firmware on the RCX. Use with care!
New Brains for Hank
In this section I'll present a longer example prog ram. It's a program for a slightly modified version of Hank, the robot from
te
Chap r 2, Hank, the Bumper Tank. All you need to do is mount the light sensor on the front of Hank and attach it to input 2.
This light sensor will allow Hank to search for light, while the bump ers allow him to avoid obstacles. Figure 10-2 shows a
picture of Hank, newly fitted with the light sensor.
Hank's n ew legOS program will be implemented us ing subsumption architecture. The basic structure of the program is similar
e
to th su bsumption architecture example presented in Chapter 9, RoboTag, a Game for Two Robots, although the syntax is
somewhat different.
Hank's light-seeking proclivity is produced by the interaction of three behaviors:
• cruise, as in the RoboTag program, constantly tries to move forward.
• seek_enlightenment() examines the valu es of the light sensor. If the values are decreasing, generally speaking, this
behavior attempts to turn Hank back toward the ligh t.