Aria  2.8.0
gotoActionExample.cpp

Uses ArActionGoto to drive the robot in a squareThis program will make the robot drive in a 2.5x2.5 meter square by setting each corner in turn as the goal for an ArActionGoto action. It also uses speed limiting actions to avoid collisions. After some time, it cancels the goal (and the robot stops due to a stopping action) and exits.

Press escape to shut down Aria and exit.

/*
Adept MobileRobots Robotics Interface for Applications (ARIA)
Copyright (C) 2004, 2005 ActivMedia Robotics LLC
Copyright (C) 2006, 2007, 2008, 2009, 2010 MobileRobots Inc.
Copyright (C) 2011, 2012, 2013 Adept Technology
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
If you wish to redistribute ARIA under different terms, contact
Adept MobileRobots for information about a commercial version of ARIA at
robots@mobilerobots.com or
Adept MobileRobots, 10 Columbia Drive, Amherst, NH 03031; +1-603-881-7960
*/
#include "Aria.h"
int main(int argc, char **argv)
{
ArArgumentParser parser(&argc, argv);
ArSimpleConnector simpleConnector(&parser);
ArRobot robot;
ArAnalogGyro gyro(&robot);
robot.addRangeDevice(&sonar);
// Make a key handler, so that escape will shut down the program
// cleanly
ArKeyHandler keyHandler;
Aria::setKeyHandler(&keyHandler);
robot.attachKeyHandler(&keyHandler);
printf("You may press escape to exit\n");
// Collision avoidance actions at higher priority
ArActionLimiterForwards limiterAction("speed limiter near", 300, 600, 250);
ArActionLimiterForwards limiterFarAction("speed limiter far", 300, 1100, 400);
ArActionLimiterTableSensor tableLimiterAction;
robot.addAction(&tableLimiterAction, 100);
robot.addAction(&limiterAction, 95);
robot.addAction(&limiterFarAction, 90);
// Goto action at lower priority
ArActionGoto gotoPoseAction("goto");
robot.addAction(&gotoPoseAction, 50);
// Stop action at lower priority, so the robot stops if it has no goal
ArActionStop stopAction("stop");
robot.addAction(&stopAction, 40);
// Parse all command line arguments
{
return 1;
}
// Connect to the robot
if (!simpleConnector.connectRobot(&robot))
{
printf("Could not connect to robot... exiting\n");
return 1;
}
robot.runAsync(true);
// turn on the motors, turn off amigobot sounds
robot.enableMotors();
const int duration = 30000; //msec
ArLog::log(ArLog::Normal, "Going to four goals in turn for %d seconds, then cancelling goal and exiting.", duration/1000);
bool first = true;
int goalNum = 0;
ArTime start;
start.setToNow();
while (Aria::getRunning())
{
robot.lock();
// Choose a new goal if this is the first loop iteration, or if we
// achieved the previous goal.
if (first || gotoPoseAction.haveAchievedGoal())
{
first = false;
goalNum++;
if (goalNum > 4)
goalNum = 1; // start again at goal #1
// set our positions for the different goals
if (goalNum == 1)
gotoPoseAction.setGoal(ArPose(2500, 0));
else if (goalNum == 2)
gotoPoseAction.setGoal(ArPose(2500, 2500));
else if (goalNum == 3)
gotoPoseAction.setGoal(ArPose(0, 2500));
else if (goalNum == 4)
gotoPoseAction.setGoal(ArPose(0, 0));
ArLog::log(ArLog::Normal, "Going to next goal at %.0f %.0f",
gotoPoseAction.getGoal().getX(), gotoPoseAction.getGoal().getY());
}
if(start.mSecSince() >= duration) {
ArLog::log(ArLog::Normal, "%d seconds have elapsed. Cancelling current goal, waiting 3 seconds, and exiting.", duration/1000);
gotoPoseAction.cancelGoal();
robot.unlock();
break;
}
robot.unlock();
}
// Robot disconnected or time elapsed, shut down
return 0;
}
ArActionGoto::setGoal
void setGoal(ArPose goal)
Sets a new goal and sets the action to go there.
Definition: ArActionGoto.cpp:79
ArArgumentParser::loadDefaultArguments
void loadDefaultArguments(int positon=1)
Adds args from default files and environmental variables.
Definition: ArArgumentParser.cpp:736
ArKeyHandler
Perform actions when keyboard keys are pressed.
Definition: ArKeyHandler.h:65
ArActionLimiterTableSensor
Action to limit speed (and stop) based on whether the "table"-sensors see anything.
Definition: ArActionLimiterTableSensor.h:40
ArAnalogGyro
Use onboard gyro to improve the heading in an ArRobot object's pose value.
Definition: ArAnalogGyro.h:95
ArActionGoto::cancelGoal
void cancelGoal(void)
Cancels the goal; this action will stop requesting movement.
Definition: ArActionGoto.cpp:74
ArSimpleConnector
Legacy connector for robot and laser.
Definition: ArSimpleConnector.h:51
ArActionGoto::haveAchievedGoal
bool haveAchievedGoal(void)
Sees if the goal has been achieved.
Definition: ArActionGoto.cpp:66
ArRobot::comInt
bool comInt(unsigned char command, short int argument)
Sends a command to the robot with an int for argument.
Definition: ArRobot.cpp:5634
ArRobot::enableMotors
void enableMotors()
Enables the motors on the robot.
Definition: ArRobot.cpp:6521
Aria::setKeyHandler
static void setKeyHandler(ArKeyHandler *keyHandler)
Sets the key handler, so that other classes can find it using getKeyHandler()
Definition: Aria.cpp:624
ArSimpleConnector::connectRobot
bool connectRobot(ArRobot *robot)
Sets up the robot then connects it.
Definition: ArSimpleConnector.cpp:209
ArRobot::addRangeDevice
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
Aria::exit
static void exit(int exitCode=0)
Shutdown all Aria processes/threads, call exit callbacks, and exit the program.
Definition: Aria.cpp:367
ArLog::log
static void log(LogLevel level, const char *str,...)
Log a message, with formatting and variable number of arguments.
Definition: ArLog.cpp:93
ArPose::getY
double getY(void) const
Gets the y position.
Definition: ariaUtil.h:814
ArPose::getX
double getX(void) const
Gets the x position.
Definition: ariaUtil.h:812
ArTime::setToNow
void setToNow(void)
Resets the time.
Definition: ariaUtil.cpp:1086
ArTime::mSecSince
long mSecSince(ArTime since) const
Gets the number of milliseconds since the given timestamp to this one.
Definition: ariaUtil.h:1029
Aria::init
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
ArArgumentParser::checkHelpAndWarnUnparsed
bool checkHelpAndWarnUnparsed(unsigned int numArgsOkay=0)
Checks for the help strings and warns about unparsed arguments.
Definition: ArArgumentParser.cpp:843
ArRobot
Central class for communicating with and operating the robot.
Definition: ArRobot.h:82
ArArgumentParser
Parse and store program command-line arguments for use by other ARIA classes.
Definition: ArArgumentParser.h:64
Aria::logOptions
static void logOptions(void)
Logs all the options for the program (Calls all the callbacks added with addLogOptionsCB())
Definition: Aria.cpp:794
ArSonarDevice
Keep track of recent sonar readings from a robot as an ArRangeDevice.
Definition: ArSonarDevice.h:51
ArActionGoto::getGoal
ArPose getGoal(void)
Gets the goal the action has.
Definition: ArActionGoto.h:77
ArActionGoto
This action goes to a given ArPose very naively.
Definition: ArActionGoto.h:52
ArRobot::runAsync
void runAsync(bool stopRunIfNotConnected, bool runNonThreadedPacketReader=false)
Starts the instance to do processing in its own new thread.
Definition: ArRobot.cpp:301
ArRobot::unlock
int unlock()
Unlock the robot instance.
Definition: ArRobot.h:1272
ArRobot::addAction
bool addAction(ArAction *action, int priority)
Adds an action to the list with the given priority.
Definition: ArRobot.cpp:3278
ArCommands::SOUNDTOG
@ SOUNDTOG
int, AmigoBot (old H8 model) specific, enable(1) or diable(0) sound
Definition: ArCommands.h:125
Aria::parseArgs
static bool parseArgs(void)
Parses the arguments for the program (calls all the callbacks added with addParseArgsCB())
Definition: Aria.cpp:759
ArUtil::sleep
static void sleep(unsigned int ms)
Sleep for the given number of milliseconds.
Definition: ariaUtil.cpp:151
ArLog::Normal
@ Normal
Use normal logging.
Definition: ArLog.h:62
ArTime
A class for time readings and measuring durations.
Definition: ariaUtil.h:1001
ArActionStop
Action for stopping the robot.
Definition: ArActionStop.h:37
ArPose
Represents an x, y position with an orientation.
Definition: ariaUtil.h:758
Aria::getRunning
static bool getRunning(void)
Sees if Aria is still running (mostly for the thread in main)
Definition: Aria.cpp:753
ArRobot::lock
int lock()
Lock the robot instance.
Definition: ArRobot.h:1268
ArRobot::attachKeyHandler
void attachKeyHandler(ArKeyHandler *keyHandler, bool exitOnEscape=true, bool useExitNotShutdown=true)
Attachs a key handler.
Definition: ArRobot.cpp:6641
ArActionLimiterForwards
Action to limit the forwards motion of the robot based on range sensor readings.
Definition: ArActionLimiterForwards.h:39