/* 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. */ #ifndef COREWRAPPER_H_ #define COREWRAPPER_H_ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "rtabmap_ros/GetMap.h" #include "rtabmap_ros/PublishMap.h" #include "rtabmap_ros/SetGoal.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include typedef actionlib::SimpleActionClient MoveBaseClient; class CoreWrapper { public: CoreWrapper(bool deleteDbOnStart); virtual ~CoreWrapper(); private: void setupCallbacks(bool subscribeDepth, bool subscribeLaserScan, bool subscribeStereo, int queueSize, bool stereoApproxSync); void defaultCallback(const sensor_msgs::ImageConstPtr & imageMsg); // no odom bool commonMetricCallbackBegin(const nav_msgs::OdometryConstPtr & odomMsg); 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); 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); void goalCommonCallback(const std::list > & poses); void goalCallback(const geometry_msgs::PoseStampedConstPtr & msg); void goalGlobalCallback(const geometry_msgs::PoseStampedConstPtr & msg); void updateGoal(const ros::Time & stamp); void process( int id, const cv::Mat & image, const rtabmap::Transform & odom = rtabmap::Transform(), const std::string & odomFrameId = "", float odomVariance = 1.0f, const cv::Mat & depthOrRightImage = cv::Mat(), float fx = 0.0f, float fyOrBaseline = 0.0f, float cx = 0.0f, float cy = 0.0f, const rtabmap::Transform & localTransform = rtabmap::Transform(), const cv::Mat & scan = cv::Mat()); 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&); bool setModeLocalizationCallback(std_srvs::Empty::Request&, std_srvs::Empty::Response&); bool setModeMappingCallback(std_srvs::Empty::Request&, std_srvs::Empty::Response&); 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); bool publishMapCallback(rtabmap_ros::PublishMap::Request&, rtabmap_ros::PublishMap::Response&); bool setGoalCallback(rtabmap_ros::SetGoal::Request& req, rtabmap_ros::SetGoal::Response& res); rtabmap::ParametersMap loadParameters(const std::string & configFile); void saveParameters(const std::string & configFile); void publishLoop(double tfDelay); void publishStats(const ros::Time & stamp); std::map updateMapCaches(const std::map & poses, bool updateCloud, bool updateProj, bool updateGrid); void publishMaps(const std::map & poses, const ros::Time & stamp); void publishCurrentGoal(const ros::Time & stamp); void goalDoneCb(const actionlib::SimpleClientGoalState& state, const move_base_msgs::MoveBaseResultConstPtr& result); void goalActiveCb(); void goalFeedbackCb(const move_base_msgs::MoveBaseFeedbackConstPtr& feedback); void publishLocalPath(const ros::Time & stamp); private: rtabmap::Rtabmap rtabmap_; bool paused_; rtabmap::Transform lastPose_; float _variance; rtabmap::Transform currentMetricGoal_; std::string frameId_; std::string mapFrameId_; std::string odomFrameId_; std::string configPath_; std::string databasePath_; bool waitForTransform_; bool useActionForGoal_; // mapping stuff int cloudDecimation_; double cloudMaxDepth_; double cloudVoxelSize_; double projMaxGroundAngle_; int projMinClusterSize_; double projMaxHeight_; double gridCellSize_; double gridSize_; double mapFilterRadius_; double mapFilterAngle_; tf::Transform mapToOdom_; boost::mutex mapToOdomMutex_; std::map::Ptr > clouds_; std::map > projMaps_; // std::map > gridMaps_; // ros::Publisher infoPub_; ros::Publisher mapDataPub_; ros::Publisher mapGraphPub_; ros::Publisher cloudMapPub_; ros::Publisher projMapPub_; ros::Publisher gridMapPub_; //Planning stuff ros::Subscriber goalSub_; ros::Subscriber goalGlobalSub_; ros::Publisher nextMetricGoalPub_; ros::Publisher goalReachedPub_; ros::Publisher globalPathPub_; ros::Publisher localPathPub_; // for loop closure detection only image_transport::Subscriber defaultSub_; //for depth callback image_transport::SubscriberFilter imageSub_; image_transport::SubscriberFilter imageDepthSub_; message_filters::Subscriber cameraInfoSub_; //stereo callback image_transport::SubscriberFilter imageRectLeft_; image_transport::SubscriberFilter imageRectRight_; message_filters::Subscriber cameraInfoLeft_; message_filters::Subscriber cameraInfoRight_; message_filters::Subscriber odomSub_; message_filters::Subscriber 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 * depthScanSync_; typedef message_filters::sync_policies::ApproximateTime< sensor_msgs::Image, nav_msgs::Odometry, sensor_msgs::Image, sensor_msgs::CameraInfo> MyDepthSyncPolicy; message_filters::Synchronizer * depthSync_; 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 * stereoScanSync_; typedef message_filters::sync_policies::ApproximateTime< sensor_msgs::Image, sensor_msgs::Image, sensor_msgs::CameraInfo, sensor_msgs::CameraInfo, nav_msgs::Odometry> MyStereoApproxSyncPolicy; message_filters::Synchronizer * 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 * stereoExactSync_; tf::TransformBroadcaster tfBroadcaster_; tf::TransformListener tfListener_; ros::ServiceServer updateSrv_; ros::ServiceServer resetSrv_; ros::ServiceServer pauseSrv_; ros::ServiceServer resumeSrv_; ros::ServiceServer triggerNewMapSrv_; ros::ServiceServer setModeLocalizationSrv_; ros::ServiceServer setModeMappingSrv_; ros::ServiceServer getMapDataSrv_; ros::ServiceServer getProjMapSrv_; ros::ServiceServer getGridMapSrv_; ros::ServiceServer publishMapDataSrv_; ros::ServiceServer setGoalSrv_; MoveBaseClient mbClient_; boost::thread* transformThread_; float rate_; ros::Time time_; }; #endif /* COREWRAPPER_H_ */