guard.c File Reference

In this file we implement the control structures for a guard. More...

#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <string.h>
#include <pthread.h>
#include <libfg/capture.h>
#include <ncurses.h>
#include "guardmodes.h"
#include "kh3moves.h"
#include "frameconversions.h"
#include "picturedisplayer.h"
#include "sensorwatcher.h"
#include "blobtracker.h"
#include "batterywatcher.h"
#include "logger.h"
#include "brain.h"

Include dependency graph for guard.c:

Go to the source code of this file.

Defines

#define FG_WIDTH   176
 Frame width.
#define FG_HEIGHT   144
 Frame height.
#define FG_BRIGHTNESS   66
 Camera brightness.
#define FG_CONTRAST   15
 Camera contrast.
#define FG_PALETTE   VIDEO_PALETTE_RGB32
 Color palette.
#define DEFAULT_VIDEO_DEV_NAME   "/dev/v4l/video0"
 Default video device file name.
#define LEFTLOGFILE   "leftguard.log"
 Names for permanent log files depending on guards mode.
#define RIGHTLOGFILE   "rightguard.log"
 Names for permanent log files depending on guards mode.
#define UNDEFLOGFILE   "undefguard.log"
 Names for permanent log files depending on guards mode.

Functions

WINDOW * createNewWin (int height, int width, int yoff, int xoff, char *title, WINDOW **parentWindow)
 Creates new ncurses window with the given dimension, border and title.
void initializeWindows ()
 Initializes all output windows in ncurses manner.
void forceStop (int signal)
 Callback function for signals.
void toggleWatchToRun (void)
 Switches from the watching mode to running mode.
void toggleRunToWatch (void)
 Switches from running to watching mode.
void cmdStop (void)
 Stops all threads.
void cmdQuit (void)
 Called if user wants to exit this programm at all.
int cmdGuard (int withBrain)
 Starts what is needed to let the robot act as a left or right guard.
int cmdWatcherMode (void)
 Starts what is needed to let the robot act as a left guard in watcher mode.
int startAllThreads (void)
 Starts all threads we have specified.
int cmdToggleMode (void)
 Manually forces the robot from one mode to another.
void showHelp (void)
 Prints some help for the user.
int main (int argc, char *argv[])

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.
char * videoDeviceName = DEFAULT_VIDEO_DEV_NAME
 Video device for the USB camera on the robot.
char quitReq = 0
 program ends, if this is set to 1
pthread_mutex_t hsvFrameMutex = PTHREAD_MUTEX_INITIALIZER
 Mutex for accessing the hsvFrame.
pthread_mutex_t fgFrameMutex = PTHREAD_MUTEX_INITIALIZER
 Mutex for accessing the libfg frame.
FRAMEGRABBER * fg = NULL
 Frame grabber.
FRAME * frame = NULL
 Frame for the frame grabber.
bgr_frame_tbgrFrame = NULL
 Our BGR frame.
shsv_frame_thsvFrame = NULL
 Our HSV frame.
pthread_t pictureDisplayerThread = 0
 Identifier for the picture displayer thread.
pthread_t batteryWatcherThread = 0
 Identifier for the battery watcher thread.
pthread_t blobTrackerThread = 0
 Identifier for the blob tracker thread.
pthread_t sensorWatcherThread = 0
 Identifier for the sensor watcher thread.
pthread_t brainThread = 0
 Indentifier for the brain thread.
char guardMode = GUARD_MODE_UNDEF
 The guard's mode: running or watching.
char guardSide = GUARD_SIDE_UNDEF
 Tells if the guard is running along the left or right wall.
char doFollowBlob = 1
 should we follow the color blob or just watch it
config_t config
 configuration we parse from command line options
char sensorWatcherQuitReq
 Set to 1 to end the blob tracker thread.
char blobTrackerQuitReq
 Set to 1 to end the blob tracker thread.
char batteryWatcherQuitReq
 If set to 1, battery watcher will quit.
char pictureDisplayerQuitReq
 Set to 1 to end the blob tracker thread.
char brainQuitReq
 Set to 1 to end the thread.
char sensorWatcherPauseReq
 Set to 1 to let the blob tracker pause.
char blobTrackerPauseReq
 Set to 1 to let the blob tracker pause.
char sensorWatcherMode
 Set to 1 to let the blob tracker pause.
char blobTrackerMode
 Tells if the blob tracker is running or pausing.
WINDOW * brainWindow = NULL
 ncurses output windows
WINDOW * sensorWatcherBlobTrackerWindow = NULL
 wall follower's and blob tracker's output goes here
WINDOW * schedulerWindow = NULL
 scheduler status goes here
WINDOW * othersWindow = NULL
 everything else goes here
WINDOW * commandWindow = NULL
 here we can input something
WINDOW * pBrainWindow = NULL
 ncurses output parent windows (needed for refreshing)
WINDOW * pSensorWatcherBlobTrackerWindow = NULL
 wall follower's and blob tracker's output parent window
