ADCIntelligentVehicle.cpp 77 KB

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