ivdecision.cpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. #include "ivdecision.h"
  2. #include "gnss_coordinate_convert.h"
  3. namespace iv {
  4. ivdecision::ivdecision()
  5. {
  6. }
  7. void ivdecision::modulerun()
  8. {
  9. ModuleFun fungps = std::bind(&iv::ivdecision::UpdateGPS,this,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
  10. mpagpsmsg = iv::modulecomm::RegisterRecvPlus(mstrgpsmsgname.data(),fungps);
  11. ModuleFun funlidar = std::bind(&iv::ivdecision::UpdateLIDAR,this,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
  12. mpalidarmsg = iv::modulecomm::RegisterRecvPlus(mstrlidarmsgname.data(),funlidar);
  13. ModuleFun funradar = std::bind(&iv::ivdecision::UpdateRADAR,this,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
  14. mparadarmsg = iv::modulecomm::RegisterRecvPlus(mstrradarmsgname.data(),funradar);
  15. ModuleFun funmap = std::bind(&iv::ivdecision::UpdateMAP,this,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
  16. mpamapmsg = iv::modulecomm::RegisterRecvPlus(mstrmapmsgname.data(),funmap);
  17. ModuleFun funmobileye = std::bind(&iv::ivdecision::UpdateMobileye,this,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
  18. mpamobileyemsg = iv::modulecomm::RegisterRecvPlus(mstrmobileyemsgname.data(),funmobileye);
  19. ModuleFun funhmi = std::bind(&iv::ivdecision::UpdateHMI,this,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
  20. mpahmimsg = iv::modulecomm::RegisterRecvPlus(mstrhmimsgname.data(),funhmi);
  21. mpapadmsg = iv::modulecomm::RegisterRecvPlus(mstrpadmsgname.data(),funhmi);
  22. while(mbrun)
  23. {
  24. //RunDecision
  25. //ShareMsg
  26. }
  27. iv::modulecomm::Unregister(mpapadmsg);
  28. iv::modulecomm::Unregister(mpahmimsg);
  29. iv::modulecomm::Unregister(mpamobileyemsg);
  30. iv::modulecomm::Unregister(mpamapmsg);
  31. iv::modulecomm::Unregister(mparadarmsg);
  32. iv::modulecomm::Unregister(mpalidarmsg);
  33. iv::modulecomm::Unregister(mpagpsmsg);
  34. }
  35. void ivdecision::UpdateGPS(const char *strdata, const unsigned int nSize, const unsigned int index, const QDateTime *dt, const char *strmemname)
  36. {
  37. (void )&index;
  38. (void )&dt;
  39. (void )strmemname;
  40. if(nSize<1)return;
  41. iv::gps::gpsimu xgpsimu;
  42. if(!xgpsimu.ParseFromArray(strdata,nSize))
  43. {
  44. std::cout<<"ivdecision::UpdateGPSMsg error."<<std::endl;
  45. return;
  46. }
  47. iv::GPSData data(new iv::GPS_INS);
  48. data->ins_status = xgpsimu.ins_state();
  49. data->rtk_status = xgpsimu.rtk_state();
  50. data->accel_x = xgpsimu.acce_x();
  51. data->accel_y = xgpsimu.acce_y();
  52. data->accel_z = xgpsimu.acce_z();
  53. data->ang_rate_x = xgpsimu.gyro_x();
  54. data->ang_rate_y = xgpsimu.gyro_y();
  55. data->ang_rate_z = xgpsimu.gyro_z();
  56. data->gps_lat = xgpsimu.lat();
  57. data->gps_lng = xgpsimu.lon();
  58. data->gps_z = xgpsimu.height();
  59. data->ins_heading_angle = xgpsimu.heading();
  60. data->ins_pitch_angle = xgpsimu.pitch();
  61. data->ins_roll_angle = xgpsimu.roll();
  62. data->speed = sqrt(pow(xgpsimu.ve(),2)+pow(xgpsimu.vn(),2)) * 3.6;
  63. GaussProjCal(data->gps_lng, data->gps_lat, &data->gps_x, &data->gps_y);
  64. mMutexGPS.lock();
  65. iv::gps::gpsimu * pgpsimu = new iv::gps::gpsimu;
  66. pgpsimu->CopyFrom(xgpsimu);
  67. mGPSIMUptr.reset(pgpsimu);
  68. mNowGPS = data;
  69. mnGPSUpdateTime = QDateTime::currentMSecsSinceEpoch();
  70. mMutexGPS.unlock();
  71. }
  72. bool ivdecision::GetGPS(GPSData &xGPSData)
  73. {
  74. if((QDateTime::currentMSecsSinceEpoch() - mnGPSUpdateTime)>mnNewThresh)
  75. {
  76. xGPSData = NULL;
  77. return false;
  78. }
  79. xGPSData = mNowGPS;
  80. return true;
  81. }
  82. void ivdecision::UpdateRADAR(const char *strdata, const unsigned int nSize, const unsigned int index, const QDateTime *dt, const char *strmemname)
  83. {
  84. (void )&index;
  85. (void )&dt;
  86. (void )strmemname;
  87. if(nSize<1)return;
  88. iv::radar::radarobjectarray * pradar = new iv::radar::radarobjectarray;
  89. if(!pradar->ParseFromArray(strdata,nSize))
  90. {
  91. std::cout<<"ivdecision::UpdateRADARMsg Parse Error"<<std::endl;
  92. return;
  93. }
  94. mMutexRADAR.lock();
  95. mRADAR.reset(pradar);
  96. mnRADARUpdateTime = QDateTime::currentMSecsSinceEpoch();
  97. mMutexRADAR.unlock();
  98. }
  99. bool ivdecision::GetRADAR(std::shared_ptr<radar::radarobjectarray> &xRADAR)
  100. {
  101. if((QDateTime::currentMSecsSinceEpoch() - mnRADARUpdateTime)>mnNewThresh)
  102. {
  103. xRADAR = NULL;
  104. return false;
  105. }
  106. xRADAR = mRADAR;
  107. return true;
  108. }
  109. void ivdecision::UpdateLIDAR(const char *strdata, const unsigned int nSize, const unsigned int index, const QDateTime *dt, const char *strmemname)
  110. {
  111. (void )&index;
  112. (void )&dt;
  113. (void )strmemname;
  114. if(nSize<1)return;
  115. unsigned int nCount = nSize/sizeof(iv::ObstacleBasic);
  116. std::shared_ptr<std::vector<iv::ObstacleBasic>> lidar_obs = std::shared_ptr<std::vector<iv::ObstacleBasic>>(new std::vector<iv::ObstacleBasic>);
  117. lidar_obs->resize(nCount);
  118. memcpy(lidar_obs->data(),strdata,nCount*sizeof(iv::ObstacleBasic));
  119. mMutexLIDAR.lock();
  120. mlidar_obs = lidar_obs;
  121. mnLIDARUpdateTime = QDateTime::currentMSecsSinceEpoch();
  122. mMutexLIDAR.unlock();
  123. }
  124. bool ivdecision::GetLIDARGrid(LidarGridPtr &lidargridptr)
  125. {
  126. if((QDateTime::currentMSecsSinceEpoch() - mnLIDARUpdateTime)>mnNewThresh)
  127. {
  128. lidargridptr = NULL;
  129. return false;
  130. }
  131. LidarGridPtr ptr = (Obs_grid *)malloc(sizeof(Obs_grid[iv::grx][iv::gry]));
  132. memset(ptr, 0, sizeof(Obs_grid[iv::grx][iv::gry]));
  133. for (int i = 0; i <iv::grx; i++)//复制到指针数组
  134. {
  135. for (int j = 0; j <iv::gry; j++)
  136. {
  137. // ptr[i * (iv::gry) + j].high = obs_grid[i][j].high;
  138. // ptr[i * (iv::gry) + j].low = obs_grid[i][j].low;
  139. ptr[i * (iv::gry) + j].ob = 0;
  140. // ptr[i * (iv::gry) + j].obshight = obs_grid[i][j].obshight;
  141. // ptr[i * (iv::gry) + j].pointcount = obs_grid[i][j].pointcount;
  142. }
  143. }
  144. mMutexLIDAR.lock();
  145. for(unsigned int i=0;i<mlidar_obs->size();i++)
  146. {
  147. iv::ObstacleBasic xobs = mlidar_obs->at(i);
  148. int dx,dy;
  149. dx = (xobs.nomal_x + gridwide * (double)centerx)/gridwide;
  150. dy = (xobs.nomal_y + gridwide * (double)centery)/gridwide;
  151. if((dx>=0)&&(dx<iv::grx)&&(dy>=0)&&(dy<iv::gry))
  152. {
  153. ptr[dx*(iv::gry) +dy].high = xobs.high;
  154. ptr[dx*(iv::gry) +dy].low = xobs.low;
  155. ptr[dx*(iv::gry) + dy].ob = 2;
  156. ptr[dx*(iv::gry) + dy].obshight = xobs.nomal_z;
  157. ptr[dx*(iv::gry) + dy].pointcount = 5;
  158. }
  159. }
  160. lidargridptr = ptr;
  161. mMutexLIDAR.unlock();
  162. return true;
  163. }
  164. bool ivdecision::GetLIDARObs(std::shared_ptr<std::vector<ObstacleBasic> > &xlidar_obs)
  165. {
  166. if((QDateTime::currentMSecsSinceEpoch() - mnLIDARUpdateTime)>mnNewThresh)
  167. {
  168. xlidar_obs = NULL;
  169. return false;
  170. }
  171. mMutexLIDAR.lock();
  172. xlidar_obs = mlidar_obs;
  173. mMutexLIDAR.unlock();
  174. return true;
  175. }
  176. void ivdecision::UpdateMAP(const char *strdata, const unsigned int nSize, const unsigned int index, const QDateTime *dt, const char *strmemname)
  177. {
  178. (void )&index;
  179. (void )&dt;
  180. (void )strmemname;
  181. if(nSize<1)return;
  182. // std::cout<<"update map "<<std::endl;
  183. int gpsunitsize = sizeof(iv::GPS_INS);
  184. int nMapSize = nSize/gpsunitsize;
  185. // std::cout<<"map size is "<<nMapSize<<std::endl;
  186. if(nMapSize < 1)return;
  187. bool bUpdate = true;
  188. // if(nMapSize != mnavigation_data.size())
  189. // {
  190. // bUpdate = true;
  191. // }
  192. // else
  193. // {
  194. // iv::GPS_INS * p = (iv::GPS_INS *)mapdata;
  195. // if((p->gps_lat == navigation_data.at(0)->gps_lat)&&(p->ins_heading_angle == navigation_data.at(0)->ins_heading_angle))
  196. // {
  197. // // qDebug("same map");
  198. // bUpdate = false;
  199. // }
  200. // else
  201. // {
  202. // bUpdate = true;
  203. // }
  204. // }
  205. if(bUpdate)
  206. {
  207. mMutexMAP.lock();
  208. mnavigation_data.clear();
  209. mnavigation_data.resize(nMapSize);
  210. memcpy(mnavigation_data.data(),strdata,nMapSize * sizeof(iv::GPS_INS));
  211. mnMAPUpdateTime = QDateTime::currentMSecsSinceEpoch();
  212. mMutexMAP.unlock();
  213. }
  214. else
  215. {
  216. }
  217. }
  218. bool ivdecision::IsMAPUpdate(qint64 &nLastUpdateTime)
  219. {
  220. if(mnavigation_data.size()<1)
  221. {
  222. return false;
  223. }
  224. if(nLastUpdateTime != mnMAPUpdateTime)
  225. {
  226. return true;
  227. }
  228. return false;
  229. }
  230. bool ivdecision::GetMAP(std::vector<GPSData> &navigation_data, qint64 &nLastUpdateTime)
  231. {
  232. if(mnavigation_data.size()<1)
  233. {
  234. return false;
  235. }
  236. mMutexMAP.unlock();
  237. nLastUpdateTime = mnMAPUpdateTime;
  238. navigation_data = mnavigation_data;
  239. mMutexMAP.unlock();
  240. return true;
  241. }
  242. void ivdecision::UpdateMobileye(const char *strdata, const unsigned int nSize, const unsigned int index, const QDateTime *dt, const char *strmemname)
  243. {
  244. (void )&index;
  245. (void )&dt;
  246. (void )strmemname;
  247. if(nSize<1)return;
  248. std::shared_ptr<iv::mobileye::mobileye> xmobileye = std::shared_ptr<iv::mobileye::mobileye>(new iv::mobileye::mobileye);
  249. if(!xmobileye->ParseFromArray(strdata,nSize))
  250. {
  251. std::cout<<"ivdecision::UpdateMobileye Parse Error."<<std::endl;
  252. return;
  253. }
  254. mMutexmobileye.lock();
  255. mmobileye = xmobileye;
  256. mnmobileyeUpdateTime = QDateTime::currentMSecsSinceEpoch();
  257. mMutexmobileye.unlock();
  258. }
  259. bool ivdecision::GetMobileye(std::shared_ptr<mobileye::mobileye> &xmobileye)
  260. {
  261. if((QDateTime::currentMSecsSinceEpoch() - mnmobileyeUpdateTime)>mnNewThresh)
  262. {
  263. xmobileye = NULL;
  264. return false;
  265. }
  266. mMutexmobileye.lock();
  267. xmobileye = mmobileye;
  268. mMutexmobileye.unlock();
  269. return true;
  270. }
  271. void ivdecision::UpdateHMI(const char *strdata, const unsigned int nSize, const unsigned int index, const QDateTime *dt, const char *strmemname)
  272. {
  273. (void )&index;
  274. (void )&dt;
  275. (void )strmemname;
  276. if(nSize<1)return;
  277. std::shared_ptr<iv::hmi::hmimsg> xhmiptr = std::shared_ptr<iv::hmi::hmimsg>(new iv::hmi::hmimsg);
  278. if(!xhmiptr->ParseFromArray(strdata,nSize))
  279. {
  280. std::cout<<"ivdecision::UpdateHMI Parse Error."<<std::endl;
  281. return;
  282. }
  283. mMutexHMI.lock();
  284. mHMImsg = xhmiptr;
  285. mnHMIUpdateTime = QDateTime::currentMSecsSinceEpoch();
  286. mMutexHMI.unlock();
  287. }
  288. bool ivdecision::GetHMImsg(std::shared_ptr<hmi::hmimsg> &xhmimsg)
  289. {
  290. if((QDateTime::currentMSecsSinceEpoch() - mnHMIUpdateTime)>mnNewThresh)
  291. {
  292. xhmimsg = NULL;
  293. return false;
  294. }
  295. mMutexHMI.lock();
  296. xhmimsg = mHMImsg;
  297. mMutexHMI.unlock();
  298. return true;
  299. }
  300. void ivdecision::UpdateVbox(const char *strdata, const unsigned int nSize, const unsigned int index, const QDateTime *dt, const char *strmemname)
  301. {
  302. (void )&index;
  303. (void )&dt;
  304. (void )strmemname;
  305. std::shared_ptr<iv::vbox::vbox> vbox_ptr = std::shared_ptr<iv::vbox::vbox>(new iv::vbox::vbox);
  306. if(!vbox_ptr->ParseFromArray(strdata,nSize))
  307. {
  308. std::cout<<"vdecision::UpdateVbox Parse Error"<<std::endl;
  309. return;
  310. }
  311. mMutexvbox.lock();
  312. mvboxmsg = vbox_ptr;
  313. mnvboxUpdateTime = QDateTime::currentMSecsSinceEpoch();
  314. mMutexvbox.unlock();
  315. }
  316. bool ivdecision::Getvboxmsg(std::shared_ptr<vbox::vbox> &xvboxmsg)
  317. {
  318. if((QDateTime::currentMSecsSinceEpoch() - mnvboxUpdateTime)>mnNewThresh)
  319. {
  320. xvboxmsg = NULL;
  321. return false;
  322. }
  323. mMutexvbox.lock();
  324. xvboxmsg = mvboxmsg;
  325. mMutexvbox.unlock();
  326. return true;
  327. }
  328. void ivdecision::Updatev2x(const char *strdata, const unsigned int nSize, const unsigned int index, const QDateTime *dt, const char *strmemname)
  329. {
  330. (void )&index;
  331. (void )&dt;
  332. (void )strmemname;
  333. std::shared_ptr<iv::v2x::v2x> xv2x_ptr = std::shared_ptr<iv::v2x::v2x>(new iv::v2x::v2x);
  334. if(!xv2x_ptr->ParseFromArray(strdata,nSize))
  335. {
  336. std::cout<<"ivdecision::Updatev2x Parse Error."<<std::endl;
  337. return;
  338. }
  339. mMutexv2x.lock();
  340. mv2xmsg = xv2x_ptr;
  341. mnv2xUpdateTime = QDateTime::currentMSecsSinceEpoch();
  342. mMutexv2x.unlock();
  343. }
  344. bool ivdecision::Getv2xmsg(std::shared_ptr<v2x::v2x> &xv2xmsg)
  345. {
  346. if((QDateTime::currentMSecsSinceEpoch() - mnv2xUpdateTime)>mnNewThresh)
  347. {
  348. xv2xmsg = NULL;
  349. return false;
  350. }
  351. mMutexv2x.lock();
  352. xv2xmsg = mv2xmsg;
  353. mMutexv2x.unlock();
  354. return true;
  355. }
  356. void ivdecision::Updateultrasonic(const char *strdata, const unsigned int nSize, const unsigned int index, const QDateTime *dt, const char *strmemname)
  357. {
  358. (void )&index;
  359. (void )&dt;
  360. (void )strmemname;
  361. std::shared_ptr<iv::ultrasonic::ultrasonic> xultrasonic_ptr
  362. = std::shared_ptr<iv::ultrasonic::ultrasonic>(new iv::ultrasonic::ultrasonic);
  363. if(!xultrasonic_ptr->ParseFromArray(strdata,nSize))
  364. {
  365. std::cout<<"ivdecision::Updateultrasonic Parse Error."<<std::endl;
  366. return;
  367. }
  368. mMutexultrasonic.lock();
  369. multrasonicmsg = xultrasonic_ptr;
  370. mnultrasonicUpdateTime = QDateTime::currentMSecsSinceEpoch();
  371. mMutexultrasonic.unlock();
  372. }
  373. bool ivdecision::Getultrasonic(std::shared_ptr<ultrasonic::ultrasonic> &xultramsg)
  374. {
  375. if((QDateTime::currentMSecsSinceEpoch() - mnultrasonicUpdateTime)>mnNewThresh)
  376. {
  377. xultramsg = NULL;
  378. return false;
  379. }
  380. mMutexultrasonic.lock();
  381. xultramsg = multrasonicmsg;
  382. mMutexultrasonic.unlock();
  383. return true;
  384. }
  385. }