Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages | Examples

demo.cpp

00001 /*
00002 MobileRobots Advanced Robotics Interface for Applications (ARIA)
00003 Copyright (C) 2004, 2005 ActivMedia Robotics LLC
00004 Copyright (C) 2006, 2007 MobileRobots Inc.
00005 
00006      This program is free software; you can redistribute it and/or modify
00007      it under the terms of the GNU General Public License as published by
00008      the Free Software Foundation; either version 2 of the License, or
00009      (at your option) any later version.
00010 
00011      This program is distributed in the hope that it will be useful,
00012      but WITHOUT ANY WARRANTY; without even the implied warranty of
00013      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014      GNU General Public License for more details.
00015 
00016      You should have received a copy of the GNU General Public License
00017      along with this program; if not, write to the Free Software
00018      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 
00020 If you wish to redistribute ARIA under different terms, contact 
00021 MobileRobots for information about a commercial version of ARIA at 
00022 robots@mobilerobots.com or 
00023 MobileRobots Inc, 19 Columbia Drive, Amherst, NH 03031; 800-639-9481
00024 */
00025 
00026 #include "Aria.h"
00027 
00028 
00039 int main(int argc, char** argv)
00040 {
00041   // mandatory init
00042   Aria::init();
00043 
00044   // set up our parser
00045   ArArgumentParser parser(&argc, argv);
00046   // set up our simple connector
00047   ArSimpleConnector simpleConnector(&parser);
00048   // robot
00049   ArRobot robot;
00050   // a laser in case one is used
00051   ArSick sick;
00052   // sonar, must be added to the robot, for teleop and wander
00053   ArSonarDevice sonarDev;
00054 
00055 
00056   // load the default arguments 
00057   parser.loadDefaultArguments();
00058 
00059   // parse the command line... fail and print the help if the parsing fails
00060   // or if the help was requested
00061   if (!Aria::parseArgs() || !parser.checkHelpAndWarnUnparsed())
00062   {    
00063     Aria::logOptions();
00064     exit(1);
00065   }
00066   
00067   //ArLog::init(ArLog::StdOut, ArLog::Verbose);
00068 
00069   // if you're using a program at startup in linux you must NOT
00070   // include a keyhandler or you'll get lockups when trying to read
00071   // keys with no terminal
00072 
00073   // a key handler so we can do our key handling
00074   ArKeyHandler keyHandler;
00075   // let the global aria stuff know about it
00076   Aria::setKeyHandler(&keyHandler);
00077   // toss it on the robot
00078   robot.attachKeyHandler(&keyHandler);
00079   printf("You may press escape to exit\n");
00080 
00081   // add the sonar to the robot
00082   robot.addRangeDevice(&sonarDev);
00083   // add the laser to the robot
00084   robot.addRangeDevice(&sick);
00085 
00086  
00087 
00088   // add a gyro, it'll see if it should attach to the robot or not
00089   ArAnalogGyro gyro(&robot);
00090 
00091   // set up the robot for connecting
00092   if (!simpleConnector.connectRobot(&robot))
00093   {
00094     printf("Could not connect to robot... exiting\n");
00095     Aria::exit(1);
00096   }
00097 
00098   // start the robot running, true so that if we lose connection the run stops
00099   robot.runAsync(true);
00100 
00101   // set up the laser before handing it to the laser mode
00102   sick.runAsync();
00103 
00104   // connect the laser if it was requested
00105   if (!simpleConnector.connectLaser(&sick))
00106   {
00107     printf("Could not connect to laser... exiting\n");
00108     Aria::exit(2);
00109   }
00110   
00111   // we need to lock the robot since we'll be setting up these modes
00112   // while the robot is already running and don't want anything to
00113   // break
00114   robot.lock();
00115 
00116   // now add all the modes
00117   ArModeLaser laser(&robot, "laser", 'l', 'L', &sick);
00118   ArModeTeleop teleop(&robot, "teleop", 't', 'T');
00119   ArModeUnguardedTeleop unguardedTeleop(&robot, "unguarded teleop", 'u', 'U');
00120   ArModeWander wander(&robot, "wander", 'w', 'W');
00121   ArModeGripper gripper(&robot, "gripper", 'g', 'G');
00122   ArModeCamera camera(&robot, "camera", 'c', 'C');
00123   ArModeSonar sonar(&robot, "sonar", 's', 'S');
00124   ArModeBumps bumps(&robot, "bumps", 'b', 'B');
00125   ArModePosition position(&robot, "position", 'p', 'P', &gyro);
00126   ArModeIO io(&robot, "io", 'i', 'I');
00127   ArModeActs actsMode(&robot, "acts", 'a', 'A');
00128   ArModeCommand command(&robot, "command", 'd', 'D');
00129   ArModeTCM2 tcm2(&robot, "tcm2", 'm', 'M');
00130 
00131   // activate the default mode
00132   teleop.activate();
00133 
00134   // turn on the motors
00135   robot.comInt(ArCommands::ENABLE, 1);
00136   //robot.comInt(ArCommands::JOYDRIVE, 1);
00137 
00138   robot.unlock();
00139   
00140   robot.waitForRunExit();
00141   // now exit
00142   Aria::exit(0);
00143 
00144 
00145 }
00146 

Generated on Tue Feb 20 10:51:42 2007 for Aria by  doxygen 1.4.0