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

sickRobotExample.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 connects to a robot, then to a laser, then prints out
00030   some readings, and finally exits.
00031 */
00032 
00033 int main(int argc, char **argv)
00034 {
00035   // parse our args and make sure they were all accounted for
00036   ArSimpleConnector connector(&argc, argv);
00037 
00038   // the robot
00039   ArRobot robot;
00040   // the laser
00041   ArSick sick;
00042   // all the information for our printing out
00043   double dist, angle;
00044   std::list<ArPoseWithTime *> *readings;
00045   std::list<ArPoseWithTime *>::iterator it;
00046   double farDist, farAngle;
00047   bool found;
00048 
00049   if (!connector.parseArgs() || argc > 1)
00050   {
00051     connector.logOptions();
00052     exit(1);
00053   }
00054 
00055   // add the laser to the robot
00056   robot.addRangeDevice(&sick);
00057 
00058   // try to connect, if we fail exit
00059   if (!connector.connectRobot(&robot))
00060   {
00061     printf("Could not connect to robot... exiting\n");
00062     Aria::shutdown();
00063     return 1;
00064   }
00065 
00066   // start the robot running, true so that if we lose connection the run stops
00067   robot.runAsync(true);
00068 
00069   // now set up the laser
00070   connector.setupLaser(&sick);
00071 
00072   sick.runAsync();
00073 
00074   if (!sick.blockingConnect())
00075   {
00076     printf("Could not connect to SICK laser... exiting\n");
00077     Aria::shutdown();
00078     return 1;
00079   }
00080 
00081   printf("Connected\n");
00082   ArUtil::sleep(500);
00083   
00084   int times = 0;
00085   while (times++ < 3)
00086   {
00087     //dist = sick.getCurrentBuffer().getClosestPolar(-90, 90, ArPose(0, 0), 30000, &angle);
00088     sick.lockDevice();
00089     dist = sick.currentReadingPolar(-90, 90, &angle);
00090     if (dist < sick.getMaxRange())
00091       printf("Closest reading %.2f mm away at %.2f degrees\n", dist, angle);
00092     else
00093       printf("No close reading.\n");
00094     readings = sick.getCurrentBuffer();
00095     int i = 0;
00096     for (it = readings->begin(), found = false; it != readings->end(); it++)
00097     {
00098       i++;
00099       dist = (*it)->findDistanceTo(ArPose(0, 0));
00100       angle = (*it)->findAngleTo(ArPose(0, 0));
00101       if (!found || dist > farDist)
00102       {
00103     found = true;
00104     farDist = dist;
00105     farAngle = angle;
00106       }
00107     }
00108     printf("%d readings\n", i);
00109     if (found)
00110       printf("Furthest reading %.2f mm away at %.2f degrees\n", 
00111          farDist, farAngle);
00112     else
00113       printf("No far reading found.\n");
00114     
00115     sick.unlockDevice();
00116     ArUtil::sleep(100);
00117   }
00118 
00119   Aria::shutdown();
00120   return 0;
00121 }
00122 
00123 
00124 
00125 

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