2011-06-20 16:49:22 +00:00
|
|
|
/*
|
2014-08-11 17:03:39 +00:00
|
|
|
Copyright (c) 2010-2014, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
|
|
|
|
|
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.
|
|
|
|
|
*/
|
2011-06-20 16:49:22 +00:00
|
|
|
|
|
|
|
|
#ifndef COREWRAPPER_H_
|
|
|
|
|
#define COREWRAPPER_H_
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <ros/ros.h>
|
|
|
|
|
|
2013-12-11 00:12:44 +00:00
|
|
|
#include <tf/tf.h>
|
|
|
|
|
#include <tf/transform_broadcaster.h>
|
|
|
|
|
#include <tf/transform_listener.h>
|
|
|
|
|
|
|
|
|
|
#include <std_srvs/Empty.h>
|
|
|
|
|
|
|
|
|
|
#include <cv_bridge/cv_bridge.h>
|
|
|
|
|
|
|
|
|
|
#include <std_msgs/Empty.h>
|
2015-01-30 15:31:44 -05:00
|
|
|
#include <std_msgs/Int32.h>
|
2013-12-11 00:12:44 +00:00
|
|
|
#include <sensor_msgs/PointCloud2.h>
|
|
|
|
|
#include <sensor_msgs/Image.h>
|
|
|
|
|
#include <sensor_msgs/CameraInfo.h>
|
|
|
|
|
#include <sensor_msgs/LaserScan.h>
|
|
|
|
|
#include <nav_msgs/Odometry.h>
|
2015-02-11 17:09:29 -05:00
|
|
|
#include <nav_msgs/GetMap.h>
|
2013-12-11 00:12:44 +00:00
|
|
|
|
|
|
|
|
#include <rtabmap/core/Statistics.h>
|
|
|
|
|
#include <rtabmap/core/Parameters.h>
|
|
|
|
|
#include <rtabmap/core/Rtabmap.h>
|
|
|
|
|
|
2014-11-25 17:13:15 -05:00
|
|
|
#include "rtabmap_ros/GetMap.h"
|
|
|
|
|
#include "rtabmap_ros/PublishMap.h"
|
2015-02-06 13:56:20 -05:00
|
|
|
#include "rtabmap_ros/SetGoal.h"
|
2014-07-06 19:58:15 +00:00
|
|
|
|
2013-12-11 00:12:44 +00:00
|
|
|
#include <message_filters/subscriber.h>
|
|
|
|
|
#include <message_filters/synchronizer.h>
|
|
|
|
|
#include <message_filters/sync_policies/approximate_time.h>
|
2014-11-14 19:16:16 +00:00
|
|
|
#include <message_filters/sync_policies/exact_time.h>
|
2013-12-11 00:12:44 +00:00
|
|
|
|
|
|
|
|
#include <image_transport/image_transport.h>
|
|
|
|
|
#include <image_transport/subscriber_filter.h>
|
2011-06-20 16:49:22 +00:00
|
|
|
|
2015-02-11 17:09:29 -05:00
|
|
|
#include <pcl/point_types.h>
|
|
|
|
|
#include <pcl/point_cloud.h>
|
|
|
|
|
|
2015-02-06 15:27:02 -05:00
|
|
|
#include <actionlib/client/simple_action_client.h>
|
|
|
|
|
#include <move_base_msgs/MoveBaseAction.h>
|
|
|
|
|
#include <move_base_msgs/MoveBaseActionGoal.h>
|
|
|
|
|
#include <move_base_msgs/MoveBaseActionResult.h>
|
|
|
|
|
#include <move_base_msgs/MoveBaseActionFeedback.h>
|
|
|
|
|
#include <actionlib_msgs/GoalStatusArray.h>
|
|
|
|
|
typedef actionlib::SimpleActionClient<move_base_msgs::MoveBaseAction> MoveBaseClient;
|
|
|
|
|
|
2013-02-03 22:12:44 +00:00
|
|
|
class CoreWrapper
|
2011-06-20 16:49:22 +00:00
|
|
|
{
|
|
|
|
|
public:
|
2014-10-28 01:23:52 +00:00
|
|
|
CoreWrapper(bool deleteDbOnStart);
|
2011-06-20 16:49:22 +00:00
|
|
|
virtual ~CoreWrapper();
|
|
|
|
|
|
|
|
|
|
private:
|
2014-11-14 19:16:16 +00:00
|
|
|
void setupCallbacks(bool subscribeDepth, bool subscribeLaserScan, bool subscribeStereo, int queueSize, bool stereoApproxSync);
|
2013-12-11 00:12:44 +00:00
|
|
|
void defaultCallback(const sensor_msgs::ImageConstPtr & imageMsg); // no odom
|
2014-12-18 16:58:23 -05:00
|
|
|
|
|
|
|
|
bool commonMetricCallbackBegin(const nav_msgs::OdometryConstPtr & odomMsg);
|
2013-12-11 00:12:44 +00:00
|
|
|
void depthCallback(const sensor_msgs::ImageConstPtr& imageMsg,
|
|
|
|
|
const nav_msgs::OdometryConstPtr & odomMsg,
|
|
|
|
|
const sensor_msgs::ImageConstPtr& imageDepthMsg,
|
|
|
|
|
const sensor_msgs::CameraInfoConstPtr& camInfoMsg);
|
|
|
|
|
void depthScanCallback(const sensor_msgs::ImageConstPtr& imageMsg,
|
|
|
|
|
const nav_msgs::OdometryConstPtr & odomMsg,
|
|
|
|
|
const sensor_msgs::ImageConstPtr& imageDepthMsg,
|
|
|
|
|
const sensor_msgs::CameraInfoConstPtr& camInfoMsg,
|
|
|
|
|
const sensor_msgs::LaserScanConstPtr& scanMsg);
|
2014-10-16 00:17:11 +00:00
|
|
|
void stereoCallback(const sensor_msgs::ImageConstPtr& leftImageMsg,
|
|
|
|
|
const sensor_msgs::ImageConstPtr& rightImageMsg,
|
|
|
|
|
const sensor_msgs::CameraInfoConstPtr& leftCamInfoMsg,
|
|
|
|
|
const sensor_msgs::CameraInfoConstPtr& rightCamInfoMsg,
|
|
|
|
|
const nav_msgs::OdometryConstPtr & odomMsg);
|
|
|
|
|
void stereoScanCallback(const sensor_msgs::ImageConstPtr& leftImageMsg,
|
|
|
|
|
const sensor_msgs::ImageConstPtr& rightImageMsg,
|
|
|
|
|
const sensor_msgs::CameraInfoConstPtr& leftCamInfoMsg,
|
|
|
|
|
const sensor_msgs::CameraInfoConstPtr& rightCamInfoMsg,
|
|
|
|
|
const sensor_msgs::LaserScanConstPtr& scanMsg,
|
|
|
|
|
const nav_msgs::OdometryConstPtr & odomMsg);
|
2015-02-06 13:56:20 -05:00
|
|
|
|
|
|
|
|
void goalCommonCallback(const std::list<std::pair<int, rtabmap::Transform> > & poses);
|
|
|
|
|
void goalCallback(const geometry_msgs::PoseStampedConstPtr & msg);
|
|
|
|
|
void goalGlobalCallback(const geometry_msgs::PoseStampedConstPtr & msg);
|
2015-02-03 11:16:06 -05:00
|
|
|
void updateGoal(const ros::Time & stamp);
|
2011-06-20 16:49:22 +00:00
|
|
|
|
2013-12-11 00:12:44 +00:00
|
|
|
void process(
|
|
|
|
|
int id,
|
|
|
|
|
const cv::Mat & image,
|
|
|
|
|
const rtabmap::Transform & odom = rtabmap::Transform(),
|
|
|
|
|
const std::string & odomFrameId = "",
|
2014-12-14 16:44:13 -05:00
|
|
|
float odomVariance = 1.0f,
|
2014-10-16 00:17:11 +00:00
|
|
|
const cv::Mat & depthOrRightImage = cv::Mat(),
|
2014-10-13 19:14:30 +00:00
|
|
|
float fx = 0.0f,
|
2014-10-16 00:17:11 +00:00
|
|
|
float fyOrBaseline = 0.0f,
|
2014-10-13 19:14:30 +00:00
|
|
|
float cx = 0.0f,
|
|
|
|
|
float cy = 0.0f,
|
2013-12-11 00:12:44 +00:00
|
|
|
const rtabmap::Transform & localTransform = rtabmap::Transform(),
|
|
|
|
|
const cv::Mat & scan = cv::Mat());
|
2011-06-20 16:49:22 +00:00
|
|
|
|
2013-12-11 00:12:44 +00:00
|
|
|
bool updateRtabmapCallback(std_srvs::Empty::Request&, std_srvs::Empty::Response&);
|
|
|
|
|
bool resetRtabmapCallback(std_srvs::Empty::Request&, std_srvs::Empty::Response&);
|
|
|
|
|
bool pauseRtabmapCallback(std_srvs::Empty::Request&, std_srvs::Empty::Response&);
|
|
|
|
|
bool resumeRtabmapCallback(std_srvs::Empty::Request&, std_srvs::Empty::Response&);
|
|
|
|
|
bool triggerNewMapCallback(std_srvs::Empty::Request&, std_srvs::Empty::Response&);
|
2014-07-09 21:12:24 +00:00
|
|
|
bool setModeLocalizationCallback(std_srvs::Empty::Request&, std_srvs::Empty::Response&);
|
|
|
|
|
bool setModeMappingCallback(std_srvs::Empty::Request&, std_srvs::Empty::Response&);
|
2015-02-11 17:09:29 -05:00
|
|
|
bool getMapCallback(rtabmap_ros::GetMap::Request& req, rtabmap_ros::GetMap::Response& res);
|
|
|
|
|
bool getProjMapCallback(nav_msgs::GetMap::Request &req, nav_msgs::GetMap::Response &res);
|
|
|
|
|
bool getGridMapCallback(nav_msgs::GetMap::Request &req, nav_msgs::GetMap::Response &res);
|
2014-11-25 17:13:15 -05:00
|
|
|
bool publishMapCallback(rtabmap_ros::PublishMap::Request&, rtabmap_ros::PublishMap::Response&);
|
2015-02-06 13:56:20 -05:00
|
|
|
bool setGoalCallback(rtabmap_ros::SetGoal::Request& req, rtabmap_ros::SetGoal::Response& res);
|
2013-12-11 00:12:44 +00:00
|
|
|
|
|
|
|
|
rtabmap::ParametersMap loadParameters(const std::string & configFile);
|
|
|
|
|
void saveParameters(const std::string & configFile);
|
|
|
|
|
|
|
|
|
|
void publishLoop(double tfDelay);
|
2011-06-20 16:49:22 +00:00
|
|
|
|
2015-02-11 17:09:29 -05:00
|
|
|
void publishStats(const ros::Time & stamp);
|
|
|
|
|
std::map<int, rtabmap::Transform> updateMapCaches(const std::map<int, rtabmap::Transform> & poses, bool updateCloud, bool updateProj, bool updateGrid);
|
|
|
|
|
void publishMaps(const std::map<int, rtabmap::Transform> & poses, const ros::Time & stamp);
|
2015-02-06 13:56:20 -05:00
|
|
|
void publishCurrentGoal(const ros::Time & stamp);
|
2015-02-06 15:27:02 -05:00
|
|
|
void goalDoneCb(const actionlib::SimpleClientGoalState& state, const move_base_msgs::MoveBaseResultConstPtr& result);
|
|
|
|
|
void goalActiveCb();
|
|
|
|
|
void goalFeedbackCb(const move_base_msgs::MoveBaseFeedbackConstPtr& feedback);
|
2015-02-03 11:16:06 -05:00
|
|
|
void publishLocalPath(const ros::Time & stamp);
|
2011-06-20 16:49:22 +00:00
|
|
|
|
|
|
|
|
private:
|
2013-12-11 00:12:44 +00:00
|
|
|
rtabmap::Rtabmap rtabmap_;
|
|
|
|
|
bool paused_;
|
2014-12-18 16:58:23 -05:00
|
|
|
rtabmap::Transform lastPose_;
|
|
|
|
|
float _variance;
|
2015-01-30 15:31:44 -05:00
|
|
|
rtabmap::Transform currentMetricGoal_;
|
2013-12-11 00:12:44 +00:00
|
|
|
|
|
|
|
|
std::string frameId_;
|
|
|
|
|
std::string mapFrameId_;
|
|
|
|
|
std::string odomFrameId_;
|
2013-04-30 20:25:52 +00:00
|
|
|
std::string configPath_;
|
2014-10-28 01:23:52 +00:00
|
|
|
std::string databasePath_;
|
2014-12-03 22:35:43 -05:00
|
|
|
bool waitForTransform_;
|
2015-02-06 15:27:02 -05:00
|
|
|
bool useActionForGoal_;
|
2011-06-20 16:49:22 +00:00
|
|
|
|
2015-02-11 17:09:29 -05:00
|
|
|
// mapping stuff
|
|
|
|
|
int cloudDecimation_;
|
|
|
|
|
double cloudMaxDepth_;
|
|
|
|
|
double cloudVoxelSize_;
|
|
|
|
|
double projMaxGroundAngle_;
|
|
|
|
|
int projMinClusterSize_;
|
|
|
|
|
double projMaxHeight_;
|
|
|
|
|
double gridCellSize_;
|
|
|
|
|
double gridSize_;
|
|
|
|
|
double mapFilterRadius_;
|
|
|
|
|
double mapFilterAngle_;
|
|
|
|
|
|
2013-12-11 00:12:44 +00:00
|
|
|
tf::Transform mapToOdom_;
|
|
|
|
|
boost::mutex mapToOdomMutex_;
|
|
|
|
|
|
2015-02-11 17:09:29 -05:00
|
|
|
std::map<int, pcl::PointCloud<pcl::PointXYZRGB>::Ptr > clouds_;
|
|
|
|
|
std::map<int, std::pair<cv::Mat, cv::Mat> > projMaps_; // <ground, obstacles>
|
|
|
|
|
std::map<int, std::pair<cv::Mat, cv::Mat> > gridMaps_; // <ground, obstacles>
|
|
|
|
|
|
2013-12-11 00:12:44 +00:00
|
|
|
ros::Publisher infoPub_;
|
2015-02-11 17:09:29 -05:00
|
|
|
ros::Publisher mapDataPub_;
|
|
|
|
|
ros::Publisher mapGraphPub_;
|
|
|
|
|
ros::Publisher cloudMapPub_;
|
|
|
|
|
ros::Publisher projMapPub_;
|
|
|
|
|
ros::Publisher gridMapPub_;
|
2013-12-11 00:12:44 +00:00
|
|
|
|
2015-01-30 15:31:44 -05:00
|
|
|
//Planning stuff
|
2015-02-06 13:56:20 -05:00
|
|
|
ros::Subscriber goalSub_;
|
|
|
|
|
ros::Subscriber goalGlobalSub_;
|
2015-01-30 15:31:44 -05:00
|
|
|
ros::Publisher nextMetricGoalPub_;
|
|
|
|
|
ros::Publisher goalReachedPub_;
|
2015-02-03 11:16:06 -05:00
|
|
|
ros::Publisher globalPathPub_;
|
|
|
|
|
ros::Publisher localPathPub_;
|
2015-01-30 15:31:44 -05:00
|
|
|
|
2014-10-16 00:17:11 +00:00
|
|
|
// for loop closure detection only
|
2013-12-11 00:12:44 +00:00
|
|
|
image_transport::Subscriber defaultSub_;
|
2014-10-16 00:17:11 +00:00
|
|
|
|
|
|
|
|
//for depth callback
|
2013-12-11 00:12:44 +00:00
|
|
|
image_transport::SubscriberFilter imageSub_;
|
|
|
|
|
image_transport::SubscriberFilter imageDepthSub_;
|
|
|
|
|
message_filters::Subscriber<sensor_msgs::CameraInfo> cameraInfoSub_;
|
2014-10-16 00:17:11 +00:00
|
|
|
|
|
|
|
|
//stereo callback
|
|
|
|
|
image_transport::SubscriberFilter imageRectLeft_;
|
|
|
|
|
image_transport::SubscriberFilter imageRectRight_;
|
|
|
|
|
message_filters::Subscriber<sensor_msgs::CameraInfo> cameraInfoLeft_;
|
|
|
|
|
message_filters::Subscriber<sensor_msgs::CameraInfo> cameraInfoRight_;
|
|
|
|
|
|
2013-12-11 00:12:44 +00:00
|
|
|
message_filters::Subscriber<nav_msgs::Odometry> odomSub_;
|
|
|
|
|
message_filters::Subscriber<sensor_msgs::LaserScan> scanSub_;
|
|
|
|
|
|
|
|
|
|
typedef message_filters::sync_policies::ApproximateTime<
|
|
|
|
|
sensor_msgs::Image,
|
|
|
|
|
nav_msgs::Odometry,
|
|
|
|
|
sensor_msgs::Image,
|
|
|
|
|
sensor_msgs::CameraInfo,
|
|
|
|
|
sensor_msgs::LaserScan> MyDepthScanSyncPolicy;
|
|
|
|
|
message_filters::Synchronizer<MyDepthScanSyncPolicy> * depthScanSync_;
|
|
|
|
|
|
|
|
|
|
typedef message_filters::sync_policies::ApproximateTime<
|
|
|
|
|
sensor_msgs::Image,
|
|
|
|
|
nav_msgs::Odometry,
|
|
|
|
|
sensor_msgs::Image,
|
|
|
|
|
sensor_msgs::CameraInfo> MyDepthSyncPolicy;
|
|
|
|
|
message_filters::Synchronizer<MyDepthSyncPolicy> * depthSync_;
|
|
|
|
|
|
2014-10-16 00:17:11 +00:00
|
|
|
typedef message_filters::sync_policies::ApproximateTime<
|
|
|
|
|
sensor_msgs::Image,
|
|
|
|
|
sensor_msgs::Image,
|
|
|
|
|
sensor_msgs::CameraInfo,
|
|
|
|
|
sensor_msgs::CameraInfo,
|
|
|
|
|
sensor_msgs::LaserScan,
|
|
|
|
|
nav_msgs::Odometry> MyStereoScanSyncPolicy;
|
|
|
|
|
message_filters::Synchronizer<MyStereoScanSyncPolicy> * stereoScanSync_;
|
|
|
|
|
|
|
|
|
|
typedef message_filters::sync_policies::ApproximateTime<
|
|
|
|
|
sensor_msgs::Image,
|
|
|
|
|
sensor_msgs::Image,
|
|
|
|
|
sensor_msgs::CameraInfo,
|
|
|
|
|
sensor_msgs::CameraInfo,
|
2014-11-14 19:16:16 +00:00
|
|
|
nav_msgs::Odometry> MyStereoApproxSyncPolicy;
|
|
|
|
|
message_filters::Synchronizer<MyStereoApproxSyncPolicy> * stereoApproxSync_;
|
|
|
|
|
|
|
|
|
|
typedef message_filters::sync_policies::ExactTime<
|
|
|
|
|
sensor_msgs::Image,
|
|
|
|
|
sensor_msgs::Image,
|
|
|
|
|
sensor_msgs::CameraInfo,
|
|
|
|
|
sensor_msgs::CameraInfo,
|
|
|
|
|
nav_msgs::Odometry> MyStereoExactSyncPolicy;
|
|
|
|
|
message_filters::Synchronizer<MyStereoExactSyncPolicy> * stereoExactSync_;
|
2014-10-16 00:17:11 +00:00
|
|
|
|
2013-12-11 00:12:44 +00:00
|
|
|
tf::TransformBroadcaster tfBroadcaster_;
|
|
|
|
|
tf::TransformListener tfListener_;
|
|
|
|
|
|
|
|
|
|
ros::ServiceServer updateSrv_;
|
|
|
|
|
ros::ServiceServer resetSrv_;
|
|
|
|
|
ros::ServiceServer pauseSrv_;
|
|
|
|
|
ros::ServiceServer resumeSrv_;
|
|
|
|
|
ros::ServiceServer triggerNewMapSrv_;
|
2014-07-09 21:12:24 +00:00
|
|
|
ros::ServiceServer setModeLocalizationSrv_;
|
|
|
|
|
ros::ServiceServer setModeMappingSrv_;
|
2014-07-06 19:58:15 +00:00
|
|
|
ros::ServiceServer getMapDataSrv_;
|
2015-02-11 17:09:29 -05:00
|
|
|
ros::ServiceServer getProjMapSrv_;
|
|
|
|
|
ros::ServiceServer getGridMapSrv_;
|
2014-08-13 19:25:44 +00:00
|
|
|
ros::ServiceServer publishMapDataSrv_;
|
2015-02-06 13:56:20 -05:00
|
|
|
ros::ServiceServer setGoalSrv_;
|
2013-12-11 00:12:44 +00:00
|
|
|
|
2015-02-06 15:27:02 -05:00
|
|
|
MoveBaseClient mbClient_;
|
|
|
|
|
|
2013-12-11 00:12:44 +00:00
|
|
|
boost::thread* transformThread_;
|
|
|
|
|
|
|
|
|
|
float rate_;
|
|
|
|
|
ros::Time time_;
|
2011-06-20 16:49:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif /* COREWRAPPER_H_ */
|