Browse Source

fix(grpc_client_BS):fix remote control rate too slow to get many zero result

孙嘉城 3 years ago
parent
commit
753ad7e854

+ 5 - 7
src/driver/driver_cloud_grpc_client_BS/main.cpp

@@ -43,8 +43,8 @@ mainloop::mainloop(VehicleControlClient *pCC,DataExchangeClient *pUC)
 void mainloop::run()
 {
     while (1) {
-        msleep(100);
-//        if(pControlClient->get_isNeedMap() == true)
+//        msleep(100);
+        if(pControlClient->get_isNeedMap() == true)
         {
             std::cout<<"patrol path calculating"<<std::endl;
             QFile mapfile("/home/samuel/Documents/path1.txt");
@@ -64,12 +64,10 @@ void mainloop::run()
                     somePoints.append(onePoint);
                 }
             }
-//            pUploadClient->updatePath(pControlClient->get_patrolPathID(),somePoints);
-            pUploadClient->updatePath("testpath1",somePoints);
+            pUploadClient->updatePath(pControlClient->get_patrolPathID(),somePoints);
             pUploadClient->uploadPath();
             pControlClient->set_isNeedMap(false);
         }
-//        std::cout<<"thread running"<<std::endl;
     }
 }
 
@@ -157,10 +155,10 @@ int main(int argc, char *argv[])
     std::string upload_str = gstrserverip+":";
     upload_str = upload_str + gstruploadPort ;
 
-    VehicleControlClient *vehiclecontrol = new VehicleControlClient(grpc::CreateChannel(control_str, grpc::InsecureChannelCredentials()));
-
     DataExchangeClient *vehicleupload = new DataExchangeClient(grpc::CreateChannel(upload_str, grpc::InsecureChannelCredentials()));
 
+    VehicleControlClient *vehiclecontrol = new VehicleControlClient(grpc::CreateChannel(control_str, grpc::InsecureChannelCredentials()));
+
     VehiclePatrolExceptionClient vehiclepatrol(grpc::CreateChannel(patrol_str, grpc::InsecureChannelCredentials()));
 
     mainloop loop(vehiclecontrol,vehicleupload);

+ 24 - 15
src/driver/driver_cloud_grpc_client_BS/vehicle_control.cpp

@@ -19,11 +19,11 @@ VehicleControlClient::VehicleControlClient(std::shared_ptr<Channel> channel)
     stub_ = VehicleControl::NewStub(channel);
 
     controlTimer = new QTimer();
-    connect(controlTimer,SIGNAL(timeout()),this,SLOT(controlTimeout()));
-//    controlTimer->start(std::atoi(gstrcontrolInterval.c_str()));
+    connect(controlTimer,&QTimer::timeout,this,&VehicleControlClient::controlTimeout);
+    controlTimer->start(std::atoi(gstrcontrolInterval.c_str()));
 
     uploadMapTimer = new QTimer();
-    connect(uploadMapTimer,SIGNAL(timeout()),this,SLOT(uploadMapTimeout()));
+    connect(uploadMapTimer,&QTimer::timeout,this,&VehicleControlClient::uploadMapTimeout);
     uploadMapTimer->start(std::atoi(gstruploadMapInterval.c_str()));
 }
 
@@ -56,8 +56,17 @@ std::string VehicleControlClient::vehicleControl(void)
             shiftCMD = reply.shiftcmd();
             steeringWheelAngleCMD = reply.steeringwheelanglecmd();
             throttleCMD = reply.throttlecmd();
+            std::cout<<"throttle:"<<reply.throttlecmd()<<std::endl;
             brakeCMD = reply.brakecmd();
         }
