#include #include #include //#include #include #include #include #include //#include #include #include #include "modulecomm.h" #include "lidar_driver_hesaipandarqt64.h" #include "lidar_hesaipandarqt64_rawdata.h" #include "ivexit.h" #include "ivfault.h" #include "ivlog.h" #ifdef VV7_1 int vv7; #endif #define Lidar_Pi 3.1415926535897932384626433832795 #define Lidar32 (unsigned long)3405883584//192.168.1.203 #define Lidar_roll_ang 90*Lidar_Pi/180.0 static std::thread * g_phesaipandar64Thread; static std::thread * g_phesaipandar64ProcThread; //float gV_theta[16] = {-15,1,-13,3,-11,5,-9,7,-7,9,-5,11,-3,13,-1,15}; //16 Angles //static float gV_theta[64] = {14.7,10.85,7.877,4.875,2.858,1.846,1.678,1.506,1.34,1.169,1.002,0.831,0.664,0.493,0.326,0.155,-0.013,-0.182,-0.351,-0.519,-0.69,-0.857,-1.027,-1.195,-1.366,-1.533,-1.704,-1.87,-2.042,-2.21,-2.38,-2.547,-2.718,-2.882,-3.055,-3.222,-3.392,-3.557,-3.73,-3.894,-4.066,-4.232,-4.403,-4.567,-4.74,-4.902,-5.074,-5.239,-5.411,-5.573,-5.747,-5.908,-6.08,-6.243,-7.245,-8.241,-9.242,-10.227,-11.214,-12.188,-13.156,-14.112,-19.071,-25.079}; //64 Angles static float gV_theta[64] = {-52.121,-49.785,-47.577,-45.477,-43.465,-41.528,-39.653,-37.831, -36.055,-34.32,-32.619,-30.95,-29.308,-27.69,-26.094,-24.517, -22.964,-21.42,-19.889,-18.372,-16.865,-15.368,-13.88,-12.399, -10.925,-9.457,-7.994,-6.535,-5.079,-3.626,-2.175,-0.725, 0.725,2.175,3.626,5.079,6.534,7.993,9.456,10.923, 12.397,13.877,15.365,16.861,18.368,19.885,21.415,22.959, 24.524,26.101,27.697,29.315,30.957,32.627,34.328,36.064, 37.84,39.662,41.537,43.475,45.487,47.587,49.795,52.133}; static float gH_theta[64] = {8.736,8.314,7.964,7.669,7.417,7.198,7.007,6.838, 6.688,6.554,6.434,6.326,6.228,6.14,6.059,5.987, -5.27,-5.216,-5.167,-5.123,-5.083,-5.047,-5.016,-4.988, -4.963,-4.942,-4.924,-4.91,-4.898,-4.889,-4.884,-4.881, 5.493,5.496,5.502,5.512,5.525,5.541,5.561,5.584, 5.611,5.642,5.676,5.716,5.759,5.808,5.862,5.921, -5.33,-5.396,-5.469,-5.55,-5.64,-5.74,-5.85,-5.974, -6.113,-6.269,-6.447,-6.651,-6.887,-7.163,-7.493,-7.892}; //static float gH_theta[64] = {-1.042,-1.042,-1.042,-1.042,-1.042,-1.042,1.042,3.125,5.208,-5.208,-3.125,-1.042,1.042,3.125,5.208,-5.208,-3.125,-1.042,1.042,3.125,5.208,-5.208,-3.125,-1.042,1.042,3.125,5.208,-5.208,-3.125,-1.042,1.042,3.125,5.208,-5.208,-3.125,-1.042,1.042,3.125,5.208,-5.208,-3.125,-1.042,1.042,3.125,5.208,-5.208,-3.125,-1.042,1.042,3.125,5.208,-5.208,-3.125,-1.042,-1.042,-1.042,-1.042,-1.042,-1.042,-1.042,-1.042,-1.042,-1.042,-1.042}; static float gV_theta_cos[64],gV_theta_sin[64]; //static void * g_hesaipandar64_raw; static void * g_lidar_pc; static bool g_bhesaipandar64_run = false; static bool g_bhesaipandar64_running = false; static bool g_bhesaipandar64_Proc_running = false; static int g_seq = 0; static unsigned short glidar_port=2368; extern char gstr_memname[256]; extern char gstr_rollang[256]; extern char gstr_inclinationang_yaxis[256]; //from y axis extern char gstr_inclinationang_xaxis[256]; //from x axis //char gstr_hostip[256]; extern char gstr_port[256]; extern char gstr_yaml[256]; extern char gstr_calibfile[256]; extern iv::Ivfault * gIvfault; extern iv::Ivlog * gIvlog; /** * @brief The hesaipandar64_Buf class * Use for Lidar UDP DATA Save */ class hesaipandar64_Buf { private: char * mstrdata; int mnSize; //Data SizeUse QMutex mMutex; int mIndex; public: hesaipandar64_Buf() { mstrdata = new char[BK32_DATA_BUFSIZE]; mIndex = 0; mnSize = 0; } ~hesaipandar64_Buf() { delete mstrdata; } void WriteData(const char * strdata,const int nSize) { mMutex.lock(); memcpy(mstrdata,strdata,nSize); mnSize = nSize; mIndex++; mMutex.unlock(); } int ReadData(char * strdata,const int nRead,int * pnIndex) { int nRtn = 0; if(mnSize <= 0)return 0; mMutex.lock(); nRtn = mnSize; if(nRtn >nRead) { nRtn = nRead; std::cout<<"lidar_hesaipandarQT64 hesaipandarQT64_Buf ReadData data nRead = "< static QTime gTime; /** * @brief processhesaipandar64_Data * @param ba UDP Buffer * 1.UDP ByteArray Length is npacsize. * 2.if Angle is More than 360. Tell Another thread process. */ static void processhesaipandar64_Data(QByteArray ba) { gnPac++; unsigned short * pAng; float fAng; char * pdata; pdata = ba.data(); // const int npacsize = 1194; const int npacsize = 1072; if(ba.length() >= npacsize) { // pAng = (unsigned short *)(pdata+8); pAng = (unsigned short *)(pdata+6+6); fAng = *pAng;fAng = fAng*0.01; if(fabs(fAng-gAngle_Old)>300) { gAngle_Total = gAngle_Total + fabs(fabs(fAng-gAngle_Old)-360); } else { gAngle_Total = gAngle_Total + fabs(fabs(fAng-gAngle_Old)); } gAngle_Old = fAng; if(gAngle_Total > 360) { g_hesaipandar64_Buf->WriteData(g_RawData_Buf,gnRawPos); lidar_hesaipandar64_raw * p = new lidar_hesaipandar64_raw(); p->mnLen = gnRawPos; memcpy(p->mstrdata,g_RawData_Buf,gnRawPos); // iv::modulecomm::ModuleSendMsg(g_hesaipandar64_raw,(char *)p,sizeof(lidar_hesaipandar64_raw)); delete p; memcpy(g_RawData_Buf,pdata,npacsize); gnRawPos = npacsize; // std::cout<<"index = "<bind(QHostAddress::Any, glidar_port); unsigned int ndatamisstime = 0; int nstate = 0; int nlaststate = 0; while(g_bhesaipandar64_run) { if(udpSocket->hasPendingDatagrams()) { ndatamisstime = 0; // std::cout<<"have data."<pendingDatagramSize()); QHostAddress sender; quint16 senderPort; udpSocket->readDatagram(datagram.data(), datagram.size(), &sender, &senderPort); // processTheDatagram(datagram); // std::cout<<"have data."<receiveDatagram(); processhesaipandar64_Data(datagram); datagram.clear(); } else { // std::cout<<"running."< 1000) { nstate = 1; } if(ndatamisstime > 60000) { nstate = 2; } if(ndatamisstime < 100) { nstate = 0; } if(nlaststate != nstate) { nlaststate = nstate; switch (nstate) { case 0: gIvfault->SetFaultState(0,0,"OK"); gIvlog->info("received udp data.device is ok."); break; case 1: gIvfault->SetFaultState(1,1,"No data"); gIvlog->warn("more than 1 second no data. warning."); break; case 2: gIvfault->SetFaultState(2,2,"No data,Please Check Device or setting."); gIvlog->error("more than 60 seconds no data. error. Please check device or setting."); break; default: break; } } } udpSocket->close(); delete udpSocket; g_bhesaipandar64_running = false; std::cout<<"hesaipandar64_Func Exit."<::Ptr point_cloud( new pcl::PointCloud()); point_cloud->header.frame_id = "velodyne"; point_cloud->height = 1; point_cloud->header.stamp = dt.currentMSecsSinceEpoch(); point_cloud->width = 0; point_cloud->header.seq =g_seq; g_seq++; unsigned char * pstr = (unsigned char *)strdata; // std::cout<<"enter obs."<points.push_back(point); ++point_cloud->width; } } } char * strOut = new char[4+sizeof(point_cloud->header.frame_id.size()) + 4+8+point_cloud->width * sizeof(pcl::PointXYZI)]; int * pHeadSize = (int *)strOut; *pHeadSize = 4 + point_cloud->header.frame_id.size()+4+8; memcpy(strOut+4,point_cloud->header.frame_id.c_str(),point_cloud->header.frame_id.size()); pcl::uint32_t * pu32 = (pcl::uint32_t *)(strOut+4+sizeof(point_cloud->header.frame_id.size())); *pu32 = point_cloud->header.seq; memcpy(strOut+4+sizeof(point_cloud->header.frame_id.size()) + 4,&point_cloud->header.stamp,8); pcl::PointXYZI * p; p = (pcl::PointXYZI *)(strOut +4+sizeof(point_cloud->header.frame_id.size()) + 4+8 ); memcpy(p,point_cloud->points.data(),point_cloud->width * sizeof(pcl::PointXYZI)); iv::modulecomm::ModuleSendMsg(g_lidar_pc,strOut,4+sizeof(point_cloud->header.frame_id.size()) + 4+8+point_cloud->width * sizeof(pcl::PointXYZI)); delete strOut; // std::cout<<"point cloud width = "<width<<" size = "<size()<ReadData(strdata,BK32_DATA_BUFSIZE,&nIndex))>0) { //process data. process_hesaipandar64obs(strdata,nRead); } else { // std::cout<<"running."<=3) { pxV[i-1] = QString(strlistvalue.at(1)).toDouble(); pxH[i-1] = QString(strlistvalue.at(2)).toDouble(); } else { bAllOK = false; } } std::cout<<"Elevation:"<join(); g_phesaipandar64ProcThread->join(); iv::modulecomm::Unregister(g_lidar_pc); delete g_phesaipandar64ProcThread; delete g_phesaipandar64Thread; delete g_hesaipandar64_Buf; delete g_RawData_Buf; }