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

#include <yarp/dev/MapGrid2D.h>

+ Inheritance diagram for yarp::dev::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
 
typedef yarp::math::Vec2D< int > XYCell
 
typedef yarp::math::Vec2D< double > XYWorld
 

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 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...
 
XYWorld cell2World (XYCell cell) const
 
XYCell world2Cell (XYWorld world) 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...
 
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...
 
virtual bool read (yarp::os::ConnectionReader &connection) YARP_OVERRIDE
 Read this object from a network connection. More...
 
virtual bool write (yarp::os::ConnectionWriter &connection) YARP_OVERRIDE
 Write vector to a connection. More...
 
- Public Member Functions inherited from yarp::os::Portable
virtual Type getType ()
 
- Public Member Functions inherited from yarp::os::PortReader
virtual ~PortReader ()
 Destructor. More...
 
virtual Type getReadType ()
 
- Public Member Functions inherited from yarp::os::PortWriter
virtual ~PortWriter ()
 Destructor. More...
 
virtual void onCompletion ()
 This is called when the port has finished all writing operations. More...
 
virtual void onCommencement ()
 This is called when the port is about to begin writing operations. More...
 
virtual Type getWriteType ()
 

Private Member Functions

void enlargeCell (XYCell cell)
 
CellData PixelToCellData (const yarp::sig::PixelRgb &pixin) const
 
yarp::sig::PixelRgb CellDataToPixel (const CellData &pixin) const
 
bool loadMapYarpOnly (std::string yarp_img_filename)
 
bool loadMapROSOnly (std::string ros_yaml_filename)
 
bool loadROSParams (std::string ros_yaml_filename, std::string &pgm_occ_filename, double &resolution, double &orig_x, double &orig_y, double &orig_t)
 
bool loadMapYarpAndRos (std::string yarp_img_filename, std::string ros_yaml_filename)
 

Private Attributes

yarp::sig::ImageOf< CellDatam_map_occupancy
 
yarp::sig::ImageOf< CellDatam_map_flags
 
double m_resolution
 
double m_occupied_thresh
 
double m_free_thresh
 
size_t m_width
 
size_t m_height
 
std::string m_map_name
 
struct {
   double   x
 
   double   y
 
