example showing how to connect to laser rangefinders attached to the robot and retrieve data from them. What kinds of laser or lasers are connected to the robot, and their parameters, are loaded from the robot's parameter file in the params directory. First the default for this type of mobile robot is loaded (e.g. p3dx-sh.p for a Pioneer 3 DX), followed by a parameter file specific to this individual robot (based on its 'name'), if such a parameter file exists. Laser parameters may also be given as command line options, use the -help option to list them. This program will only connect to any lasers that have LaserAutoConnect true in the parameter file, or if the -connectLaser or -cl command-line options are given. You may need to edit the parameter file for your robot to set LaserAutoConnect to true.
TODO: show how to force laser connect even if autoconnect is false.
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.)
#include "Aria.h"
int main(int argc, char **argv)
{
{
{
}
}
{
return 2;
}
{
return 3;
}
{
int numLasers = 0;
for(std::map<int, ArLaser*>::const_iterator i = lasers->begin(); i != lasers->end(); ++i)
{
int laserIndex = (*i).first;
if(!laser)
continue;
++numLasers;
double angle = 0;
ArLog::log(
ArLog::Normal,
"Laser #%d (%s): %s. Have %d 'current' readings. Closest reading is at %3.0f degrees and is %2.4f meters away.", laserIndex, laser->
getName(), (laser->
isConnected() ?
"connected" :
"NOT CONNECTED"), currentReadings->size(), angle, dist/1000.0);
}
if(numLasers == 0)
else
}
return 0;
}
bool connectRobot(void)
Sets up the robot then connects it.
Definition: ArRobotConnector.cpp:405
const std::map< int, ArLaser * > * getLaserMap(void) const
Gets the range device list.
Definition: ArRobot.cpp:6932
void loadDefaultArguments(int positon=1)
Adds args from default files and environmental variables.
Definition: ArArgumentParser.cpp:736
virtual double currentReadingPolar(double startAngle, double endAngle, double *angle=NULL) const
Gets the closest current reading in the given polar region.
Definition: ArRangeDevice.cpp:304
Use terse logging.
Definition: ArLog.h:61
Connect to robot or simulator based on program command line parameters.
Definition: ArRobotConnector.h:80
bool isConnected(void) const
Questions whether the robot is connected or not.
Definition: ArRobot.h:133
static void exit(int exitCode=0)
Shutdown all Aria processes/threads, call exit callbacks, and exit the program.
Definition: Aria.cpp:367
static void log(LogLevel level, const char *str,...)
Log a message, with formatting and variable number of arguments.
Definition: ArLog.cpp:93
Create laser interface objects (for any kind of laser supported by ARIA) and connect to lasers based ...
Definition: ArLaserConnector.h:80
static void init(SigHandleMethod method=SIGHANDLE_THREAD, bool initSockets=true, bool sigHandleExitNotShutdown=true)
Initialize Aria global data struture and perform OS-specific initialization, including adding OS sign...
Definition: Aria.cpp:128
bool checkHelpAndWarnUnparsed(unsigned int numArgsOkay=0)
Checks for the help strings and warns about unparsed arguments.
Definition: ArArgumentParser.cpp:843
Central class for communicating with and operating the robot.
Definition: ArRobot.h:82
Parse and store program command-line arguments for use by other ARIA classes.
Definition: ArArgumentParser.h:64
static void logOptions(void)
Logs all the options for the program (Calls all the callbacks added with addLogOptionsCB())
Definition: Aria.cpp:794
virtual bool isConnected(void)=0
See if the laser is connected.
virtual const char * getName(void) const
Gets the name of the device.
Definition: ArRangeDevice.cpp:135
static bool init(LogType type, LogLevel level, const char *fileName="", bool logTime=false, bool alsoPrint=false, bool printThisCall=true)
Initialize the logging utility with options.
Definition: ArLog.cpp:437
Use stderr for logging.
Definition: ArLog.h:55
void runAsync(bool stopRunIfNotConnected, bool runNonThreadedPacketReader=false)
Starts the instance to do processing in its own new thread.
Definition: ArRobot.cpp:301
int unlock()
Unlock the robot instance.
Definition: ArRobot.h:1272
static bool parseArgs(void)
Parses the arguments for the program (calls all the callbacks added with addParseArgsCB())
Definition: Aria.cpp:759
static void sleep(unsigned int ms)
Sleep for the given number of milliseconds.
Definition: ariaUtil.cpp:151
bool connectLasers(bool continueOnFailedConnect=false, bool addConnectedLasersToRobot=true, bool addAllLasersToRobot=false, bool turnOnLasers=true, bool powerCycleLaserOnFailedConnect=true, int *failedOnLaser=NULL)
Connects all the lasers the robot has that should be auto connected.
Definition: ArLaserConnector.cpp:1213
virtual const std::list< ArPoseWithTime * > * getCurrentBuffer(void) const
Gets the current buffer of readings.
Definition: ArRangeDevice.h:140
Use normal logging.
Definition: ArLog.h:62
Use verbose logging.
Definition: ArLog.h:63
double getEndDegrees(void)
Gets the end angle.
Definition: ArLaser.h:271
int lock()
Lock the robot instance.
Definition: ArRobot.h:1268
double getStartDegrees(void)
Gets the start angle.
Definition: ArLaser.h:259
Range device interface specialized for laser rangefinder sensors.
Definition: ArLaser.h:111