sensorwatcher.h File Reference

#include <pthread.h>
#include <ncurses.h>
#include "guardmodes.h"
#include "macros.h"
#include "sensordefs.h"
#include "config.h"

Include dependency graph for sensorwatcher.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  sensorWatcherArgs
 Structure for thread's arguments. More...

Defines

#define SENSORWATCHERSLEEPCYCLE   70000
 Time to pause between subsequent walk through the main loop.
#define DEFAULT_SENSOR_WATCHER_CONFIG_FILE   "/etc/irsensors.conf"
 Default file name for the sensor watcher config file.

Functions

void * sensorWatcher (void *arg)
 This thread is responsible running along the specified wall.
double sensorToDistance (char sensorNum, ir_rec_t *ir_rec)
 Convert the sensor value we obtain from the robot to a distance (in [mm]).
int setSensorConversionValues (float linearCoeff[], float constCoeff[], int length)
 Sets the coefficients for our conversion functions.
int readSensorConversionValues (char *fileName, float linears[], float consts[], int len)
 Parameters for conversion table from a file.
void sensorWatcherPause (void)
 Send a pause request to the sensor watcher and wait for it to reach the pause mode.
void sensorWatcherWakeup (void)
 Remove the pause request (if set) and send a wakeup signal.
void sensorWatcherStop (void)
 Send a quit request and send a wakeup signal if the sensor watcher is in pause mode.
void sensorWatcherChangeSides (void)
 Changes the active side.

Variables

char sensorWatcherQuitReq
 Set to 1 to end the sensor watcher thread.
char sensorWatcherPauseReq
 Set to 1 to let the sensor watcher pause.
char sensorWatcherMode
 Tells if the sensor watcher is running or pausing.
char * sensorWatcherConfigFile
 Config file with sensor conversion table.
pthread_cond_t sensorWatcherRun
 Sending a signal to this variable wakes the sensor watcher from pausing.
pthread_mutex_t sensorWatcherRunMutex
 Mutex needed for the conditional variable.


Define Documentation

#define DEFAULT_SENSOR_WATCHER_CONFIG_FILE   "/etc/irsensors.conf"

Default file name for the sensor watcher config file.

Definition at line 42 of file sensorwatcher.h.

#define SENSORWATCHERSLEEPCYCLE   70000

Time to pause between subsequent walk through the main loop.

Definition at line 39 of file sensorwatcher.h.


Function Documentation

int readSensorConversionValues ( char *  fileName,
float  linears[],
float  consts[],
int  len 
)

Parameters for conversion table from a file.

The format of the file is two float value per line, one line for each sensor. The first value ist the linear factor, the second the constant factor.

Parameters:
fileName The name of the config file
linears Array where linear factors will be stored
consts Array where constant factors will be stored
len Number of elements in linears and consts
Returns:
-1 if an error occured or number of lines read from file. We read at most len.

Definition at line 456 of file sensorwatcher.c.

double sensorToDistance ( char  sensorNum,
ir_rec_t ir_rec 
)

Convert the sensor value we obtain from the robot to a distance (in [mm]).

Attention! Depending on the surface's reflectivity sensor values above 4000 are not relyable any more. It also says that distances below 20mm do not have to reflect the real distance!

Parameters:
sensorNum sensor number, as defined in constants
ir_rec pointer to the structure containing latest sensor values
Returns:
the distance from the the sensor to the next obstale.

void* sensorWatcher ( void *  arg  ) 

This thread is responsible running along the specified wall.

Parameters:
arg Arguments for this thread. Currently unused.
Returns:
Nothing.

Definition at line 244 of file sensorwatcher.c.

void sensorWatcherChangeSides ( void   ) 

Changes the active side.

Keep in mind, that the robot must be stopped before, or you will get unpredictable behaviour. This also will not rotate the robot.

Definition at line 538 of file sensorwatcher.c.

void sensorWatcherPause ( void   ) 

Send a pause request to the sensor watcher and wait for it to reach the pause mode.

Definition at line 521 of file sensorwatcher.c.

void sensorWatcherStop ( void   ) 

Send a quit request and send a wakeup signal if the sensor watcher is in pause mode.

Definition at line 528 of file sensorwatcher.c.

void sensorWatcherWakeup ( void   ) 

Remove the pause request (if set) and send a wakeup signal.

It also restores robot's previous orientation.

Definition at line 514 of file sensorwatcher.c.

int setSensorConversionValues ( float  linearCoeff[],
float  constCoeff[],
int  length 
)

Sets the coefficients for our conversion functions.

Our sensor values cannot be used directly, because they differ a lot. We have to apply a value mapping function

\[ \frac{a}{\sqrt{x}} + b , \]

where $x$ is our sensor value. If you specify more or less coefficients than there are sensors, you will get a warning message.

Parameters:
linearCoeff an array with linear coefficients for all sensors
constCoeff an array with constant coefficients for all sensors
length number of coefficients in both arrays
Returns:
0 if number of coefficients does not match, 1 else.

Definition at line 440 of file sensorwatcher.c.


Variable Documentation

Config file with sensor conversion table.

Definition at line 43 of file sensorwatcher.c.

Tells if the sensor watcher is running or pausing.

Values are defined in guardmodes.h

Definition at line 42 of file sensorwatcher.c.

Set to 1 to let the sensor watcher pause.

To run the sensor watcher again you have to send a signal via the condition variable sensorWatcherRun

Definition at line 41 of file sensorwatcher.c.

Set to 1 to end the sensor watcher thread.

Definition at line 40 of file sensorwatcher.c.

pthread_cond_t sensorWatcherRun

Sending a signal to this variable wakes the sensor watcher from pausing.

Definition at line 38 of file sensorwatcher.c.

pthread_mutex_t sensorWatcherRunMutex

Mutex needed for the conditional variable.

Definition at line 37 of file sensorwatcher.c.


Generated on Sun Sep 28 21:20:01 2008 for Guard by  doxygen 1.5.6