Parcourir la source

change controller_hapo. for add TorqueBrakeTest.

yuchuli il y a 3 ans
Parent
commit
92cb273eeb

+ 9 - 0
src/controller/controller_hapo/controller_hapo.pro

@@ -40,6 +40,15 @@ include($$PWD/control/control.pri)
     error( "Couldn't find the ivboost.pri file!" )
 }
 
+!include(../controllercommon/controllercommon.pri ) {
+    error( "Couldn't find the controllercommon.pri.pri file!" )
+}
+
+INCLUDEPATH += $$PWD/../controllercommon
+
+
+#DEFINES += TORQUEBRAKETEST
+
 #unix:!macx: LIBS += -L/home/yuchuli/qt/lib -lncomgnss -ladcmemshare
 
 unix:!macx: INCLUDEPATH += $$PWD/.

+ 28 - 0
src/controller/controller_hapo/main.cpp

@@ -16,6 +16,8 @@
 #include "decition.pb.h"
 #include "chassis.pb.h"
 
+#include "torquebrake.h"
+
 #include <thread>
 
 void * gpacansend;
@@ -97,6 +99,28 @@ void executeDecition(const iv::brain::decition decition)
     gcontroller->control_turnsignals(decition.leftlamp(),decition.rightlamp());
     gcontroller->control_door(decition.door());
 
+#ifdef TORQUEBRAKETEST
+    if(gnothavetb < 10)
+    {
+        iv::controller::torquebrake xtb;
+        gMutextb.lock();
+        xtb.CopyFrom(gtb);
+        gMutextb.unlock();
+        if(xtb.enable())
+        {
+            gcontroller->control_torque(xtb.torque());
+            gcontroller->control_brake(xtb.brake());
+//            qDebug("use tb value torque is %f brake is %f",xtb.torque(),xtb.brake());
+        }
+        else
+        {
+//            qDebug("torquebrake not enable.");
+        }
+        gnothavetb++;
+    }
+
+#endif
+
     /*if(decition.has_door())
     {
         if(decition.door())
@@ -298,6 +322,10 @@ int main(int argc, char *argv[])
     gpadecition = iv::modulecomm::RegisterRecv(gstrmemdecition.data(),ListenDeciton);
     gpachassis = iv::modulecomm::RegisterRecv(gstrmemchassis.data(),UpdateChassis);
 
+#ifdef TORQUEBRAKETEST
+    EnableTorqueBrakeTest();
+#endif
+
     std::thread xthread(sendthread);
 
     return a.exec();

+ 7 - 0
src/controller/controllercommon/controllercommon.pri

@@ -0,0 +1,7 @@
+HEADERS += \
+    $$PWD/../../include/msgtype/torquebrake.pb.h \
+    $$PWD/torquebrake.h
+
+SOURCES += \
+    $$PWD/../../include/msgtype/torquebrake.pb.cc \
+    $$PWD/torquebrake.cpp

+ 31 - 0
src/controller/controllercommon/torquebrake.cpp

@@ -0,0 +1,31 @@
+
+#include "torquebrake.h"
+#include "modulecomm.h"
+
+#include <QMutex>
+#include <iostream>
+
+iv::controller::torquebrake gtb;
+int gnothavetb = 10;
+QMutex gMutextb;
+void * gpatorquebrake;
+
+void UpdateTorqueBrake(const char *strdata, const unsigned int nSize, const unsigned int index, const QDateTime *dt, const char *strmemname)
+{
+    iv::controller::torquebrake xtb;
+    if(!xtb.ParseFromArray(strdata,nSize))
+    {
+        std::cout<<"UpdateTorqueBrake ParseFrom Array Error."<<std::endl;
+        return;
+    }
+    gMutextb.lock();
+    gtb.CopyFrom(xtb);
+    gMutextb.unlock();
+    gnothavetb= 0;
+}
+
+void EnableTorqueBrakeTest()
+{
+    gpatorquebrake = iv::modulecomm::RegisterRecv("torquebrake",UpdateTorqueBrake);
+}
+

+ 14 - 0
src/controller/controllercommon/torquebrake.h

@@ -0,0 +1,14 @@
+#ifndef TORQUEBRAKE_H
+#define TORQUEBRAKE_H
+
+#include <QMutex>
+
+#include "torquebrake.pb.h"
+
+
+extern iv::controller::torquebrake gtb;
+extern int gnothavetb ;
+extern QMutex gMutextb;
+
+void EnableTorqueBrakeTest();
+#endif // TORQUEBRAKE_H