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 /* 00029 This is an example of how to use the limiting behaviors. 00030 00031 The way it works is that it has a limiting behavior higher priority 00032 than the joydrive action behavior. So the joydrive action can try 00033 to do whatever it wants, but it won't work. 00034 */ 00035 00036 00037 int main(int argc, char **argv) 00038 { 00039 int ret; 00040 std::string str; 00041 // robot 00042 ArRobot robot; 00043 00044 // the laser 00045 ArSick sick; 00046 // the joydrive action 00047 ArActionJoydrive jdAct; 00048 00049 // limiter for close obstacles 00050 ArActionLimiterForwards limiter("speed limiter near", 300, 600, 250); 00051 // limiter for far away obstacles 00052 ArActionLimiterForwards limiterFar("speed limiter far", 300, 1100, 400); 00053 // limiter so we don't bump things backwards 00054 // limiter for far away obstacles 00055 ArActionLimiterTableSensor tableLimiter; 00056 // limiter so we don't bump things backwards 00057 ArActionLimiterBackwards backwardsLimiter; 00058 // sonar device, so the limiter will work, this must be added to the robot 00059 //ArSonarDevice sonar; 00060 00061 // mandatory init 00062 Aria::init(); 00063 00064 // add the sonar to the robot 00065 //robot.addRangeDevice(&sonar); 00066 // Set the laser onto the robot 00067 robot.addRangeDevice(&sick); 00068 00069 ArSimpleConnector connector(&argc, argv); 00070 00071 if (!connector.parseArgs() || argc > 1) 00072 { 00073 connector.logOptions(); 00074 exit(1); 00075 } 00076 00077 // try to connect, if we fail exit 00078 if (!connector.connectRobot(&robot)) 00079 { 00080 printf("Could not connect to robot... exiting\n"); 00081 Aria::shutdown(); 00082 return 1; 00083 } 00084 00085 connector.setupLaser(&sick); 00086 00087 // now that we're connected to the robot, connect to the laser 00088 sick.runAsync(); 00089 00090 if (!sick.blockingConnect()) 00091 { 00092 printf("Could not connect to SICK laser... exiting\n"); 00093 Aria::shutdown(); 00094 return 1; 00095 } 00096 00097 00098 // enable the motors, disable amigobot sounds 00099 robot.comInt(ArCommands::ENABLE, 1); 00100 robot.comInt(ArCommands::SOUNDTOG, 0); 00101 00102 // add the cations, put the limiters on top, then have the action, 00103 // this will keep the action from being able to drive too fast and hit 00104 // something 00105 robot.addAction(&tableLimiter, 100); 00106 robot.addAction(&limiter, 95); 00107 robot.addAction(&limiterFar, 90); 00108 robot.addAction(&backwardsLimiter, 85); 00109 robot.addAction(&jdAct, 50); 00110 00111 // run the robot, true here so that the run will exit if connection lost 00112 robot.run(true); 00113 00114 // now exit 00115 Aria::shutdown(); 00116 return 0; 00117 }