simpleConnect.cpp

example showing how to connect to the robot with ArRobotConnector

One of the simplest ARIA programs possible: Connects with ArRobotConnector, waits 3 seconds doing nothing, then exits.

This program will work either with the MobileSim simulator or on a real robot's onboard computer. (Or use -remoteHost to connect to a wireless ethernet-serial bridge.)

00001 #include "Aria.h"
00002 
00014 int main(int argc, char **argv)
00015 {
00016   Aria::init();
00017   ArRobot robot;
00018   ArArgumentParser parser(&argc, argv);
00019   parser.loadDefaultArguments();
00020 
00021   // Connect to the robot, get some initial data from it such as type and name,
00022   // and then load parameter files for this robot.
00023   ArRobotConnector robotConnector(&parser, &robot);
00024   if(!robotConnector.connectRobot())
00025   {
00026     ArLog::log(ArLog::Terse, "simpleConnect: Could not connect to the robot.");
00027     if(parser.checkHelpAndWarnUnparsed())
00028     {
00029         // -help not given
00030         Aria::logOptions();
00031         Aria::exit(1);
00032     }
00033   }
00034   if (!Aria::parseArgs())
00035   {
00036     Aria::logOptions();
00037     Aria::shutdown();
00038     return 1;
00039   }
00040   
00041   ArLog::log(ArLog::Normal, "simpleConnect: Connected.");
00042 
00043   // Start the robot processing cycle running in the background.
00044   // True parameter means that if the connection is lost, then the 
00045   // run loop ends.
00046   robot.runAsync(true);
00047 
00048   // Print out some data from the SIP.  We must "lock" the ArRobot object
00049   // before calling its methods, and "unlock" when done, to prevent conflicts
00050   // with the background thread started by the call to robot.runAsync() above.
00051   // See the section on threading in the manual for more about this.
00052   robot.lock();
00053   ArLog::log(ArLog::Normal, "simpleConnect: Pose=(%.2f,%.2f,%.2f), Trans. Vel=%.2f, Battery=%.2fV",
00054     robot.getX(), robot.getY(), robot.getTh(), robot.getVel(), robot.getBatteryVoltage());
00055   robot.unlock();
00056 
00057   // Sleep for 3 seconds.
00058   ArLog::log(ArLog::Normal, "simpleConnect: Sleeping for 3 seconds...");
00059   ArUtil::sleep(3000);
00060 
00061   
00062   ArLog::log(ArLog::Normal, "simpleConnect: Ending robot thread...");
00063   robot.stopRunning();
00064 
00065   // wait for the thread to stop
00066   robot.waitForRunExit();
00067 
00068   // exit
00069   ArLog::log(ArLog::Normal, "simpleConnect: Exiting.");
00070   return 0;
00071 }

Generated on Fri Jul 31 12:36:37 2009 for Aria by  doxygen 1.4.7