ADCIntelligentVehicle.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. #ifndef ADCINTELLIGENTVEHICLE_H
  2. #define ADCINTELLIGENTVEHICLE_H
  3. #include <QMainWindow>
  4. #include <QtWidgets/QMainWindow>
  5. #include <common/boost.h>
  6. //#include <control/control_status.h>
  7. //#include <control/can.h>
  8. #include "ui_ADCIntelligentVehicle.h"
  9. //#include <decition/brain.h>
  10. //#include <control/can.h>
  11. #include "look.h"
  12. #include <common/car_status.h>
  13. #include <qtimer.h>
  14. #include <qpainter.h>
  15. #include <QGraphicsView>
  16. #include <QWheelEvent>
  17. #include <QKeyEvent>
  18. #include <QPoint>
  19. #include <QPointF>
  20. #include <qfiledialog.h>
  21. #include <qmessagebox.h>
  22. #include <QCloseEvent>
  23. #include <qabstractscrollarea.h>
  24. #include <QGraphicsItem>
  25. #include <QKeyEvent>
  26. #include <qpainter.h>
  27. #include <QDebug>
  28. #include <string>
  29. #include <cassert>
  30. #include <iostream>
  31. #include <sstream>
  32. #include <math.h>
  33. #include <mobileye_info.h>
  34. #include <QUdpSocket>
  35. #include <QHostAddress>
  36. #include <QTime>
  37. #include <QSet>
  38. #include <QtWebEngineWidgets/QtWebEngineWidgets>
  39. #include "common/can_type.h"
  40. #include "common/decition_type.h"
  41. #include "common/vehiclestate_type.h"
  42. #include "common/hmi_type.h"
  43. #include "common/lidar.h"
  44. #include "common/obstacle_type.h"
  45. #include "common/constants.h"
  46. #include "../../../src/decition/common/common/tracepointstation.h"
  47. #include "modulecomm.h"
  48. #include <QMutex>
  49. //#include <platform/platform.h>
  50. #include "hmi.pb.h"
  51. #include "gpsimu.pb.h"
  52. #include "radarobjectarray.pb.h"
  53. #include "decition.pb.h"
  54. #include "brainstate.pb.h"
  55. #include "canstate.pb.h"
  56. #include "v2x.pb.h"
  57. #include "mobileye.pb.h"
  58. #include "ivlog.h"
  59. #include "mapreq.pb.h"
  60. #include "vbox.pb.h"
  61. #include "fusionobject.pb.h"
  62. #include "fusionobjectarray.pb.h"
  63. #include "brainrunstate.pb.h"
  64. extern iv::Ivlog * gIvlog;
  65. #define USE_PAD_CTRL
  66. class MyView : public QGraphicsView
  67. {
  68. Q_OBJECT
  69. public:
  70. MyView(QWidget *parent);
  71. qreal x, y, beishu; //倍数
  72. protected:
  73. void wheelEvent(QWheelEvent *event) Q_DECL_OVERRIDE; //Q_DECL_OVERRIDE也就是c++的override 作用是防止写错虚函数:
  74. void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
  75. void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
  76. void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
  77. void keyPressEvent(QKeyEvent *event) Q_DECL_OVERRIDE;
  78. void keyReleaseEvent(QKeyEvent *event) Q_DECL_OVERRIDE;
  79. signals:
  80. void CtrlManual(bool bManual);
  81. public:
  82. QSet<int> mPressKeys;
  83. public Q_SLOTS:
  84. void zoomIn(); // 放大
  85. void zoomOut(); // 缩小
  86. private:
  87. bool bottonstatus = false;
  88. QPoint myview_lastMousePos;
  89. };
  90. namespace Ui {
  91. class ADCIntelligentVehicle;
  92. }
  93. struct packageHead
  94. {
  95. unsigned char type;
  96. int size;
  97. };
  98. struct dataInfo //与PAD通信结构体
  99. {
  100. unsigned char is_run = 0;
  101. unsigned char is_mapLoad = 0;
  102. unsigned char is_initSuccess = 0;
  103. double speed;
  104. double accelerate;
  105. double brake;
  106. double swerve;
  107. double gps_lng;
  108. double gps_lat;
  109. double gps_head;
  110. double radarobs;
  111. double lidarobs;
  112. double obs;
  113. unsigned char RTKstatus;
  114. unsigned char radarStatus;
  115. unsigned char lidarStatus;
  116. unsigned char boche_status;
  117. };
  118. class DataToUI
  119. {
  120. public:
  121. struct packageHead mHead;
  122. struct dataInfo mInfo;
  123. };
  124. //Split Map to Some Domain for quick find gps point for draw.
  125. namespace iv {
  126. struct MapPointDomain
  127. {
  128. public:
  129. int mxpos;
  130. int mypos;
  131. std::vector<iv::GPSData> mvectorgpsdata;
  132. };
  133. }
  134. class ADCIntelligentVehicle : public QMainWindow
  135. {
  136. Q_OBJECT
  137. public:
  138. explicit ADCIntelligentVehicle(QWidget *parent = 0);
  139. ~ADCIntelligentVehicle();
  140. public slots:
  141. void savestabuyEditinfo(const QString &txt);
  142. // void on_pb_load_navigation_data_clicked(); //加载地图 当前没有实现
  143. void on_pb_start_all_clicked(); //启动无人驾驶
  144. // void on_pb_open_can_card_clicked(); //打开can
  145. void on_pb_auto_drive_mode_clicked(); //自动驾驶使能
  146. void on_pb_auto_braking_mode_clicked(); //自动刹车使能
  147. void on_pb_auto_accelerate_mode_clicked(); //自动油门使能
  148. void on_pb_auto_wheel_mode_clicked(); //自动方向盘使能
  149. void on_pushButton_clicked();
  150. void on_pb_speed_control_mode_clicked(); //速度控制模式使能
  151. void on_hs_braking_percent_valueChanged(int value); //响应刹车压力改变
  152. void on_hs_accelerate_percent_valueChanged(int value); //响应油门改变
  153. void on_hs_wheel_angle_valueChanged(int value); //响应方向盘改变
  154. // void on_pushButton_2_clicked(); //打开地图采集器
  155. void on_pushButton_3_clicked();
  156. void on_pushButton_4_clicked();
  157. void on_timer_car_status_time_out(); //获取车辆状态定时器响应
  158. void on_timer_mobileye_info_time_out();
  159. virtual void paintEvent(QPaintEvent *);
  160. void timeoutslot();
  161. void onRecvUDP();
  162. void onStateTimer();
  163. void onStateTimerMap();
  164. void onStateTimer1();
  165. protected:
  166. void keyPressEvent(QKeyEvent *event) Q_DECL_OVERRIDE;// 加/减键进行缩放
  167. void closeEvent(QCloseEvent *event);
  168. private slots:
  169. void on_listWidget_clicked();
  170. void on_pushButton_5_clicked();
  171. void on_pushButton_6_clicked();
  172. void on_pushButton_7_clicked();
  173. void on_pushButton_8_clicked();
  174. void on_pushButton_9_clicked();
  175. void onTimerManual();
  176. void onCtrlManual(bool bCtrl);
  177. void on_pb_v2xEn_clicked();
  178. void on_pBtn_door_open_clicked();
  179. void on_pBtn_door_close_clicked();
  180. void on_pBtn_low_beam_open_clicked();
  181. void on_pBtn_low_beam_close_clicked();
  182. void on_pBtn_high_beam_open_clicked();
  183. void on_pBtn_high_beam_close_clicked();
  184. private:
  185. Ui::ADCIntelligentVehicle *ui;
  186. /**************************************/
  187. QWebEngineView * mMapview;
  188. /**************************************/
  189. // boost::shared_ptr<iv::decition::BrainDecition> brain;
  190. bool is_brain_running_flag_ = false;
  191. bool is_map_loaded_flag_ = false;
  192. bool is_can_opened_ = false;
  193. bool is_auto_drive_mode_enable_ = false;
  194. bool is_auto_braking_mode_enable_ = false;
  195. bool is_auto_accelerate_mode_enable_ = false;
  196. bool is_auto_wheel_mode_enable_ = false;
  197. bool is_3 = false;
  198. bool is_speed_control_mode_enable_ = false;
  199. bool is_show_enable = false;
  200. Look_decition *look_decition;
  201. Mobileye_info *mobileye_info;
  202. Qt::MouseButton m_translateButton; // 平移按钮
  203. qreal m_translateSpeed; // 平移速度
  204. qreal m_zoomDelta; // 缩放的增量
  205. bool m_bMouseTranslate; // 平移标识
  206. QPoint m_lastMousePos; // 鼠标最后按下的位置
  207. qreal m_scale; // 缩放值
  208. QTimer * timer_car_status;
  209. QTimer * timer_mobileye_info;
  210. qreal horizontalOffset;
  211. qreal verticalOffset;
  212. qreal scaleFactor;
  213. qreal currentStepScaleFactor;
  214. QImage *image,*image_small;
  215. QPainter *painter,*painter_small;
  216. MyView *myview,*myview_small;
  217. QTimer *timer;
  218. QGraphicsScene *scene,*scene_small;
  219. iv::ObsLiDAR Lidar_read;
  220. iv::ObsLiDAR Lidar_obsread;
  221. iv::ObsRadar RadarDate;
  222. double asd = 0.0;
  223. int load_counts = 0;
  224. void AutoStart();
  225. QUdpSocket msocksend;
  226. QUdpSocket msockrecv;
  227. QTimer mTimerState;
  228. QTimer mTimerStateMap;
  229. DataToUI mDataToUI;
  230. QTime mTime;
  231. int mnTimeLastUpdatePaint;
  232. void * mpa;
  233. QMutex mMutexNavi;
  234. std::vector<iv::GPSData> m_navigation_data;
  235. qint64 mnNaviUpdateTime = 0;
  236. bool mbBrainRunning = false;
  237. double mdecition_period = 0;
  238. QTime mTimeState;
  239. int mnTimeUpdateGPS= 0;
  240. int mnTimeUpdateRadar=0;
  241. int mnTimeUpdateDecition=0;
  242. int mnTimeUpdateVS=0;
  243. int mnTimeUpdateCANState=0;
  244. double mfSOC = 0.0;
  245. void * mpManualCtrl;
  246. bool mbManual= false;
  247. QTimer * mTimerManual;
  248. int mnCtrlValue[3]; //Acc Brake Gear Acc 0-1000 Brake 0-1000 Gear -500 --- 500
  249. QTime mManualTime;
  250. int mnLastManualTime;
  251. void * mpafusiongpsimu;
  252. int64_t mnLastFusionGPSIMUUpdate = 0;
  253. private:
  254. void UpdateMap(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname);
  255. private:
  256. void * mpagpsimu;
  257. public:
  258. void UpdateGPSIMU(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname);
  259. unsigned int mv2xStEn = 0;
  260. private:
  261. void * mparadar;
  262. private:
  263. iv::radar::radarobjectarray mradararray;
  264. bool mbradarUpdate = false;
  265. QMutex mMutexRadar;
  266. void UpdateRADAR(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname);
  267. void UpdateChassis(const char *strdata, const unsigned int nSize, const unsigned int index, const QDateTime *dt, const char *strmemname);
  268. void * mpachassis;
  269. private:
  270. void * mpacanstate;
  271. public:
  272. int mimobileyeState;
  273. public:
  274. void UpdateCANState(const char * pdata,const int ndatasize);
  275. private:
  276. void * mpaDecition;
  277. public:
  278. void UpdateDecition(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname);
  279. private:
  280. void * mpaVechicleState;
  281. public:
  282. void UpdateVehicleState(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname);
  283. void UpdateBrainRunState(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname);
  284. private:
  285. void * mpaHMI;
  286. /***********20200509****************/
  287. public:
  288. void UpdatePlanTrace(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname);
  289. void UpdatePlanTrace_left(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname);
  290. void UpdatePlanTrace_right(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname);
  291. std::vector<iv::TracePoint> m_plan,m_plan_left,m_plan_right;
  292. QMutex mMutexPlan,mMutexPlan_left,mMutexPlan_right;
  293. private:
  294. void * mpaplantrace;
  295. void * mpaplantrace_left;
  296. void * mpaplantrace_right;
  297. /**************************/
  298. /**********20210429***********************/
  299. public:
  300. void UpdateFusion(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname);
  301. QMutex mMutexFusion;
  302. private:
  303. iv::fusion::fusionobjectarray mfusionarray;
  304. bool mbfusionUpdate = false;
  305. void * mpafusion;
  306. /*****************************************/
  307. private:
  308. void * mpaLidar;
  309. public:
  310. void UpdateOBS(std::shared_ptr<std::vector<iv::ObstacleBasic> > lidar_obs);
  311. void UpdateV2xStEn(unsigned int enable);
  312. private:
  313. void * mp_v2xStSend;
  314. void ShareHMIMsg(iv::hmi::HMIBasic xhmi);
  315. iv::Ivlog * mpivlog;
  316. // iv::platform::Client mplatform_client;
  317. public:
  318. void * mpamapreq; //请求地图
  319. void shareMapReqMsg();
  320. private:
  321. void * mpaVbox;
  322. public:
  323. void UpdateVbox(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname);
  324. private:
  325. QImage img,img2,img3,img4;
  326. QTimer mTimerState1;
  327. private:
  328. void threadCalcDrawTrace(); //Thread for caluclate draw trace.
  329. void UpdateMapDomain(std::vector<iv::GPSData> & xvectorMap,std::vector<iv::MapPointDomain> & xvectorMapDomain,const int nDomainSize);
  330. std::vector<double> mDraw_x0,mDraw_y0,mDraw_x1,mDraw_y1,mDraw_x2,mDraw_y2; //Save Draw Point
  331. QMutex mMutexDraw;
  332. };
  333. #endif