Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages | Examples

ArSimpleConnector Class Reference

#include <ArSimpleConnector.h>

List of all members.


Detailed Description

Connect to robot and laser based on run-time availablitily and command-line arguments.

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

See the documentation for parseArgs() for a list of recognized command line parameters.

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 ArSimpleConnector 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 ArSick::runAsync() or ArSick()::run()) and then use ArSimpleConnector::connectLaser() to connect with the laser if specifically requested on the command line using the -connectLaser option (or simply call ArSick::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).

Examples:

actionExample.cpp, actionGroupExample.cpp, actsColorFollowingExample.cpp, armExample.cpp, auxSerialExample.cpp, demo.cpp, dpptuExample.cpp, gotoActionExample.cpp, gripperExample.cpp, gyroExample.cpp, joydriveActionExample.cpp, lineFinderExample.cpp, robotConnectionCallbacks.cpp, robotSyncTaskExample.cpp, simpleConnect.cpp, teleopActionsExample.cpp, triangleDriveToActionExample.cpp, and wander.cpp.

Definition at line 82 of file ArSimpleConnector.h.

Public Member Functions

 ArSimpleConnector (ArArgumentParser *parser)
 Constructor that takes argument parser.
 ArSimpleConnector (ArArgumentBuilder *arguments)
 Constructor that takes argument builder.
 ArSimpleConnector (int *argc, char **argv)
 Constructor that takes args from the main.
bool connectLaser (ArSick *sick)
 Connects the laser synchronously (will take up to a minute).
bool connectLaserArbitrary (ArSick *sick, int laserNumber)
 Connects the laser synchronously (make sure you setMaxNumLasers).
bool connectRobot (ArRobot *robot)
 Sets up the robot then connects it.
bool connectSecondLaser (ArSick *sick)
 Connects the laser synchronously (will take up to a minute).
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.
void setMaxNumLasers (int maxNumLasers=1)
 Sets the number of possible lasers.
bool setupLaser (ArSick *sick)
 Sets up the laser to be connected.
bool setupLaserArbitrary (ArSick *sick, int laserNumber)
 Sets up a laser t obe connected (make sure you setMaxNumLasers).
bool setupRobot (ArRobot *robot)
 Sets up the robot to be connected.
bool setupSecondLaser (ArSick *sick)
 Sets up a second laser to be connected.
 ~ArSimpleConnector (void)
 Destructor.

Protected Member Functions

void logLaserOptions (unsigned int laserNumber) const
 Logs the laser parameters.
bool parseLaserArgs (ArArgumentParser *parser, int laserNumber)
 Parses the laser arguments.
void reset (void)

Protected Attributes

std::list< LaserData * > myLasers
ArSerialConnection myLaserSerConn
ArSerialConnection myLaserSerConn2
ArTcpConnection myLaserTcpConn
ArTcpConnection myLaserTcpConn2
ArConstFunctorC< ArSimpleConnectormyLogOptionsCB
int myMaxNumLasers
bool myOwnParser
ArRetFunctorC< bool, ArSimpleConnectormyParseArgsCB
ArArgumentParsermyParser
const char * myRemoteHost
bool myRemoteIsSim
int myRemoteRobotTcpPort
ArRobotmyRobot
int myRobotBaud
const char * myRobotPort
ArSerialConnection myRobotSerConn
ArTcpConnection myRobotTcpConn
bool myUsingSim

Classes

class  LaserData
 Class that holds information about the laser data. More...


Member Function Documentation

bool ArSimpleConnector::connectLaser ArSick sick  ) 
 

Connects the laser synchronously (will take up to a minute).

This will setup and connect the laser if the command line switch was given to do so or simply return true if no connection was wanted.

Definition at line 658 of file ArSimpleConnector.cpp.

bool ArSimpleConnector::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().

Definition at line 514 of file ArSimpleConnector.cpp.

bool ArSimpleConnector::connectSecondLaser ArSick sick  ) 
 

Connects the laser synchronously (will take up to a minute).

This will setup and connect the laser if the command line switch was given to do so or simply return true if no connection was requested.

Definition at line 669 of file ArSimpleConnector.cpp.

bool ArSimpleConnector::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 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)

-robotBaud baudrate
-rb baudrate Use the given baud rate when connecting over a serial port, instead of trying to use the normal rate.

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".

-laserPort port
-lp port
Use the given port device name when connecting to a laser. For example, COM2 or on Linux, /dev/ttyS1. The default laser port is COM2, which is the typical Pioneer laser port setup.

-laserFlipped true|false
-lf true|false
If true, then the laser is mounted upside-down on the robot and the ordering of readings should be reversed.

-connectLaser
-cl
Explicitly request that the client program connect to a laser, if it does not always do so

-laserPowerControlled true|false
-lpc true|false
If 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.

-laserDegrees degrees
-ld degrees
Indicate the size of the laser field of view, either 180 (default) or 100.

-laserIncrement increment
-li increment
Configures the laser's angular resolution. If one, then configure the laser to take a reading every degree. If half, then configure it for a reading every 1/2 degrees.

-laserUnits units
-lu units
Configures the laser's range resolution. May be 1mm for one milimiter, 1cm for ten milimeters, or 10cm for one hundred milimeters.

-laserReflectorBits bits
-lrb bits
Enables special reflectance detection, and configures the granularity of reflector detection information. Using more bits allows the laser to provide values for several different reflectance levels, but also may force a reduction in range. (Note, the SICK LMS-200 only detects high reflectance on special reflector material manufactured by SICK.)

Definition at line 201 of file ArSimpleConnector.cpp.

bool ArSimpleConnector::parseArgs void   ) 
 

Function to parse the arguments given in the constructor.

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

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

Returns:
true if the arguments were parsed successfully false if not

Definition at line 114 of file ArSimpleConnector.cpp.

void ArSimpleConnector::setMaxNumLasers int  maxNumLasers = 1  ) 
 

Sets the number of possible lasers.

This gets rid of all of the data that was set for the lasers, so call this before you parse.

Definition at line 94 of file ArSimpleConnector.cpp.

bool ArSimpleConnector::setupLaser ArSick sick  ) 
 

Sets up the laser to be connected.

Description of the logic for connection to the laser: If --remoteHost then the laser will a tcp connection will be opened to that remoteHost at port 8102 or --remoteLaserTcpPort if that argument is given, if this connection fails then the setup fails. If --remoteHost wasn't provided and the robot connected to a simulator as described elsewhere then the laser is just configured to be simulated, if the robot isn't connected to a simulator it tries to open a serial connection to ArUtil::COM3 or --laserPort if that argument is given.

Definition at line 534 of file ArSimpleConnector.cpp.

bool ArSimpleConnector::setupRobot ArRobot robot  ) 
 

Sets up the 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).

Returns:
false if -remoteHost was given and there was an error connecting to the remote host, true otherwise.

Definition at line 452 of file ArSimpleConnector.cpp.

bool ArSimpleConnector::setupSecondLaser ArSick sick  ) 
 

Sets up a second laser to be connected.

Description of the logic for connecting to a second laser: Given the fact that there are no parameters for the location of a second laser, the laser's port must be passed in to ArSimpleConnector from the main or from ArArgumentBuilder. Similarly, a tcp connection must be explicitly defined with the --remoteLaserTcpPort2 argument.

Definition at line 546 of file ArSimpleConnector.cpp.


The documentation for this class was generated from the following files:
Generated on Tue Feb 20 10:51:45 2007 for Aria by  doxygen 1.4.0