2013-12-11 00:12:44 +00:00
|
|
|
/*
|
2016-07-17 22:06:11 -04:00
|
|
|
Copyright (c) 2010-2016, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
|
2014-08-11 17:03:39 +00:00
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
|
modification, are permitted provided that the following conditions are met:
|
|
|
|
|
* Redistributions of source code must retain the above copyright
|
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
|
* Redistributions in binary form must reproduce the above copyright
|
|
|
|
|
notice, this list of conditions and the following disclaimer in the
|
|
|
|
|
documentation and/or other materials provided with the distribution.
|
|
|
|
|
* Neither the name of the Universite de Sherbrooke nor the
|
|
|
|
|
names of its contributors may be used to endorse or promote products
|
|
|
|
|
derived from this software without specific prior written permission.
|
|
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
|
|
|
|
|
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
|
|
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
*/
|
2013-12-11 00:12:44 +00:00
|
|
|
|
2014-08-20 16:57:49 +00:00
|
|
|
#include <ros/ros.h>
|
2014-11-25 17:13:15 -05:00
|
|
|
#include "rtabmap_ros/MapData.h"
|
|
|
|
|
#include "rtabmap_ros/MsgConversion.h"
|
2015-10-31 15:20:57 -04:00
|
|
|
#include "MapsManager.h"
|
2015-05-13 19:55:18 -04:00
|
|
|
#include <rtabmap/core/util3d_transforms.h>
|
2014-08-20 16:57:49 +00:00
|
|
|
#include <rtabmap/core/util3d.h>
|
2015-05-13 19:55:18 -04:00
|
|
|
#include <rtabmap/core/util3d_filtering.h>
|
|
|
|
|
#include <rtabmap/core/util3d_mapping.h>
|
2015-01-23 11:19:19 -05:00
|
|
|
#include <rtabmap/core/Compression.h>
|
|
|
|
|
#include <rtabmap/core/Graph.h>
|
2014-08-20 16:57:49 +00:00
|
|
|
#include <rtabmap/utilite/ULogger.h>
|
|
|
|
|
#include <rtabmap/utilite/UStl.h>
|
2015-02-11 17:09:29 -05:00
|
|
|
#include <rtabmap/utilite/UTimer.h>
|
2013-12-11 00:12:44 +00:00
|
|
|
#include <pcl_ros/transforms.h>
|
|
|
|
|
#include <pcl_conversions/pcl_conversions.h>
|
2014-10-20 21:48:59 +00:00
|
|
|
#include <nav_msgs/OccupancyGrid.h>
|
2014-11-02 01:04:49 +00:00
|
|
|
#include <std_srvs/Empty.h>
|
2013-12-11 00:12:44 +00:00
|
|
|
|
|
|
|
|
using namespace rtabmap;
|
|
|
|
|
|
|
|
|
|
class MapAssembler
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
MapAssembler() :
|
2015-10-31 15:20:57 -04:00
|
|
|
mapsManager_(false)
|
2013-12-11 00:12:44 +00:00
|
|
|
{
|
|
|
|
|
ros::NodeHandle pnh("~");
|
2014-10-20 21:48:59 +00:00
|
|
|
|
2013-12-11 00:12:44 +00:00
|
|
|
ros::NodeHandle nh;
|
|
|
|
|
mapDataTopic_ = nh.subscribe("mapData", 1, &MapAssembler::mapDataReceivedCallback, this);
|
|
|
|
|
|
2014-11-02 01:04:49 +00:00
|
|
|
// private service
|
|
|
|
|
resetService_ = pnh.advertiseService("reset", &MapAssembler::reset, this);
|
2013-12-11 00:12:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~MapAssembler()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-25 17:13:15 -05:00
|
|
|
void mapDataReceivedCallback(const rtabmap_ros::MapDataConstPtr & msg)
|
2013-12-11 00:12:44 +00:00
|
|
|
{
|
2015-02-11 17:09:29 -05:00
|
|
|
UTimer timer;
|
2015-10-31 15:20:57 -04:00
|
|
|
|
|
|
|
|
std::map<int, Transform> poses;
|
|
|
|
|
std::multimap<int, Link> constraints;
|
|
|
|
|
Transform mapOdom;
|
|
|
|
|
rtabmap_ros::mapGraphFromROS(msg->graph, poses, constraints, mapOdom);
|
2014-10-26 21:49:30 +00:00
|
|
|
for(unsigned int i=0; i<msg->nodes.size(); ++i)
|
2014-07-04 23:12:34 +00:00
|
|
|
{
|
2015-10-31 15:20:57 -04:00
|
|
|
if(msg->nodes[i].image.size() ||
|
|
|
|
|
msg->nodes[i].depth.size() ||
|
|
|
|
|
msg->nodes[i].laserScan.size())
|
2013-12-11 00:12:44 +00:00
|
|
|
{
|
2015-10-31 15:20:57 -04:00
|
|
|
uInsert(nodes_, std::make_pair(msg->nodes[i].id, rtabmap_ros::nodeDataFromROS(msg->nodes[i])));
|
2014-01-08 16:11:44 +00:00
|
|
|
}
|
2013-12-11 00:12:44 +00:00
|
|
|
}
|
|
|
|
|
|
2015-10-31 15:20:57 -04:00
|
|
|
// create a tmp signature with latest sensory data
|
|
|
|
|
if(poses.size() && nodes_.find(poses.rbegin()->first) != nodes_.end())
|
2014-10-20 21:48:59 +00:00
|
|
|
{
|
2015-10-31 15:20:57 -04:00
|
|
|
Signature tmpS = nodes_.at(poses.rbegin()->first);
|
|
|
|
|
SensorData tmpData = tmpS.sensorData();
|
|
|
|
|
tmpData.setId(-1);
|
2016-01-12 16:07:15 -05:00
|
|
|
uInsert(nodes_, std::make_pair(-1, Signature(-1, -1, 0, tmpS.getStamp(), "", tmpS.getPose(), Transform(), tmpData)));
|
2015-10-31 15:20:57 -04:00
|
|
|
poses.insert(std::make_pair(-1, poses.rbegin()->second));
|
2014-10-20 21:48:59 +00:00
|
|
|
}
|
2014-01-08 16:11:44 +00:00
|
|
|
|
2015-10-31 15:20:57 -04:00
|
|
|
// Update maps
|
|
|
|
|
poses = mapsManager_.updateMapCaches(
|
|
|
|
|
poses,
|
|
|
|
|
0,
|
|
|
|
|
false,
|
|
|
|
|
false,
|
|
|
|
|
false,
|
|
|
|
|
false,
|
2016-06-28 19:02:01 -04:00
|
|
|
false,
|
2015-10-31 15:20:57 -04:00
|
|
|
nodes_);
|
2013-12-11 00:12:44 +00:00
|
|
|
|
2015-10-31 15:20:57 -04:00
|
|
|
mapsManager_.publishMaps(poses, msg->header.stamp, msg->header.frame_id);
|
2013-12-11 00:12:44 +00:00
|
|
|
|
2015-10-31 15:20:57 -04:00
|
|
|
ROS_INFO("map_assembler: Publishing data = %fs", timer.ticks());
|
2013-12-11 00:12:44 +00:00
|
|
|
}
|
|
|
|
|
|
2014-11-02 01:04:49 +00:00
|
|
|
bool reset(std_srvs::Empty::Request&, std_srvs::Empty::Response&)
|
|
|
|
|
{
|
|
|
|
|
ROS_INFO("map_assembler: reset!");
|
2015-10-31 15:20:57 -04:00
|
|
|
mapsManager_.clear();
|
2014-11-02 01:04:49 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-11 00:12:44 +00:00
|
|
|
private:
|
2015-10-31 15:20:57 -04:00
|
|
|
MapsManager mapsManager_;
|
|
|
|
|
std::map<int, Signature> nodes_;
|
2014-10-20 21:48:59 +00:00
|
|
|
|
2013-12-11 00:12:44 +00:00
|
|
|
ros::Subscriber mapDataTopic_;
|
|
|
|
|
|
2014-11-02 01:04:49 +00:00
|
|
|
ros::ServiceServer resetService_;
|
2013-12-11 00:12:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char** argv)
|
|
|
|
|
{
|
|
|
|
|
ros::init(argc, argv, "map_assembler");
|
|
|
|
|
MapAssembler assembler;
|
|
|
|
|
ros::spin();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|