Browse Source

change RemoteCtrl_h264.

yuchuli 2 years ago
parent
commit
c4975edb10

BIN
doc/工具/远程驾驶方案总结.pptx


+ 2 - 1
src/tool/RemoteCtrl_h264/grpcpc.cpp

@@ -185,7 +185,7 @@ int grpcpc::AddQueryMsg(iv::cloud::cloudmsg & xcloudmsg)
         mvectorquerymsg.erase(mvectorquerymsg.begin());
     }
     mvectorquerymsg.push_back(xcloudmsg);
-    mmutexctrlmsg.unlock();
+    mmutexquerymsg.unlock();
     mcvquery.notify_all();
     return 0;
 }
@@ -241,6 +241,7 @@ void grpcpc::run()
         int nkeeptime = 0;
 
             iv::cloud::cloudmsg xmsg;
+            xmsg.clear_xclouddata();
             GetCtrlMsg(xmsg);
             xmsg.set_xtime(QDateTime::currentMSecsSinceEpoch());
             nlastsend = xTime.elapsed();

+ 167 - 52
src/tool/RemoteCtrl_h264/mainwindow.cpp

@@ -190,7 +190,7 @@ MainWindow::MainWindow(QWidget *parent)
 
     mpTimerRemote = new QTimer(this);
     connect(mpTimerRemote,SIGNAL(timeout()),this,SLOT(onTimerRemote()));
-    mpTimerRemote->start(10);
+    mpTimerRemote->start(50);
 
     mpTimerUpdateView = new QTimer(this);
     connect(mpTimerUpdateView,SIGNAL(timeout()),this,SLOT(onTimerUpdateView()));
@@ -198,7 +198,7 @@ MainWindow::MainWindow(QWidget *parent)
 
     QTimer * timer = new QTimer(this);
     connect(timer,SIGNAL(timeout()),this,SLOT(onTimerUpdatePic()));
-    timer->start(10);
+    timer->start(1000);
 
     mpadst = iv::modulecomm::RegisterSend("xodrreq",1000,1);
 
@@ -221,6 +221,7 @@ MainWindow::MainWindow(QWidget *parent)
         mpthreadpic[i] = new std::thread(&MainWindow::threadpic,this,i);
 
     }
+    mpthreadinfo = new std::thread(&MainWindow::threadinfo,this);
 
     mstrVIN = mgrpcpc->GetVIN().data();
     mstrVIN = " VIN:"+ mstrVIN+" ";
@@ -232,7 +233,7 @@ MainWindow::MainWindow(QWidget *parent)
 
     for(i=0;i<4;i++)
     {
-        mpPicSave[i]->start();
+//        mpPicSave[i]->start();
     }
 
     mppicdlg = new DialogPic(this);
@@ -274,6 +275,7 @@ MainWindow::~MainWindow()
 //    delete mpbaiduapp;
     mbThreadrun = false;
     int i;
