blobtracker.c File Reference

This file implements functions we need to let the robot recognize a color blob and follow it. More...

#include <korebot/korebot.h>
#include <libfg/capture.h>
#include "kh3moves.h"
#include "blobtracker.h"
#include "blob.h"
#include "logger.h"

Include dependency graph for blobtracker.c:

Go to the source code of this file.

Functions

void followBlob (blob_t *blob, const shsv_frame_t *frame)
 Computes a rotation angle needed to center the given blob in the picture and rotate the robot.
void * blobTracker (void *arg)
 This thread is responsible for tracking the color blob and moving the robot to center the blob in its view area.
void blobTrackerPause (void)
 Send a pause request to the blob tracker and wait for it to reach the pause mode.
void blobTrackerWakeup (void)
 Remove the pause request (if set) and send a wakeup signal.
void blobTrackerStop (void)
 Send a quit request and send a wakeup signal if the blob tracker is in pause mode.
void blobTrackerSaveOrientation (void)
 Saves the current wheel positions to restore the robot's orientation later.
void blobTrackerRestoreOrientation (void)
 Restores the robot's orientation based on previously stored values, see blobTrackerSaveOrientation().

Variables

pthread_mutex_t blobTrackerRunMutex = PTHREAD_MUTEX_INITIALIZER
 Mutex needed for the conditional variable.
pthread_cond_t blobTrackerRun = PTHREAD_COND_INITIALIZER
 Sending a signal to this variable wakes the blob tracker from pausing.
WINDOW * btLogWindow = NULL
 ncurses window, where the logging output will go to.
char blobTrackerQuitReq = 0
 Set to 1 to end the blob tracker thread.
char blobTrackerPauseReq = 1
 Set to 1 to let the blob tracker pause.
char blobTrackerMode = THREAD_MODE_PAUSE
 Tells if the blob tracker is running or pausing.
char blobTrackerSearchOrFollow = BLOBTRACKER_FOLLOW
 Tells us, if the blob tracker actively searches for a blob or simply follows an existing blob.
char guardMode
 The guard's mode: running or watching.
char guardSide
 Tells if the guard is running along the left or right wall.
pthread_mutex_t hsvFrameMutex
 Mutex for accessing the hsvFrame.
pthread_mutex_t fgFrameMutex
 Mutex for accessing the libfg frame.
FRAMEGRABBER * fg
 Frame grabber which hides the whole V4L thing.
FRAME * frame
 The frame we get from the frame grabber.
shsv_frame_thsvFrame
 Our HSV frame.
bgr_frame_tbgrFrame
 Our BGR frame.
char doFollowBlob
 Indicates if we shoud activly follow the blob or just track it without movement.
long lMotOldPos = 0
 Variables for saving and restoring the robot's orientation.
long rMotOldPos = 0
 Saved position for right wheel.


Detailed Description

This file implements functions we need to let the robot recognize a color blob and follow it.

Blob tracker is implemented as a thread.

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

Definition in file blobtracker.c.


Function Documentation

void* blobTracker ( void *  arg  ) 

This thread is responsible for tracking the color blob and moving the robot to center the blob in its view area.

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

Definition at line 95 of file blobtracker.c.

void blobTrackerPause ( void   ) 

Send a pause request to the blob tracker and wait for it to reach the pause mode.

Definition at line 192 of file blobtracker.c.

void blobTrackerRestoreOrientation ( void   ) 

Restores the robot's orientation based on previously stored values, see blobTrackerSaveOrientation().

This method blocks, until the previous position is restored.

< Difference between both wheel positions

< Current (new) position for left wheel

< Current (new) position for right wheel

< Intermediate position for left wheel while trying to reach the old position

< Intermediate position for right wheel while trying to reach the old position

Definition at line 225 of file blobtracker.c.

void blobTrackerSaveOrientation ( void   ) 

Saves the current wheel positions to restore the robot's orientation later.

Keep in mind, that the robot should have stopped before, to get reliable values.

Definition at line 219 of file blobtracker.c.

void blobTrackerStop ( void   ) 

Send a quit request and send a wakeup signal if the blob tracker is in pause mode.

Definition at line 206 of file blobtracker.c.

void blobTrackerWakeup ( void   ) 

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

Definition at line 199 of file blobtracker.c.

void followBlob ( blob_t blob,
const shsv_frame_t frame 
)

Computes a rotation angle needed to center the given blob in the picture and rotate the robot.

Parameters:
blob The blob we will center in the picture
frame the picture frame in which we want to center the blob. We need it, because it holds the information about its width.

Definition at line 72 of file blobtracker.c.


Variable Documentation

Our BGR frame.

Definition at line 94 of file camServer.c.

char blobTrackerMode = THREAD_MODE_PAUSE

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

Sending a signal to this variable wakes the blob tracker from pausing.

Definition at line 37 of file blobtracker.c.

pthread_mutex_t blobTrackerRunMutex = PTHREAD_MUTEX_INITIALIZER

Mutex needed for the conditional variable.

Definition at line 36 of file blobtracker.c.

char blobTrackerSearchOrFollow = BLOBTRACKER_FOLLOW

Tells us, if the blob tracker actively searches for a blob or simply follows an existing blob.

See Search or follow mode for blob tracker for a list of valid modes. The intended usage is

  • Brain sets the mode to search and revives this blob tracker thread
  • Blob tracker searches for a blob, finds it, stops and goes to the transient search2follow mode.
  • The previously found blob is centered and blob tracker changes to the follow mode
  • Brain, who monitors the blob tracker mode, tells the other robot to proceed.

Definition at line 52 of file blobtracker.c.

WINDOW* btLogWindow = NULL

ncurses window, where the logging output will go to.

Definition at line 40 of file blobtracker.c.

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

Definition at line 132 of file camServer.c.

FRAMEGRABBER* fg

Frame grabber which hides the whole V4L thing.

Definition at line 90 of file camServer.c.

pthread_mutex_t fgFrameMutex

Mutex for accessing the libfg frame.

Definition at line 94 of file guard.c.

FRAME* frame

The frame we get from the frame grabber.

Definition at line 92 of file camServer.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.

Our HSV frame.

Definition at line 121 of file guard.c.

pthread_mutex_t hsvFrameMutex

Mutex for accessing the hsvFrame.

Definition at line 92 of file guard.c.

long lMotOldPos = 0

Variables for saving and restoring the robot's orientation.

Saved position for left wheel

Definition at line 44 of file blobtracker.c.

long rMotOldPos = 0

Saved position for right wheel.

Definition at line 45 of file blobtracker.c.


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