/*** * @brief: cleaning robot path planning * @author: Wang * @date: 20170702 ***/ #ifndef CLEANINGPATHPLANNING_H #define CLEANINGPATHPLANNING_H #include #include #include #include #include #include #include "tf/tf.h" #include "tf/transform_listener.h" #include #include #include #include using namespace cv; using namespace std; constexpr double PI =3.14159; struct cellIndex { int row; int col; double theta; //{0, 45,90,135,180,225,270,315} 角度信息 hjr 注 }; /************************************************* * * 读取栅格地图并根据占据信息获取其对应的空闲(可行走)空间, * 按照遍历算法规划行走路线。 * * **********************************************/ class CleaningPathPlanning { public: //CleaningPathPlanning() = delete; CleaningPathPlanning(costmap_2d::Costmap2DROS *costmap2d_ros); vector GetPathInROS(); vector GetBorderTrackingPathInROS(); void SetCoveredGrid(double wx,double wy); int GetSizeOfCell(){return this->SIZE_OF_CELL;} //for visualization void PublishCoveragePath(); void PublishGrid(); private: //helper functions. bool initializeMats(); bool initializeCoveredGrid(); void getCellMatAndFreeSpace(Mat srcImg, Mat &cellMat,vector &freeSpaceVec); void initializeNeuralMat(Mat cellMat, Mat neuralizedMat); void writeResult(Mat resultmat,vector pathVec); void writeResult(cv::Mat resultmat,std::vector pathVec); void mainPlanningLoop(); double distance(Point2i pta,Point2i ptb); bool findElement(vector pointsVec,cv::Point2i pt, int&index); void publishPlan(const std::vector& path); bool cellContainsPoint(cv::Point2i pt,cellIndex cell); void GetBorderTrackingPathInCV(vector&resultVec); vector GetPathInCV(); bool initialized_; Mat srcMap_; Mat cellMat_; Mat neuralizedMat_; vector freeSpaceVec_; vector pathVec_; vector pathVecInROS_; double resolution_; ros::Publisher plan_pub_; ros::Publisher grid_pub_; nav_msgs::OccupancyGrid covered_path_grid_; //tf::TransformListener &tf_; tf::Stamped initPose_; costmap_2d::Costmap2D* costmap2d_; costmap_2d::Costmap2DROS* costmap2d_ros_; int SIZE_OF_CELL; //must be odd number. int GRID_COVERED_VALUE; }; #endif // CLEANINGPATHPLANNING_H