WINDOW * pSchedulerWindow = NULL
 scheduler status parent window
WINDOW * pOthersWindow = NULL
 parent window for others window
WINDOW * pCommandWindow = NULL
 parent window for command
struct blobTrackerArgs btArgs
 Structures with arguments for each thread.
struct brainArgs bArgs
 Structures with arguments for each thread.
struct pictureDisplayerArgs pdArgs
 Structures with arguments for each thread.
struct sensorWatcherArgs swArgs
 Structures with arguments for each thread.
struct batteryWatcherArgs bwArgs
 Structures with arguments for each thread.


Detailed Description

In this file we implement the control structures for a guard.

A guard is a process running on the Khepera III robot, which let the robot explore a polygon according to the "Two Guards Problem". The guard controls several independent threads:

Version:
Id
guard.c,v 1.32 2008/09/18 12:59:01 prokop Exp

Definition in file guard.c.


Define Documentation

#define DEFAULT_VIDEO_DEV_NAME   "/dev/v4l/video0"

Default video device file name.

Definition at line 72 of file guard.c.

#define FG_BRIGHTNESS   66

Camera brightness.

Definition at line 64 of file guard.c.

#define FG_CONTRAST   15

Camera contrast.

Definition at line 66 of file guard.c.

#define FG_HEIGHT   144

Frame height.

Definition at line 62 of file guard.c.

#define FG_PALETTE   VIDEO_PALETTE_RGB32

Color palette.

Definition at line 68 of file guard.c.

#define FG_WIDTH   176

Frame width.

Definition at line 60 of file guard.c.

#define LEFTLOGFILE   "leftguard.log"

Names for permanent log files depending on guards mode.

Definition at line 76 of file guard.c.

#define RIGHTLOGFILE   "rightguard.log"

Names for permanent log files depending on guards mode.

Definition at line 77 of file guard.c.

#define UNDEFLOGFILE   "undefguard.log"

Names for permanent log files depending on guards mode.

Definition at line 78 of file guard.c.


Function Documentation

int cmdGuard ( int  withBrain  ) 

Starts what is needed to let the robot act as a left or right guard.

The side condition must be set somewhere else.

Parameters:
withBrain set to true if brain thread should be started as well. If not set, sensor watcher will be started by default and run forever, since there is no brain to stop it.
Returns:
0 if all threads were started successfully, true else.

Definition at line 354 of file guard.c.

void cmdQuit ( void   ) 

Called if user wants to exit this programm at all.

It stops both motors and sets the exit variable

Definition at line 341 of file guard.c.

void cmdStop ( void   ) 

Stops all threads.

Definition at line 251 of file guard.c.

int cmdToggleMode ( void   ) 

Manually forces the robot from one mode to another.

Returns:
0 on success, 1 on failure

Definition at line 478 of file guard.c.

int cmdWatcherMode ( void   ) 

Starts what is needed to let the robot act as a left guard in watcher mode.

Returns:
0 if all threads were started successfully, true else.

Definition at line 379 of file guard.c.

WINDOW* createNewWin ( int  height,
int  width,
int  yoff,
int  xoff,
char *  title,
WINDOW **  parentWindow 
)

Creates new ncurses window with the given dimension, border and title.

Keep in mind, that the usable window area is one character smaller at each side, because the border is withhin the specified window. The window returned is a subwindow so you can use it without restrictions.

Parameters:
height window's height
width window's width
yoff Y-offset. Distance from the upper edge of the screen
xoff X-offset. Distance from the left edge of the screen
title Title which will be displayer over the window's upper border
parentWindow The reference to the parent window will be stored here may be NULL, in which case it will be ignored.
Returns:
Subwindow within window's borders.

Definition at line 188 of file guard.c.

void forceStop ( int  signal  ) 

Callback function for signals.

Right now, the only thing it does is halting the program immediately.

Parameters:
signal The signal which has been sent by the system

Definition at line 222 of file guard.c.

void initializeWindows (  ) 

Initializes all output windows in ncurses manner.

Keep in mind, that the output area is 2 characters smaller than defined, because we have a border drawn around the window area.

Definition at line 207 of file guard.c.

int main ( int  argc,
char *  argv[] 
)

Definition at line 541 of file guard.c.

void showHelp ( void   ) 

Prints some help for the user.

Definition at line 499 of file guard.c.

int startAllThreads ( void   ) 

Starts all threads we have specified.

Returns:
0 if all threads were started successfully, true otherwise

Definition at line 404 of file guard.c.

void toggleRunToWatch ( void   ) 

Switches from running to watching mode.

It halts the sensor watcher and starts the blob tracker.

Definition at line 243 of file guard.c.

void toggleWatchToRun ( void   ) 

Switches from the watching mode to running mode.

It halts the blob tracker and starts the sensor watcher.

Definition at line 233 of file guard.c.


Variable Documentation

struct brainArgs bArgs

Structures with arguments for each thread.

