#include <ArMap.h>
Public Types | |
enum | { INFO_COUNT = LAST_INFO + 1 } |
enum | InfoType { TASK_INFO, ROUTE_INFO, LAST_INFO = ROUTE_INFO } |
List of the standard Info categories defined for the map. More... | |
Public Member Functions | |
void | addMapChangedCB (ArFunctor *functor, ArListPos::Pos position=ArListPos::LAST) |
Adds a callback called when the map is changed. | |
ArMap (const char *baseDirectory="./", bool addToGlobalConfig=true, const char *configSection="Files", const char *configParam="Map", const char *configDesc="Map of the environment we'll use to navigate", bool ignoreEmptyFileName=true) | |
Constructor. | |
ArMapObject * | findMapObject (const char *name, const char *type=NULL) |
Gets a map object of given name and type if it exists. | |
const char * | getBaseDirectory (void) const |
Gets the base directory. | |
const char * | getFileName (void) const |
Gets the fileName that was loaded. | |
bool | getIgnoreEmptyFileName (void) |
Gets whether we ignore empty file names or fail if we encounter one. | |
std::list< ArArgumentBuilder * > * | getInfo (int infoType) |
Gets the strings for the specified Info category. | |
ArTime | getInfoChanged (int infoType) |
Returns the last time that the specified Info category was changed. | |
ArPose | getLineMaxPose (void) |
Gets the upper right point of the lines. | |
ArPose | getLineMinPose (void) |
Gets the lower left point of the lines. | |
std::vector< ArLineSegment > * | getLines (void) |
Gets the lines. | |
ArTime | getLinesChanged (void) |
Gets the last time the lines were changed. | |
ArLog::LogLevel | getMapChangedLogLevel (void) |
Gets the level we log our map changed callback at. | |
std::list< ArArgumentBuilder * > * | getMapInfo (void) |
Gets the map info strings. | |
ArTime | getMapInfoChanged (void) |
Gets the last time the map info was changed. | |
std::list< ArMapObject * > * | getMapObjects (void) |
Gets the map objects. | |
ArTime | getMapObjectsChanged (void) |
Gets the last time the map objects were changed. | |
ArPose | getMaxPose (void) |
Gets the upper right point of the points. | |
ArPose | getMinPose (void) |
Gets the lower left point of the points. | |
int | getNumLines (void) |
Gets the number of lines. | |
int | getNumPoints (void) |
Gets the number of points. | |
std::vector< ArPose > * | getPoints (void) |
Gets the map points. | |
ArTime | getPointsChanged (void) |
Gets the last time the points were changed. | |
int | getResolution (void) |
Gets the resolution (-1 if none specified). | |
bool | isLoadingDataStarted () |
bool | isLoadingLinesAndDataStarted () |
void | loadDataPoint (double x, double y) |
Adds the specified data point to the loading points. | |
void | loadLineSegment (double x1, double y1, double x2, double y2) |
Adds the specified line segment to the loading lines. | |
int | lock () |
Lock the map instance. | |
void | mapChanged (void) |
Function that will call the map changed CBs if needed. | |
bool | parseLine (char *line) |
Parses a map line. | |
void | parsingComplete (void) |
Says that the parsing by lines is done and to use the parsed data. | |
bool | readDataPoint (char *line) |
Reads a data point from the given line, and adds it to the loading points. | |
bool | readFile (const char *fileName, char *errorBuffer=NULL, size_t errorBufferLen=0) |
Reads a map. | |
bool | readLineSegment (char *line) |
Reads a line segment from the given line, and adds it to the loading lines. | |
void | remMapChangedCB (ArFunctor *functor) |
Removes a callback called when the map is changed. | |
void | setBaseDirectory (const char *baseDirectory) |
Sets the base directory. | |
void | setIgnoreEmptyFileName (bool ignore) |
Sets whether we ignore empty file names or fail if we encounter one. | |
bool | setInfo (int infoType, const std::list< ArArgumentBuilder * > *infoList) |
Sets the contents of the specified Info category. | |
void | setLines (const std::vector< ArLineSegment > *lines) |
Sets the lines (copies those passed in). | |
void | setMapChangedLogLevel (ArLog::LogLevel level) |
Sets the level we log our map changed callback at. | |
void | setMapInfo (const std::list< ArArgumentBuilder * > *mapInfo) |
Sets the map info (copies those passed in). | |
void | setMapObjects (const std::list< ArMapObject * > *mapObjects) |
Sets the map objects (copies those passed in). | |
void | setPoints (const std::vector< ArPose > *points) |
Sets the points (copies those passed in). | |
void | setResolution (int resolution) |
int | tryLock () |
Try to lock the map instance without blocking. | |
int | unlock () |
Unlock the map instance. | |
bool | writeFile (const char *fileName) |
Write out a map file. | |
void | writeLinesToFunctor (ArFunctor2< int, std::vector< ArLineSegment > * > *functor) |
Writes the map line segments to a functor. | |
void | writeObjectsToFunctor (ArFunctor1< const char * > *functor, const char *endOfLineChars) |
Writes the map header information and objects to a text-based functor. | |
void | writePointsToFunctor (ArFunctor2< int, std::vector< ArPose > * > *functor) |
Writes the map data points to a functor. | |
void | writeToFunctor (ArFunctor1< const char * > *functor, const char *endOfLineChars) |
Writes all of the map to a functor instead of a to a file. | |
virtual | ~ArMap (void) |
Destructor. | |
Protected Member Functions | |
virtual const char * | getInfoName (int infoType) |
Returns the name of the specified Info category (i.e. the "xInfo:" tag at the beginning of the line). | |
bool | handle2DMap (ArArgumentBuilder *arg) |
bool | handleData (ArArgumentBuilder *arg) |
bool | handleInfo (ArArgumentBuilder *arg, int info) |
bool | handleLine (ArArgumentBuilder *arg) |
bool | handleLineMaxPos (ArArgumentBuilder *arg) |
bool | handleLineMinPos (ArArgumentBuilder *arg) |
bool | handleLines (ArArgumentBuilder *arg) |
bool | handleMapInfo (ArArgumentBuilder *arg) |
bool | handleMapObject (ArArgumentBuilder *arg) |
bool | handleMaxPos (ArArgumentBuilder *arg) |
bool | handleMinPos (ArArgumentBuilder *arg) |
bool | handleNumLines (ArArgumentBuilder *arg) |
bool | handleNumPoints (ArArgumentBuilder *arg) |
bool | handlePoint (ArArgumentBuilder *arg) |
bool | handleResolution (ArArgumentBuilder *arg) |
bool | processFile (char *errorBuffer, size_t errorBufferLen) |
bool | reset (void) |
Protected Attributes | |
ArRetFunctor1C< bool, ArMap, ArArgumentBuilder * > | my2DMapCB |
std::string | myBaseDirectory |
char | myConfigMapName [512] |
std::string | myConfigParam |
bool | myConfigProcessedBefore |
ArRetFunctor1C< bool, ArMap, ArArgumentBuilder * > | myDataCB |
std::string | myFileName |
bool | myIgnoreEmptyFileName |
std::list< ArArgumentBuilder * > * | myInfoArray |
ArRetFunctor2C< bool, ArMap, ArArgumentBuilder *, int > ** | myInfoCBArray |
ArTime * | myInfoChangedArray |
ArRetFunctor1C< bool, ArMap, ArArgumentBuilder * > | myLineCB |
ArPose | myLineMax |
ArRetFunctor1C< bool, ArMap, ArArgumentBuilder * > | myLineMaxPosCB |
ArPose | myLineMin |
ArRetFunctor1C< bool, ArMap, ArArgumentBuilder * > | myLineMinPosCB |
std::vector< ArLineSegment > | myLines |
ArRetFunctor1C< bool, ArMap, ArArgumentBuilder * > | myLinesCB |
ArTime | myLinesChanged |
bool | myLoadingDataStarted |
bool | myLoadingGot2DMap |
bool | myLoadingGotLineMaxPos |
bool | myLoadingGotLineMinPos |
bool | myLoadingGotMaxPos |
bool | myLoadingGotMinPos |
std::list< ArArgumentBuilder * > * | myLoadingInfoArray |
ArPose | myLoadingLineMax |
ArPose | myLoadingLineMaxFromFile |
ArPose | myLoadingLineMin |
ArPose | myLoadingLineMinFromFile |
std::vector< ArLineSegment > | myLoadingLines |
bool | myLoadingLinesAndDataStarted |
int | myLoadingLinesRead |
std::list< ArArgumentBuilder * > | myLoadingMapInfo |
std::list< ArMapObject * > | myLoadingMapObjects |
ArPose | myLoadingMax |
ArPose | myLoadingMaxFromFile |
ArPose | myLoadingMin |
ArPose | myLoadingMinFromFile |
int | myLoadingNumLines |
int | myLoadingNumPoints |
ArFileParser * | myLoadingParser |
std::vector< ArPose > | myLoadingPoints |
int | myLoadingPointsRead |
int | myLoadingResolution |
std::list< ArFunctor * > | myMapChangedCBList |
ArTime * | myMapChangedInfoArray |
ArLog::LogLevel | myMapChangedLogLevel |
ArTime | myMapChangedMapInfo |
ArTime | myMapChangedMapObjects |
ArTime | myMapChangedPoints |
std::list< ArArgumentBuilder * > | myMapInfo |
ArRetFunctor1C< bool, ArMap, ArArgumentBuilder * > | myMapInfoCB |
ArTime | myMapInfoChanged |
ArRetFunctor1C< bool, ArMap, ArArgumentBuilder * > | myMapObjectCB |
std::list< ArMapObject * > | myMapObjects |
ArTime | myMapObjectsChanged |
ArPose | myMax |
ArRetFunctor1C< bool, ArMap, ArArgumentBuilder * > | myMaxPosCB |
ArPose | myMin |
ArRetFunctor1C< bool, ArMap, ArArgumentBuilder * > | myMinPosCB |
ArMutex | myMutex |
int | myNumInfos |
Number of different Info categories available in this map. | |
int | myNumLines |
ArRetFunctor1C< bool, ArMap, ArArgumentBuilder * > | myNumLinesCB |
int | myNumPoints |
ArRetFunctor1C< bool, ArMap, ArArgumentBuilder * > | myNumPointsCB |
ArRetFunctor1C< bool, ArMap, ArArgumentBuilder * > | myPointCB |
std::vector< ArPose > | myPoints |
ArTime | myPointsChanged |
ArRetFunctor2C< bool, ArMap, char *, size_t > | myProcessFileCB |
stat | myReadFileStat |
int | myResolution |
ArRetFunctor1C< bool, ArMap, ArArgumentBuilder * > | myResolutionCB |
Static Protected Attributes | |
static const char * | ourInfoNames [INFO_COUNT] |
Array of names for the standard Info categories; see InfoType. |
ArMap encapsulates the data contained in a .map file. It provides methods to read and write a .map file, and to obtain and modify the contents of the map. In addition, the application may install callbacks on the map to be notified when its contents are modified.
Aria maps contain the following types of data:
Thread Issues
The ArMap class is not inherently thread-safe. It has a lock and unlock associated with it, which the application must call before and after calls to get and set the data (e.g. getMapObjects(), getPoints()... setMapObjects(), setPoints()...).
If you are going to use setMapObjects(), setPoints(), setLines(), or setMapInfo(), then you should lock() the map beforehand, call the methods, then call mapChanged() to invoke the callbacks, and then finally unlock() the map when done. Note that mapChanged() will only invoke the callbacks if the data has actually changed.
The readFile() and writeFile() methods do automatically lock the map while they read and write.
Map Objects
Certain types of objects are always predefined for ArMaps. These include Goal, GoalWithHeading, Dock, ForbiddenLine, ForbiddenArea, and RobotHome.
Each rectangle object may have an associated angle of rotation that is currently stored in the ArMapObject::getPose().getTh() value. If this value is non-zero, then the actual global coordinates of the rectangle's polygon must be calculated from the "from-to" values. The following formula should be used (with improvements in efficiency perhaps):
double degreesToRadians(double degrees) { return degrees * (3.1415926535 / 180.0); } int round(double d) { if (d >= 0.0) { return int(d + 0.5); } else { return int( d - ((int)d-1) + 0.5 ) + ((int)d-1); } }
// Computation: double rotation = mapObject->getPose().getTh(); ArPose minPt = mapObject->getFromPose(); ArPose maxPt = mapObject->getToPose();
double radians = ArQ::degreesToRadians(rotation); double c = ::cos(radians); double s = ::sin(radians);
ArPose globalPoints[4]; globalPoints[0] = ArPose(minPt.getX(), minPt.getY()); globalPoints[1] = ArPose(maxPt.getX(), minPt.getY()); globalPoints[2] = ArPose(maxPt.getX(), maxPt.getY()); globalPoints[3] = ArPose(minPt.getX(), maxPt.getY());
for (int i = 0; i < 4; i++) { ArPose pt = globalPoints[i]; globalPoints[i] = ArPose(round((c * pt.getX()) - (s * pt.getY())), round((s * pt.getX()) + (c * pt.getY()))); }
Map Customization
It is possible to add additional types of objects to an ArMap using the MapInfo metadata section. For example, if you wished to program some special behavior that would only occur upon reaching certain goals, you could define a new goal type as follows:
MapInfo: GoalType Name=SpecialGoal "Label=Special" "Desc=Doing special stuff" Heading=Required Shape=VBarsThe new goal type will appear be available in Mapper3 in a drop-down menu. Instances in the map will also be displayed by MobileEyes.
Note that if a map defines special GoalType or DockType items, then it must define all of the goal or dock types (including the default "Goal" if desired).
Please read the following information carefully if you plan to use this feature.
Each MapInfo line is of the format:
MapInfo: <Keyword> ([ParamName=ParmValue] )*
The following Keywords are supported:
The available parameters depend on the Keyword. Unless otherwise specified, parameters are optional.
If a parameter value contains a space, then both the parameter name and value must be enclosed within quotes. For example:
"Label=Normal Goal"Neither the name nor the value can contain the special characters #, ;, , or ".
The following ParamNames are valid for all keywords:
For GoalType, DockType, and LocationType, the following ParamNames are also supported:
The .map file is an ASCII text file which may be viewed or edited with a text editor (although using Mapper3 is usually more advisable for simple editing).
The format of the file is as follows:
ARMAPFILE = ("2D-Map\n") (MapHeader) (Metadata)* (MapObjects)* (DataSection)
MapHeader = HeaderKey ":" WS HeaderVal "\n" HeaderKey = MinPos | MaxPos | NumPoints | LineMinPos | LineMaxPos | NumLines | Resolution HeaderVal = Integer | Integer WS Integer
Metadata = MapInfo ":" WS MapInfoVal "\n" MapInfoVal = MapInfoKeyword ([ParamName=ParamValue] )* MapInfoKeyword (see "Map Customization" above) ParamName (see "Map Customization" above) ParamValue (see "Map Customization" above)
MapObjects = Cairn ":" CairnType WS (Pose) WS Nothing WS "ICON" WS Label [CairnTypeSpecificData] "\n" CairnType = StringID Pose = XPos WS YPos WS Theta FromPos = XPos WS YPos ToPos = XPos WS YPos XPos = Integer YPos = Integer Theta = Double Nothing = "" Label = QuotedString
DataSection = ("LINES\n" (LineLine)*) | ("DATA\n" (PointLine)*) LineLine = FromPos WS ToPos "\n" PointLine = XPos WS YPos "\n"
Integer = ["-"](DIGIT +)) StringID = (ALNUM)(ALNUM*) QuotedString = " (ALNUM | WS)* "
DIGIT = ("0"-"9") ALNUM = any 8 bit ASCII character or numeral except " (double quote mark), #, ; (semi-colon), (percent), or space, tab, newline, or any other whitespace or control character. WS = (" ")*
Notes:
CairnTypeSpecificData = FromPos WS ToPosThese are the coordinates that should generally be used for these objects. For the rectangular (i.e. non-line) objects, the main Pose in the Cairn line contains the rotation; the x and y values are currently undefined.
Definition at line 280 of file ArMap.h.
|
|
|
List of the standard Info categories defined for the map.
|
|
Constructor. myRouteInfoCB(this, &ArMap::handleRouteInfo), Definition at line 49 of file ArMap.cpp. References ArConfig::addParam(), ArConfig::addProcessFileWithErrorCB(), Aria::getConfig(), myNumInfos, setBaseDirectory(), and ArFunctor::setName(). |
|
Adds a callback called when the map is changed. Adds a read callback that is called when the map is read in, the map is locked when this callback happens so you don't need to worry about that. Definition at line 196 of file ArMap.cpp. References ArLog::log(). Referenced by ArForbiddenRangeDevice::setRobot(). |
|
Gets a map object of given name and type if it exists.
Definition at line 1351 of file ArMap.cpp. References getMapObjects(), ArMapObject::getName(), and ArMapObject::getType(). |
|
Gets the strings for the specified Info category.
Definition at line 181 of file ArMap.cpp. References myNumInfos. |
|
Returns the last time that the specified Info category was changed.
Definition at line 617 of file ArMap.cpp. References ArTime::setMSec(), and ArTime::setSec(). |
|
Returns the name of the specified Info category (i.e. the "xInfo:" tag at the beginning of the line). If subclasses define additional Info categories, then they must override this method.
Definition at line 1378 of file ArMap.cpp. References INFO_COUNT, and ourInfoNames. |
|
bool ArMap::handleRouteInfo(ArArgumentBuilder *arg) { ArArgumentBuilder *routeInfo = NULL; routeInfo = new ArArgumentBuilder(*arg); myLoadingRouteInfo.push_back(routeInfo); return true; } Definition at line 501 of file ArMap.cpp. References ArLog::log(). |
|
This value returns true once the DATA tag has been reached. The rest of the map contains data points. |
|
This value returns true once the LINES tag has been reached. The rest of the map contains data points. |
|
Says that the parsing by lines is done and to use the parsed data. If you've been giving the map lines to parse with parseLine and you are finished then you should call this function call to move all of that data from the loading zone into the main variables. Definition at line 1075 of file ArMap.cpp. References lock(), ArLog::log(), mapChanged(), setInfo(), setLines(), setMapInfo(), setMapObjects(), setPoints(), and unlock(). |
|
Reads a map.
Definition at line 842 of file ArMap.cpp. References lock(), ArLog::log(), mapChanged(), readDataPoint(), readLineSegment(), setInfo(), setLines(), setMapInfo(), setMapObjects(), setPoints(), and unlock(). |
|
Sets the contents of the specified Info category.
Definition at line 779 of file ArMap.cpp. References ArUtil::deleteSet(), and ArTime::setToNow(). Referenced by parsingComplete(), and readFile(). |
|
Sets the lines (copies those passed in). Deletes and clears the old lines (and the info about our lines) and then makes a copy of the ones passed in.
Definition at line 705 of file ArMap.cpp. References ArPose::getX(), ArLineSegment::getX1(), ArLineSegment::getX2(), ArPose::getY(), ArLineSegment::getY1(), ArLineSegment::getY2(), ArTime::setToNow(), ArPose::setX(), and ArPose::setY(). Referenced by parsingComplete(), and readFile(). |
|
Sets the map info (copies those passed in). Deletes and clears the old mapInfo and then makes a copy of the ones passed in.
Definition at line 765 of file ArMap.cpp. References ArUtil::deleteSet(), and ArTime::setToNow(). Referenced by parsingComplete(), and readFile(). |
|
Sets the map objects (copies those passed in). Deletes and clears the old map objects and then makes a copy of the ones passed in.
Definition at line 637 of file ArMap.cpp. References ArUtil::deleteSet(), and ArTime::setToNow(). Referenced by parsingComplete(), and readFile(). |
|
Sets the points (copies those passed in). Deletes and clears the old points (and the info about our points) and then makes a copy of the ones passed in.
Definition at line 657 of file ArMap.cpp. References ArPose::getX(), ArPose::getY(), ArTime::setToNow(), ArPose::setX(), and ArPose::setY(). Referenced by parsingComplete(), and readFile(). |
|
Write out a map file. Writes a file out... The map is locked while the write happens.
Definition at line 1304 of file ArMap.cpp. References lock(), ArLog::log(), unlock(), and writeToFunctor(). |
|
Writes the map line segments to a functor. A pointer to the entire line segment vector is passed directly to the modify the vector's contents. |
|
Writes the map header information and objects to a text-based functor. This method writes everything up to and including the DATA tag to the given functor. The data points are not written. Definition at line 1189 of file ArMap.cpp. References ArUtil::functorPrintf(), ArMapObject::getFileName(), ArMapObject::getFromPose(), ArMapObject::getIconName(), ArMapObject::getName(), ArMapObject::getPose(), ArPose::getTh(), ArMapObject::getToPose(), ArMapObject::getType(), ArPose::getX(), ArPose::getY(), ArMapObject::hasFromTo(), and ArLog::log(). Referenced by writeToFunctor(). |
|
Writes the map data points to a functor. A pointer to the entire data point vector is passed directly to the functor in order to improve performance. The functor should not modify the vector's contents. |
|
Writes all of the map to a functor instead of a to a file.
This function calls the functor with each line of the map, the lines do not have any Definition at line 1146 of file ArMap.cpp. References ArUtil::functorPrintf(), and writeObjectsToFunctor(). Referenced by writeFile(). |
|
Initial value: { "TaskInfo:", "RouteInfo:" }
Definition at line 37 of file ArMap.cpp. Referenced by getInfoName(). |