
Page 199
The
dir_write()
function does not work in the March 30, 1999 build of legOS 0.1.7.
Two functions are provided for reading data from the IR port:
size_t dir_read(void
∗
buf, size_t len)
This method reads
len
bytes of data into the supplied buffer. It returns the number of bytes read or
-1
if there is an error.
void dir_fflush(void)
The IR input is buffered, which means incoming data is placed in a buffer. When it fills up, it is made available to
dir_read()
. To force the contents of the input buffer to be available to
dir_read()
, first call
dir_fflush()
.
One of the legOS demos is
tm-and-ir.c.
This program listens for incoming IR data and shows it on the RCX's display. You can type into a terminal emulator on your PC and see the data show up
on the display.
Multitasking in legOS (unistd.h and sys/tm.h)
Multiple tasks are supported in legOS through a reduced version of the standard Unix libraries. The basic idea is to set up some number of tasks using the
execi()
function. Then the task
manager itself must be started with a call to
tm_start()
.
pid_t execi(int (
∗
code_start)(int, char
∗∗
), int argc, char
∗∗
argv,
priority_tpriority, size_t stack_size)
This function starts the task described by
code_start
. Don't worry about the nasty-looking syntax above; all you have to do is pass the name of a function. You can pass information to the task
using the
argc
and
argv
parameters. The new task has the given priority and stack size. Lower priorities take precedence over higher priorities. In general, you can pass 0 for the priority and
DEFAULT_STACK_SIZE
as the stack size. This function returns a process identification number (PID). You can stop a task, as you'll see later, using this number.
If the stack size you pass to
execi()
is too small, all sorts of weird behavior results. If your program crashes, this is one of the first things you should check.
Remember, a function's return addresses and automatic variables (declared in the scope of the function) are stored on the stack. If you have many levels of function calls, or
many automatic variables, or large arrays as automatic variables, you may overrun your stack.
Page 200
void tm_start(void)
Use this function to start up the task manager.
Once the task manager is running, new tasks can be started (with
execi()
), and running tasks can be stopped with this function:
void kill(pid_t pid)
Use this function to stop the task represented by
pid
.
You can suspend tasks for a given amount of time with the following two functions:
unsigned int sleep(unsigned int sec)
This function suspends execution for the given number of seconds.
unsigned int msleep(unsigned int msec)
This function suspends execution for the given number of milliseconds (ms).
Содержание 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 ...