ソースを参照

change controller_changan_shenlan_v2 for remote control.

yuchuli 2 ヶ月 前
コミット
c2aee8a21e

BIN
doc/远程驾驶配置手册.docx


+ 112 - 3
src/controller/controller_changan_shenlan_v2/main.cpp

@@ -17,6 +17,7 @@
 #include "chassis.pb.h"
 
 #include "torquebrake.h"
+#include "remotectrl.pb.h"
 
 #include <thread>
 
@@ -27,10 +28,12 @@
 static void * gpacansend;
 static void * gpadecition;
 static void * gpachassis;
+static void * gparemote;
 
 static std::string gstrmemdecition;
 static std::string gstrmemcansend;
 static std::string gstrmemchassis;
+std::string gstrmemremote; //Remote Ctrl
 static bool gbSendRun = true;
 
 static bool gbChassisEPS = false;
@@ -38,6 +41,14 @@ static bool gbChassisEPS = false;
 static iv::brain::decition gdecition_def;
 static iv::brain::decition gdecition;
 
+bool gbAllowRemote = false;   //Default, Not Allow Remote
+
+qint64 gLastRemoteTime = 0;
+
+bool gbAutoDriving = true; //if true, Auto Driving, false, remote controll
+
+iv::brain::decition gdecition_remote;
+
 static QTime gTime;
 static int gnLastSendTime = 0;
 static int gnLastRecvDecTime = -1000;
@@ -553,6 +564,51 @@ void ListenDeciton(const char * strdata,const unsigned int nSize,const unsigned
 
 }
 
