This example program will constantly search for a line-like pattern in the sensor readings of a laser rangefinder. If you press the 'f' key, those points will be saved in 'points' and 'lines' files. Use arrow keys or joystick to teleoperate the robot.
00001 #include "Aria.h" 00002 00013 int main(int argc, char **argv) 00014 { 00015 Aria::init(); 00016 00017 ArSimpleConnector connector(&argc, argv); 00018 ArRobot robot; 00019 ArSick sick; 00020 00021 if (!Aria::parseArgs() || argc > 1) 00022 { 00023 Aria::logOptions(); 00024 Aria::shutdown(); 00025 exit(1); 00026 } 00027 00028 ArKeyHandler keyHandler; 00029 Aria::setKeyHandler(&keyHandler); 00030 robot.attachKeyHandler(&keyHandler); 00031 00032 00033 robot.addRangeDevice(&sick); 00034 00035 // Create the ArLineFinder object. Set it to log lots of information about its 00036 // processing. 00037 ArLineFinder lineFinder(&sick); 00038 lineFinder.setVerbose(true); 00039 00040 // Add key callbacks that simply call the ArLineFinder::getLinesAndSaveThem() 00041 // function, which searches for lines in the current set of laser sensor 00042 // readings, and saves them in files with the names 'points' and 'lines'. 00043 ArFunctorC<ArLineFinder> findLineCB(&lineFinder, 00044 &ArLineFinder::getLinesAndSaveThem); 00045 keyHandler.addKeyHandler('f', &findLineCB); 00046 keyHandler.addKeyHandler('F', &findLineCB); 00047 00048 00049 ArLog::log(ArLog::Normal, "lineFinderExample: connecting to robot..."); 00050 if (!connector.connectRobot(&robot)) 00051 { 00052 printf("Could not connect to robot... exiting\n"); 00053 Aria::shutdown(); 00054 return 1; 00055 } 00056 robot.runAsync(true); 00057 00058 // now set up the laser 00059 ArLog::log(ArLog::Normal, "lineFinderExample: connecting to SICK laser..."); 00060 connector.setupLaser(&sick); 00061 sick.runAsync(); 00062 if (!sick.blockingConnect()) 00063 { 00064 printf("Could not connect to SICK laser... exiting\n"); 00065 Aria::shutdown(); 00066 return 1; 00067 } 00068 00069 printf("If you press the 'f' key the points and lines found will be saved\n"); 00070 printf("Into the 'points' and 'lines' file in the current working directory\n"); 00071 00072 robot.waitForRunExit(); 00073 return 0; 00074 } 00075 00076 00077
1.4.7