ADCIntelligentVehicle.cpp 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875
  1. #include "ADCIntelligentVehicle.h"
  2. #include "chassis.pb.h"
  3. #include "xmlparam.h"
  4. #define qtcout qDebug() << "[ " << __FILE__ << ":" << __LINE__<< " ]";
  5. extern std::string gstrmemgps;
  6. /**
  7. 常量 值 描述
  8. QHostAddress::Null 0 空地址对象,相当于QHostAddress()。
  9. QHostAddress::LocalHost 2 IPv4本地主机地址,相当于QHostAddress(“127.0.0.1”)。
  10. QHostAddress::LocalHostIPv6 3 IPv6本地主机地址,相当于 QHostAddress(“::1”)。
  11. QHostAddress::Broadcast 1 Pv4广播地址,相当于QHostAddress(“255.255.255.255”)。
  12. QHostAddress::AnyIPv4 6 IPv4 any-address,相当于QHostAddress(“0.0.0.0”)。与该地址绑定的socket将只监听IPv4接口。
  13. QHostAddress::AnyIPv6 5 IPv6 any-address,相当于QHostAddress(“::”)。与该地址绑定的socket将只监听IPv4接口。
  14. QHostAddress::Any 4 双any-address栈,与该地址绑定的socket将侦听IPv4和IPv6接口。
  15. */
  16. #define VIEW_CENTER viewport()->rect().center()
  17. const double PI = 3.1415926535898;
  18. extern iv::Ivlog * gIvlog;
  19. /**
  20. * @brief MyView::MyView
  21. * @param parent
  22. */
  23. MyView::MyView(QWidget *parent) :
  24. QGraphicsView(parent),
  25. beishu(1.00000)
  26. {
  27. setDragMode(QGraphicsView::ScrollHandDrag); //设置视图的拖拽模式 (光标变为指向手,然后拖动鼠标将滚动滚动条,此模式在交互和非交互模式下均有效)
  28. }
  29. /**
  30. * @brief MyView::mousePressEvent
  31. * @param event
  32. */
  33. void MyView::mousePressEvent(QMouseEvent *event)
  34. {
  35. bottonstatus = true;
  36. QGraphicsView::mousePressEvent(event);
  37. }
  38. /**
  39. * @brief MyView::mouseMoveEvent
  40. * @param event
  41. */
  42. void MyView::mouseMoveEvent(QMouseEvent *event)
  43. {
  44. QGraphicsView::mouseMoveEvent(event);
  45. }
  46. void MyView::keyPressEvent(QKeyEvent *event)
  47. {
  48. //按键按下,key值放入容器,如果是长按触发的repeat就不判断
  49. if(!event->isAutoRepeat())
  50. mPressKeys.insert(event->key());
  51. if(event->key() == Qt::Key_J)
  52. {
  53. emit CtrlManual(true);
  54. }
  55. if(event->key() == Qt::Key_K)
  56. {
  57. emit CtrlManual(false);
  58. }
  59. // qDebug("key count is %d",mPressKeys.count());
  60. // QDateTime dt;
  61. // qDebug("key press %ld",QDateTime::currentMSecsSinceEpoch());
  62. // qDebug(" key is %d",event->key());
  63. }
  64. void MyView::keyReleaseEvent(QKeyEvent *event)
  65. {
  66. if(!event->isAutoRepeat())mPressKeys.remove(event->key());
  67. qDebug("key count is %d",mPressKeys.count());
  68. // QDateTime dt;
  69. // qDebug("key release %ld",QDateTime::currentMSecsSinceEpoch());
  70. }
  71. /**
  72. * @brief MyView::mouseReleaseEvent
  73. * @param event
  74. */
  75. void MyView::mouseReleaseEvent(QMouseEvent *event)
  76. {
  77. bottonstatus = false;
  78. QGraphicsView::mouseReleaseEvent(event);
  79. }
  80. ADCIntelligentVehicle * gAV;
  81. //void ListenTraceMap(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
  82. //{
  83. // gAV->UpdateMap(strdata,nSize);
  84. //}
  85. // void Listengpsimu(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
  86. // {
  87. // gAV->UpdateGPSIMU(strdata,nSize);
  88. // }
  89. // void ListenRadar(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
  90. // {
  91. // gAV->UpdateRADAR(strdata,nSize);
  92. // }
  93. /**
  94. * @brief ListenCANState
  95. * @param strdata
  96. * @param nSize
  97. * @param index
  98. * @param dt
  99. * @param strmemname
  100. */
  101. void ListenCANState(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
  102. {
  103. // gIvlog->debug("ListenCanState");
  104. gAV->UpdateCANState(strdata,nSize);
  105. }
  106. //void ListenDecition(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
  107. //{
  108. // gAV->UpdateDecition(strdata,nSize);
  109. //}
  110. //void ListenVehicleState(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
  111. //{
  112. // gAV->UpdateVehicleState(strdata,nSize);
  113. //}
  114. /**
  115. * @brief ListenOBS
  116. * @param strdata
  117. * @param nSize
  118. * @param index
  119. * @param dt
  120. * @param strmemname
  121. */
  122. void ListenOBS(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
  123. {
  124. // qDebug("size is %d",nSize);
  125. std::shared_ptr<std::vector<iv::ObstacleBasic>> lidar_obs(new std::vector<iv::ObstacleBasic>);
  126. iv::ObstacleBasic * pdata = (iv::ObstacleBasic *)strdata;
  127. int nCount = nSize/sizeof(iv::ObstacleBasic);
  128. int i;
  129. for(i=0;i<nCount;i++)
  130. {
  131. iv::ObstacleBasic temp;
  132. memcpy(&temp,pdata,sizeof(iv::ObstacleBasic));
  133. lidar_obs->push_back(temp);
  134. pdata++;
  135. }
  136. gAV->UpdateOBS(lidar_obs);
  137. // gw->UpdateOBS(lidar_obs);
  138. }
  139. //v2x使能状态请求
  140. void ListenV2xStReq(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
  141. {
  142. // gIvlog->info("hmi", "v2x enable request %d %d",nSize,sizeof(iv::v2x::v2xStReq));
  143. // if(nSize < sizeof(iv::v2x::v2xStReq))
  144. // return;
  145. iv::v2x::v2xStReq xv2xStReqMsg;
  146. if(!xv2xStReqMsg.ParseFromArray(strdata,nSize))
  147. {
  148. gIvlog->error("hmi", "iv::v2x::xv2xStReqMsg::ListenV2xStReq parse error");
  149. return;
  150. }
  151. if(xv2xStReqMsg.v2xstreq())
  152. {
  153. gAV->UpdateV2xStEn(gAV->mv2xStEn);
  154. gIvlog->info("hmi", "v2x enable request %d",gAV->mv2xStEn);
  155. }
  156. }
  157. /**
  158. * @brief ADCIntelligentVehicle::ADCIntelligentVehicle
  159. * @param parent
  160. */
  161. ADCIntelligentVehicle::ADCIntelligentVehicle(QWidget *parent)
  162. : QMainWindow(parent),
  163. ui(new Ui::ADCIntelligentVehicle),
  164. m_translateButton(Qt::LeftButton),
  165. m_translateSpeed(1.0),
  166. m_zoomDelta(0.1),
  167. m_bMouseTranslate(false),
  168. m_scale(1.0),
  169. horizontalOffset(0),
  170. verticalOffset(0),
  171. scaleFactor(1),
  172. currentStepScaleFactor(1)
  173. {
  174. ui->setupUi(this);
  175. gAV = this;
  176. gIvlog->info("ADCIntelligentVehicle Start Initialize");
  177. mTime.start();
  178. /*
  179. QString strpath = QCoreApplication::applicationDirPath();
  180. strpath = strpath + "/ADS_decision.xml";
  181. iv::xmlparam::Xmlparam xp(strpath.toStdString());
  182. ServiceCarStatus.mvehtype= xp.GetParam("vehType","ge3");
  183. if(ServiceCarStatus.mvehtype=="ge3"){
  184. ;
  185. }else if( ServiceCarStatus.mvehtype=="qingyuan"){
  186. ;
  187. }else if( ServiceCarStatus.mvehtype=="vv7"){
  188. ;
  189. }else if( ServiceCarStatus.mvehtype=="zhongche"){
  190. ;
  191. }
  192. */
  193. QString strpath = QCoreApplication::applicationDirPath();
  194. strpath = strpath + "/ui_ads_hmi.xml";
  195. iv::xmlparam::Xmlparam xp(strpath.toStdString());
  196. ServiceCarStatus.esr_y_offset = atof(xp.GetParam("esr_y_offset","2.5").data());
  197. ServiceCarStatus.lidar_y_offset = atof(xp.GetParam("lidar_y_offset","0").data());
  198. ui->listWidget->setIconSize(QSize(40,40));
  199. ui->stackedWidget->setCurrentIndex(0);
  200. // QObject::connect(ui->listWidget,SIGNAL(currentRowChanged(int)),ui->stackedWidget,SLOT(on_listWidget_clicked()));//信号与槽
  201. QObject::connect(ui->listWidget,SIGNAL(currentRowChanged(int)),this,SLOT(on_listWidget_clicked()));//信号与槽
  202. // /********************************** 百度地图显示 ********************************/
  203. // mMapview = new QWebEngineView(ui->stackedWidget->widget(0));
  204. //// qDebug((QDir::currentPath()).toLatin1().data());
  205. // mMapview->load(QUrl(QString("file:///%1/%2").arg(QApplication::applicationDirPath()).arg("BaiDuMap.html")));
  206. // mMapview->setGeometry(750,250,400,400);
  207. // /********************************************************************************/
  208. ui->listWidget->setCurrentRow(1); //apollo_fu debug 20200409
  209. myview = new MyView(ui->stackedWidget->widget(1));
  210. myview->setObjectName(QStringLiteral("graphicsView"));
  211. myview->setGeometry(QRect(0, 100, 900, 900)); //从屏幕上(0,100)位置开始(即为最左上角的点),显示一个900*900的界面(宽900,高900)
  212. #if 0
  213. myview_small = new MyView(ui->stackedWidget->widget(1));
  214. myview_small->setObjectName(QStringLiteral("graphicsView_small"));
  215. myview_small->setGeometry(QRect(1000,100,500,500));
  216. myview_small->setAlignment(Qt::AlignLeft | Qt::AlignTop);
  217. #endif
  218. // myview_small->scale(0.7,0.7);
  219. //myview_small->centerOn(-200,-200);
  220. /********************************** 百度地图显示 ********************************/
  221. mMapview = new QWebEngineView(ui->stackedWidget->widget(1));
  222. // qDebug((QDir::currentPath()).toLatin1().data());
  223. mMapview->load(QUrl(QString("file:///%1/%2").arg(QApplication::applicationDirPath()).arg("BaiDuMap.html")));
  224. mMapview->setGeometry(1000,100,500,500);
  225. /********************************************************************************/
  226. image = new QImage(900 * 2, 900 * 2, QImage::Format_RGB32);//画布的初始化大小设为600*500,使用32位颜色
  227. //QImage的32、24、8位图。 图像格式:QImage::Format_RGB32 ,QImage::Format_RGB888,QImage::Format_Indexed8。
  228. //QImage myImage2 = QImage(width, height, QImage::Format_…); 根据图像宽高来构造一幅图像,程序会自动根据图像格式对齐图像数据。
  229. image_small = new QImage(1800,1800,QImage::Format_RGB32);
  230. myview->setCacheMode(myview->CacheBackground);
  231. #if 0
  232. myview_small->setCacheMode(myview_small->CacheBackground);
  233. #endif
  234. painter = new QPainter(image); //创建QPainter对象
  235. painter_small = new QPainter(image_small); //创建QPainter对象
  236. scene = new QGraphicsScene;
  237. scene_small = new QGraphicsScene;
  238. timer = new QTimer(this);
  239. connect(timer, SIGNAL(timeout()), this, SLOT(timeoutslot()));//timeoutslot()为自定义槽
  240. timer->start(100);
  241. Lidar_obsread = boost::shared_ptr<std::vector<iv::ObstacleBasic>>(new std::vector<iv::ObstacleBasic>);
  242. Lidar_read = boost::shared_ptr<std::vector<iv::ObstacleBasic>>(new std::vector<iv::ObstacleBasic>);
  243. mDataToUI.mHead.type = 1;
  244. mDataToUI.mInfo.accelerate = 0;
  245. mDataToUI.mInfo.brake = 0;
  246. mDataToUI.mInfo.gps_lat = 0;
  247. mDataToUI.mInfo.gps_lng = 0;
  248. mDataToUI.mInfo.is_mapLoad = 0;
  249. mDataToUI.mInfo.is_initSuccess = 0;
  250. mDataToUI.mInfo.is_run = 0;
  251. mDataToUI.mInfo.speed = 0;
  252. msockrecv.bind(QHostAddress::Any,9998);//绑定端口
  253. connect(&msockrecv,SIGNAL(readyRead()),this,SLOT(onRecvUDP())); //接收来自PAD的UDP数据报 readyRead():socket读取缓冲区有数据时发送此信号,在此信号的槽函数里读取缓冲区的数据。
  254. ServiceCarStatus.speed = 0.0;
  255. mTimerState.setTimerType(Qt::PreciseTimer); //设置计时器的精确程度 Qt::PreciseTimer值为0,含义:精确定时器试图保持毫秒精度
  256. connect(&mTimerState,SIGNAL(timeout()),this,SLOT(onStateTimer()));//广播发送UDP数据报
  257. mTimerState.start(100); //定时100ms
  258. mTimerStateMap.setTimerType(Qt::PreciseTimer); //
  259. connect(&mTimerStateMap,SIGNAL(timeout()),this,SLOT(onStateTimerMap()));//
  260. mTimerStateMap.start(500); //定时500ms
  261. is_show_enable = true;
  262. #ifdef USE_PAD_CTRL
  263. AutoStart();
  264. #endif
  265. ModuleFun funplantrace = std::bind(&ADCIntelligentVehicle::UpdatePlanTrace,this,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
  266. mpaplantrace = iv::modulecomm::RegisterRecvPlus("plantrace",funplantrace);
  267. ModuleFun funplantrace_left = std::bind(&ADCIntelligentVehicle::UpdatePlanTrace_left,this,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
  268. mpaplantrace_left = iv::modulecomm::RegisterRecvPlus("obstraceleft",funplantrace_left);
  269. ModuleFun funplantrace_right = std::bind(&ADCIntelligentVehicle::UpdatePlanTrace_right,this,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
  270. mpaplantrace_right = iv::modulecomm::RegisterRecvPlus("obstraceright",funplantrace_right);
  271. ModuleFun funfusion = std::bind(&ADCIntelligentVehicle::UpdateFusion,this,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
  272. mpafusion = iv::modulecomm::RegisterRecvPlus("li_ra_fusion",funfusion);
  273. ModuleFun funmap = std::bind(&ADCIntelligentVehicle::UpdateMap,this,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
  274. mpa = iv::modulecomm::RegisterRecvPlus("tracemap",funmap);
  275. // mpa = iv::modulecomm::RegisterRecv("tracemap",ListenTraceMap);
  276. ModuleFun fungpsimu =std::bind(&ADCIntelligentVehicle::UpdateGPSIMU,this,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
  277. mpagpsimu = iv::modulecomm::RegisterRecvPlus(gstrmemgps.data(),fungpsimu);
  278. // mpagpsimu = iv::modulecomm::RegisterRecv("gpsimu",Listengpsimu);
  279. ModuleFun funradar =std::bind(&ADCIntelligentVehicle::UpdateRADAR,this,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
  280. mparadar = iv::modulecomm::RegisterRecvPlus("radar",funradar);
  281. ModuleFun funchassis =std::bind(&ADCIntelligentVehicle::UpdateChassis,this,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
  282. mpachassis = iv::modulecomm::RegisterRecvPlus("chassis",funchassis);
  283. mpacanstate = iv::modulecomm::RegisterRecv("canstate",ListenCANState);
  284. gIvlog->debug("canState ptr: %x",mpacanstate);
  285. ModuleFun funbrainstate =std::bind(&ADCIntelligentVehicle::UpdateVehicleState,this,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
  286. // mpaVechicleState = iv::modulecomm::RegisterRecvPlus("vehiclestate",funbrainstate);
  287. mpaVechicleState = iv::modulecomm::RegisterRecvPlus("brainstate",funbrainstate);
  288. ModuleFun fundecition =std::bind(&ADCIntelligentVehicle::UpdateDecition,this,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
  289. // mpaDecition = iv::modulecomm::RegisterRecvPlus("decition",fundecition);
  290. mpaDecition = iv::modulecomm::RegisterRecvPlus("deciton",fundecition);
  291. mpaLidar = iv::modulecomm::RegisterRecv("lidar_obs",ListenOBS);
  292. mpaHMI = iv::modulecomm::RegisterSend("hmi",10*sizeof(iv::hmi::HMIBasic),10);
  293. iv::modulecomm::RegisterRecv("v2xStReq", ListenV2xStReq);
  294. mp_v2xStSend = iv::modulecomm::RegisterSend("v2xStEn",1000,1);
  295. mTimeState.start();
  296. mpManualCtrl = iv::modulecomm::RegisterSend("ivmanual",1000,1);
  297. mTimerManual = new QTimer(this);
  298. connect(mTimerManual,SIGNAL(timeout()),this,SLOT(onTimerManual()));
  299. connect(myview,SIGNAL(CtrlManual(bool)),this,SLOT(onCtrlManual(bool)));
  300. mnCtrlValue[0] = 0; mnCtrlValue[1] = 0; mnCtrlValue[2] = 0;
  301. // timermanualctrl->start(10);
  302. //connect(ui->lineEdit_6, SIGNAL(textEdited(const QString &)), this, SLOT(savestabuyEditinfo(const QString &)));
  303. mpamapreq = iv::modulecomm::RegisterSend("mapreq",1000,1);
  304. shareMapReqMsg();
  305. ModuleFun funvbox = std::bind(&ADCIntelligentVehicle::UpdateVbox,this,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
  306. mpaplantrace = iv::modulecomm::RegisterRecvPlus("vbox",funvbox);
  307. }
  308. /**
  309. * @brief ADCIntelligentVehicle::savestabuyEditinfo
  310. * @param txt
  311. */
  312. void ADCIntelligentVehicle::savestabuyEditinfo(const QString &txt)
  313. {
  314. //ServiceControlStatus.set_accelerate((float)txt.toDouble());
  315. }
  316. /**
  317. * @brief ADCIntelligentVehicle::timeoutslot
  318. */
  319. void ADCIntelligentVehicle::timeoutslot()
  320. {
  321. update();
  322. /////////////////////////////////
  323. // //
  324. // 实时状态信息显示 //
  325. ////////////////////////////////
  326. QString is_ok;
  327. ui->lineEdit->setText(QString::number(ServiceCarStatus.location->rtk_status));//rtk状态
  328. ui->lineEdit_12->setText(QString::number(ServiceCarStatus.location->rtk_status));//rtk状态
  329. if(ServiceCarStatus.location->rtk_status==6)
  330. {
  331. ui->pushButton_10->setStyleSheet("background-color: green");
  332. ui->pushButton_23->setStyleSheet("background-color: green");
  333. }
  334. else
  335. {
  336. ui->pushButton_10->setStyleSheet("background-color: red");
  337. ui->pushButton_23->setStyleSheet("background-color: red");
  338. }
  339. ui->lineEdit_2->setText(QString::number(ServiceCarStatus.location->ins_status));//ins状态
  340. if(ServiceCarStatus.location->ins_status==4)
  341. ui->pushButton_11->setStyleSheet("background-color: green");
  342. else
  343. ui->pushButton_11->setStyleSheet("background-color: red");
  344. is_ok = (ServiceCarStatus.mRadarS>0)?QStringLiteral("ok"):QStringLiteral("error");
  345. ui->lineEdit_3->setText(is_ok);//毫米波雷达状态
  346. ui->lineEdit_15->setText(is_ok);//毫米波雷达状态
  347. if(ServiceCarStatus.mRadarS>0)
  348. {
  349. ui->pushButton_12->setStyleSheet("background-color: green");
  350. ui->pushButton_25->setStyleSheet("background-color: green");
  351. }
  352. else
  353. {
  354. ui->pushButton_12->setStyleSheet("background-color:red");
  355. ui->pushButton_25->setStyleSheet("background-color:red");
  356. }
  357. is_ok = (ServiceCarStatus.mLidarS>0)?QStringLiteral("ok"):QStringLiteral("error");
  358. ui->lineEdit_4->setText(is_ok);//激光雷达状态
  359. ui->lineEdit_16->setText(is_ok);//激光雷达状态
  360. if(ServiceCarStatus.mLidarS>0)
  361. {
  362. ui->pushButton_13->setStyleSheet("background-color: green");
  363. ui->pushButton_26->setStyleSheet("background-color: green");
  364. }
  365. else
  366. {
  367. ui->pushButton_13->setStyleSheet("background-color:red");
  368. ui->pushButton_26->setStyleSheet("background-color:red");
  369. }
  370. ui->lineEdit_5->setText(QString::number(mdecition_period)+QStringLiteral("ms"));//决策周期
  371. ui->lineEdit_17->setText(QString::number(mdecition_period)+QStringLiteral("ms"));//决策周期
  372. if(mdecition_period>0)
  373. {
  374. ui->pushButton_14->setStyleSheet("background-color: green");
  375. ui->pushButton_27->setStyleSheet("background-color: green");
  376. }
  377. if((mTimeState.elapsed()-mnTimeUpdateGPS) > 1000)
  378. {
  379. ui->pushButton_10->setStyleSheet("background-color: red");
  380. ui->pushButton_11->setStyleSheet("background-color: red");
  381. ui->pushButton_23->setStyleSheet("background-color: red");
  382. }
  383. if((mTimeState.elapsed() - mnTimeUpdateDecition)>1000)
  384. {
  385. ui->pushButton_14->setStyleSheet("background-color:red");
  386. ui->pushButton_27->setStyleSheet("background-color:red");
  387. ui->label_decition->setText("No decition");
  388. mbBrainRunning = false;
  389. }
  390. else
  391. {
  392. QString strdec = "Acc:";
  393. strdec = strdec + QString::number(ServiceCarStatus.mfAcc,'f',1);
  394. // strdec = strdec + " Brake:";
  395. // strdec = strdec + QString::number(ServiceCarStatus.mfBrake,'f',1);
  396. strdec = strdec + " EPS:";
  397. strdec = strdec + QString::number(ServiceCarStatus.mfWheel,'f',1);
  398. ui->label_decition->setText(strdec);
  399. }
  400. if(mbManual)
  401. {
  402. char strmanual[256];
  403. snprintf(strmanual,256,"Manual %d %d %d",mnCtrlValue[0],mnCtrlValue[1],mnCtrlValue[2]);
  404. ui->label_decition->setText(strmanual);
  405. }
  406. /////////////////////////////////
  407. // //
  408. // 实时显示障碍物状态 //
  409. /////////////////////////////////
  410. // ServiceCarStatus.mObs = 10;
  411. // ServiceCarStatus.mLidarObs = 9.123;
  412. // ServiceCarStatus.mRadarObs = 9.222;
  413. // ServiceCarStatus.mfttc = 0.5;
  414. // ServiceCarStatus.mfBrake = 20;
  415. if(ServiceCarStatus.mObs > 0)
  416. {
  417. ui->label_13->setText("Obs:"+QString::number(ServiceCarStatus.mObs,'f',1)+" Lidar:"
  418. +QString::number(ServiceCarStatus.mLidarObs,'f',1) + " Radar:"
  419. +QString::number(ServiceCarStatus.mRadarObs,'f',1));
  420. }
  421. else
  422. {
  423. ui->label_13->setText(QString("前方没有障碍物"));
  424. }
  425. ui->label_26->setText("ttc is "+QString::number(ServiceCarStatus.mfttc,'f',1) + " brake is " + QString::number(ServiceCarStatus.mfBrake,'f',2)); //add 20200518
  426. QString strstate = "Map:";
  427. if(mDataToUI.mInfo.is_mapLoad == 1)
  428. {
  429. strstate = strstate+"Yes ";
  430. }
  431. else
  432. {
  433. strstate = strstate+"No ";
  434. }
  435. strstate = strstate+" CANCARD:";
  436. if(mDataToUI.mInfo.is_initSuccess == 1)
  437. {
  438. strstate = strstate+"OK ";
  439. }
  440. else
  441. {
  442. strstate = strstate+"Fail ";
  443. }
  444. strstate = strstate + " Run State:";
  445. if(mbBrainRunning)
  446. {
  447. strstate = strstate+"RUN";
  448. }
  449. else
  450. {
  451. strstate = strstate+"STOP";
  452. }
  453. ui->label_State->setText(strstate);
  454. ui->lb_current_speed_big->setText(QString::number(ServiceCarStatus.speed,'f',1));
  455. // QString is_ok;
  456. // is_ok = (ServiceLidar.did_lidar_ok() == true)?QStringLiteral("ok"):QStringLiteral("error");
  457. // ui->lineEdit_4->setText(is_ok);
  458. //can state
  459. mDataToUI.mInfo.is_initSuccess = 0;
  460. }
  461. /**
  462. * @brief ADCIntelligentVehicle::on_pb_load_navigation_data_clicked
  463. */
  464. //void ADCIntelligentVehicle::on_pb_load_navigation_data_clicked() //加载地图
  465. //{
  466. //}
  467. /**
  468. * @brief ADCIntelligentVehicle::onRecvUDP
  469. */
  470. void ADCIntelligentVehicle::onRecvUDP()
  471. {
  472. while (msockrecv.hasPendingDatagrams()) //hasPendingDatagrams()表示是否有待读取的传入数据报
  473. {
  474. qDebug("recv cmd");
  475. QByteArray ba;
  476. ba.resize(msockrecv.pendingDatagramSize());//pendingDatagramSize()返回待读取数据报的字节数
  477. msockrecv.readDatagram(ba.data(), ba.size()); //readDatagram()函数用于读取数据报内容
  478. int * p;
  479. iv::hmi::HMIBasic hmi;
  480. p = (int *)ba.data();
  481. // qDebug("cmd is ",*p);
  482. // std::cout<<"data len is "<<ba.size()<<" value is "<<*p<<std::endl;
  483. if(*p == 1)
  484. {
  485. std::cout<<ServiceCarStatus.mRunTime.elapsed()<<":"<<"recv start."<<std::endl;
  486. ServiceCarStatus.mbRunPause = false;
  487. hmi.mbBocheMode = false;
  488. hmi.mbPause = false;
  489. ShareHMIMsg(hmi);
  490. }
  491. if(*p == 0)
  492. {
  493. ServiceCarStatus.mbRunPause = true;
  494. hmi.mbBocheMode = false;
  495. hmi.mbPause = true;
  496. ShareHMIMsg(hmi);
  497. }
  498. if(*p == 2)
  499. {
  500. ServiceCarStatus.bocheMode = true;
  501. hmi.mbBocheMode = true;
  502. hmi.mbPause = false;
  503. ShareHMIMsg(hmi);
  504. }
  505. if(*p == 3)
  506. {
  507. hmi.mbbusmode = true;
  508. hmi.mbPause = ServiceCarStatus.mbRunPause;
  509. ShareHMIMsg(hmi);
  510. }
  511. if(*p == 4)
  512. {
  513. hmi.mbbusmode = false;
  514. hmi.mbPause = ServiceCarStatus.mbRunPause;
  515. ShareHMIMsg(hmi);
  516. }
  517. }
  518. }
  519. /**
  520. * @brief ADCIntelligentVehicle::onStateTimer
  521. */
  522. void ADCIntelligentVehicle::onStateTimer()
  523. {
  524. if(ServiceCarStatus.mbBrainCtring)
  525. mDataToUI.mInfo.is_run = 1;
  526. else
  527. mDataToUI.mInfo.is_run = 0;
  528. if(ServiceCarStatus.mLidarS<0)
  529. mDataToUI.mInfo.lidarStatus = 0;
  530. else
  531. mDataToUI.mInfo.lidarStatus = 1;
  532. if(ServiceCarStatus.mRadarS<0)
  533. mDataToUI.mInfo.radarStatus = 0;
  534. else
  535. mDataToUI.mInfo.radarStatus = 1;
  536. ServiceCarStatus.mLidarS--; //如果从10减到0,表示没有接收到数据。
  537. ServiceCarStatus.mRadarS--;
  538. mDataToUI.mInfo.RTKstatus = ServiceCarStatus.mRTKStatus;
  539. ServiceCarStatus.mRTKStatus = 0;
  540. mDataToUI.mInfo.radarobs = ServiceCarStatus.mRadarObs;
  541. mDataToUI.mInfo.lidarobs = ServiceCarStatus.mLidarObs;
  542. mDataToUI.mInfo.obs = ServiceCarStatus.mObs;
  543. mDataToUI.mInfo.gps_lat = ServiceCarStatus.location->gps_lat;
  544. mDataToUI.mInfo.gps_lng = ServiceCarStatus.location->gps_lng;
  545. mDataToUI.mInfo.accelerate = ServiceCarStatus.mfAcc;
  546. mDataToUI.mInfo.speed = ServiceCarStatus.speed;
  547. mDataToUI.mInfo.brake = ServiceCarStatus.mfBrake;
  548. mDataToUI.mInfo.swerve = ServiceCarStatus.mfWheel;
  549. mDataToUI.mInfo.boche_status = ServiceCarStatus.bocheEnable;
  550. if(fabs(mDataToUI.mInfo.gps_lat)<1 )
  551. {
  552. // qDebug("gps lat is error.");
  553. // std::cout<<"no gps."<<std::endl;
  554. }
  555. // std::cout<<"send data."<<std::endl;
  556. // qDebug("speed is %d",mDataToUI.mInfo.speed);
  557. // mDataToUI.mInfo.is_initSuccess = 1;
  558. // mDataToUI.mInfo.speed = 36.1;
  559. msocksend.writeDatagram((char *)&mDataToUI,sizeof(DataToUI),QHostAddress::Broadcast,9999); //QHostAddress::Broadcast 值为1 Pv4广播地址,相当于QHostAddress(“255.255.255.255”)。
  560. // _udp->writeDatagram(str.toUtf8(), QHostAddress::Broadcast, 10002);
  561. // multicast, 224.0.0.1~224.0.0.255 is multicast address of LAN
  562. // _udp->writeDatagram(str.toUtf8(), QHostAddress("224.0.0.131"), 10002);
  563. }
  564. void ADCIntelligentVehicle::onStateTimerMap()
  565. {
  566. /*******************************更新百度地图******************************/
  567. double flat = ServiceCarStatus.location->gps_lat;
  568. double flon = ServiceCarStatus.location->gps_lng;
  569. double fang = ServiceCarStatus.location->ins_heading_angle;
  570. char strscript[256];
  571. snprintf(strscript,255,"theLocation(%11.7f,%11.7f,%11.7f);",flon,flat,fang);
  572. mMapview->page()->runJavaScript(strscript);
  573. /************************************************************************/
  574. }
  575. /**
  576. * @brief ADCIntelligentVehicle::AutoStart
  577. */
  578. void ADCIntelligentVehicle::AutoStart()
  579. {
  580. // is_brain_running_flag_ = true;
  581. // mDataToUI.mInfo.is_initSuccess = 1;
  582. // std::cout<<ServiceCarStatus.mRunTime.elapsed()<<"ms:"<<"Start Run SuccessFully."<<std::endl;
  583. }
  584. /**
  585. * @brief ADCIntelligentVehicle::on_pb_start_all_clicked
  586. */
  587. void ADCIntelligentVehicle::on_pb_start_all_clicked() {
  588. #ifdef USE_PAD_CTRL
  589. ServiceCarStatus.mbRunPause = false;
  590. iv::hmi::HMIBasic hmi;
  591. hmi.mbBocheMode = false;
  592. hmi.mbPause = false;
  593. ShareHMIMsg(hmi);
  594. return;
  595. #endif
  596. }
  597. /**
  598. * @brief ADCIntelligentVehicle::on_pb_open_can_card_clicked
  599. */
  600. //void ADCIntelligentVehicle::on_pb_open_can_card_clicked() {
  601. //}
  602. /**
  603. * @brief ADCIntelligentVehicle::on_timer_car_status_time_out
  604. */
  605. //void ADCIntelligentVehicle::on_timer_car_status_time_out() {
  606. // ui->lb_current_speed_big->setText(QString::number(ServiceCarStatus.speed));
  607. // //ui->sb_accelerate_percent->setValue(ServiceControlStatus.accelerate_percent);
  608. // //ui->sb_wheel_percent->setValue(ServiceControlStatus.wheel_angle);
  609. //}
  610. /**
  611. * @brief ADCIntelligentVehicle::keyPressEvent 加/减键进行缩放
  612. * @param event
  613. */
  614. void ADCIntelligentVehicle::keyPressEvent(QKeyEvent *event)
  615. {
  616. switch (event->key()) {
  617. case Qt::Key_Plus: // 放大
  618. myview->zoomIn();
  619. break;
  620. case Qt::Key_Minus: // 缩小
  621. myview->zoomOut();
  622. break;
  623. default:
  624. QMainWindow::keyPressEvent(event);
  625. }
  626. }
  627. /**
  628. * @brief ADCIntelligentVehicle::closeEvent
  629. * @param event
  630. */
  631. void ADCIntelligentVehicle::closeEvent(QCloseEvent *event)
  632. {
  633. QMessageBox::StandardButton button;
  634. button=QMessageBox::question(this,tr("退出程序"),QString(tr("确认退出程序")),QMessageBox::Yes|QMessageBox::No);
  635. if(button==QMessageBox::No)
  636. {
  637. event->ignore(); // 忽略退出信号,程序继续进行
  638. }
  639. else if(button==QMessageBox::Yes)
  640. {
  641. event->accept(); // 接受退出信号,程序退出
  642. }
  643. }
  644. /**
  645. * @brief MyView::wheelEvent 放大/缩小
  646. * @param event
  647. */
  648. void MyView::wheelEvent(QWheelEvent *event)
  649. {
  650. // 滚轮的滚动量
  651. QPoint scrollAmount = event->angleDelta();
  652. // 正值表示滚轮远离使用者(放大),负值表示朝向使用者(缩小)
  653. scrollAmount.y() > 0 ? zoomIn() : zoomOut();
  654. }
  655. /**
  656. * @brief MyView::zoomIn 放大
  657. */
  658. void MyView::zoomIn()
  659. {
  660. scale(1.1, 1.1);
  661. beishu *= 1.1;
  662. centerOn(450, 700 - (200 / beishu));
  663. }
  664. /**
  665. * @brief MyView::zoomOut 缩小
  666. */
  667. void MyView::zoomOut()
  668. {
  669. scale(1 / 1.1, 1 / 1.1);
  670. beishu /= 1.1;
  671. centerOn(450, 700 - (200 / beishu));
  672. }
  673. /**
  674. * @brief ADCIntelligentVehicle::paintEvent 刷新
  675. */
  676. void ADCIntelligentVehicle::paintEvent(QPaintEvent *)
  677. {
  678. if (is_show_enable)
  679. {
  680. // qDebug("enter paint. time1 is %d",mTime.elapsed());
  681. if(fabs(mTime.elapsed() - mnTimeLastUpdatePaint)<100)
  682. {
  683. return;
  684. }
  685. mnTimeLastUpdatePaint = mTime.elapsed();
  686. // qDebug("enter paint. time is %d",mTime.elapsed());
  687. painter->begin(image);
  688. // painter_small->begin(image_small);
  689. // image->fill(QColor(60, 60, 60));//对画布进行填充
  690. image->fill(QColor(220, 220, 220));//对画布进行填充
  691. image_small->fill(QColor(220,220,220));
  692. std::vector<iv::GPSData> navigation_data;
  693. mMutexNavi.lock();
  694. navigation_data = m_navigation_data;
  695. mMutexNavi.unlock();
  696. std::vector<iv::Point2D> myplan,myplan_left,myplan_right;
  697. mMutexPlan.lock();
  698. myplan = m_plan;
  699. mMutexPlan.unlock();
  700. mMutexPlan_left.lock();
  701. myplan_left = m_plan_left;
  702. mMutexPlan_left.unlock();
  703. mMutexPlan_right.lock();
  704. myplan_right = m_plan_right;
  705. mMutexPlan_right.unlock();
  706. // std::cout<<"plan size is "<<myplan.size()<<std::endl;
  707. // std::vector<iv::GPSData> navigation_data = brain->navigation_data;
  708. painter->setRenderHint(QPainter::Antialiasing, true);//设置反锯齿模式,好看一点
  709. painter_small->setRenderHint(QPainter::Antialiasing, true);//设置反锯齿模式,好看一点
  710. int pointx = 450, pointy = 700;//确定坐标轴起点坐标,这里定义(35,280)
  711. // int pointx_small = 450, pointy_small = 700;
  712. // double x0[22000], y0[22000], lng[22000], x1[22000], y1[22000], x2[22000], y2[22000];
  713. double * x0, * y0, * lng, * x1, * y1, * x2, * y2;
  714. std::shared_ptr<double> ptrx0,ptry0,ptrlng,ptrx1,ptry1,ptrx2,ptry2;
  715. int nmapsize = navigation_data.size();
  716. x0 = new double[nmapsize];
  717. y0 = new double[nmapsize];
  718. lng = new double[nmapsize];
  719. x1 = new double[nmapsize];
  720. y1 = new double[nmapsize];
  721. x2 = new double[nmapsize];
  722. y2 = new double[nmapsize];
  723. ptrx0.reset(x0);
  724. ptry0.reset(y0);
  725. ptrlng.reset(lng);
  726. ptrx1.reset(x1);
  727. ptry1.reset(y1);
  728. ptrx2.reset(x2);
  729. ptry2.reset(y2);
  730. double xx = 0, yy = 0;
  731. double sumx = 0, sumy = 0;//, ave_x = 0, ave_y = 0;
  732. int sizeN = navigation_data.size();
  733. //int max_x_pos = 0, min_x_pos = 0, max_y_pos = 0, min_y_pos = 0;
  734. int x_max = 0, y_max = 0;//数组里的最大值
  735. int x_min = 0x3f3f3f3f, y_min = 0x3f3f3f3f;//inf为 #define inf 0x3f3f3f3f
  736. double k1, k2;
  737. QPen pen, penPoint;
  738. //先绘制车位置点及框图
  739. static const QPointF points1[2] = { QPointF(300, 700), QPointF(600, 700) };
  740. static const QPointF points2[2] = { QPointF(450, 0), QPointF(450, 900) };
  741. // static const QPointF points1_small[2] = { QPointF(300, 700), QPointF(600, 700) };
  742. // static const QPointF points2_small[2] = { QPointF(450, 0), QPointF(450, 900) };
  743. penPoint.setColor(Qt::red);
  744. penPoint.setWidth(2);
  745. painter->setPen(penPoint);
  746. // painter_small->setPen(penPoint);
  747. painter->drawPoint(pointx, pointy);
  748. // painter_small->drawPoint(pointx_small,pointy_small);
  749. painter->drawPolyline(points1, 2);
  750. painter->drawPolyline(points2, 2);
  751. // painter_small->drawPolyline(points1_small, 2);
  752. // painter_small->drawPolyline(points2_small, 2);
  753. //路径点的预处理
  754. for (int i = 0; i < sizeN; i++)
  755. {
  756. x0[i] = navigation_data[i]->gps_x;
  757. y0[i] = navigation_data[i]->gps_y;
  758. lng[i] = navigation_data[i]->ins_heading_angle;
  759. sumx = sumx + navigation_data[i]->gps_x;
  760. sumy = sumy + navigation_data[i]->gps_y;
  761. if (x0[i] > x_max) {
  762. x_max = x0[i];
  763. //max_x_pos = i;
  764. }
  765. if (x0[i] < x_min) {
  766. x_min = x0[i];
  767. //min_x_pos = i;
  768. }
  769. if (y0[i] > y_max) {
  770. y_max = y0[i];
  771. //max_y_pos = i;
  772. }
  773. if (y0[i] < y_min) {
  774. y_min = y0[i];
  775. //min_y_pos = i;
  776. }
  777. }
  778. //ave_x = sumx / sizeN;
  779. //ave_y = sumy / sizeN;
  780. //获取到实时 GPS信息,并做路径点的显示更新
  781. if (ServiceCarStatus.location->gps_x == 0)
  782. {
  783. painter->drawText(rect(), Qt::AlignLeft, QString::fromLocal8Bit("等待车辆实时GPS位置信息"));
  784. // painter_small->drawText(rect(), Qt::AlignLeft, QString::fromLocal8Bit("等待车辆实时GPS位置信息"));
  785. }
  786. else
  787. {
  788. x0[0] = ServiceCarStatus.location->gps_x;
  789. y0[0] = ServiceCarStatus.location->gps_y;
  790. // std::cout<<"x = "<<x0[0]<<" y= "<<y0[0]<<std::endl;
  791. lng[0] = ServiceCarStatus.location->ins_heading_angle;
  792. }
  793. //根据标定原点的选取,对路径点进行转化
  794. for (int i = 1; i < sizeN; i++)
  795. {
  796. // if(i == 1)std::cout<<" x1 = "<<x0[i]<<std::endl;
  797. x0[i] = x0[i] - x0[0];
  798. y0[i] = y0[i] - y0[0];
  799. xx = x0[i];
  800. yy = y0[i];
  801. x0[i] = xx * cos(lng[0] * PI / 180) - yy * sin(lng[0] * PI / 180);
  802. y0[i] = xx * sin(lng[0] * PI / 180) + yy * cos(lng[0] * PI / 180);
  803. k1 = sin((90 + (lng[i] - lng[0])) * PI / 180);
  804. k2 = cos((90 + (lng[i] - lng[0])) * PI / 180);
  805. #if 0
  806. x1[i] = x0[i] + k1 * 5;
  807. y1[i] = y0[i] + k2 * 5;
  808. x2[i] = x0[i] - k1 * 5;
  809. y2[i] = y0[i] - k2 * 5;
  810. #else
  811. x1[i] = x0[i] + k1 * 1.75;
  812. y1[i] = y0[i] + k2 * 1.75;
  813. x2[i] = x0[i] - k1 * 1.75;
  814. y2[i] = y0[i] - k2 * 1.75;
  815. #endif
  816. }
  817. // double kx_small = (double)(1200) / (abs(y_max - y_min));//x轴的系数
  818. // double ky_small = (double)(1200) / (abs(y_max - y_min));//y方向的比例系数
  819. double kx = 10;
  820. double ky = 10;
  821. //距离车正前方10m处画一条线
  822. static const QPointF points3[2] = { QPointF(0, 700 - 10 * ky), QPointF(900, 700 - 10 * ky) };
  823. painter->drawPolyline(points3, 2);
  824. //绘制路径点
  825. penPoint.setColor(Qt::black);
  826. penPoint.setWidth(1);
  827. for (int i = 1; i < sizeN - 1; i++)
  828. {
  829. painter->setPen(penPoint);//蓝色的笔,用于标记各个点
  830. // painter_small->setPen(penPoint);//蓝色的笔,用于标记各个点
  831. painter->drawPoint(pointx + x0[i] * kx, pointy - y0[i] * ky);
  832. // painter_small->drawPoint(pointx_small + x0[i] * kx_small, pointy_small - y0[i] * ky_small);
  833. painter->drawPoint(pointx + x1[i] * kx, pointy - y1[i] * ky);
  834. // painter_small->drawPoint(pointx_small + x1[i] * kx_small, pointy_small - y1[i] * ky_small);
  835. painter->drawPoint(pointx + x2[i] * kx, pointy - y2[i] * ky);
  836. // painter_small->drawPoint(pointx_small + x2[i] * kx_small, pointy_small - y2[i] * ky_small);
  837. }
  838. painter->drawPoint(pointx + x0[sizeN - 1] * kx, pointy - y0[sizeN - 1] * ky);//绘制最后一个点
  839. // painter_small->drawPoint(pointx_small + x0[sizeN - 1] * kx_small, pointy_small - y0[sizeN - 1] * ky_small);//绘制最后一个点
  840. penPoint.setColor(Qt::red);
  841. penPoint.setWidth(2);
  842. painter->drawPoint(pointx + x0[0] * kx, pointy - y0[0] * ky);
  843. // painter_small->drawPoint(pointx_small + x0[0] * kx_small, pointy_small - y0[0] * ky_small);
  844. #if 1
  845. // draw plan trace
  846. penPoint.setColor(QColor(187, 255, 255, 100));
  847. penPoint.setWidth(2);
  848. painter->setPen(penPoint);
  849. QPointF tracePoints[myplan.size()];
  850. if(myplan.size()>2)
  851. {
  852. for(int i=0;i<(myplan.size()-1);i++)
  853. {
  854. tracePoints[i].setX((float)(450+myplan[i].x*kx));
  855. tracePoints[i].setY((float)(700-myplan[i].y*ky));
  856. painter->drawLine((float)(450+myplan[i].x*kx),(float)(700-myplan[i].y*ky),
  857. (float)(450+myplan[i+1].x*kx),(float)(700-myplan[i+1].y*ky));
  858. }
  859. }
  860. #endif
  861. #if 1
  862. // penPoint.setColor(Qt::gray);
  863. penPoint.setColor(QColor(187, 255, 255, 100));
  864. penPoint.setWidth(2);
  865. painter->setPen(penPoint);
  866. QPointF tracePoints_left[myplan_left.size()];
  867. if(myplan_left.size()>2)
  868. {
  869. for(int i=0;i<(myplan_left.size()-1);i++)
  870. {
  871. tracePoints_left[i].setX((float)(450+myplan_left[i].x*kx));
  872. tracePoints_left[i].setY((float)(700-myplan_left[i].y*ky));
  873. painter->drawLine((float)(450+myplan_left[i].x*kx),(float)(700-myplan_left[i].y*ky),
  874. (float)(450+myplan_left[i+1].x*kx),(float)(700-myplan_left[i+1].y*ky));
  875. }
  876. }
  877. // penPoint.setColor(Qt::gray);
  878. // penPoint.setWidth(2);
  879. // painter->setPen(penPoint);
  880. QPointF tracePoints_right[myplan_right.size()];
  881. if(myplan_right.size()>2)
  882. {
  883. for(int i=0;i<(myplan_right.size()-1);i++)
  884. {
  885. tracePoints_right[i].setX((float)(450+myplan_right[i].x*kx));
  886. tracePoints_right[i].setY((float)(700-myplan_right[i].y*ky));
  887. painter->drawLine((float)(450+myplan_right[i].x*kx),(float)(700-myplan_right[i].y*ky),
  888. (float)(450+myplan_right[i+1].x*kx),(float)(700-myplan_right[i+1].y*ky));
  889. }
  890. }
  891. #endif
  892. // painter->drawPolyline(tracePoints,myplan.size());
  893. // draw plan trace end
  894. /////////////////////////////////////apollo add car icon 20200409
  895. QPixmap pix;
  896. //pix.load("car.png");
  897. pix.load(":/ADCIntelligentVehicle/car1.png");
  898. painter->drawPixmap(435,667,30,67,pix);
  899. // painter_small->drawPixmap(442,683,16,34,pix);
  900. ///////////////////////////////////////////////////////////////////
  901. penPoint.setColor(Qt::blue);
  902. penPoint.setWidth(3);
  903. painter->setPen(penPoint);
  904. QFont font;
  905. font.setFamily("Microsoft YaHei");
  906. font.setPointSize(50);
  907. font.setItalic(true);
  908. painter->setFont(font);
  909. //////////////////////////////////////
  910. // //
  911. // 显示毫米波雷达和激光雷达的信息 //
  912. // //
  913. //////////////////////////////////////
  914. if(ui->checkBox_8->isChecked())
  915. {
  916. painter->setPen(QPen(Qt::black, 2));
  917. painter->setBrush(Qt::blue);
  918. QFont esr_font("Microsoft YaHei", 10, 75); //第一个属性是字体(微软雅黑),第二个是大小,第三个是加粗(权重是75)
  919. painter->setFont(esr_font);
  920. char coordinate_ear[100];
  921. iv::radar::radarobjectarray xradararray;
  922. if(mbradarUpdate)
  923. {
  924. mMutexRadar.lock();
  925. xradararray.CopyFrom(mradararray);
  926. mMutexRadar.unlock();
  927. for (int a = 0; a < xradararray.obj_size(); a++)
  928. {
  929. if (xradararray.obj(a).bvalid())
  930. {
  931. painter->drawEllipse(xradararray.obj(a).x() * 10 + 450, -((xradararray.obj(a).y() + ServiceCarStatus.esr_y_offset) * 10) + 700, 10, 10);
  932. sprintf(coordinate_ear, "(%d, %d)", (int)xradararray.obj(a).x(), (int)xradararray.obj(a).y());
  933. painter->drawText(xradararray.obj(a).x() * 10 + 450, -((xradararray.obj(a).y() + ServiceCarStatus.esr_y_offset ) * 10) + 700, QString(coordinate_ear));
  934. }
  935. }
  936. // mbradarUpdate = false;
  937. }
  938. }
  939. if(ui->checkBox_9->isChecked())
  940. {
  941. ServiceLidar.copylidarto(Lidar_read); //激光雷达障碍物
  942. ServiceLidar.copylidarobsto(Lidar_obsread);
  943. painter->setPen(QColor(255, 0, 0));
  944. for (unsigned int x = 0; x < Lidar_read->size(); x++)
  945. {
  946. //painter->drawPoint(((*Lidar_read)[x].nomal_x) * 10 + 450, -(*Lidar_read)[x].nomal_y * 10 + 700);
  947. }
  948. painter->setPen(QColor(255,0,0));
  949. for (unsigned int x = 0; x < Lidar_obsread->size(); x++)
  950. {
  951. painter->drawPoint(((*Lidar_obsread)[x].nomal_x) * 10 + 450, -((*Lidar_obsread)[x].nomal_y + ServiceCarStatus.lidar_y_offset) * 10 + 700);
  952. }
  953. }
  954. //////////////////////////////////////
  955. // //
  956. // 显示融合的信息 //
  957. // //
  958. //////////////////////////////////////
  959. if(ui->checkBox_10->isChecked())
  960. {
  961. painter->setPen(QColor(255,0,0));
  962. iv::fusion::fusionobjectarray xfusionarray;
  963. if(mbfusionUpdate)
  964. {
  965. mMutexFusion.lock();
  966. xfusionarray.CopyFrom(mfusionarray);
  967. mMutexFusion.unlock();
  968. for(int a = 0; a < xfusionarray.obj_size(); a++)
  969. {
  970. for(int b = 0; b < xfusionarray.obj(a).nomal_centroid_size(); b++)
  971. {
  972. painter->drawPoint((xfusionarray.obj(a).nomal_centroid(b).nomal_x())*10 + 450, -(xfusionarray.obj(a).nomal_centroid(b).nomal_y() + ServiceCarStatus.lidar_y_offset)*10 + 700);
  973. }
  974. }
  975. }
  976. }
  977. painter->end();
  978. // painter_small->end();
  979. scene->clear();
  980. // scene_small->clear();
  981. scene->addPixmap(QPixmap::fromImage(*image));
  982. // scene_small->addPixmap(QPixmap::fromImage(*image_small));
  983. myview->setScene(scene);
  984. // myview_small->setScene(scene_small);
  985. myview->show();
  986. // myview_small->show();
  987. navigation_data.clear();
  988. }
  989. }
  990. /**
  991. * @brief ADCIntelligentVehicle::on_listWidget_clicked
  992. */
  993. void ADCIntelligentVehicle::on_listWidget_clicked()
  994. {
  995. int currentRow=ui->listWidget->currentRow(); //currentRow()获取当前行号
  996. if(currentRow==0) //点击第一切换到第一页
  997. {
  998. ui->stackedWidget->setCurrentIndex(0);//为堆栈窗体切换到当前索引
  999. }
  1000. else if(currentRow==1)
  1001. {
  1002. ui->stackedWidget->setCurrentIndex(1);
  1003. }
  1004. else if(currentRow==2)
  1005. {
  1006. ui->stackedWidget->setCurrentIndex(2);
  1007. }
  1008. else
  1009. {
  1010. ui->stackedWidget->setCurrentIndex(0);
  1011. }
  1012. }
  1013. /**
  1014. * @brief ADCIntelligentVehicle::UpdatePlanTrace
  1015. * @param strdata
  1016. * @param nSize
  1017. * @param index
  1018. * @param dt
  1019. * @param strmemname
  1020. */
  1021. void ADCIntelligentVehicle::UpdatePlanTrace(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
  1022. {
  1023. mMutexPlan.lock();
  1024. m_plan.clear();
  1025. int nplansize = nSize/sizeof(iv::Point2D);
  1026. int npsize = sizeof(iv::Point2D);
  1027. int i;
  1028. for(i=0;i<nplansize;i++)
  1029. {
  1030. iv::Point2D x;
  1031. memcpy(&x,strdata + i*npsize,npsize);
  1032. m_plan.push_back(x);
  1033. }
  1034. mMutexPlan.unlock();
  1035. }
  1036. void ADCIntelligentVehicle::UpdatePlanTrace_left(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
  1037. {
  1038. mMutexPlan_left.lock();
  1039. m_plan_left.clear();
  1040. int nplansize = nSize/sizeof(iv::Point2D);
  1041. if(nplansize < 1)
  1042. std::cout<<"UpdatePlanTrace_left size is 0................. "<<std::endl;
  1043. // return;
  1044. int npsize = sizeof(iv::Point2D);
  1045. int i;
  1046. for(i=0;i<nplansize;i++)
  1047. {
  1048. iv::Point2D x;
  1049. memcpy(&x,strdata + i*npsize,npsize);
  1050. m_plan_left.push_back(x);
  1051. }
  1052. mMutexPlan_left.unlock();
  1053. }
  1054. void ADCIntelligentVehicle::UpdatePlanTrace_right(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
  1055. {
  1056. mMutexPlan_right.lock();
  1057. m_plan_right.clear();
  1058. int nplansize = nSize/sizeof(iv::Point2D);
  1059. if(nplansize < 1)
  1060. std::cout<<"UpdatePlanTrace_right size is 0................. "<<std::endl;
  1061. int npsize = sizeof(iv::Point2D);
  1062. int i;
  1063. for(i=0;i<nplansize;i++)
  1064. {
  1065. iv::Point2D x;
  1066. memcpy(&x,strdata + i*npsize,npsize);
  1067. m_plan_right.push_back(x);
  1068. }
  1069. mMutexPlan_right.unlock();
  1070. }
  1071. void ADCIntelligentVehicle::UpdateFusion(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
  1072. {
  1073. iv::fusion::fusionobjectarray xfusionarray;
  1074. if(!xfusionarray.ParseFromArray(strdata,nSize))
  1075. {
  1076. gIvlog->warn("ADCIntelligentVehicle::UpdateFusion Parse Error.");
  1077. return;
  1078. }
  1079. mMutexFusion.lock();
  1080. mfusionarray.CopyFrom(xfusionarray);
  1081. mbfusionUpdate = true;
  1082. mMutexFusion.unlock();
  1083. }
  1084. /**
  1085. * @brief ADCIntelligentVehicle::UpdateMap
  1086. * @param strdata
  1087. * @param nSize
  1088. * @param index
  1089. * @param dt
  1090. * @param strmemname
  1091. */
  1092. void ADCIntelligentVehicle::UpdateMap(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
  1093. {
  1094. // std::cout<<"update map "<<std::endl;
  1095. int gpsunitsize = sizeof(iv::GPS_INS);
  1096. int nMapSize = nSize/gpsunitsize;
  1097. // std::cout<<"map size is "<<nMapSize<<std::endl;
  1098. if(nMapSize < 1)return;
  1099. bool bUpdate = false;
  1100. if(nMapSize != m_navigation_data.size())
  1101. {
  1102. bUpdate = true;
  1103. }
  1104. else
  1105. {
  1106. iv::GPS_INS * p = (iv::GPS_INS *)strdata;
  1107. if((p->gps_lat == m_navigation_data.at(0)->gps_lat)&&(p->ins_heading_angle == m_navigation_data.at(0)->ins_heading_angle))
  1108. {
  1109. // qDebug("same map");
  1110. bUpdate = false;
  1111. }
  1112. else
  1113. {
  1114. bUpdate = true;
  1115. }
  1116. }
  1117. if(bUpdate)
  1118. {
  1119. int i;
  1120. mMutexNavi.lock();
  1121. m_navigation_data.clear();
  1122. for(i=0;i<nMapSize;i++)
  1123. {
  1124. iv::GPS_INS x;
  1125. memcpy(&x,strdata + i*gpsunitsize,gpsunitsize);
  1126. iv::GPSData data(new iv::GPS_INS);
  1127. *data = x;
  1128. m_navigation_data.push_back(data);
  1129. }
  1130. mMutexNavi.unlock();
  1131. if(m_navigation_data.size()>0)
  1132. {
  1133. mDataToUI.mInfo.is_mapLoad = 1;
  1134. }
  1135. else
  1136. {
  1137. mDataToUI.mInfo.is_mapLoad = 0;
  1138. }
  1139. }
  1140. else
  1141. {
  1142. // qDebug("not need update");
  1143. }
  1144. }
  1145. //=======================zhaobo0904
  1146. #define PI 3.14159265358979
  1147. /**
  1148. * @brief GaussProjCal
  1149. * @param lon
  1150. * @param lat
  1151. * @param X
  1152. * @param Y
  1153. */
  1154. /*
  1155. void GaussProjCal(double lon, double lat, double *X, double *Y)
  1156. {
  1157. // 1975 年国际椭球体长半轴 a, 第一离心率 e2, 第二离心率 ep2
  1158. double a = 6378140.0;
  1159. double e2 = 0.006694384999588;
  1160. double ep2 = e2/(1-e2);
  1161. // 原点所在经度
  1162. double lon_origin = 6.0*int(lon/6) + 3.0;
  1163. lon_origin *= PI / 180.0;
  1164. double k0 = 0.9996;
  1165. // 角度转弧度
  1166. double lat1 = lat * PI / 180.0;
  1167. double lon1 = lon * PI / 180.0;
  1168. // 经线在该点处的曲率半径,
  1169. double N = a / sqrt(1 - e2*sin(lat1)*sin(lat1));
  1170. // 赤道到该点的经线长度近似值 M, 使用泰勒展开逐项积分然后取前四项.
  1171. // 这个近似值是将 N 作为纬度 \phi 的函数展开为泰勒计数, 然后在区间 [0, lat1] 上积分得到的.
  1172. // 首先计算前四项的系数 a1~a4.
  1173. double a1 = 1 - e2/4 - (3*e2*e2)/64 - (5*e2*e2*e2)/256;
  1174. double a2 = (3*e2)/8 + (3*e2*e2)/32 + (45*e2*e2*e2)/1024;
  1175. double a3 = (15*e2*e2)/256 + (45*e2*e2*e2)/1024;
  1176. double a4 = (35*e2*e2*e2)/3072;
  1177. double M = a * (a1*lat1 - a2*sin(2*lat1) + a3*sin(4*lat1) - a4*sin(6*lat1));
  1178. // 辅助量
  1179. double T = tan(lat1)*tan(lat1);
  1180. double C = ep2*cos(lat1)*cos(lat1);
  1181. double A = (lon1 - lon_origin)*cos(lat1);
  1182. *X = 500000.0 + k0 * N * (A + (1 - T + C)*(A*A*A)/6 + (5 - 18*T + T*T + 72*C - 58*ep2)*(A*A*A*A*A)/120);
  1183. *Y = M + N * tan(lat1) * ((A*A)/2 +
  1184. (5 - T + 9*C + 4*C*C)*(A*A*A*A)/24 +
  1185. (61 - 58*T + T*T + 600*C - 330*ep2)*(A*A*A*A*A*A)/720);
  1186. *Y *= k0;
  1187. return;
  1188. }
  1189. */
  1190. //高斯投影由经纬度(Unit:DD)反算大地坐标(含带号,Unit:Metres)
  1191. void GaussProjCal(double longitude, double latitude, double *X, double *Y)
  1192. {
  1193. int ProjNo = 0; int ZoneWide; ////带宽
  1194. double longitude1, latitude1, longitude0, latitude0, X0, Y0, xval, yval;
  1195. double a, f, e2, ee, NN, T, C, A, M, iPI;
  1196. iPI = 0.0174532925199433; ////3.1415926535898/180.0;
  1197. ZoneWide = 6; ////6度带宽
  1198. a = 6378245.0; f = 1.0 / 298.3; //54年北京坐标系参数
  1199. ////a=6378140.0; f=1/298.257; //80年西安坐标系参数
  1200. ProjNo = (int)(longitude / ZoneWide);
  1201. longitude0 = ProjNo * ZoneWide + ZoneWide / 2;
  1202. longitude0 = longitude0 * iPI;
  1203. latitude0 = 0;
  1204. longitude1 = longitude * iPI; //经度转换为弧度
  1205. latitude1 = latitude * iPI; //纬度转换为弧度
  1206. e2 = 2 * f - f * f;
  1207. ee = e2 * (1.0 - e2);
  1208. NN = a / sqrt(1.0 - e2 * sin(latitude1)*sin(latitude1));
  1209. T = tan(latitude1)*tan(latitude1);
  1210. C = ee * cos(latitude1)*cos(latitude1);
  1211. A = (longitude1 - longitude0)*cos(latitude1);
  1212. M = a * ((1 - e2 / 4 - 3 * e2*e2 / 64 - 5 * e2*e2*e2 / 256)*latitude1 - (3 * e2 / 8 + 3 * e2*e2 / 32 + 45 * e2*e2
  1213. *e2 / 1024)*sin(2 * latitude1)
  1214. + (15 * e2*e2 / 256 + 45 * e2*e2*e2 / 1024)*sin(4 * latitude1) - (35 * e2*e2*e2 / 3072)*sin(6 * latitude1));
  1215. xval = NN * (A + (1 - T + C)*A*A*A / 6 + (5 - 18 * T + T * T + 72 * C - 58 * ee)*A*A*A*A*A / 120);
  1216. yval = M + NN * tan(latitude1)*(A*A / 2 + (5 - T + 9 * C + 4 * C*C)*A*A*A*A / 24
  1217. + (61 - 58 * T + T * T + 600 * C - 330 * ee)*A*A*A*A*A*A / 720);
  1218. X0 = 1000000L * (ProjNo + 1) + 500000L;
  1219. Y0 = 0;
  1220. xval = xval + X0; yval = yval + Y0;
  1221. *X = xval;
  1222. *Y = yval;
  1223. }
  1224. //高斯投影由大地坐标(Unit:Metres)反算经纬度(Unit:DD)
  1225. void GaussProjInvCal(double X, double Y, double *longitude, double *latitude)
  1226. {
  1227. int ProjNo; int ZoneWide; ////带宽
  1228. double longitude1, latitude1, longitude0, latitude0, X0, Y0, xval, yval;
  1229. double e1, e2, f, a, ee, NN, T, C, M, D, R, u, fai, iPI;
  1230. iPI = 0.0174532925199433; ////3.1415926535898/180.0;
  1231. a = 6378245.0; f = 1.0 / 298.3; //54年北京坐标系参数
  1232. ////a=6378140.0; f=1/298.257; //80年西安坐标系参数
  1233. ZoneWide = 6; ////6度带宽
  1234. ProjNo = (int)(X / 1000000L); //查找带号
  1235. longitude0 = (ProjNo - 1) * ZoneWide + ZoneWide / 2;
  1236. longitude0 = longitude0 * iPI; //中央经线
  1237. X0 = ProjNo * 1000000L + 500000L;
  1238. Y0 = 0;
  1239. xval = X - X0; yval = Y - Y0; //带内大地坐标
  1240. e2 = 2 * f - f * f;
  1241. e1 = (1.0 - sqrt(1 - e2)) / (1.0 + sqrt(1 - e2));
  1242. ee = e2 / (1 - e2);
  1243. M = yval;
  1244. u = M / (a*(1 - e2 / 4 - 3 * e2*e2 / 64 - 5 * e2*e2*e2 / 256));
  1245. fai = u + (3 * e1 / 2 - 27 * e1*e1*e1 / 32)*sin(2 * u) + (21 * e1*e1 / 16 - 55 * e1*e1*e1*e1 / 32)*sin(
  1246. 4 * u)
  1247. + (151 * e1*e1*e1 / 96)*sin(6 * u) + (1097 * e1*e1*e1*e1 / 512)*sin(8 * u);
  1248. C = ee * cos(fai)*cos(fai);
  1249. T = tan(fai)*tan(fai);
  1250. NN = a / sqrt(1.0 - e2 * sin(fai)*sin(fai));
  1251. R = a * (1 - e2) / sqrt((1 - e2 * sin(fai)*sin(fai))*(1 - e2 * sin(fai)*sin(fai))*(1 - e2 * sin
  1252. (fai)*sin(fai)));
  1253. D = xval / NN;
  1254. //计算经度(Longitude) 纬度(Latitude)
  1255. longitude1 = longitude0 + (D - (1 + 2 * T + C)*D*D*D / 6 + (5 - 2 * C + 28 * T - 3 * C*C + 8 * ee + 24 * T*T)*D
  1256. *D*D*D*D / 120) / cos(fai);
  1257. latitude1 = fai - (NN*tan(fai) / R)*(D*D / 2 - (5 + 3 * T + 10 * C - 4 * C*C - 9 * ee)*D*D*D*D / 24
  1258. + (61 + 90 * T + 298 * C + 45 * T*T - 256 * ee - 3 * C*C)*D*D*D*D*D*D / 720);
  1259. //转换为度 DD
  1260. *longitude = longitude1 / iPI;
  1261. *latitude = latitude1 / iPI;
  1262. }
  1263. //==========================================================
  1264. /**
  1265. * @brief ADCIntelligentVehicle::UpdateGPSIMU
  1266. * @param strdata
  1267. * @param nSize
  1268. * @param index
  1269. * @param dt
  1270. * @param strmemname
  1271. */
  1272. void ADCIntelligentVehicle::UpdateGPSIMU(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
  1273. {
  1274. iv::gps::gpsimu xgpsimu;
  1275. if(!xgpsimu.ParseFromArray(strdata,nSize))
  1276. {
  1277. gIvlog->warn("ADCIntelligentVehicle::UpdateGPSIMU parse error. nSize is %d",nSize);
  1278. return;
  1279. }
  1280. iv::GPSData data(new iv::GPS_INS);
  1281. data->gps_lat = xgpsimu.lat();
  1282. data->gps_lng = xgpsimu.lon();
  1283. data->ins_heading_angle = xgpsimu.heading();
  1284. data->rtk_status = xgpsimu.rtk_state();
  1285. data->ins_status = xgpsimu.ins_state();
  1286. data->vel_D = xgpsimu.vd(); //地向速度,单位(米/秒)
  1287. data->vel_E = xgpsimu.ve(); //东向速度,单位(米/秒)
  1288. data->vel_N = xgpsimu.vn(); //北向速度,单位(米/秒)
  1289. GaussProjCal(data->gps_lng,data->gps_lat,&data->gps_x,&data->gps_y);
  1290. ServiceCarStatus.mRTKStatus = data->rtk_status;
  1291. ServiceCarStatus.speed = data->speed;
  1292. ServiceCarStatus.location->gps_lat = data->gps_lat;
  1293. ServiceCarStatus.location->gps_lng = data->gps_lng;
  1294. ServiceCarStatus.location->ins_heading_angle = data->ins_heading_angle;
  1295. ServiceCarStatus.location->gps_x = data->gps_x;
  1296. ServiceCarStatus.location->gps_y = data->gps_y;
  1297. ServiceCarStatus.location->rtk_status = data->rtk_status;
  1298. ServiceCarStatus.location->ins_status = data->ins_status;
  1299. ServiceCarStatus.speed = sqrt(pow(data->vel_E,2)+pow(data->vel_N,2)) * 3.6; //double pow(double x, double y) 返回 x 的 y 次幂,即 xy。
  1300. mnTimeUpdateGPS = mTimeState.elapsed();
  1301. }
  1302. /**
  1303. * @brief ADCIntelligentVehicle::UpdateRADAR
  1304. * @param strdata
  1305. * @param nSize
  1306. * @param index
  1307. * @param dt
  1308. * @param strmemname
  1309. */
  1310. void ADCIntelligentVehicle::UpdateRADAR(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
  1311. {
  1312. static qint64 oldrecvtime;
  1313. iv::radar::radarobjectarray xradararray;
  1314. if(!xradararray.ParseFromArray(strdata,nSize))
  1315. {
  1316. gIvlog->warn("ADCIntelligentVehicle::UpdateRADAR Parse Error.");
  1317. return;
  1318. }
  1319. // gIvlog->verbose("radar time is %ld",QDateTime::currentMSecsSinceEpoch());
  1320. if((QDateTime::currentMSecsSinceEpoch() - oldrecvtime)>100)
  1321. {
  1322. gIvlog->warn("radar interval is more than 100ms. value is %ld",QDateTime::currentMSecsSinceEpoch() - oldrecvtime);
  1323. }
  1324. oldrecvtime = QDateTime::currentMSecsSinceEpoch();
  1325. mMutexRadar.lock();
  1326. mradararray.CopyFrom(xradararray);
  1327. mbradarUpdate = true;
  1328. mMutexRadar.unlock();
  1329. // int i;
  1330. // for(i=0;i<64;i++)
  1331. // {
  1332. // iv::ObstacleBasic x;
  1333. // memcpy(&x,pdata + i*sizeof(iv::ObstacleBasic),sizeof(iv::ObstacleBasic));
  1334. // ServiceCarStatus.obs_radar[i] = x;
  1335. // }
  1336. ServiceCarStatus.mRadarS = 10;
  1337. // mnTimeUpdateRadar = mTimeState.elapsed();
  1338. // mnTimeUpdateCANState = mTimeState.elapsed();
  1339. }
  1340. /**
  1341. * @brief ADCIntelligentVehicle::UpdateCANState
  1342. * @param pdata
  1343. * @param ndatasize
  1344. */
  1345. void ADCIntelligentVehicle::UpdateCANState(const char *pdata, const int ndatasize)
  1346. {
  1347. iv::canstate::canstate recCanstate;
  1348. if(!recCanstate.ParseFromArray(pdata, ndatasize))
  1349. {
  1350. gIvlog->warn("ADCIntelligentVehicle::updateCanstate error");
  1351. return;
  1352. }
  1353. // if(ndatasize<sizeof(iv::can_state))return;
  1354. // char ccanstate[ndatasize];
  1355. // memcpy(ccanstate,pdata,4);
  1356. #if 1
  1357. if(recCanstate.b_canstate())
  1358. {
  1359. // gIvlog->debug("UpdateCANState<success>");
  1360. mDataToUI.mInfo.is_initSuccess = 1;
  1361. }
  1362. else
  1363. {
  1364. // gIvlog->debug("UpdateCANState<failed>size %d %s ");
  1365. mDataToUI.mInfo.is_initSuccess = 0;
  1366. }
  1367. #endif
  1368. // iv::can_state x;
  1369. // memcpy(&x,pdata,sizeof(iv::can_state));
  1370. // if(x.mbCANOpen)
  1371. // {
  1372. // mDataToUI.mInfo.is_initSuccess = 1;
  1373. // }
  1374. // else
  1375. // {
  1376. // mDataToUI.mInfo.is_initSuccess = 0;
  1377. // }
  1378. }
  1379. /**
  1380. * @brief ADCIntelligentVehicle::UpdateDecition
  1381. * @param strdata
  1382. * @param nSize
  1383. * @param index
  1384. * @param dt
  1385. * @param strmemname
  1386. */
  1387. void ADCIntelligentVehicle::UpdateDecition(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
  1388. {
  1389. iv::brain::decition xdecition;
  1390. if(!xdecition.ParseFromArray(strdata,nSize))
  1391. {
  1392. gIvlog->warn("ADCIntelligentVehicle::UpdateDecition parse errror. nSize is %d",nSize);
  1393. return;
  1394. }
  1395. //ServiceCarStatus.mfAcc = xdecition.accelerator(); //
  1396. ServiceCarStatus.mfAcc = xdecition.torque(); //
  1397. ServiceCarStatus.mfBrake = xdecition.brake();
  1398. ServiceCarStatus.mfWheel = xdecition.wheelangle();
  1399. ServiceCarStatus.mfttc = xdecition.ttc();
  1400. mnTimeUpdateDecition = mTimeState.elapsed();
  1401. }
  1402. /**
  1403. * @brief ADCIntelligentVehicle::UpdateVehicleState
  1404. * @param strdata
  1405. * @param nSize
  1406. * @param index
  1407. * @param dt
  1408. * @param strmemname
  1409. */
  1410. void ADCIntelligentVehicle::UpdateVehicleState(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
  1411. {
  1412. iv::brain::brainstate xbrainstate;
  1413. if(!xbrainstate.ParseFromArray(strdata,nSize))
  1414. {
  1415. gIvlog->warn("ADCIntelligentVehicle::UpdateVehicleState parse error,nSize is %d ",nSize);
  1416. return;
  1417. }
  1418. ServiceCarStatus.bocheEnable = xbrainstate.mbbocheenable();
  1419. ServiceCarStatus.mObs = xbrainstate.mfobs();
  1420. ServiceCarStatus.mLidarObs = xbrainstate.mflidarobs();
  1421. ServiceCarStatus.mRadarObs = xbrainstate.mfradarobs();
  1422. mbBrainRunning = xbrainstate.mbbrainrunning();
  1423. ServiceCarStatus.mbBrainCtring = xbrainstate.mbbrainrunning();
  1424. mdecition_period = xbrainstate.decision_period();
  1425. mnTimeUpdateVS = mTimeState.elapsed();
  1426. }
  1427. /**
  1428. * @brief ADCIntelligentVehicle::UpdateOBS
  1429. * @param lidar_obs
  1430. */
  1431. void ADCIntelligentVehicle::UpdateOBS(std::shared_ptr<std::vector<iv::ObstacleBasic> > lidar_obs)
  1432. {
  1433. iv::ObsLiDAR _obs_grid_ = boost::shared_ptr<std::vector<iv::ObstacleBasic>>(new std::vector<iv::ObstacleBasic>);
  1434. int i;
  1435. int nSize = lidar_obs->size();
  1436. for(i=0;i<nSize;i++)
  1437. _obs_grid_->push_back(lidar_obs->at(i));
  1438. ServiceLidar.copyfromlidarobs(_obs_grid_);
  1439. ServiceCarStatus.mLidarS = 10;
  1440. }
  1441. void ADCIntelligentVehicle::UpdateV2xStEn(unsigned int enable)
  1442. {
  1443. iv::v2x::v2xStEn x;
  1444. x.set_v2xsten(enable);
  1445. int nsize = x.ByteSize();
  1446. char * str = new char[nsize];
  1447. if(x.SerializeToArray(str,nsize))
  1448. {
  1449. iv::modulecomm::ModuleSendMsg(mp_v2xStSend,str,nsize);
  1450. }
  1451. else
  1452. {
  1453. gIvlog->error("hmi","send enable st error");
  1454. }
  1455. delete str;
  1456. }
  1457. /**
  1458. * @brief ADCIntelligentVehicle::ShareHMIMsg
  1459. * @param xhmi
  1460. */
  1461. void ADCIntelligentVehicle::ShareHMIMsg(iv::hmi::HMIBasic xhmi)
  1462. {
  1463. iv::hmi::hmimsg xhmimsg;
  1464. xhmimsg.set_mbpause(xhmi.mbPause);
  1465. xhmimsg.set_mbbusmode(xhmi.mbbusmode);
  1466. xhmimsg.set_mbbochemode(xhmi.mbBocheMode);
  1467. xhmimsg.set_mbchemen(xhmi.mbchemen);
  1468. xhmimsg.set_mbjinguang(xhmi.mbjinguang);
  1469. xhmimsg.set_mbyuanguang(xhmi.mbyuanguang);
  1470. int nsize = xhmimsg.ByteSize();
  1471. char * str = new char[nsize];
  1472. std::shared_ptr<char> pstr;
  1473. pstr.reset(str); //将就对象的引用计数减1(当然,如果发现引用计数为0时,则析构旧对象),然后将新对象的指针交给智能指针保管。这样做可以省略了delete的过程。
  1474. if(!xhmimsg.SerializeToArray(str,nsize))
  1475. {
  1476. std::cout<<"ADCIntelligentVehicle::ShareHMIMsg serialize error."<<std::endl;
  1477. mpivlog->error("ADCIntelligentVehicle::ShareHMIMsg serialize error.");
  1478. return;
  1479. }
  1480. iv::modulecomm::ModuleSendMsg(mpaHMI,str,nsize);
  1481. }
  1482. void ADCIntelligentVehicle::UpdateChassis(const char *strdata, const unsigned int nSize, const unsigned int index, const QDateTime *dt, const char *strmemname)
  1483. {
  1484. iv::chassis xchassis;
  1485. static int ncount = 0;
  1486. if(!xchassis.ParseFromArray(strdata,nSize))
  1487. {
  1488. std::cout<<"iv::decition::BrainDecition::UpdateChassis ParseFrom Array Error."<<std::endl;
  1489. return;
  1490. }
  1491. if((xchassis.has_epsmode())&&(xchassis.epsmode() == 0))
  1492. {
  1493. ServiceCarStatus.mbRunPause = true;
  1494. }
  1495. if((xchassis.has_soc()))
  1496. {
  1497. mfSOC = xchassis.soc();
  1498. }
  1499. }
  1500. void ADCIntelligentVehicle::onTimerManual()
  1501. {
  1502. // if(myview->mPressKeys.count() == 0)return;
  1503. if(mbManual == false)
  1504. {
  1505. if(myview->mPressKeys.contains(Qt::Key_J))
  1506. {
  1507. mbManual = true;
  1508. }
  1509. }
  1510. if(mbManual == true)
  1511. {
  1512. if(myview->mPressKeys.contains(Qt::Key_K))
  1513. {
  1514. mbManual = false;
  1515. }
  1516. }
  1517. if(mbManual == false)return;
  1518. int timediff = mManualTime.elapsed() - mnLastManualTime;
  1519. mnLastManualTime = mManualTime.elapsed();
  1520. if(myview->mPressKeys.contains(Qt::Key_W))
  1521. {
  1522. if(mnCtrlValue[0]<1000)mnCtrlValue[0] = mnCtrlValue[0] + 5 * timediff /20;
  1523. }
  1524. if(myview->mPressKeys.contains(Qt::Key_S))
  1525. {
  1526. mnCtrlValue[0] = 0;
  1527. if(mnCtrlValue[1]<990) mnCtrlValue[1] = mnCtrlValue[1] + 10* timediff /20;
  1528. }
  1529. else
  1530. {
  1531. mnCtrlValue[1] = 0;
  1532. }
  1533. if(myview->mPressKeys.contains(Qt::Key_A))
  1534. {
  1535. if(mnCtrlValue[2]<500)mnCtrlValue[2] = mnCtrlValue[2] + 3* timediff /20;
  1536. }
  1537. if(myview->mPressKeys.contains(Qt::Key_D))
  1538. {
  1539. if(mnCtrlValue[2]>-500)mnCtrlValue[2] = mnCtrlValue[2] - 3* timediff /20;
  1540. }
  1541. iv::modulecomm::ModuleSendMsg(mpManualCtrl,(char *)mnCtrlValue,3*sizeof(int));
  1542. }
  1543. void ADCIntelligentVehicle::onCtrlManual(bool bCtrl)
  1544. {
  1545. mbManual = bCtrl;
  1546. if(bCtrl)
  1547. {
  1548. mTimerManual->start(10);
  1549. mManualTime.start();
  1550. mnLastManualTime = mManualTime.elapsed();
  1551. }
  1552. else
  1553. {
  1554. mTimerManual->stop();
  1555. mnCtrlValue[0] = 0; mnCtrlValue[1] = 0; mnCtrlValue[2] = 0;
  1556. }
  1557. }
  1558. void ADCIntelligentVehicle::on_pb_v2xEn_clicked()
  1559. {
  1560. qDebug()<<mv2xStEn;
  1561. if(mv2xStEn){
  1562. ui->pb_v2xEn->setText("云平台控制:关");
  1563. mv2xStEn = 0;
  1564. }
  1565. else{
  1566. ui->pb_v2xEn->setText("云平台控制:开");
  1567. mv2xStEn = 1;
  1568. }
  1569. gIvlog->info("hmi","v2x enable:%d", mv2xStEn);
  1570. UpdateV2xStEn(mv2xStEn);
  1571. }
  1572. void ADCIntelligentVehicle::shareMapReqMsg()
  1573. {
  1574. iv::map::mapreq x;
  1575. x.set_maptype(1);
  1576. int nsize = x.ByteSize();
  1577. char * str = new char[nsize];
  1578. if(x.SerializeToArray(str,nsize))
  1579. {
  1580. iv::modulecomm::ModuleSendMsg(mpamapreq,str,nsize);
  1581. }
  1582. else
  1583. {
  1584. std::cout<<"iv::map::mapreq serialize error."<<std::endl;
  1585. }
  1586. std::cout<<"iv::map::mapreq serialize OK."<<std::endl;
  1587. delete str;
  1588. }
  1589. void ADCIntelligentVehicle::UpdateVbox(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
  1590. {
  1591. iv::vbox::vbox xvbox;
  1592. if(!xvbox.ParseFromArray(strdata,nSize))
  1593. {
  1594. gIvlog->warn("ADCIntelligentVehicle::UpdateVbox parse errror. nSize is %d",nSize);
  1595. return;
  1596. }
  1597. ServiceCarStatus.st_straight = xvbox.st_straight();
  1598. ServiceCarStatus.st_left = xvbox.st_left();
  1599. ServiceCarStatus.st_right = xvbox.st_right();
  1600. ServiceCarStatus.st_turn = xvbox.st_turn();
  1601. ServiceCarStatus.time_straight = xvbox.time_straight();
  1602. ServiceCarStatus.time_left = xvbox.time_left();
  1603. ServiceCarStatus.time_right = xvbox.time_right();
  1604. ServiceCarStatus.time_turn = xvbox.time_turn();
  1605. }