ADCIntelligentVehicle.cpp 74 KB

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