ADCIntelligentVehicle.cpp 97 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794
  1. #include "ADCIntelligentVehicle.h"
  2. #include "chassis.pb.h"
  3. #include "xmlparam.h"
  4. #include <thread>
  5. #define qtcout qDebug() << "[ " << __FILE__ << ":" << __LINE__<< " ]";
  6. extern std::string gstrmemgps;
  7. extern std::string gstrvehtype;
  8. /**
  9. 常量 值 描述
  10. QHostAddress::Null 0 空地址对象,相当于QHostAddress()。
  11. QHostAddress::LocalHost 2 IPv4本地主机地址,相当于QHostAddress(“127.0.0.1”)。
  12. QHostAddress::LocalHostIPv6 3 IPv6本地主机地址,相当于 QHostAddress(“::1”)。
  13. QHostAddress::Broadcast 1 Pv4广播地址,相当于QHostAddress(“255.255.255.255”)。
  14. QHostAddress::AnyIPv4 6 IPv4 any-address,相当于QHostAddress(“0.0.0.0”)。与该地址绑定的socket将只监听IPv4接口。
  15. QHostAddress::AnyIPv6 5 IPv6 any-address,相当于QHostAddress(“::”)。与该地址绑定的socket将只监听IPv4接口。
  16. QHostAddress::Any 4 双any-address栈,与该地址绑定的socket将侦听IPv4和IPv6接口。
  17. */
  18. #define VIEW_CENTER viewport()->rect().center()
  19. const double PI = 3.1415926535898;
  20. extern iv::Ivlog * gIvlog;
  21. /**
  22. * @brief MyView::MyView
  23. * @param parent
  24. */
  25. MyView::MyView(QWidget *parent) :
  26. QGraphicsView(parent),
  27. beishu(1.00000)
  28. {
  29. setDragMode(QGraphicsView::ScrollHandDrag); //设置视图的拖拽模式 (光标变为指向手,然后拖动鼠标将滚动滚动条,此模式在交互和非交互模式下均有效)
  30. }
  31. /**
  32. * @brief MyView::mousePressEvent
  33. * @param event
  34. */
  35. void MyView::mousePressEvent(QMouseEvent *event)
  36. {
  37. bottonstatus = true;
  38. QGraphicsView::mousePressEvent(event);
  39. }
  40. /**
  41. * @brief MyView::mouseMoveEvent
  42. * @param event
  43. */
  44. void MyView::mouseMoveEvent(QMouseEvent *event)
  45. {
  46. QGraphicsView::mouseMoveEvent(event);
  47. }
  48. void MyView::keyPressEvent(QKeyEvent *event)
  49. {
  50. //按键按下,key值放入容器,如果是长按触发的repeat就不判断
  51. if(!event->isAutoRepeat())
  52. mPressKeys.insert(event->key());
  53. if(event->key() == Qt::Key_J)
  54. {
  55. emit CtrlManual(true);
  56. }
  57. if(event->key() == Qt::Key_K)
  58. {
  59. emit CtrlManual(false);
  60. }
  61. // qDebug("key count is %d",mPressKeys.count());
  62. // QDateTime dt;
  63. // qDebug("key press %ld",QDateTime::currentMSecsSinceEpoch());
  64. // qDebug(" key is %d",event->key());
  65. }
  66. void MyView::keyReleaseEvent(QKeyEvent *event)
  67. {
  68. if(!event->isAutoRepeat())mPressKeys.remove(event->key());
  69. qDebug("key count is %d",mPressKeys.count());
  70. // QDateTime dt;
  71. // qDebug("key release %ld",QDateTime::currentMSecsSinceEpoch());
  72. }
  73. /**
  74. * @brief MyView::mouseReleaseEvent
  75. * @param event
  76. */
  77. void MyView::mouseReleaseEvent(QMouseEvent *event)
  78. {
  79. bottonstatus = false;
  80. QGraphicsView::mouseReleaseEvent(event);
  81. }
  82. ADCIntelligentVehicle * gAV;
  83. //void ListenTraceMap(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
  84. //{
  85. // gAV->UpdateMap(strdata,nSize);
  86. //}
  87. // void Listengpsimu(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
  88. // {
  89. // gAV->UpdateGPSIMU(strdata,nSize);
  90. // }
  91. // void ListenRadar(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
  92. // {
  93. // gAV->UpdateRADAR(strdata,nSize);
  94. // }
  95. /**
  96. * @brief ListenCANState
  97. * @param strdata
  98. * @param nSize
  99. * @param index
  100. * @param dt
  101. * @param strmemname
  102. */
  103. void ListenCANState(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
  104. {
  105. // gIvlog->debug("ListenCanState");
  106. gAV->UpdateCANState(strdata,nSize);
  107. }
  108. //void ListenDecition(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
  109. //{
  110. // gAV->UpdateDecition(strdata,nSize);
  111. //}
  112. //void ListenVehicleState(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
  113. //{
  114. // gAV->UpdateVehicleState(strdata,nSize);
  115. //}
  116. /**
  117. * @brief ListenOBS
  118. * @param strdata
  119. * @param nSize
  120. * @param index
  121. * @param dt
  122. * @param strmemname
  123. */
  124. void ListenOBS(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
  125. {
  126. // qDebug("size is %d",nSize);
  127. std::shared_ptr<std::vector<iv::ObstacleBasic>> lidar_obs(new std::vector<iv::ObstacleBasic>);
  128. iv::ObstacleBasic * pdata = (iv::ObstacleBasic *)strdata;
  129. int nCount = nSize/sizeof(iv::ObstacleBasic);
  130. int i;
  131. for(i=0;i<nCount;i++)
  132. {
  133. iv::ObstacleBasic temp;
  134. memcpy(&temp,pdata,sizeof(iv::ObstacleBasic));
  135. lidar_obs->push_back(temp);
  136. pdata++;
  137. }
  138. gAV->UpdateOBS(lidar_obs);
  139. // gw->UpdateOBS(lidar_obs);
  140. }
  141. //v2x使能状态请求
  142. void ListenV2xStReq(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
  143. {
  144. // gIvlog->info("hmi", "v2x enable request %d %d",nSize,sizeof(iv::v2x::v2xStReq));
  145. // if(nSize < sizeof(iv::v2x::v2xStReq))
  146. // return;
  147. iv::v2x::v2xStReq xv2xStReqMsg;
  148. if(!xv2xStReqMsg.ParseFromArray(strdata,nSize))
  149. {
  150. gIvlog->error("hmi", "iv::v2x::xv2xStReqMsg::ListenV2xStReq parse error");
  151. return;
  152. }
  153. if(xv2xStReqMsg.v2xstreq())
  154. {
  155. gAV->UpdateV2xStEn(gAV->mv2xStEn);
  156. gIvlog->info("hmi", "v2x enable request %d",gAV->mv2xStEn);
  157. }
  158. }
  159. //v2x使能状态请求
  160. void ListenMobileye(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
  161. {
  162. // gIvlog->info("hmi", "v2x enable request %d %d",nSize,sizeof(iv::v2x::v2xStReq));
  163. // if(nSize < sizeof(iv::v2x::v2xStReq))
  164. // return;
  165. iv::mobileye::mobileye mobMsg;
  166. if(!mobMsg.ParseFromArray(strdata,nSize))
  167. {
  168. gIvlog->error("hmi", "ListenMobileye parse error");
  169. return;
  170. }
  171. gAV->mimobileyeState= 10;
  172. }
  173. /**
  174. * @brief ADCIntelligentVehicle::ADCIntelligentVehicle
  175. * @param parent
  176. */
  177. ADCIntelligentVehicle::ADCIntelligentVehicle(QWidget *parent)
  178. : QMainWindow(parent),
  179. ui(new Ui::ADCIntelligentVehicle),
  180. m_translateButton(Qt::LeftButton),
  181. m_translateSpeed(1.0),
  182. m_zoomDelta(0.1),
  183. m_bMouseTranslate(false),
  184. m_scale(1.0),
  185. horizontalOffset(0),
  186. verticalOffset(0),
  187. scaleFactor(1),
  188. currentStepScaleFactor(1)
  189. {
  190. ui->setupUi(this);
  191. gAV = this;
  192. gIvlog->info("ADCIntelligentVehicle Start Initialize");
  193. mTime.start();
  194. /*
  195. QString strpath = QCoreApplication::applicationDirPath();
  196. strpath = strpath + "/ADS_decision.xml";
  197. iv::xmlparam::Xmlparam xp(strpath.toStdString());
  198. ServiceCarStatus.mvehtype= xp.GetParam("vehType","ge3");
  199. if(ServiceCarStatus.mvehtype=="ge3"){
  200. ;
  201. }else if( ServiceCarStatus.mvehtype=="qingyuan"){
  202. ;
  203. }else if( ServiceCarStatus.mvehtype=="vv7"){
  204. ;
  205. }else if( ServiceCarStatus.mvehtype=="zhongche"){
  206. ;
  207. }
  208. */
  209. QString strpath = QCoreApplication::applicationDirPath();
  210. strpath = strpath + "/ui_ads_hmi.xml";
  211. iv::xmlparam::Xmlparam xp(strpath.toStdString());
  212. ServiceCarStatus.esr_y_offset = atof(xp.GetParam("esr_y_offset","2.5").data());
  213. ServiceCarStatus.lidar_y_offset = atof(xp.GetParam("lidar_y_offset","0").data());
  214. ui->listWidget->setIconSize(QSize(40,40));
  215. ui->stackedWidget->setCurrentIndex(0);
  216. // QObject::connect(ui->listWidget,SIGNAL(currentRowChanged(int)),ui->stackedWidget,SLOT(on_listWidget_clicked()));//信号与槽
  217. QObject::connect(ui->listWidget,SIGNAL(currentRowChanged(int)),this,SLOT(on_listWidget_clicked()));//信号与槽
  218. // /********************************** 百度地图显示 ********************************/
  219. // mMapview = new QWebEngineView(ui->stackedWidget->widget(0));
  220. //// qDebug((QDir::currentPath()).toLatin1().data());
  221. // mMapview->load(QUrl(QString("file:///%1/%2").arg(QApplication::applicationDirPath()).arg("BaiDuMap.html")));
  222. // mMapview->setGeometry(750,250,400,400);
  223. // /********************************************************************************/
  224. ui->listWidget->setCurrentRow(1); //apollo_fu debug 20200409
  225. myview = new MyView(ui->stackedWidget->widget(1));
  226. myview->setObjectName(QStringLiteral("graphicsView"));
  227. myview->setGeometry(QRect(0, 100, 900, 900)); //从屏幕上(0,100)位置开始(即为最左上角的点),显示一个900*900的界面(宽900,高900)
  228. #if 0
  229. myview_small = new MyView(ui->stackedWidget->widget(1));
  230. myview_small->setObjectName(QStringLiteral("graphicsView_small"));
  231. myview_small->setGeometry(QRect(1000,100,500,500));
  232. myview_small->setAlignment(Qt::AlignLeft | Qt::AlignTop);
  233. #endif
  234. // myview_small->scale(0.7,0.7);
  235. //myview_small->centerOn(-200,-200);
  236. /********************************** 百度地图显示 ********************************/
  237. if(gstrvehtype != "LuBan")
  238. {
  239. mMapview = new QWebEngineView(ui->stackedWidget->widget(1));
  240. // qDebug((QDir::currentPath()).toLatin1().data());
  241. mMapview->load(QUrl(QString("file:///%1/%2").arg(QApplication::applicationDirPath()).arg("BaiDuMap.html")));
  242. mMapview->setGeometry(1000,100,500,500);
  243. }
  244. /********************************************************************************/
  245. image = new QImage(900 * 2, 900 * 2, QImage::Format_RGB32);//画布的初始化大小设为600*500,使用32位颜色
  246. //QImage的32、24、8位图。 图像格式:QImage::Format_RGB32 ,QImage::Format_RGB888,QImage::Format_Indexed8。
  247. //QImage myImage2 = QImage(width, height, QImage::Format_…); 根据图像宽高来构造一幅图像,程序会自动根据图像格式对齐图像数据。
  248. image_small = new QImage(1800,1800,QImage::Format_RGB32);
  249. myview->setCacheMode(myview->CacheBackground);
  250. #if 0
  251. myview_small->setCacheMode(myview_small->CacheBackground);
  252. #endif
  253. painter = new QPainter(image); //创建QPainter对象
  254. painter_small = new QPainter(image_small); //创建QPainter对象
  255. scene = new QGraphicsScene;
  256. scene_small = new QGraphicsScene;
  257. look_decition = new Look_decition;
  258. mobileye_info = new Mobileye_info;
  259. timer = new QTimer(this);
  260. connect(timer, SIGNAL(timeout()), this, SLOT(timeoutslot()));//timeoutslot()为自定义槽
  261. timer->start(100);
  262. Lidar_obsread = boost::shared_ptr<std::vector<iv::ObstacleBasic>>(new std::vector<iv::ObstacleBasic>);
  263. Lidar_read = boost::shared_ptr<std::vector<iv::ObstacleBasic>>(new std::vector<iv::ObstacleBasic>);
  264. mDataToUI.mHead.type = 1;
  265. mDataToUI.mInfo.accelerate = 0;
  266. mDataToUI.mInfo.brake = 0;
  267. mDataToUI.mInfo.gps_lat = 0;
  268. mDataToUI.mInfo.gps_lng = 0;
  269. mDataToUI.mInfo.is_mapLoad = 0;
  270. mDataToUI.mInfo.is_initSuccess = 0;
  271. mDataToUI.mInfo.is_run = 0;
  272. mDataToUI.mInfo.speed = 0;
  273. msockrecv.bind(QHostAddress::Any,9998);//绑定端口
  274. connect(&msockrecv,SIGNAL(readyRead()),this,SLOT(onRecvUDP())); //接收来自PAD的UDP数据报 readyRead():socket读取缓冲区有数据时发送此信号,在此信号的槽函数里读取缓冲区的数据。
  275. ServiceCarStatus.speed = 0.0;
  276. mTimerState.setTimerType(Qt::PreciseTimer); //设置计时器的精确程度 Qt::PreciseTimer值为0,含义:精确定时器试图保持毫秒精度
  277. connect(&mTimerState,SIGNAL(timeout()),this,SLOT(onStateTimer()));//广播发送UDP数据报
  278. mTimerState.start(100); //定时100ms
  279. mTimerStateMap.setTimerType(Qt::PreciseTimer); //
  280. connect(&mTimerStateMap,SIGNAL(timeout()),this,SLOT(onStateTimerMap()));//
  281. mTimerStateMap.start(500); //定时500ms
  282. is_show_enable = true;
  283. #ifdef USE_PAD_CTRL
  284. AutoStart();
  285. #endif
  286. ModuleFun funplantrace = std::bind(&ADCIntelligentVehicle::UpdatePlanTrace,this,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
  287. mpaplantrace = iv::modulecomm::RegisterRecvPlus("plantrace",funplantrace);
  288. ModuleFun funplantrace_left = std::bind(&ADCIntelligentVehicle::UpdatePlanTrace_left,this,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
  289. mpaplantrace_left = iv::modulecomm::RegisterRecvPlus("obstraceleft",funplantrace_left);
  290. ModuleFun funplantrace_right = std::bind(&ADCIntelligentVehicle::UpdatePlanTrace_right,this,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
  291. mpaplantrace_right = iv::modulecomm::RegisterRecvPlus("obstraceright",funplantrace_right);
  292. ModuleFun funfusion = std::bind(&ADCIntelligentVehicle::UpdateFusion,this,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
  293. mpafusion = iv::modulecomm::RegisterRecvPlus("li_ra_fusion",funfusion);
  294. ModuleFun funYolo = std::bind(&ADCIntelligentVehicle::UpdateYolo,this,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
  295. mpaYolo = iv::modulecomm::RegisterRecvPlus("yolo_obs",funYolo);
  296. ModuleFun funmap = std::bind(&ADCIntelligentVehicle::UpdateMap,this,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
  297. mpa = iv::modulecomm::RegisterRecvPlus("tracemap",funmap);
  298. // mpa = iv::modulecomm::RegisterRecv("tracemap",ListenTraceMap);
  299. ModuleFun fungpsimu =std::bind(&ADCIntelligentVehicle::UpdateGPSIMU,this,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
  300. mpagpsimu = iv::modulecomm::RegisterRecvPlus(gstrmemgps.data(),fungpsimu);
  301. ModuleFun funfusiongpsimu =std::bind(&ADCIntelligentVehicle::UpdateGPSIMU,this,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
  302. mpafusiongpsimu = iv::modulecomm::RegisterRecvPlus("fusion_gpsimu",funfusiongpsimu);
  303. // mpagpsimu = iv::modulecomm::RegisterRecv("gpsimu",Listengpsimu);
  304. ModuleFun funradar =std::bind(&ADCIntelligentVehicle::UpdateRADAR,this,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
  305. mparadar = iv::modulecomm::RegisterRecvPlus("radar",funradar);
  306. ModuleFun funchassis =std::bind(&ADCIntelligentVehicle::UpdateChassis,this,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
  307. mpachassis = iv::modulecomm::RegisterRecvPlus("chassis",funchassis);
  308. mpacanstate = iv::modulecomm::RegisterRecv("canstate",ListenCANState);
  309. // gIvlog->debug("canState ptr: %x",mpacanstate);
  310. ModuleFun funbrainstate =std::bind(&ADCIntelligentVehicle::UpdateVehicleState,this,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
  311. // mpaVechicleState = iv::modulecomm::RegisterRecvPlus("vehiclestate",funbrainstate);
  312. mpaVechicleState = iv::modulecomm::RegisterRecvPlus("brainstate",funbrainstate);
  313. ModuleFun funbrainrunstate =std::bind(&ADCIntelligentVehicle::UpdateBrainRunState,this,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
  314. // mpaVechicleState = iv::modulecomm::RegisterRecvPlus("vehiclestate",funbrainstate);
  315. void * parun = iv::modulecomm::RegisterRecvPlus("brainrunstate",funbrainrunstate);
  316. ModuleFun fundecition =std::bind(&ADCIntelligentVehicle::UpdateDecition,this,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
  317. // mpaDecition = iv::modulecomm::RegisterRecvPlus("decition",fundecition);
  318. mpaDecition = iv::modulecomm::RegisterRecvPlus("deciton",fundecition);
  319. mpaLidar = iv::modulecomm::RegisterRecv("lidar_obs",ListenOBS);
  320. mpaHMI = iv::modulecomm::RegisterSend("hmi",10*sizeof(iv::hmi::HMIBasic),10);
  321. iv::modulecomm::RegisterRecv("v2xStReq", ListenV2xStReq);
  322. mp_v2xStSend = iv::modulecomm::RegisterSend("v2xStEn",1000,1);
  323. iv::modulecomm::RegisterRecv("mobileye",ListenMobileye);
  324. mTimeState.start();
  325. mpManualCtrl = iv::modulecomm::RegisterSend("ivmanual",1000,1);
  326. mTimerManual = new QTimer(this);
  327. connect(mTimerManual,SIGNAL(timeout()),this,SLOT(onTimerManual()));
  328. connect(myview,SIGNAL(CtrlManual(bool)),this,SLOT(onCtrlManual(bool)));
  329. mnCtrlValue[0] = 0; mnCtrlValue[1] = 0; mnCtrlValue[2] = 0;
  330. // timermanualctrl->start(10);
  331. //connect(ui->lineEdit_6, SIGNAL(textEdited(const QString &)), this, SLOT(savestabuyEditinfo(const QString &)));
  332. mpamapreq = iv::modulecomm::RegisterSend("mapreq",1000,1);
  333. shareMapReqMsg();
  334. ModuleFun funvbox = std::bind(&ADCIntelligentVehicle::UpdateVbox,this,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
  335. mpaVbox = iv::modulecomm::RegisterRecvPlus("vbox",funvbox);
  336. #if 1
  337. ui->lcdNumber->setDigitCount(3); //设置显示几个数字
  338. ui->lcdNumber->setMode(QLCDNumber::Dec);
  339. ui->lcdNumber->setSegmentStyle(QLCDNumber::Flat);//设置数字字体:Outline,轮廓突出,颜色为背景色;Filled,内部填充型,颜色为黑色;Flat,平面型
  340. // 设置数字颜色时要注意: 函数setSegmentStyle(QLCDNumber::Flat)中选择Flat属性,否则在setColor()设置数字颜色时不生效
  341. // 设置背景色直接用setStyleSheet()函数设定就可以了。
  342. //调色板
  343. QPalette lcdpat = ui->lcdNumber->palette();
  344. /*设置颜色,整体背景颜色 颜色蓝色,此函数的第一个参数可以设置多种。如文本、按钮按钮文字、多种*/
  345. lcdpat.setColor(QPalette::Normal,QPalette::WindowText,Qt::red);
  346. //设置当前窗口的调色板
  347. ui->lcdNumber->setPalette(lcdpat);
  348. //设置背景色
  349. //ui->lcdNumber->setStyleSheet("background-color: black");
  350. //ui->lcdNumber->display(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"));
  351. ui->lcdNumber->display(0);
  352. ui->lcdNumber_2->setDigitCount(3);
  353. ui->lcdNumber_2->setMode(QLCDNumber::Dec);
  354. ui->lcdNumber_2->setSegmentStyle(QLCDNumber::Flat);
  355. ui->lcdNumber_2->setPalette(lcdpat);
  356. //ui->lcdNumber_2->setStyleSheet("background-color: black");
  357. ui->lcdNumber_2->display(0);
  358. ui->lcdNumber_3->setDigitCount(3);
  359. ui->lcdNumber_3->setMode(QLCDNumber::Dec);
  360. ui->lcdNumber_3->setSegmentStyle(QLCDNumber::Flat);
  361. ui->lcdNumber_3->setPalette(lcdpat);
  362. //ui->lcdNumber_3->setStyleSheet("background-color: black");
  363. ui->lcdNumber_3->display(0);
  364. ui->lcdNumber_4->setDigitCount(3);
  365. ui->lcdNumber_4->setMode(QLCDNumber::Dec);
  366. ui->lcdNumber_4->setSegmentStyle(QLCDNumber::Flat);
  367. ui->lcdNumber_4->setPalette(lcdpat);
  368. //ui->lcdNumber_4->setStyleSheet("background-color: black");
  369. ui->lcdNumber_4->display(0);
  370. #endif
  371. // 新建qimage
  372. // QImage img,img2,img3,img4;
  373. // 加载图片
  374. img.load(":/light_image/diaotou-black.png");
  375. img = img.scaled(66,66,Qt::IgnoreAspectRatio);
  376. ui->label_38->setPixmap(QPixmap::fromImage(img));
  377. img2.load(":/light_image/zuoguai-black.png");
  378. img2 = img2.scaled(66,66,Qt::IgnoreAspectRatio);
  379. ui->label_33->setPixmap(QPixmap::fromImage(img2));
  380. img3.load(":/light_image/zhixing-black.png");
  381. img3 = img3.scaled(66,66,Qt::IgnoreAspectRatio);
  382. ui->label_35->setPixmap(QPixmap::fromImage(img3));
  383. img4.load(":/light_image/youguai-black.png");
  384. img4 = img4.scaled(66,66,Qt::IgnoreAspectRatio);
  385. ui->label_32->setPixmap(QPixmap::fromImage(img4));
  386. #if 1
  387. mTimerState1.setTimerType(Qt::PreciseTimer); //设置计时器的精确程度 Qt::PreciseTimer值为0,含义:精确定时器试图保持毫秒精度
  388. connect(&mTimerState1,SIGNAL(timeout()),this,SLOT(onStateTimer1()));//广播发送UDP数据报
  389. mTimerState1.start(100); //定时100ms
  390. #endif
  391. ui->pBtn_door_open->setIcon(QIcon(":/Car-Control-icon/MenJin-Kai.svg"));
  392. ui->pBtn_door_close->setIcon(QIcon(":/Car-Control-icon/MenJin-Guan.svg"));
  393. ui->pBtn_low_beam_open->setIcon(QIcon(":/Car-Control-icon/JinGuang-Kai.svg"));
  394. ui->pBtn_low_beam_close->setIcon(QIcon(":/Car-Control-icon/JinGuang-Guan.svg"));
  395. ui->pBtn_high_beam_open->setIcon(QIcon(":/Car-Control-icon/YuanGuang-Kai.svg"));
  396. ui->pBtn_high_beam_close->setIcon(QIcon(":/Car-Control-icon/YuanGuang-Guan.svg"));
  397. if(gstrvehtype == "LuBan")
  398. {
  399. ui->groupBox->setVisible(false);
  400. ui->groupBox_4->setVisible(false);
  401. ui->groupBox_5->setVisible(false);
  402. ui->groupBox_6->setVisible(false);
  403. ui->groupBox_7->setVisible(false);
  404. ui->groupBox_8->setVisible(false);
  405. ui->groupBox_9->setVisible(false);
  406. ui->groupBox_10->setVisible(false);
  407. ui->groupBox_13->setVisible(false);
  408. ui->pushButton_3->setVisible(false);
  409. ui->pushButton_4->setVisible(false);
  410. ui->groupBox_11->setVisible(false);
  411. }
  412. }
  413. ADCIntelligentVehicle::~ADCIntelligentVehicle()
  414. {
  415. gIvlog->warn("ADCIntelligentVehchicle Exit.");
  416. iv::modulecomm::Unregister(mpaplantrace);
  417. iv::modulecomm::Unregister(mpamapreq);
  418. iv::modulecomm::Unregister(mpManualCtrl);
  419. iv::modulecomm::Unregister(mp_v2xStSend);
  420. iv::modulecomm::Unregister(mpaHMI);
  421. iv::modulecomm::Unregister(mpaLidar);
  422. iv::modulecomm::Unregister(mpaDecition);
  423. iv::modulecomm::Unregister(mpaVechicleState);
  424. iv::modulecomm::Unregister(mpacanstate);
  425. iv::modulecomm::Unregister(mpachassis);
  426. iv::modulecomm::Unregister(mparadar);
  427. iv::modulecomm::Unregister(mpagpsimu);
  428. iv::modulecomm::Unregister(mpa);
  429. iv::modulecomm::Unregister(mpafusion);
  430. iv::modulecomm::Unregister(mpaplantrace_right);
  431. iv::modulecomm::Unregister(mpaplantrace_left);
  432. iv::modulecomm::Unregister(mpaVbox);
  433. qDebug("~ADCIntelligentVehicle()");
  434. }
  435. /**
  436. * @brief ADCIntelligentVehicle::savestabuyEditinfo
  437. * @param txt
  438. */
  439. void ADCIntelligentVehicle::savestabuyEditinfo(const QString &txt)
  440. {
  441. //ServiceControlStatus.set_accelerate((float)txt.toDouble());
  442. }
  443. /**
  444. * @brief ADCIntelligentVehicle::timeoutslot
  445. */
  446. void ADCIntelligentVehicle::timeoutslot()
  447. {
  448. update();
  449. /////////////////////////////////
  450. // //
  451. // 实时状态信息显示 //
  452. ////////////////////////////////
  453. QString is_ok;
  454. ui->lineEdit->setText(QString::number(ServiceCarStatus.location->rtk_status));//rtk状态
  455. ui->lineEdit_12->setText(QString::number(ServiceCarStatus.location->rtk_status));//rtk状态
  456. static int oldrtkstatus = -1;
  457. if(oldrtkstatus != ServiceCarStatus.location->rtk_status)
  458. {
  459. oldrtkstatus = ServiceCarStatus.location->rtk_status;
  460. if(ServiceCarStatus.location->rtk_status==6)
  461. {
  462. ui->pushButton_10->setStyleSheet("background-color: green");
  463. ui->pushButton_23->setStyleSheet("background-color: green");
  464. }
  465. else
  466. {
  467. ui->pushButton_10->setStyleSheet("background-color: red");
  468. ui->pushButton_23->setStyleSheet("background-color: red");
  469. }
  470. }
  471. static int oldinstatus = -1;
  472. if(oldinstatus != ServiceCarStatus.location->ins_status)
  473. {
  474. oldinstatus == ServiceCarStatus.location->ins_status;
  475. ui->lineEdit_2->setText(QString::number(ServiceCarStatus.location->ins_status));//ins状态
  476. if(ServiceCarStatus.location->ins_status==4)
  477. ui->pushButton_11->setStyleSheet("background-color: green");
  478. else
  479. ui->pushButton_11->setStyleSheet("background-color: red");
  480. }
  481. is_ok = (ServiceCarStatus.mRadarS>0)?QStringLiteral("ok"):QStringLiteral("error");
  482. ui->lineEdit_3->setText(is_ok);//毫米波雷达状态
  483. //ui->lineEdit_15->setText(is_ok);//毫米波雷达状态
  484. static int nOldRadarState = 0; //1 ok -1 not ok 0 notdefine
  485. if(ServiceCarStatus.mRadarS>0)
  486. {
  487. if(nOldRadarState != 1)
  488. {
  489. nOldRadarState = 1;
  490. ui->pushButton_12->setStyleSheet("background-color: green");
  491. ui->pushButton_25->setStyleSheet("background-color: green");
  492. }
  493. }
  494. else
  495. {
  496. ServiceCarStatus.mRadarS = -1;
  497. if(nOldRadarState != -1)
  498. {
  499. nOldRadarState = -1;
  500. ui->pushButton_12->setStyleSheet("background-color:red");
  501. ui->pushButton_25->setStyleSheet("background-color:red");
  502. }
  503. }
  504. is_ok = (ServiceCarStatus.mLidarS>0)?QStringLiteral("ok"):QStringLiteral("error");
  505. ui->lineEdit_4->setText(is_ok);//激光雷达状态
  506. // ui->lineEdit_16->setText(is_ok);//激光雷达状态
  507. int nOldLidarState = 0;
  508. if(ServiceCarStatus.mLidarS>0)
  509. {
  510. if(nOldLidarState != 1)
  511. {
  512. nOldLidarState = 1;
  513. ui->pushButton_13->setStyleSheet("background-color: green");
  514. ui->pushButton_26->setStyleSheet("background-color: green");
  515. }
  516. }
  517. else
  518. {
  519. if(nOldLidarState != -1)
  520. {
  521. nOldLidarState = -1;
  522. ui->pushButton_13->setStyleSheet("background-color:red");
  523. ui->pushButton_26->setStyleSheet("background-color:red");
  524. ServiceCarStatus.mLidarS = -1;
  525. }
  526. }
  527. //------------------YOLO----------------------------
  528. is_ok = (ServiceCarStatus.mYoloS>0)?QStringLiteral("ok"):QStringLiteral("error");
  529. int nOldYoloState = 0;
  530. if(ServiceCarStatus.mYoloS>0)
  531. {
  532. if(nOldYoloState != 1)
  533. {
  534. nOldYoloState = 1;
  535. ui->Camera_Yolo->setStyleSheet("background-color: green");
  536. }
  537. }
  538. else
  539. {
  540. if(nOldYoloState != -1)
  541. {
  542. nOldYoloState = -1;
  543. ui->Camera_Yolo->setStyleSheet("background-color:red");
  544. ServiceCarStatus.mYoloS = -1;
  545. }
  546. }
  547. //-------------------------------------------------
  548. int nMState = 0;
  549. if(mimobileyeState>0)
  550. {
  551. if(nMState != 1)
  552. {
  553. nMState = 1;
  554. // ui->Mobileye_st->setStyleSheet("background-color: green");
  555. }
  556. }
  557. else
  558. {
  559. if(nMState != -1)
  560. {
  561. nMState =-1;
  562. // ui->Mobileye_st->setStyleSheet("background-color: red");
  563. }
  564. mimobileyeState = -1;
  565. }
  566. ui->lineEdit_5->setText(QString::number(mdecition_period)+QStringLiteral("ms"));//决策周期
  567. ui->lineEdit_17->setText(QString::number(mdecition_period)+QStringLiteral("ms"));//决策周期
  568. if(mdecition_period>0)
  569. {
  570. ui->pushButton_14->setStyleSheet("background-color: green");
  571. ui->pushButton_27->setStyleSheet("background-color: green");
  572. }
  573. if((mTimeState.elapsed()-mnTimeUpdateGPS) > 1000)
  574. {
  575. oldrtkstatus = -1;
  576. oldinstatus = -1;
  577. ui->pushButton_10->setStyleSheet("background-color: red");
  578. ui->pushButton_11->setStyleSheet("background-color: red");
  579. ui->pushButton_23->setStyleSheet("background-color: red");
  580. }
  581. if((mTimeState.elapsed() - mnTimeUpdateDecition)>1000)
  582. {
  583. ui->pushButton_14->setStyleSheet("background-color:red");
  584. ui->pushButton_27->setStyleSheet("background-color:red");
  585. ui->label_decition->setText("No decition");
  586. mbBrainRunning = false;
  587. }
  588. else
  589. {
  590. QString strdec = "Acc:";
  591. strdec = strdec + QString::number(ServiceCarStatus.mfAcc,'f',1);
  592. // strdec = strdec + " Brake:";
  593. // strdec = strdec + QString::number(ServiceCarStatus.mfBrake,'f',1);
  594. strdec = strdec + " EPS:";
  595. strdec = strdec + QString::number(ServiceCarStatus.mfWheel,'f',1);
  596. ui->label_decition->setText(strdec);
  597. }
  598. if(mbManual)
  599. {
  600. char strmanual[256];
  601. snprintf(strmanual,256,"Manual %d %d %d",mnCtrlValue[0],mnCtrlValue[1],mnCtrlValue[2]);
  602. ui->label_decition->setText(strmanual);
  603. }
  604. #if 0
  605. ui->lineEdit->setText(QString::number(6));//rtk状态
  606. ui->pushButton_10->setStyleSheet("background-color: green");
  607. ui->lineEdit_12->setText(QString::number(6));//rtk状态
  608. ui->pushButton_23->setStyleSheet("background-color: green");
  609. ui->lineEdit_2->setText(QString::number(4));
  610. ui->pushButton_11->setStyleSheet("background-color: green");
  611. ui->lineEdit_3->setText("ok");
  612. ui->pushButton_12->setStyleSheet("background-color: green");
  613. ui->lineEdit_15->setText("ok");
  614. ui->pushButton_25->setStyleSheet("background-color: green");
  615. ui->lineEdit_4->setText("ok");
  616. ui->pushButton_13->setStyleSheet("background-color: green");
  617. ui->lineEdit_16->setText("ok");
  618. ui->pushButton_26->setStyleSheet("background-color: green");
  619. ui->lineEdit_5->setText(QString::number(20)+QStringLiteral("ms"));//决策周期
  620. ui->pushButton_14->setStyleSheet("background-color: green");
  621. ui->lineEdit_17->setText(QString::number(20)+QStringLiteral("ms"));//决策周期
  622. ui->pushButton_27->setStyleSheet("background-color: green");
  623. #endif
  624. /////////////////////////////////
  625. // //
  626. // 实时显示障碍物状态 //
  627. /////////////////////////////////
  628. // ServiceCarStatus.mObs = 10;
  629. // ServiceCarStatus.mLidarObs = 9.123;
  630. // ServiceCarStatus.mRadarObs = 9.222;
  631. // ServiceCarStatus.mfttc = 0.5;
  632. // ServiceCarStatus.mfBrake = 20;
  633. if(ServiceCarStatus.mObs > 0)
  634. {
  635. ui->label_13->setText("Obs:"+QString::number(ServiceCarStatus.mObs,'f',1)+" Lidar:"
  636. +QString::number(ServiceCarStatus.mLidarObs,'f',1) + " Radar:"
  637. +QString::number(ServiceCarStatus.mRadarObs,'f',1));
  638. }
  639. else
  640. {
  641. ui->label_13->setText(QString(tr("前方没有障碍物")));
  642. }
  643. ui->label_26->setText("ttc is "+QString::number(ServiceCarStatus.mfttc,'f',1) + " brake is " + QString::number(ServiceCarStatus.mfBrake,'f',2)); //add 20200518
  644. QString strstate = "Map:";
  645. if(mDataToUI.mInfo.is_mapLoad == 1)
  646. {
  647. strstate = strstate+"Yes ";
  648. }
  649. else
  650. {
  651. strstate = strstate+"No ";
  652. }
  653. strstate = strstate+" CANCARD:";
  654. if(mDataToUI.mInfo.is_initSuccess == 1)
  655. {
  656. strstate = strstate+"OK ";
  657. }
  658. else
  659. {
  660. strstate = strstate+"Fail ";
  661. }
  662. strstate = strstate + " Run State:";
  663. if(mbBrainRunning)
  664. {
  665. strstate = strstate+"RUN";
  666. }
  667. else
  668. {
  669. strstate = strstate+"STOP";
  670. }
  671. ui->label_State->setText(strstate);
  672. /////////////////////////////////
  673. // //
  674. // 模式选择标志置位 //
  675. // //
  676. ////////////////////////////////
  677. // if(ui->checkBox->isChecked()==true)ServiceControlStatus.change_line = 1;//是否换道标志
  678. // else ServiceControlStatus.change_line = 0;
  679. // if(ui->checkBox_2->isChecked()==true)ServiceControlStatus.stop_obstacle = 1;//是否停障标志
  680. // else ServiceControlStatus.stop_obstacle = 0;
  681. // if(ui->checkBox_3->isChecked()==true)ServiceControlStatus.elude_obstacle = 1;//是否避障标志
  682. // else ServiceControlStatus.elude_obstacle = 0;
  683. // if(ui->checkBox_4->isChecked()==true)ServiceControlStatus.special_signle = 1;//是否特殊信号输入标志
  684. // else ServiceControlStatus.special_signle = 0;
  685. // if(ui->checkBox_5->isChecked()==true)ServiceControlStatus.car_pullover = 1;//是否靠边停车标志位
  686. // else ServiceControlStatus.car_pullover = 0;
  687. //zk add speed scale
  688. //ui->lb_current_speed_big->setText(QString::number(ServiceCarStatus.speed,'f',1));
  689. QString strpath = QCoreApplication::applicationDirPath();
  690. strpath = strpath + "/speed.xml";
  691. iv::xmlparam::Xmlparam xp1(strpath.toStdString());
  692. float speed_scale = stof(xp1.GetParam("speed_scale","1"));
  693. // std::cout<<speed_scale<<std::endl;
  694. ui->lb_current_speed_big->setText(QString::number(ServiceCarStatus.speed*speed_scale,'f',1));
  695. ui->lb_current_speed_big->setText(QString::number(ServiceCarStatus.speed,'f',1));
  696. // QString is_ok;
  697. // is_ok = (ServiceLidar.did_lidar_ok() == true)?QStringLiteral("ok"):QStringLiteral("error");
  698. // ui->lineEdit_4->setText(is_ok);
  699. //can state
  700. mDataToUI.mInfo.is_initSuccess = 0;
  701. }
  702. /**
  703. * @brief ADCIntelligentVehicle::on_pb_load_navigation_data_clicked
  704. */
  705. //void ADCIntelligentVehicle::on_pb_load_navigation_data_clicked() //加载地图
  706. //{
  707. //}
  708. /**
  709. * @brief ADCIntelligentVehicle::onRecvUDP
  710. */
  711. void ADCIntelligentVehicle::onRecvUDP()
  712. {
  713. if (msockrecv.hasPendingDatagrams()) //hasPendingDatagrams()表示是否有待读取的传入数据报
  714. {
  715. qDebug("recv cmd");
  716. QByteArray ba;
  717. ba.resize(msockrecv.pendingDatagramSize());//pendingDatagramSize()返回待读取数据报的字节数
  718. msockrecv.readDatagram(ba.data(), ba.size()); //readDatagram()函数用于读取数据报内容
  719. int * p;
  720. iv::hmi::HMIBasic hmi;
  721. p = (int *)ba.data();
  722. // qDebug("cmd is ",*p);
  723. // std::cout<<"data len is "<<ba.size()<<" value is "<<*p<<std::endl;
  724. if(*p == 1)
  725. {
  726. std::cout<<ServiceCarStatus.mRunTime.elapsed()<<":"<<"recv start."<<std::endl;
  727. ServiceCarStatus.mbRunPause = false;
  728. hmi.mbBocheMode = false;
  729. hmi.mbPause = false;
  730. ShareHMIMsg(hmi);
  731. }
  732. if(*p == 0)
  733. {
  734. ServiceCarStatus.mbRunPause = true;
  735. hmi.mbBocheMode = false;
  736. hmi.mbPause = true;
  737. ShareHMIMsg(hmi);
  738. }
  739. if(*p == 2)
  740. {
  741. ServiceCarStatus.bocheMode = true;
  742. hmi.mbBocheMode = true;
  743. hmi.mbPause = false;
  744. ShareHMIMsg(hmi);
  745. }
  746. if(*p == 3)
  747. {
  748. hmi.mbbusmode = true;
  749. hmi.mbPause = ServiceCarStatus.mbRunPause;
  750. ShareHMIMsg(hmi);
  751. }
  752. if(*p == 4)
  753. {
  754. hmi.mbbusmode = false;
  755. hmi.mbPause = ServiceCarStatus.mbRunPause;
  756. ShareHMIMsg(hmi);
  757. }
  758. }
  759. }
  760. /**
  761. * @brief ADCIntelligentVehicle::onStateTimer
  762. */
  763. void ADCIntelligentVehicle::onStateTimer()
  764. {
  765. if(ServiceCarStatus.mbBrainCtring)
  766. mDataToUI.mInfo.is_run = 1;
  767. else
  768. mDataToUI.mInfo.is_run = 0;
  769. if(ServiceCarStatus.mLidarS<0)
  770. mDataToUI.mInfo.lidarStatus = 0;
  771. else
  772. mDataToUI.mInfo.lidarStatus = 1;
  773. //----------Yolo-----------
  774. if(ServiceCarStatus.mYoloS<0)
  775. mDataToUI.mInfo.YoloStatus = 0;
  776. else
  777. mDataToUI.mInfo.YoloStatus = 1;
  778. //---------------------------
  779. if(ServiceCarStatus.mRadarS<0)
  780. mDataToUI.mInfo.radarStatus = 0;
  781. else
  782. mDataToUI.mInfo.radarStatus = 1;
  783. ServiceCarStatus.mLidarS--; //如果从10减到0,表示没有接收到数据。
  784. ServiceCarStatus.mRadarS--;
  785. ServiceCarStatus.mYoloS--;
  786. mimobileyeState--;
  787. mDataToUI.mInfo.RTKstatus = ServiceCarStatus.mRTKStatus;
  788. ServiceCarStatus.mRTKStatus = 0;
  789. mDataToUI.mInfo.radarobs = ServiceCarStatus.mRadarObs;
  790. mDataToUI.mInfo.lidarobs = ServiceCarStatus.mLidarObs;
  791. mDataToUI.mInfo.obs = ServiceCarStatus.mObs;
  792. mDataToUI.mInfo.gps_lat = ServiceCarStatus.location->gps_lat;
  793. mDataToUI.mInfo.gps_lng = ServiceCarStatus.location->gps_lng;
  794. mDataToUI.mInfo.accelerate = ServiceCarStatus.mfAcc;
  795. mDataToUI.mInfo.speed = ServiceCarStatus.speed;
  796. mDataToUI.mInfo.brake = ServiceCarStatus.mfBrake;
  797. mDataToUI.mInfo.swerve = ServiceCarStatus.mfWheel;
  798. mDataToUI.mInfo.boche_status = ServiceCarStatus.bocheEnable;
  799. if(fabs(mDataToUI.mInfo.gps_lat)<1 )
  800. {
  801. // qDebug("gps lat is error.");
  802. // std::cout<<"no gps."<<std::endl;
  803. }
  804. // std::cout<<"send data."<<std::endl;
  805. // qDebug("speed is %d",mDataToUI.mInfo.speed);
  806. // mDataToUI.mInfo.is_initSuccess = 1;
  807. // mDataToUI.mInfo.speed = 36.1;
  808. msocksend.writeDatagram((char *)&mDataToUI,sizeof(DataToUI),QHostAddress::Broadcast,9999); //QHostAddress::Broadcast 值为1 Pv4广播地址,相当于QHostAddress(“255.255.255.255”)。
  809. // _udp->writeDatagram(str.toUtf8(), QHostAddress::Broadcast, 10002);
  810. // multicast, 224.0.0.1~224.0.0.255 is multicast address of LAN
  811. // _udp->writeDatagram(str.toUtf8(), QHostAddress("224.0.0.131"), 10002);
  812. }
  813. void ADCIntelligentVehicle::onStateTimerMap()
  814. {
  815. /*******************************更新百度地图******************************/
  816. if(gstrvehtype != "LuBan")
  817. {
  818. double flat = ServiceCarStatus.location->gps_lat;
  819. double flon = ServiceCarStatus.location->gps_lng;
  820. double fang = ServiceCarStatus.location->ins_heading_angle;
  821. char strscript[256];
  822. snprintf(strscript,255,"theLocation(%11.7f,%11.7f,%11.7f);",flon,flat,fang);
  823. mMapview->page()->runJavaScript(strscript);
  824. }
  825. /************************************************************************/
  826. }
  827. /**
  828. * @brief ADCIntelligentVehicle::AutoStart
  829. */
  830. void ADCIntelligentVehicle::AutoStart()
  831. {
  832. // is_brain_running_flag_ = true;
  833. // mDataToUI.mInfo.is_initSuccess = 1;
  834. // std::cout<<ServiceCarStatus.mRunTime.elapsed()<<"ms:"<<"Start Run SuccessFully."<<std::endl;
  835. }
  836. /**
  837. * @brief ADCIntelligentVehicle::on_pb_start_all_clicked
  838. */
  839. void ADCIntelligentVehicle::on_pb_start_all_clicked() {
  840. #ifdef USE_PAD_CTRL
  841. ServiceCarStatus.mbRunPause = false;
  842. iv::hmi::HMIBasic hmi;
  843. hmi.mbBocheMode = false;
  844. hmi.mbPause = false;
  845. ShareHMIMsg(hmi);
  846. return;
  847. #endif
  848. }
  849. /**
  850. * @brief ADCIntelligentVehicle::on_pb_open_can_card_clicked
  851. */
  852. //void ADCIntelligentVehicle::on_pb_open_can_card_clicked() {
  853. //}
  854. /**
  855. * @brief ADCIntelligentVehicle::on_timer_car_status_time_out
  856. */
  857. void ADCIntelligentVehicle::on_timer_car_status_time_out() {
  858. // zk add speed scale
  859. //ui->lb_current_speed_big->setText(QString::number(ServiceCarStatus.speed));
  860. // speed scale
  861. QString strpath = QCoreApplication::applicationDirPath();
  862. strpath = strpath + "/speed.xml";
  863. iv::xmlparam::Xmlparam xp1(strpath.toStdString());
  864. float speed_scale = stof(xp1.GetParam("speed_scale","1"));
  865. // std::cout<<speed_scale<<std::endl;
  866. ui->lb_current_speed_big->setText(QString::number(ServiceCarStatus.speed*speed_scale));
  867. //ui->sb_accelerate_percent->setValue(ServiceControlStatus.accelerate_percent);
  868. //ui->sb_wheel_percent->setValue(ServiceControlStatus.wheel_angle);
  869. }
  870. /**
  871. * @brief ADCIntelligentVehicle::on_timer_mobileye_info_time_out
  872. */
  873. void ADCIntelligentVehicle::on_timer_mobileye_info_time_out(){
  874. mobileye_info->aws_display.dusk_time = ServiceCarStatus.aws_display.dusk_time;
  875. mobileye_info->Lane.curvature = ServiceCarStatus.Lane.curvature;
  876. mobileye_info->Lane.heading = ServiceCarStatus.Lane.heading;
  877. mobileye_info->Lane.pitch = ServiceCarStatus.Lane.pitch;
  878. mobileye_info->Lane.yaw = ServiceCarStatus.Lane.yaw;
  879. mobileye_info->obstacleStatus.num_obstacles = ServiceCarStatus.obstacleStatus.num_obstacles;
  880. mobileye_info->obstacleStatus.timestamp = ServiceCarStatus.obstacleStatus.timestamp;
  881. mobileye_info->aftermarketLane.dist_to_lane_l = ServiceCarStatus.aftermarketLane.dist_to_lane_l;
  882. mobileye_info->aftermarketLane.dist_to_lane_r = ServiceCarStatus.aftermarketLane.dist_to_lane_r;
  883. mobileye_info->aftermarketLane.lane_type_left = ServiceCarStatus.aftermarketLane.lane_type_left;
  884. mobileye_info->aftermarketLane.lane_type_right = ServiceCarStatus.aftermarketLane.lane_type_right;
  885. for(int i = 0; i < 15; i++)
  886. {
  887. mobileye_info->obstacleStatusA[i].obstacle_ID = ServiceCarStatus.obstacleStatusA[i].obstacle_ID;
  888. mobileye_info->obstacleStatusA[i].obstacle_pos_x = ServiceCarStatus.obstacleStatusA[i].obstacle_pos_x;
  889. mobileye_info->obstacleStatusA[i].obstacle_pos_y = ServiceCarStatus.obstacleStatusA[i].obstacle_pos_y;
  890. mobileye_info->obstacleStatusA[i].obstacle_rel_vel_x = ServiceCarStatus.obstacleStatusA[i].obstacle_rel_vel_x;
  891. mobileye_info->obstacleStatusA[i].obstacle_status = ServiceCarStatus.obstacleStatusA[i].obstacle_status;
  892. mobileye_info->obstacleStatusA[i].obstacle_type = ServiceCarStatus.obstacleStatusA[i].obstacle_type;
  893. mobileye_info->obstacleStatusA[i].is_obstacle_brake_lights = ServiceCarStatus.obstacleStatusA[i].is_obstacle_brake_lights;
  894. }
  895. for(int i = 0; i < 15; i++)
  896. {
  897. mobileye_info->obstacleStatusB[i].obstacle_length = ServiceCarStatus.obstacleStatusB[i].obstacle_length;
  898. mobileye_info->obstacleStatusB[i].obstacle_width = ServiceCarStatus.obstacleStatusB[i].obstacle_width;
  899. mobileye_info->obstacleStatusB[i].obstacle_age = ServiceCarStatus.obstacleStatusB[i].obstacle_age;
  900. }
  901. for(int i = 0; i < 15; i++)
  902. {
  903. mobileye_info->obstacleStatusC[i].obstacle_angle_rate = ServiceCarStatus.obstacleStatusC[i].obstacle_angle_rate;
  904. mobileye_info->obstacleStatusC[i].obstacle_angle = ServiceCarStatus.obstacleStatusC[i].obstacle_angle;
  905. mobileye_info->obstacleStatusC[i].object_accel_x = ServiceCarStatus.obstacleStatusC[i].object_accel_x;
  906. }
  907. }
  908. /**
  909. * @brief ADCIntelligentVehicle::keyPressEvent 加/减键进行缩放
  910. * @param event
  911. */
  912. void ADCIntelligentVehicle::keyPressEvent(QKeyEvent *event)
  913. {
  914. switch (event->key()) {
  915. case Qt::Key_Plus: // 放大
  916. myview->zoomIn();
  917. break;
  918. case Qt::Key_Minus: // 缩小
  919. myview->zoomOut();
  920. break;
  921. default:
  922. QMainWindow::keyPressEvent(event);
  923. }
  924. }
  925. /**
  926. * @brief ADCIntelligentVehicle::closeEvent
  927. * @param event
  928. */
  929. void ADCIntelligentVehicle::closeEvent(QCloseEvent *event)
  930. {
  931. QMessageBox::StandardButton button;
  932. button=QMessageBox::question(this,tr("退出程序"),QString(tr("确认退出程序")),QMessageBox::Yes|QMessageBox::No);
  933. if(button==QMessageBox::No)
  934. {
  935. event->ignore(); // 忽略退出信号,程序继续进行
  936. }
  937. else if(button==QMessageBox::Yes)
  938. {
  939. event->accept(); // 接受退出信号,程序退出
  940. }
  941. }
  942. /**
  943. * @brief MyView::wheelEvent 放大/缩小
  944. * @param event
  945. */
  946. void MyView::wheelEvent(QWheelEvent *event)
  947. {
  948. // 滚轮的滚动量
  949. QPoint scrollAmount = event->angleDelta();
  950. // 正值表示滚轮远离使用者(放大),负值表示朝向使用者(缩小)
  951. scrollAmount.y() > 0 ? zoomIn() : zoomOut();
  952. }
  953. /**
  954. * @brief MyView::zoomIn 放大
  955. */
  956. void MyView::zoomIn()
  957. {
  958. scale(1.1, 1.1);
  959. beishu *= 1.1;
  960. centerOn(450, 700 - (200 / beishu));
  961. }
  962. /**
  963. * @brief MyView::zoomOut 缩小
  964. */
  965. void MyView::zoomOut()
  966. {
  967. scale(1 / 1.1, 1 / 1.1);
  968. beishu /= 1.1;
  969. centerOn(450, 700 - (200 / beishu));
  970. }
  971. /**
  972. * @brief ADCIntelligentVehicle::paintEvent 刷新
  973. */
  974. void ADCIntelligentVehicle::paintEvent(QPaintEvent *)
  975. {
  976. QTime xTime;
  977. xTime.start();
  978. if (is_show_enable)
  979. {
  980. // qDebug("enter paint. time1 is %d",mTime.elapsed());
  981. if(fabs(mTime.elapsed() - mnTimeLastUpdatePaint)<100)
  982. {
  983. return;
  984. }
  985. mnTimeLastUpdatePaint = mTime.elapsed();
  986. // qDebug("enter paint. time is %d",mTime.elapsed());
  987. painter->begin(image);
  988. // painter_small->begin(image_small);
  989. // image->fill(QColor(60, 60, 60));//对画布进行填充
  990. image->fill(QColor(220, 220, 220));//对画布进行填充
  991. image_small->fill(QColor(220,220,220));
  992. std::vector<iv::GPSData> navigation_data;
  993. mMutexNavi.lock();
  994. navigation_data = m_navigation_data;
  995. mMutexNavi.unlock();
  996. std::vector<iv::TracePoint> myplan,myplan_left,myplan_right;
  997. mMutexPlan.lock();
  998. myplan = m_plan;
  999. mMutexPlan.unlock();
  1000. mMutexPlan_left.lock();
  1001. myplan_left = m_plan_left;
  1002. mMutexPlan_left.unlock();
  1003. mMutexPlan_right.lock();
  1004. myplan_right = m_plan_right;
  1005. mMutexPlan_right.unlock();
  1006. // std::cout<<"plan size is "<<myplan.size()<<std::endl;
  1007. // std::vector<iv::GPSData> navigation_data = brain->navigation_data;
  1008. painter->setRenderHint(QPainter::Antialiasing, true);//设置反锯齿模式,好看一点
  1009. painter_small->setRenderHint(QPainter::Antialiasing, true);//设置反锯齿模式,好看一点
  1010. int pointx = 450, pointy = 700;//确定坐标轴起点坐标,这里定义(35,280)
  1011. // int pointx_small = 450, pointy_small = 700;
  1012. // double x0[22000], y0[22000], lng[22000], x1[22000], y1[22000], x2[22000], y2[22000];
  1013. double * x0, * y0, * lng, * x1, * y1, * x2, * y2;
  1014. std::shared_ptr<double> ptrx0,ptry0,ptrlng,ptrx1,ptry1,ptrx2,ptry2;
  1015. int nmapsize = navigation_data.size();
  1016. x0 = new double[nmapsize];
  1017. y0 = new double[nmapsize];
  1018. lng = new double[nmapsize];
  1019. x1 = new double[nmapsize];
  1020. y1 = new double[nmapsize];
  1021. x2 = new double[nmapsize];
  1022. y2 = new double[nmapsize];
  1023. ptrx0.reset(x0);
  1024. ptry0.reset(y0);
  1025. ptrlng.reset(lng);
  1026. ptrx1.reset(x1);
  1027. ptry1.reset(y1);
  1028. ptrx2.reset(x2);
  1029. ptry2.reset(y2);
  1030. double xx = 0, yy = 0;
  1031. double sumx = 0, sumy = 0;//, ave_x = 0, ave_y = 0;
  1032. int sizeN = navigation_data.size();
  1033. //int max_x_pos = 0, min_x_pos = 0, max_y_pos = 0, min_y_pos = 0;
  1034. int x_max = 0, y_max = 0;//数组里的最大值
  1035. int x_min = 0x3f3f3f3f, y_min = 0x3f3f3f3f;//inf为 #define inf 0x3f3f3f3f
  1036. double k1, k2;
  1037. QPen pen, penPoint;
  1038. //先绘制车位置点及框图
  1039. static const QPointF points1[2] = { QPointF(300, 700), QPointF(600, 700) };
  1040. static const QPointF points2[2] = { QPointF(450, 0), QPointF(450, 900) };
  1041. // static const QPointF points1_small[2] = { QPointF(300, 700), QPointF(600, 700) };
  1042. // static const QPointF points2_small[2] = { QPointF(450, 0), QPointF(450, 900) };
  1043. penPoint.setColor(Qt::red);
  1044. penPoint.setWidth(2);
  1045. painter->setPen(penPoint);
  1046. // painter_small->setPen(penPoint);
  1047. painter->drawPoint(pointx, pointy);
  1048. // painter_small->drawPoint(pointx_small,pointy_small);
  1049. painter->drawPolyline(points1, 2);
  1050. painter->drawPolyline(points2, 2);
  1051. // painter_small->drawPolyline(points1_small, 2);
  1052. // painter_small->drawPolyline(points2_small, 2);
  1053. //路径点的预处理
  1054. for (int i = 0; i < sizeN; i++)
  1055. {
  1056. x0[i] = navigation_data[i]->gps_x;
  1057. y0[i] = navigation_data[i]->gps_y;
  1058. lng[i] = navigation_data[i]->ins_heading_angle;
  1059. sumx = sumx + navigation_data[i]->gps_x;
  1060. sumy = sumy + navigation_data[i]->gps_y;
  1061. if (x0[i] > x_max) {
  1062. x_max = x0[i];
  1063. //max_x_pos = i;
  1064. }
  1065. if (x0[i] < x_min) {
  1066. x_min = x0[i];
  1067. //min_x_pos = i;
  1068. }
  1069. if (y0[i] > y_max) {
  1070. y_max = y0[i];
  1071. //max_y_pos = i;
  1072. }
  1073. if (y0[i] < y_min) {
  1074. y_min = y0[i];
  1075. //min_y_pos = i;
  1076. }
  1077. }
  1078. //ave_x = sumx / sizeN;
  1079. //ave_y = sumy / sizeN;
  1080. //获取到实时 GPS信息,并做路径点的显示更新
  1081. if (ServiceCarStatus.location->gps_x == 0)
  1082. {
  1083. painter->drawText(rect(), Qt::AlignLeft, QString(tr("等待车辆实时GPS位置信息")));
  1084. // painter_small->drawText(rect(), Qt::AlignLeft, QString::fromLocal8Bit("等待车辆实时GPS位置信息"));
  1085. }
  1086. else
  1087. {
  1088. x0[0] = ServiceCarStatus.location->gps_x;
  1089. y0[0] = ServiceCarStatus.location->gps_y;
  1090. // std::cout<<"x = "<<x0[0]<<" y= "<<y0[0]<<std::endl;
  1091. lng[0] = ServiceCarStatus.location->ins_heading_angle;
  1092. }
  1093. //根据标定原点的选取,对路径点进行转化
  1094. for (int i = 1; i < sizeN; i++)
  1095. {
  1096. // if(i == 1)std::cout<<" x1 = "<<x0[i]<<std::endl;
  1097. x0[i] = x0[i] - x0[0];
  1098. y0[i] = y0[i] - y0[0];
  1099. xx = x0[i];
  1100. yy = y0[i];
  1101. x0[i] = xx * cos(lng[0] * PI / 180) - yy * sin(lng[0] * PI / 180);
  1102. y0[i] = xx * sin(lng[0] * PI / 180) + yy * cos(lng[0] * PI / 180);
  1103. k1 = sin((90 + (lng[i] - lng[0])) * PI / 180);
  1104. k2 = cos((90 + (lng[i] - lng[0])) * PI / 180);
  1105. #if 0
  1106. x1[i] = x0[i] + k1 * 5;
  1107. y1[i] = y0[i] + k2 * 5;
  1108. x2[i] = x0[i] - k1 * 5;
  1109. y2[i] = y0[i] - k2 * 5;
  1110. #else
  1111. x1[i] = x0[i] + k1 * 1.75;
  1112. y1[i] = y0[i] + k2 * 1.75;
  1113. x2[i] = x0[i] - k1 * 1.75;
  1114. y2[i] = y0[i] - k2 * 1.75;
  1115. #endif
  1116. }
  1117. // double kx_small = (double)(1200) / (abs(y_max - y_min));//x轴的系数
  1118. // double ky_small = (double)(1200) / (abs(y_max - y_min));//y方向的比例系数
  1119. double kx = 10;
  1120. double ky = 10;
  1121. //距离车正前方10m处画一条线
  1122. static const QPointF points3[2] = { QPointF(0, 700 - 10 * ky), QPointF(900, 700 - 10 * ky) };
  1123. painter->drawPolyline(points3, 2);
  1124. //绘制路径点
  1125. penPoint.setColor(Qt::black);
  1126. penPoint.setWidth(1);
  1127. for (int i = 1; i < sizeN - 1; i++)
  1128. {
  1129. painter->setPen(penPoint);//蓝色的笔,用于标记各个点
  1130. // painter_small->setPen(penPoint);//蓝色的笔,用于标记各个点
  1131. painter->drawPoint(pointx + x0[i] * kx, pointy - y0[i] * ky);
  1132. // painter_small->drawPoint(pointx_small + x0[i] * kx_small, pointy_small - y0[i] * ky_small);
  1133. painter->drawPoint(pointx + x1[i] * kx, pointy - y1[i] * ky);
  1134. // painter_small->drawPoint(pointx_small + x1[i] * kx_small, pointy_small - y1[i] * ky_small);
  1135. painter->drawPoint(pointx + x2[i] * kx, pointy - y2[i] * ky);
  1136. // painter_small->drawPoint(pointx_small + x2[i] * kx_small, pointy_small - y2[i] * ky_small);
  1137. }
  1138. painter->drawPoint(pointx + x0[sizeN - 1] * kx, pointy - y0[sizeN - 1] * ky);//绘制最后一个点
  1139. // painter_small->drawPoint(pointx_small + x0[sizeN - 1] * kx_small, pointy_small - y0[sizeN - 1] * ky_small);//绘制最后一个点
  1140. penPoint.setColor(Qt::red);
  1141. penPoint.setWidth(2);
  1142. painter->drawPoint(pointx + x0[0] * kx, pointy - y0[0] * ky);
  1143. // painter_small->drawPoint(pointx_small + x0[0] * kx_small, pointy_small - y0[0] * ky_small);
  1144. #if 1
  1145. // draw plan trace
  1146. penPoint.setColor(QColor(187, 255, 255, 100));
  1147. penPoint.setWidth(2);
  1148. painter->setPen(penPoint);
  1149. QPointF tracePoints[myplan.size()];
  1150. if(myplan.size()>2)
  1151. {
  1152. for(int i=0;i<(myplan.size()-1);i++)
  1153. {
  1154. tracePoints[i].setX((float)(450+myplan[i].x*kx));
  1155. tracePoints[i].setY((float)(700-myplan[i].y*ky));
  1156. painter->drawLine((float)(450+myplan[i].x*kx),(float)(700-myplan[i].y*ky),
  1157. (float)(450+myplan[i+1].x*kx),(float)(700-myplan[i+1].y*ky));
  1158. }
  1159. }
  1160. #endif
  1161. #if 1
  1162. // penPoint.setColor(Qt::gray);
  1163. penPoint.setColor(QColor(187, 255, 255, 100));
  1164. penPoint.setWidth(2);
  1165. painter->setPen(penPoint);
  1166. QPointF tracePoints_left[myplan_left.size()];
  1167. if(myplan_left.size()>2)
  1168. {
  1169. for(int i=0;i<(myplan_left.size()-1);i++)
  1170. {
  1171. tracePoints_left[i].setX((float)(450+myplan_left[i].x*kx));
  1172. tracePoints_left[i].setY((float)(700-myplan_left[i].y*ky));
  1173. painter->drawLine((float)(450+myplan_left[i].x*kx),(float)(700-myplan_left[i].y*ky),
  1174. (float)(450+myplan_left[i+1].x*kx),(float)(700-myplan_left[i+1].y*ky));
  1175. }
  1176. }
  1177. // penPoint.setColor(Qt::gray);
  1178. // penPoint.setWidth(2);
  1179. // painter->setPen(penPoint);
  1180. QPointF tracePoints_right[myplan_right.size()];
  1181. if(myplan_right.size()>2)
  1182. {
  1183. for(int i=0;i<(myplan_right.size()-1);i++)
  1184. {
  1185. tracePoints_right[i].setX((float)(450+myplan_right[i].x*kx));
  1186. tracePoints_right[i].setY((float)(700-myplan_right[i].y*ky));
  1187. painter->drawLine((float)(450+myplan_right[i].x*kx),(float)(700-myplan_right[i].y*ky),
  1188. (float)(450+myplan_right[i+1].x*kx),(float)(700-myplan_right[i+1].y*ky));
  1189. }
  1190. }
  1191. #endif
  1192. // painter->drawPolyline(tracePoints,myplan.size());
  1193. // draw plan trace end
  1194. /////////////////////////////////////apollo add car icon 20200409
  1195. QPixmap pix;
  1196. //pix.load("car.png");
  1197. // pix.load(":/ADCIntelligentVehicle/car1.png");
  1198. // painter->drawPixmap(435,667,30,67,pix);
  1199. // painter_small->drawPixmap(442,683,16,34,pix);
  1200. ///////////////////////////////////////////////////////////////////
  1201. penPoint.setColor(Qt::blue);
  1202. penPoint.setWidth(3);
  1203. painter->setPen(penPoint);
  1204. QFont font;
  1205. font.setFamily("Microsoft YaHei");
  1206. font.setPointSize(50);
  1207. font.setItalic(true);
  1208. painter->setFont(font);
  1209. //////////////////////////////////////
  1210. // //
  1211. // 显示毫米波雷达和激光雷达的信息 //
  1212. // //
  1213. //////////////////////////////////////
  1214. if(ui->checkBox_8->isChecked())
  1215. {
  1216. painter->setPen(QPen(Qt::black, 2));
  1217. painter->setBrush(Qt::blue);
  1218. QFont esr_font("Microsoft YaHei", 10, 75); //第一个属性是字体(微软雅黑),第二个是大小,第三个是加粗(权重是75)
  1219. painter->setFont(esr_font);
  1220. char coordinate_ear[100];
  1221. iv::radar::radarobjectarray xradararray;
  1222. if(mbradarUpdate)
  1223. {
  1224. mMutexRadar.lock();
  1225. xradararray.CopyFrom(mradararray);
  1226. mMutexRadar.unlock();
  1227. for (int a = 0; a < xradararray.obj_size(); a++)
  1228. {
  1229. if (xradararray.obj(a).bvalid())
  1230. {
  1231. painter->drawEllipse(xradararray.obj(a).x() * 10 + 450, -((xradararray.obj(a).y() + ServiceCarStatus.esr_y_offset) * 10) + 700, 10, 10);
  1232. sprintf(coordinate_ear, "(%d, %d)", (int)xradararray.obj(a).x(), (int)xradararray.obj(a).y());
  1233. painter->drawText(xradararray.obj(a).x() * 10 + 450, -((xradararray.obj(a).y() + ServiceCarStatus.esr_y_offset ) * 10) + 700, QString(coordinate_ear));
  1234. }
  1235. }
  1236. // mbradarUpdate = false;
  1237. }
  1238. }
  1239. if(ui->checkBox_9->isChecked())
  1240. {
  1241. ServiceLidar.copylidarto(Lidar_read); //激光雷达障碍物
  1242. ServiceLidar.copylidarobsto(Lidar_obsread);
  1243. painter->setPen(QColor(255, 0, 0));
  1244. for (unsigned int x = 0; x < Lidar_read->size(); x++)
  1245. {
  1246. //painter->drawPoint(((*Lidar_read)[x].nomal_x) * 10 + 450, -(*Lidar_read)[x].nomal_y * 10 + 700);
  1247. }
  1248. painter->setPen(QColor(255,0,0));
  1249. for (unsigned int x = 0; x < Lidar_obsread->size(); x++)
  1250. {
  1251. painter->drawPoint(((*Lidar_obsread)[x].nomal_x) * 10 + 450, -((*Lidar_obsread)[x].nomal_y + ServiceCarStatus.lidar_y_offset) * 10 + 700);
  1252. }
  1253. }
  1254. //----------------------Yolo-------------------------
  1255. if(ui->checkBox_11->isChecked())
  1256. {
  1257. painter->setPen(QColor(255,0,0));
  1258. iv::fusion::fusionobjectarray xYoloarray;
  1259. if(mbYoloUpdate)
  1260. {
  1261. mMutexYolo.lock();
  1262. xYoloarray.CopyFrom(mYoloarray);
  1263. mMutexYolo.unlock();
  1264. std::cout<<"Yolo_array.size(): "<<xYoloarray.obj_size()<<std::endl;
  1265. for(int a = 0; a < xYoloarray.obj_size(); a++)
  1266. {
  1267. for(int b = 0; b < xYoloarray.obj(a).nomal_centroid_size(); b++)
  1268. {
  1269. std::cout<<"x:"<<xYoloarray.obj(a).nomal_centroid(b).nomal_x()<<std::endl;
  1270. std::cout<<"y:"<<xYoloarray.obj(a).nomal_centroid(b).nomal_y()<<std::endl;
  1271. painter->drawPoint((xYoloarray.obj(a).nomal_centroid(b).nomal_x())*10 + 450, -(xYoloarray.obj(a).nomal_centroid(b).nomal_y())*10 + 700);
  1272. }
  1273. }
  1274. }
  1275. }
  1276. //----------------------------------------------------
  1277. //////////////////////////////////////
  1278. // //
  1279. // 显示融合的信息 //
  1280. // //
  1281. //////////////////////////////////////
  1282. if(ui->checkBox_10->isChecked())
  1283. {
  1284. painter->setPen(QColor(255,0,0));
  1285. iv::fusion::fusionobjectarray xfusionarray;
  1286. if(mbfusionUpdate)
  1287. {
  1288. mMutexFusion.lock();
  1289. xfusionarray.CopyFrom(mfusionarray);
  1290. mMutexFusion.unlock();
  1291. std::cout<<"fusion_array.size(): "<<xfusionarray.obj_size()<<std::endl;
  1292. for(int a = 0; a < xfusionarray.obj_size(); a++)
  1293. {
  1294. for(int b = 0; b < xfusionarray.obj(a).nomal_centroid_size(); b++)
  1295. {
  1296. std::cout<<"x:"<<xfusionarray.obj(a).nomal_centroid(b).nomal_x()<<std::endl;
  1297. std::cout<<"y:"<<xfusionarray.obj(a).nomal_centroid(b).nomal_y()<<std::endl;
  1298. painter->drawPoint((xfusionarray.obj(a).nomal_centroid(b).nomal_x())*10 + 450, -(xfusionarray.obj(a).nomal_centroid(b).nomal_y() + ServiceCarStatus.lidar_y_offset)*10 + 700);
  1299. }
  1300. }
  1301. }
  1302. }
  1303. painter->end();
  1304. // painter_small->end();
  1305. scene->clear();
  1306. // scene_small->clear();
  1307. scene->addPixmap(QPixmap::fromImage(*image));
  1308. // scene_small->addPixmap(QPixmap::fromImage(*image_small));
  1309. myview->setScene(scene);
  1310. // myview_small->setScene(scene_small);
  1311. myview->show();
  1312. // myview_small->show();
  1313. navigation_data.clear();
  1314. if(mfSOC != 0.0)
  1315. {
  1316. ui->label_11->setText(QString::number(mfSOC,'f',1));
  1317. }
  1318. }
  1319. // qDebug("painter use %d ms",xTime.elapsed());
  1320. }
  1321. /**
  1322. * @brief ADCIntelligentVehicle::on_pb_auto_drive_mode_clicked
  1323. */
  1324. void ADCIntelligentVehicle::on_pb_auto_drive_mode_clicked() {
  1325. is_auto_drive_mode_enable_ = !is_auto_drive_mode_enable_;
  1326. // ServiceCanUtil.startsend(is_auto_drive_mode_enable_);
  1327. ui->pb_auto_drive_mode->setText(is_auto_drive_mode_enable_ ? QString(tr("决策控制使能:开")) : QString(tr("决策控制使能:关")));
  1328. }
  1329. /**
  1330. * @brief ADCIntelligentVehicle::on_pb_auto_braking_mode_clicked
  1331. */
  1332. void ADCIntelligentVehicle::on_pb_auto_braking_mode_clicked() {
  1333. is_auto_braking_mode_enable_ = !is_auto_braking_mode_enable_;
  1334. // ServiceControlStatus.set_turnsignals_control(is_auto_braking_mode_enable_,0);
  1335. ui->pb_auto_braking_mode->setText(is_auto_braking_mode_enable_ ? QString(tr("左转向灯:开")) : QString(tr("左转向灯:关")));
  1336. }
  1337. /**
  1338. * @brief ADCIntelligentVehicle::on_pb_auto_accelerate_mode_clicked
  1339. * QStringLiteral 是Qt5中新引入的一个用来从“字符串常量”创建QString对象的宏
  1340. */
  1341. void ADCIntelligentVehicle::on_pb_auto_accelerate_mode_clicked() {
  1342. is_auto_accelerate_mode_enable_ = !is_auto_accelerate_mode_enable_;
  1343. // ServiceControlStatus.set_turnsignals_control(0,is_auto_accelerate_mode_enable_);
  1344. ui->pb_auto_accelerate_mode->setText(is_auto_accelerate_mode_enable_ ? QString(tr("右转向灯:开")) : QString(tr("右转向灯:关")));
  1345. }
  1346. /**
  1347. * @brief ADCIntelligentVehicle::on_pb_auto_wheel_mode_clicked
  1348. */
  1349. void ADCIntelligentVehicle::on_pb_auto_wheel_mode_clicked() {
  1350. is_auto_wheel_mode_enable_ = !is_auto_wheel_mode_enable_;
  1351. // ServiceControlStatus.set_speaker(is_auto_wheel_mode_enable_);
  1352. ui->pb_auto_wheel_mode->setText(is_auto_wheel_mode_enable_ ? QString(tr("喇叭")) : QString(tr("喇叭")));
  1353. }
  1354. /**
  1355. * @brief ADCIntelligentVehicle::on_pushButton_clicked
  1356. */
  1357. void ADCIntelligentVehicle::on_pushButton_clicked(){
  1358. is_3 = !is_3;
  1359. // ServiceControlStatus.set_light(is_3);
  1360. ui->pushButton->setText(is_3 ? QString(tr("近光灯:开")) : QString(tr("近光灯:关")));
  1361. }
  1362. /**
  1363. * @brief ADCIntelligentVehicle::on_pb_speed_control_mode_clicked
  1364. */
  1365. void ADCIntelligentVehicle::on_pb_speed_control_mode_clicked() {
  1366. is_speed_control_mode_enable_ = !is_speed_control_mode_enable_;
  1367. // if(is_speed_control_mode_enable_==true)
  1368. // ServiceControlStatus.set_engine(0x03);
  1369. // else
  1370. // ServiceControlStatus.set_engine(0x02);
  1371. ui->pb_speed_control_mode->setText(is_speed_control_mode_enable_ ? QString(tr("点火:开")) : QString(tr("点火:关")));
  1372. }
  1373. /**
  1374. * @brief ADCIntelligentVehicle::on_hs_braking_percent_valueChanged
  1375. * @param value
  1376. */
  1377. void ADCIntelligentVehicle::on_hs_braking_percent_valueChanged(int value) {
  1378. //ServiceControlStatus.set_braking((float)value);
  1379. }
  1380. /**
  1381. * @brief ADCIntelligentVehicle::on_hs_accelerate_percent_valueChanged
  1382. * @param value
  1383. */
  1384. void ADCIntelligentVehicle::on_hs_accelerate_percent_valueChanged(int value) {
  1385. //ServiceControlStatus.set_accelerate((float)value);
  1386. }
  1387. /**
  1388. * @brief ADCIntelligentVehicle::on_hs_wheel_angle_valueChanged
  1389. * @param value
  1390. */
  1391. void ADCIntelligentVehicle::on_hs_wheel_angle_valueChanged(int value) {
  1392. //ServiceControlStatus.set_wheel_angle((float)value);
  1393. }
  1394. /**
  1395. * @brief ADCIntelligentVehicle::on_pushButton_3_clicked
  1396. */
  1397. void ADCIntelligentVehicle::on_pushButton_3_clicked(){
  1398. look_decition->show();
  1399. }
  1400. /**
  1401. * @brief ADCIntelligentVehicle::on_pushButton_4_clicked
  1402. */
  1403. void ADCIntelligentVehicle::on_pushButton_4_clicked(){
  1404. mobileye_info->show();
  1405. }
  1406. /**
  1407. * @brief ADCIntelligentVehicle::on_listWidget_clicked
  1408. */
  1409. void ADCIntelligentVehicle::on_listWidget_clicked()
  1410. {
  1411. int currentRow=ui->listWidget->currentRow(); //currentRow()获取当前行号
  1412. if(currentRow==0) //点击第一切换到第一页
  1413. {
  1414. ui->stackedWidget->setCurrentIndex(0);//为堆栈窗体切换到当前索引
  1415. }
  1416. else if(currentRow==1)
  1417. {
  1418. ui->stackedWidget->setCurrentIndex(1);
  1419. }
  1420. else if(currentRow==2)
  1421. {
  1422. ui->stackedWidget->setCurrentIndex(2);
  1423. }
  1424. else
  1425. {
  1426. ui->stackedWidget->setCurrentIndex(0);
  1427. }
  1428. }
  1429. /**
  1430. * @brief ADCIntelligentVehicle::on_pushButton_5_clicked
  1431. */
  1432. void ADCIntelligentVehicle::on_pushButton_5_clicked()//常规速度
  1433. {
  1434. QString normal_speed_ = ui->textEdit->toPlainText();
  1435. // if(normal_speed_!=NULL)
  1436. // ServiceControlStatus.normal_speed = normal_speed_.toInt();
  1437. }
  1438. /**
  1439. * @brief ADCIntelligentVehicle::on_pushButton_6_clicked
  1440. */
  1441. void ADCIntelligentVehicle::on_pushButton_6_clicked()//转弯速度
  1442. {
  1443. QString swerve_speed_ = ui->textEdit_2->toPlainText();
  1444. // if(swerve_speed_!=NULL)
  1445. // ServiceControlStatus.swerve_speed = swerve_speed_.toInt();
  1446. }
  1447. /**
  1448. * @brief ADCIntelligentVehicle::on_pushButton_7_clicked
  1449. */
  1450. void ADCIntelligentVehicle::on_pushButton_7_clicked()//快速
  1451. {
  1452. QString high_speed_ = ui->textEdit_3->toPlainText();
  1453. // if(high_speed_!=NULL)
  1454. // ServiceControlStatus.high_speed = high_speed_.toInt();
  1455. }
  1456. /**
  1457. * @brief ADCIntelligentVehicle::on_pushButton_8_clicked
  1458. */
  1459. void ADCIntelligentVehicle::on_pushButton_8_clicked()//中速
  1460. {
  1461. QString mid_speed_ = ui->textEdit_4->toPlainText();
  1462. // if(mid_speed_!=NULL)
  1463. // ServiceControlStatus.mid_speed = mid_speed_.toInt();
  1464. }
  1465. /**
  1466. * @brief ADCIntelligentVehicle::on_pushButton_9_clicked
  1467. */
  1468. void ADCIntelligentVehicle::on_pushButton_9_clicked()//慢速
  1469. {
  1470. QString low_speed_ = ui->textEdit_5->toPlainText();
  1471. // if(low_speed_!=NULL)
  1472. // ServiceControlStatus.low_speed = low_speed_.toInt();
  1473. }
  1474. void ADCIntelligentVehicle::UpdatePlanTrace(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
  1475. {
  1476. mMutexPlan.lock();
  1477. m_plan.clear();
  1478. int nplansize = nSize/sizeof(iv::TracePoint);
  1479. int npsize = sizeof(iv::TracePoint);
  1480. int i;
  1481. for(i=0;i<nplansize;i++)
  1482. {
  1483. iv::TracePoint x;
  1484. memcpy(&x,strdata + i*npsize,npsize);
  1485. m_plan.push_back(x);
  1486. }
  1487. mMutexPlan.unlock();
  1488. }
  1489. void ADCIntelligentVehicle::UpdatePlanTrace_left(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
  1490. {
  1491. mMutexPlan_left.lock();
  1492. m_plan_left.clear();
  1493. int nplansize = nSize/sizeof(iv::TracePoint);
  1494. if(nplansize < 1)
  1495. std::cout<<"UpdatePlanTrace_left size is 0................. "<<std::endl;
  1496. // return;
  1497. int npsize = sizeof(iv::TracePoint);
  1498. int i;
  1499. for(i=0;i<nplansize;i++)
  1500. {
  1501. iv::TracePoint x;
  1502. memcpy(&x,strdata + i*npsize,npsize);
  1503. m_plan_left.push_back(x);
  1504. }
  1505. mMutexPlan_left.unlock();
  1506. }
  1507. void ADCIntelligentVehicle::UpdatePlanTrace_right(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
  1508. {
  1509. mMutexPlan_right.lock();
  1510. m_plan_right.clear();
  1511. int nplansize = nSize/sizeof(iv::TracePoint);
  1512. if(nplansize < 1)
  1513. std::cout<<"UpdatePlanTrace_right size is 0................. "<<std::endl;
  1514. int npsize = sizeof(iv::TracePoint);
  1515. int i;
  1516. for(i=0;i<nplansize;i++)
  1517. {
  1518. iv::TracePoint x;
  1519. memcpy(&x,strdata + i*npsize,npsize);
  1520. m_plan_right.push_back(x);
  1521. }
  1522. mMutexPlan_right.unlock();
  1523. }
  1524. void ADCIntelligentVehicle::UpdateFusion(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
  1525. {
  1526. iv::fusion::fusionobjectarray xfusionarray;
  1527. if(!xfusionarray.ParseFromArray(strdata,nSize))
  1528. {
  1529. gIvlog->warn("ADCIntelligentVehicle::UpdateFusion Parse Error.");
  1530. return;
  1531. }
  1532. mMutexFusion.lock();
  1533. mfusionarray.CopyFrom(xfusionarray);
  1534. std::cout<<"Fusion update_flag: "<<mbfusionUpdate<<std::endl;
  1535. mbfusionUpdate = true;
  1536. mMutexFusion.unlock();
  1537. ServiceCarStatus.mLidarS = 10;
  1538. }
  1539. void ADCIntelligentVehicle::UpdateYolo(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
  1540. {
  1541. iv::fusion::fusionobjectarray xYoloarray;
  1542. if(!xYoloarray.ParseFromArray(strdata,nSize))
  1543. {
  1544. gIvlog->warn("ADCIntelligentVehicle::UpdateYolo Parse Error.");
  1545. return;
  1546. }
  1547. mMutexYolo.lock();
  1548. mYoloarray.CopyFrom(xYoloarray);
  1549. std::cout<<"Yolo update_flag: "<<mbYoloUpdate<<std::endl;
  1550. mbYoloUpdate = true;
  1551. mMutexYolo.unlock();
  1552. ServiceCarStatus.mYoloS = 10;
  1553. }
  1554. /**
  1555. * @brief ADCIntelligentVehicle::UpdateMap
  1556. * @param strdata
  1557. * @param nSize
  1558. * @param index
  1559. * @param dt
  1560. * @param strmemname
  1561. */
  1562. void ADCIntelligentVehicle::UpdateMap(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
  1563. {
  1564. // std::cout<<"update map "<<std::endl;
  1565. int gpsunitsize = sizeof(iv::GPS_INS);
  1566. int nMapSize = nSize/gpsunitsize;
  1567. // std::cout<<"map size is "<<nMapSize<<std::endl;
  1568. if(nMapSize < 1)return;
  1569. bool bUpdate = false;
  1570. if(nMapSize != m_navigation_data.size())
  1571. {
  1572. bUpdate = true;
  1573. }
  1574. else
  1575. {
  1576. iv::GPS_INS * p = (iv::GPS_INS *)strdata;
  1577. if((p->gps_lat == m_navigation_data.at(0)->gps_lat)&&(p->ins_heading_angle == m_navigation_data.at(0)->ins_heading_angle))
  1578. {
  1579. // qDebug("same map");
  1580. bUpdate = false;
  1581. }
  1582. else
  1583. {
  1584. bUpdate = true;
  1585. }
  1586. }
  1587. if(bUpdate)
  1588. {
  1589. int i;
  1590. mMutexNavi.lock();
  1591. m_navigation_data.clear();
  1592. for(i=0;i<nMapSize;i++)
  1593. {
  1594. iv::GPS_INS x;
  1595. memcpy(&x,strdata + i*gpsunitsize,gpsunitsize);
  1596. iv::GPSData data(new iv::GPS_INS);
  1597. *data = x;
  1598. m_navigation_data.push_back(data);
  1599. }
  1600. mnNaviUpdateTime = QDateTime::currentMSecsSinceEpoch();
  1601. mMutexNavi.unlock();
  1602. if(m_navigation_data.size()>0)
  1603. {
  1604. mDataToUI.mInfo.is_mapLoad = 1;
  1605. }
  1606. else
  1607. {
  1608. mDataToUI.mInfo.is_mapLoad = 0;
  1609. }
  1610. }
  1611. else
  1612. {
  1613. // qDebug("not need update");
  1614. }
  1615. }
  1616. //=======================zhaobo0904
  1617. #define PI 3.14159265358979
  1618. /**
  1619. * @brief GaussProjCal
  1620. * @param lon
  1621. * @param lat
  1622. * @param X
  1623. * @param Y
  1624. */
  1625. /*
  1626. void GaussProjCal(double lon, double lat, double *X, double *Y)
  1627. {
  1628. // 1975 年国际椭球体长半轴 a, 第一离心率 e2, 第二离心率 ep2
  1629. double a = 6378140.0;
  1630. double e2 = 0.006694384999588;
  1631. double ep2 = e2/(1-e2);
  1632. // 原点所在经度
  1633. double lon_origin = 6.0*int(lon/6) + 3.0;
  1634. lon_origin *= PI / 180.0;
  1635. double k0 = 0.9996;
  1636. // 角度转弧度
  1637. double lat1 = lat * PI / 180.0;
  1638. double lon1 = lon * PI / 180.0;
  1639. // 经线在该点处的曲率半径,
  1640. double N = a / sqrt(1 - e2*sin(lat1)*sin(lat1));
  1641. // 赤道到该点的经线长度近似值 M, 使用泰勒展开逐项积分然后取前四项.
  1642. // 这个近似值是将 N 作为纬度 \phi 的函数展开为泰勒计数, 然后在区间 [0, lat1] 上积分得到的.
  1643. // 首先计算前四项的系数 a1~a4.
  1644. double a1 = 1 - e2/4 - (3*e2*e2)/64 - (5*e2*e2*e2)/256;
  1645. double a2 = (3*e2)/8 + (3*e2*e2)/32 + (45*e2*e2*e2)/1024;
  1646. double a3 = (15*e2*e2)/256 + (45*e2*e2*e2)/1024;
  1647. double a4 = (35*e2*e2*e2)/3072;
  1648. double M = a * (a1*lat1 - a2*sin(2*lat1) + a3*sin(4*lat1) - a4*sin(6*lat1));
  1649. // 辅助量
  1650. double T = tan(lat1)*tan(lat1);
  1651. double C = ep2*cos(lat1)*cos(lat1);
  1652. double A = (lon1 - lon_origin)*cos(lat1);
  1653. *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);
  1654. *Y = M + N * tan(lat1) * ((A*A)/2 +
  1655. (5 - T + 9*C + 4*C*C)*(A*A*A*A)/24 +
  1656. (61 - 58*T + T*T + 600*C - 330*ep2)*(A*A*A*A*A*A)/720);
  1657. *Y *= k0;
  1658. return;
  1659. }
  1660. */
  1661. //高斯投影由经纬度(Unit:DD)反算大地坐标(含带号,Unit:Metres)
  1662. void GaussProjCal(double longitude, double latitude, double *X, double *Y)
  1663. {
  1664. int ProjNo = 0; int ZoneWide; ////带宽
  1665. double longitude1, latitude1, longitude0, latitude0, X0, Y0, xval, yval;
  1666. double a, f, e2, ee, NN, T, C, A, M, iPI;
  1667. iPI = 0.0174532925199433; ////3.1415926535898/180.0;
  1668. ZoneWide = 6; ////6度带宽
  1669. a = 6378245.0; f = 1.0 / 298.3; //54年北京坐标系参数
  1670. ////a=6378140.0; f=1/298.257; //80年西安坐标系参数
  1671. ProjNo = (int)(longitude / ZoneWide);
  1672. longitude0 = ProjNo * ZoneWide + ZoneWide / 2;
  1673. longitude0 = longitude0 * iPI;
  1674. latitude0 = 0;
  1675. longitude1 = longitude * iPI; //经度转换为弧度
  1676. latitude1 = latitude * iPI; //纬度转换为弧度
  1677. e2 = 2 * f - f * f;
  1678. ee = e2 * (1.0 - e2);
  1679. NN = a / sqrt(1.0 - e2 * sin(latitude1)*sin(latitude1));
  1680. T = tan(latitude1)*tan(latitude1);
  1681. C = ee * cos(latitude1)*cos(latitude1);
  1682. A = (longitude1 - longitude0)*cos(latitude1);
  1683. 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
  1684. *e2 / 1024)*sin(2 * latitude1)
  1685. + (15 * e2*e2 / 256 + 45 * e2*e2*e2 / 1024)*sin(4 * latitude1) - (35 * e2*e2*e2 / 3072)*sin(6 * latitude1));
  1686. 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);
  1687. yval = M + NN * tan(latitude1)*(A*A / 2 + (5 - T + 9 * C + 4 * C*C)*A*A*A*A / 24
  1688. + (61 - 58 * T + T * T + 600 * C - 330 * ee)*A*A*A*A*A*A / 720);
  1689. X0 = 1000000L * (ProjNo + 1) + 500000L;
  1690. Y0 = 0;
  1691. xval = xval + X0; yval = yval + Y0;
  1692. *X = xval;
  1693. *Y = yval;
  1694. }
  1695. //高斯投影由大地坐标(Unit:Metres)反算经纬度(Unit:DD)
  1696. void GaussProjInvCal(double X, double Y, double *longitude, double *latitude)
  1697. {
  1698. int ProjNo; int ZoneWide; ////带宽
  1699. double longitude1, latitude1, longitude0, latitude0, X0, Y0, xval, yval;
  1700. double e1, e2, f, a, ee, NN, T, C, M, D, R, u, fai, iPI;
  1701. iPI = 0.0174532925199433; ////3.1415926535898/180.0;
  1702. a = 6378245.0; f = 1.0 / 298.3; //54年北京坐标系参数
  1703. ////a=6378140.0; f=1/298.257; //80年西安坐标系参数
  1704. ZoneWide = 6; ////6度带宽
  1705. ProjNo = (int)(X / 1000000L); //查找带号
  1706. longitude0 = (ProjNo - 1) * ZoneWide + ZoneWide / 2;
  1707. longitude0 = longitude0 * iPI; //中央经线
  1708. X0 = ProjNo * 1000000L + 500000L;
  1709. Y0 = 0;
  1710. xval = X - X0; yval = Y - Y0; //带内大地坐标
  1711. e2 = 2 * f - f * f;
  1712. e1 = (1.0 - sqrt(1 - e2)) / (1.0 + sqrt(1 - e2));
  1713. ee = e2 / (1 - e2);
  1714. M = yval;
  1715. u = M / (a*(1 - e2 / 4 - 3 * e2*e2 / 64 - 5 * e2*e2*e2 / 256));
  1716. fai = u + (3 * e1 / 2 - 27 * e1*e1*e1 / 32)*sin(2 * u) + (21 * e1*e1 / 16 - 55 * e1*e1*e1*e1 / 32)*sin(
  1717. 4 * u)
  1718. + (151 * e1*e1*e1 / 96)*sin(6 * u) + (1097 * e1*e1*e1*e1 / 512)*sin(8 * u);
  1719. C = ee * cos(fai)*cos(fai);
  1720. T = tan(fai)*tan(fai);
  1721. NN = a / sqrt(1.0 - e2 * sin(fai)*sin(fai));
  1722. R = a * (1 - e2) / sqrt((1 - e2 * sin(fai)*sin(fai))*(1 - e2 * sin(fai)*sin(fai))*(1 - e2 * sin
  1723. (fai)*sin(fai)));
  1724. D = xval / NN;
  1725. //计算经度(Longitude) 纬度(Latitude)
  1726. 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
  1727. *D*D*D*D / 120) / cos(fai);
  1728. latitude1 = fai - (NN*tan(fai) / R)*(D*D / 2 - (5 + 3 * T + 10 * C - 4 * C*C - 9 * ee)*D*D*D*D / 24
  1729. + (61 + 90 * T + 298 * C + 45 * T*T - 256 * ee - 3 * C*C)*D*D*D*D*D*D / 720);
  1730. //转换为度 DD
  1731. *longitude = longitude1 / iPI;
  1732. *latitude = latitude1 / iPI;
  1733. }
  1734. //==========================================================
  1735. /**
  1736. * @brief ADCIntelligentVehicle::UpdateGPSIMU
  1737. * @param strdata
  1738. * @param nSize
  1739. * @param index
  1740. * @param dt
  1741. * @param strmemname
  1742. */
  1743. void ADCIntelligentVehicle::UpdateGPSIMU(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
  1744. {
  1745. iv::gps::gpsimu xgpsimu;
  1746. if(!xgpsimu.ParseFromArray(strdata,nSize))
  1747. {
  1748. gIvlog->warn("ADCIntelligentVehicle::UpdateGPSIMU parse error. nSize is %d",nSize);
  1749. return;
  1750. }
  1751. if(strcmp(gstrmemgps.data(),strmemname) == 0)
  1752. {
  1753. int64_t nmsnow = std::chrono::system_clock::now().time_since_epoch().count()/1000000;
  1754. if(abs(nmsnow - mnLastFusionGPSIMUUpdate)<3000)
  1755. {
  1756. return;
  1757. }
  1758. }
  1759. else
  1760. {
  1761. mnLastFusionGPSIMUUpdate = std::chrono::system_clock::now().time_since_epoch().count()/1000000;
  1762. }
  1763. iv::GPSData data(new iv::GPS_INS);
  1764. data->gps_lat = xgpsimu.lat();
  1765. data->gps_lng = xgpsimu.lon();
  1766. data->ins_heading_angle = xgpsimu.heading();
  1767. data->rtk_status = xgpsimu.rtk_state();
  1768. data->ins_status = xgpsimu.ins_state();
  1769. data->vel_D = xgpsimu.vd(); //地向速度,单位(米/秒)
  1770. data->vel_E = xgpsimu.ve(); //东向速度,单位(米/秒)
  1771. data->vel_N = xgpsimu.vn(); //北向速度,单位(米/秒)
  1772. GaussProjCal(data->gps_lng,data->gps_lat,&data->gps_x,&data->gps_y);
  1773. ServiceCarStatus.mRTKStatus = data->rtk_status;
  1774. if(xgpsimu.has_speed())
  1775. data->speed = xgpsimu.speed() *3.6;
  1776. else
  1777. {
  1778. data->speed= sqrt(pow(data->vel_E,2)+pow(data->vel_N,2)) * 3.6;
  1779. }
  1780. ServiceCarStatus.speed = data->speed;
  1781. // std::cout<<"chrono: "<<std::chrono::system_clock::now().time_since_epoch().count()/1000000<<std::endl;
  1782. // std::cout<<" speed : "<<ServiceCarStatus.speed;
  1783. ServiceCarStatus.location->gps_lat = data->gps_lat;
  1784. ServiceCarStatus.location->gps_lng = data->gps_lng;
  1785. ServiceCarStatus.location->ins_heading_angle = data->ins_heading_angle;
  1786. ServiceCarStatus.location->gps_x = data->gps_x;
  1787. ServiceCarStatus.location->gps_y = data->gps_y;
  1788. ServiceCarStatus.location->rtk_status = data->rtk_status;
  1789. ServiceCarStatus.location->ins_status = data->ins_status;
  1790. // ServiceCarStatus.speed = sqrt(pow(data->vel_E,2)+pow(data->vel_N,2)) * 3.6; //double pow(double x, double y) 返回 x 的 y 次幂,即 xy。
  1791. mnTimeUpdateGPS = mTimeState.elapsed();
  1792. }
  1793. /**
  1794. * @brief ADCIntelligentVehicle::UpdateRADAR
  1795. * @param strdata
  1796. * @param nSize
  1797. * @param index
  1798. * @param dt
  1799. * @param strmemname
  1800. */
  1801. void ADCIntelligentVehicle::UpdateRADAR(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
  1802. {
  1803. static qint64 oldrecvtime;
  1804. iv::radar::radarobjectarray xradararray;
  1805. if(!xradararray.ParseFromArray(strdata,nSize))
  1806. {
  1807. gIvlog->warn("ADCIntelligentVehicle::UpdateRADAR Parse Error.");
  1808. return;
  1809. }
  1810. // gIvlog->verbose("radar time is %ld",QDateTime::currentMSecsSinceEpoch());
  1811. if((QDateTime::currentMSecsSinceEpoch() - oldrecvtime)>100)
  1812. {
  1813. gIvlog->warn("radar interval is more than 100ms. value is %ld",QDateTime::currentMSecsSinceEpoch() - oldrecvtime);
  1814. }
  1815. oldrecvtime = QDateTime::currentMSecsSinceEpoch();
  1816. mMutexRadar.lock();
  1817. mradararray.CopyFrom(xradararray);
  1818. mbradarUpdate = true;
  1819. mMutexRadar.unlock();
  1820. // int i;
  1821. // for(i=0;i<64;i++)
  1822. // {
  1823. // iv::ObstacleBasic x;
  1824. // memcpy(&x,pdata + i*sizeof(iv::ObstacleBasic),sizeof(iv::ObstacleBasic));
  1825. // ServiceCarStatus.obs_radar[i] = x;
  1826. // }
  1827. ServiceCarStatus.mRadarS = 10;
  1828. // mnTimeUpdateRadar = mTimeState.elapsed();
  1829. // mnTimeUpdateCANState = mTimeState.elapsed();
  1830. }
  1831. /**
  1832. * @brief ADCIntelligentVehicle::UpdateCANState
  1833. * @param pdata
  1834. * @param ndatasize
  1835. */
  1836. void ADCIntelligentVehicle::UpdateCANState(const char *pdata, const int ndatasize)
  1837. {
  1838. iv::canstate::canstate recCanstate;
  1839. if(!recCanstate.ParseFromArray(pdata, ndatasize))
  1840. {
  1841. gIvlog->warn("ADCIntelligentVehicle::updateCanstate error");
  1842. return;
  1843. }
  1844. // if(ndatasize<sizeof(iv::can_state))return;
  1845. // char ccanstate[ndatasize];
  1846. // memcpy(ccanstate,pdata,4);
  1847. #if 1
  1848. if(recCanstate.b_canstate())
  1849. {
  1850. // gIvlog->debug("UpdateCANState<success>");
  1851. mDataToUI.mInfo.is_initSuccess = 1;
  1852. }
  1853. else
  1854. {
  1855. // gIvlog->debug("UpdateCANState<failed>size %d %s ");
  1856. mDataToUI.mInfo.is_initSuccess = 0;
  1857. }
  1858. #endif
  1859. // iv::can_state x;
  1860. // memcpy(&x,pdata,sizeof(iv::can_state));
  1861. // if(x.mbCANOpen)
  1862. // {
  1863. // mDataToUI.mInfo.is_initSuccess = 1;
  1864. // }
  1865. // else
  1866. // {
  1867. // mDataToUI.mInfo.is_initSuccess = 0;
  1868. // }
  1869. }
  1870. /**
  1871. * @brief ADCIntelligentVehicle::UpdateDecition
  1872. * @param strdata
  1873. * @param nSize
  1874. * @param index
  1875. * @param dt
  1876. * @param strmemname
  1877. */
  1878. void ADCIntelligentVehicle::UpdateDecition(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
  1879. {
  1880. iv::brain::decition xdecition;
  1881. if(!xdecition.ParseFromArray(strdata,nSize))
  1882. {
  1883. gIvlog->warn("ADCIntelligentVehicle::UpdateDecition parse errror. nSize is %d",nSize);
  1884. return;
  1885. }
  1886. //ServiceCarStatus.mfAcc = xdecition.accelerator(); //
  1887. ServiceCarStatus.mfAcc = xdecition.torque(); //
  1888. ServiceCarStatus.mfBrake = xdecition.brake();
  1889. ServiceCarStatus.mfWheel = xdecition.wheelangle();
  1890. ServiceCarStatus.mfttc = xdecition.ttc();
  1891. mnTimeUpdateDecition = mTimeState.elapsed();
  1892. }
  1893. void ADCIntelligentVehicle::UpdateBrainRunState(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
  1894. {
  1895. iv::brain::brainrunstate xbrainstate;
  1896. if(!xbrainstate.ParseFromArray(strdata,nSize))
  1897. {
  1898. gIvlog->warn("ADCIntelligentVehicle::UpdateVehicleState parse error,nSize is %d ",nSize);
  1899. return;
  1900. }
  1901. mdecition_period = xbrainstate.decision_period();
  1902. qDebug("period: %f ",mdecition_period);
  1903. }
  1904. /**
  1905. * @brief ADCIntelligentVehicle::UpdateVehicleState
  1906. * @param strdata
  1907. * @param nSize
  1908. * @param index
  1909. * @param dt
  1910. * @param strmemname
  1911. */
  1912. void ADCIntelligentVehicle::UpdateVehicleState(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
  1913. {
  1914. iv::brain::brainstate xbrainstate;
  1915. if(!xbrainstate.ParseFromArray(strdata,nSize))
  1916. {
  1917. gIvlog->warn("ADCIntelligentVehicle::UpdateVehicleState parse error,nSize is %d ",nSize);
  1918. return;
  1919. }
  1920. ServiceCarStatus.bocheEnable = xbrainstate.mbbocheenable();
  1921. ServiceCarStatus.mObs = xbrainstate.mfobs();
  1922. ServiceCarStatus.mLidarObs = xbrainstate.mflidarobs();
  1923. ServiceCarStatus.mRadarObs = xbrainstate.mfradarobs();
  1924. mbBrainRunning = xbrainstate.mbbrainrunning();
  1925. ServiceCarStatus.mbBrainCtring = xbrainstate.mbbrainrunning();
  1926. // mdecition_period = xbrainstate.decision_period();
  1927. // qDebug("period: %f ",mdecition_period);
  1928. mnTimeUpdateVS = mTimeState.elapsed();
  1929. }
  1930. /**
  1931. * @brief ADCIntelligentVehicle::UpdateOBS
  1932. * @param lidar_obs
  1933. */
  1934. void ADCIntelligentVehicle::UpdateOBS(std::shared_ptr<std::vector<iv::ObstacleBasic> > lidar_obs)
  1935. {
  1936. iv::ObsLiDAR _obs_grid_ = boost::shared_ptr<std::vector<iv::ObstacleBasic>>(new std::vector<iv::ObstacleBasic>);
  1937. int i;
  1938. int nSize = lidar_obs->size();
  1939. for(i=0;i<nSize;i++)
  1940. _obs_grid_->push_back(lidar_obs->at(i));
  1941. ServiceLidar.copyfromlidarobs(_obs_grid_);
  1942. ServiceCarStatus.mLidarS = 10;
  1943. }
  1944. void ADCIntelligentVehicle::UpdateV2xStEn(unsigned int enable)
  1945. {
  1946. iv::v2x::v2xStEn x;
  1947. x.set_v2xsten(enable);
  1948. int nsize = x.ByteSize();
  1949. char * str = new char[nsize];
  1950. if(x.SerializeToArray(str,nsize))
  1951. {
  1952. iv::modulecomm::ModuleSendMsg(mp_v2xStSend,str,nsize);
  1953. }
  1954. else
  1955. {
  1956. gIvlog->error("hmi","send enable st error");
  1957. }
  1958. delete str;
  1959. }
  1960. /**
  1961. * @brief ADCIntelligentVehicle::ShareHMIMsg
  1962. * @param xhmi
  1963. */
  1964. void ADCIntelligentVehicle::ShareHMIMsg(iv::hmi::HMIBasic xhmi)
  1965. {
  1966. iv::hmi::hmimsg xhmimsg;
  1967. xhmimsg.set_mbpause(xhmi.mbPause);
  1968. xhmimsg.set_mbbusmode(xhmi.mbbusmode);
  1969. xhmimsg.set_mbbochemode(xhmi.mbBocheMode);
  1970. xhmimsg.set_mbchemen(xhmi.mbchemen);
  1971. xhmimsg.set_mbjinguang(xhmi.mbjinguang);
  1972. xhmimsg.set_mbyuanguang(xhmi.mbyuanguang);
  1973. int nsize = xhmimsg.ByteSize();
  1974. char * str = new char[nsize];
  1975. std::shared_ptr<char> pstr;
  1976. pstr.reset(str); //将就对象的引用计数减1(当然,如果发现引用计数为0时,则析构旧对象),然后将新对象的指针交给智能指针保管。这样做可以省略了delete的过程。
  1977. if(!xhmimsg.SerializeToArray(str,nsize))
  1978. {
  1979. std::cout<<"ADCIntelligentVehicle::ShareHMIMsg serialize error."<<std::endl;
  1980. mpivlog->error("ADCIntelligentVehicle::ShareHMIMsg serialize error.");
  1981. return;
  1982. }
  1983. iv::modulecomm::ModuleSendMsg(mpaHMI,str,nsize);
  1984. }
  1985. void ADCIntelligentVehicle::UpdateChassis(const char *strdata, const unsigned int nSize, const unsigned int index, const QDateTime *dt, const char *strmemname)
  1986. {
  1987. iv::chassis xchassis;
  1988. static int ncount = 0;
  1989. if(!xchassis.ParseFromArray(strdata,nSize))
  1990. {
  1991. std::cout<<"iv::decition::BrainDecition::UpdateChassis ParseFrom Array Error."<<std::endl;
  1992. return;
  1993. }
  1994. if((xchassis.has_epsmode())&&(xchassis.epsmode() == 0))
  1995. {
  1996. ServiceCarStatus.mbRunPause = true;
  1997. }
  1998. if((xchassis.has_soc()))
  1999. {
  2000. mfSOC = xchassis.soc();
  2001. }
  2002. }
  2003. void ADCIntelligentVehicle::onTimerManual()
  2004. {
  2005. // if(myview->mPressKeys.count() == 0)return;
  2006. if(mbManual == false)
  2007. {
  2008. if(myview->mPressKeys.contains(Qt::Key_J))
  2009. {
  2010. mbManual = true;
  2011. }
  2012. }
  2013. if(mbManual == true)
  2014. {
  2015. if(myview->mPressKeys.contains(Qt::Key_K))
  2016. {
  2017. mbManual = false;
  2018. }
  2019. }
  2020. if(mbManual == false)return;
  2021. int timediff = mManualTime.elapsed() - mnLastManualTime;
  2022. mnLastManualTime = mManualTime.elapsed();
  2023. if(myview->mPressKeys.contains(Qt::Key_W))
  2024. {
  2025. if(mnCtrlValue[0]<1000)mnCtrlValue[0] = mnCtrlValue[0] + 5 * timediff /20;
  2026. }
  2027. if(myview->mPressKeys.contains(Qt::Key_S))
  2028. {
  2029. mnCtrlValue[0] = 0;
  2030. if(mnCtrlValue[1]<990) mnCtrlValue[1] = mnCtrlValue[1] + 10* timediff /20;
  2031. }
  2032. else
  2033. {
  2034. mnCtrlValue[1] = 0;
  2035. }
  2036. if(myview->mPressKeys.contains(Qt::Key_A))
  2037. {
  2038. if(mnCtrlValue[2]<500)mnCtrlValue[2] = mnCtrlValue[2] + 3* timediff /20;
  2039. }
  2040. if(myview->mPressKeys.contains(Qt::Key_D))
  2041. {
  2042. if(mnCtrlValue[2]>-500)mnCtrlValue[2] = mnCtrlValue[2] - 3* timediff /20;
  2043. }
  2044. iv::modulecomm::ModuleSendMsg(mpManualCtrl,(char *)mnCtrlValue,3*sizeof(int));
  2045. }
  2046. void ADCIntelligentVehicle::onCtrlManual(bool bCtrl)
  2047. {
  2048. mbManual = bCtrl;
  2049. if(bCtrl)
  2050. {
  2051. mTimerManual->start(10);
  2052. mManualTime.start();
  2053. mnLastManualTime = mManualTime.elapsed();
  2054. }
  2055. else
  2056. {
  2057. mTimerManual->stop();
  2058. mnCtrlValue[0] = 0; mnCtrlValue[1] = 0; mnCtrlValue[2] = 0;
  2059. }
  2060. }
  2061. void ADCIntelligentVehicle::on_pb_v2xEn_clicked()
  2062. {
  2063. qDebug()<<mv2xStEn;
  2064. if(mv2xStEn){
  2065. ui->pb_v2xEn->setText(tr("云平台控制:关"));
  2066. mv2xStEn = 0;
  2067. }
  2068. else{
  2069. ui->pb_v2xEn->setText(tr("云平台控制:开"));
  2070. mv2xStEn = 1;
  2071. }
  2072. gIvlog->info("hmi","v2x enable:%d", mv2xStEn);
  2073. UpdateV2xStEn(mv2xStEn);
  2074. }
  2075. void ADCIntelligentVehicle::shareMapReqMsg()
  2076. {
  2077. iv::map::mapreq x;
  2078. x.set_maptype(1);
  2079. int nsize = x.ByteSize();
  2080. char * str = new char[nsize];
  2081. if(x.SerializeToArray(str,nsize))
  2082. {
  2083. iv::modulecomm::ModuleSendMsg(mpamapreq,str,nsize);
  2084. }
  2085. else
  2086. {
  2087. std::cout<<"iv::map::mapreq serialize error."<<std::endl;
  2088. }
  2089. std::cout<<"iv::map::mapreq serialize OK."<<std::endl;
  2090. delete str;
  2091. }
  2092. void ADCIntelligentVehicle::UpdateVbox(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
  2093. {
  2094. iv::vbox::vbox xvbox;
  2095. if(!xvbox.ParseFromArray(strdata,nSize))
  2096. {
  2097. gIvlog->warn("ADCIntelligentVehicle::UpdateVbox parse errror. nSize is %d",nSize);
  2098. return;
  2099. }
  2100. ServiceCarStatus.st_straight = xvbox.st_straight();
  2101. ServiceCarStatus.st_left = xvbox.st_left();
  2102. ServiceCarStatus.st_right = xvbox.st_right();
  2103. ServiceCarStatus.st_turn = xvbox.st_turn();
  2104. ServiceCarStatus.time_straight = xvbox.time_straight();
  2105. ServiceCarStatus.time_left = xvbox.time_left();
  2106. ServiceCarStatus.time_right = xvbox.time_right();
  2107. ServiceCarStatus.time_turn = xvbox.time_turn();
  2108. }
  2109. void ADCIntelligentVehicle::onStateTimer1()
  2110. {
  2111. ui->lcdNumber->display((int)ServiceCarStatus.time_turn);
  2112. ui->lcdNumber_2->display((int)ServiceCarStatus.time_left);
  2113. ui->lcdNumber_3->display((int)ServiceCarStatus.time_straight);
  2114. ui->lcdNumber_4->display((int)ServiceCarStatus.time_right);
  2115. static uint32_t xturn = -1;
  2116. static uint32_t xstraiht = -1;
  2117. static uint32_t xright = -1;
  2118. static uint32_t xleft = -1;
  2119. if(xturn != ServiceCarStatus.st_turn)
  2120. {
  2121. xturn = ServiceCarStatus.st_turn;
  2122. switch (ServiceCarStatus.st_turn) {
  2123. case 0:
  2124. img.load(":/light_image/diaotou-black.png");
  2125. img = img.scaled(66,66,Qt::IgnoreAspectRatio);
  2126. ui->label_38->setPixmap(QPixmap::fromImage(img));
  2127. break;
  2128. case 1:
  2129. img.load(":/light_image/diaotou-green.png");
  2130. img = img.scaled(66,66,Qt::IgnoreAspectRatio);
  2131. ui->label_38->setPixmap(QPixmap::fromImage(img));
  2132. break;
  2133. case 2:
  2134. img.load(":/light_image/diaotou-red.png");
  2135. img = img.scaled(66,66,Qt::IgnoreAspectRatio);
  2136. ui->label_38->setPixmap(QPixmap::fromImage(img));
  2137. break;
  2138. case 3:
  2139. img.load(":/light_image/diaotou-yellow.png");
  2140. img = img.scaled(66,66,Qt::IgnoreAspectRatio);
  2141. ui->label_38->setPixmap(QPixmap::fromImage(img));
  2142. break;
  2143. default:
  2144. img.load(":/light_image/diaotou-black.png");
  2145. img = img.scaled(66,66,Qt::IgnoreAspectRatio);
  2146. ui->label_38->setPixmap(QPixmap::fromImage(img));
  2147. break;
  2148. }
  2149. }
  2150. if(xleft != ServiceCarStatus.st_left)
  2151. {
  2152. xleft = ServiceCarStatus.st_left;
  2153. switch (ServiceCarStatus.st_left) {
  2154. case 0:
  2155. img2.load(":/light_image/zuoguai-black.png");
  2156. img2 = img2.scaled(66,66,Qt::IgnoreAspectRatio);
  2157. ui->label_33->setPixmap(QPixmap::fromImage(img2));
  2158. break;
  2159. case 1:
  2160. img2.load(":/light_image/zuoguai-green.png");
  2161. img2 = img2.scaled(66,66,Qt::IgnoreAspectRatio);
  2162. ui->label_33->setPixmap(QPixmap::fromImage(img2));
  2163. break;
  2164. case 2:
  2165. img2.load(":/light_image/zuoguai-red.png");
  2166. img2 = img2.scaled(66,66,Qt::IgnoreAspectRatio);
  2167. ui->label_33->setPixmap(QPixmap::fromImage(img2));
  2168. break;
  2169. case 3:
  2170. img2.load(":/light_image/zuoguai-yellow.png");
  2171. img2 = img2.scaled(66,66,Qt::IgnoreAspectRatio);
  2172. ui->label_33->setPixmap(QPixmap::fromImage(img2));
  2173. break;
  2174. default:
  2175. img2.load(":/light_image/zuoguai-black.png");
  2176. img2 = img2.scaled(66,66,Qt::IgnoreAspectRatio);
  2177. ui->label_33->setPixmap(QPixmap::fromImage(img2));
  2178. break;
  2179. }
  2180. }
  2181. if(xstraiht != ServiceCarStatus.st_straight)
  2182. {
  2183. xstraiht = ServiceCarStatus.st_straight;
  2184. switch (ServiceCarStatus.st_straight) {
  2185. case 0:
  2186. img3.load(":/light_image/zhixing-black.png");
  2187. img3 = img3.scaled(66,66,Qt::IgnoreAspectRatio);
  2188. ui->label_35->setPixmap(QPixmap::fromImage(img3));
  2189. break;
  2190. case 1:
  2191. img3.load(":/light_image/zhixing-green.png");
  2192. img3 = img3.scaled(66,66,Qt::IgnoreAspectRatio);
  2193. ui->label_35->setPixmap(QPixmap::fromImage(img3));
  2194. break;
  2195. case 2:
  2196. img3.load(":/light_image/zhixing-red.png");
  2197. img3 = img3.scaled(66,66,Qt::IgnoreAspectRatio);
  2198. ui->label_35->setPixmap(QPixmap::fromImage(img3));
  2199. break;
  2200. case 3:
  2201. img3.load(":/light_image/zhixing-yellow.png");
  2202. img3 = img3.scaled(66,66,Qt::IgnoreAspectRatio);
  2203. ui->label_35->setPixmap(QPixmap::fromImage(img3));
  2204. break;
  2205. default:
  2206. img3.load(":/light_image/zhixing-black.png");
  2207. img3 = img3.scaled(66,66,Qt::IgnoreAspectRatio);
  2208. ui->label_35->setPixmap(QPixmap::fromImage(img3));
  2209. break;
  2210. }
  2211. }
  2212. if(xright != ServiceCarStatus.st_right)
  2213. {
  2214. xright = ServiceCarStatus.st_right;
  2215. switch (ServiceCarStatus.st_right) {
  2216. case 0:
  2217. img4.load(":/light_image/youguai-black.png");
  2218. img4 = img4.scaled(66,66,Qt::IgnoreAspectRatio);
  2219. ui->label_32->setPixmap(QPixmap::fromImage(img4));
  2220. break;
  2221. case 1:
  2222. img4.load(":/light_image/youguai-green.png");
  2223. img4 = img4.scaled(66,66,Qt::IgnoreAspectRatio);
  2224. ui->label_32->setPixmap(QPixmap::fromImage(img4));
  2225. break;
  2226. case 2:
  2227. img4.load(":/light_image/youguai-red.png");
  2228. img4 = img4.scaled(66,66,Qt::IgnoreAspectRatio);
  2229. ui->label_32->setPixmap(QPixmap::fromImage(img4));
  2230. break;
  2231. case 3:
  2232. img4.load(":/light_image/youguai-yellow.png");
  2233. img4 = img4.scaled(66,66,Qt::IgnoreAspectRatio);
  2234. ui->label_32->setPixmap(QPixmap::fromImage(img4));
  2235. break;
  2236. default:
  2237. img4.load(":/light_image/youguai-black.png");
  2238. img4 = img4.scaled(66,66,Qt::IgnoreAspectRatio);
  2239. ui->label_32->setPixmap(QPixmap::fromImage(img4));
  2240. break;
  2241. }
  2242. }
  2243. }
  2244. void ADCIntelligentVehicle::on_pBtn_door_open_clicked()
  2245. {
  2246. iv::hmi::HMIBasic hmi;
  2247. hmi.mbchemen = true;
  2248. ShareHMIMsg(hmi);
  2249. }
  2250. void ADCIntelligentVehicle::on_pBtn_door_close_clicked()
  2251. {
  2252. iv::hmi::HMIBasic hmi;
  2253. hmi.mbchemen = false;
  2254. ShareHMIMsg(hmi);
  2255. }
  2256. void ADCIntelligentVehicle::on_pBtn_low_beam_open_clicked()
  2257. {
  2258. iv::hmi::HMIBasic hmi;
  2259. hmi.mbjinguang = true;
  2260. ShareHMIMsg(hmi);
  2261. }
  2262. void ADCIntelligentVehicle::on_pBtn_low_beam_close_clicked()
  2263. {
  2264. iv::hmi::HMIBasic hmi;
  2265. hmi.mbjinguang = false;
  2266. ShareHMIMsg(hmi);
  2267. }
  2268. void ADCIntelligentVehicle::on_pBtn_high_beam_open_clicked()
  2269. {
  2270. iv::hmi::HMIBasic hmi;
  2271. hmi.mbyuanguang = true;
  2272. ShareHMIMsg(hmi);
  2273. }
  2274. void ADCIntelligentVehicle::on_pBtn_high_beam_close_clicked()
  2275. {
  2276. iv::hmi::HMIBasic hmi;
  2277. hmi.mbyuanguang = false;
  2278. ShareHMIMsg(hmi);
  2279. }
  2280. void ADCIntelligentVehicle::threadCalcDrawTrace()
  2281. {
  2282. bool mbRun = true;
  2283. qint64 nMapUpdateTime = 0;
  2284. std::vector<iv::MapPointDomain> xvectorMapDomain;
  2285. xvectorMapDomain.clear();
  2286. std::vector<iv::GPSData> xvectoroptmap;
  2287. double foldx = 0;
  2288. double foldy = 0;
  2289. double foldhdg = 0;
  2290. const int nDomainSize = 30;
  2291. int nOldDomain_x = 0;
  2292. int nOldDomain_y = 0;
  2293. bool bMapUpdate = false;
  2294. while(mbRun)
  2295. {
  2296. std::this_thread::sleep_for(std::chrono::milliseconds(9));
  2297. if(nMapUpdateTime != mnNaviUpdateTime)
  2298. {
  2299. nMapUpdateTime = mnNaviUpdateTime;
  2300. std::vector<iv::GPSData> navigation_data;
  2301. mMutexNavi.lock();
  2302. navigation_data = m_navigation_data;
  2303. mMutexNavi.unlock();
  2304. UpdateMapDomain(navigation_data,xvectorMapDomain,nDomainSize);
  2305. bMapUpdate = true;
  2306. }
  2307. double fHeading = ServiceCarStatus.location->ins_heading_angle;
  2308. double fX = ServiceCarStatus.location->gps_x;
  2309. double fY = ServiceCarStatus.location->gps_y;
  2310. if((fabs(fHeading - foldhdg)<0.1)&&(fabs(foldx - fX)<0.1)&&(fabs(foldy - fY)<0.1) &&(bMapUpdate == false))
  2311. {
  2312. continue;
  2313. }
  2314. foldhdg = fHeading;
  2315. foldx = fX;
  2316. foldy = fY;
  2317. int nNowDomain_x = ((int)(fX/(double)nDomainSize))*nDomainSize;
  2318. int nNowDomain_y = ((int)(fY/(double)nDomainSize))*nDomainSize;
  2319. //Decide Need Update map
  2320. if((nNowDomain_x != nOldDomain_x) ||(nNowDomain_y != nOldDomain_y) || bMapUpdate)
  2321. {
  2322. bMapUpdate = false;
  2323. nOldDomain_x = nNowDomain_x;
  2324. nOldDomain_y = nNowDomain_y;
  2325. //Need Update option Map
  2326. xvectoroptmap.clear();
  2327. unsigned int i;
  2328. for(i=0;i<xvectorMapDomain.size();i++)
  2329. {
  2330. if(fabs(pow(xvectorMapDomain[i].mxpos - nNowDomain_x,2)+pow(xvectorMapDomain[i].mypos - nNowDomain_y,2))>150)
  2331. {
  2332. continue;
  2333. }
  2334. unsigned int j;
  2335. for(j=0;j<xvectorMapDomain[i].mvectorgpsdata.size();j++)
  2336. {
  2337. xvectoroptmap.push_back(xvectorMapDomain[i].mvectorgpsdata[j]);
  2338. }
  2339. }
  2340. }
  2341. std::vector<double> xDraw_x0,xDraw_y0,xDraw_x1,xDraw_y1,xDraw_x2,xDraw_y2;
  2342. int sizeN = xvectoroptmap.size();
  2343. for (int i = 0; i < sizeN; i++)
  2344. {
  2345. // if(i == 1)std::cout<<" x1 = "<<x0[i]<<std::endl;
  2346. double x0,y0,x1,y1,x2,y2,k,k1,k2,xx,yy;
  2347. x0 = xvectoroptmap[i]->gps_x - fX;
  2348. y0 = xvectoroptmap[i]->gps_y - fY;
  2349. xx = x0;
  2350. yy = y0;
  2351. x0 = xx * cos(fHeading * PI / 180) - yy * sin(fHeading * PI / 180);
  2352. y0 = xx * sin(fHeading * PI / 180) + yy * cos(fHeading * PI / 180);
  2353. k1 = sin((90 + (xvectoroptmap[i]->ins_heading_angle - fHeading)) * PI / 180);
  2354. k2 = cos((90 + (xvectoroptmap[i]->ins_heading_angle - fHeading)) * PI / 180);
  2355. #if 0
  2356. x1[i] = x0[i] + k1 * 5;
  2357. y1[i] = y0[i] + k2 * 5;
  2358. x2[i] = x0[i] - k1 * 5;
  2359. y2[i] = y0[i] - k2 * 5;
  2360. #else
  2361. x1 = x0+ k1 * 1.75;
  2362. y1 = y0 + k2 * 1.75;
  2363. x2 = x0 - k1 * 1.75;
  2364. y2 = y0 - k2 * 1.75;
  2365. #endif
  2366. xDraw_x0.push_back(x0);
  2367. xDraw_y0.push_back(y0);
  2368. xDraw_x1.push_back(x1);
  2369. xDraw_y1.push_back(y1);
  2370. xDraw_x2.push_back(x2);
  2371. xDraw_y2.push_back(y2);
  2372. mMutexDraw.lock();
  2373. mDraw_x0 = xDraw_x0;
  2374. mDraw_x1 = xDraw_x1;
  2375. mDraw_x2 = xDraw_x2;
  2376. mDraw_y0 = xDraw_y0;
  2377. mDraw_y1 = xDraw_y1;
  2378. mDraw_y2 = xDraw_y2;
  2379. mMutexDraw.unlock();
  2380. }
  2381. }
  2382. }
  2383. void ADCIntelligentVehicle::UpdateMapDomain(std::vector<iv::GPSData> &xvectorMap, std::vector<iv::MapPointDomain> &xvectorMapDomain,const int nDomainSize)
  2384. {
  2385. xvectorMapDomain.clear();
  2386. int nsize = xvectorMap.size();
  2387. int i;
  2388. for(i=0;i<nsize;i++)
  2389. {
  2390. iv::GPSData xGPSData = xvectorMap[i];
  2391. int npos = -1;
  2392. int nMapDomainsize = xvectorMapDomain.size();
  2393. double xpos = xGPSData->gps_x;
  2394. double ypos = xGPSData->gps_y;
  2395. xpos = xpos/((double)nDomainSize);
  2396. ypos = ypos/((double)nDomainSize);
  2397. int nxpos = (int)xpos;
  2398. int nypos = (int)ypos;
  2399. nxpos = nxpos * nDomainSize;
  2400. nypos = nypos * nDomainSize;
  2401. //Find a map Domain
  2402. int j;
  2403. for(j=0;j<nMapDomainsize;j++)
  2404. {
  2405. if((nxpos == xvectorMapDomain[j].mxpos) &&(nypos == xvectorMapDomain[j].mypos))
  2406. {
  2407. npos = j;
  2408. break;
  2409. }
  2410. }
  2411. //not found, add one.
  2412. if(npos == -1)
  2413. {
  2414. iv::MapPointDomain xMP;
  2415. xMP.mxpos = nxpos;
  2416. xMP.mypos = nypos;
  2417. xMP.mvectorgpsdata.push_back(xGPSData);
  2418. xvectorMapDomain.push_back(xMP);
  2419. }
  2420. else
  2421. {
  2422. xvectorMapDomain[npos].mvectorgpsdata.push_back(xGPSData);
  2423. }
  2424. }
  2425. }