mainwindow.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. #ifndef MAINWINDOW_H
  2. #define MAINWINDOW_H
  3. #include "v2x.h"
  4. #include "pc5.h"
  5. #include <QMainWindow>
  6. #include <QDialog>
  7. #include <QInputDialog>
  8. #include <iostream>
  9. #include "QDebug"
  10. #include <QTextCodec>
  11. #include "xmlparam.h"
  12. #include <string>
  13. #include "v2r.pb.h"
  14. #include "gpsimu.pb.h"
  15. #include "rawpic.pb.h"
  16. #include "fusionobjectarray.pb.h"
  17. #include "fusionobject.pb.h"
  18. #include "radarobject.pb.h"
  19. #include "lightarray.pb.h"
  20. #include "ivlog.h"
  21. #include "modulecomm.h"
  22. #include <QtXml>
  23. #include <QDomComment>
  24. #include <QFile>
  25. #include <cmath>
  26. #include <string>
  27. #include <iostream>
  28. namespace Ui {
  29. class MainWindow;
  30. }
  31. struct onelightMessage
  32. {
  33. bool isEnable=false;
  34. unsigned char lightType;//0x01:绿灯;0x02:红灯;0x03:黄灯;
  35. int timeRemaining;
  36. };
  37. class MainWindow : public QMainWindow
  38. {
  39. Q_OBJECT
  40. public:
  41. explicit MainWindow(QWidget *parent = 0);
  42. ~MainWindow();
  43. PC5 *m_pc5;
  44. V2X *m_tbox;
  45. void initUI();//程序初始化
  46. void initproto();//共享内存初始化
  47. void initLight1();//红绿灯1初始化
  48. void initLight2();//红绿灯2初始化
  49. void initLight3();//红绿灯3初始化
  50. void initLight4();//红绿灯4初始化
  51. void initFace();//红绿灯4初始化
  52. //void *gfu = iv::modulecomm::RegisterSend("li_ra_fusion",10000000,1);
  53. void *gfu = iv::modulecomm::RegisterSend("v2v_send",10000000,1);
  54. void sendProto(iv::v2r::v2r_send radio_protobuf_send);//发送共享内存数据
  55. void UpdateGps(const char *strdata, const unsigned int nSize, const unsigned int index, const QDateTime *dt, const char *strmemname);//读取共享内存
  56. void UpdateCAM(const char *strdata, const unsigned int nSize, const unsigned int index, const QDateTime *dt, const char *strmemname);//读取共享内存
  57. void UpdateLIDAR(const char *strdata, const unsigned int nSize, const unsigned int index, const QDateTime *dt, const char *strmemname);//读取共享内存
  58. void UpdateRADAR(const char *strdata, const unsigned int nSize, const unsigned int index, const QDateTime *dt, const char *strmemname);//读取共享内存
  59. void Updatelight(const char *strdata, const unsigned int nSize, const unsigned int index, const QDateTime *dt, const char *strmemname);//读取红绿灯共享内存并转发
  60. void outLight(onelightMessage light);//设置红绿灯共享内存数据
  61. void outRealtimeTraffic(realtimeTrafficMessage realtimeTraffic);//设置路况信息共享内存数据
  62. void outCollisionWarning(collisionEarlyWarningMessage collisionWarning);//设置碰撞预警共享内存数据
  63. void outCongestionIdenti(congestionIdentificationMessage congestionIdenti);//设置交通拥堵共享内存数据
  64. void outmbpause(bool runmod);//设置自动驾驶启停共享内存数据
  65. void outV2VData(QMap<QString,OBUCarFormation> V2VMessage);
  66. void setTboxMemoryRaw();//云平台发送数据设置
  67. void initMemory();//云平台路测数据赋初值
  68. bool RSUTYPE=false;
  69. // void getRandomNum();
  70. // void initRadio();
  71. private:
  72. Ui::MainWindow *ui;
  73. QTimer *timer;
  74. QTimer *timerV2V;
  75. //----------共享内存变量--------------------
  76. std::string gstrmemgps;
  77. std::string gstrmemlight;
  78. std::string gstrmecamera;
  79. std::string gstrmelidar;
  80. std::string gstrmeradar;
  81. void *mpMemGPS;
  82. void *mpMemcamera;
  83. void *mpMemlidar;
  84. void *mpMemradar;
  85. void *vision_lightMem;
  86. int visionsendstate;
  87. double lightStopLat;
  88. double lightStopLon;
  89. double light1Stophead;
  90. double light1StopLat;
  91. double light1StopLon;
  92. double light2Stophead;
  93. double light2StopLat;
  94. double light2StopLon;
  95. //-----------使能变量-------------------------
  96. bool mplatformEn = false;//云平台使能状态
  97. bool mobuEn = false;//obu使能状态
  98. bool mv2xRunmodEn=false;
  99. bool mpc5RunmodEn=false;
  100. bool mVirtualEn=false;//虚拟车使能状态
  101. bool mbTrafficInfoEn = false; //路况信息使能
  102. bool mcusdatashowEn=false;
  103. bool mbFCWEn = false;//碰撞预警使能状态
  104. bool mbdriCrimsEn = false;//危险驾驶使能状态
  105. bool visionflag=true;//视觉红绿灯识别转发使能
  106. bool mshowdebugEn = false;
  107. bool v2vEn = false;
  108. bool v2vshow =false;
  109. bool v2vshowmore =false;
  110. int mGPSs=0;//GPS状态清零计数
  111. int mCAMs=0;//视觉状态清零计数
  112. int mLIDARs=0;//激光状态清零计数
  113. int mRADARs=0;//毫米波状态清零计数
  114. bool sendProto_flag;//共享内存发送使能
  115. // std::vector<int> m_vectorRandom;
  116. // std::vector<std::string> m_vectorVin;
  117. //-------------结构数据----------------------
  118. QImage redimg,greenimg,yellowimg,blackimg,nofaceimg,facetoimg;
  119. realtimeTrafficMessage TrafficMessage;
  120. lightMessage light;
  121. collisionEarlyWarningMessage collisionWarning;
  122. congestionIdentificationMessage congestionIdenti;
  123. void * mpmem_radio_send_addr = nullptr;
  124. gpsImuM m_structMGpsImu;
  125. sensor_state seneor_m;
  126. iv::v2r::v2r_send protobuf;
  127. double calculateRelativeAngle(double selfAngleRad, double targetAngleRad)
  128. {
  129. // 计算目标角度相对于自身角度的相对角度
  130. selfAngleRad = qDegreesToRadians(selfAngleRad);
  131. targetAngleRad = qDegreesToRadians(targetAngleRad);
  132. double relativeAngleRad = targetAngleRad - selfAngleRad;
  133. // 将相对角度调整为在 0 到 2π 之间
  134. while (relativeAngleRad < 0) {
  135. relativeAngleRad += 2.0 * M_PI;
  136. }
  137. // 如果相对角度超过π,则将其调整为π到2π之间
  138. if (relativeAngleRad > 2.0 *M_PI) {
  139. relativeAngleRad = relativeAngleRad-(2.0 * M_PI);
  140. }
  141. // 取反
  142. relativeAngleRad = 2.0 * M_PI - relativeAngleRad;
  143. return relativeAngleRad;
  144. }
  145. void GaussProjCal(double longitude, double latitude, double& X, double& Y)
  146. {
  147. int ProjNo = 0; int ZoneWide; ////带宽
  148. double longitude1, latitude1, longitude0, latitude0, X0, Y0, xval, yval;
  149. double a, f, e2, ee, NN, T, C, A, M, iPI;
  150. iPI = 0.0174532925199433; ////3.1415926535898/180.0;
  151. ZoneWide = 6; ////6度带宽
  152. a = 6378245.0; f = 1.0 / 298.3; //54年北京坐标系参数
  153. ////a=6378140.0; f=1/298.257; //80年西安坐标系参数
  154. ProjNo = (int)(longitude / ZoneWide);
  155. longitude0 = ProjNo * ZoneWide + ZoneWide / 2;
  156. longitude0 = longitude0 * iPI;
  157. latitude0 = 0;
  158. longitude1 = longitude * iPI; //经度转换为弧度
  159. latitude1 = latitude * iPI; //纬度转换为弧度
  160. e2 = 2 * f - f * f;
  161. ee = e2 * (1.0 - e2);
  162. NN = a / sqrt(1.0 - e2 * sin(latitude1)*sin(latitude1));
  163. T = tan(latitude1)*tan(latitude1);
  164. C = ee * cos(latitude1)*cos(latitude1);
  165. A = (longitude1 - longitude0)*cos(latitude1);
  166. 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
  167. *e2 / 1024)*sin(2 * latitude1)
  168. + (15 * e2*e2 / 256 + 45 * e2*e2*e2 / 1024)*sin(4 * latitude1) - (35 * e2*e2*e2 / 3072)*sin(6 * latitude1));
  169. 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);
  170. yval = M + NN * tan(latitude1)*(A*A / 2 + (5 - T + 9 * C + 4 * C*C)*A*A*A*A / 24
  171. + (61 - 58 * T + T * T + 600 * C - 330 * ee)*A*A*A*A*A*A / 720);
  172. X0 = 1000000L * (ProjNo + 1) + 500000L;
  173. Y0 = 0;
  174. xval = xval + X0; yval = yval + Y0;
  175. X = xval;
  176. Y = yval;
  177. }
  178. void GaussProjInvCal(double X, double Y, double *longitude, double *latitude)
  179. {
  180. int ProjNo; int ZoneWide; ////带宽
  181. double longitude1, latitude1, longitude0, latitude0, X0, Y0, xval, yval;
  182. double e1, e2, f, a, ee, NN, T, C, M, D, R, u, fai, iPI;
  183. iPI = 0.0174532925199433; ////3.1415926535898/180.0;
  184. a = 6378245.0; f = 1.0 / 298.3; //54年北京坐标系参数
  185. ////a=6378140.0; f=1/298.257; //80年西安坐标系参数
  186. ZoneWide = 6; ////6度带宽
  187. ProjNo = (int)(X / 1000000L); //查找带号
  188. longitude0 = (ProjNo - 1) * ZoneWide + ZoneWide / 2;
  189. longitude0 = longitude0 * iPI; //中央经线
  190. X0 = ProjNo * 1000000L + 500000L;
  191. Y0 = 0;
  192. xval = X - X0; yval = Y - Y0; //带内大地坐标
  193. e2 = 2 * f - f * f;
  194. e1 = (1.0 - sqrt(1 - e2)) / (1.0 + sqrt(1 - e2));
  195. ee = e2 / (1 - e2);
  196. M = yval;
  197. u = M / (a*(1 - e2 / 4 - 3 * e2*e2 / 64 - 5 * e2*e2*e2 / 256));
  198. fai = u + (3 * e1 / 2 - 27 * e1*e1*e1 / 32)*sin(2 * u) + (21 * e1*e1 / 16 - 55 * e1*e1*e1*e1 / 32)*sin(
  199. 4 * u)
  200. + (151 * e1*e1*e1 / 96)*sin(6 * u) + (1097 * e1*e1*e1*e1 / 512)*sin(8 * u);
  201. C = ee * cos(fai)*cos(fai);
  202. T = tan(fai)*tan(fai);
  203. NN = a / sqrt(1.0 - e2 * sin(fai)*sin(fai));
  204. R = a * (1 - e2) / sqrt((1 - e2 * sin(fai)*sin(fai))*(1 - e2 * sin(fai)*sin(fai))*(1 - e2 * sin
  205. (fai)*sin(fai)));
  206. D = xval / NN;
  207. //计算经度(Longitude) 纬度(Latitude)
  208. 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
  209. *D*D*D*D / 120) / cos(fai);
  210. latitude1 = fai - (NN*tan(fai) / R)*(D*D / 2 - (5 + 3 * T + 10 * C - 4 * C*C - 9 * ee)*D*D*D*D / 24
  211. + (61 + 90 * T + 298 * C + 45 * T*T - 256 * ee - 3 * C*C)*D*D*D*D*D*D / 720);
  212. //转换为度 DD
  213. *longitude = longitude1 / iPI;
  214. *latitude = latitude1 / iPI;
  215. }
  216. void Coordinate_Transfer(double x_path, double y_path,double aimx,double aimy,double aimheading,double& X, double& Y)
  217. {
  218. double x_vehicle, y_vehicle;
  219. double x_t= x_path- aimx;
  220. double y_t= y_path- aimy;
  221. x_vehicle = x_t * cos(aimheading * M_PI / 180) - y_t * sin(aimheading * M_PI / 180);
  222. y_vehicle = x_t * sin(aimheading * M_PI / 180) + y_t * cos(aimheading * M_PI / 180);
  223. X=x_vehicle;
  224. Y=y_vehicle;
  225. }
  226. private slots:
  227. void heartBeat();
  228. void V2VOUT();
  229. void on_button_platform_en_clicked();
  230. void on_button_obu_en_clicked();
  231. void on_button_v2xrunmod_en_clicked();
  232. void on_button_pc5runmod_en_clicked();
  233. void on_button_car_vin_set_clicked();
  234. void on_button_obu_vin_set_clicked();
  235. void on_button_trafficInfo_en_clicked();
  236. void on_button_FCW_en_clicked();
  237. void on_button_DriCrims_en_clicked();
  238. void on_button_v2v_en_clicked();
  239. void on_button_v2vshow_en_clicked();
  240. void on_button_v2vshowmore_en_clicked();
  241. void on_button_SimCar_en_clicked();
  242. void on_show_debug_clicked();
  243. void on_ea_collect_clicked();
  244. void on_ns_collect_clicked();
  245. void on_ea_cf_clicked();
  246. void on_ns_cf_clicked();
  247. void on_button_pc5send_clicked();
  248. void on_button_pc5show_clicked();
  249. };
  250. #endif // MAINWINDOW_H