Aria  2.8.0
ArBatteryConnector Class Reference

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...
 
ArBatteryMTXgetBattery (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< ArBatteryConnectormyLogOptionsCB
 
bool myOwnParser
 
ArRetFunctorC< bool, ArBatteryConnectormyParseArgsCB
 
bool myParsedArgs
 
ArArgumentParsermyParser
 
ArRobotmyRobot
 
ArRobotConnectormyRobotConnector
 

Detailed Description

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().

Since
2.8.0

Constructor & Destructor Documentation

◆ ArBatteryConnector()

ArBatteryConnector::ArBatteryConnector ( ArArgumentParser parser,
ArRobot robot,
ArRobotConnector robotConnector,
bool  autoParseArgs = true,
ArLog::LogLevel  infoLogLevel = ArLog::Verbose 
)

Constructor that takes argument parser.

Warning
do not delete parser during the lifetime of this ArBatteryConnector, which may need to access its contents later.
Parameters
parserthe parser with the arguments to parse
robotthe robot these batteries 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 batteries and such, this is also passed to all the batteries created as their infoLogLevel too

Member Function Documentation

◆ addBattery()

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.()

◆ connectBattery()

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().

◆ parseArgs() [1/2]

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.

Returns
true if the arguments were parsed successfully false if not

◆ parseArgs() [2/2]

bool ArBatteryConnector::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 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".

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

◆ setupBattery()

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().


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