   double   theta
 
m_origin
 

Additional Inherited Members

- Static Public Member Functions inherited from yarp::os::Portable
static bool copyPortable (PortWriter &writer, PortReader &reader)
 Copy one portable to another, via writing and reading. More...
 

Detailed Description

Definition at line 23 of file MapGrid2D.h.

Member Typedef Documentation

◆ CellData

◆ XYCell

Definition at line 27 of file MapGrid2D.h.

◆ XYWorld

Definition at line 28 of file MapGrid2D.h.

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 29 of file MapGrid2D.h.

Constructor & Destructor Documentation

◆ MapGrid2D()

MapGrid2D::MapGrid2D ( )

Definition at line 55 of file MapGrid2D.cpp.

◆ ~MapGrid2D()

MapGrid2D::~MapGrid2D ( )
virtual

Definition at line 79 of file MapGrid2D.cpp.

Member Function Documentation

◆ cell2World()

MapGrid2D::XYWorld MapGrid2D::cell2World ( MapGrid2D::XYCell  cell) const

Definition at line 673 of file MapGrid2D.cpp.

◆ CellDataToPixel()

yarp::sig::PixelRgb MapGrid2D::CellDataToPixel ( const CellData pixin) const
private

Definition at line 536 of file MapGrid2D.cpp.

◆ enlargeCell()

void MapGrid2D::enlargeCell ( XYCell  cell)
private

Definition at line 219 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 robot bounding box. In this way a navigation algorithm can easly check obstacle collision by comparing the location of the center of the robot with cell value (free/occupied etc)

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

Definition at line 172 of file MapGrid2D.cpp.

◆ getMapImage()

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

Definition at line 139 of file MapGrid2D.cpp.

◆ getMapName()

std::string MapGrid2D::getMapName ( ) const

Retrieves the map name.

Returns
the map_name.

Definition at line 806 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 879 of file MapGrid2D.cpp.

◆ getOccupancyGrid()

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

Definition at line 902 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 772 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 790 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 851 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 845 of file MapGrid2D.cpp.

◆ height()

size_t MapGrid2D::height ( ) const

Retrieves the map height, expressed in cells.

Returns
the map height.

Definition at line 129 of file MapGrid2D.cpp.

◆ isFree()

bool MapGrid2D::isFree ( MapGrid2D::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 96 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 39 of file MapGrid2D.cpp.

◆ isInsideMap() [1/2]

bool MapGrid2D::isInsideMap ( MapGrid2D::XYCell  cell) const

Checks if a cell is inside the map.

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

Definition at line 732 of file MapGrid2D.cpp.

◆ isInsideMap() [2/2]

bool MapGrid2D::isInsideMap ( MapGrid2D::XYWorld  world) const

Checks if a world coordinate is inside the map.

Parameters
worldis the world cordinate, expressed in meters, referred to the map origin reference frame.
Returns
true if cell is inside the map, false otherwise.

Definition at line 726 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 throught 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 107 of file MapGrid2D.cpp.

◆ isNotFree()

bool MapGrid2D::isNotFree ( MapGrid2D::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 84 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 117 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 sucessfull, false otherwise.

Definition at line 460 of file MapGrid2D.cpp.

◆ loadMapROSOnly()

bool MapGrid2D::loadMapROSOnly ( std::string  ros_yaml_filename)
private

Definition at line 360 of file MapGrid2D.cpp.

◆ loadMapYarpAndRos()

bool MapGrid2D::loadMapYarpAndRos ( std::string  yarp_img_filename,
std::string  ros_yaml_filename 
)
private

Definition at line 290 of file MapGrid2D.cpp.

◆ loadMapYarpOnly()

bool MapGrid2D::loadMapYarpOnly ( std::string  yarp_img_filename)
private

Definition at line 414 of file MapGrid2D.cpp.

◆ loadROSParams()

bool MapGrid2D::loadROSParams ( std::string  ros_yaml_filename,
std::string &  pgm_occ_filename,
double &  resolution,
double &  orig_x,
double &  orig_y,
double &  orig_t 
)
private

Definition at line 238 of file MapGrid2D.cpp.

◆ PixelToCellData()

MapGrid2D::CellData MapGrid2D::PixelToCellData ( const yarp::sig::PixelRgb pixin) const
private

Definition at line 527 of file MapGrid2D.cpp.

◆ read()

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

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 591 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 sucessfull, false otherwise.

Definition at line 553 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 857 of file MapGrid2D.cpp.

◆ setMapImage()

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

Definition at line 154 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 795 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 868 of file MapGrid2D.cpp.

◆ setOccupancyGrid()

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

Definition at line 890 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 741 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 779 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 sucessfull, false otherwise.

Definition at line 829 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 sucessfull, false otherwise.

Definition at line 811 of file MapGrid2D.cpp.

◆ width()

size_t MapGrid2D::width ( ) const

Retrieves the map width, expressed in cells.

Returns
the map width.

Definition at line 134 of file MapGrid2D.cpp.

◆ world2Cell()

MapGrid2D::XYCell MapGrid2D::world2Cell ( MapGrid2D::XYWorld  world) const

Definition at line 702 of file MapGrid2D.cpp.

◆ write()

bool MapGrid2D::write ( yarp::os::ConnectionWriter connection)
virtual

Write vector to a connection.

return true iff a vector was written correctly

Implements yarp::os::Portable.

Definition at line 637 of file MapGrid2D.cpp.

Member Data Documentation

◆ m_free_thresh

double yarp::dev::MapGrid2D::m_free_thresh
private

Definition at line 45 of file MapGrid2D.h.

◆ m_height

size_t yarp::dev::MapGrid2D::m_height
private

Definition at line 47 of file MapGrid2D.h.

◆ m_map_flags

yarp::sig::ImageOf<CellData> yarp::dev::MapGrid2D::m_map_flags
private

Definition at line 41 of file MapGrid2D.h.

◆ m_map_name

std::string yarp::dev::MapGrid2D::m_map_name
private

Definition at line 48 of file MapGrid2D.h.

◆ m_map_occupancy

yarp::sig::ImageOf<CellData> yarp::dev::MapGrid2D::m_map_occupancy
private

Definition at line 40 of file MapGrid2D.h.

◆ m_occupied_thresh

double yarp::dev::MapGrid2D::m_occupied_thresh
private

Definition at line 44 of file MapGrid2D.h.

◆ m_origin

struct { ... } yarp::dev::MapGrid2D::m_origin

◆ m_resolution

double yarp::dev::MapGrid2D::m_resolution
private

Definition at line 43 of file MapGrid2D.h.

◆ m_width

size_t yarp::dev::MapGrid2D::m_width
private

Definition at line 46 of file MapGrid2D.h.

◆ theta

double yarp::dev::MapGrid2D::theta

Definition at line 54 of file MapGrid2D.h.

◆ x

double yarp::dev::MapGrid2D::x

Definition at line 52 of file MapGrid2D.h.

◆ y

double yarp::dev::MapGrid2D::y

Definition at line 53 of file MapGrid2D.h.


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