YARP
Yet Another Robot Platform
yarp::dev::Nav2D::MapGrid2D Class Reference

#include <yarp/dev/MapGrid2D.h>

+ Inheritance diagram for yarp::dev::Nav2D::MapGrid2D:

Public Types

enum  map_flags {
  MAP_CELL_FREE = 0,
  MAP_CELL_KEEP_OUT = 1,
  MAP_CELL_TEMPORARY_OBSTACLE = 2,
  MAP_CELL_ENLARGED_OBSTACLE = 3,
  MAP_CELL_WALL = 4,
  MAP_CELL_UNKNOWN = 5
}
 
typedef yarp::sig::PixelMono CellData
 

Public Member Functions

 MapGrid2D ()
 
virtual ~MapGrid2D ()
 
bool isWall (XYCell cell) const
 Checks if a specific cell of the map contains a wall. More...
 
bool isFree (XYCell cell) const
 Checks if a specific cell of the map is free, i.e. More...
 
bool isNotFree (XYCell cell) const
 Checks if a specific cell of the map contains is not free. More...
 
bool isKeepOut (XYCell cell) const
 Checks if a specific cell of the map is marked as keep-out. More...
 
bool getMapFlag (XYCell cell, map_flags &flag) const
 Get the flag of a specific cell of the map. More...
 
bool setMapFlag (XYCell cell, map_flags flag)
 Set the flag of a specific cell of the map. More...
 
bool setOccupancyData (XYCell cell, double occupancy)
 Set the occupancy data of a specific cell of the map. More...
 
bool getOccupancyData (XYCell cell, double &occupancy) const
 Retrieves the occupancy data of a specific cell of the map. More...
 
bool setMapImage (yarp::sig::ImageOf< yarp::sig::PixelRgb > &image)
 
bool getMapImage (yarp::sig::ImageOf< yarp::sig::PixelRgb > &image) const
 
bool setOccupancyGrid (yarp::sig::ImageOf< yarp::sig::PixelMono > &image)
 
bool getOccupancyGrid (yarp::sig::ImageOf< yarp::sig::PixelMono > &image) const
 
bool setOrigin (double x, double y, double theta)
 Sets the origin of the map reference frame (according to ROS convention) More...
 
void getOrigin (double &x, double &y, double &theta) const
 Retrieves the origin of the map reference frame (according to ROS convention) More...
 
bool setResolution (double resolution)
 Sets the resolution of the map, i.e. More...
 
void getResolution (double &resolution) const
 Retrieves the resolution of the map, i.e. More...
 
bool setSize_in_meters (double x, double y)
 Sets the size of the map in meters, according to the current map resolution. More...
 
bool setSize_in_cells (size_t x, size_t y)
 Sets the size of the map in cells. More...
 
void getSize_in_meters (double &x, double &y) const
 Returns the size of the map in meters, according to the current map resolution. More...
 
void getSize_in_cells (size_t &x, size_t &y) const
 Returns the size of the map in cells. More...
 
size_t width () const
 Retrieves the map width, expressed in cells. More...
 
size_t height () const
 Retrieves the map height, expressed in cells. More...
 
bool setMapName (std::string map_name)
 Sets the map name. More...
 
std::string getMapName () const
 Retrieves the map name. More...
 
bool crop (int left, int top, int right, int bottom)
 Modifies the map, cropping pixels at the boundaries. More...
 
bool isIdenticalTo (const MapGrid2D &otherMap) const
 Checks is two maps are identical. More...
 
bool enlargeObstacles (double size)
 Performs the obstacle enlargement operation. More...
 
bool loadFromFile (std::string map_filename)
 Loads a yarp map file from disk. More...
 
bool saveToFile (std::string map_filename) const
 Store a yarp map file to disk. More...
 
bool read (yarp::os::ConnectionReader &connection) override
 Read this object from a network connection. More...
 
bool write (yarp::os::ConnectionWriter &connection) const override
 Write vector to a connection. More...
 
- Public Member Functions inherited from yarp::os::Portable
virtual Type getType () const
 
- Public Member Functions inherited from yarp::os::PortReader
virtual ~PortReader ()
 Destructor. More...
 
virtual Type getReadType () const
 
