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)
{
argParser.loadDefaultArguments();
{
return 1;
}
Chase chase(&acts, &vcc4);
if (!simpleConnector.connectRobot(&robot))
{
}
{
}
vcc4.init();
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;
}
bool setAbsoluteMaxTransVel(double maxVel)
Sets the robot's absolute maximum translational velocity.
Definition: ArRobot.cpp:2144
Communicate with ACTS.
Definition: ArACTS.h:89
Perform actions when keyboard keys are pressed.
Definition: ArKeyHandler.h:65
Base class for actions.
Definition: ArAction.h:63
@ Terse
Use terse logging.
Definition: ArLog.h:61
Legacy connector for robot and laser.
Definition: ArSimpleConnector.h:51
bool comInt(unsigned char command, short int argument)
Sends a command to the robot with an int for argument.
Definition: ArRobot.cpp:5634
static void setKeyHandler(ArKeyHandler *keyHandler)
Sets the key handler, so that other classes can find it using getKeyHandler()
Definition: Aria.cpp:624
void addRangeDevice(ArRangeDevice *device)
Adds a rangeDevice to the robot's list of them, and set the ArRangeDevice object's robot pointer to t...
Definition: ArRobot.cpp:5757
static void exit(int exitCode=0)
Shutdown all Aria processes/threads, call exit callbacks, and exit the program.
Definition: Aria.cpp:367
virtual void deactivate(void)
Deactivate the action.
Definition: ArAction.cpp:115
static void log(LogLevel level, const char *str,...)
Log a message, with formatting and variable number of arguments.
Definition: ArLog.cpp:93
A class for the acts blob.
Definition: ArACTS.h:36
Action for going straight at a constant velocity.
Definition: ArActionConstantVelocity.h:37
int getYCG(void)
Gets the Y Center of Gravity of the blob.
Definition: ArACTS.h:48
bool addKeyHandler(int keyToHandle, ArFunctor *functor)
This adds a keyhandler, when the keyToHandle is hit, functor will fire.
Definition: ArKeyHandler.cpp:144
Contains values returned by ArAction objects expressing desired motion commands to resolver.
Definition: ArActionDesired.h:225
virtual const char * getName(void) const
Gets the name of the action.
Definition: ArAction.cpp:51
static double fabs(double val)
Finds the absolute value of a double.
Definition: ariaUtil.h:601
virtual bool isActive(void) const
Returns whether the action is active or not.
Definition: ArAction.cpp:105
static void init(SigHandleMethod method=SIGHANDLE_THREAD, bool initSockets=true, bool sigHandleExitNotShutdown=true)
Initialize Aria global data struture and perform OS-specific initialization, including adding OS sign...
Definition: Aria.cpp:128
Central class for communicating with and operating the robot.
Definition: ArRobot.h:82
Parse and store program command-line arguments for use by other ARIA classes.
Definition: ArArgumentParser.h:64
static void logOptions(void)
Logs all the options for the program (Calls all the callbacks added with addLogOptionsCB())
Definition: Aria.cpp:794
Keep track of recent sonar readings from a robot as an ArRangeDevice.
Definition: ArSonarDevice.h:51
virtual void activate(void)
Activate the action.
Definition: ArAction.cpp:110
virtual ArActionDesired * fire(ArActionDesired currentDesired)=0
Fires the action, returning what the action wants to do.
bool openPort(ArRobot *robot, const char *host="localhost", int port=5001)
Opens the connection to ACTS.
Definition: ArACTS.cpp:56
Functor for a global function with 1 parameter.
Definition: ArFunctor.h:679
bool addAction(ArAction *action, int priority)
Adds an action to the list with the given priority.
Definition: ArRobot.cpp:3278
@ SOUNDTOG
int, AmigoBot (old H8 model) specific, enable(1) or diable(0) sound
Definition: ArCommands.h:125
static bool parseArgs(void)
Parses the arguments for the program (calls all the callbacks added with addParseArgsCB())
Definition: Aria.cpp:759
This action will use the keyboard arrow keys for input to drive the robot.
Definition: ArActionKeydrive.h:37
static void sleep(unsigned int ms)
Sleep for the given number of milliseconds.
Definition: ariaUtil.cpp:151
@ Normal
Use normal logging.
Definition: ArLog.h:62
A class for time readings and measuring durations.
Definition: ariaUtil.h:1001
Action to limit the backwards motion of the robot based on range sensor readings.
Definition: ArActionLimiterBackwards.h:40
void run(bool stopRunIfNotConnected, bool runNonThreaded=false)
Starts the instance to do processing in this thread.
Definition: ArRobot.cpp:255
@ NUM_CHANNELS
Number of channels there are.
Definition: ArACTS.h:128
void attachKeyHandler(ArKeyHandler *keyHandler, bool exitOnEscape=true, bool useExitNotShutdown=true)
Attachs a key handler.
Definition: ArRobot.cpp:6641
@ ENABLE
int, enable (1) or disable (0) motors
Definition: ArCommands.h:43
Action to limit the forwards motion of the robot based on range sensor readings.
Definition: ArActionLimiterForwards.h:39
void restore(void)
Sets stdin back to its original settings, if its been restored it won't read anymore.
Definition: ArKeyHandler.cpp:117
int getXCG(void)
Gets the X Center of Gravity of the blob.
Definition: ArACTS.h:46
int getArea(void)
Gets the number of pixels (area) covered by the blob.
Definition: ArACTS.h:44