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

sickLogger.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 /*
00029 This program will let you joystick the robot around, and take logs for
00030 the mapper while you drive, automatically... 
00031 
00032 Control: 
00033 
00034 Attach an analog joystick to the joyport on the robot, not on the
00035 computer.  Now calibrate the joystick: Leaving the stick centered,
00036 press the trigger button for a second or so, then release it. Now
00037 rotate the stick around its extremes two or three times, holding it in
00038 each corner for a second or two. You are now ready to drive.  You can
00039 then drive the robot by holding the trigger and moving the joystick.
00040 To make goals you can press the top button on the joystick (this
00041 requires AROS1_5).
00042 
00043 You could also attach USB joystick attached to robot computer (this
00044 depends on having a robot equiped with an accessible usb port): To
00045 drive the robot just press the trigger button and then move the
00046 joystick how you wish the robot to move.  You can use the throttle on
00047 the side of the joystick to control the maximum (and hence scaled)
00048 speed at which the robot drives.  To make a goal you can press any of
00049 the other buttons on the joystick itself (button 2, 3, or 4).
00050 
00051 You could run this with the keyboard, but not very versatile.  Use the
00052 arrow keys to control the robot, and press g to make a goal.
00053 */
00054 
00055 
00056 int main(int argc, char **argv)
00057 {
00058 
00059   // mandatory init
00060   Aria::init();
00061 
00062   // set up our parser
00063   ArArgumentParser parser(&argc, argv);
00064   // set up our simple connector
00065   ArSimpleConnector simpleConnector(&parser);
00066 
00067   // robot
00068   ArRobot robot;
00069   // the laser
00070   ArSick sick;
00071   // the serial connection (robot)
00072   ArSerialConnection serConn;
00073   // tcp connection (sim)
00074   ArTcpConnection tcpConn;
00075   // Laser connection
00076   ArSerialConnection laserCon;
00077   // whether or not we're using the sim (auto determined);
00078   bool useSim = false;
00079   // a key handler so we can do our key handling
00080   ArKeyHandler keyHandler;
00081 
00082   // let the global aria stuff know about it
00083   Aria::setKeyHandler(&keyHandler);
00084   // toss it on the robot
00085   robot.attachKeyHandler(&keyHandler);
00086 
00087 #ifdef WIN32
00088   printf("Pausing 5 seconds so you can disconnect VNC if you are using it.\n");
00089   ArUtil::sleep(5000);
00090 #endif
00091 
00092   // attach the laser to the robot
00093   robot.addRangeDevice(&sick);
00094 
00095   // make an analog gyro object (it won't do anything if we don't have
00096   // one), if we have soemthing it'll take care of it itself
00097   ArAnalogGyro analogGyro(&robot);
00098 
00099   // try to load up the old school inertials
00100   if (!useSim && 
00101       ArModuleLoader::load("libArInertial", &robot, NULL, true) == 0)
00102   {
00103     printf("Loaded the base inertial library\n");
00104     if (ArModuleLoader::load("ISense_Mod", &robot, (void *)"2", true) == 0)
00105     {
00106       printf("The ISense inertial module has been loaded and should be correcting heading now.\n");
00107     }   
00108     else if (
00109     ArModuleLoader::load("ISIS_Mod", &robot,(void *)ArUtil::COM2, false) == 0)
00110     {
00111       printf("The ISIS inertial module has been loaded and should be correcting heading now.\n");
00112     }
00113   }
00114 
00115   
00116   // load the default arguments 
00117   parser.loadDefaultArguments();
00118   // add our right increments and degrees as a deafult
00119   parser.addDefaultArgument("-laserDegrees 180 -laserIncrement half");
00120   // parse the command line... fail and print the help if the parsing fails
00121   // or if the help was requested
00122   if (!simpleConnector.parseArgs() || !parser.checkHelpAndWarnUnparsed(1))
00123   {    
00124     simpleConnector.logOptions();
00125     keyHandler.restore();
00126     exit(1);
00127   }
00128 
00129   std::string filename = "1scans.2d";
00130   if (argc > 1)
00131     filename = argv[1];
00132   printf("Logging to file %s\n", filename.c_str());
00133   
00134   
00135   
00136   // set up the robot for connecting
00137   if (!simpleConnector.connectRobot(&robot))
00138   {
00139     printf("Could not connect to robot... exiting\n");
00140     Aria::shutdown();
00141     keyHandler.restore();
00142     return 1;
00143   }
00144 
00145   // make the group to drive the robot (mostly for the USB)
00146 
00147   ArActionGroupRatioDriveUnsafe group(&robot);
00148   group.activateExclusive();
00149 
00150   // run the robot, true here so that the run will exit if connection lost
00151   robot.runAsync(true);
00152 
00153   simpleConnector.setupLaser(&sick);
00154   // This must be created after the robot is connected so that it'll
00155   // get the right laser pos
00156   ArSickLogger logger(&robot, &sick, 300, 25, filename.c_str(),
00157               false);
00158 
00159   // now that we're connected to the robot, connect to the laser
00160   sick.runAsync();
00161 
00162   // connect the laser if it was requested
00163   if (!sick.blockingConnect())
00164   {
00165     printf("Could not connect to laser... exiting\n");
00166     Aria::shutdown();
00167     keyHandler.restore();
00168     return 1;
00169   }
00170   
00171 
00172   // enable the motors, disable amigobot sounds
00173   robot.comInt(ArCommands::SONAR, 0);
00174   robot.comInt(ArCommands::ENABLE, 1);
00175   robot.comInt(ArCommands::SOUND, 32);
00176   robot.comInt(ArCommands::SOUNDTOG, 0);
00177   // enable the joystick driving from the one connected to the microcontroller
00178   robot.comInt(ArCommands::JOYDRIVE, 1);
00179   // just hang out and wait for the end
00180   robot.waitForRunExit();
00181   sick.lockDevice();
00182   sick.disconnect();
00183   sick.unlockDevice();
00184   // now exit
00185   Aria::shutdown();
00186   return 0;
00187 }

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