- Public Member Functions inherited from yarp::os::PortWriter
virtual ~PortWriter ()
 Destructor. More...
 
virtual void onCompletion () const
 This is called when the port has finished all writing operations. More...
 
virtual void onCommencement () const
 This is called when the port is about to begin writing operations. More...
 
virtual yarp::os::Type getWriteType () const
 
- Public Member Functions inherited from yarp::dev::Nav2D::MapGrid2DInfo
 MapGrid2DInfo ()
 
XYWorld cell2World (XYCell cell) const
 
yarp::dev::Nav2D::Map2DLocation toLocation (XYCell cell) const
 
XYCell toXYCell (yarp::dev::Nav2D::Map2DLocation loc) const
 
XYCell world2Cell (XYWorld world) const
 
XYCell world2Cell_unsafeFast (XYWorld world) const
 
yarp::dev::Nav2D::Map2DLocation toLocation (XYWorld cell) const
 
XYWorld toXYWorld (yarp::dev::Nav2D::Map2DLocation loc) const
 
bool isInsideMap (XYCell cell) const
 Checks if a cell is inside the map. More...
 
bool isInsideMap (XYWorld world) const
 Checks if a world coordinate is inside the map. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from yarp::os::Portable
static bool copyPortable (const PortWriter &writer, PortReader &reader)
 Copy one portable to another, via writing and reading. More...
 
- Public Attributes inherited from yarp::dev::Nav2D::MapGrid2DInfo
std::string m_map_name
 
double m_resolution
 meters/pixel More...
 
MapGrid2DOrigin m_origin
 pose of the map frame w.r.t. the bottom left corner of the map image More...
 
size_t m_width
 cells More...
 
size_t m_height
 cells More...
 

Detailed Description

Definition at line 30 of file MapGrid2D.h.

Member Typedef Documentation

◆ CellData

Member Enumeration Documentation

◆ map_flags

Enumerator
MAP_CELL_FREE 
MAP_CELL_KEEP_OUT 
MAP_CELL_TEMPORARY_OBSTACLE 
MAP_CELL_ENLARGED_OBSTACLE 
MAP_CELL_WALL 
MAP_CELL_UNKNOWN 

Definition at line 38 of file MapGrid2D.h.

Constructor & Destructor Documentation

◆ MapGrid2D()

MapGrid2D::MapGrid2D ( )

Definition at line 69 of file MapGrid2D.cpp.

◆ ~MapGrid2D()

MapGrid2D::~MapGrid2D ( )
virtualdefault

Member Function Documentation

◆ crop()

bool MapGrid2D::crop ( int  left,
int  top,
int  right,
int  bottom 
)

Modifies the map, cropping pixels at the boundaries.

Parameters
left,top,right,bottomthe corners of the map area to keep (expressed in pixel coordinates). If the value is negative, all unknown pixels are removed until a significative pixel is found.
Returns
true if the operation is performed successfully (the input parameters are valid), false otherwise.

Definition at line 614 of file MapGrid2D.cpp.

◆ enlargeObstacles()

bool MapGrid2D::enlargeObstacles ( double  size)

Performs the obstacle enlargement operation.

It's useful to set size to a value equal or larger to the radius of the robot bounding box. In this way a navigation algorithm can easily check obstacle collision by comparing the location of the center of the robot with cell value (free/occupied etc)

Parameters
sizethe size of the enlargement, in meters. If size>0 the requested enlargement is performed. If the function is called multiple times, the enlargement sums up. If size <= 0 the enlargement stored in the map is cleaned up.
Returns
true always.

Definition at line 180 of file MapGrid2D.cpp.

◆ getMapFlag()

bool MapGrid2D::getMapFlag ( XYCell  cell,
map_flags flag 
) const

Get the flag of a specific cell of the map.

Parameters
cellis the cell location, referred to the top-left corner of the map.
Returns
true if cell is valid cell inside the map, false otherwise.

Definition at line 973 of file MapGrid2D.cpp.

◆ getMapImage()

bool MapGrid2D::getMapImage ( yarp::sig::ImageOf< yarp::sig::PixelRgb > &  image) const

Definition at line 147 of file MapGrid2D.cpp.

◆ getMapName()

std::string MapGrid2D::getMapName ( ) const

