Robot Software


Introduction

The software for R4 is written in C-language.  My main aim with R4's software was to make it modular.  I wanted to be able to take any part of the software and have it run on separate computers, if necessary.  To achieve this, each of the software modules runs as a separate program and sends data to other modules by reading and/or writing to "named pipes" (these are special file structures within unix which act as funnels where one or more programs may write data to the pipe and one program reads data from the pipe).  Data written into a named pipe on one computer may be sent to a named pipe on another computer, thus, allowing the program modules to reside on different computers.

A central control program (r4d) is used to prioritise some of the inter-module communication.  This is also the "cognitive thought" of R4.  Most of the decision logic occurs within this program.  All the other programs (modules) are designed to perform specific tasks.  If you look at the diagram of the software (77Kbytes), you will see how the different modules (separate programs) communicate with each other.  In the diagram, the green and blue arrows represent the named pipes.  Although the disgram shows all data passing though the control program (r4d), some modules pass instructions directly to others.  For example, the voice module passes instructions to the face module to allow for mouth movements.

For copies of the current source code, please check the source code directory.  Remember that I am still (slowly) working on R4's software so changes will happen from time to time.

Below are discussions of the running envronment and each of the modules...


The Program Environment

The computer on R4 should have the Linux operating system installed.  Just about any version will do.  As I used a fairly small hard disk (100MB), I had to customise the install carefully.  You will need a base OS with some basic networking (if you use the LAN card - which is advisable) and the VGA libraries to allow for joystick control.  I used the PC speaker sound driver for the "sound" module.

The control porgram (r4d) communicates with the other modules by writing or reading single-line text commands to or from the named pipe associated with each of the other modules.  The named pipes associated with each module are:

voice voice_pipe
sound sound_pipe
face face_pipe
drive drive_pipe
commandcommand_pipe
joystickjoystick_pipe
sensor sensor_pipe
Two environment variables are used for the location of the modules (programs) and named pipes.  These are:
Variable Default Value
R4_BINARIES /usr/local/bin/r4
R4_LIB /usr/local/lib/r4
The programs (modules) are compiled (make all) and then installed into $R4_BINARIES.  Each of the named pipes will need to be created in the $R4_LIB directory with the command:
mknod module_pipe p


r4d

The name is short for "R4 daemon".  This is the main controling program for R4.  It reads from the input modules (command, joystick and sensor) and writes to the other modules.  A good deal of the decision-making is done withing this program. 

When the Control program (r4d) starts, it forks and and the parent dies (ie. it runs in background - as a daemon).  The existence of each of the named pipes is tested and if it exists, is opened in the following ways:

voice_pipe output append
sound_pipe output append
face_pipe output append
drive_pipe output append
command_pipe input
joystick_pipe input
sensor_pipe input
The other modules are then spawned (started as separate processes).

The input pipes are read in the order "command", "sensor" then "joystick", with a very short time-out (<100ms).  Data read from the pipes is in the form:

Cxxxxxxxxxxxxxxx
where "C" is a 1 byte command and "xxxxxxxxxxxxxxx" is a variable parameter string defined by the type of command.  The input is always terminated by an EOL (^J) character.  This means it can be read with standard library routines such as fgets().  Commands to the output pipes are of the same format.


command

This is the command interpretor. 


joystick

This module checks for a joystick and, if connected, sends motion and arm-movement commands. 


sensor


drive

This module controls R4's motors.  It drive the wheels and controls the arm. 


face

This module displays a face on the 6-inch colour monitor.  It allows for facial expression and mouth movement (for realistic voice). 


sound

This module plays ".wav" and ".au" audio files for sound effects.  All ".au" files must be stored in the directory /usr/local/sound/audio and all ".wav" file must be stored in /usr/local/sound/wave.  This program reads a "p" (play) command from "sound_pipe" and plays a sound file out the speaker.  The full sound line format is:
ptsoundfile
where "t" is the file type ("a" = audio, "w" = wave).  For example, the command:
pawhistle
will play the audio file "/usr/local/sound/audio/whistle.au".


voice


If you need more details, please mail me (Gary Hoggard).
Last updated on 19th May, 2000