sensorwatcher.c File Reference

This file implements the wall follower thread. More...

#include <math.h>
#include "sensorwatcher.h"
#include "kh3moves.h"
#include "logger.h"

Include dependency graph for sensorwatcher.c:

Go to the source code of this file.

Typedefs

typedef enum pauseProcessRet_e pauseProcessRet

Enumerations

enum  pauseProcessRet_e { quitReq = -1, noPause = 0, paused = 1 }

Functions

double s2d (char sensorNum, ir_rec_t *ir_rec)
 Sensor value to distance converter Converts the integer value from the given sensor do distance in [mm] using the conversion tables.
void initRobotForLeftSide (void)
 Initialize values for the robot to run along the left wall.
void initRobotForRightSide (void)
 Initialize values for the robot to run along the right wall.
int robotInConvexCorner (ir_rec_t *ir_rec)
 Checks sensor values to tell if the robot is in a pointy convex corner.
int robotInCorner (ir_rec_t *ir_rec)
 Checks sensor values to tell if the robot is in a (open) convex corner If true, variable nearReflexVertex will be set to 0.
int robotNearReflexVertex (ir_rec_t *ir_rec)
 Checks sensor values to tell if the robot approaches a reflex vertex If true, variable nearReflexVertex will be set to 1.
int robotOverReflexEdge (ir_rec_t *ir_rec)
 Checks sensor values to tell if the robot has just passed a reflex vertex.
int kh3_arcSpeedWalk (double arcCenterDist, double speed, char guardSide)
 Let the robot walk an arc around a point at the given distance in the direction implied by guardSide.
pauseProcessRet processPauseReq ()
 Looks if a pause request has been issued (sensorWatcherPauseReq) and processes it.
void * sensorWatcher (void *arg)
 This thread is responsible running along the specified wall.
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.
int kh3_get_ir_prox (ir_rec_t *rec, knet_dev_t *dev)
 Gets all IR measure values from the robot.
void sensorWatcherWakeup (void)
 Remove the pause request (if set) and send a wakeup signal.
void sensorWatcherPause (void)
 Send a pause request to the sensor watcher and wait for it to reach the pause mode.
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

knet_dev_t * dsPic
 Khepera's status information device.
knet_dev_t * lMot
 Khepera's left motor.
knet_dev_t * rMot
 Khepera's right motor.
pthread_mutex_t sensorWatcherRunMutex = PTHREAD_MUTEX_INITIALIZER
 Mutex needed for the conditional variable.
pthread_cond_t sensorWatcherRun = PTHREAD_COND_INITIALIZER
 Sending a signal to this variable wakes the sensor watcher from pausing.
char sensorWatcherQuitReq = 0
 Set to 1 to end the sensor watcher thread.
char sensorWatcherPauseReq = 1
 Set to 1 to let the sensor watcher pause.
char sensorWatcherMode = THREAD_MODE_PAUSE
 Tells if the sensor watcher is running or pausing.
char * sensorWatcherConfigFile = DEFAULT_SENSOR_WATCHER_CONFIG_FILE
 Config file with sensor conversion table.
float linearScale [] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }
 Linear coefficients for sensor value scaling.
float constScale [] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }
 Constant coefficients for sensor value scaling.
char guardMode
 The guard's mode: running or watching.
char guardSide
 Tells if the guard is running along the left or right wall.
ir_rec_t ir_rec
 Infrared record for ALL LEDs.
char nearReflexVertex = 0
 1 if we are approaching a reflex vertex, 0 else
double distToReflexVertex = 0.0
 Last distance to the reflex vertex, as read from the sensors.
WINDOW * swLogWindow = NULL
 ncurses window, where the logging output will go to.
const double higherSpeed = 60.0
 Speed value higher than normal.
const double normalSpeed = 50.0
 Normal speed value.
const double lowerSpeed = 40.0
 Speed value lower than normal.
char sensWall90 = -1
 Sensor pointing to the wall side - 90°.
char sensWall45 = -1
 Sensor pointing to the wall side - 45°.
char sensWall0 = -1
 Sensor pointing forward on the wall side.
char sensOppo0 = -1
 Sensor pointing forward on the opposite side.
char sensOppo45 = -1
 Sensor pointing to the opposite side - 45°.


Detailed Description

This file implements the wall follower thread.

This file contains definitions needed to use the wall follower AKA sensor watcher.

Wall follower watches IR sensors and tries to keep a constant distance to the wall.

Version:
Id
sensorwatcher.c,v 1.31 2008/09/18 12:59:03 prokop Exp

Wall follower is a thread which keep the robot at constant distance to the wall.

Version:
Id
sensorwatcher.h,v 1.16 2008/09/18 12:59:03 prokop Exp

Definition in file sensorwatcher.c.


Typedef Documentation


Enumeration Type Documentation

Enumerator:
quitReq 
noPause 
paused 

Definition at line 87 of file sensorwatcher.c.


Function Documentation

void initRobotForLeftSide ( void   ) 

Initialize values for the robot to run along the left wall.

Definition at line 108 of file sensorwatcher.c.

void initRobotForRightSide ( void   ) 

Initialize values for the robot to run along the right wall.

Definition at line 118 of file sensorwatcher.c.

int kh3_arcSpeedWalk ( double  arcCenterDist,
double  speed,
char  guardSide 
)

Let the robot walk an arc around a point at the given distance in the direction implied by guardSide.

Parameters:
arcCenterDist distance to arc's center
speed speed for the inner wheel. Speed for the outer wheel will be calculated.
guardSide the side along which the robot is running. One of GUARD_SIDE_LEFT or GUARD_SIDE_RIGHT
Returns:
0 on success, or -1 on failure.