Retrieves the map name.

Returns
the map_name.

Definition at line 911 of file MapGrid2D.cpp.

◆ getOccupancyData()

bool MapGrid2D::getOccupancyData ( XYCell  cell,
double &  occupancy 
) const

Retrieves the occupancy data of a specific cell of the map.

Parameters
occupancyrepresents the probability (0-100) of the cell of being occupied by a wall/obstacle etc.
Returns
true if cell is valid cell inside the map, false otherwise.

Definition at line 995 of file MapGrid2D.cpp.

◆ getOccupancyGrid()

bool MapGrid2D::getOccupancyGrid ( yarp::sig::ImageOf< yarp::sig::PixelMono > &  image) const

Definition at line 1025 of file MapGrid2D.cpp.

◆ getOrigin()

void MapGrid2D::getOrigin ( double &  x,
double &  y,
double &  theta 
) const

Retrieves the origin of the map reference frame (according to ROS convention)

Parameters
x,y,thetais the pose of the origin, expressed in [m], [deg] and referred to the bottom-left corner of the map, pointing outwards.

Definition at line 877 of file MapGrid2D.cpp.

◆ getResolution()

void MapGrid2D::getResolution ( double &  resolution) const

Retrieves the resolution of the map, i.e.

the conversion factor which represents the metric size of a map cell.

Parameters
resolutionthe map resolution, expressed in [m/cell]. e.g. resolution=0.05 means that each cell of the map represent 5cm of the real world.

Definition at line 895 of file MapGrid2D.cpp.

◆ getSize_in_cells()

void MapGrid2D::getSize_in_cells ( size_t &  x,
size_t &  y 
) const

Returns the size of the map in cells.

Parameters
x,yis the map size in cells.

Definition at line 956 of file MapGrid2D.cpp.

◆ getSize_in_meters()

void MapGrid2D::getSize_in_meters ( double &  x,
double &  y 
) const

Returns the size of the map in meters, according to the current map resolution.

Parameters
x,yis the map size in meters.

Definition at line 950 of file MapGrid2D.cpp.

◆ height()

size_t MapGrid2D::height ( ) const

Retrieves the map height, expressed in cells.

Returns
the map height.

Definition at line 137 of file MapGrid2D.cpp.

◆ isFree()

bool MapGrid2D::isFree ( XYCell  cell) const

Checks if a specific cell of the map is free, i.e.

the robot can freely pass through the cell

Parameters
cellis the cell location, referred to the top-left corner of the map.
Returns
true if cell is valid cell inside the map, false otherwise.

Definition at line 104 of file MapGrid2D.cpp.

◆ isIdenticalTo()

bool MapGrid2D::isIdenticalTo ( const MapGrid2D otherMap) const

Checks is two maps are identical.

Returns
true if all the internal data of the maps are identical, false otherwise.

Definition at line 55 of file MapGrid2D.cpp.

◆ isKeepOut()

bool MapGrid2D::isKeepOut ( XYCell  cell) const

Checks if a specific cell of the map is marked as keep-out.

User can set a cell as keep-out to prevent a robot to pass through it, even if no obstacles are present in the path.

Parameters
cellis the cell location, referred to the top-left corner of the map.
Returns
true if cell is valid cell inside the map, false otherwise.

Definition at line 115 of file MapGrid2D.cpp.

◆ isNotFree()

bool MapGrid2D::isNotFree ( XYCell  cell) const

Checks if a specific cell of the map contains is not free.

It may be occupied by a wall, an obstacle, a keep-out area etc.

Parameters
cellis the cell location, referred to the top-left corner of the map.
Returns
true if cell is valid cell inside the map, false otherwise.

Definition at line 92 of file MapGrid2D.cpp.

◆ isWall()

bool MapGrid2D::isWall ( XYCell  cell) const

Checks if a specific cell of the map contains a wall.

A robot cannot pass through a cell occupied by a wall.

Parameters
cellis the cell location, referred to the top-left corner of the map.
Returns
true if cell is valid cell inside the map, false otherwise.

Definition at line 125 of file MapGrid2D.cpp.

◆ loadFromFile()

bool MapGrid2D::loadFromFile ( std::string  map_filename)