+        else
+        {
+//            std::cout<<"id:"<<reply.id()<<std::endl;
+//            if(throttleCMD > 0)throttleCMD -= 1.5;
+//            if(throttleCMD <= 0)throttleCMD = 0;
+//            if(brakeCMD > 0)brakeCMD -= 1.5;
+//            if(brakeCMD <= 0)brakeCMD = 0;
+        }
         return "vehicleControl RPC successed";
     } else {
         std::cout << status.error_code() << ": " << status.error_message()
@@ -86,19 +95,19 @@ std::string VehicleControlClient::uploadMap(void)
     if (status.ok()) {
         if(reply.id() == gstrid)
         {
-            std::cout<<reply.id()<<std::endl;
+//            std::cout<<reply.id()<<std::endl;
             isNeedMap = false;
             patrolPathID = "noPath";
             POIPoints.clear();
 
             isNeedMap = reply.isneedmap();
-            std::cout<<reply.isneedmap()<<std::endl;
+//            std::cout<<reply.isneedmap()<<std::endl;
             patrolPathID = reply.patrolpathid();
-            std::cout<<reply.patrolpathid()<<std::endl;
+//            std::cout<<reply.patrolpathid()<<std::endl;
             for(int i = 0;i < reply.mappoints_size();i++)
             {
                 POIPoints.append(reply.mappoints(i));
-                std::cout<<reply.mappoints(i).index()<<std::endl;
+//                std::cout<<reply.mappoints(i).index()<<std::endl;
             }
         }
         return "UploadMap RPC successed";
@@ -141,10 +150,10 @@ std::string VehicleControlClient::changeCtrlMode(void)
 
 void VehicleControlClient::updateControlData(void)
 {
-    std::cout<<"shift:"<<shiftCMD<<std::endl;
-    std::cout<<"steeringWheelAngle:"<<steeringWheelAngleCMD<<std::endl;
+//    std::cout<<"shift:"<<shiftCMD<<std::endl;
+//    std::cout<<"steeringWheelAngle:"<<steeringWheelAngleCMD<<std::endl;
     std::cout<<"throttle:"<<throttleCMD<<std::endl;
-    std::cout<<"brake:"<<brakeCMD<<std::endl;
+//    std::cout<<"brake:"<<brakeCMD<<std::endl;
 }
 
 void VehicleControlClient::updateMapPOIData(void)
@@ -155,18 +164,18 @@ void VehicleControlClient::updateMapPOIData(void)
 
 void VehicleControlClient::updateCtrolMode(void)
 {
-    std::cout<<"modeCMD:"<<modeCMD<<std::endl;
+//    std::cout<<"modeCMD:"<<modeCMD<<std::endl;
 }
 
 void VehicleControlClient::controlTimeout(void)
 {
     std::string reply = changeCtrlMode();
-    std::cout<< reply <<std::endl;
+//    std::cout<< reply <<std::endl;
     updateCtrolMode();
 
     reply = vehicleControl();
-    std::cout<< reply <<std::endl;
-    if(modeCMD == CtrlMode::CMD_REMOTE)
+//    std::cout<< reply <<std::endl;
+    if(modeCMD == CtrlMode::CMD_REMOTE || modeCMD == CtrlMode::CMD_CLOUD_PLATFORM)
     {
         updateControlData();
     }
@@ -177,7 +186,7 @@ void VehicleControlClient::uploadMapTimeout(void)
     if(isNeedMap == false)
     {
         std::string reply = uploadMap();
-        std::cout<< reply <<std::endl;
+//        std::cout<< reply <<std::endl;
         if(isNeedMap == true)
         {
             updateMapPOIData();

+ 4 - 4
src/driver/driver_cloud_grpc_client_BS/vehicle_control.h

@@ -45,10 +45,10 @@ public:
 private:
     std::unique_ptr<VehicleControl::Stub> stub_;
 
-    org::jeecg::defsControl::grpc::ShiftStatus shiftCMD;
-    double steeringWheelAngleCMD;
-    double throttleCMD;
-    double brakeCMD;
+    org::jeecg::defsControl::grpc::ShiftStatus shiftCMD = org::jeecg::defsControl::grpc::ShiftStatus::SHIFT_PARKING;
+    double steeringWheelAngleCMD = 0;
+    double throttleCMD = 0;
+    double brakeCMD = 0;
 
     bool isNeedMap = false;
     std::string patrolPathID;

+ 23 - 21
src/driver/driver_cloud_grpc_client_BS/vehicle_patrol.cpp

@@ -16,7 +16,7 @@ VehiclePatrolExceptionClient::VehiclePatrolExceptionClient(std::shared_ptr<Chann
     stub_ = VehiclePatrolException::NewStub(channel);
 
     patrolTimer = new QTimer();
-    connect(patrolTimer,SIGNAL(timeout()),this,SLOT(patrolTimeout()));
+    connect(patrolTimer,&QTimer::timeout,this,&VehiclePatrolExceptionClient::patrolTimeout);
 //    patrolTimer->start(std::atoi(gstrpatrolInterval.c_str()));
 }
 
@@ -34,6 +34,7 @@ std::string VehiclePatrolExceptionClient::uploadVehiclePatrolInfo(void)
     request.set_violationstatus(violationStatus);
     request.set_vehiclelicensenumber(vehicleLicenseNumber);
     request.set_violationimage(violationImage.data(),violationImage.size());
+    request.set_violationtime(violationTime);
     request.mutable_violationposition()->CopyFrom(violationPosition);
 
     request.set_isfsm(isFSM);
@@ -78,13 +79,13 @@ void VehiclePatrolExceptionClient::updatePatrolData(void)
     violationStatus = 2;
     vehicleLicenseNumber = "津B654321";
 
-//    QFile xFile;
-//    xFile.setFileName("/home/samuel/Pictures/123.jpg");
-//    if(xFile.open(QIODevice::ReadOnly))
-//    {
-//        violationImage = xFile.readAll();
-//    }
-//    xFile.close();
+    QFile xFile;
+    xFile.setFileName("/home/samuel/Pictures/123.jpg");
+    if(xFile.open(QIODevice::ReadOnly))
+    {
+        violationImage = xFile.readAll();
+    }
+    xFile.close();
 
     violationTime = QDateTime::currentMSecsSinceEpoch();
     violationPosition.set_height(0.1);
@@ -94,12 +95,12 @@ void VehiclePatrolExceptionClient::updatePatrolData(void)
     isFSM = true;
     fireStatus = 1;
 
-//    xFile.setFileName("/home/samuel/Pictures/123.jpg");
-//    if(xFile.open(QIODevice::ReadOnly))
-//    {
-//        fireImage = xFile.readAll();
-//    }
-//    xFile.close();
+    xFile.setFileName("/home/samuel/Pictures/123.jpg");
+    if(xFile.open(QIODevice::ReadOnly))
+    {
+        fireImage = xFile.readAll();
+    }
+    xFile.close();
 
     fireTime = QDateTime::currentMSecsSinceEpoch();
     firePosition.set_height(0.1);
@@ -109,12 +110,12 @@ void VehiclePatrolExceptionClient::updatePatrolData(void)
     isTSGM = true;
     gateStatus = 2;
 
-//    xFile.setFileName("/home/samuel/Pictures/123.jpg");
-//    if(xFile.open(QIODevice::ReadOnly))
-//    {
-//        gateImage = xFile.readAll();
-//    }
-//    xFile.close();
+    xFile.setFileName("/home/samuel/Pictures/123.jpg");
+    if(xFile.open(QIODevice::ReadOnly))
+    {
+        gateImage = xFile.readAll();
+    }
+    xFile.close();
 
     gateTime = QDateTime::currentMSecsSinceEpoch();
     gatePosition.set_height(0.1);
@@ -127,5 +128,6 @@ void VehiclePatrolExceptionClient::updatePatrolData(void)
 void VehiclePatrolExceptionClient::patrolTimeout(void)
 {
     updatePatrolData();
-    uploadVehiclePatrolInfo();
+    std::string reply = uploadVehiclePatrolInfo();
+    std::cout<< reply <<std::endl;
 }

+ 2 - 2
src/driver/driver_cloud_grpc_client_BS/vehicle_upload.cpp

@@ -21,7 +21,7 @@ DataExchangeClient::DataExchangeClient(std::shared_ptr<Channel> channel)
     stub_ = DataExchange::NewStub(channel);
 
     uploadTimer = new QTimer();
-    connect(uploadTimer,SIGNAL(timeout()),this,SLOT(uploadTimeout()));
+    connect(uploadTimer,&QTimer::timeout,this,&DataExchangeClient::uploadTimeout);
     uploadTimer->start(std::atoi(gstruploadInterval.c_str()));
 }
 
@@ -203,5 +203,5 @@ void DataExchangeClient::uploadTimeout(void)
 {
     updateData();
     std::string reply = uploadVehicleInfo();
-    std::cout<< reply <<std::endl;
+//    std::cout<< reply <<std::endl;
 }