本文整理汇总了C++中ArRobot::getLaserMap方法的典型用法代码示例。如果您正苦于以下问题:C++ ArRobot::getLaserMap方法的具体用法?C++ ArRobot::getLaserMap怎么用?C++ ArRobot::getLaserMap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ArRobot
的用法示例。
在下文中一共展示了ArRobot::getLaserMap方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char **argv)
{
Aria::init();
ArRobot robot;
ArArgumentParser parser(&argc, argv);
parser.loadDefaultArguments();
ArRobotConnector robotConnector(&parser, &robot);
ArLaserConnector laserConnector(&parser, &robot, &robotConnector);
// Connect to the robot, get some initial data from it such as type and name,
// and then load parameter files for this robot.
if(!robotConnector.connectRobot())
{
ArLog::log(ArLog::Terse, "lasersExample: Could not connect to the robot.");
if(parser.checkHelpAndWarnUnparsed())
{
// -help not given
Aria::logOptions();
Aria::exit(1);
}
}
if (!Aria::parseArgs())
{
Aria::logOptions();
Aria::exit(2);
return 2;
}
ArLog::log(ArLog::Normal, "lasersExample: Connected to robot.");
// Start the robot processing cycle running in the background.
// True parameter means that if the connection is lost, then the
// run loop ends.
robot.runAsync(true);
// Connect to laser(s) as defined in parameter files.
// (Some flags are available as arguments to connectLasers() to control error behavior and to control which lasers are put in the list of lasers stored by ArRobot. See docs for details.)
if(!laserConnector.connectLasers())
{
ArLog::log(ArLog::Terse, "Could not connect to configured lasers. Exiting.");
Aria::exit(3);
return 3;
}
// Allow some time to read laser data
ArUtil::sleep(500);
ArLog::log(ArLog::Normal, "Connected to all lasers.");
// Print out some data from each connected laser.
while(robot.isConnected())
{
int numLasers = 0;
// Get a pointer to ArRobot's list of connected lasers. We will lock the robot while using it to prevent changes by tasks in the robot's background task thread or any other threads. Each laser has an index. You can also store the laser's index or name (laser->getName()) and use that to get a reference (pointer) to the laser object using ArRobot::findLaser().
robot.lock();
std::map<int, ArLaser*> *lasers = robot.getLaserMap();
for(std::map<int, ArLaser*>::const_iterator i = lasers->begin(); i != lasers->end(); ++i)
{
int laserIndex = (*i).first;
ArLaser* laser = (*i).second;
if(!laser)
continue;
++numLasers;
laser->lockDevice();
// The current readings are a set of obstacle readings (with X,Y positions as well as other attributes) that are the most recent set from teh laser.
std::list<ArPoseWithTime*> *currentReadings = laser->getCurrentBuffer(); // see ArRangeDevice interface doc
// The raw readings are just range or other data supplied by the sensor. It may also include some device-specific extra values associated with each reading as well. (e.g. Reflectance for LMS200)
const std::list<ArSensorReading*> *rawReadings = laser->getRawReadings();
// There is a utility to find the closest reading wthin a range of degrees around the laser, here we use this laser's full field of view (start to end)
// If there are no valid closest readings within the given range, dist will be greater than laser->getMaxRange().
double angle = 0;
double dist = laser->currentReadingPolar(laser->getStartDegrees(), laser->getEndDegrees(), &angle);
ArLog::log(ArLog::Normal, "Laser #%d (%s): %s.\n\tHave %d 'current' readings.\n\tHave %d 'raw' readings.\n\tClosest reading is at %3.0f degrees and is %2.4f meters away.",
laserIndex, laser->getName(), (laser->isConnected() ? "connected" : "NOT CONNECTED"),
currentReadings->size(),
rawReadings->size(),
angle, dist/1000.0);
laser->unlockDevice();
}
if(numLasers == 0)
ArLog::log(ArLog::Normal, "No lasers.");
else
ArLog::log(ArLog::Normal, "");
// Unlock robot and sleep for 5 seconds before next loop.
robot.unlock();
ArUtil::sleep(5000);
}
//.........这里部分代码省略.........
示例2: main
//.........这里部分代码省略.........
// Set up the map object, this will look for files in the examples
// directory (unless the file name starts with a /, \, or .
// You can take out the 'fileDir' argument to look in the program's current directory
// instead.
// When a configuration file is loaded into ArConfig later, if it specifies a
// map file, then that file will be loaded as the map.
ArMap map(fileDir);
// set it up to ignore empty file names (otherwise if a configuration omits
// the map file, the whole configuration change will fail)
map.setIgnoreEmptyFileName(true);
// ignore the case, so that if someone is using MobileEyes or
// MobilePlanner from Windows and changes the case on a map name,
// it will still work.
map.setIgnoreCase(true);
/* Create localization and path planning threads */
ArPathPlanningTask pathTask(&robot, &sonarDev, &map);
ArLog::log(ArLog::Normal, "Creating laser localization task");
// Laser Monte-Carlo Localization
ArLocalizationTask locTask(&robot, firstLaser, &map);
// Set some options on each laser that the laser connector
// connected to.
std::map<int, ArLaser *>::iterator laserIt;
for (laserIt = robot.getLaserMap()->begin();
laserIt != robot.getLaserMap()->end();
laserIt++)
{
int laserNum = (*laserIt).first;
ArLaser *laser = (*laserIt).second;
// Skip lasers that aren't connected
if(!laser->isConnected())
continue;
// add the disconnectOnError CB to shut things down if the laser
// connection is lost
laser->addDisconnectOnErrorCB(&shutdownFunctor);
// set the number of cumulative readings the laser will take
laser->setCumulativeBufferSize(200);
// add the lasers to the path planning task
pathTask.addRangeDevice(laser, ArPathPlanningTask::BOTH);
// set the cumulative clean offset (so that they don't all fire at once)
laser->setCumulativeCleanOffset(laserNum * 100);
// reset the cumulative clean time (to make the new offset take effect)
laser->resetLastCumulativeCleanTime();
// Add the packet count to the Aria info strings (It will be included in
// MobileEyes custom details so you can monitor whether the laser data is
// being received correctly)
std::string laserPacketCountName;
laserPacketCountName = laser->getName();
laserPacketCountName += " Packet Count";
Aria::getInfoGroup()->addStringInt(
laserPacketCountName.c_str(), 10,
new ArRetFunctorC<int, ArLaser>(laser,
&ArLaser::getReadingCount));
示例3: main
//.........这里部分代码省略.........
#ifndef ARNL_GPSLOC
// A callback function, which is called if localization fails
ArGlobalFunctor1<int> locFailedCB(&locFailed);
locTask.setFailedCallBack(&locFailedCB); //, &locTask);
#endif
#ifdef ARNL_GPSLOC
ArLog::log(ArLog::Normal, "Connecting to GPS...");
// Connect to GPS
ArGPS *gps = gpsConnector.createGPS(&robot);
if(!gps || !gps->connect())
{
ArLog::log(ArLog::Terse, "Error connecting to GPS device."
"Try -gpsType, -gpsPort, and/or -gpsBaud command-line arguments."
"Use -help for help. Exiting.");
Aria::exit(5);
}
// set up GPS localization task
ArLog::log(ArLog::Normal, "Creating GPS localization task");
ArGPSLocalizationTask gpsLocTask(&robot, gps, &map);
#ifdef ARNL_MULTILOC
locManager.addLocalizationTask(&gpsLocTask);
#else
#define LOCTASK gpsLocTask
#endif
#endif
#ifdef ARNL_LASER
// Set some options and callbacks on each laser that the laser connector
// connected to.
std::map<int, ArLaser *>::iterator laserIt;
for (laserIt = robot.getLaserMap()->begin();
laserIt != robot.getLaserMap()->end();
laserIt++)
{
int laserNum = (*laserIt).first;
ArLaser *laser = (*laserIt).second;
// Skip lasers that aren't connected
if(!laser->isConnected())
continue;
// add the disconnectOnError CB to shut things down if the laser
// connection is lost
laser->addDisconnectOnErrorCB(&shutdownFunctor);
// set the number of cumulative readings the laser will take
laser->setCumulativeBufferSize(200);
// set the cumulative clean offset (so that they don't all fire at once)
laser->setCumulativeCleanOffset(laserNum * 100);
// reset the cumulative clean time (to make the new offset take effect)
laser->resetLastCumulativeCleanTime();
// Add the packet count to the Aria info strings (It will be included in
// MobileEyes custom details so you can monitor whether the laser data is
// being received correctly)
std::string laserPacketCountName;
laserPacketCountName = laser->getName();
laserPacketCountName += " Packet Count";
Aria::getInfoGroup()->addStringInt(
laserPacketCountName.c_str(), 10,
new ArRetFunctorC<int, ArLaser>(laser,
&ArLaser::getReadingCount));
}
#endif