#include <ArLaserConnector.h>
ArLaserConnector makes a laser connection either through a TCP port (for the simulator or for robots with Ethernet-serial bridge devices instead of onboard computers), or through a direct serial port connection. Normally, it first attempts a TCP connection on localhost port 8101, to use a simulator if running. If the simulator is not running, then it normally then connects using the serial port (the first serial port, COM1, by default). Various other connection parameters are configurable through command-line arguments.
When you create your ArLaserConnector, pass it command line parameters via either the argc and argv variables from main(), or pass it an ArArgumentBuilder or ArArgumentParser object. (ArArgumentBuilder is able to obtain command line parameters from a Windows program that uses WinMain() instead of main()). ArLaserConnector registers a callback with the global Aria class. Use Aria::parseArgs() to parse all command line parameters to the program, and Aria::logOptions() to print out information about all registered command-line parameters.
The following command-line arguments are checked:
Laser types and options may also be set in the robot parameter file. See the ARIA reference documentation for details. If a program supports multiple lasers, then options for additional lasers after the first are given by appending the laser number (e.g. -laserType2) To enable use of a laser, choose its type with the -laserType<N> options (e.g.: -laserType lms2xx -laserType2 urg) The default laser type for the primary laser (laser 1) is "lms2xx". Instruct a program to connect to a laser using the -connectLaser<N> option; if a program requires use of a laser it usually always attempts to connect to the primary laser, however. The index number is optional in options for the primary laser (laser 1). For laser type "lms2xx": -laserPort <laserPort> -lp <laserPort> -laserPortType <serial|tcp> -lpt <serial|tcp> -remoteLaserTcpPort <remoteLaserTcpPort> -rltp <remoteLaserTcpPort> -laserFlipped <true|false> -lf <true|false> -laserMaxRange <maxRange> -lmr <maxRange> <maxRange> is an unsigned int less than 32000 -laserDegrees <100|180> -ld <100|180> -laserIncrement <half|one> -li <half|one> -laserUnits <1mm|1cm|10cm> -lu <1mm|1cm|10cm> -laserReflectorBits <1ref|2ref|3ref> -lrb <1ref|2ref|3ref> -laserPowerControlled <true|false> -lpc <true|false> -laserStartingBaud <9600|19200|38400> -lsb <9600|19200|38400> -laserAutoBaud <9600|19200|38400> -lab <9600|19200|38400> -laserAdditionalIgnoreReadings <readings> -lair <readings> <readings> is a string that contains readings to ignore separated by commas, where ranges are acceptable with a -, example '75,76,90-100,-75,-76,-90--100' For laser type "urg": -laserPort <laserPort> -lp <laserPort> -laserPortType <serial|tcp> -lpt <serial|tcp> -remoteLaserTcpPort <remoteLaserTcpPort> -rltp <remoteLaserTcpPort> -laserFlipped <true|false> -lf <true|false> -laserMaxRange <maxRange> -lmr <maxRange> <maxRange> is an unsigned int less than 4095 -laserDegreesStart <startAngle> -lds <startAngle> <startAngle> is a double between -135 and 135 -laserDegreesEnd <endAngle> -lde <endAngle> <endAngle> is a double between -135 and 135 -laserIncrementByDegrees <incrementByDegrees> -libd <incrementByDegrees> <incrementByDegrees> is a double between 0 and 135 -laserStartingBaud <019200|057600|115200|250000|500000|750000> -lsb <019200|057600|115200|250000|500000|750000> -laserAutoBaud <019200|057600|115200|250000|500000|750000> -lab <019200|057600|115200|250000|500000|750000> -laserAdditionalIgnoreReadings <readings> -lair <readings> <readings> is a string that contains readings to ignore separated by commas, where ranges are acceptable with a -, example '75,76,90-100,-75,-76,-90--100'
You can prepare an ArRobot object for connection (with various connection options configured via the command line parameters) and initiate the connection attempt by that object by calling connectRobot().
After it's connected, you must then begin the robot processing cycle by calling ArRobot::runAsync() or ArRobot::run().
You can then configure ArLaserConnector for the SICK laser based on the robot connection, and command line parameters with setupLaser(). After calling setupLaser(), you must then run the laser processing thread (with ArLaser::runAsync() or ArLaser()run()) and then use ArLaserConnector::connectLaser() to connect with the laser if specifically requested on the command line using the -connectLaser option (or simply call ArLaser::blockingConnect() (or similar) to attempt a laser connection regardless of whether or not the -connectLaser option was given; use this latter technique if your program always prefers or requires use of the laser).
demo.cpp, and wander.cpp.
Public Member Functions | |
| bool | addLaser (ArLaser *laser, int laserNumber=1) |
| Adds a laser so parsing will get it. | |
| bool | addPlaceholderLaser (ArLaser *placeholderLaser, int laserNumber=1, bool takeOwnershipOfPlaceholder=false) |
| Adds a laser for parsing but where connectLaser will be called later. | |
| ArLaserConnector (ArArgumentParser *parser, ArRobot *robot, ArRobotConnector *robotConnector, bool autoParseArgs=true, ArLog::LogLevel infoLogLevel=ArLog::Verbose) | |
| Constructor that takes argument parser. | |
| bool | connectLaser (ArLaser *laser, int laserNumber=1, bool forceConnection=true) |
| Connects the laser synchronously (will take up to a minute). | |
| bool | connectLasers (bool continueOnFailedConnect=false, bool addConnectedLasersToRobot=true, bool addAllLasersToRobot=false, bool turnOnLasers=true, bool powerCycleLaserOnFailedConnect=true) |
| Connects all the lasers the robot has that should be auto connected. | |
| void | logOptions (void) const |
| Log the options the simple connector has. | |
| bool | parseArgs (ArArgumentParser *parser) |
| Function to parse the arguments given in an arbitrary parser. | |
| bool | parseArgs (void) |
| Function to parse the arguments given in the constructor. | |
| bool | setupLaser (ArLaser *laser, int laserNumber=1) |
| Sets up a laser to be connected. | |
| ~ArLaserConnector (void) | |
| Destructor. | |
Protected Member Functions | |
| bool | internalConfigureLaser (LaserData *laserData) |
| void | logLaserOptions (LaserData *laserdata, bool header=true, bool metaOpts=true) const |
| Logs the laser command line option help text. | |
| bool | parseLaserArgs (ArArgumentParser *parser, LaserData *laserData) |
| Parses the laser arguments. | |
Protected Attributes | |
| bool | myAutoParseArgs |
| ArLog::LogLevel | myInfoLogLevel |
| std::map< int, LaserData * > | myLasers |
| std::string | myLaserTypes |
| ArConstFunctorC< ArLaserConnector > | myLogOptionsCB |
| bool | myOwnParser |
| ArRetFunctorC< bool, ArLaserConnector > | myParseArgsCB |
| bool | myParsedArgs |
| ArArgumentParser * | myParser |
| ArRobot * | myRobot |
| ArRobotConnector * | myRobotConnector |
Classes | |
| class | LaserData |
| Class that holds information about the laser data. More... | |
| ArLaserConnector::ArLaserConnector | ( | ArArgumentParser * | parser, | |
| ArRobot * | robot, | |||
| ArRobotConnector * | robotConnector, | |||
| bool | autoParseArgs = true, |
|||
| ArLog::LogLevel | infoLogLevel = ArLog::Verbose | |||
| ) |
Constructor that takes argument parser.
| parser | the parser with the arguments to parse | |
| robot | the robot these lasers are attached to (or NULL for none) | |
| robotConnector | the connector used for connecting to the robot (so we can see if it was a sim or not) | |
| autoParseArgs | if this class should autoparse the args if they aren't parsed explicitly | |
| infoLogLevel | The log level for information about creating lasers and such, this is also passed to all the lasers created as their infoLogLevel too |
| bool ArLaserConnector::addLaser | ( | ArLaser * | laser, | |
| int | laserNumber = 1 | |||
| ) |
Adds a laser so parsing will get it.
Normally adding lasers is done from the .p file, you can use this if you want to add them explicitly in a program (which will override the .p file, and may cause some problems).
This is mainly for backwards compatibility (ie used for ArSimpleConnector). If you're using this class you should probably use the new functionality which is just ArLaserConnector::connectLasers.
| bool ArLaserConnector::addPlaceholderLaser | ( | ArLaser * | placeholderLaser, | |
| int | laserNumber = 1, |
|||
| bool | takeOwnershipOfPlaceholder = false | |||
| ) |
Adds a laser for parsing but where connectLaser will be called later.
Normally adding lasers is done from the .p file, you can use this if you want to add them explicitly in a program (which will override the .p file, and may cause some problems).
This is only for backwards compatibility (ie used for ArSimpleConnector). If you're using this class you should probably use the new functionality which is just ArLaserConnector::connectLasers.
| bool ArLaserConnector::connectLaser | ( | ArLaser * | laser, | |
| int | laserNumber = 1, |
|||
| bool | forceConnection = true | |||
| ) |
Connects the laser synchronously (will take up to a minute).
This is mainly for backwards compatibility (ie used for ArSimpleConnector). If you're using this class you should probably use the new functionality which is just ArLaserConnector::connectLasers.
| bool ArLaserConnector::connectLasers | ( | bool | continueOnFailedConnect = false, |
|
| bool | addConnectedLasersToRobot = true, |
|||
| bool | addAllLasersToRobot = false, |
|||
| bool | turnOnLasers = true, |
|||
| bool | powerCycleLaserOnFailedConnect = true | |||
| ) |
Connects all the lasers the robot has that should be auto connected.
TODO see if this firmware can actually do the power cycling
| bool ArLaserConnector::parseArgs | ( | ArArgumentParser * | parser | ) |
Function to parse the arguments given in an arbitrary parser.
Parse command line arguments held by the given ArArgumentParser.
-robotPort port -rp port COM1, or /dev/ttyS0 if on Linux.) The default is the first serial port, or COM1, which is the typical Pioneer setup. The following arguments are accepted for laser connections. A program may request support for more than one laser using setMaxNumLasers(); if multi-laser support is enabled in this way, then these arguments must have the laser index number appended. For example, "-laserPort" for laser 1 would instead by "-laserPort1", and for laser 2 it would be "-laserPort2".
COM2 or on Linux, /dev/ttyS1. The default laser port is COM2, which is the typical Pioneer laser port setup.
true, then the laser is mounted upside-down on the robot and the ordering of readings should be reversed.
true, then the laser is powered on when the serial port is initially opened, so enable certain features when connecting such as a waiting period as the laser initializes.
180 (default) or 100.
one, then configure the laser to take a reading every degree. If half, then configure it for a reading every 1/2 degrees.
| bool ArLaserConnector::parseArgs | ( | void | ) |
Function to parse the arguments given in the constructor.
Parse command line arguments using the ArArgumentParser given in the ArLaserConnector constructor.
See parseArgs(ArArgumentParser*) for details about argument parsing.
| bool ArLaserConnector::setupLaser | ( | ArLaser * | laser, | |
| int | laserNumber = 1 | |||
| ) |
Sets up a laser to be connected.
This is mainly for backwards compatibility (ie used for ArSimpleConnector). If you're using this class you should probably use the new functionality which is just ArLaserConnector::connectLasers.
1.4.7