Definition at line 194 of file sensorwatcher.c.

int kh3_get_ir_prox ( ir_rec_t rec,
knet_dev_t *  dev 
)

Gets all IR measure values from the robot.

Parameters:
rec The structure storing all values
dev Khepera device we can ask for valus (dsPic)
Returns:
Number of bytes read from the robot, i.e. a positive value on success, or a negative value on failure

Definition at line 485 of file sensorwatcher.c.

pauseProcessRet processPauseReq (  ) 

Looks if a pause request has been issued (sensorWatcherPauseReq) and processes it.

This function will sleep until the pause request is removen and a signal (sensorWatcherRun) has been send.

Returns:
quitReq if quit was requested, noPause, if no pause was requested or paused if a pause has been performed

Definition at line 215 of file sensorwatcher.c.

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.

int robotInConvexCorner ( ir_rec_t ir_rec  ) 

Checks sensor values to tell if the robot is in a pointy convex corner.

If true, variable nearReflexVertex will be set to 0

Parameters:
ir_rec pointer to the struct with IR sensor values
Returns:
1 if the robot is in a pointy convex corner, 0 otherwise.

Definition at line 131 of file sensorwatcher.c.

int robotInCorner ( ir_rec_t ir_rec  ) 

Checks sensor values to tell if the robot is in a (open) convex corner If true, variable nearReflexVertex will be set to 0.

Parameters:
ir_rec pointer to the struct with IR sensor values
Returns:
1 if the robot is in a (open) convex corner, 0 otherwise.

Definition at line 146 of file sensorwatcher.c.

int robotNearReflexVertex ( ir_rec_t ir_rec  ) 

Checks sensor values to tell if the robot approaches a reflex vertex If true, variable nearReflexVertex will be set to 1.

Parameters:
ir_rec pointer to the struct with IR sensor values
Returns:
1 if the robot is near a reflex vertex, 0 otherwise

Definition at line 160 of file sensorwatcher.c.

int robotOverReflexEdge ( ir_rec_t ir_rec  ) 

Checks sensor values to tell if the robot has just passed a reflex vertex.

If true, variable nearReflexVertex will be set to 0

Parameters:
ir_rec pointer to the struct with IR sensor values
Returns:
1 if the robot passed by a reflex vertex, 0 otherwise.

Definition at line 174 of file sensorwatcher.c.

double s2d ( char  sensorNum,
ir_rec_t ir_rec 
) [inline]

Sensor value to distance converter Converts the integer value from the given sensor do distance in [mm] using the conversion tables.

Parameters:
sensorNum Sensor number whose value will be converted
ir_rec Pointer to the struct with IR measures from which we read the sensor value.
Returns:
Sensor value converted to millimeters, using conversion tables.

Definition at line 101 of file sensorwatcher.c.

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

float constScale[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }

Constant coefficients for sensor value scaling.

Definition at line 48 of file sensorwatcher.c.

double distToReflexVertex = 0.0

Last distance to the reflex vertex, as read from the sensors.

Definition at line 82 of file sensorwatcher.c.

knet_dev_t* dsPic

Khepera's status information device.

Khepera status device.

Definition at line 58 of file kh3moves.c.

char guardMode

The guard's mode: running or watching.

See Possible Guard Modes

Definition at line 136 of file guard.c.

char guardSide

Tells if the guard is running along the left or right wall.

See Guard's side

Definition at line 140 of file guard.c.

const double higherSpeed = 60.0

Speed value higher than normal.

Definition at line 59 of file sensorwatcher.c.

Infrared record for ALL LEDs.

Definition at line 54 of file sensorwatcher.c.

float linearScale[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }

Linear coefficients for sensor value scaling.

Definition at line 46 of file sensorwatcher.c.

knet_dev_t* lMot

Khepera's left motor.

Definition at line 60 of file kh3moves.c.

const double lowerSpeed = 40.0

Speed value lower than normal.

Definition at line 63 of file sensorwatcher.c.

char nearReflexVertex = 0

1 if we are approaching a reflex vertex, 0 else

Definition at line 80 of file sensorwatcher.c.

const double normalSpeed = 50.0

Normal speed value.

Definition at line 61 of file sensorwatcher.c.

knet_dev_t* rMot

Khepera's right motor.

Definition at line 62 of file kh3moves.c.

char sensOppo0 = -1

Sensor pointing forward on the opposite side.

Definition at line 74 of file sensorwatcher.c.

char sensOppo45 = -1

Sensor pointing to the opposite side - 45°.

Definition at line 76 of file sensorwatcher.c.

char* sensorWatcherConfigFile = DEFAULT_SENSOR_WATCHER_CONFIG_FILE

Config file with sensor conversion table.

Definition at line 43 of file sensorwatcher.c.

char sensorWatcherMode = THREAD_MODE_PAUSE

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 = PTHREAD_COND_INITIALIZER

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

Definition at line 38 of file sensorwatcher.c.

pthread_mutex_t sensorWatcherRunMutex = PTHREAD_MUTEX_INITIALIZER

Mutex needed for the conditional variable.

Definition at line 37 of file sensorwatcher.c.

char sensWall0 = -1

Sensor pointing forward on the wall side.

Definition at line 72 of file sensorwatcher.c.

char sensWall45 = -1

Sensor pointing to the wall side - 45°.

Definition at line 70 of file sensorwatcher.c.

char sensWall90 = -1

Sensor pointing to the wall side - 90°.

Definition at line 68 of file sensorwatcher.c.

WINDOW* swLogWindow = NULL

ncurses window, where the logging output will go to.

Definition at line 85 of file sensorwatcher.c.


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