Aria
2.8.0
|
Connect to robot or simulator based on program command line parameters. More...
#include <ArRobotConnector.h>
Public Member Functions | |
ArRobotConnector (ArArgumentParser *parser, ArRobot *robot, bool autoParseArgs=true, bool connectAllComponents=true) | |
Constructor that takes argument parser. More... | |
bool | connectRobot (void) |
Sets up the robot then connects it. More... | |
bool | connectRobot (ArRobot *robot) |
Sets up the robot then connects it. More... | |
const char * | getRemoteHost (void) const |
Gets the remote host, if one was used, or NULL if it wasn't. | |
bool | getRemoteIsSim (void) const |
Gets if the remote connection is a sim. | |
ArRobot * | getRobot (void) |
Gets the robot this connector is using (mostly for backwards compatibility stuff) | |
void | logOptions (void) const |
Log the options the simple connector has. More... | |
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... | |
void | setRemoteIsSim (bool remoteIsSim) |
Call for forcing the remote to be a sim (mostly for internal use) | |
bool | setupRobot (void) |
Sets up the given robot to be connected. More... | |
bool | setupRobot (ArRobot *robot) |
Sets up an arbitrary robot to be connected. More... | |
~ArRobotConnector (void) | |
Destructor. | |
Protected Attributes | |
bool | myAutoParseArgs |
ArBatteryConnector * | myBatteryConnector |
bool | myConnectAllComponents |
bool | myHaveParsedArgs |
ArConstFunctorC< ArRobotConnector > | myLogOptionsCB |
bool | myOwnParser |
ArRetFunctorC< bool, ArRobotConnector > | myParseArgsCB |
ArArgumentParser * | myParser |
const char * | myRemoteHost |
bool | myRemoteIsNotSim |
bool | myRemoteIsSim |
int | myRemoteRobotTcpPort |
ArRobot * | myRobot |
int | myRobotBaud |
bool | myRobotLogActions |
bool | myRobotLogMovementReceived |
bool | myRobotLogMovementSent |
bool | myRobotLogPacketsReceived |
bool | myRobotLogPacketsSent |
bool | myRobotLogVelocitiesReceived |
const char * | myRobotPort |
ArSerialConnection | myRobotSerConn |
ArTcpConnection | myRobotTcpConn |
ArSonarConnector * | mySonarConnector |
bool | myUsingSim |
Connect to robot or simulator based on program command line parameters.
ArRobotConnector makes a robot 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 ArRobotConnector, 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()). ArRobotConnector 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 ArRobotConnector (see docs for more details): Robot options: -remoteHost <remoteHostNameOrIP> -rh <remoteHostNameOrIP> -robotPort <robotSerialPort> -rp <robotSerialPort> -robotBaud <baud> -rb <baud> -remoteRobotTcpPort <remoteRobotTcpPort> -rrtp <remoteRobotTcpPort> -remoteIsSim -ris -remoteIsNotSim -rins -robotLogPacketsReceived -rlpr -robotLogPacketsSent -rlps -robotLogMovementReceived -rlmr -robotLogMovementSent -rlms -robotLogVelocitiesReceived -rlvr -robotLogActions -rla
You can then 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().
ArRobotConnector::ArRobotConnector | ( | ArArgumentParser * | parser, |
ArRobot * | robot, | ||
bool | autoParseArgs = true , |
||
bool | connectAllComponents = true |
||
) |
Constructor that takes argument parser.
parser | argument parser object (see parseArgs() for list of command line arguments recognized) |
robot | ArRobot object to connect to the robot |
autoParseArgs | if true (default), trigger argument parsing before connection if not already done. (normally, a program will call Aria::parseArgs() to trigger argument parsing for all created objects. |
connectAllComponents | if true (default), then connect to all robot components. If false, then your program may need to create additional connector objects for components such as sonar and battery. (MTX-series robots have separate connections to components such as battery, sonar, etc. Other robots do not require this.) |
bool ArRobotConnector::connectRobot | ( | void | ) |
Sets up the robot then connects it.
Prepares the given ArRobot object for connection, then begins a blocking connection attempt.
If you wish to simply prepare the ArRobot object, but not begin the connection, then use setupRobot().
bool ArRobotConnector::connectRobot | ( | ArRobot * | robot | ) |
Sets up the robot then connects it.
Prepares the given ArRobot object for connection, then begins a blocking connection attempt.
If you wish to simply prepare the ArRobot object, but not begin the connection, then use setupRobot().
void ArRobotConnector::logOptions | ( | void | ) | const |
Log the options the simple connector has.
Normally called by Aria::logOptions().
bool ArRobotConnector::parseArgs | ( | void | ) |
Function to parse the arguments given in the constructor.
Parse command line arguments using the ArArgumentParser given in the ArRobotConnector constructor.
See parseArgs(ArArgumentParser*) for details about argument parsing.
bool ArRobotConnector::parseArgs | ( | ArArgumentParser * | parser | ) |
Function to parse the arguments given in an arbitrary parser.
Parse command line arguments for ArRobotConnector held by the given ArArgumentParser.
Normally called via global Aria::parseArgs() method.
The following arguments are used for the robot connection:
-robotPort
port -rp
port Use the given serial port device name for a serial port connection (e.g. COM1
, or /dev/ttyS0
if on Linux.) The default is the first serial port, or COM1, which is the typical Pioneer setup.
-remoteHost
hostname -rh
hostname Use a TCP connection to a remote computer with the given network host name instead of a serial port connection
-remoteRobotTcpPort
port -rrtp
port Use the given TCP port number if connecting to a remote robot using TCP due to -remoteHost
having been given.
-remoteIsSim
-ris
The remote TCP robot given by -remoteHost
or -rh
is actually a simulator. Use any alternative behavior intended for the simulator (e.g. tell the laser device object to request laser data from the simulator rather than trying to connect to a real laser device on the local computer)
-remoteIsNotSim
-rins
The remote TCP robot given by -remoteHost
or -rh
(or their defaults) is actually a simulator but DO NOT treat it like one. Use any the default robot behavior, instead of the simulator behavior (ie open a real laser device for the laser type given and try and talk to it over it's actual local port or remote port if given)
-robotBaud
baudrate -rb
baudrate bool ArRobotConnector::setupRobot | ( | void | ) |
Sets up the given robot to be connected.
This method is normally used internally by connectRobot(), but you may use it if you wish.
If -remoteHost was given, then open that TCP port. If it was not given, then try to open a TCP port to the simulator on localhost. If that fails, then use a local serial port connection. Sets the given ArRobot's device connection pointer to this object. Sets up internal settings determined by command line arguments such as serial port and baud rate, etc.
After calling this function (and it returns true), then you may connect ArRobot to the robot using ArRobot::blockingConnect() (or similar).
bool ArRobotConnector::setupRobot | ( | ArRobot * | robot | ) |
Sets up an arbitrary robot to be connected.
This method is normally used internally by connectRobot(), but you may use it if you wish.
If -remoteHost was given, then open that TCP port. If it was not given, then try to open a TCP port to the simulator on localhost. If that fails, then use a local serial port connection. Sets the given ArRobot's device connection pointer to this object. Sets up internal settings determined by command line arguments such as serial port and baud rate, etc.
After calling this function (and it returns true), then you may connect ArRobot to the robot using ArRobot::blockingConnect() (or similar).