Aria
2.8.0
|
Connect to robot and battery based on run-time availablitily and command-line arguments. More...
#include <ArBatteryConnector.h>
Classes | |
class | BatteryData |
Class that holds information about the battery data. More... | |
Public Member Functions | |
bool | addBattery (ArBatteryMTX *battery, int batteryNumber=1) |
Adds a battery so parsing will get it. More... | |
ArBatteryConnector (ArArgumentParser *parser, ArRobot *robot, ArRobotConnector *robotConnector, bool autoParseArgs=true, ArLog::LogLevel infoLogLevel=ArLog::Verbose) | |
Constructor that takes argument parser. More... | |
bool | connectBatteries (bool continueOnFailedConnect=false, bool addConnectedBatteriesToRobot=true, bool addAllBatteriesToRobot=false, bool turnOnBatteries=true, bool powerCycleBatteryOnFailedConnect=true) |
Connects all the batteries the robot has that should be auto connected. | |
bool | connectBattery (ArBatteryMTX *battery, int batteryNumber=1, bool forceConnection=true) |
Connects the battery synchronously (will take up to a minute) More... | |
ArBatteryMTX * | getBattery (int batteryNumber) |
Internal function to get the battery (only useful between parseArgs and connectBatteries) | |
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 | replaceBattery (ArBatteryMTX *battery, int batteryNumber) |
Internal function to replace the battery (only useful between parseArgs and connectBatteries) but not the battery data. | |
bool | setupBattery (ArBatteryMTX *battery, int batteryNumber=1) |
Sets up a battery to be connected. More... | |
~ArBatteryConnector (void) | |
Destructor. | |
Protected Member Functions | |
bool | internalConfigureBattery (BatteryData *batteryData) |
void | logBatteryOptions (BatteryData *batterydata, bool header=true, bool metaOpts=true) const |
Logs the battery command line option help text. | |
bool | parseBatteryArgs (ArArgumentParser *parser, BatteryData *batteryData) |
Parses the battery arguments. | |
Protected Attributes | |
bool | myAutoParseArgs |
std::map< int, BatteryData * > | myBatteries |
bool | myBatteryLogPacketsReceived |
bool | myBatteryLogPacketsSent |
std::string | myBatteryTypes |
ArLog::LogLevel | myInfoLogLevel |
ArConstFunctorC< ArBatteryConnector > | myLogOptionsCB |
bool | myOwnParser |
ArRetFunctorC< bool, ArBatteryConnector > | myParseArgsCB |
bool | myParsedArgs |
ArArgumentParser * | myParser |
ArRobot * | myRobot |
ArRobotConnector * | myRobotConnector |
Connect to robot and battery based on run-time availablitily and command-line arguments.
ArBatteryConnector makes a battery connection either through a serial port connection, or through a TCP port (for the simulator or for robots with Ethernet-serial bridge devices instead of onboard computers). 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 Various connection parameters are configurable through command-line arguments or in the robot parameter file. (Though the internal interface used by ARIA to do this is also available if you need to use it: See addBattery(); otherwise don't use addBattery(), setupBattery(), etc.).
When you create your ArBatteryConnector, 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()). ArBatteryConnector 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:
To connect to any batteries that were set up in the robot parameter file or via command line arguments, call connectBatteries(). If successful, connectBatteries() will return true and add an entry for each battery connected in the ArRobot object's list of batteries. These ArBatteryMTX objects can be accessed from your ArRobot object via ArRobot::findBattery() or ArRobot::getBatteryMap().
ArBatteryConnector::ArBatteryConnector | ( | 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 batteries 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 batteries and such, this is also passed to all the batteries created as their infoLogLevel too |
bool ArBatteryConnector::addBattery | ( | ArBatteryMTX * | battery, |
int | batteryNumber = 1 |
||
) |
Adds a battery so parsing will get it.
Normally adding batteries 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 ArBatteryConnector::connectBatteries.()
bool ArBatteryConnector::connectBattery | ( | ArBatteryMTX * | battery, |
int | batteryNumber = 1 , |
||
bool | forceConnection = true |
||
) |
Connects the battery 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 ArBatteryConnector::connectBatteries().
bool ArBatteryConnector::parseArgs | ( | void | ) |
Function to parse the arguments given in the constructor.
Parse command line arguments using the ArArgumentParser given in the ArBatteryConnector constructor.
See parseArgs(ArArgumentParser*) for details about argument parsing.
bool ArBatteryConnector::parseArgs | ( | ArArgumentParser * | parser | ) |
Function to parse the arguments given in an arbitrary parser.
Parse command line arguments held by the given ArArgumentParser.
The following arguments are accepted for battery connections. A program may request support for more than one battery using setMaxNumBatteries(); if multi-battery support is enabled in this way, then these arguments must have the battery index number appended. For example, "-batteryPort" for battery 1 would instead by "-batteryPort1", and for battery 2 it would be "-batteryPort2".
COM2
or on Linux, /dev/ttyS1
. The default battery port is COM2, which is the typical Pioneer battery port setup. bool ArBatteryConnector::setupBattery | ( | ArBatteryMTX * | battery, |
int | batteryNumber = 1 |
||
) |
Sets up a battery 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 ArBatteryConnector::connectBatteries().