+void ListenRemotectrl(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
+{
+    (void)index; (void)dt; (void)strmemname;
+    iv::brain::decition xdecition;
+
+    iv::remotectrl xrc;
+
+    if(!xrc.ParseFromArray(strdata,nSize))
+    {
+        std::cout<<"ListenRemotectrl parse error."<<std::endl;
+        return;
+    }
+
+    if(xrc.ntype() == iv::remotectrl_CtrlType_AUTO)
+    {
+        gbAutoDriving = true;
+    }
+    else
+    {
+        gbAutoDriving = false;
+        xdecition.set_accelerator(xrc.acc());
+        xdecition.set_brake(xrc.brake());
+        xdecition.set_wheelangle(xrc.wheel());
+
+        if(xrc.acc()>0.0)xdecition.set_torque(xrc.acc() * 100);
+
+        xdecition.set_angle_mode(1);
+        xdecition.set_angle_active(1);
+        xdecition.set_acc_active(1);
+        xdecition.set_brake_active(1);
+    //    xdecition.set_brake_type(1);
+        xdecition.set_auto_mode(3);
+
+        gMutex.lock();
+        gdecition_remote.CopyFrom(xdecition);
+        gMutex.unlock();
+        gLastRemoteTime = QDateTime::currentMSecsSinceEpoch();
+
+        gnDecitionNum = gnDecitionNumMax;
+        gbChassisEPS = false;
+
+    }
+
+}
+
 void ExecSend()
 {
     static int nCount = 0;
@@ -640,6 +696,37 @@ void sendthread()
 //    Activate();
     while(gbSendRun)
     {
+
+        if(gbAutoDriving)
+        {
+            if(gnDecitionNum <= 0)
+            {
+                gMutex.lock();
+                xdecition.CopyFrom(gdecition_def);
+                gMutex.unlock();
+            }
+            else
+            {
+                xdecition.CopyFrom(gdecition);
+                gnDecitionNum--;
+            }
+        }
+        else
+        {
+            if((QDateTime::currentMSecsSinceEpoch() - gLastRemoteTime)> 1000)
+            {
+                gbAutoDriving = true;
+                continue;
+            }
+            else
+            {
+                gMutex.lock();
+                xdecition.CopyFrom(gdecition_remote);
+                gMutex.unlock();
+            }
+        }
+
+
         if(gnDecitionNum <= 0)
         {
             if(nstate == 1)
@@ -656,9 +743,18 @@ void sendthread()
                 Activate();
                 nstate = 1;
             }
-            gMutex.lock();
-            xdecition.CopyFrom(gdecition);
-            gMutex.unlock();
+            if(gbAutoDriving)
+            {
+                gMutex.lock();
+                xdecition.CopyFrom(gdecition);
+                gMutex.unlock();
+            }
+            else
+            {
+                gMutex.lock();
+                xdecition.CopyFrom(gdecition_remote);
+                gMutex.unlock();
+            }
             gnDecitionNum--;
         }
 
@@ -832,6 +928,8 @@ int main(int argc, char *argv[])
     gstrmemcansend = xp.GetParam("cansend","cansend0");
     gstrmemdecition = xp.GetParam("dection","deciton");
     gstrmemchassis = xp.GetParam("chassismsgname","chassis");
+    gstrmemremote = xp.GetParam("remotectrl","remotectrl");
+
     kp = xp.GetParam("kp",0.1);
     ki = xp.GetParam("ki",0.0);
     kd = xp.GetParam("kd",0.0);
@@ -839,10 +937,21 @@ int main(int argc, char *argv[])
     gbUsePID =  xp.GetParam("UsePID",false);
     gbPrintPIDOut = xp.GetParam("PrintPIDOut",false);
 
+    std::string strremote = xp.GetParam("allowremote","true");
+    if(strremote == "true")
+    {
+        gbAllowRemote = true;
+    }
+
     gpacansend = iv::modulecomm::RegisterSend(gstrmemcansend.data(),10000,1);
     gpadecition = iv::modulecomm::RegisterRecv(gstrmemdecition.data(),ListenDeciton);
     gpachassis = iv::modulecomm::RegisterRecv(gstrmemchassis.data(),UpdateChassis);
 
+    if(gbAllowRemote)
+    {
+        gparemote = iv::modulecomm::RegisterRecv(gstrmemremote.data(),ListenRemotectrl);
+    }
+
 #ifdef TORQUEBRAKETEST
     EnableTorqueBrakeTest();
 #endif

+ 5 - 1
src/detection/sign_detection/include/infer.hpp

@@ -90,9 +90,13 @@ class Infer {
   virtual void print() = 0;
 };
 
+#ifdef UBUNTU_22_04
+    #define TENSORRTNEW
+#endif
+
 std::shared_ptr<Infer> load(const std::string &file);
 std::string format_shape(const std::vector<int> &shape);
 
 }  // namespace trt
 
-#endif  // __INFER_HPP__
+#endif  // __INFER_HPP__

+ 31 - 1
src/detection/sign_detection/signdetect.pro

@@ -21,6 +21,34 @@ else: unix:!android: target.path = /opt/$${TARGET}/bin
 
 
 
+# 获取Ubuntu的版本信息
+UBUNTU_VERSION = $$system(lsb_release -rs)
+
+# 移除可能存在的空白字符
+UBUNTU_VERSION = $$replace(UBUNTU_VERSION, \\s+, )
+
+# 打印版本信息(可选)
+message(Ubuntu version: $$UBUNTU_VERSION)
+
+# 判断版本并定义宏
+contains(UBUNTU_VERSION, 20\\.04$) {
+    DEFINES += UBUNTU_20_04
+    message(Defining UBUNTU_20_04)
+}
+else:contains(UBUNTU_VERSION, 22\\.04$) {
+    DEFINES += UBUNTU_22_04
+    message(Defining UBUNTU_22_04)
+}
+else:contains(UBUNTU_VERSION, 24\\.04$) {
+    DEFINES += UBUNTU_24_04
+    message(Defining UBUNTU_24_04)
+}
+else {
+    message(Unknown Ubuntu version: $$UBUNTU_VERSION)
+}
+
+
+
 SOURCES += main.cpp \
            src/Hungarian.cpp \
            src/KalmanTracker.cpp \
@@ -90,7 +118,7 @@ LIBS += -L/usr/lib/aarch64-linux-gnu/ -lglog
 #####系统类型,计算能力###########
 SYSTEM_NAME = linux         # Depending on your system either 'Win32', 'x64', or 'Win64'
 SYSTEM_TYPE = 64            # '32' or '64', depending on your system
-CUDA_ARCH = sm_72           # Type of CUDA architecture, for example 'compute_10', 'compute_11', 'sm_10'
+CUDA_ARCH = sm_87           # Type of CUDA architecture, for example 'compute_10', 'compute_11', 'sm_10'
 NVCC_OPTIONS = --use_fast_math
 
 INCLUDEPATH += $$CUDA_DIR/include
@@ -122,3 +150,5 @@ else {
     cuda.dependency_type = TYPE_C
     QMAKE_EXTRA_COMPILERS += cuda
 }
+
+

+ 12 - 2
src/detection/sign_detection/src/infer.cu

@@ -255,8 +255,15 @@ class __native_engine_context {
     runtime_ = shared_ptr<IRuntime>(createInferRuntime(gLogger), destroy_nvidia_pointer<IRuntime>);
     if (runtime_ == nullptr) return false;
 
+
+
+//    engine_ = shared_ptr<ICudaEngine>(runtime_->deserializeCudaEngine(pdata, size),
+//                                      destroy_nvidia_pointer<ICudaEngine>);
+
+
     engine_ = shared_ptr<ICudaEngine>(runtime_->deserializeCudaEngine(pdata, size, nullptr),
-                                      destroy_nvidia_pointer<ICudaEngine>);
+                                      destroy_nvidia_pointer<ICudaEngine>);   //Old TensorRT
+
     if (engine_ == nullptr) return false;
 
     context_ = shared_ptr<IExecutionContext>(engine_->createExecutionContext(),
@@ -305,11 +312,13 @@ class InferImpl : public Infer {
 
   void setup() {
     auto engine = this->context_->engine_;
-    int nbBindings = engine->getNbBindings();
+//    int nbBindings = engine->getNbBindings();
+    int nbBindings = engine->getNbIOTensors();  //TensorRT 8.5 use this
 
     binding_name_to_index_.clear();
     for (int i = 0; i < nbBindings; ++i) {
       const char *bindingName = engine->getBindingName(i);
+//      const char *bindingName = engine->getIOTensorName(i);  //TensorRT 8.5
       binding_name_to_index_[bindingName] = i;
     }
   }
@@ -325,6 +334,7 @@ class InferImpl : public Infer {
                        void *input_consum_event) override {
     return this->context_->context_->enqueueV2((void**)bindings.data(), (cudaStream_t)stream,
                                                (cudaEvent_t *)input_consum_event);
+//    return this->context_->context_->enqueueV3((cudaStream_t)stream);  //TensorRT 8.5
   }
 
   virtual std::vector<int> run_dims(const std::string &name) override {

+ 5 - 4
src/driver/driver_cloud_grpc_client_h264/grpcclient.cpp

@@ -37,13 +37,12 @@ grpcclient::grpcclient(std::string stryamlpath)
     mstrpicmsgname[3] = "h264right";
 
     unsigned int i;
-    if(mbFrameUpdate)
-    {
+
         for(i=0;i<mvectormsgunit.size();i++)
         {
             mvectormsgunit[i].mpa = iv::modulecomm::RegisterRecv(mvectormsgunit[i].mstrmsgname,ListenData);
         }
-    }
+
 
     for(i=0;i<mvectorctrlmsgunit.size();i++)
     {
@@ -53,7 +52,7 @@ grpcclient::grpcclient(std::string stryamlpath)
 
     for(i=0;i<NUM_CAM;i++)
     {
-        mpaPic[i] = iv::modulecomm::RegisterRecv(mstrpicmsgname[i].data(),ListenPicData);
+//        mpaPic[i] = iv::modulecomm::RegisterRecv(mstrpicmsgname[i].data(),ListenPicData);
     }
 
 
@@ -415,11 +414,13 @@ void grpcclient::UpdateData(const char *strdata, const unsigned int nSize, const
 {
     int nsize = mvectormsgunit.size();
     int i;
+
     for(i=0;i<nsize;i++)
     {
 
         if(strncmp(strmemname,mvectormsgunit[i].mstrmsgname,255) == 0)
         {
+//            std::cout<<" update a data. name: "<<strmemname<<std::endl;
             gMutexMsg.lock();
             char * strtem = new char[nSize];
             memcpy(strtem,strdata,nSize);