| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268 |
- #ifndef MAINWINDOW_H
- #define MAINWINDOW_H
- #include "v2x.h"
- #include "pc5.h"
- #include <QMainWindow>
- #include <QDialog>
- #include <QInputDialog>
- #include <iostream>
- #include "QDebug"
- #include <QTextCodec>
- #include "xmlparam.h"
- #include <string>
- #include "v2r.pb.h"
- #include "gpsimu.pb.h"
- #include "rawpic.pb.h"
- #include "fusionobjectarray.pb.h"
- #include "fusionobject.pb.h"
- #include "radarobject.pb.h"
- #include "lightarray.pb.h"
- #include "ivlog.h"
- #include "modulecomm.h"
- #include <QtXml>
- #include <QDomComment>
- #include <QFile>
- #include <cmath>
- #include <string>
- #include <iostream>
- namespace Ui {
- class MainWindow;
- }
- struct onelightMessage
- {
- bool isEnable=false;
- unsigned char lightType;//0x01:绿灯;0x02:红灯;0x03:黄灯;
- int timeRemaining;
- };
- class MainWindow : public QMainWindow
- {
- Q_OBJECT
- public:
- explicit MainWindow(QWidget *parent = 0);
- ~MainWindow();
- PC5 *m_pc5;
- V2X *m_tbox;
- void initUI();//程序初始化
- void initproto();//共享内存初始化
- void initLight1();//红绿灯1初始化
- void initLight2();//红绿灯2初始化
- void initLight3();//红绿灯3初始化
- void initLight4();//红绿灯4初始化
- void initFace();//红绿灯4初始化
- //void *gfu = iv::modulecomm::RegisterSend("li_ra_fusion",10000000,1);
- void *gfu = iv::modulecomm::RegisterSend("v2v_send",10000000,1);
- void sendProto(iv::v2r::v2r_send radio_protobuf_send);//发送共享内存数据
- void UpdateGps(const char *strdata, const unsigned int nSize, const unsigned int index, const QDateTime *dt, const char *strmemname);//读取共享内存
- void UpdateCAM(const char *strdata, const unsigned int nSize, const unsigned int index, const QDateTime *dt, const char *strmemname);//读取共享内存
- void UpdateLIDAR(const char *strdata, const unsigned int nSize, const unsigned int index, const QDateTime *dt, const char *strmemname);//读取共享内存
- void UpdateRADAR(const char *strdata, const unsigned int nSize, const unsigned int index, const QDateTime *dt, const char *strmemname);//读取共享内存
- void Updatelight(const char *strdata, const unsigned int nSize, const unsigned int index, const QDateTime *dt, const char *strmemname);//读取红绿灯共享内存并转发
- void outLight(onelightMessage light);//设置红绿灯共享内存数据
- void outRealtimeTraffic(realtimeTrafficMessage realtimeTraffic);//设置路况信息共享内存数据
- void outCollisionWarning(collisionEarlyWarningMessage collisionWarning);//设置碰撞预警共享内存数据
- void outCongestionIdenti(congestionIdentificationMessage congestionIdenti);//设置交通拥堵共享内存数据
- void outmbpause(bool runmod);//设置自动驾驶启停共享内存数据
- void outV2VData(QMap<QString,OBUCarFormation> V2VMessage);
- void setTboxMemoryRaw();//云平台发送数据设置
- void initMemory();//云平台路测数据赋初值
- bool RSUTYPE=false;
- // void getRandomNum();
- // void initRadio();
- private:
- Ui::MainWindow *ui;
- QTimer *timer;
- QTimer *timerV2V;
- //----------共享内存变量--------------------
- std::string gstrmemgps;
- std::string gstrmemlight;
- std::string gstrmecamera;
- std::string gstrmelidar;
- std::string gstrmeradar;
- void *mpMemGPS;
- void *mpMemcamera;
- void *mpMemlidar;
- void *mpMemradar;
- void *vision_lightMem;
- int visionsendstate;
- double lightStopLat;
- double lightStopLon;
- double light1Stophead;
- double light1StopLat;
- double light1StopLon;
- double light2Stophead;
- double light2StopLat;
- double light2StopLon;
- //-----------使能变量-------------------------
- bool mplatformEn = false;//云平台使能状态
- bool mobuEn = false;//obu使能状态
- bool mv2xRunmodEn=false;
- bool mpc5RunmodEn=false;
- bool mVirtualEn=false;//虚拟车使能状态
- bool mbTrafficInfoEn = false; //路况信息使能
- bool mcusdatashowEn=false;
- bool mbFCWEn = false;//碰撞预警使能状态
- bool mbdriCrimsEn = false;//危险驾驶使能状态
- bool visionflag=true;//视觉红绿灯识别转发使能
- bool mshowdebugEn = false;
- bool v2vEn = false;
- bool v2vshow =false;
- bool v2vshowmore =false;
- int mGPSs=0;//GPS状态清零计数
- int mCAMs=0;//视觉状态清零计数
- int mLIDARs=0;//激光状态清零计数
- int mRADARs=0;//毫米波状态清零计数
- bool sendProto_flag;//共享内存发送使能
- // std::vector<int> m_vectorRandom;
- // std::vector<std::string> m_vectorVin;
- //-------------结构数据----------------------
- QImage redimg,greenimg,yellowimg,blackimg,nofaceimg,facetoimg;
- realtimeTrafficMessage TrafficMessage;
- lightMessage light;
- collisionEarlyWarningMessage collisionWarning;
- congestionIdentificationMessage congestionIdenti;
- void * mpmem_radio_send_addr = nullptr;
- gpsImuM m_structMGpsImu;
- sensor_state seneor_m;
- iv::v2r::v2r_send protobuf;
- double calculateRelativeAngle(double selfAngleRad, double targetAngleRad)
- {
- // 计算目标角度相对于自身角度的相对角度
- selfAngleRad = qDegreesToRadians(selfAngleRad);
- targetAngleRad = qDegreesToRadians(targetAngleRad);
- double relativeAngleRad = targetAngleRad - selfAngleRad;
- // 将相对角度调整为在 0 到 2π 之间
- while (relativeAngleRad < 0) {
- relativeAngleRad += 2.0 * M_PI;
- }
- // 如果相对角度超过π,则将其调整为π到2π之间
- if (relativeAngleRad > 2.0 *M_PI) {
- relativeAngleRad = relativeAngleRad-(2.0 * M_PI);
- }
- // 取反
- relativeAngleRad = 2.0 * M_PI - relativeAngleRad;
- return relativeAngleRad;
- }
- void GaussProjCal(double longitude, double latitude, double& X, double& Y)
- {
- int ProjNo = 0; int ZoneWide; ////带宽
- double longitude1, latitude1, longitude0, latitude0, X0, Y0, xval, yval;
- double a, f, e2, ee, NN, T, C, A, M, iPI;
- iPI = 0.0174532925199433; ////3.1415926535898/180.0;
- ZoneWide = 6; ////6度带宽
- a = 6378245.0; f = 1.0 / 298.3; //54年北京坐标系参数
- ////a=6378140.0; f=1/298.257; //80年西安坐标系参数
- ProjNo = (int)(longitude / ZoneWide);
- longitude0 = ProjNo * ZoneWide + ZoneWide / 2;
- longitude0 = longitude0 * iPI;
- latitude0 = 0;
- longitude1 = longitude * iPI; //经度转换为弧度
- latitude1 = latitude * iPI; //纬度转换为弧度
- e2 = 2 * f - f * f;
- ee = e2 * (1.0 - e2);
- NN = a / sqrt(1.0 - e2 * sin(latitude1)*sin(latitude1));
- T = tan(latitude1)*tan(latitude1);
- C = ee * cos(latitude1)*cos(latitude1);
- A = (longitude1 - longitude0)*cos(latitude1);
- 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
- *e2 / 1024)*sin(2 * latitude1)
- + (15 * e2*e2 / 256 + 45 * e2*e2*e2 / 1024)*sin(4 * latitude1) - (35 * e2*e2*e2 / 3072)*sin(6 * latitude1));
- 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);
- yval = M + NN * tan(latitude1)*(A*A / 2 + (5 - T + 9 * C + 4 * C*C)*A*A*A*A / 24
- + (61 - 58 * T + T * T + 600 * C - 330 * ee)*A*A*A*A*A*A / 720);
- X0 = 1000000L * (ProjNo + 1) + 500000L;
- Y0 = 0;
- xval = xval + X0; yval = yval + Y0;
- X = xval;
- Y = yval;
- }
- void GaussProjInvCal(double X, double Y, double *longitude, double *latitude)
- {
- int ProjNo; int ZoneWide; ////带宽
- double longitude1, latitude1, longitude0, latitude0, X0, Y0, xval, yval;
- double e1, e2, f, a, ee, NN, T, C, M, D, R, u, fai, iPI;
- iPI = 0.0174532925199433; ////3.1415926535898/180.0;
- a = 6378245.0; f = 1.0 / 298.3; //54年北京坐标系参数
- ////a=6378140.0; f=1/298.257; //80年西安坐标系参数
- ZoneWide = 6; ////6度带宽
- ProjNo = (int)(X / 1000000L); //查找带号
- longitude0 = (ProjNo - 1) * ZoneWide + ZoneWide / 2;
- longitude0 = longitude0 * iPI; //中央经线
- X0 = ProjNo * 1000000L + 500000L;
- Y0 = 0;
- xval = X - X0; yval = Y - Y0; //带内大地坐标
- e2 = 2 * f - f * f;
- e1 = (1.0 - sqrt(1 - e2)) / (1.0 + sqrt(1 - e2));
- ee = e2 / (1 - e2);
- M = yval;
- u = M / (a*(1 - e2 / 4 - 3 * e2*e2 / 64 - 5 * e2*e2*e2 / 256));
- fai = u + (3 * e1 / 2 - 27 * e1*e1*e1 / 32)*sin(2 * u) + (21 * e1*e1 / 16 - 55 * e1*e1*e1*e1 / 32)*sin(
- 4 * u)
- + (151 * e1*e1*e1 / 96)*sin(6 * u) + (1097 * e1*e1*e1*e1 / 512)*sin(8 * u);
- C = ee * cos(fai)*cos(fai);
- T = tan(fai)*tan(fai);
- NN = a / sqrt(1.0 - e2 * sin(fai)*sin(fai));
- R = a * (1 - e2) / sqrt((1 - e2 * sin(fai)*sin(fai))*(1 - e2 * sin(fai)*sin(fai))*(1 - e2 * sin
- (fai)*sin(fai)));
- D = xval / NN;
- //计算经度(Longitude) 纬度(Latitude)
- 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
- *D*D*D*D / 120) / cos(fai);
- latitude1 = fai - (NN*tan(fai) / R)*(D*D / 2 - (5 + 3 * T + 10 * C - 4 * C*C - 9 * ee)*D*D*D*D / 24
- + (61 + 90 * T + 298 * C + 45 * T*T - 256 * ee - 3 * C*C)*D*D*D*D*D*D / 720);
- //转换为度 DD
- *longitude = longitude1 / iPI;
- *latitude = latitude1 / iPI;
- }
- void Coordinate_Transfer(double x_path, double y_path,double aimx,double aimy,double aimheading,double& X, double& Y)
- {
- double x_vehicle, y_vehicle;
- double x_t= x_path- aimx;
- double y_t= y_path- aimy;
- x_vehicle = x_t * cos(aimheading * M_PI / 180) - y_t * sin(aimheading * M_PI / 180);
- y_vehicle = x_t * sin(aimheading * M_PI / 180) + y_t * cos(aimheading * M_PI / 180);
- X=x_vehicle;
- Y=y_vehicle;
- }
- private slots:
- void heartBeat();
- void V2VOUT();
- void on_button_platform_en_clicked();
- void on_button_obu_en_clicked();
- void on_button_v2xrunmod_en_clicked();
- void on_button_pc5runmod_en_clicked();
- void on_button_car_vin_set_clicked();
- void on_button_obu_vin_set_clicked();
- void on_button_trafficInfo_en_clicked();
- void on_button_FCW_en_clicked();
- void on_button_DriCrims_en_clicked();
- void on_button_v2v_en_clicked();
- void on_button_v2vshow_en_clicked();
- void on_button_v2vshowmore_en_clicked();
- void on_button_SimCar_en_clicked();
- void on_show_debug_clicked();
- void on_ea_collect_clicked();
- void on_ns_collect_clicked();
- void on_ea_cf_clicked();
- void on_ns_cf_clicked();
- void on_button_pc5send_clicked();
- void on_button_pc5show_clicked();
- };
- #endif // MAINWINDOW_H
|