Aria  2.8.0
demo.cpp

General purpose testing and demo program, using ArMode classes to provide keyboard control of various robot functions.demo uses ArMode subclasses from ARIA. These modes provide keyboard control of various aspects and accessories of the robot, and can be re-used in your programs if you wish.
The ArMode classes are defined in ArModes.cpp.

"demo" is a useful program for testing out the operation of the robot for diagnostic or demonstration purposes. Other example programs focus on individual areas.

/*
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)
{
// Initialize some global data
// If you want ArLog to print "Verbose" level messages uncomment this:
//ArLog::init(ArLog::StdOut, ArLog::Verbose);
// This object parses program options from the command line
ArArgumentParser parser(&argc, argv);
// Load some default values for command line arguments from /etc/Aria.args
// (Linux) or the ARIAARGS environment variable.
// Central object that is an interface to the robot and its integrated
// devices, and which manages control of the robot by the rest of the program.
ArRobot robot;
// Object that connects to the robot or simulator using program options
ArRobotConnector robotConnector(&parser, &robot);
// If the robot has an Analog Gyro, this object will activate it, and
// if the robot does not automatically use the gyro to correct heading,
// this object reads data from it and corrects the pose in ArRobot
ArAnalogGyro gyro(&robot);
// Connect to the robot, get some initial data from it such as type and name,
// and then load parameter files for this robot.
if (!robotConnector.connectRobot())
{
// Error connecting:
// if the user gave the -help argumentp, then just print out what happened,
// and continue so options can be displayed later.
if (!parser.checkHelpAndWarnUnparsed())
{
ArLog::log(ArLog::Terse, "Could not connect to robot, will not have parameter file so options displayed later may not include everything");
}
// otherwise abort
else
{
ArLog::log(ArLog::Terse, "Error, could not connect to robot.");
}
}
if(!robot.isConnected())
{
ArLog::log(ArLog::Terse, "Internal error: robot connector succeeded but ArRobot::isConnected() is false!");
}
// Connector for laser rangefinders
ArLaserConnector laserConnector(&parser, &robot, &robotConnector);
// Connector for compasses
ArCompassConnector compassConnector(&parser);
// Parse the command line options. Fail and print the help message if the parsing fails
// or if the help was requested with the -help option
{
return 1;
}
// Used to access and process sonar range data
ArSonarDevice sonarDev;
// Used to perform actions when keyboard keys are pressed
ArKeyHandler keyHandler;
Aria::setKeyHandler(&keyHandler);
// ArRobot contains an exit action for the Escape key. It also
// stores a pointer to the keyhandler so that other parts of the program can
// use the same keyhandler.
robot.attachKeyHandler(&keyHandler);
printf("You may press escape to exit\n");
// Attach sonarDev to the robot so it gets data from it.
robot.addRangeDevice(&sonarDev);
// Start the robot task loop running in a new background thread. The 'true' argument means if it loses
// connection the task loop stops and the thread exits.
robot.runAsync(true);
// Connect to the laser(s) if lasers were configured in this robot's parameter
// file or on the command line, and run laser processing thread if applicable
// for that laser class. For the purposes of this demo, add all
// possible lasers to ArRobot's list rather than just the ones that were
// connected by this call so when you enter laser mode, you
// can then interactively choose which laser to use from that list of all
// lasers mentioned in robot parameters and on command line. Normally,
// only connected lasers are put in ArRobot's list.
if (!laserConnector.connectLasers(
false, // continue after connection failures
false, // add only connected lasers to ArRobot
true // add all lasers to ArRobot
))
{
printf("Could not connect to lasers... exiting\n");
}
/* not needed, robot connector will do it by default
if (!sonarConnector.connectSonars(
false, // continue after connection failures
false, // add only connected lasers to ArRobot
true // add all lasers to ArRobot
))
{
printf("Could not connect to sonars... exiting\n");
Aria::exit(2);
}
*/
// Create and connect to the compass if the robot has one.
ArTCM2 *compass = compassConnector.create(&robot);
if(compass && !compass->blockingConnect()) {
compass = NULL;
}
// Sleep for a second so some messages from the initial responses
// from robots and cameras and such can catch up
// We need to lock the robot since we'll be setting up these modes
// while the robot task loop thread is already running, and they
// need to access some shared data in ArRobot.
robot.lock();
// now add all the modes for this demo
// these classes are defined in ArModes.cpp in ARIA's source code.
new ArModeGripper(&robot, "gripper", 'g', 'G');
else
ArLog::log(ArLog::Normal, "Robot does not indicate that it has a gripper.");
ArModeActs actsMode(&robot, "acts", 'a', 'A');
ArModeTCM2 tcm2(&robot, "tcm2", 'm', 'M', compass);
ArModeIO io(&robot, "io", 'i', 'I');
ArModeConfig cfg(&robot, "report robot config", 'o' , 'O');
ArModeCommand command(&robot, "command", 'd', 'D');
ArModeCamera camera(&robot, "camera", 'c', 'C');
ArModePosition position(&robot, "position", 'p', 'P', &gyro);
ArModeSonar sonar(&robot, "sonar", 's', 'S');
ArModeBumps bumps(&robot, "bumps", 'b', 'B');
ArModeLaser laser(&robot, "laser", 'l', 'L');
ArModeWander wander(&robot, "wander", 'w', 'W');
ArModeUnguardedTeleop unguardedTeleop(&robot, "unguarded teleop", 'u', 'U');
ArModeTeleop teleop(&robot, "teleop", 't', 'T');
// activate the default mode
teleop.activate();
// turn on the motors
robot.unlock();
// Block execution of the main thread here and wait for the robot's task loop
// thread to exit (e.g. by robot disconnecting, escape key pressed, or OS
// signal)
robot.waitForRunExit();
return 0;
}
ArRobotConnector::connectRobot
bool connectRobot(void)
Sets up the robot then connects it.
Definition: ArRobotConnector.cpp:405
ArModeConfig
Mode for requesting config packet.
Definition: ArModes.h:492
ArCompassConnector
Use this class to create an instance of a TCM2 subclass and connect to the device based on program co...
Definition: ArTCM2.h:228
ArActionGroup::activate
virtual void activate(void)
Activates all the actions in this group.
Definition: ArActionGroup.cpp:84
ArModeSonar
Mode for displaying the sonar.
Definition: ArModes.h:245
ArRobot::getOrigRobotConfig
const ArRobotConfigPacketReader * getOrigRobotConfig(void) const
Gets the original robot config packet information.
Definition: ArRobot.cpp:2592
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
ArAnalogGyro
Use onboard gyro to improve the heading in an ArRobot object's pose value.
Definition: ArAnalogGyro.h:95
ArLog::Terse
@ Terse
Use terse logging.
Definition: ArLog.h:61
ArTCM2::blockingConnect
virtual bool blockingConnect(unsigned long connectTimeout=5000)
If a connection/initialization procedure is required, perform it, wait until data is recieved from th...
Definition: ArTCM2.cpp:64
ArModeActs
Mode for following a color blob using ACTS.
Definition: ArModes.h:385
ArTCM2
Interface to the PNI TCM 2, TCM 2.5, and TCM 2.6 3-axis compass (magnetometer) that can sense absolut...
Definition: ArTCM2.h:63
ArRobotConfigPacketReader::getHasGripper
bool getHasGripper(void) const
Gets the gripper value (whether or not the robot has a gripper)
Definition: ArRobotConfigPacketReader.h:88
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
ArRobotConnector
Connect to robot or simulator based on program command line parameters.
Definition: ArRobotConnector.h:80
ArRobot::isConnected
bool isConnected(void) const
Questions whether the robot is connected or not.
Definition: ArRobot.h:133
Aria::setKeyHandler
static void setKeyHandler(ArKeyHandler *keyHandler)
Sets the key handler, so that other classes can find it using getKeyHandler()
Definition: Aria.cpp:624
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
ArModeTCM2
Mode for following a color blob using ACTS.
Definition: ArModes.h:462
ArLaserConnector
Create laser interface objects (for any kind of laser supported by ARIA) and connect to lasers based ...
Definition: ArLaserConnector.h:80
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
ArModeWander
Mode for wandering around.
Definition: ArModes.h:84
ArSonarDevice
Keep track of recent sonar readings from a robot as an ArRangeDevice.
Definition: ArSonarDevice.h:51
ArModeTeleop
Mode for teleoping the robot with joystick + keyboard.
Definition: ArModes.h:46
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
ArModeGripper
Mode for controlling the gripper.
Definition: ArModes.h:100
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
ArLaserConnector::connectLasers
bool connectLasers(bool continueOnFailedConnect=false, bool addConnectedLasersToRobot=true, bool addAllLasersToRobot=false, bool turnOnLasers=true, bool powerCycleLaserOnFailedConnect=true, int *failedOnLaser=NULL)
Connects all the lasers the robot has that should be auto connected.
Definition: ArLaserConnector.cpp:1213
ArModeUnguardedTeleop
Mode for teleoping the robot with joystick + keyboard.
Definition: ArModes.h:65
ArLog::Normal
@ Normal
Use normal logging.
Definition: ArLog.h:62
ArModeCamera
Mode for controlling the camera.
Definition: ArModes.h:139
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
ArCommands::ENABLE
@ ENABLE
int, enable (1) or disable (0) motors
Definition: ArCommands.h:43
ArRobot::waitForRunExit
WaitState waitForRunExit(unsigned int msecs=0)
Suspend calling thread until the ArRobot run loop has exited.
Definition: ArRobot.cpp:2923