main.cpp
Go to the documentation of this file.
00001 #include <ros/ros.h>
00002 #include <iostream>
00003 #include <ros/console.h>
00004 #include <geometry_msgs/PolygonStamped.h>
00005 #include <geometry_msgs/PoseArray.h>
00006 #include <geometry_msgs/Pose.h>
00007 #include <tf/transform_broadcaster.h>
00008 #include <tf/LinearMath/Quaternion.h>
00009 #include <geometry_msgs/PoseStamped.h>
00010 #include <geometry_msgs/PoseArray.h>
00011 #include "visualization_msgs/ImageMarker.h"
00012 #include "nav_msgs/OccupancyGrid.h"
00013 #include "Hexagon_map/point.h"
00014 #include "Hexagon_map/hexagon_map.h"
00015 #include <fstream>
00016 #include <iomanip>
00017 #include <vector>
00018 #include <deque>
00019 #include <set>
00020 #include <queue>
00021 #include <sensor_msgs/PointCloud.h>
00022 #include <sensor_msgs/PointCloud2.h>
00023 #include <pcl/point_cloud.h>
00024 #include <pcl_ros/point_cloud.h>
00025 #include <pcl_conversions/pcl_conversions.h>
00026 #include <sensor_msgs/LaserScan.h>
00027 
00028 // nav_msgs::OccupancyGrid gridmap;
00029 // int count = 250;
00030 // void drawplogon(const float &C_x,const float &C_y,const float &L)
00031 // {
00032 //     int dx = floor((C_x - gridmap.info.origin.position.x)/gridmap.info.resolution);
00033 //     int dy = floor((C_y - gridmap.info.origin.position.y)/gridmap.info.resolution);
00034     
00035 //     float h = L * cos(30.0/180.0*3.1415926);
00036         
00037 //      int h_index = ceil(h/gridmap.info.resolution);
00038 
00039 
00040 //     for(int i=-h_index;i<=h_index;i++)
00041 //     {
00042 //         float this_h = h - i * gridmap.info.resolution;
00043                 
00044 //         if(i<0)
00045 //         {
00046 //             this_h = h + i * gridmap.info.resolution;
00047 //         }
00048 //         else
00049 //         {
00050 //             this_h = h - i * gridmap.info.resolution;
00051 
00052 //         }
00053 
00054 //         float addlen = this_h * tan(30.0/180.0*3.1415926);
00055                 
00056 //         int addlen_index = ceil(addlen/gridmap.info.resolution);
00057                 
00058 //         int L_index = ceil(L/2/gridmap.info.resolution);
00059                 
00060 //              int half_index = addlen_index + L_index;
00061 
00062 //         for(int j=-half_index;j<=half_index;j++)
00063 //         {
00064 //             int deta_x = dx + j;
00065 //             int deta_y = dy + i;
00066 //             int index = deta_x + deta_y * gridmap.info.width;
00067 //             if(gridmap.data[index]==0)
00068 //             {
00069 //                   gridmap.data[index] = count;
00070 //             }
00071 //         }
00072 //     }
00073 // }
00074 
00075 // std::vector<CPoint2d> Pointset;
00076 
00077 // bool isInpointset(CPoint2d &Checkpoint)
00078 // {
00079 //     for(int i = 0;i<Pointset.size();i++)
00080 //     {
00081 //         CPoint2d tempoint = Pointset[i];
00082 
00083 //         float dis = (tempoint.x - Checkpoint.x) * (tempoint.x - Checkpoint.x) 
00084 //                     + (tempoint.y - Checkpoint.y) * (tempoint.y - Checkpoint.y); 
00085         
00086 //         if(dis<0.0001)
00087 //         {
00088 //             return true;
00089 //         }
00090 //     }
00091 //     return false;
00092 // }
00093 
00094 float R = 7.0;
00095 float resolution = 0.1;
00096 int count = 0;
00097 
00098 hexagon_map* hexagon_map_;
00099 ros::Publisher *g_path1Publisher;
00100 ros::Subscriber Getcloudpointssuber; 
00101 
00102 
00103 void PointcloudCallback(sensor_msgs::PointCloud2 msg)
00104 {
00105         count++;
00106         if(count==2)
00107         {
00108                 hexagon_map_->updateMap(msg);
00109                 std::cout<<"------- "<<std::endl;
00110                 g_path1Publisher->publish(hexagon_map_->gridmap);
00111                 count = 0;
00112         }
00113         
00114 }
00115 
00116 int main(int argc, char** argv)
00117 {
00118     ros::init(argc, argv, "Hexagon_map");
00119     ros::NodeHandle node;
00120         
00121     g_path1Publisher = new ros::Publisher;
00122     *g_path1Publisher = node.advertise<nav_msgs::OccupancyGrid>("Hexagon_map", 20);
00123 
00124     Getcloudpointssuber = node.subscribe("/rslidar_points", 100, &PointcloudCallback);
00125 
00126     hexagon_map_ = new hexagon_map(R,resolution);
00127 
00128     // std::cout<<"input num "<<std::endl;
00129     // float X,Y;
00130     // std::cin>>X;
00131     // std::cin>>Y;
00132     // CPoint2d tempoint;
00133     // tempoint.x = X;
00134     // tempoint.y = Y;
00135 
00136     // CPoint2d Centerp;
00137     // Centerp = hexagon_map_.JudgeHexCenpoint(tempoint);
00138     // std::cout<<"Centerp is "<<Centerp.x<<" "<<Centerp.y<<std::endl;
00139     // int count = 250;
00140     // hexagon_map_.drawplogon(Centerp.x,Centerp.y,hexagon_map_.Resulution_L,count);
00141     
00142  //    gridmap.header.frame_id = "/camera_init";
00143  //    gridmap.header.stamp = ros::Time::now();
00144  //    gridmap.info.resolution = 0.01;
00145  //    gridmap.info.width = 3600;
00146  //    gridmap.info.height = 3600;
00147  //    gridmap.info.origin.position.x = -18.0;
00148  //    gridmap.info.origin.position.y = -18.0;
00149  //    gridmap.info.origin.position.z = 0.0;
00150 
00151  //    gridmap.data.assign(gridmap.info.width*gridmap.info.height,0);
00152 
00153  //    std::vector<int> flagmap;
00154  //    flagmap.assign(gridmap.info.width*gridmap.info.height,0);
00155 
00156  //    float L = 0.2;
00157         // std::cout<<L<<std::endl;
00158         
00159         // CPoint2d Centerpoint;
00160         // Centerpoint.x = 0.0;
00161         // Centerpoint.y = 0.0;
00162         
00163 
00164         // std::queue<CPoint2d> Pointqueue;
00165 
00166  //    int geshu = 0;
00167 
00168  //    std::cout<<"--------Centerpoint--------- "<<Centerpoint.x<<" "<<Centerpoint.y<<std::endl;
00169  //    int d_x = (Centerpoint.x - gridmap.info.origin.position.x)/gridmap.info.resolution;
00170  //    int d_y = (Centerpoint.y - gridmap.info.origin.position.y)/gridmap.info.resolution;
00171  //    int inde_x = d_x + d_y * gridmap.info.width;
00172  //    std::cout<<"inde_x "<<inde_x<<std::endl;
00173  //    flagmap[inde_x] = 1;
00174  //    geshu++;
00175 
00176  //    Pointset.push_back(Centerpoint);
00177     
00178  //    Pointqueue.push(Centerpoint);
00179 
00180         // while(!Pointqueue.empty())
00181         // {
00182         //      int size = Pointset.size();
00183  //        int size1 = Pointqueue.size();
00184         //      std::cout<<"------------------------ "<<size<<std::endl;
00185  //        std::cout<<"Pointqueue size is "<<size1<<std::endl;
00186  //        std::cout<<"geshu is ........"<<std::endl;        
00187  //        std::cout<<geshu<<std::endl;
00188  //        if(geshu==6163)
00189  //        {
00190  //            break;
00191 
00192  //        }
00193         //      /*if(size==91)
00194         //      {
00195         //              break;
00196         //      }*/
00197 
00198         //      int angle[]={60,120,180,240,300};
00199                 
00200         //      CPoint2d Genepoint;
00201         //      Genepoint = Pointqueue.front();
00202         //      Pointqueue.pop();
00203 
00204         //      std::cout<<"loop begin_________________________Genepoint "<<Genepoint.x<<" "<<Genepoint.y<<std::endl;
00205 
00206         //      CPoint2d tempoint;
00207                 
00208         //      tempoint.x = Genepoint.x + 4.5 * L;
00209         //      tempoint.y = Genepoint.y + -L * tan(60*3.1415926/180)/2;
00210         //      tempoint.pointangle = atan2(-L * tan(60*3.1415926/180)/2, 4.5 * L);
00211         //      float R = sqrt(4.5 * L * 4.5 * L + -L * tan(60*3.1415926/180)/2 * -L * tan(60*3.1415926/180)/2);
00212 
00213         //      int dx_ = (tempoint.x - gridmap.info.origin.position.x)/gridmap.info.resolution;
00214  //        int dy_ = (tempoint.y - gridmap.info.origin.position.y)/gridmap.info.resolution;
00215  //        int index_ = dx_ + dy_ * gridmap.info.width;
00216         //      std::cout<<"tempoint "<<tempoint.x<<" "<<tempoint.y<<std::endl;
00217  //        std::cout<<" index_ "<<index_<<std::endl;
00218  //        geshu++;
00219 
00220  //        if(flagmap[index_]!=0 || isInpointset(tempoint))
00221  //        {   
00222  //             std::cout<<" chongfu_____ "<<std::endl;
00223  //        }
00224         //     else
00225         //     {
00226  //            Pointset.push_back(tempoint);
00227         //              Pointqueue.push(tempoint);
00228  //            flagmap[index_] = 1;
00229         //     }
00230 
00231 
00232 
00233         //      for(int i=0;i<5;i++)
00234         //      {
00235         //              CPoint2d Othertempoint;
00236         //              Othertempoint.x = Genepoint.x + R * cos((tempoint.pointangle * 180 /3.1415926 + angle[i])*3.1415926/180);
00237         //              Othertempoint.y = Genepoint.y + R * sin((tempoint.pointangle * 180 /3.1415926 + angle[i])*3.1415926/180);
00238                     
00239                     
00240                     
00241         //          int d_x2 = (Othertempoint.x - gridmap.info.origin.position.x)/gridmap.info.resolution;
00242         //          int d_y2 = (Othertempoint.y - gridmap.info.origin.position.y)/gridmap.info.resolution;
00243         //          int inde_x2 = d_x2 + d_y2 * gridmap.info.width;
00244         //          //flagmap[inde_x2] = 1;
00245         //              std::cout<<"-------first Othertempoint "<<Othertempoint.x<<" "<<Othertempoint.y<<std::endl;
00246         //          std::cout<<"inde_x2 "<<inde_x2<<std::endl;
00247  //            geshu++;
00248 
00249         //              if(flagmap[inde_x2]!=0 || isInpointset(Othertempoint))
00250  //            {
00251  //                std::cout<<"chongfu"<<inde_x2<<std::endl;
00252  //                continue;
00253  //            }
00254  //            else
00255  //            {
00256  //                Pointset.push_back(Othertempoint);
00257         //                      Pointqueue.push(Othertempoint);
00258  //             flagmap[inde_x2] = 1;
00259  //            }
00260         //      }
00261         // }
00262     
00263 
00264 /*      
00265         int angle[]={60,120,180,240,300};
00266         
00267         CPoint2d tempoint;
00268         tempoint.x = 4.5 * L;
00269         tempoint.y = -L * tan(60*3.1415926/180)/2;
00270         tempoint.pointangle = atan2(tempoint.y,tempoint.x); 
00271         float R = sqrt(tempoint.x * tempoint.x + tempoint.y * tempoint.y);
00272 
00273 
00274     std::cout<<"----first tempoint "<<tempoint.x<<" "<<tempoint.y<<std::endl;
00275     int d_x1 = (tempoint.x - gridmap.info.origin.position.x)/gridmap.info.resolution;
00276     int d_y1 = (tempoint.y - gridmap.info.origin.position.y)/gridmap.info.resolution;
00277     int inde_x1 = d_x1 + d_y1 * gridmap.info.width;
00278     flagmap[inde_x1] = 1;
00279     std::cout<<"inde_x1 "<<inde_x1<<std::endl;
00280 
00281         Pointset.push_back(tempoint);
00282         
00283         for(int i=0;i<5;i++)
00284         {
00285                 CPoint2d Othertempoint;
00286                 Othertempoint.x = Centerpoint.x + R * cos((tempoint.pointangle * 180 /3.1415926 + angle[i])*3.1415926/180);
00287                 Othertempoint.y = Centerpoint.y + R * sin((tempoint.pointangle * 180 /3.1415926 + angle[i])*3.1415926/180);
00288         
00289         
00290         std::cout<<"-------first Othertempoint "<<Othertempoint.x<<" "<<Othertempoint.y<<std::endl;
00291         int d_x2 = (Othertempoint.x - gridmap.info.origin.position.x)/gridmap.info.resolution;
00292         int d_y2 = (Othertempoint.y - gridmap.info.origin.position.y)/gridmap.info.resolution;
00293         int inde_x2 = d_x2 + d_y2 * gridmap.info.width;
00294         flagmap[inde_x2] = 1;
00295         std::cout<<"inde_x2 "<<inde_x2<<std::endl;
00296 
00297                 Pointset.push_back(Othertempoint);
00298                 
00299         //std::cout<<" Othertempoint "<<Othertempoint.x<<" "<<Othertempoint.y<<std::endl;
00300         }
00301 
00302 
00303     
00304     std::cout<<Pointset.size()<<std::endl;
00305     std::cout<<"----------------------------"<<std::endl;
00306 
00307     std::vector<CPoint2d> PointsetCopy;
00308     PointsetCopy = Pointset;
00309 
00310     for(int i=1;i<Pointset.size();i++)
00311     {
00312         CPoint2d Cpoint;
00313         Cpoint = Pointset[i];
00314         std::cout<<"--------- shengcheng Cpoint------------------------ "<<Cpoint.x<<" "<<Cpoint.y<<std::endl;
00315 
00316         CPoint2d tem;
00317         tem.x = Cpoint.x + 4.5 * L;
00318             tem.y = Cpoint.y + -L * tan(60*3.1415926/180)/2;
00319             tem.pointangle = atan2(-L * tan(60*3.1415926/180)/2, 4.5 * L);
00320         
00321 
00322         std::cout<<"tem "<<tem.x<<" "<<tem.y<<std::endl;
00323         int dx_ = (tem.x - gridmap.info.origin.position.x)/gridmap.info.resolution;
00324         int dy_ = (tem.y - gridmap.info.origin.position.y)/gridmap.info.resolution;
00325         int index_ = dx_ + dy_ * gridmap.info.width;
00326         std::cout<<" index_ "<<index_<<std::endl;
00327 
00328         if(flagmap[index_]!=0)
00329         {   
00330              std::cout<<" chongfu_____ "<<std::endl;
00331         }
00332             else
00333             {
00334             PointsetCopy.push_back(tem);
00335             flagmap[index_] = 1;
00336             }
00337    
00338 
00339         //PointsetCopy.push_back(tem);
00340         //flagmap[inde_x2] = 1;
00341       
00342 
00343         for(int j=0;j<5;j++)
00344             {
00345 
00346                     CPoint2d Othertempoint1;
00347                     Othertempoint1.x = Cpoint.x + R * cos((tempoint.pointangle * 180 /3.1415926 + angle[j])*3.1415926/180);
00348                     Othertempoint1.y = Cpoint.y + R * sin((tempoint.pointangle * 180 /3.1415926 + angle[j])*3.1415926/180);
00349         
00350 
00351             std::cout<<"Othertempoint1 "<<Othertempoint1.x<<" "<<Othertempoint1.y<<std::endl;
00352             int d_x21 = (Othertempoint1.x - gridmap.info.origin.position.x)/gridmap.info.resolution;
00353             int d_y21 = (Othertempoint1.y - gridmap.info.origin.position.y)/gridmap.info.resolution;
00354             int inde_x21 = d_x21 + d_y21 * gridmap.info.width;
00355             std::cout<<"inde_x21 "<<inde_x21<<std::endl;
00356 
00357 
00358             
00359             if(flagmap[inde_x21]!=0)
00360             {
00361                 std::cout<<"chongfu"<<inde_x21<<std::endl;
00362                 continue;
00363             }
00364             else
00365             {
00366                  PointsetCopy.push_back(Othertempoint1);
00367                  flagmap[inde_x21] = 1;
00368             }
00369     
00370            // PointsetCopy.push_back(Othertempoint1);
00371             }
00372    }
00373 
00374     std::cout<<"-------- "<<PointsetCopy.size()<<std::endl;
00375 
00376     Pointset.clear();
00377     Pointset = PointsetCopy;
00378 */
00379     // std::cout<<"--------------- Pointset.size() "<<Pointset.size()<<std::endl;
00380     // for(int i=0;i<Pointset.size();i++)
00381     // {
00382     //     std::cout<<"Pointset "<<Pointset[i].x<<" "<<Pointset[i].y<<std::endl;
00383     //     drawplogon(Pointset[i].x,Pointset[i].y,L);
00384     // }
00385 
00386  //    int singleangle[]={30,90,150,210,270,330};
00387         // float r1 = L * tan(60*3.1415926/180);
00388         
00389         // for(int i = 0;i<Pointset.size();i++)
00390         // {
00391         //      count = count - 2;
00392         //      drawplogon(Pointset[i].x,Pointset[i].y,L);
00393                 
00394   
00395         //      for(int j=0;j<6;j++)
00396         //      {
00397         //                      CPoint2d temppoint;
00398         //                      temppoint.x = Pointset[i].x + r1 * cos(singleangle[j] * 3.1415926/180);
00399         //                      temppoint.y = Pointset[i].y + r1 * sin(singleangle[j] * 3.1415926/180);
00400         //                      count = count - 2;
00401         //                      drawplogon(temppoint.x,temppoint.y,L);
00402         //      }
00403         // }
00404 
00405 
00406 
00407    /* for(int i = 1;i<Pointset.size();i++)
00408     {
00409         CPoint2d Cpoint;
00410         Cpoint = Pointset[i];
00411 
00412         CPoint2d tempoint;
00413         tempoint.x = Cpoint.x + 4.5 * L;
00414             tempoint.y = Cpoint.y + -L * tan(60*3.1415926/180)/2;
00415             tempoint.pointangle = atan2(-L * tan(60*3.1415926/180)/2, 4.5 * L); 
00416 
00417         Pointset.push_back(tempoint);
00418 
00419         for(int j=0;j<5;j++)
00420             {
00421                     CPoint2d Othertempoint1;
00422                     Othertempoint1.x = Cpoint.x + R * cos((tempoint.pointangle * 180 /3.1415926 + angle[j])*3.1415926/180);
00423                     Othertempoint1.y = Cpoint.y + R * sin((tempoint.pointangle * 180 /3.1415926 + angle[j])*3.1415926/180);
00424                     Pointset.push_back(Othertempoint1);
00425                 
00426             std::cout<<" Othertempoint1 "<<Othertempoint1.x<<" "<<Othertempoint1.y<<std::endl;
00427             }
00428     }*/
00429 
00430 
00431         
00432         
00433         
00434         
00435         /*
00436         for(int i = -4;i<=4;i++)
00437                 //int i = 0;
00438                 for(int j=-5;j<=5;j++)
00439                 {
00440                         if(j%2==0)
00441                         {
00442                                 C_x = 0.0 + j * 3 * L /2;
00443                                 C_y = 0.0 + i * tan(60*3.1415926/180) * L;
00444                         }
00445                         else
00446                         {
00447                                 C_x = 0.0 + j * 3 * L /2;
00448                                 C_y = 0.0 + i * tan(60*3.1415926/180) * L + 
00449                                                         tan(60*3.1415926/180) * L / 2;
00450                         
00451                         }
00452                         //std::cout<<"C_x C_y "<<C_x<<" "<<C_y<<std::endl;
00453                         drawplogon(C_x, C_y,L);
00454                         count = count + 5;
00455                 }*/
00456         
00457     /*L = 0.05;
00458     C_x = 0.0;
00459     C_y = 0.0;
00460     drawplogon(C_x,C_y,L);
00461 
00462 
00463     L = 0.05;
00464     C_x = 0.0 * L;
00465     C_y = -1.7321 * L;
00466     drawplogon(C_x, C_y,L);
00467 
00468     //L = 0.1;
00469     C_x = -1.5 * L;
00470     C_y = -0.866 * L;
00471     drawplogon(C_x, C_y,L);
00472 
00473 
00474     //L = 0.1;
00475     C_x = -1.5 * L;
00476     C_y = 0.866 * L;
00477     drawplogon(C_x, C_y,L);
00478 
00479 
00480     //L = 0.1;
00481     C_x = 0.0 * L;
00482     C_y = 1.7321 * L;
00483     drawplogon(C_x, C_y,L);
00484 
00485     //L = 0.1;
00486     C_x = 1.5 * L;
00487     C_y = 0.866 * L;
00488     drawplogon(C_x, C_y,L);
00489 
00490     
00491     //L = 0.1;
00492     C_x = 1.5 * L;
00493     C_y = -0.866 * L;
00494     drawplogon(C_x, C_y,L);*/
00495 
00496         // ros::Rate r(30);
00497         // while(ros::ok())
00498         // {
00499                 
00500         //      g_path1Publisher->publish(hexagon_map_.gridmap);
00501         //       r.sleep();
00502 
00503         // }
00504    
00505      ros::spin();
00506 
00507      delete hexagon_map_;
00508 
00509 }


hexagon_map
Author(s):
autogenerated on Thu May 24 2018 02:44:30