Definition at line 169 of file guard.c.

If set to 1, battery watcher will quit.

Definition at line 43 of file batterywatcher.c.

pthread_t batteryWatcherThread = 0

Identifier for the battery watcher thread.

Definition at line 126 of file guard.c.

Our BGR frame.

Definition at line 119 of file guard.c.

Tells if the blob tracker is running or pausing.

Values are defined in guardmodes.h

Definition at line 50 of file blobtracker.c.

Set to 1 to let the blob tracker pause.

To run the blob tracker again you have to send a signal via the condition variable blobTrackerRun

Definition at line 49 of file blobtracker.c.

Set to 1 to end the blob tracker thread.

Definition at line 48 of file blobtracker.c.

pthread_t blobTrackerThread = 0

Identifier for the blob tracker thread.

Definition at line 128 of file guard.c.

Set to 1 to end the thread.

Definition at line 46 of file brain.c.

pthread_t brainThread = 0

Indentifier for the brain thread.

Definition at line 132 of file guard.c.

WINDOW* brainWindow = NULL

ncurses output windows

brain's output goes here

Definition at line 150 of file guard.c.

Structures with arguments for each thread.

Definition at line 168 of file guard.c.

Structures with arguments for each thread.

Definition at line 172 of file guard.c.

WINDOW* commandWindow = NULL

here we can input something

Definition at line 154 of file guard.c.

configuration we parse from command line options

Definition at line 146 of file guard.c.

char doFollowBlob = 1

should we follow the color blob or just watch it

Indicates if we shoud activly follow the blob or just track it without movement.

Definition at line 143 of file guard.c.

knet_dev_t* dsPic

Khepera's status information device.

Khepera status device.

Definition at line 58 of file kh3moves.c.

FRAMEGRABBER* fg = NULL

Frame grabber.

Frame grabber which hides the whole V4L thing.

Definition at line 115 of file guard.c.

pthread_mutex_t fgFrameMutex = PTHREAD_MUTEX_INITIALIZER

Mutex for accessing the libfg frame.

Definition at line 94 of file guard.c.

FRAME* frame = NULL

Frame for the frame grabber.

The frame we get from the frame grabber.

Definition at line 117 of file guard.c.

char guardMode = GUARD_MODE_UNDEF

The guard's mode: running or watching.

See Possible Guard Modes

Definition at line 136 of file guard.c.

char guardSide = GUARD_SIDE_UNDEF

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

See Guard's side

Definition at line 140 of file guard.c.

Our HSV frame.

Definition at line 121 of file guard.c.

pthread_mutex_t hsvFrameMutex = PTHREAD_MUTEX_INITIALIZER

Mutex for accessing the hsvFrame.

Definition at line 92 of file guard.c.

knet_dev_t* lMot

Khepera's left motor.

Definition at line 60 of file kh3moves.c.

WINDOW* othersWindow = NULL

everything else goes here

Definition at line 153 of file guard.c.

WINDOW* pBrainWindow = NULL

ncurses output parent windows (needed for refreshing)

brain's output parent window

Definition at line 159 of file guard.c.

WINDOW* pCommandWindow = NULL

parent window for command

Definition at line 163 of file guard.c.

Structures with arguments for each thread.

Definition at line 170 of file guard.c.

Set to 1 to end the blob tracker thread.

Definition at line 40 of file picturedisplayer.c.

pthread_t pictureDisplayerThread = 0

Identifier for the picture displayer thread.

Definition at line 124 of file guard.c.

WINDOW* pOthersWindow = NULL

parent window for others window

Definition at line 162 of file guard.c.

WINDOW* pSchedulerWindow = NULL

scheduler status parent window

Definition at line 161 of file guard.c.

wall follower's and blob tracker's output parent window

Definition at line 160 of file guard.c.

char quitReq = 0

program ends, if this is set to 1

Definition at line 89 of file guard.c.

knet_dev_t* rMot

Khepera's right motor.

Definition at line 62 of file kh3moves.c.

WINDOW* schedulerWindow = NULL

scheduler status goes here

Definition at line 152 of file guard.c.

wall follower's and blob tracker's output goes here

Definition at line 151 of file guard.c.

Set to 1 to let the blob tracker pause.

To run the blob tracker again you have to send a signal via the condition variable blobTrackerRun

Definition at line 42 of file sensorwatcher.c.

Set to 1 to let the blob tracker pause.

To run the blob tracker again you have to send a signal via the condition variable blobTrackerRun

Definition at line 41 of file sensorwatcher.c.

Set to 1 to end the blob tracker thread.

Definition at line 40 of file sensorwatcher.c.

pthread_t sensorWatcherThread = 0

Identifier for the sensor watcher thread.

Definition at line 130 of file guard.c.

Structures with arguments for each thread.

Definition at line 171 of file guard.c.

char* videoDeviceName = DEFAULT_VIDEO_DEV_NAME

Video device for the USB camera on the robot.

Definition at line 86 of file guard.c.


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