ADCIntelligentVehicle.cpp 75 KB

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