Aria  2.8.0
ArSonarConnector Class Reference

Connect to sonar based on robot parameters and command-line arguments. More...

#include <ArSonarConnector.h>

Classes

class  SonarData
 Class that holds information about the sonar data. More...
 

Public Member Functions

bool addSonar (ArSonarMTX *sonar, int sonarNumber=1)
 Adds a sonar so parsing will get it. More...
 
 ArSonarConnector (ArArgumentParser *parser, ArRobot *robot, ArRobotConnector *robotConnector, bool autoParseArgs=true, ArLog::LogLevel infoLogLevel=ArLog::Verbose, ArRetFunctor1< bool, const char *> *turnOnPowerOutputCB=NULL, ArRetFunctor1< bool, const char *> *turnOffPowerOutputCB=NULL)
 Constructor that takes argument parser. More...
 
bool connectReplaySonars (bool continueOnFailedConnect=false, bool addConnectedSonarsToRobot=true, bool addAllSonarsToRobot=false, bool turnOnSonars=true, bool powerCycleSonarOnFailedConnect=true)
 
bool connectSonar (ArSonarMTX *sonar, int sonarNumber=1, bool forceConnection=true)
 Connects the sonar synchronously (will take up to a minute) More...
 
bool connectSonars (bool continueOnFailedConnect=false, bool addConnectedSonarsToRobot=true, bool addAllSonarsToRobot=false, bool turnOnSonars=true, bool powerCycleSonarOnFailedConnect=true)
 Connects all the sonars the robot has that should be auto connected.
 
ArSonarMTXgetSonar (int sonarNumber)
 Internal function to get the sonar (only useful between parseArgs and connectSonars)
 
void logOptions (void) const
 Log the options the simple connector has.
 
bool parseArgs (void)
 Function to parse the arguments given in the constructor. More...
 
bool parseArgs (ArArgumentParser *parser)
 Function to parse the arguments given in an arbitrary parser. More...
 
bool replaceSonar (ArSonarMTX *sonar, int sonarNumber)
 Internal function to replace the sonar (only useful between parseArgs and connectSonars) but not the sonar data.
 
bool setupSonar (ArSonarMTX *sonar, int sonarNumber=1)
 Sets up a sonar to be connected. More...
 
 ~ArSonarConnector (void)
 Destructor.
 

Protected Member Functions

bool internalConfigureSonar (SonarData *sonarData)
 
void logSonarOptions (SonarData *sonardata, bool header=true, bool metaOpts=true) const
 Logs the sonar command line option help text.
 
bool parseSonarArgs (ArArgumentParser *parser, SonarData *sonarData)
 Parses the sonar arguments.
 
bool turnOnPower (SonarData *sonarData)
 Turns on the power for the specific board in the firmware. More...
 

Protected Attributes

bool myAutoParseArgs
 
ArLog::LogLevel myInfoLogLevel
 
ArConstFunctorC< ArSonarConnectormyLogOptionsCB
 
bool myOwnParser
 
ArRetFunctorC< bool, ArSonarConnectormyParseArgsCB
 
bool myParsedArgs
 
ArArgumentParsermyParser
 
ArRobotmyRobot
 
ArRobotConnectormyRobotConnector
 
bool mySonarLogPacketsReceived
 
bool mySonarLogPacketsSent
 
std::map< int, SonarData * > mySonars
 
std::string mySonarTypes
 
ArRetFunctor1< bool, const char * > * myTurnOffPowerOutputCB
 
ArRetFunctor1< bool, const char * > * myTurnOnPowerOutputCB
 

Detailed Description

Connect to sonar based on robot parameters and command-line arguments.

ArSonarConnector makes a sonar connection either through a serial port connection. When you create your ArSonarConnector, 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()). ArSonarConnector 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:

Options for ArSonarConnector:
-sonarLogPacketsReceived
-slpr
-sonarLogPacketsSent
-slps

Options shown are for currently set up sonars.  Activate sonars with -sonarType<N> option
to see options for that sonar (e.g. "-help -sonarType1 sonarMTX").
Valid sonar types are: mtx

See docs for details.

To connect to any sonars that were set up in the robot parameter file or via command line arguments, call connectSonars(). If successful, connectSonars() will return true and add an entry for each sonar connected in the ArRobot object's list of sonars. These ArSonarMTX objects can be accessed from your ArRobot object via ArRobot::findSonar() or ArRobot::getSonarMap().

Since
2.8.0

Constructor & Destructor Documentation

◆ ArSonarConnector()

ArSonarConnector::ArSonarConnector ( ArArgumentParser parser,
ArRobot robot,
ArRobotConnector robotConnector,
bool  autoParseArgs = true,
ArLog::LogLevel  infoLogLevel = ArLog::Verbose,
ArRetFunctor1< bool, const char *> *  turnOnPowerOutputCB = NULL,
ArRetFunctor1< bool, const char *> *  turnOffPowerOutputCB = NULL 
)

Constructor that takes argument parser.

Warning
do not delete parser during the lifetime of this ArSonarConnector, which may need to access its contents later.
Parameters
parserthe parser with the arguments to parse
robotthe robot these sonars are attached to (or NULL for none)
robotConnectorthe connector used for connecting to the robot (so we can see if it was a sim or not)
autoParseArgsif this class should autoparse the args if they aren't parsed explicitly
infoLogLevelThe log level for information about creating sonars and such, this is also passed to all the sonars created as their infoLogLevel too

Member Function Documentation

◆ addSonar()

bool ArSonarConnector::addSonar ( ArSonarMTX sonar,
int  sonarNumber = 1 
)

Adds a sonar so parsing will get it.

Normally adding sonars 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 ArSonarConnector::connectSonars.()

◆ connectSonar()

bool ArSonarConnector::connectSonar ( ArSonarMTX sonar,
int  sonarNumber = 1,
bool  forceConnection = true 
)

Connects the sonar 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 ArSonarConnector::connectSonars().

◆ parseArgs() [1/2]

bool ArSonarConnector::parseArgs ( void  )

Function to parse the arguments given in the constructor.

Parse command line arguments using the ArArgumentParser given in the ArSonarConnector constructor.

See parseArgs(ArArgumentParser*) for details about argument parsing.

Returns
true if the arguments were parsed successfully false if not

◆ parseArgs() [2/2]

bool ArSonarConnector::parseArgs ( ArArgumentParser parser)

Function to parse the arguments given in an arbitrary parser.

Parse command line arguments held by the given ArArgumentParser.

Returns
true if the arguments were parsed successfully false if not

The following arguments are accepted for sonar connections. A program may request support for more than one sonar using setMaxNumSonarBoards(); if multi-sonar support is enabled in this way, then these arguments must have the sonar index number appended. For example, "-sonarPort" for sonar 1 would instead by "-sonarPort1", and for sonar 2 it would be "-sonarPort2".

-sonarPort port
-sp port
Use the given port device name when connecting to a sonar. For example, COM2 or on Linux, /dev/ttyS1. The default sonar port is COM2, which is the typical Pioneer sonar port setup.
-connectSonar
-sl
Explicitly request that the client program connect to a sonar, if it does not always do so

◆ setupSonar()

bool ArSonarConnector::setupSonar ( ArSonarMTX sonar,
int  sonarNumber = 1 
)

Sets up a sonar 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 ArSonarConnector::connectSonars().

◆ turnOnPower()

bool ArSonarConnector::turnOnPower ( SonarData sonarData)
protected

Turns on the power for the specific board in the firmware.

MPL the new way


The documentation for this class was generated from the following files: