Connects to the ACTS program, and uses an ArAction subclass to drive the robot towards the largest detected blob.
#include "Aria.h"
{
public:
enum State {
NO_TARGET,
TARGET,
};
~Chase(void);
bool setChannel(int channel);
State getState(void) { return myState; }
enum {
WIDTH = 160,
HEIGHT = 120
};
protected:
State myState;
int myChannel;
int myMaxTime;
};
ArAction(
"Chase",
"Chases the largest blob.")
{
myActs = acts;
myCamera = camera;
myChannel = 0;
myState = NO_TARGET;
setChannel(1);
myLastSeen.setToNow();
myMaxTime = 1000;
}
Chase::~Chase(void) {}
{
bool flag = false;
int numberOfBlobs;
int blobArea = 10;
double xRel, yRel;
myDesired.reset();
numberOfBlobs = myActs->getNumBlobs(myChannel);
if(numberOfBlobs != 0)
{
for(int i = 0; i < numberOfBlobs; i++)
{
myActs->getBlob(myChannel, i + 1, &blob);
{
flag = true;
largestBlob = blob;
}
}
myLastSeen.setToNow();
}
if (myLastSeen.mSecSince() > myMaxTime)
{
myState = NO_TARGET;
}
else
{
if(myState != TARGET) {
}
myState = TARGET;
}
if(myState == TARGET && flag == true)
{
xRel = (double)(largestBlob.
getXCG() - WIDTH/2.0) / (double)WIDTH;
yRel = (double)(largestBlob.
getYCG() - HEIGHT/2.0) / (double)HEIGHT;
{
if (-yRel > 0)
myCamera->tiltRel(1);
else
myCamera->tiltRel(-1);
}
{
myDesired.setDeltaHeading(0);
}
else
{
myDesired.setDeltaHeading(-xRel * 10);
else if (-xRel > 0)
myDesired.setDeltaHeading(10);
else
myDesired.setDeltaHeading(-10);
}
myDesired.setVel(200);
return &myDesired;
}
return &myDesired;
}
bool Chase::setChannel(int channel)
{
{
myChannel = channel;
return true;
}
else
return false;
}
{
}
else {
}
}
int main(int argc, char** argv)
{
{
return 1;
}
Chase chase(&acts, &vcc4);
{
}
{
}
keydriveAction.
deactivate();
ArLog::log(
ArLog::Normal,
"Running. Train ACTS to detect a color to drive towards an object, or use 'a' key to switch to keyboard driving mode.");
return 0;
}