+    mpthreadinfo->join();
     for(i=0;i<NUM_CAM;i++)
     {
 //        mph264decode[i] = new ivh264framedecode(mnframewidth,mnframeheight);
@@ -457,33 +459,41 @@ void MainWindow::resizeEvent(QResizeEvent *event)
 
     ui->groupBox_gps->setGeometry(groupgps_x,groupgps_y,groupgps_width,groupgps_height);
 
-    int lablewidth = (groupgps_width-50)*2/10;
-    int lewidth = (groupgps_width-50)*3/10;
+    int lablewidth =groupgps_width*3/10;// (groupgps_width-50)*2/10;
+    int lewidth = groupgps_width*6/10;
     int leheight = 26;
 
     int nypos = 40;
     ui->label_gpsins->setGeometry(10,nypos,lablewidth,leheight);
     ui->lineEdit_gpsins->setGeometry(20+lablewidth,nypos,lewidth,leheight);
-    ui->label_gpsrtk->setGeometry(30+lablewidth+lewidth,nypos,lablewidth,leheight);
-    ui->lineEdit_gpsrtk->setGeometry(40+2*lablewidth +lewidth,nypos,lewidth,leheight);
+
+    nypos = nypos + leheight*11/10;
+    ui->label_gpsrtk->setGeometry(10,nypos,lablewidth,leheight);
+    ui->lineEdit_gpsrtk->setGeometry(20+lablewidth,nypos,lewidth,leheight);
 
     nypos = nypos + leheight*11/10;
     ui->label_gpslon->setGeometry(10,nypos,lablewidth,leheight);
     ui->lineEdit_gpslon->setGeometry(20+lablewidth,nypos,lewidth,leheight);
-    ui->label_gpslat->setGeometry(30+lablewidth+lewidth,nypos,lablewidth,leheight);
-    ui->lineEdit_gpslat->setGeometry(40+2*lablewidth +lewidth,nypos,lewidth,leheight);
+
+    nypos = nypos + leheight*11/10;
+    ui->label_gpslat->setGeometry(10,nypos,lablewidth,leheight);
+    ui->lineEdit_gpslat->setGeometry(20+lablewidth,nypos,lewidth,leheight);
 
     nypos = nypos + leheight*11/10;
     ui->label_gpsheading->setGeometry(10,nypos,lablewidth,leheight);
     ui->lineEdit_gpsheading->setGeometry(20+lablewidth,nypos,lewidth,leheight);
-    ui->label_gpsheight->setGeometry(30+lablewidth+lewidth,nypos,lablewidth,leheight);
-    ui->lineEdit_gpsheight->setGeometry(40+2*lablewidth +lewidth,nypos,lewidth,leheight);
+
+    nypos = nypos + leheight*11/10;
+    ui->label_gpsheight->setGeometry(10,nypos,lablewidth,leheight);
+    ui->lineEdit_gpsheight->setGeometry(20+lablewidth,nypos,lewidth,leheight);
 
     nypos = nypos + leheight*11/10;
     ui->label_gpsspeed->setGeometry(10,nypos,lablewidth,leheight);
     ui->lineEdit_gpsspeed->setGeometry(20+lablewidth,nypos,lewidth,leheight);
-    ui->label_gpssat->setGeometry(30+lablewidth+lewidth,nypos,lablewidth,leheight);
-    ui->lineEdit_gpssat->setGeometry(40+2*lablewidth +lewidth,nypos,lewidth,leheight);
+
+    nypos = nypos + leheight*11/10;
+    ui->label_gpssat->setGeometry(10,nypos,lablewidth,leheight);
+    ui->lineEdit_gpssat->setGeometry(20+lablewidth,nypos,lewidth,leheight);
 
 
     double fscale = (sizemain.width()*2/3)*1.0/mnframewidth;
@@ -532,13 +542,16 @@ void MainWindow::on_radioButton_manual_clicked()
 void MainWindow::onTimerManual()
 {
 
-
+    static qint64 nLastKeepKeyTime = 0;
+    const qint64 nKeepTime = 3000; //if press c key, 5 seconds. in keep mode.
     double fOldWheel = mfWheel;
     double fOldAcc = mfAcc;
     double fOldBrake = mfBrake;
     int timediff = mManualTime.elapsed() - mnLastTime;
     mnLastTime = mManualTime.elapsed();
 
+    bool bInKeepMode = false;
+
     int nOldShift = mnShift;
 
     if(mpJRT->isOK())
@@ -577,6 +590,16 @@ void MainWindow::onTimerManual()
         return;
     }
 
+    if(mPressKeys.contains(Qt::Key_C)||(mPressKeys.contains(Qt::Key_A))||(mPressKeys.contains(Qt::Key_D))||(mPressKeys.contains(Qt::Key_W))||(mPressKeys.contains(Qt::Key_S)))
+    {
+        nLastKeepKeyTime = QDateTime::currentMSecsSinceEpoch();
+    }
+
+    if(abs(QDateTime::currentMSecsSinceEpoch() - nLastKeepKeyTime)  < nKeepTime)
+    {
+        bInKeepMode = true;
+    }
+
 
     if(mPressKeys.contains(Qt::Key_A)&&(mPressKeys.contains((Qt::Key_D))))
     {
@@ -586,30 +609,35 @@ void MainWindow::onTimerManual()
     {
         if(mPressKeys.contains(Qt::Key_A))
         {
-            if(mfWheel<0)mfWheel = 0;
-            else
-            {
+//            if(mfWheel<0)mfWheel = 0;
+//            else
+//            {
                 mfWheel = mfWheel + timediff*mfWheelSpeed/1000;
                 if(mfWheel < -100)mfWheel = -100;
                 if(mfWheel > 100 )mfWheel = 100;
-            }
+//            }
         }
 
         if(mPressKeys.contains(Qt::Key_D))
         {
-            if(mfWheel>0)mfWheel = 0;
-            else
-            {
+//            if(mfWheel>0)mfWheel = 0;
+//            else
+//            {
                 mfWheel = mfWheel - timediff*mfWheelSpeed/1000;
                 if(mfWheel < -100)mfWheel = -100;
                 if(mfWheel > 100 )mfWheel = 100;
-            }
+//            }
         }
 
 
     }
 
-    if(!mPressKeys.contains(Qt::Key_A)&&(!mPressKeys.contains((Qt::Key_D))))
+    if(mPressKeys.contains(Qt::Key_Z))
+    {
+        mfWheel = 0;
+    }
+
+    if(!mPressKeys.contains(Qt::Key_A)&&(!mPressKeys.contains((Qt::Key_D)))&&(bInKeepMode == false))
     {
         if(mfWheel != 0)
         {
@@ -619,43 +647,91 @@ void MainWindow::onTimerManual()
         }
     }
 
-    if(mPressKeys.contains(Qt::Key_W)&&(mPressKeys.contains((Qt::Key_S))))
+    if(mnVehMode == 2)   //ACC BRAKE
     {
-        mfAcc = 0;
-        mfBrake = mfBrake + timediff*mfBrakeSpeed/1000;
-        if(mfBrake<0)mfBrake = 0;
-        if(mfBrake > 100)mfBrake = 100;
-    }
-    else
-    {
-        if(mPressKeys.contains(Qt::Key_W))
-        {
-            mfBrake = 0;
-            mfAcc = mfAcc + timediff*mfAccSpeed/1000;
-            if(mfAcc<0)mfAcc = 0;
-            if(mfAcc > 100)mfAcc = 100;
-
-        }
-
-        if(mPressKeys.contains(Qt::Key_S))
+        if(mPressKeys.contains(Qt::Key_W)&&(mPressKeys.contains((Qt::Key_S))))
         {
             mfAcc = 0;
             mfBrake = mfBrake + timediff*mfBrakeSpeed/1000;
             if(mfBrake<0)mfBrake = 0;
             if(mfBrake > 100)mfBrake = 100;
         }
+        else
+        {
+            if(mPressKeys.contains(Qt::Key_W))
+            {
+                mfBrake = 0;
+                mfAcc = mfAcc + timediff*mfAccSpeed/1000;
+                if(mfAcc<0)mfAcc = 0;
+                if(mfAcc > 100)mfAcc = 100;
+
+            }
 
+            if(mPressKeys.contains(Qt::Key_S))
+            {
+                mfAcc = 0;
+                mfBrake = mfBrake + timediff*mfBrakeSpeed/1000;
+                if(mfBrake<0)mfBrake = 0;
+                if(mfBrake > 100)mfBrake = 100;
+            }
 
+
+        }
     }
+    else   //Speed Mode
+    {
+        if(mPressKeys.contains(Qt::Key_W)&&(mPressKeys.contains((Qt::Key_S))))
+        {
+            if(mfAcc > 0)
+            {
+                mfAcc = mfAcc - 10*timediff*mfAccSpeed/1000;
+                if(mfAcc<0)mfAcc = 0;
+            }
+            else
+            {
+                mfBrake = mfBrake + timediff*mfBrakeSpeed/1000;
+                if(mfBrake<0)mfBrake = 0;
+                if(mfBrake > 100)mfBrake = 100;
+            }
+        }
+        else
+        {
+            if(mPressKeys.contains(Qt::Key_W))
+            {
+                mfBrake = 0;
+                mfAcc = mfAcc + timediff*mfAccSpeed/1000;
+                if(mfAcc<0)mfAcc = 0;
+                if(mfAcc > 100)mfAcc = 100;
+
+            }
+
+            if(mPressKeys.contains(Qt::Key_S))
+            {
+                if(mfAcc > 0)
+                {
+                    mfAcc = mfAcc - 10*timediff*mfAccSpeed/1000;
+                    if(mfAcc<0)mfAcc = 0;
+                }
+                else
+                {
+                    mfBrake = mfBrake + timediff*mfBrakeSpeed/1000;
+                    if(mfBrake<0)mfBrake = 0;
+                    if(mfBrake > 100)mfBrake = 100;
+                }
+            }
+
 
+        }
+    }
 
-    if(!mPressKeys.contains(Qt::Key_W)&&(!mPressKeys.contains((Qt::Key_S))))
+
+    if(!mPressKeys.contains(Qt::Key_W)&&(!mPressKeys.contains((Qt::Key_S)))&&(bInKeepMode == false))
     {
         if(mfBrake != 0)
         {
-            mfBrake = mfBrake - timediff*mfBrakeAutoDownSpeed/1000;
-            if(mfBrake<0)mfBrake = 0;
-            if(mfBrake > 100)mfBrake = 100;
+//            mfBrake = mfBrake - timediff*mfBrakeAutoDownSpeed/1000;
+//            if(mfBrake<0)mfBrake = 0;
+//            if(mfBrake > 100)mfBrake = 100;
         }
 
         if(mfAcc != 0)
@@ -703,11 +779,13 @@ void MainWindow::onTimerRemote()
     mremotectrl.set_wheel(mfWheel);
     mremotectrl.set_shift(mnShift);
 
+
     int nsersize = mremotectrl.ByteSize();
     char * strbuf = new char[nsersize];
     if(mremotectrl.SerializeToArray(strbuf,nsersize))
     {
-        iv::modulecomm::ModuleSendMsg(mpa,strbuf,nsersize);
+        mgrpcpc->SetCtrlMsg("remotectrl",strbuf,nsersize);
+//        iv::modulecomm::ModuleSendMsg(mpa,strbuf,nsersize);
     }
     delete strbuf;
 }
@@ -836,21 +914,26 @@ void MainWindow::onTimerUpdateView()
 void MainWindow::paintEvent(QPaintEvent *)
 {
     int i;
+//    QTime xTime;
     for(i=0;i<NUM_CAM;i++)
     {
         if(mbCamUpdate[i])
         {
+ //           xTime.start();
             std::cout<<" copy image. "<<std::endl;
             mMutexCam[i].lock();
-            QImage image = mpImageCam[i]->copy();
+//            QImage image = mpImageCam[i]->copy();
             mbCamUpdate[i] = false;
 
-            mMutexCam[i].unlock();
+
             //       QImage image = mpPicView->GetImage();
             mpsceneImg[i]->clear();
-            mpsceneImg[i]->addPixmap(QPixmap::fromImage(image));
+ //           mpsceneImg[i]->addPixmap(QPixmap::fromImage(image));
+            mpsceneImg[i]->addPixmap(QPixmap::fromImage(*mpImageCam[i]));
             mpviewImg[i]->setScene(mpsceneImg[i]);
             mpviewImg[i]->show();
+            mMutexCam[i].unlock();
+//            std::cout<<" update a image use. "<<xTime.elapsed()<<std::endl;
         }
     }
 //    if(mbCamUpdate[0])
@@ -901,7 +984,9 @@ void MainWindow::on_pushButton_Go_clicked()
     xo.flat = lat;
     xo.lane = 3;
 
-    iv::modulecomm::ModuleSendMsg(mpadst,(char *)&xo,sizeof(xodrobj));
+
+    mgrpcpc->SetCtrlMsg("xodrreq",(char *)&xo,sizeof(xodrobj));
+//    iv::modulecomm::ModuleSendMsg(mpadst,(char *)&xo,sizeof(xodrobj));
 }
 
 void MainWindow::on_comboBox_Station_currentIndexChanged(int index)
@@ -942,7 +1027,7 @@ void MainWindow::on_radioButton_Drive_clicked()
 {
     mnShift = 1;
     ui->radioButton_picfront->setChecked(true);
-    on_radioButton_picfront_clicked();
+//    on_radioButton_picfront_clicked();
     mpbigpicdlg->SetFront();
 }
 
@@ -956,7 +1041,7 @@ void MainWindow::on_radioButton_Rear_clicked()
 {
     mnShift = -1;
     ui->radioButton_picrear->setChecked(true);
-    on_radioButton_picrear_clicked();
+//    on_radioButton_picrear_clicked();
     mpbigpicdlg->SetRear();
 }
 
@@ -1078,6 +1163,36 @@ void MainWindow::on_actionSet_Ctrl_Pass_triggered()
 
 }
 
+void MainWindow::threadinfo()
+{
+    int nrtn;
+    iv::cloud::cloudmsg xcloudmsg;
+    while(mbThreadrun)
+    {
+        nrtn = mgrpcpc->GetQueryMsg(xcloudmsg,1000);
+        if(nrtn == 1)
+        {
+            int i;
+            for(i=0;i<xcloudmsg.xclouddata_size();i++)
+            {
+                iv::cloud::cloudunit * punit = xcloudmsg.mutable_xclouddata(i);
+                if(punit->msgname() == "hcp2_gpsimu")
+                {
+                    iv::gps::gpsimu xgpsimu;
+                    if(!xgpsimu.ParseFromArray(punit->data().data(),punit->data().size()))
+                    {
+                        std::cout<<"ListenRaw Parse error."<<std::endl;
+                        continue;
+                    }
+                    ggpsimu.CopyFrom(xgpsimu);
+                    gTimeGPSIMUUpdate = QDateTime::currentMSecsSinceEpoch();
+                }
+            }
+            std::cout<<" receive info msg. "<<std::endl;
+        }
+    }
+}
+
 void MainWindow::threadframe(int ncamppos)
 {
     iv::h264rawframedata xframe;

+ 4 - 0
src/tool/RemoteCtrl_h264/mainwindow.h

@@ -226,6 +226,7 @@ private:
 private:
     void threadframe(int ncamppos);
     void threadpic(int ncampos);
+    void threadinfo();
 
 private:
     ivh264framedecode * mph264decode[NUM_CAM];
@@ -235,9 +236,12 @@ private:
 
     std::thread * mpthreadframe[NUM_CAM];
     std::thread * mpthreadpic[NUM_CAM];
+    std::thread * mpthreadinfo;
 
     QImage * mpImageCam[NUM_CAM];
     bool mbCamUpdate[NUM_CAM];
     QMutex mMutexCam[NUM_CAM];
+
+    int mnVehMode = 1; //1 Speed Mode  2 AccBrakeMode
 };
 #endif // MAINWINDOW_H

+ 8 - 8
src/tool/RemoteCtrl_h264/mainwindow.ui

@@ -145,8 +145,8 @@
    <widget class="QGroupBox" name="groupBox_map">
     <property name="geometry">
      <rect>
-      <x>280</x>
-      <y>320</y>
+      <x>420</x>
+      <y>190</y>
       <width>351</width>
       <height>121</height>
      </rect>
@@ -181,10 +181,10 @@
    <widget class="QGroupBox" name="groupBox_gps">
     <property name="geometry">
      <rect>
-      <x>280</x>
-      <y>470</y>
-      <width>361</width>
-      <height>151</height>
+      <x>200</x>
+      <y>320</y>
+      <width>411</width>
+      <height>351</height>
      </rect>
     </property>
     <property name="title">
@@ -378,8 +378,8 @@
    <widget class="QGroupBox" name="groupBox_picsel">
     <property name="geometry">
      <rect>
-      <x>280</x>
-      <y>210</y>
+      <x>360</x>
+      <y>40</y>
       <width>551</width>
       <height>91</height>
      </rect>