浏览代码

change controller_changan_a07. add some APA logic.

yuchuli 1 月之前
父节点
当前提交
84c51455e4
共有 1 个文件被更改,包括 48 次插入0 次删除
  1. 48 0
      src/controller/controller_changan_a07/main.cpp

+ 48 - 0
src/controller/controller_changan_a07/main.cpp

@@ -28,6 +28,9 @@
 #include "changan_a07.h"
 #include "dbcsigpacker.h"
 
+bool gbUseAPA;
+int gnAPAstate = 0; //0 not request   1 request   2 active
+
 std::string gstrdbcpath;
 bool gbUseOutDBC;
 
@@ -120,6 +123,51 @@ void executeDecition(const iv::brain::decition &decition)
     SetMsgSignal("ECU_23C","ACC_AccTrqReq",ftorque);
     SetMsgSignal("ECU_23C","ACC_AccTrqReqActive",decition.acc_active());
 
+    if(gbUseAPA)
+    {
+        static int64_t ntimeChangetoreq = std::chrono::system_clock::now().time_since_epoch().count()/1e6;
+        int64_t nnow;
+        if(decition.angle_active() == 0)
+        {
+            switch (gnAPAstate) {
+            case 0:
+                gnAPAstate = 1;
+                ntimeChangetoreq = std::chrono::system_clock::now().time_since_epoch().count()/1e6;
+                break;
+            case 1:
+                nnow = std::chrono::system_clock::now().time_since_epoch().count()/1e6;
+                if(abs(nnow - ntimeChangetoreq)<300)
+                    gnAPAstate = 1;
+                else
+                    gnAPAstate = 2;
+                break;
+            case 2:
+                gnAPAstate = 2;
+                break;
+            default:
+                gnAPAstate = 0;
+                break;
+            }
+        }
+        else
+        {
+            switch (gnAPAstate) {
+            case 0:
+                gnAPAstate = 0;
+                break;
+            case 1:
+                gnAPAstate = 0;
+                break;
+            case 2:
+                gnAPAstate = 0;
+                break;
+            default:
+                gnAPAstate = 0;
+                break;
+            }
+        }
+    }
+
     if(decition.brake()<(-5.0))
     {
         SetMsgSignal("ECU_23C","ACC_ACCTargetAcceleration",-5.0);