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

teleopActionsExample.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 
00040 int main(int argc, char **argv)
00041 {
00042   Aria::init();
00043 
00044   ArRobot robot;
00045   
00046   // limiter for close obstacles
00047   ArActionLimiterForwards limiter("speed limiter near", 300, 600, 250);
00048   // limiter for far away obstacles
00049   ArActionLimiterForwards limiterFar("speed limiter far", 300, 1100, 400);
00050   // limiter that checks IR sensors (like Peoplebot has)
00051   ArActionLimiterTableSensor tableLimiter;
00052   // limiter so we don't bump things backwards
00053   ArActionLimiterBackwards backwardsLimiter;
00054   // the joydrive action
00055   ArActionJoydrive joydriveAct;
00056   // the keydrive action
00057   ArActionKeydrive keydriveAct;
00058   
00059   // sonar device, used by the limiter actions.
00060   ArSonarDevice sonar;
00061 
00062   ArArgumentParser parser(&argc, argv);
00063   parser.loadDefaultArguments();
00064   ArSimpleConnector connector(&parser);
00065   
00066   if (!Aria::parseArgs())
00067   {
00068     Aria::logOptions();
00069     Aria::shutdown();
00070     return 1;
00071   }
00072   
00073 
00074   printf("This program will allow you to use a joystick or keyboard to control the robot.\nYou can use the arrow keys to drive, and the spacebar to stop.\nFor joystick control press the trigger button and then drive.\nPress escape to exit.\n");
00075 
00076   // if we don't have a joystick, let 'em know
00077   if (!joydriveAct.joystickInited())
00078     printf("Do not have a joystick, only the arrow keys on the keyboard will work.\n");
00079   
00080   // set the joystick so it won't do anything if the button isn't pressed
00081   joydriveAct.setStopIfNoButtonPressed(false);
00082 
00083   // add the sonar to the robot
00084   robot.addRangeDevice(&sonar);
00085 
00086   // try to connect, if we fail exit
00087   if (!connector.connectRobot(&robot))
00088   {
00089     printf("Could not connect to robot... exiting\n");
00090     Aria::shutdown();
00091     return 1;
00092   }
00093 
00094   // set the robots maximum velocity (sonar don't work at all well if you're
00095   // going faster)
00096   robot.setAbsoluteMaxTransVel(400);
00097 
00098   // enable the motor
00099   robot.enableMotors();
00100 
00101   // Add the actions, with the limiters as highest priority, then the teleop.
00102   // actions.  This will keep the teleop. actions from being able to drive too 
00103   // fast and hit something
00104   robot.addAction(&tableLimiter, 100);
00105   robot.addAction(&limiter, 95);
00106   robot.addAction(&limiterFar, 90);
00107   robot.addAction(&backwardsLimiter, 85);
00108   robot.addAction(&joydriveAct, 50);
00109   robot.addAction(&keydriveAct, 45);
00110 
00111   // Configure the joydrive action so it will let the lower priority actions
00112   // (i.e. keydriveAct) request motion if the joystick button is
00113   // not pressed.
00114   joydriveAct.setStopIfNoButtonPressed(false);
00115 
00116   
00117   // run the robot, true means that the run will exit if connection lost
00118   robot.run(true);
00119   
00120   Aria::shutdown();
00121   return 0;
00122 }

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