Skip to content
Snippets Groups Projects
Commit 8da12a60 authored by Projekt Robbie's avatar Projekt Robbie
Browse files

reworking map_manager to use dynamic map sizes

parent 04801341
No related branches found
No related tags found
1 merge request!2Feature/dynamic map size
...@@ -60,12 +60,6 @@ class MapManager ...@@ -60,12 +60,6 @@ class MapManager
* @brief clearMapLayers Clear all map layers * @brief clearMapLayers Clear all map layers
*/ */
void clearMapLayers(); void clearMapLayers();
/** getters */
double getHeight() { return m_Height; }
double getWidth() { return m_Width; }
double getResolution() { return m_Resolution; }
geometry_msgs::Pose getOrigin() { return m_Origin; }
void updateLaser(int layer, const sensor_msgs::LaserScan::ConstPtr& msg ); void updateLaser(int layer, const sensor_msgs::LaserScan::ConstPtr& msg );
...@@ -94,11 +88,7 @@ class MapManager ...@@ -94,11 +88,7 @@ class MapManager
std::map<int, bool> m_MapVisibility; std::map<int, bool> m_MapVisibility;
//sizes of the last slam map //sizes of the last slam map
double m_Height;
double m_Width;
double m_Resolution;
bool m_got_transform; bool m_got_transform;
geometry_msgs::Pose m_Origin;
geometry_msgs::PoseStamped::ConstPtr m_pose; geometry_msgs::PoseStamped::ConstPtr m_pose;
tf::StampedTransform m_sick_transform; tf::StampedTransform m_sick_transform;
tf::StampedTransform m_hokuyo_transform; tf::StampedTransform m_hokuyo_transform;
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include <ros/ros.h> #include <ros/ros.h>
#include <nav_msgs/OccupancyGrid.h> #include <nav_msgs/OccupancyGrid.h>
#include <nav_msgs/MapMetaData.h>
#include <homer_mapnav_msgs/ModifyMap.h> #include <homer_mapnav_msgs/ModifyMap.h>
#include <sstream> #include <sstream>
...@@ -18,11 +19,13 @@ class MaskingManager ...@@ -18,11 +19,13 @@ class MaskingManager
public: public:
/** @brief The constructor. */ /** @brief The constructor. */
MaskingManager(int mapSize, float resolution); MaskingManager(nav_msgs::MapMetaData mapInfo);
/** @brief The destructor. */ /** @brief The destructor. */
virtual ~MaskingManager(); virtual ~MaskingManager();
void updateMapInfo(const nav_msgs::MapMetaData::ConstPtr mapInfo);
/** modifies either the masking layer or the slam layer (accordingly to the given map layer in the msg */ /** modifies either the masking layer or the slam layer (accordingly to the given map layer in the msg */
nav_msgs::OccupancyGrid::ConstPtr modifyMap(homer_mapnav_msgs::ModifyMap::ConstPtr msg); nav_msgs::OccupancyGrid::ConstPtr modifyMap(homer_mapnav_msgs::ModifyMap::ConstPtr msg);
...@@ -39,9 +42,6 @@ class MaskingManager ...@@ -39,9 +42,6 @@ class MaskingManager
/** stores the masking values that are afterwards sent to the slam map */ /** stores the masking values that are afterwards sent to the slam map */
nav_msgs::OccupancyGrid m_SlamMap; nav_msgs::OccupancyGrid m_SlamMap;
/** sizes of the masking map layer */
int m_Width, m_Height;
float m_CellSize;
/** tools to draw masking polygons */ /** tools to draw masking polygons */
void drawPolygon ( std::vector< geometry_msgs::Point > vertices, int value, int mapLayer ); void drawPolygon ( std::vector< geometry_msgs::Point > vertices, int value, int mapLayer );
......
...@@ -23,10 +23,6 @@ MapManager::MapManager(ros::NodeHandle* nh) ...@@ -23,10 +23,6 @@ MapManager::MapManager(ros::NodeHandle* nh)
{ {
m_MapVisibility[m_laser_layers[i]] = true; m_MapVisibility[m_laser_layers[i]] = true;
} }
m_Height = -1;
m_Width = -1;
m_Resolution = -1;
try try
{ {
...@@ -56,14 +52,15 @@ MapManager::~MapManager() ...@@ -56,14 +52,15 @@ MapManager::~MapManager()
void MapManager::updateMapLayer(int type, nav_msgs::OccupancyGrid::ConstPtr layer) void MapManager::updateMapLayer(int type, nav_msgs::OccupancyGrid::ConstPtr layer)
{ {
//TODO possible crash
if(m_MapLayers[type]->info.width != layer->info.width)
{
ROS_INFO_STREAM("Map_manager: map size changed!");
}
m_MapLayers[type] = layer; m_MapLayers[type] = layer;
//if slam map update map sizes
if(type == homer_mapnav_msgs::MapLayers::SLAM_LAYER) if(type == homer_mapnav_msgs::MapLayers::SLAM_LAYER)
{ {
m_Height = layer->info.height;
m_Width = layer->info.width;
m_Resolution = layer->info.resolution;
m_Origin = layer->info.origin;
sendMergedMap(); sendMergedMap();
} }
} }
......
...@@ -2,32 +2,41 @@ ...@@ -2,32 +2,41 @@
using namespace std; using namespace std;
MaskingManager::MaskingManager(int mapSize, float resolution) MaskingManager::MaskingManager(nav_msgs::MapMetaData mapInfo)
{ {
m_CellSize = resolution; m_MaskingMap.info = mapInfo;
m_Width = mapSize / m_CellSize + 1; m_MaskingMap.data.resize(m_MaskingMap.info.width * m_MaskingMap.info.height);
m_Height = mapSize / m_CellSize + 1;
ROS_INFO_STREAM( "Creating " << m_Width << " x " << m_Height << " map." );
m_MaskingMap.info.resolution = m_CellSize;
m_MaskingMap.info.height = m_Height;
m_MaskingMap.info.width = m_Width;
m_MaskingMap.info.origin.position.x = -m_Height * resolution / 2;
m_MaskingMap.info.origin.position.y = -m_Width * resolution / 2;
m_MaskingMap.data.resize(m_Width * m_Height);
std::fill( m_MaskingMap.data.begin(), m_MaskingMap.data.end(), homer_mapnav_msgs::ModifyMap::NOT_MASKED ); std::fill( m_MaskingMap.data.begin(), m_MaskingMap.data.end(), homer_mapnav_msgs::ModifyMap::NOT_MASKED );
m_SlamMap.info.resolution = m_CellSize; m_SlamMap.info = mapInfo;
m_SlamMap.info.height = m_Height; m_SlamMap.data.resize(m_SlamMap.info.width * m_SlamMap.info.height);
m_SlamMap.info.width = m_Width;
m_SlamMap.info.origin.position.x = -m_Height * resolution / 2;
m_SlamMap.info.origin.position.y = -m_Width * resolution / 2;
m_SlamMap.data.resize(m_Width * m_Height);
std::fill( m_SlamMap.data.begin(), m_SlamMap.data.end(), homer_mapnav_msgs::ModifyMap::NOT_MASKED ); std::fill( m_SlamMap.data.begin(), m_SlamMap.data.end(), homer_mapnav_msgs::ModifyMap::NOT_MASKED );
} }
MaskingManager::~MaskingManager() MaskingManager::~MaskingManager()
{} {}
void MaskingManager::updateMapInfo(const nav_msgs::MapMetaData::ConstPtr mapInfo)
{
if(m_SlamMap.info.width != mapInfo.width)
{
m_SlamMap.info = mapInfo;
std::vector<int> tmpData = m_MaskingMap.data;
m_MaskingMap.data.resize(mapInfo.width * mapInfo.height);
std::fill(m_MaskingMap.data.begin(), m_MaskingMap.data.end(), 0);
for(int x = 0; x < )
{
for(int y = 0;)
{
}
}
m_MaskingMap.info = mapInfo;
}
}
nav_msgs::OccupancyGrid::ConstPtr MaskingManager::modifyMap(homer_mapnav_msgs::ModifyMap::ConstPtr msg) nav_msgs::OccupancyGrid::ConstPtr MaskingManager::modifyMap(homer_mapnav_msgs::ModifyMap::ConstPtr msg)
{ {
//reset SLAM mask map before each masking //reset SLAM mask map before each masking
...@@ -69,11 +78,8 @@ void MaskingManager::drawPolygon ( vector< geometry_msgs::Point > vertices , int ...@@ -69,11 +78,8 @@ void MaskingManager::drawPolygon ( vector< geometry_msgs::Point > vertices , int
return; return;
} }
//make temp. map //make temp. map
std::vector<int> data(m_Width * m_Height); std::vector<int> data(m_MaskingMap.info.width * m_MaskingMap.info.height);
for ( int i = 0; i < data.size(); i++ ) std::fill (data.begin(), data.end(), 0);
{
data[i] = 0;
}
//draw the lines surrounding the polygon //draw the lines surrounding the polygon
for ( unsigned int i = 0; i < vertices.size(); i++ ) for ( unsigned int i = 0; i < vertices.size(); i++ )
...@@ -153,7 +159,7 @@ void MaskingManager::drawLine ( std::vector<int> &data, int startX, int startY, ...@@ -153,7 +159,7 @@ void MaskingManager::drawLine ( std::vector<int> &data, int startX, int startY,
// compute cells // compute cells
for ( t = 0; t < dist; t++ ) for ( t = 0; t < dist; t++ )
{ {
data[x + m_Width * y] = value; data[x + m_MaskingMap.info.width * y] = value;
xerr += dx; xerr += dx;
yerr += dy; yerr += dy;
...@@ -173,7 +179,7 @@ void MaskingManager::drawLine ( std::vector<int> &data, int startX, int startY, ...@@ -173,7 +179,7 @@ void MaskingManager::drawLine ( std::vector<int> &data, int startX, int startY,
void MaskingManager::fillPolygon ( std::vector<int> &data, int x, int y, int value ) void MaskingManager::fillPolygon ( std::vector<int> &data, int x, int y, int value )
{ {
int index = x + m_Width * y; int index = x + m_MaskingMap.info.width * y;
if ( value != data[index] ) if ( value != data[index] )
{ {
data[index] = value; data[index] = value;
......
...@@ -15,7 +15,20 @@ MapManagerNode::MapManagerNode(ros::NodeHandle *nh) ...@@ -15,7 +15,20 @@ MapManagerNode::MapManagerNode(ros::NodeHandle *nh)
m_MapManager = new MapManager(nh); m_MapManager = new MapManager(nh);
m_POIManager = new PoiManager(nh); m_POIManager = new PoiManager(nh);
m_ROIManager = new RoiManager(nh); m_ROIManager = new RoiManager(nh);
m_MaskingManager = new MaskingManager(mapSize, resolution);
nav_msgs::MapMetaData mapInfo;
mapInfo.width = mapSize / resolution;
mapInfo.height = mapSize / resolution;
mapInfo.resolution = resolution;
mapInfo.origin.position.x = 0;
mapInfo.origin.position.y = 0;
mapInfo.origin.position.z = 0;
mapInfo.origin.orientation.x = 0;
mapInfo.origin.orientation.y = 0;
mapInfo.origin.orientation.z = 0;
mapInfo.origin.orientation.w = 1;
m_MaskingManager = new MaskingManager(mapInfo);
//subscriptions of MapManagerModule //subscriptions of MapManagerModule
m_RapidMapSubscriber = nh->subscribe("/rapid_mapping/map", 1, &MapManagerNode::callbackRapidMap, this); m_RapidMapSubscriber = nh->subscribe("/rapid_mapping/map", 1, &MapManagerNode::callbackRapidMap, this);
...@@ -88,6 +101,7 @@ MapManagerNode::~MapManagerNode() ...@@ -88,6 +101,7 @@ MapManagerNode::~MapManagerNode()
void MapManagerNode::callbackSLAMMap(const nav_msgs::OccupancyGrid::ConstPtr &msg) void MapManagerNode::callbackSLAMMap(const nav_msgs::OccupancyGrid::ConstPtr &msg)
{ {
m_MapManager->updateMapLayer(homer_mapnav_msgs::MapLayers::SLAM_LAYER, msg); m_MapManager->updateMapLayer(homer_mapnav_msgs::MapLayers::SLAM_LAYER, msg);
m_MaskingManager->updateMapInfo(const nav_msgs::MapMetaData::ConstPtr msg->info);
} }
void MapManagerNode::callbackRapidMap( const nav_msgs::OccupancyGrid::ConstPtr& msg) void MapManagerNode::callbackRapidMap( const nav_msgs::OccupancyGrid::ConstPtr& msg)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment