Go to the documentation of this file.00001
00024 #ifndef CCNY_RGBD_KEYFRAME_MAPPER_H
00025 #define CCNY_RGBD_KEYFRAME_MAPPER_H
00026
00027 #include <iostream>
00028 #include <fstream>
00029 #include <ros/ros.h>
00030 #include <ros/publisher.h>
00031 #include <pcl/point_cloud.h>
00032 #include <pcl_ros/point_cloud.h>
00033 #include <pcl_ros/transforms.h>
00034 #include <pcl/filters/passthrough.h>
00035 #include <tf/transform_listener.h>
00036 #include <visualization_msgs/Marker.h>
00037 #include <boost/regex.hpp>
00038 #include <boost/filesystem.hpp>
00039 #include <octomap/octomap.h>
00040 #include <octomap/OcTree.h>
00041 #include <octomap/ColorOcTree.h>
00042 #include <rgbdtools/rgbdtools.h>
00043
00044 #include "ccny_rgbd/types.h"
00045 #include "ccny_rgbd/util.h"
00046 #include "ccny_rgbd/GenerateGraph.h"
00047 #include "ccny_rgbd/SolveGraph.h"
00048 #include "ccny_rgbd/AddManualKeyframe.h"
00049 #include "ccny_rgbd/PublishKeyframe.h"
00050 #include "ccny_rgbd/PublishKeyframes.h"
00051 #include "ccny_rgbd/Save.h"
00052 #include "ccny_rgbd/Load.h"
00053
00054 namespace ccny_rgbd {
00055
00069 class Navigator
00070 {
00071 public:
00072
00077 Navigator(const ros::NodeHandle& nh,
00078 const ros::NodeHandle& nh_private);
00079
00082 virtual ~Navigator();
00083
00086 void initParams();
00087
00102 bool publishKeyframesSrvCallback(
00103 PublishKeyframes::Request& request,
00104 PublishKeyframes::Response& response);
00105
00110 bool publishKeyframeSrvCallback(
00111 PublishKeyframe::Request& request,
00112 PublishKeyframe::Response& response);
00113
00119 bool saveKeyframesSrvCallback(
00120 Save::Request& request,
00121 Save::Response& response);
00122
00131 bool savePcdMapSrvCallback(
00132 Save::Request& request,
00133 Save::Response& response);
00134
00143 bool saveOctomapSrvCallback(
00144 Save::Request& request,
00145 Save::Response& response);
00146
00152 bool loadKeyframesSrvCallback(
00153 Load::Request& request,
00154 Load::Response& response);
00155
00158 bool addManualKeyframeSrvCallback(
00159 AddManualKeyframe::Request& request,
00160 AddManualKeyframe::Response& response);
00161
00165 bool generateGraphSrvCallback(
00166 GenerateGraph::Request& request,
00167 GenerateGraph::Response& response);
00168
00174 bool solveGraphSrvCallback(
00175 SolveGraph::Request& request,
00176 SolveGraph::Response& response);
00177
00178 protected:
00179 std::vector<std::vector<double> > aruco_pos;
00180 std::vector<int> aruco_kfs;
00181 ros::NodeHandle nh_;
00182 ros::NodeHandle nh_private_;
00183
00184 std::string fixed_frame_;
00185
00186 int queue_size_;
00187
00188 double max_range_;
00189 double max_stdev_;
00190
00191 rgbdtools::KeyframeVector keyframes_;
00192
00199 virtual void RGBDCallback(const ImageMsg::ConstPtr& rgb_msg,
00200 const ImageMsg::ConstPtr& depth_msg,
00201 const CameraInfoMsg::ConstPtr& info_msg);
00202
00203 private:
00204
00205 ros::Publisher keyframes_pub_;
00206 ros::Publisher poses_pub_;
00207 ros::Publisher kf_assoc_pub_;
00208 ros::Publisher path_pub_;
00209 ros::Publisher aruco_pub_;
00210
00212 ros::ServiceServer generate_graph_service_;
00213
00215 ros::ServiceServer solve_graph_service_;
00216
00218 ros::ServiceServer pub_keyframe_service_;
00219
00221 ros::ServiceServer pub_keyframes_service_;
00222
00224 ros::ServiceServer save_kf_service_;
00225
00227 ros::ServiceServer save_pcd_map_service_;
00228
00230 ros::ServiceServer save_octomap_service_;
00231
00233 ros::ServiceServer load_kf_service_;
00234
00236 ros::ServiceServer add_manual_keyframe_service_;
00237
00238 tf::TransformListener tf_listener_;
00239
00241 boost::shared_ptr<ImageTransport> rgb_it_;
00242
00244 boost::shared_ptr<ImageTransport> depth_it_;
00245
00247 boost::shared_ptr<RGBDSynchronizer3> sync_;
00248
00250 ImageSubFilter sub_rgb_;
00251
00253 ImageSubFilter sub_depth_;
00254
00256 CameraInfoSubFilter sub_info_;
00257
00258
00259 double pcd_map_res_;
00260 double octomap_res_;
00261 double kf_dist_eps_;
00262 double kf_angle_eps_;
00263 bool octomap_with_color_;
00264 double max_map_z_;
00265 double min_map_z_;
00266
00267
00268 bool manual_add_;
00269
00270 int rgbd_frame_index_;
00271
00272 rgbdtools::KeyframeGraphDetector graph_detector_;
00273 rgbdtools::KeyframeGraphSolverG2O graph_solver_;
00274 rgbdtools::KeyframeGraphSolverISAM solver_;
00275 rgbdtools::KeyframeAssociationVector associations_;
00276
00277 PathMsg path_msg_;
00278 PathMsg aruco_path;
00286 bool processFrame(const rgbdtools::RGBDFrame& frame, const AffineTransform& pose);
00287
00293 void addKeyframe(const rgbdtools::RGBDFrame& frame, const AffineTransform& pose);
00294
00298 void publishKeyframeData(int i);
00299
00303 void publishKeyframePose(int i);
00304
00307 void publishKeyframeAssociations();
00308
00311 void publishKeyframePoses();
00312 void publishArucoPos();
00313
00316 void publishPath();
00317
00323 bool savePcdMap(const std::string& path);
00324
00328 void buildPcdMap(PointCloudT& map_cloud);
00329 void buildFullCloud(PointCloudT& map_cloud);
00330
00336 bool saveOctomap(const std::string& path);
00337
00338
00342 void buildColorOctomap(octomap::ColorOcTree& tree);
00343
00348 static inline octomap::pose6d poseTfToOctomap(
00349 const tf::Pose& poseTf)
00350 {
00351 return octomap::pose6d(
00352 pointTfToOctomap(poseTf.getOrigin()),
00353 quaternionTfToOctomap(poseTf.getRotation()));
00354 }
00355
00360 static inline octomap::point3d pointTfToOctomap(
00361 const tf::Point& ptTf)
00362 {
00363 return octomap::point3d(ptTf.x(), ptTf.y(), ptTf.z());
00364 }
00365
00370 static inline octomath::Quaternion quaternionTfToOctomap(
00371 const tf::Quaternion& qTf)
00372 {
00373 return octomath::Quaternion(qTf.w(), qTf.x(), qTf.y(), qTf.z());
00374 }
00375
00376 bool savePath(const std::string& filepath);
00377 bool savePathTUMFormat(const std::string& filepath);
00378 void filter_aruco();
00379 bool loadPath(const std::string& filepath);
00380
00381 void updatePathFromKeyframePoses();
00382 };
00383
00384 }
00385
00386 #endif // CCNY_RGBD_KEYFRAME_MAPPER_H