ADCIntelligentVehicle.cpp 80 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288
  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. look_decition = new Look_decition;
  239. mobileye_info = new Mobileye_info;
  240. timer = new QTimer(this);
  241. connect(timer, SIGNAL(timeout()), this, SLOT(timeoutslot()));//timeoutslot()为自定义槽
  242. timer->start(100);
  243. Lidar_obsread = boost::shared_ptr<std::vector<iv::ObstacleBasic>>(new std::vector<iv::ObstacleBasic>);
  244. Lidar_read = boost::shared_ptr<std::vector<iv::ObstacleBasic>>(new std::vector<iv::ObstacleBasic>);
  245. mDataToUI.mHead.type = 1;
  246. mDataToUI.mInfo.accelerate = 0;
  247. mDataToUI.mInfo.brake = 0;
  248. mDataToUI.mInfo.gps_lat = 0;
  249. mDataToUI.mInfo.gps_lng = 0;
  250. mDataToUI.mInfo.is_mapLoad = 0;
  251. mDataToUI.mInfo.is_initSuccess = 0;
  252. mDataToUI.mInfo.is_run = 0;
  253. mDataToUI.mInfo.speed = 0;
  254. msockrecv.bind(QHostAddress::Any,9998);//绑定端口
  255. connect(&msockrecv,SIGNAL(readyRead()),this,SLOT(onRecvUDP())); //接收来自PAD的UDP数据报 readyRead():socket读取缓冲区有数据时发送此信号,在此信号的槽函数里读取缓冲区的数据。
  256. ServiceCarStatus.speed = 0.0;
  257. mTimerState.setTimerType(Qt::PreciseTimer); //设置计时器的精确程度 Qt::PreciseTimer值为0,含义:精确定时器试图保持毫秒精度
  258. connect(&mTimerState,SIGNAL(timeout()),this,SLOT(onStateTimer()));//广播发送UDP数据报
  259. mTimerState.start(100); //定时100ms
  260. mTimerStateMap.setTimerType(Qt::PreciseTimer); //
  261. connect(&mTimerStateMap,SIGNAL(timeout()),this,SLOT(onStateTimerMap()));//
  262. mTimerStateMap.start(500); //定时500ms
  263. is_show_enable = true;
  264. #ifdef USE_PAD_CTRL
  265. AutoStart();
  266. #endif
  267. ModuleFun funplantrace = std::bind(&ADCIntelligentVehicle::UpdatePlanTrace,this,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
  268. mpaplantrace = iv::modulecomm::RegisterRecvPlus("plantrace",funplantrace);
  269. ModuleFun funplantrace_left = std::bind(&ADCIntelligentVehicle::UpdatePlanTrace_left,this,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
  270. mpaplantrace_left = iv::modulecomm::RegisterRecvPlus("obstraceleft",funplantrace_left);
  271. ModuleFun funplantrace_right = std::bind(&ADCIntelligentVehicle::UpdatePlanTrace_right,this,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
  272. mpaplantrace_right = iv::modulecomm::RegisterRecvPlus("obstraceright",funplantrace_right);
  273. ModuleFun funfusion = std::bind(&ADCIntelligentVehicle::UpdateFusion,this,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
  274. mpafusion = iv::modulecomm::RegisterRecvPlus("li_ra_fusion",funfusion);
  275. ModuleFun funmap = std::bind(&ADCIntelligentVehicle::UpdateMap,this,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
  276. mpa = iv::modulecomm::RegisterRecvPlus("tracemap",funmap);
  277. // mpa = iv::modulecomm::RegisterRecv("tracemap",ListenTraceMap);
  278. ModuleFun fungpsimu =std::bind(&ADCIntelligentVehicle::UpdateGPSIMU,this,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
  279. mpagpsimu = iv::modulecomm::RegisterRecvPlus(gstrmemgps.data(),fungpsimu);
  280. // mpagpsimu = iv::modulecomm::RegisterRecv("gpsimu",Listengpsimu);
  281. ModuleFun funradar =std::bind(&ADCIntelligentVehicle::UpdateRADAR,this,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
  282. mparadar = iv::modulecomm::RegisterRecvPlus("radar",funradar);
  283. ModuleFun funchassis =std::bind(&ADCIntelligentVehicle::UpdateChassis,this,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
  284. mpachassis = iv::modulecomm::RegisterRecvPlus("chassis",funchassis);
  285. mpacanstate = iv::modulecomm::RegisterRecv("canstate",ListenCANState);
  286. gIvlog->debug("canState ptr: %x",mpacanstate);
  287. ModuleFun funbrainstate =std::bind(&ADCIntelligentVehicle::UpdateVehicleState,this,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
  288. // mpaVechicleState = iv::modulecomm::RegisterRecvPlus("vehiclestate",funbrainstate);
  289. mpaVechicleState = iv::modulecomm::RegisterRecvPlus("brainstate",funbrainstate);
  290. ModuleFun fundecition =std::bind(&ADCIntelligentVehicle::UpdateDecition,this,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
  291. // mpaDecition = iv::modulecomm::RegisterRecvPlus("decition",fundecition);
  292. mpaDecition = iv::modulecomm::RegisterRecvPlus("deciton",fundecition);
  293. mpaLidar = iv::modulecomm::RegisterRecv("lidar_obs",ListenOBS);
  294. mpaHMI = iv::modulecomm::RegisterSend("hmi",10*sizeof(iv::hmi::HMIBasic),10);
  295. iv::modulecomm::RegisterRecv("v2xStReq", ListenV2xStReq);
  296. mp_v2xStSend = iv::modulecomm::RegisterSend("v2xStEn",1000,1);
  297. mTimeState.start();
  298. mpManualCtrl = iv::modulecomm::RegisterSend("ivmanual",1000,1);
  299. mTimerManual = new QTimer(this);
  300. connect(mTimerManual,SIGNAL(timeout()),this,SLOT(onTimerManual()));
  301. connect(myview,SIGNAL(CtrlManual(bool)),this,SLOT(onCtrlManual(bool)));
  302. mnCtrlValue[0] = 0; mnCtrlValue[1] = 0; mnCtrlValue[2] = 0;
  303. // timermanualctrl->start(10);
  304. //connect(ui->lineEdit_6, SIGNAL(textEdited(const QString &)), this, SLOT(savestabuyEditinfo(const QString &)));
  305. mpamapreq = iv::modulecomm::RegisterSend("mapreq",1000,1);
  306. shareMapReqMsg();
  307. ModuleFun funvbox = std::bind(&ADCIntelligentVehicle::UpdateVbox,this,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
  308. mpaplantrace = iv::modulecomm::RegisterRecvPlus("vbox",funvbox);
  309. #if 1
  310. ui->lcdNumber->setDigitCount(3); //设置显示几个数字
  311. ui->lcdNumber->setMode(QLCDNumber::Dec);
  312. ui->lcdNumber->setSegmentStyle(QLCDNumber::Flat);//设置数字字体:Outline,轮廓突出,颜色为背景色;Filled,内部填充型,颜色为黑色;Flat,平面型
  313. // 设置数字颜色时要注意: 函数setSegmentStyle(QLCDNumber::Flat)中选择Flat属性,否则在setColor()设置数字颜色时不生效
  314. // 设置背景色直接用setStyleSheet()函数设定就可以了。
  315. //调色板
  316. QPalette lcdpat = ui->lcdNumber->palette();
  317. /*设置颜色,整体背景颜色 颜色蓝色,此函数的第一个参数可以设置多种。如文本、按钮按钮文字、多种*/
  318. lcdpat.setColor(QPalette::Normal,QPalette::WindowText,Qt::red);
  319. //设置当前窗口的调色板
  320. ui->lcdNumber->setPalette(lcdpat);
  321. //设置背景色
  322. //ui->lcdNumber->setStyleSheet("background-color: black");
  323. //ui->lcdNumber->display(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"));
  324. ui->lcdNumber->display(0);
  325. ui->lcdNumber_2->setDigitCount(3);
  326. ui->lcdNumber_2->setMode(QLCDNumber::Dec);
  327. ui->lcdNumber_2->setSegmentStyle(QLCDNumber::Flat);
  328. ui->lcdNumber_2->setPalette(lcdpat);
  329. //ui->lcdNumber_2->setStyleSheet("background-color: black");
  330. ui->lcdNumber_2->display(0);
  331. ui->lcdNumber_3->setDigitCount(3);
  332. ui->lcdNumber_3->setMode(QLCDNumber::Dec);
  333. ui->lcdNumber_3->setSegmentStyle(QLCDNumber::Flat);
  334. ui->lcdNumber_3->setPalette(lcdpat);
  335. //ui->lcdNumber_3->setStyleSheet("background-color: black");
  336. ui->lcdNumber_3->display(0);
  337. ui->lcdNumber_4->setDigitCount(3);
  338. ui->lcdNumber_4->setMode(QLCDNumber::Dec);
  339. ui->lcdNumber_4->setSegmentStyle(QLCDNumber::Flat);
  340. ui->lcdNumber_4->setPalette(lcdpat);
  341. //ui->lcdNumber_4->setStyleSheet("background-color: black");
  342. ui->lcdNumber_4->display(0);
  343. #endif
  344. // 新建qimage
  345. // QImage img,img2,img3,img4;
  346. // 加载图片
  347. img.load(":/light_image/diaotou-black.png");
  348. img = img.scaled(66,66,Qt::IgnoreAspectRatio);
  349. ui->label_38->setPixmap(QPixmap::fromImage(img));
  350. img2.load(":/light_image/zuoguai-black.png");
  351. img2 = img2.scaled(66,66,Qt::IgnoreAspectRatio);
  352. ui->label_33->setPixmap(QPixmap::fromImage(img2));
  353. img3.load(":/light_image/zhixing-black.png");
  354. img3 = img3.scaled(66,66,Qt::IgnoreAspectRatio);
  355. ui->label_35->setPixmap(QPixmap::fromImage(img3));
  356. img4.load(":/light_image/youguai-black.png");
  357. img4 = img4.scaled(66,66,Qt::IgnoreAspectRatio);
  358. ui->label_32->setPixmap(QPixmap::fromImage(img4));
  359. #if 1
  360. mTimerState1.setTimerType(Qt::PreciseTimer); //设置计时器的精确程度 Qt::PreciseTimer值为0,含义:精确定时器试图保持毫秒精度
  361. connect(&mTimerState1,SIGNAL(timeout()),this,SLOT(onStateTimer1()));//广播发送UDP数据报
  362. mTimerState1.start(100); //定时100ms
  363. #endif
  364. }
  365. /**
  366. * @brief ADCIntelligentVehicle::savestabuyEditinfo
  367. * @param txt
  368. */
  369. void ADCIntelligentVehicle::savestabuyEditinfo(const QString &txt)
  370. {
  371. //ServiceControlStatus.set_accelerate((float)txt.toDouble());
  372. }
  373. /**
  374. * @brief ADCIntelligentVehicle::timeoutslot
  375. */
  376. void ADCIntelligentVehicle::timeoutslot()
  377. {
  378. update();
  379. /////////////////////////////////
  380. // //
  381. // 实时状态信息显示 //
  382. ////////////////////////////////
  383. QString is_ok;
  384. ui->lineEdit->setText(QString::number(ServiceCarStatus.location->rtk_status));//rtk状态
  385. ui->lineEdit_12->setText(QString::number(ServiceCarStatus.location->rtk_status));//rtk状态
  386. if(ServiceCarStatus.location->rtk_status==6)
  387. {
  388. ui->pushButton_10->setStyleSheet("background-color: green");
  389. ui->pushButton_23->setStyleSheet("background-color: green");
  390. }
  391. else
  392. {
  393. ui->pushButton_10->setStyleSheet("background-color: red");
  394. ui->pushButton_23->setStyleSheet("background-color: red");
  395. }
  396. ui->lineEdit_2->setText(QString::number(ServiceCarStatus.location->ins_status));//ins状态
  397. if(ServiceCarStatus.location->ins_status==4)
  398. ui->pushButton_11->setStyleSheet("background-color: green");
  399. else
  400. ui->pushButton_11->setStyleSheet("background-color: red");
  401. is_ok = (ServiceCarStatus.mRadarS>0)?QStringLiteral("ok"):QStringLiteral("error");
  402. ui->lineEdit_3->setText(is_ok);//毫米波雷达状态
  403. ui->lineEdit_15->setText(is_ok);//毫米波雷达状态
  404. if(ServiceCarStatus.mRadarS>0)
  405. {
  406. ui->pushButton_12->setStyleSheet("background-color: green");
  407. ui->pushButton_25->setStyleSheet("background-color: green");
  408. }
  409. else
  410. {
  411. ui->pushButton_12->setStyleSheet("background-color:red");
  412. ui->pushButton_25->setStyleSheet("background-color:red");
  413. }
  414. is_ok = (ServiceCarStatus.mLidarS>0)?QStringLiteral("ok"):QStringLiteral("error");
  415. ui->lineEdit_4->setText(is_ok);//激光雷达状态
  416. ui->lineEdit_16->setText(is_ok);//激光雷达状态
  417. if(ServiceCarStatus.mLidarS>0)
  418. {
  419. ui->pushButton_13->setStyleSheet("background-color: green");
  420. ui->pushButton_26->setStyleSheet("background-color: green");
  421. }
  422. else
  423. {
  424. ui->pushButton_13->setStyleSheet("background-color:red");
  425. ui->pushButton_26->setStyleSheet("background-color:red");
  426. }
  427. ui->lineEdit_5->setText(QString::number(mdecition_period)+QStringLiteral("ms"));//决策周期
  428. ui->lineEdit_17->setText(QString::number(mdecition_period)+QStringLiteral("ms"));//决策周期
  429. if(mdecition_period>0)
  430. {
  431. ui->pushButton_14->setStyleSheet("background-color: green");
  432. ui->pushButton_27->setStyleSheet("background-color: green");
  433. }
  434. if((mTimeState.elapsed()-mnTimeUpdateGPS) > 1000)
  435. {
  436. ui->pushButton_10->setStyleSheet("background-color: red");
  437. ui->pushButton_11->setStyleSheet("background-color: red");
  438. ui->pushButton_23->setStyleSheet("background-color: red");
  439. }
  440. if((mTimeState.elapsed() - mnTimeUpdateDecition)>1000)
  441. {
  442. ui->pushButton_14->setStyleSheet("background-color:red");
  443. ui->pushButton_27->setStyleSheet("background-color:red");
  444. ui->label_decition->setText("No decition");
  445. mbBrainRunning = false;
  446. }
  447. else
  448. {
  449. QString strdec = "Acc:";
  450. strdec = strdec + QString::number(ServiceCarStatus.mfAcc,'f',1);
  451. // strdec = strdec + " Brake:";
  452. // strdec = strdec + QString::number(ServiceCarStatus.mfBrake,'f',1);
  453. strdec = strdec + " EPS:";
  454. strdec = strdec + QString::number(ServiceCarStatus.mfWheel,'f',1);
  455. ui->label_decition->setText(strdec);
  456. }
  457. if(mbManual)
  458. {
  459. char strmanual[256];
  460. snprintf(strmanual,256,"Manual %d %d %d",mnCtrlValue[0],mnCtrlValue[1],mnCtrlValue[2]);
  461. ui->label_decition->setText(strmanual);
  462. }
  463. #if 0
  464. ui->lineEdit->setText(QString::number(6));//rtk状态
  465. ui->pushButton_10->setStyleSheet("background-color: green");
  466. ui->lineEdit_12->setText(QString::number(6));//rtk状态
  467. ui->pushButton_23->setStyleSheet("background-color: green");
  468. ui->lineEdit_2->setText(QString::number(4));
  469. ui->pushButton_11->setStyleSheet("background-color: green");
  470. ui->lineEdit_3->setText("ok");
  471. ui->pushButton_12->setStyleSheet("background-color: green");
  472. ui->lineEdit_15->setText("ok");
  473. ui->pushButton_25->setStyleSheet("background-color: green");
  474. ui->lineEdit_4->setText("ok");
  475. ui->pushButton_13->setStyleSheet("background-color: green");
  476. ui->lineEdit_16->setText("ok");
  477. ui->pushButton_26->setStyleSheet("background-color: green");
  478. ui->lineEdit_5->setText(QString::number(20)+QStringLiteral("ms"));//决策周期
  479. ui->pushButton_14->setStyleSheet("background-color: green");
  480. ui->lineEdit_17->setText(QString::number(20)+QStringLiteral("ms"));//决策周期
  481. ui->pushButton_27->setStyleSheet("background-color: green");
  482. #endif
  483. /////////////////////////////////
  484. // //
  485. // 实时显示障碍物状态 //
  486. /////////////////////////////////
  487. // ServiceCarStatus.mObs = 10;
  488. // ServiceCarStatus.mLidarObs = 9.123;
  489. // ServiceCarStatus.mRadarObs = 9.222;
  490. // ServiceCarStatus.mfttc = 0.5;
  491. // ServiceCarStatus.mfBrake = 20;
  492. if(ServiceCarStatus.mObs > 0)
  493. {
  494. ui->label_13->setText("Obs:"+QString::number(ServiceCarStatus.mObs,'f',1)+" Lidar:"
  495. +QString::number(ServiceCarStatus.mLidarObs,'f',1) + " Radar:"
  496. +QString::number(ServiceCarStatus.mRadarObs,'f',1));
  497. }
  498. else
  499. {
  500. ui->label_13->setText(QString("前方没有障碍物"));
  501. }
  502. ui->label_26->setText("ttc is "+QString::number(ServiceCarStatus.mfttc,'f',1) + " brake is " + QString::number(ServiceCarStatus.mfBrake,'f',2)); //add 20200518
  503. QString strstate = "Map:";
  504. if(mDataToUI.mInfo.is_mapLoad == 1)
  505. {
  506. strstate = strstate+"Yes ";
  507. }
  508. else
  509. {
  510. strstate = strstate+"No ";
  511. }
  512. strstate = strstate+" CANCARD:";
  513. if(mDataToUI.mInfo.is_initSuccess == 1)
  514. {
  515. strstate = strstate+"OK ";
  516. }
  517. else
  518. {
  519. strstate = strstate+"Fail ";
  520. }
  521. strstate = strstate + " Run State:";
  522. if(mbBrainRunning)
  523. {
  524. strstate = strstate+"RUN";
  525. }
  526. else
  527. {
  528. strstate = strstate+"STOP";
  529. }
  530. ui->label_State->setText(strstate);
  531. /////////////////////////////////
  532. // //
  533. // 模式选择标志置位 //
  534. // //
  535. ////////////////////////////////
  536. // if(ui->checkBox->isChecked()==true)ServiceControlStatus.change_line = 1;//是否换道标志
  537. // else ServiceControlStatus.change_line = 0;
  538. // if(ui->checkBox_2->isChecked()==true)ServiceControlStatus.stop_obstacle = 1;//是否停障标志
  539. // else ServiceControlStatus.stop_obstacle = 0;
  540. // if(ui->checkBox_3->isChecked()==true)ServiceControlStatus.elude_obstacle = 1;//是否避障标志
  541. // else ServiceControlStatus.elude_obstacle = 0;
  542. // if(ui->checkBox_4->isChecked()==true)ServiceControlStatus.special_signle = 1;//是否特殊信号输入标志
  543. // else ServiceControlStatus.special_signle = 0;
  544. // if(ui->checkBox_5->isChecked()==true)ServiceControlStatus.car_pullover = 1;//是否靠边停车标志位
  545. // else ServiceControlStatus.car_pullover = 0;
  546. ui->lb_current_speed_big->setText(QString::number(ServiceCarStatus.speed,'f',1));
  547. // QString is_ok;
  548. // is_ok = (ServiceLidar.did_lidar_ok() == true)?QStringLiteral("ok"):QStringLiteral("error");
  549. // ui->lineEdit_4->setText(is_ok);
  550. //can state
  551. mDataToUI.mInfo.is_initSuccess = 0;
  552. }
  553. /**
  554. * @brief ADCIntelligentVehicle::on_pb_load_navigation_data_clicked
  555. */
  556. //void ADCIntelligentVehicle::on_pb_load_navigation_data_clicked() //加载地图
  557. //{
  558. //}
  559. /**
  560. * @brief ADCIntelligentVehicle::onRecvUDP
  561. */
  562. void ADCIntelligentVehicle::onRecvUDP()
  563. {
  564. while (msockrecv.hasPendingDatagrams()) //hasPendingDatagrams()表示是否有待读取的传入数据报
  565. {
  566. qDebug("recv cmd");
  567. QByteArray ba;
  568. ba.resize(msockrecv.pendingDatagramSize());//pendingDatagramSize()返回待读取数据报的字节数
  569. msockrecv.readDatagram(ba.data(), ba.size()); //readDatagram()函数用于读取数据报内容
  570. int * p;
  571. iv::hmi::HMIBasic hmi;
  572. p = (int *)ba.data();
  573. // qDebug("cmd is ",*p);
  574. // std::cout<<"data len is "<<ba.size()<<" value is "<<*p<<std::endl;
  575. if(*p == 1)
  576. {
  577. std::cout<<ServiceCarStatus.mRunTime.elapsed()<<":"<<"recv start."<<std::endl;
  578. ServiceCarStatus.mbRunPause = false;
  579. hmi.mbBocheMode = false;
  580. hmi.mbPause = false;
  581. ShareHMIMsg(hmi);
  582. }
  583. if(*p == 0)
  584. {
  585. ServiceCarStatus.mbRunPause = true;
  586. hmi.mbBocheMode = false;
  587. hmi.mbPause = true;
  588. ShareHMIMsg(hmi);
  589. }
  590. if(*p == 2)
  591. {
  592. ServiceCarStatus.bocheMode = true;
  593. hmi.mbBocheMode = true;
  594. hmi.mbPause = false;
  595. ShareHMIMsg(hmi);
  596. }
  597. if(*p == 3)
  598. {
  599. hmi.mbbusmode = true;
  600. hmi.mbPause = ServiceCarStatus.mbRunPause;
  601. ShareHMIMsg(hmi);
  602. }
  603. if(*p == 4)
  604. {
  605. hmi.mbbusmode = false;
  606. hmi.mbPause = ServiceCarStatus.mbRunPause;
  607. ShareHMIMsg(hmi);
  608. }
  609. }
  610. }
  611. /**
  612. * @brief ADCIntelligentVehicle::onStateTimer
  613. */
  614. void ADCIntelligentVehicle::onStateTimer()
  615. {
  616. if(ServiceCarStatus.mbBrainCtring)
  617. mDataToUI.mInfo.is_run = 1;
  618. else
  619. mDataToUI.mInfo.is_run = 0;
  620. if(ServiceCarStatus.mLidarS<0)
  621. mDataToUI.mInfo.lidarStatus = 0;
  622. else
  623. mDataToUI.mInfo.lidarStatus = 1;
  624. if(ServiceCarStatus.mRadarS<0)
  625. mDataToUI.mInfo.radarStatus = 0;
  626. else
  627. mDataToUI.mInfo.radarStatus = 1;
  628. ServiceCarStatus.mLidarS--; //如果从10减到0,表示没有接收到数据。
  629. ServiceCarStatus.mRadarS--;
  630. mDataToUI.mInfo.RTKstatus = ServiceCarStatus.mRTKStatus;
  631. ServiceCarStatus.mRTKStatus = 0;
  632. mDataToUI.mInfo.radarobs = ServiceCarStatus.mRadarObs;
  633. mDataToUI.mInfo.lidarobs = ServiceCarStatus.mLidarObs;
  634. mDataToUI.mInfo.obs = ServiceCarStatus.mObs;
  635. mDataToUI.mInfo.gps_lat = ServiceCarStatus.location->gps_lat;
  636. mDataToUI.mInfo.gps_lng = ServiceCarStatus.location->gps_lng;
  637. mDataToUI.mInfo.accelerate = ServiceCarStatus.mfAcc;
  638. mDataToUI.mInfo.speed = ServiceCarStatus.speed;
  639. mDataToUI.mInfo.brake = ServiceCarStatus.mfBrake;
  640. mDataToUI.mInfo.swerve = ServiceCarStatus.mfWheel;
  641. mDataToUI.mInfo.boche_status = ServiceCarStatus.bocheEnable;
  642. if(fabs(mDataToUI.mInfo.gps_lat)<1 )
  643. {
  644. // qDebug("gps lat is error.");
  645. // std::cout<<"no gps."<<std::endl;
  646. }
  647. // std::cout<<"send data."<<std::endl;
  648. // qDebug("speed is %d",mDataToUI.mInfo.speed);
  649. // mDataToUI.mInfo.is_initSuccess = 1;
  650. // mDataToUI.mInfo.speed = 36.1;
  651. msocksend.writeDatagram((char *)&mDataToUI,sizeof(DataToUI),QHostAddress::Broadcast,9999); //QHostAddress::Broadcast 值为1 Pv4广播地址,相当于QHostAddress(“255.255.255.255”)。
  652. // _udp->writeDatagram(str.toUtf8(), QHostAddress::Broadcast, 10002);
  653. // multicast, 224.0.0.1~224.0.0.255 is multicast address of LAN
  654. // _udp->writeDatagram(str.toUtf8(), QHostAddress("224.0.0.131"), 10002);
  655. }
  656. void ADCIntelligentVehicle::onStateTimerMap()
  657. {
  658. /*******************************更新百度地图******************************/
  659. double flat = ServiceCarStatus.location->gps_lat;
  660. double flon = ServiceCarStatus.location->gps_lng;
  661. double fang = ServiceCarStatus.location->ins_heading_angle;
  662. char strscript[256];
  663. snprintf(strscript,255,"theLocation(%11.7f,%11.7f,%11.7f);",flon,flat,fang);
  664. mMapview->page()->runJavaScript(strscript);
  665. /************************************************************************/
  666. }
  667. /**
  668. * @brief ADCIntelligentVehicle::AutoStart
  669. */
  670. void ADCIntelligentVehicle::AutoStart()
  671. {
  672. // is_brain_running_flag_ = true;
  673. // mDataToUI.mInfo.is_initSuccess = 1;
  674. // std::cout<<ServiceCarStatus.mRunTime.elapsed()<<"ms:"<<"Start Run SuccessFully."<<std::endl;
  675. }
  676. /**
  677. * @brief ADCIntelligentVehicle::on_pb_start_all_clicked
  678. */
  679. void ADCIntelligentVehicle::on_pb_start_all_clicked() {
  680. #ifdef USE_PAD_CTRL
  681. ServiceCarStatus.mbRunPause = false;
  682. iv::hmi::HMIBasic hmi;
  683. hmi.mbBocheMode = false;
  684. hmi.mbPause = false;
  685. ShareHMIMsg(hmi);
  686. return;
  687. #endif
  688. }
  689. /**
  690. * @brief ADCIntelligentVehicle::on_pb_open_can_card_clicked
  691. */
  692. //void ADCIntelligentVehicle::on_pb_open_can_card_clicked() {
  693. //}
  694. /**
  695. * @brief ADCIntelligentVehicle::on_timer_car_status_time_out
  696. */
  697. void ADCIntelligentVehicle::on_timer_car_status_time_out() {
  698. ui->lb_current_speed_big->setText(QString::number(ServiceCarStatus.speed));
  699. //ui->sb_accelerate_percent->setValue(ServiceControlStatus.accelerate_percent);
  700. //ui->sb_wheel_percent->setValue(ServiceControlStatus.wheel_angle);
  701. }
  702. /**
  703. * @brief ADCIntelligentVehicle::on_timer_mobileye_info_time_out
  704. */
  705. void ADCIntelligentVehicle::on_timer_mobileye_info_time_out(){
  706. mobileye_info->aws_display.dusk_time = ServiceCarStatus.aws_display.dusk_time;
  707. mobileye_info->Lane.curvature = ServiceCarStatus.Lane.curvature;
  708. mobileye_info->Lane.heading = ServiceCarStatus.Lane.heading;
  709. mobileye_info->Lane.pitch = ServiceCarStatus.Lane.pitch;
  710. mobileye_info->Lane.yaw = ServiceCarStatus.Lane.yaw;
  711. mobileye_info->obstacleStatus.num_obstacles = ServiceCarStatus.obstacleStatus.num_obstacles;
  712. mobileye_info->obstacleStatus.timestamp = ServiceCarStatus.obstacleStatus.timestamp;
  713. mobileye_info->aftermarketLane.dist_to_lane_l = ServiceCarStatus.aftermarketLane.dist_to_lane_l;
  714. mobileye_info->aftermarketLane.dist_to_lane_r = ServiceCarStatus.aftermarketLane.dist_to_lane_r;
  715. mobileye_info->aftermarketLane.lane_type_left = ServiceCarStatus.aftermarketLane.lane_type_left;
  716. mobileye_info->aftermarketLane.lane_type_right = ServiceCarStatus.aftermarketLane.lane_type_right;
  717. for(int i = 0; i < 15; i++)
  718. {
  719. mobileye_info->obstacleStatusA[i].obstacle_ID = ServiceCarStatus.obstacleStatusA[i].obstacle_ID;
  720. mobileye_info->obstacleStatusA[i].obstacle_pos_x = ServiceCarStatus.obstacleStatusA[i].obstacle_pos_x;
  721. mobileye_info->obstacleStatusA[i].obstacle_pos_y = ServiceCarStatus.obstacleStatusA[i].obstacle_pos_y;
  722. mobileye_info->obstacleStatusA[i].obstacle_rel_vel_x = ServiceCarStatus.obstacleStatusA[i].obstacle_rel_vel_x;
  723. mobileye_info->obstacleStatusA[i].obstacle_status = ServiceCarStatus.obstacleStatusA[i].obstacle_status;
  724. mobileye_info->obstacleStatusA[i].obstacle_type = ServiceCarStatus.obstacleStatusA[i].obstacle_type;
  725. mobileye_info->obstacleStatusA[i].is_obstacle_brake_lights = ServiceCarStatus.obstacleStatusA[i].is_obstacle_brake_lights;
  726. }
  727. for(int i = 0; i < 15; i++)
  728. {
  729. mobileye_info->obstacleStatusB[i].obstacle_length = ServiceCarStatus.obstacleStatusB[i].obstacle_length;
  730. mobileye_info->obstacleStatusB[i].obstacle_width = ServiceCarStatus.obstacleStatusB[i].obstacle_width;
  731. mobileye_info->obstacleStatusB[i].obstacle_age = ServiceCarStatus.obstacleStatusB[i].obstacle_age;
  732. }
  733. for(int i = 0; i < 15; i++)
  734. {
  735. mobileye_info->obstacleStatusC[i].obstacle_angle_rate = ServiceCarStatus.obstacleStatusC[i].obstacle_angle_rate;
  736. mobileye_info->obstacleStatusC[i].obstacle_angle = ServiceCarStatus.obstacleStatusC[i].obstacle_angle;
  737. mobileye_info->obstacleStatusC[i].object_accel_x = ServiceCarStatus.obstacleStatusC[i].object_accel_x;
  738. }
  739. }
  740. /**
  741. * @brief ADCIntelligentVehicle::keyPressEvent 加/减键进行缩放
  742. * @param event
  743. */
  744. void ADCIntelligentVehicle::keyPressEvent(QKeyEvent *event)
  745. {
  746. switch (event->key()) {
  747. case Qt::Key_Plus: // 放大
  748. myview->zoomIn();
  749. break;
  750. case Qt::Key_Minus: // 缩小
  751. myview->zoomOut();
  752. break;
  753. default:
  754. QMainWindow::keyPressEvent(event);
  755. }
  756. }
  757. /**
  758. * @brief ADCIntelligentVehicle::closeEvent
  759. * @param event
  760. */
  761. void ADCIntelligentVehicle::closeEvent(QCloseEvent *event)
  762. {
  763. QMessageBox::StandardButton button;
  764. button=QMessageBox::question(this,tr("退出程序"),QString(tr("确认退出程序")),QMessageBox::Yes|QMessageBox::No);
  765. if(button==QMessageBox::No)
  766. {
  767. event->ignore(); // 忽略退出信号,程序继续进行
  768. }
  769. else if(button==QMessageBox::Yes)
  770. {
  771. event->accept(); // 接受退出信号,程序退出
  772. }
  773. }
  774. /**
  775. * @brief MyView::wheelEvent 放大/缩小
  776. * @param event
  777. */
  778. void MyView::wheelEvent(QWheelEvent *event)
  779. {
  780. // 滚轮的滚动量
  781. QPoint scrollAmount = event->angleDelta();
  782. // 正值表示滚轮远离使用者(放大),负值表示朝向使用者(缩小)
  783. scrollAmount.y() > 0 ? zoomIn() : zoomOut();
  784. }
  785. /**
  786. * @brief MyView::zoomIn 放大
  787. */
  788. void MyView::zoomIn()
  789. {
  790. scale(1.1, 1.1);
  791. beishu *= 1.1;
  792. centerOn(450, 700 - (200 / beishu));
  793. }
  794. /**
  795. * @brief MyView::zoomOut 缩小
  796. */
  797. void MyView::zoomOut()
  798. {
  799. scale(1 / 1.1, 1 / 1.1);
  800. beishu /= 1.1;
  801. centerOn(450, 700 - (200 / beishu));
  802. }
  803. /**
  804. * @brief ADCIntelligentVehicle::paintEvent 刷新
  805. */
  806. void ADCIntelligentVehicle::paintEvent(QPaintEvent *)
  807. {
  808. if (is_show_enable)
  809. {
  810. // qDebug("enter paint. time1 is %d",mTime.elapsed());
  811. if(fabs(mTime.elapsed() - mnTimeLastUpdatePaint)<100)
  812. {
  813. return;
  814. }
  815. mnTimeLastUpdatePaint = mTime.elapsed();
  816. // qDebug("enter paint. time is %d",mTime.elapsed());
  817. painter->begin(image);
  818. // painter_small->begin(image_small);
  819. // image->fill(QColor(60, 60, 60));//对画布进行填充
  820. image->fill(QColor(220, 220, 220));//对画布进行填充
  821. image_small->fill(QColor(220,220,220));
  822. std::vector<iv::GPSData> navigation_data;
  823. mMutexNavi.lock();
  824. navigation_data = m_navigation_data;
  825. mMutexNavi.unlock();
  826. std::vector<iv::Point2D> myplan,myplan_left,myplan_right;
  827. mMutexPlan.lock();
  828. myplan = m_plan;
  829. mMutexPlan.unlock();
  830. mMutexPlan_left.lock();
  831. myplan_left = m_plan_left;
  832. mMutexPlan_left.unlock();
  833. mMutexPlan_right.lock();
  834. myplan_right = m_plan_right;
  835. mMutexPlan_right.unlock();
  836. // std::cout<<"plan size is "<<myplan.size()<<std::endl;
  837. // std::vector<iv::GPSData> navigation_data = brain->navigation_data;
  838. painter->setRenderHint(QPainter::Antialiasing, true);//设置反锯齿模式,好看一点
  839. painter_small->setRenderHint(QPainter::Antialiasing, true);//设置反锯齿模式,好看一点
  840. int pointx = 450, pointy = 700;//确定坐标轴起点坐标,这里定义(35,280)
  841. // int pointx_small = 450, pointy_small = 700;
  842. // double x0[22000], y0[22000], lng[22000], x1[22000], y1[22000], x2[22000], y2[22000];
  843. double * x0, * y0, * lng, * x1, * y1, * x2, * y2;
  844. std::shared_ptr<double> ptrx0,ptry0,ptrlng,ptrx1,ptry1,ptrx2,ptry2;
  845. int nmapsize = navigation_data.size();
  846. x0 = new double[nmapsize];
  847. y0 = new double[nmapsize];
  848. lng = new double[nmapsize];
  849. x1 = new double[nmapsize];
  850. y1 = new double[nmapsize];
  851. x2 = new double[nmapsize];
  852. y2 = new double[nmapsize];
  853. ptrx0.reset(x0);
  854. ptry0.reset(y0);
  855. ptrlng.reset(lng);
  856. ptrx1.reset(x1);
  857. ptry1.reset(y1);
  858. ptrx2.reset(x2);
  859. ptry2.reset(y2);
  860. double xx = 0, yy = 0;
  861. double sumx = 0, sumy = 0;//, ave_x = 0, ave_y = 0;
  862. int sizeN = navigation_data.size();
  863. //int max_x_pos = 0, min_x_pos = 0, max_y_pos = 0, min_y_pos = 0;
  864. int x_max = 0, y_max = 0;//数组里的最大值
  865. int x_min = 0x3f3f3f3f, y_min = 0x3f3f3f3f;//inf为 #define inf 0x3f3f3f3f
  866. double k1, k2;
  867. QPen pen, penPoint;
  868. //先绘制车位置点及框图
  869. static const QPointF points1[2] = { QPointF(300, 700), QPointF(600, 700) };
  870. static const QPointF points2[2] = { QPointF(450, 0), QPointF(450, 900) };
  871. // static const QPointF points1_small[2] = { QPointF(300, 700), QPointF(600, 700) };
  872. // static const QPointF points2_small[2] = { QPointF(450, 0), QPointF(450, 900) };
  873. penPoint.setColor(Qt::red);
  874. penPoint.setWidth(2);
  875. painter->setPen(penPoint);
  876. // painter_small->setPen(penPoint);
  877. painter->drawPoint(pointx, pointy);
  878. // painter_small->drawPoint(pointx_small,pointy_small);
  879. painter->drawPolyline(points1, 2);
  880. painter->drawPolyline(points2, 2);
  881. // painter_small->drawPolyline(points1_small, 2);
  882. // painter_small->drawPolyline(points2_small, 2);
  883. //路径点的预处理
  884. for (int i = 0; i < sizeN; i++)
  885. {
  886. x0[i] = navigation_data[i]->gps_x;
  887. y0[i] = navigation_data[i]->gps_y;
  888. lng[i] = navigation_data[i]->ins_heading_angle;
  889. sumx = sumx + navigation_data[i]->gps_x;
  890. sumy = sumy + navigation_data[i]->gps_y;
  891. if (x0[i] > x_max) {
  892. x_max = x0[i];
  893. //max_x_pos = i;
  894. }
  895. if (x0[i] < x_min) {
  896. x_min = x0[i];
  897. //min_x_pos = i;
  898. }
  899. if (y0[i] > y_max) {
  900. y_max = y0[i];
  901. //max_y_pos = i;
  902. }
  903. if (y0[i] < y_min) {
  904. y_min = y0[i];
  905. //min_y_pos = i;
  906. }
  907. }
  908. //ave_x = sumx / sizeN;
  909. //ave_y = sumy / sizeN;
  910. //获取到实时 GPS信息,并做路径点的显示更新
  911. if (ServiceCarStatus.location->gps_x == 0)
  912. {
  913. painter->drawText(rect(), Qt::AlignLeft, QString::fromLocal8Bit("等待车辆实时GPS位置信息"));
  914. // painter_small->drawText(rect(), Qt::AlignLeft, QString::fromLocal8Bit("等待车辆实时GPS位置信息"));
  915. }
  916. else
  917. {
  918. x0[0] = ServiceCarStatus.location->gps_x;
  919. y0[0] = ServiceCarStatus.location->gps_y;
  920. // std::cout<<"x = "<<x0[0]<<" y= "<<y0[0]<<std::endl;
  921. lng[0] = ServiceCarStatus.location->ins_heading_angle;
  922. }
  923. //根据标定原点的选取,对路径点进行转化
  924. for (int i = 1; i < sizeN; i++)
  925. {
  926. // if(i == 1)std::cout<<" x1 = "<<x0[i]<<std::endl;
  927. x0[i] = x0[i] - x0[0];
  928. y0[i] = y0[i] - y0[0];
  929. xx = x0[i];
  930. yy = y0[i];
  931. x0[i] = xx * cos(lng[0] * PI / 180) - yy * sin(lng[0] * PI / 180);
  932. y0[i] = xx * sin(lng[0] * PI / 180) + yy * cos(lng[0] * PI / 180);
  933. k1 = sin((90 + (lng[i] - lng[0])) * PI / 180);
  934. k2 = cos((90 + (lng[i] - lng[0])) * PI / 180);
  935. #if 0
  936. x1[i] = x0[i] + k1 * 5;
  937. y1[i] = y0[i] + k2 * 5;
  938. x2[i] = x0[i] - k1 * 5;
  939. y2[i] = y0[i] - k2 * 5;
  940. #else
  941. x1[i] = x0[i] + k1 * 1.75;
  942. y1[i] = y0[i] + k2 * 1.75;
  943. x2[i] = x0[i] - k1 * 1.75;
  944. y2[i] = y0[i] - k2 * 1.75;
  945. #endif
  946. }
  947. // double kx_small = (double)(1200) / (abs(y_max - y_min));//x轴的系数
  948. // double ky_small = (double)(1200) / (abs(y_max - y_min));//y方向的比例系数
  949. double kx = 10;
  950. double ky = 10;
  951. //距离车正前方10m处画一条线
  952. static const QPointF points3[2] = { QPointF(0, 700 - 10 * ky), QPointF(900, 700 - 10 * ky) };
  953. painter->drawPolyline(points3, 2);
  954. //绘制路径点
  955. penPoint.setColor(Qt::black);
  956. penPoint.setWidth(1);
  957. for (int i = 1; i < sizeN - 1; i++)
  958. {
  959. painter->setPen(penPoint);//蓝色的笔,用于标记各个点
  960. // painter_small->setPen(penPoint);//蓝色的笔,用于标记各个点
  961. painter->drawPoint(pointx + x0[i] * kx, pointy - y0[i] * ky);
  962. // painter_small->drawPoint(pointx_small + x0[i] * kx_small, pointy_small - y0[i] * ky_small);
  963. painter->drawPoint(pointx + x1[i] * kx, pointy - y1[i] * ky);
  964. // painter_small->drawPoint(pointx_small + x1[i] * kx_small, pointy_small - y1[i] * ky_small);
  965. painter->drawPoint(pointx + x2[i] * kx, pointy - y2[i] * ky);
  966. // painter_small->drawPoint(pointx_small + x2[i] * kx_small, pointy_small - y2[i] * ky_small);
  967. }
  968. painter->drawPoint(pointx + x0[sizeN - 1] * kx, pointy - y0[sizeN - 1] * ky);//绘制最后一个点
  969. // painter_small->drawPoint(pointx_small + x0[sizeN - 1] * kx_small, pointy_small - y0[sizeN - 1] * ky_small);//绘制最后一个点
  970. penPoint.setColor(Qt::red);
  971. penPoint.setWidth(2);
  972. painter->drawPoint(pointx + x0[0] * kx, pointy - y0[0] * ky);
  973. // painter_small->drawPoint(pointx_small + x0[0] * kx_small, pointy_small - y0[0] * ky_small);
  974. #if 0
  975. // draw plan trace
  976. penPoint.setColor(Qt::green);
  977. penPoint.setWidth(2);
  978. painter->setPen(penPoint);
  979. QPointF tracePoints[myplan.size()];
  980. if(myplan.size()>2)
  981. {
  982. for(int i=0;i<(myplan.size()-1);i++)
  983. {
  984. tracePoints[i].setX((float)(450+myplan[i].x*kx));
  985. tracePoints[i].setY((float)(700-myplan[i].y*ky));
  986. painter->drawLine((float)(450+myplan[i].x*kx),(float)(700-myplan[i].y*ky),
  987. (float)(450+myplan[i+1].x*kx),(float)(700-myplan[i+1].y*ky));
  988. }
  989. }
  990. #endif
  991. #if 1
  992. // penPoint.setColor(Qt::gray);
  993. penPoint.setColor(QColor(187, 255, 255, 100));
  994. penPoint.setWidth(2);
  995. painter->setPen(penPoint);
  996. QPointF tracePoints_left[myplan_left.size()];
  997. if(myplan_left.size()>2)
  998. {
  999. for(int i=0;i<(myplan_left.size()-1);i++)
  1000. {
  1001. tracePoints_left[i].setX((float)(450+myplan_left[i].x*kx));
  1002. tracePoints_left[i].setY((float)(700-myplan_left[i].y*ky));
  1003. painter->drawLine((float)(450+myplan_left[i].x*kx),(float)(700-myplan_left[i].y*ky),
  1004. (float)(450+myplan_left[i+1].x*kx),(float)(700-myplan_left[i+1].y*ky));
  1005. }
  1006. }
  1007. // penPoint.setColor(Qt::gray);
  1008. // penPoint.setWidth(2);
  1009. // painter->setPen(penPoint);
  1010. QPointF tracePoints_right[myplan_right.size()];
  1011. if(myplan_right.size()>2)
  1012. {
  1013. for(int i=0;i<(myplan_right.size()-1);i++)
  1014. {
  1015. tracePoints_right[i].setX((float)(450+myplan_right[i].x*kx));
  1016. tracePoints_right[i].setY((float)(700-myplan_right[i].y*ky));
  1017. painter->drawLine((float)(450+myplan_right[i].x*kx),(float)(700-myplan_right[i].y*ky),
  1018. (float)(450+myplan_right[i+1].x*kx),(float)(700-myplan_right[i+1].y*ky));
  1019. }
  1020. }
  1021. #endif
  1022. // painter->drawPolyline(tracePoints,myplan.size());
  1023. // draw plan trace end
  1024. /////////////////////////////////////apollo add car icon 20200409
  1025. QPixmap pix;
  1026. //pix.load("car.png");
  1027. pix.load(":/ADCIntelligentVehicle/car1.png");
  1028. painter->drawPixmap(435,667,30,67,pix);
  1029. // painter_small->drawPixmap(442,683,16,34,pix);
  1030. ///////////////////////////////////////////////////////////////////
  1031. penPoint.setColor(Qt::blue);
  1032. penPoint.setWidth(3);
  1033. painter->setPen(penPoint);
  1034. QFont font;
  1035. font.setFamily("Microsoft YaHei");
  1036. font.setPointSize(50);
  1037. font.setItalic(true);
  1038. painter->setFont(font);
  1039. //////////////////////////////////////
  1040. // //
  1041. // 显示毫米波雷达和激光雷达的信息 //
  1042. // //
  1043. //////////////////////////////////////
  1044. if(ui->checkBox_8->isChecked())
  1045. {
  1046. painter->setPen(QPen(Qt::black, 2));
  1047. painter->setBrush(Qt::blue);
  1048. QFont esr_font("Microsoft YaHei", 10, 75); //第一个属性是字体(微软雅黑),第二个是大小,第三个是加粗(权重是75)
  1049. painter->setFont(esr_font);
  1050. char coordinate_ear[100];
  1051. iv::radar::radarobjectarray xradararray;
  1052. if(mbradarUpdate)
  1053. {
  1054. mMutexRadar.lock();
  1055. xradararray.CopyFrom(mradararray);
  1056. mMutexRadar.unlock();
  1057. for (int a = 0; a < xradararray.obj_size(); a++)
  1058. {
  1059. if (xradararray.obj(a).bvalid())
  1060. {
  1061. painter->drawEllipse(xradararray.obj(a).x() * 10 + 450, -((xradararray.obj(a).y() + ServiceCarStatus.esr_y_offset) * 10) + 700, 10, 10);
  1062. sprintf(coordinate_ear, "(%d, %d)", (int)xradararray.obj(a).x(), (int)xradararray.obj(a).y());
  1063. painter->drawText(xradararray.obj(a).x() * 10 + 450, -((xradararray.obj(a).y() + ServiceCarStatus.esr_y_offset ) * 10) + 700, QString(coordinate_ear));
  1064. }
  1065. }
  1066. // mbradarUpdate = false;
  1067. }
  1068. }
  1069. if(ui->checkBox_9->isChecked())
  1070. {
  1071. ServiceLidar.copylidarto(Lidar_read); //激光雷达障碍物
  1072. ServiceLidar.copylidarobsto(Lidar_obsread);
  1073. painter->setPen(QColor(255, 0, 0));
  1074. for (unsigned int x = 0; x < Lidar_read->size(); x++)
  1075. {
  1076. //painter->drawPoint(((*Lidar_read)[x].nomal_x) * 10 + 450, -(*Lidar_read)[x].nomal_y * 10 + 700);
  1077. }
  1078. painter->setPen(QColor(255,0,0));
  1079. for (unsigned int x = 0; x < Lidar_obsread->size(); x++)
  1080. {
  1081. painter->drawPoint(((*Lidar_obsread)[x].nomal_x) * 10 + 450, -((*Lidar_obsread)[x].nomal_y + ServiceCarStatus.lidar_y_offset) * 10 + 700);
  1082. }
  1083. }
  1084. //////////////////////////////////////
  1085. // //
  1086. // 显示融合的信息 //
  1087. // //
  1088. //////////////////////////////////////
  1089. if(ui->checkBox_10->isChecked())
  1090. {
  1091. painter->setPen(QColor(0,255,0));
  1092. iv::fusion::fusionobjectarray xfusionarray;
  1093. if(mbfusionUpdate)
  1094. {
  1095. mMutexFusion.lock();
  1096. xfusionarray.CopyFrom(mfusionarray);
  1097. mMutexFusion.unlock();
  1098. for(int a = 0; a < xfusionarray.obj_size(); a++)
  1099. {
  1100. for(int b = 0; b < xfusionarray.obj(a).nomal_centroid_size(); b++)
  1101. {
  1102. painter->drawPoint((xfusionarray.obj(a).nomal_centroid(b).nomal_x())*10 + 450, -(xfusionarray.obj(a).nomal_centroid(b).nomal_y())*10 + 700);
  1103. }
  1104. }
  1105. }
  1106. }
  1107. painter->end();
  1108. // painter_small->end();
  1109. scene->clear();
  1110. // scene_small->clear();
  1111. scene->addPixmap(QPixmap::fromImage(*image));
  1112. // scene_small->addPixmap(QPixmap::fromImage(*image_small));
  1113. myview->setScene(scene);
  1114. // myview_small->setScene(scene_small);
  1115. myview->show();
  1116. // myview_small->show();
  1117. navigation_data.clear();
  1118. if(mfSOC != 0.0)
  1119. {
  1120. ui->label_11->setText(QString::number(mfSOC,'f',1));
  1121. }
  1122. }
  1123. }
  1124. /**
  1125. * @brief ADCIntelligentVehicle::on_pb_auto_drive_mode_clicked
  1126. */
  1127. void ADCIntelligentVehicle::on_pb_auto_drive_mode_clicked() {
  1128. is_auto_drive_mode_enable_ = !is_auto_drive_mode_enable_;
  1129. // ServiceCanUtil.startsend(is_auto_drive_mode_enable_);
  1130. ui->pb_auto_drive_mode->setText(is_auto_drive_mode_enable_ ? QStringLiteral("决策控制使能:开") : QStringLiteral("决策控制使能:关"));
  1131. }
  1132. /**
  1133. * @brief ADCIntelligentVehicle::on_pb_auto_braking_mode_clicked
  1134. */
  1135. void ADCIntelligentVehicle::on_pb_auto_braking_mode_clicked() {
  1136. is_auto_braking_mode_enable_ = !is_auto_braking_mode_enable_;
  1137. // ServiceControlStatus.set_turnsignals_control(is_auto_braking_mode_enable_,0);
  1138. ui->pb_auto_braking_mode->setText(is_auto_braking_mode_enable_ ? QStringLiteral("左转向灯:开") : QStringLiteral("左转向灯:关"));
  1139. }
  1140. /**
  1141. * @brief ADCIntelligentVehicle::on_pb_auto_accelerate_mode_clicked
  1142. * QStringLiteral 是Qt5中新引入的一个用来从“字符串常量”创建QString对象的宏
  1143. */
  1144. void ADCIntelligentVehicle::on_pb_auto_accelerate_mode_clicked() {
  1145. is_auto_accelerate_mode_enable_ = !is_auto_accelerate_mode_enable_;
  1146. // ServiceControlStatus.set_turnsignals_control(0,is_auto_accelerate_mode_enable_);
  1147. ui->pb_auto_accelerate_mode->setText(is_auto_accelerate_mode_enable_ ? QStringLiteral("右转向灯:开") : QStringLiteral("右转向灯:关"));
  1148. }
  1149. /**
  1150. * @brief ADCIntelligentVehicle::on_pb_auto_wheel_mode_clicked
  1151. */
  1152. void ADCIntelligentVehicle::on_pb_auto_wheel_mode_clicked() {
  1153. is_auto_wheel_mode_enable_ = !is_auto_wheel_mode_enable_;
  1154. // ServiceControlStatus.set_speaker(is_auto_wheel_mode_enable_);
  1155. ui->pb_auto_wheel_mode->setText(is_auto_wheel_mode_enable_ ? QStringLiteral("喇叭") : QStringLiteral("喇叭"));
  1156. }
  1157. /**
  1158. * @brief ADCIntelligentVehicle::on_pushButton_clicked
  1159. */
  1160. void ADCIntelligentVehicle::on_pushButton_clicked(){
  1161. is_3 = !is_3;
  1162. // ServiceControlStatus.set_light(is_3);
  1163. ui->pushButton->setText(is_3 ? QStringLiteral("近光灯:开") : QStringLiteral("近光灯:关"));
  1164. }
  1165. /**
  1166. * @brief ADCIntelligentVehicle::on_pb_speed_control_mode_clicked
  1167. */
  1168. void ADCIntelligentVehicle::on_pb_speed_control_mode_clicked() {
  1169. is_speed_control_mode_enable_ = !is_speed_control_mode_enable_;
  1170. // if(is_speed_control_mode_enable_==true)
  1171. // ServiceControlStatus.set_engine(0x03);
  1172. // else
  1173. // ServiceControlStatus.set_engine(0x02);
  1174. ui->pb_speed_control_mode->setText(is_speed_control_mode_enable_ ? QStringLiteral("点火:开") : QStringLiteral("点火:关"));
  1175. }
  1176. /**
  1177. * @brief ADCIntelligentVehicle::on_hs_braking_percent_valueChanged
  1178. * @param value
  1179. */
  1180. void ADCIntelligentVehicle::on_hs_braking_percent_valueChanged(int value) {
  1181. //ServiceControlStatus.set_braking((float)value);
  1182. }
  1183. /**
  1184. * @brief ADCIntelligentVehicle::on_hs_accelerate_percent_valueChanged
  1185. * @param value
  1186. */
  1187. void ADCIntelligentVehicle::on_hs_accelerate_percent_valueChanged(int value) {
  1188. //ServiceControlStatus.set_accelerate((float)value);
  1189. }
  1190. /**
  1191. * @brief ADCIntelligentVehicle::on_hs_wheel_angle_valueChanged
  1192. * @param value
  1193. */
  1194. void ADCIntelligentVehicle::on_hs_wheel_angle_valueChanged(int value) {
  1195. //ServiceControlStatus.set_wheel_angle((float)value);
  1196. }
  1197. /**
  1198. * @brief ADCIntelligentVehicle::on_pushButton_3_clicked
  1199. */
  1200. void ADCIntelligentVehicle::on_pushButton_3_clicked(){
  1201. look_decition->show();
  1202. }
  1203. /**
  1204. * @brief ADCIntelligentVehicle::on_pushButton_4_clicked
  1205. */
  1206. void ADCIntelligentVehicle::on_pushButton_4_clicked(){
  1207. mobileye_info->show();
  1208. }
  1209. /**
  1210. * @brief ADCIntelligentVehicle::on_listWidget_clicked
  1211. */
  1212. void ADCIntelligentVehicle::on_listWidget_clicked()
  1213. {
  1214. int currentRow=ui->listWidget->currentRow(); //currentRow()获取当前行号
  1215. if(currentRow==0) //点击第一切换到第一页
  1216. {
  1217. ui->stackedWidget->setCurrentIndex(0);//为堆栈窗体切换到当前索引
  1218. }
  1219. else if(currentRow==1)
  1220. {
  1221. ui->stackedWidget->setCurrentIndex(1);
  1222. }
  1223. else if(currentRow==2)
  1224. {
  1225. ui->stackedWidget->setCurrentIndex(2);
  1226. }
  1227. else
  1228. {
  1229. ui->stackedWidget->setCurrentIndex(0);
  1230. }
  1231. }
  1232. /**
  1233. * @brief ADCIntelligentVehicle::on_pushButton_5_clicked
  1234. */
  1235. void ADCIntelligentVehicle::on_pushButton_5_clicked()//常规速度
  1236. {
  1237. QString normal_speed_ = ui->textEdit->toPlainText();
  1238. // if(normal_speed_!=NULL)
  1239. // ServiceControlStatus.normal_speed = normal_speed_.toInt();
  1240. }
  1241. /**
  1242. * @brief ADCIntelligentVehicle::on_pushButton_6_clicked
  1243. */
  1244. void ADCIntelligentVehicle::on_pushButton_6_clicked()//转弯速度
  1245. {
  1246. QString swerve_speed_ = ui->textEdit_2->toPlainText();
  1247. // if(swerve_speed_!=NULL)
  1248. // ServiceControlStatus.swerve_speed = swerve_speed_.toInt();
  1249. }
  1250. /**
  1251. * @brief ADCIntelligentVehicle::on_pushButton_7_clicked
  1252. */
  1253. void ADCIntelligentVehicle::on_pushButton_7_clicked()//快速
  1254. {
  1255. QString high_speed_ = ui->textEdit_3->toPlainText();
  1256. // if(high_speed_!=NULL)
  1257. // ServiceControlStatus.high_speed = high_speed_.toInt();
  1258. }
  1259. /**
  1260. * @brief ADCIntelligentVehicle::on_pushButton_8_clicked
  1261. */
  1262. void ADCIntelligentVehicle::on_pushButton_8_clicked()//中速
  1263. {
  1264. QString mid_speed_ = ui->textEdit_4->toPlainText();
  1265. // if(mid_speed_!=NULL)
  1266. // ServiceControlStatus.mid_speed = mid_speed_.toInt();
  1267. }
  1268. /**
  1269. * @brief ADCIntelligentVehicle::on_pushButton_9_clicked
  1270. */
  1271. void ADCIntelligentVehicle::on_pushButton_9_clicked()//慢速
  1272. {
  1273. QString low_speed_ = ui->textEdit_5->toPlainText();
  1274. // if(low_speed_!=NULL)
  1275. // ServiceControlStatus.low_speed = low_speed_.toInt();
  1276. }
  1277. /**
  1278. * @brief ADCIntelligentVehicle::UpdatePlanTrace
  1279. * @param strdata
  1280. * @param nSize
  1281. * @param index
  1282. * @param dt
  1283. * @param strmemname
  1284. */
  1285. void ADCIntelligentVehicle::UpdatePlanTrace(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
  1286. {
  1287. mMutexPlan.lock();
  1288. m_plan.clear();
  1289. int nplansize = nSize/sizeof(iv::Point2D);
  1290. int npsize = sizeof(iv::Point2D);
  1291. int i;
  1292. for(i=0;i<nplansize;i++)
  1293. {
  1294. iv::Point2D x;
  1295. memcpy(&x,strdata + i*npsize,npsize);
  1296. m_plan.push_back(x);
  1297. }
  1298. mMutexPlan.unlock();
  1299. }
  1300. void ADCIntelligentVehicle::UpdatePlanTrace_left(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
  1301. {
  1302. mMutexPlan_left.lock();
  1303. m_plan_left.clear();
  1304. int nplansize = nSize/sizeof(iv::Point2D);
  1305. if(nplansize < 1)
  1306. std::cout<<"UpdatePlanTrace_left size is 0................. "<<std::endl;
  1307. // return;
  1308. int npsize = sizeof(iv::Point2D);
  1309. int i;
  1310. for(i=0;i<nplansize;i++)
  1311. {
  1312. iv::Point2D x;
  1313. memcpy(&x,strdata + i*npsize,npsize);
  1314. m_plan_left.push_back(x);
  1315. }
  1316. mMutexPlan_left.unlock();
  1317. }
  1318. void ADCIntelligentVehicle::UpdatePlanTrace_right(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
  1319. {
  1320. mMutexPlan_right.lock();
  1321. m_plan_right.clear();
  1322. int nplansize = nSize/sizeof(iv::Point2D);
  1323. if(nplansize < 1)
  1324. std::cout<<"UpdatePlanTrace_right size is 0................. "<<std::endl;
  1325. int npsize = sizeof(iv::Point2D);
  1326. int i;
  1327. for(i=0;i<nplansize;i++)
  1328. {
  1329. iv::Point2D x;
  1330. memcpy(&x,strdata + i*npsize,npsize);
  1331. m_plan_right.push_back(x);
  1332. }
  1333. mMutexPlan_right.unlock();
  1334. }
  1335. void ADCIntelligentVehicle::UpdateFusion(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
  1336. {
  1337. iv::fusion::fusionobjectarray xfusionarray;
  1338. if(!xfusionarray.ParseFromArray(strdata,nSize))
  1339. {
  1340. gIvlog->warn("ADCIntelligentVehicle::UpdateFusion Parse Error.");
  1341. return;
  1342. }
  1343. mMutexFusion.lock();
  1344. mfusionarray.CopyFrom(xfusionarray);
  1345. mbfusionUpdate = true;
  1346. mMutexFusion.unlock();
  1347. }
  1348. /**
  1349. * @brief ADCIntelligentVehicle::UpdateMap
  1350. * @param strdata
  1351. * @param nSize
  1352. * @param index
  1353. * @param dt
  1354. * @param strmemname
  1355. */
  1356. void ADCIntelligentVehicle::UpdateMap(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
  1357. {
  1358. // std::cout<<"update map "<<std::endl;
  1359. int gpsunitsize = sizeof(iv::GPS_INS);
  1360. int nMapSize = nSize/gpsunitsize;
  1361. // std::cout<<"map size is "<<nMapSize<<std::endl;
  1362. if(nMapSize < 1)return;
  1363. bool bUpdate = false;
  1364. if(nMapSize != m_navigation_data.size())
  1365. {
  1366. bUpdate = true;
  1367. }
  1368. else
  1369. {
  1370. iv::GPS_INS * p = (iv::GPS_INS *)strdata;
  1371. if((p->gps_lat == m_navigation_data.at(0)->gps_lat)&&(p->ins_heading_angle == m_navigation_data.at(0)->ins_heading_angle))
  1372. {
  1373. // qDebug("same map");
  1374. bUpdate = false;
  1375. }
  1376. else
  1377. {
  1378. bUpdate = true;
  1379. }
  1380. }
  1381. if(bUpdate)
  1382. {
  1383. int i;
  1384. mMutexNavi.lock();
  1385. m_navigation_data.clear();
  1386. for(i=0;i<nMapSize;i++)
  1387. {
  1388. iv::GPS_INS x;
  1389. memcpy(&x,strdata + i*gpsunitsize,gpsunitsize);
  1390. iv::GPSData data(new iv::GPS_INS);
  1391. *data = x;
  1392. m_navigation_data.push_back(data);
  1393. }
  1394. mMutexNavi.unlock();
  1395. if(m_navigation_data.size()>0)
  1396. {
  1397. mDataToUI.mInfo.is_mapLoad = 1;
  1398. }
  1399. else
  1400. {
  1401. mDataToUI.mInfo.is_mapLoad = 0;
  1402. }
  1403. }
  1404. else
  1405. {
  1406. // qDebug("not need update");
  1407. }
  1408. }
  1409. //=======================zhaobo0904
  1410. #define PI 3.14159265358979
  1411. /**
  1412. * @brief GaussProjCal
  1413. * @param lon
  1414. * @param lat
  1415. * @param X
  1416. * @param Y
  1417. */
  1418. /*
  1419. void GaussProjCal(double lon, double lat, double *X, double *Y)
  1420. {
  1421. // 1975 年国际椭球体长半轴 a, 第一离心率 e2, 第二离心率 ep2
  1422. double a = 6378140.0;
  1423. double e2 = 0.006694384999588;
  1424. double ep2 = e2/(1-e2);
  1425. // 原点所在经度
  1426. double lon_origin = 6.0*int(lon/6) + 3.0;
  1427. lon_origin *= PI / 180.0;
  1428. double k0 = 0.9996;
  1429. // 角度转弧度
  1430. double lat1 = lat * PI / 180.0;
  1431. double lon1 = lon * PI / 180.0;
  1432. // 经线在该点处的曲率半径,
  1433. double N = a / sqrt(1 - e2*sin(lat1)*sin(lat1));
  1434. // 赤道到该点的经线长度近似值 M, 使用泰勒展开逐项积分然后取前四项.
  1435. // 这个近似值是将 N 作为纬度 \phi 的函数展开为泰勒计数, 然后在区间 [0, lat1] 上积分得到的.
  1436. // 首先计算前四项的系数 a1~a4.
  1437. double a1 = 1 - e2/4 - (3*e2*e2)/64 - (5*e2*e2*e2)/256;
  1438. double a2 = (3*e2)/8 + (3*e2*e2)/32 + (45*e2*e2*e2)/1024;
  1439. double a3 = (15*e2*e2)/256 + (45*e2*e2*e2)/1024;
  1440. double a4 = (35*e2*e2*e2)/3072;
  1441. double M = a * (a1*lat1 - a2*sin(2*lat1) + a3*sin(4*lat1) - a4*sin(6*lat1));
  1442. // 辅助量
  1443. double T = tan(lat1)*tan(lat1);
  1444. double C = ep2*cos(lat1)*cos(lat1);
  1445. double A = (lon1 - lon_origin)*cos(lat1);
  1446. *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);
  1447. *Y = M + N * tan(lat1) * ((A*A)/2 +
  1448. (5 - T + 9*C + 4*C*C)*(A*A*A*A)/24 +
  1449. (61 - 58*T + T*T + 600*C - 330*ep2)*(A*A*A*A*A*A)/720);
  1450. *Y *= k0;
  1451. return;
  1452. }
  1453. */
  1454. //高斯投影由经纬度(Unit:DD)反算大地坐标(含带号,Unit:Metres)
  1455. void GaussProjCal(double longitude, double latitude, double *X, double *Y)
  1456. {
  1457. int ProjNo = 0; int ZoneWide; ////带宽
  1458. double longitude1, latitude1, longitude0, latitude0, X0, Y0, xval, yval;
  1459. double a, f, e2, ee, NN, T, C, A, M, iPI;
  1460. iPI = 0.0174532925199433; ////3.1415926535898/180.0;
  1461. ZoneWide = 6; ////6度带宽
  1462. a = 6378245.0; f = 1.0 / 298.3; //54年北京坐标系参数
  1463. ////a=6378140.0; f=1/298.257; //80年西安坐标系参数
  1464. ProjNo = (int)(longitude / ZoneWide);
  1465. longitude0 = ProjNo * ZoneWide + ZoneWide / 2;
  1466. longitude0 = longitude0 * iPI;
  1467. latitude0 = 0;
  1468. longitude1 = longitude * iPI; //经度转换为弧度
  1469. latitude1 = latitude * iPI; //纬度转换为弧度
  1470. e2 = 2 * f - f * f;
  1471. ee = e2 * (1.0 - e2);
  1472. NN = a / sqrt(1.0 - e2 * sin(latitude1)*sin(latitude1));
  1473. T = tan(latitude1)*tan(latitude1);
  1474. C = ee * cos(latitude1)*cos(latitude1);
  1475. A = (longitude1 - longitude0)*cos(latitude1);
  1476. 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
  1477. *e2 / 1024)*sin(2 * latitude1)
  1478. + (15 * e2*e2 / 256 + 45 * e2*e2*e2 / 1024)*sin(4 * latitude1) - (35 * e2*e2*e2 / 3072)*sin(6 * latitude1));
  1479. 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);
  1480. yval = M + NN * tan(latitude1)*(A*A / 2 + (5 - T + 9 * C + 4 * C*C)*A*A*A*A / 24
  1481. + (61 - 58 * T + T * T + 600 * C - 330 * ee)*A*A*A*A*A*A / 720);
  1482. X0 = 1000000L * (ProjNo + 1) + 500000L;
  1483. Y0 = 0;
  1484. xval = xval + X0; yval = yval + Y0;
  1485. *X = xval;
  1486. *Y = yval;
  1487. }
  1488. //高斯投影由大地坐标(Unit:Metres)反算经纬度(Unit:DD)
  1489. void GaussProjInvCal(double X, double Y, double *longitude, double *latitude)
  1490. {
  1491. int ProjNo; int ZoneWide; ////带宽
  1492. double longitude1, latitude1, longitude0, latitude0, X0, Y0, xval, yval;
  1493. double e1, e2, f, a, ee, NN, T, C, M, D, R, u, fai, iPI;
  1494. iPI = 0.0174532925199433; ////3.1415926535898/180.0;
  1495. a = 6378245.0; f = 1.0 / 298.3; //54年北京坐标系参数
  1496. ////a=6378140.0; f=1/298.257; //80年西安坐标系参数
  1497. ZoneWide = 6; ////6度带宽
  1498. ProjNo = (int)(X / 1000000L); //查找带号
  1499. longitude0 = (ProjNo - 1) * ZoneWide + ZoneWide / 2;
  1500. longitude0 = longitude0 * iPI; //中央经线
  1501. X0 = ProjNo * 1000000L + 500000L;
  1502. Y0 = 0;
  1503. xval = X - X0; yval = Y - Y0; //带内大地坐标
  1504. e2 = 2 * f - f * f;
  1505. e1 = (1.0 - sqrt(1 - e2)) / (1.0 + sqrt(1 - e2));
  1506. ee = e2 / (1 - e2);
  1507. M = yval;
  1508. u = M / (a*(1 - e2 / 4 - 3 * e2*e2 / 64 - 5 * e2*e2*e2 / 256));
  1509. fai = u + (3 * e1 / 2 - 27 * e1*e1*e1 / 32)*sin(2 * u) + (21 * e1*e1 / 16 - 55 * e1*e1*e1*e1 / 32)*sin(
  1510. 4 * u)
  1511. + (151 * e1*e1*e1 / 96)*sin(6 * u) + (1097 * e1*e1*e1*e1 / 512)*sin(8 * u);
  1512. C = ee * cos(fai)*cos(fai);
  1513. T = tan(fai)*tan(fai);
  1514. NN = a / sqrt(1.0 - e2 * sin(fai)*sin(fai));
  1515. R = a * (1 - e2) / sqrt((1 - e2 * sin(fai)*sin(fai))*(1 - e2 * sin(fai)*sin(fai))*(1 - e2 * sin
  1516. (fai)*sin(fai)));
  1517. D = xval / NN;
  1518. //计算经度(Longitude) 纬度(Latitude)
  1519. 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
  1520. *D*D*D*D / 120) / cos(fai);
  1521. latitude1 = fai - (NN*tan(fai) / R)*(D*D / 2 - (5 + 3 * T + 10 * C - 4 * C*C - 9 * ee)*D*D*D*D / 24
  1522. + (61 + 90 * T + 298 * C + 45 * T*T - 256 * ee - 3 * C*C)*D*D*D*D*D*D / 720);
  1523. //转换为度 DD
  1524. *longitude = longitude1 / iPI;
  1525. *latitude = latitude1 / iPI;
  1526. }
  1527. //==========================================================
  1528. /**
  1529. * @brief ADCIntelligentVehicle::UpdateGPSIMU
  1530. * @param strdata
  1531. * @param nSize
  1532. * @param index
  1533. * @param dt
  1534. * @param strmemname
  1535. */
  1536. void ADCIntelligentVehicle::UpdateGPSIMU(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
  1537. {
  1538. iv::gps::gpsimu xgpsimu;
  1539. if(!xgpsimu.ParseFromArray(strdata,nSize))
  1540. {
  1541. gIvlog->warn("ADCIntelligentVehicle::UpdateGPSIMU parse error. nSize is %d",nSize);
  1542. return;
  1543. }
  1544. iv::GPSData data(new iv::GPS_INS);
  1545. data->gps_lat = xgpsimu.lat();
  1546. data->gps_lng = xgpsimu.lon();
  1547. data->ins_heading_angle = xgpsimu.heading();
  1548. data->rtk_status = xgpsimu.rtk_state();
  1549. data->ins_status = xgpsimu.ins_state();
  1550. data->vel_D = xgpsimu.vd(); //地向速度,单位(米/秒)
  1551. data->vel_E = xgpsimu.ve(); //东向速度,单位(米/秒)
  1552. data->vel_N = xgpsimu.vn(); //北向速度,单位(米/秒)
  1553. GaussProjCal(data->gps_lng,data->gps_lat,&data->gps_x,&data->gps_y);
  1554. ServiceCarStatus.mRTKStatus = data->rtk_status;
  1555. ServiceCarStatus.speed = data->speed;
  1556. ServiceCarStatus.location->gps_lat = data->gps_lat;
  1557. ServiceCarStatus.location->gps_lng = data->gps_lng;
  1558. ServiceCarStatus.location->ins_heading_angle = data->ins_heading_angle;
  1559. ServiceCarStatus.location->gps_x = data->gps_x;
  1560. ServiceCarStatus.location->gps_y = data->gps_y;
  1561. ServiceCarStatus.location->rtk_status = data->rtk_status;
  1562. ServiceCarStatus.location->ins_status = data->ins_status;
  1563. ServiceCarStatus.speed = sqrt(pow(data->vel_E,2)+pow(data->vel_N,2)) * 3.6; //double pow(double x, double y) 返回 x 的 y 次幂,即 xy。
  1564. mnTimeUpdateGPS = mTimeState.elapsed();
  1565. }
  1566. /**
  1567. * @brief ADCIntelligentVehicle::UpdateRADAR
  1568. * @param strdata
  1569. * @param nSize
  1570. * @param index
  1571. * @param dt
  1572. * @param strmemname
  1573. */
  1574. void ADCIntelligentVehicle::UpdateRADAR(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
  1575. {
  1576. static qint64 oldrecvtime;
  1577. iv::radar::radarobjectarray xradararray;
  1578. if(!xradararray.ParseFromArray(strdata,nSize))
  1579. {
  1580. gIvlog->warn("ADCIntelligentVehicle::UpdateRADAR Parse Error.");
  1581. return;
  1582. }
  1583. // gIvlog->verbose("radar time is %ld",QDateTime::currentMSecsSinceEpoch());
  1584. if((QDateTime::currentMSecsSinceEpoch() - oldrecvtime)>100)
  1585. {
  1586. gIvlog->warn("radar interval is more than 100ms. value is %ld",QDateTime::currentMSecsSinceEpoch() - oldrecvtime);
  1587. }
  1588. oldrecvtime = QDateTime::currentMSecsSinceEpoch();
  1589. mMutexRadar.lock();
  1590. mradararray.CopyFrom(xradararray);
  1591. mbradarUpdate = true;
  1592. mMutexRadar.unlock();
  1593. // int i;
  1594. // for(i=0;i<64;i++)
  1595. // {
  1596. // iv::ObstacleBasic x;
  1597. // memcpy(&x,pdata + i*sizeof(iv::ObstacleBasic),sizeof(iv::ObstacleBasic));
  1598. // ServiceCarStatus.obs_radar[i] = x;
  1599. // }
  1600. ServiceCarStatus.mRadarS = 10;
  1601. // mnTimeUpdateRadar = mTimeState.elapsed();
  1602. // mnTimeUpdateCANState = mTimeState.elapsed();
  1603. }
  1604. /**
  1605. * @brief ADCIntelligentVehicle::UpdateCANState
  1606. * @param pdata
  1607. * @param ndatasize
  1608. */
  1609. void ADCIntelligentVehicle::UpdateCANState(const char *pdata, const int ndatasize)
  1610. {
  1611. iv::canstate::canstate recCanstate;
  1612. if(!recCanstate.ParseFromArray(pdata, ndatasize))
  1613. {
  1614. gIvlog->warn("ADCIntelligentVehicle::updateCanstate error");
  1615. return;
  1616. }
  1617. // if(ndatasize<sizeof(iv::can_state))return;
  1618. // char ccanstate[ndatasize];
  1619. // memcpy(ccanstate,pdata,4);
  1620. #if 1
  1621. if(recCanstate.b_canstate())
  1622. {
  1623. // gIvlog->debug("UpdateCANState<success>");
  1624. mDataToUI.mInfo.is_initSuccess = 1;
  1625. }
  1626. else
  1627. {
  1628. // gIvlog->debug("UpdateCANState<failed>size %d %s ");
  1629. mDataToUI.mInfo.is_initSuccess = 0;
  1630. }
  1631. #endif
  1632. // iv::can_state x;
  1633. // memcpy(&x,pdata,sizeof(iv::can_state));
  1634. // if(x.mbCANOpen)
  1635. // {
  1636. // mDataToUI.mInfo.is_initSuccess = 1;
  1637. // }
  1638. // else
  1639. // {
  1640. // mDataToUI.mInfo.is_initSuccess = 0;
  1641. // }
  1642. }
  1643. /**
  1644. * @brief ADCIntelligentVehicle::UpdateDecition
  1645. * @param strdata
  1646. * @param nSize
  1647. * @param index
  1648. * @param dt
  1649. * @param strmemname
  1650. */
  1651. void ADCIntelligentVehicle::UpdateDecition(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
  1652. {
  1653. iv::brain::decition xdecition;
  1654. if(!xdecition.ParseFromArray(strdata,nSize))
  1655. {
  1656. gIvlog->warn("ADCIntelligentVehicle::UpdateDecition parse errror. nSize is %d",nSize);
  1657. return;
  1658. }
  1659. //ServiceCarStatus.mfAcc = xdecition.accelerator(); //
  1660. ServiceCarStatus.mfAcc = xdecition.torque(); //
  1661. ServiceCarStatus.mfBrake = xdecition.brake();
  1662. ServiceCarStatus.mfWheel = xdecition.wheelangle();
  1663. ServiceCarStatus.mfttc = xdecition.ttc();
  1664. mnTimeUpdateDecition = mTimeState.elapsed();
  1665. }
  1666. /**
  1667. * @brief ADCIntelligentVehicle::UpdateVehicleState
  1668. * @param strdata
  1669. * @param nSize
  1670. * @param index
  1671. * @param dt
  1672. * @param strmemname
  1673. */
  1674. void ADCIntelligentVehicle::UpdateVehicleState(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
  1675. {
  1676. iv::brain::brainstate xbrainstate;
  1677. if(!xbrainstate.ParseFromArray(strdata,nSize))
  1678. {
  1679. gIvlog->warn("ADCIntelligentVehicle::UpdateVehicleState parse error,nSize is %d ",nSize);
  1680. return;
  1681. }
  1682. ServiceCarStatus.bocheEnable = xbrainstate.mbbocheenable();
  1683. ServiceCarStatus.mObs = xbrainstate.mfobs();
  1684. ServiceCarStatus.mLidarObs = xbrainstate.mflidarobs();
  1685. ServiceCarStatus.mRadarObs = xbrainstate.mfradarobs();
  1686. mbBrainRunning = xbrainstate.mbbrainrunning();
  1687. ServiceCarStatus.mbBrainCtring = xbrainstate.mbbrainrunning();
  1688. mdecition_period = xbrainstate.decision_period();
  1689. mnTimeUpdateVS = mTimeState.elapsed();
  1690. }
  1691. /**
  1692. * @brief ADCIntelligentVehicle::UpdateOBS
  1693. * @param lidar_obs
  1694. */
  1695. void ADCIntelligentVehicle::UpdateOBS(std::shared_ptr<std::vector<iv::ObstacleBasic> > lidar_obs)
  1696. {
  1697. iv::ObsLiDAR _obs_grid_ = boost::shared_ptr<std::vector<iv::ObstacleBasic>>(new std::vector<iv::ObstacleBasic>);
  1698. int i;
  1699. int nSize = lidar_obs->size();
  1700. for(i=0;i<nSize;i++)
  1701. _obs_grid_->push_back(lidar_obs->at(i));
  1702. ServiceLidar.copyfromlidarobs(_obs_grid_);
  1703. ServiceCarStatus.mLidarS = 10;
  1704. }
  1705. void ADCIntelligentVehicle::UpdateV2xStEn(unsigned int enable)
  1706. {
  1707. iv::v2x::v2xStEn x;
  1708. x.set_v2xsten(enable);
  1709. int nsize = x.ByteSize();
  1710. char * str = new char[nsize];
  1711. if(x.SerializeToArray(str,nsize))
  1712. {
  1713. iv::modulecomm::ModuleSendMsg(mp_v2xStSend,str,nsize);
  1714. }
  1715. else
  1716. {
  1717. gIvlog->error("hmi","send enable st error");
  1718. }
  1719. delete str;
  1720. }
  1721. /**
  1722. * @brief ADCIntelligentVehicle::ShareHMIMsg
  1723. * @param xhmi
  1724. */
  1725. void ADCIntelligentVehicle::ShareHMIMsg(iv::hmi::HMIBasic xhmi)
  1726. {
  1727. iv::hmi::hmimsg xhmimsg;
  1728. xhmimsg.set_mbpause(xhmi.mbPause);
  1729. xhmimsg.set_mbbusmode(xhmi.mbbusmode);
  1730. xhmimsg.set_mbbochemode(xhmi.mbBocheMode);
  1731. int nsize = xhmimsg.ByteSize();
  1732. char * str = new char[nsize];
  1733. std::shared_ptr<char> pstr;
  1734. pstr.reset(str); //将就对象的引用计数减1(当然,如果发现引用计数为0时,则析构旧对象),然后将新对象的指针交给智能指针保管。这样做可以省略了delete的过程。
  1735. if(!xhmimsg.SerializeToArray(str,nsize))
  1736. {
  1737. std::cout<<"ADCIntelligentVehicle::ShareHMIMsg serialize error."<<std::endl;
  1738. mpivlog->error("ADCIntelligentVehicle::ShareHMIMsg serialize error.");
  1739. return;
  1740. }
  1741. iv::modulecomm::ModuleSendMsg(mpaHMI,str,nsize);
  1742. }
  1743. void ADCIntelligentVehicle::UpdateChassis(const char *strdata, const unsigned int nSize, const unsigned int index, const QDateTime *dt, const char *strmemname)
  1744. {
  1745. iv::chassis xchassis;
  1746. static int ncount = 0;
  1747. if(!xchassis.ParseFromArray(strdata,nSize))
  1748. {
  1749. std::cout<<"iv::decition::BrainDecition::UpdateChassis ParseFrom Array Error."<<std::endl;
  1750. return;
  1751. }
  1752. if((xchassis.has_epsmode())&&(xchassis.epsmode() == 0))
  1753. {
  1754. ServiceCarStatus.mbRunPause = true;
  1755. }
  1756. if((xchassis.has_soc()))
  1757. {
  1758. mfSOC = xchassis.soc();
  1759. }
  1760. }
  1761. void ADCIntelligentVehicle::onTimerManual()
  1762. {
  1763. // if(myview->mPressKeys.count() == 0)return;
  1764. if(mbManual == false)
  1765. {
  1766. if(myview->mPressKeys.contains(Qt::Key_J))
  1767. {
  1768. mbManual = true;
  1769. }
  1770. }
  1771. if(mbManual == true)
  1772. {
  1773. if(myview->mPressKeys.contains(Qt::Key_K))
  1774. {
  1775. mbManual = false;
  1776. }
  1777. }
  1778. if(mbManual == false)return;
  1779. int timediff = mManualTime.elapsed() - mnLastManualTime;
  1780. mnLastManualTime = mManualTime.elapsed();
  1781. if(myview->mPressKeys.contains(Qt::Key_W))
  1782. {
  1783. if(mnCtrlValue[0]<1000)mnCtrlValue[0] = mnCtrlValue[0] + 5 * timediff /20;
  1784. }
  1785. if(myview->mPressKeys.contains(Qt::Key_S))
  1786. {
  1787. mnCtrlValue[0] = 0;
  1788. if(mnCtrlValue[1]<990) mnCtrlValue[1] = mnCtrlValue[1] + 10* timediff /20;
  1789. }
  1790. else
  1791. {
  1792. mnCtrlValue[1] = 0;
  1793. }
  1794. if(myview->mPressKeys.contains(Qt::Key_A))
  1795. {
  1796. if(mnCtrlValue[2]<500)mnCtrlValue[2] = mnCtrlValue[2] + 3* timediff /20;
  1797. }
  1798. if(myview->mPressKeys.contains(Qt::Key_D))
  1799. {
  1800. if(mnCtrlValue[2]>-500)mnCtrlValue[2] = mnCtrlValue[2] - 3* timediff /20;
  1801. }
  1802. iv::modulecomm::ModuleSendMsg(mpManualCtrl,(char *)mnCtrlValue,3*sizeof(int));
  1803. }
  1804. void ADCIntelligentVehicle::onCtrlManual(bool bCtrl)
  1805. {
  1806. mbManual = bCtrl;
  1807. if(bCtrl)
  1808. {
  1809. mTimerManual->start(10);
  1810. mManualTime.start();
  1811. mnLastManualTime = mManualTime.elapsed();
  1812. }
  1813. else
  1814. {
  1815. mTimerManual->stop();
  1816. mnCtrlValue[0] = 0; mnCtrlValue[1] = 0; mnCtrlValue[2] = 0;
  1817. }
  1818. }
  1819. void ADCIntelligentVehicle::on_pb_v2xEn_clicked()
  1820. {
  1821. qDebug()<<mv2xStEn;
  1822. if(mv2xStEn){
  1823. ui->pb_v2xEn->setText("云平台控制:关");
  1824. mv2xStEn = 0;
  1825. }
  1826. else{
  1827. ui->pb_v2xEn->setText("云平台控制:开");
  1828. mv2xStEn = 1;
  1829. }
  1830. gIvlog->info("hmi","v2x enable:%d", mv2xStEn);
  1831. UpdateV2xStEn(mv2xStEn);
  1832. }
  1833. void ADCIntelligentVehicle::shareMapReqMsg()
  1834. {
  1835. iv::map::mapreq x;
  1836. x.set_maptype(1);
  1837. int nsize = x.ByteSize();
  1838. char * str = new char[nsize];
  1839. if(x.SerializeToArray(str,nsize))
  1840. {
  1841. iv::modulecomm::ModuleSendMsg(mpamapreq,str,nsize);
  1842. }
  1843. else
  1844. {
  1845. std::cout<<"iv::map::mapreq serialize error."<<std::endl;
  1846. }
  1847. std::cout<<"iv::map::mapreq serialize OK."<<std::endl;
  1848. delete str;
  1849. }
  1850. void ADCIntelligentVehicle::UpdateVbox(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
  1851. {
  1852. iv::vbox::vbox xvbox;
  1853. if(!xvbox.ParseFromArray(strdata,nSize))
  1854. {
  1855. gIvlog->warn("ADCIntelligentVehicle::UpdateVbox parse errror. nSize is %d",nSize);
  1856. return;
  1857. }
  1858. ServiceCarStatus.st_straight = xvbox.st_straight();
  1859. ServiceCarStatus.st_left = xvbox.st_left();
  1860. ServiceCarStatus.st_right = xvbox.st_right();
  1861. ServiceCarStatus.st_turn = xvbox.st_turn();
  1862. ServiceCarStatus.time_straight = xvbox.time_straight();
  1863. ServiceCarStatus.time_left = xvbox.time_left();
  1864. ServiceCarStatus.time_right = xvbox.time_right();
  1865. ServiceCarStatus.time_turn = xvbox.time_turn();
  1866. }
  1867. void ADCIntelligentVehicle::onStateTimer1()
  1868. {
  1869. ui->lcdNumber->display((int)ServiceCarStatus.time_turn);
  1870. ui->lcdNumber_2->display((int)ServiceCarStatus.time_left);
  1871. ui->lcdNumber_3->display((int)ServiceCarStatus.time_straight);
  1872. ui->lcdNumber_4->display((int)ServiceCarStatus.time_right);
  1873. switch (ServiceCarStatus.st_turn) {
  1874. case 0:
  1875. img.load(":/light_image/diaotou-black.png");
  1876. img = img.scaled(66,66,Qt::IgnoreAspectRatio);
  1877. ui->label_38->setPixmap(QPixmap::fromImage(img));
  1878. break;
  1879. case 1:
  1880. img.load(":/light_image/diaotou-green.png");
  1881. img = img.scaled(66,66,Qt::IgnoreAspectRatio);
  1882. ui->label_38->setPixmap(QPixmap::fromImage(img));
  1883. break;
  1884. case 2:
  1885. img.load(":/light_image/diaotou-red.png");
  1886. img = img.scaled(66,66,Qt::IgnoreAspectRatio);
  1887. ui->label_38->setPixmap(QPixmap::fromImage(img));
  1888. break;
  1889. case 3:
  1890. img.load(":/light_image/diaotou-yellow.png");
  1891. img = img.scaled(66,66,Qt::IgnoreAspectRatio);
  1892. ui->label_38->setPixmap(QPixmap::fromImage(img));
  1893. break;
  1894. default:
  1895. img.load(":/light_image/diaotou-black.png");
  1896. img = img.scaled(66,66,Qt::IgnoreAspectRatio);
  1897. ui->label_38->setPixmap(QPixmap::fromImage(img));
  1898. break;
  1899. }
  1900. switch (ServiceCarStatus.st_left) {
  1901. case 0:
  1902. img2.load(":/light_image/zuoguai-black.png");
  1903. img2 = img2.scaled(66,66,Qt::IgnoreAspectRatio);
  1904. ui->label_33->setPixmap(QPixmap::fromImage(img2));
  1905. break;
  1906. case 1:
  1907. img2.load(":/light_image/zuoguai-green.png");
  1908. img2 = img2.scaled(66,66,Qt::IgnoreAspectRatio);
  1909. ui->label_33->setPixmap(QPixmap::fromImage(img2));
  1910. break;
  1911. case 2:
  1912. img2.load(":/light_image/zuoguai-red.png");
  1913. img2 = img2.scaled(66,66,Qt::IgnoreAspectRatio);
  1914. ui->label_33->setPixmap(QPixmap::fromImage(img2));
  1915. break;
  1916. case 3:
  1917. img2.load(":/light_image/zuoguai-yellow.png");
  1918. img2 = img2.scaled(66,66,Qt::IgnoreAspectRatio);
  1919. ui->label_33->setPixmap(QPixmap::fromImage(img2));
  1920. break;
  1921. default:
  1922. img2.load(":/light_image/zuoguai-black.png");
  1923. img2 = img2.scaled(66,66,Qt::IgnoreAspectRatio);
  1924. ui->label_33->setPixmap(QPixmap::fromImage(img2));
  1925. break;
  1926. }
  1927. switch (ServiceCarStatus.st_straight) {
  1928. case 0:
  1929. img3.load(":/light_image/zhixing-black.png");
  1930. img3 = img3.scaled(66,66,Qt::IgnoreAspectRatio);
  1931. ui->label_35->setPixmap(QPixmap::fromImage(img3));
  1932. break;
  1933. case 1:
  1934. img3.load(":/light_image/zhixing-green.png");
  1935. img3 = img3.scaled(66,66,Qt::IgnoreAspectRatio);
  1936. ui->label_35->setPixmap(QPixmap::fromImage(img3));
  1937. break;
  1938. case 2:
  1939. img3.load(":/light_image/zhixing-red.png");
  1940. img3 = img3.scaled(66,66,Qt::IgnoreAspectRatio);
  1941. ui->label_35->setPixmap(QPixmap::fromImage(img3));
  1942. break;
  1943. case 3:
  1944. img3.load(":/light_image/zhixing-yellow.png");
  1945. img3 = img3.scaled(66,66,Qt::IgnoreAspectRatio);
  1946. ui->label_35->setPixmap(QPixmap::fromImage(img3));
  1947. break;
  1948. default:
  1949. img3.load(":/light_image/zhixing-black.png");
  1950. img3 = img3.scaled(66,66,Qt::IgnoreAspectRatio);
  1951. ui->label_35->setPixmap(QPixmap::fromImage(img3));
  1952. break;
  1953. }
  1954. switch (ServiceCarStatus.st_right) {
  1955. case 0:
  1956. img4.load(":/light_image/youguai-black.png");
  1957. img4 = img4.scaled(66,66,Qt::IgnoreAspectRatio);
  1958. ui->label_32->setPixmap(QPixmap::fromImage(img4));
  1959. break;
  1960. case 1:
  1961. img4.load(":/light_image/youguai-green.png");
  1962. img4 = img4.scaled(66,66,Qt::IgnoreAspectRatio);
  1963. ui->label_32->setPixmap(QPixmap::fromImage(img4));
  1964. break;
  1965. case 2:
  1966. img4.load(":/light_image/youguai-red.png");
  1967. img4 = img4.scaled(66,66,Qt::IgnoreAspectRatio);
  1968. ui->label_32->setPixmap(QPixmap::fromImage(img4));
  1969. break;
  1970. case 3:
  1971. img4.load(":/light_image/youguai-yellow.png");
  1972. img4 = img4.scaled(66,66,Qt::IgnoreAspectRatio);
  1973. ui->label_32->setPixmap(QPixmap::fromImage(img4));
  1974. break;
  1975. default:
  1976. img4.load(":/light_image/youguai-black.png");
  1977. img4 = img4.scaled(66,66,Qt::IgnoreAspectRatio);
  1978. ui->label_32->setPixmap(QPixmap::fromImage(img4));
  1979. break;
  1980. }
  1981. }