Loads a yarp map file from disk.

File must have .map extension. param map_filename is the full path to the map file.

Returns
true if load was successful, false otherwise.

Definition at line 512 of file MapGrid2D.cpp.

◆ read()

bool MapGrid2D::read ( yarp::os::ConnectionReader reader)
overridevirtual

Read this object from a network connection.

Override this for your particular class.

Parameters
readeran interface to the network connection for reading
Returns
true iff the object is successfully read

Implements yarp::os::Portable.

Definition at line 768 of file MapGrid2D.cpp.

◆ saveToFile()

bool MapGrid2D::saveToFile ( std::string  map_filename) const

Store a yarp map file to disk.

File must have .map extension. param map_filename is the full path to the map file.

Returns
true if load was successful, false otherwise.

Definition at line 709 of file MapGrid2D.cpp.

◆ setMapFlag()

bool MapGrid2D::setMapFlag ( XYCell  cell,
map_flags  flag 
)

Set the flag of a specific cell of the map.

Parameters
cellis the cell location, referred to the top-left corner of the map.
Returns
true if cell is valid cell inside the map, false otherwise.

Definition at line 962 of file MapGrid2D.cpp.

◆ setMapImage()

bool MapGrid2D::setMapImage ( yarp::sig::ImageOf< yarp::sig::PixelRgb > &  image)

Definition at line 162 of file MapGrid2D.cpp.

◆ setMapName()

bool MapGrid2D::setMapName ( std::string  map_name)

Sets the map name.

Parameters
map_namethe map name.
Returns
true if map_name is a valid non-empty string, false otherwise.

Definition at line 900 of file MapGrid2D.cpp.

◆ setOccupancyData()

bool MapGrid2D::setOccupancyData ( XYCell  cell,
double  occupancy 
)

Set the occupancy data of a specific cell of the map.

Parameters
occupancyrepresents the probability (0-100) of the cell of being occupied by a wall/obstacle etc.
Returns
true if cell is valid cell inside the map, false otherwise.

Definition at line 984 of file MapGrid2D.cpp.

◆ setOccupancyGrid()

bool MapGrid2D::setOccupancyGrid ( yarp::sig::ImageOf< yarp::sig::PixelMono > &  image)

Definition at line 1013 of file MapGrid2D.cpp.

◆ setOrigin()

bool MapGrid2D::setOrigin ( double  x,
double  y,
double  theta 
)

Sets the origin of the map reference frame (according to ROS convention)

Parameters
x,y,thetais the pose of the origin, expressed in [m], [deg] and referred to the bottom-left corner of the map, pointing outwards.
Returns
true if cell is valid value inside the map, false otherwise.

Definition at line 850 of file MapGrid2D.cpp.

◆ setResolution()

bool MapGrid2D::setResolution ( double  resolution)

Sets the resolution of the map, i.e.

the conversion factor which represents the metric size of a map cell.

Parameters
resolutionthe map resolution, expressed in [m/cell]. e.g. resolution=0.05 means that each cell of the map represent 5cm of the real world.
Returns
true if resolution is valid (>=0), false otherwise.

Definition at line 884 of file MapGrid2D.cpp.

◆ setSize_in_cells()

bool MapGrid2D::setSize_in_cells ( size_t  x,
size_t  y 
)

Sets the size of the map in cells.

Parameters
x,yis the map size in cells.
Returns
true if the operation was successful, false otherwise.

Definition at line 934 of file MapGrid2D.cpp.

◆ setSize_in_meters()

bool MapGrid2D::setSize_in_meters ( double  x,
double  y 
)

Sets the size of the map in meters, according to the current map resolution.

Parameters
x,yis the map size in meters.
Returns
true if the operation was successful, false otherwise.

Definition at line 916 of file MapGrid2D.cpp.

◆ width()

size_t MapGrid2D::width ( ) const

Retrieves the map width, expressed in cells.

Returns
the map width.

Definition at line 142 of file MapGrid2D.cpp.

◆ write()

bool MapGrid2D::write ( yarp::os::ConnectionWriter connection) const
overridevirtual

Write vector to a connection.

return true iff a vector was written correctly

Implements yarp::os::Portable.

Definition at line 814 of file MapGrid2D.cpp.


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