Browse Source

add decition_speedlimit for cameradecision.

yuchuli 3 months ago
parent
commit
19985404a5

+ 74 - 0
src/decition/decition_speedlimit/.gitignore

@@ -0,0 +1,74 @@
+# This file is used to ignore files which are generated
+# ----------------------------------------------------------------------------
+
+*~
+*.autosave
+*.a
+*.core
+*.moc
+*.o
+*.obj
+*.orig
+*.rej
+*.so
+*.so.*
+*_pch.h.cpp
+*_resource.rc
+*.qm
+.#*
+*.*#
+core
+!core/
+tags
+.DS_Store
+.directory
+*.debug
+Makefile*
+*.prl
+*.app
+moc_*.cpp
+ui_*.h
+qrc_*.cpp
+Thumbs.db
+*.res
+*.rc
+/.qmake.cache
+/.qmake.stash
+
+# qtcreator generated files
+*.pro.user*
+CMakeLists.txt.user*
+
+# xemacs temporary files
+*.flc
+
+# Vim temporary files
+.*.swp
+
+# Visual Studio generated files
+*.ib_pdb_index
+*.idb
+*.ilk
+*.pdb
+*.sln
+*.suo
+*.vcproj
+*vcproj.*.*.user
+*.ncb
+*.sdf
+*.opensdf
+*.vcxproj
+*vcxproj.*
+
+# MinGW generated files
+*.Debug
+*.Release
+
+# Python byte code
+*.pyc
+
+# Binaries
+# --------
+*.dll
+*.exe
+

+ 131 - 0
src/decition/decition_speedlimit/decisionspeedlimit.cpp

@@ -0,0 +1,131 @@
+#include "decisionspeedlimit.h"
+
+#include <iostream>
+
+decisionspeedlimit::decisionspeedlimit(double fspeedlimit) {
+
+    mfspeedlimit = fspeedlimit;
+    ModuleFun xFunchassis = std::bind(&decisionspeedlimit::ListenChassis,this,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
+    mpachassis = iv::modulecomm::RegisterRecvPlus("chassis",xFunchassis);
+
+    mpadecision = iv::modulecomm::RegisterSend("deciton",1000,1);
+
+    ModuleFun xFunSpeedLimit = std::bind(&decisionspeedlimit::ListenDecsionSpeedLimit,this,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
+    mpadecisionspeedlimit = iv::modulecomm::RegisterRecvPlus("decitonspeedlimit",xFunSpeedLimit);
+
+}
+
+decisionspeedlimit::~decisionspeedlimit(){
+    iv::modulecomm::Unregister(mpadecisionspeedlimit);
+    iv::modulecomm::Unregister(mpadecision);
+    iv::modulecomm::Unregister(mpachassis);
+}
+
+
+void decisionspeedlimit::ListenChassis(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname){
+
+    iv::chassis xchassis;
+    if(!xchassis.ParseFromArray(strdata,nSize))
+    {
+        std::cout<<"Chassis Parse  Fail."<<std::endl;
+        return;
+    }
+
+    mmutexchassis.lock();
+    mnLastChassisUpdateTime = std::chrono::system_clock::now().time_since_epoch().count();
+    mchassis.CopyFrom(xchassis);
+    mmutexchassis.unlock();
+
+    (void)index;
+    (void)dt;
+    (void)strmemname;
+}
+
+void decisionspeedlimit::ListenDecsionSpeedLimit(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::decitionspeedlimit xdecisionspeedlimit;
+    iv::brain::decition xdecition;
+
+    if(!xdecisionspeedlimit.ParseFromArray(strdata,nSize))
+    {
+        std::cout<<"decisonspeedlimit Parse  Fail."<<std::endl;
+        return;
+    }
+
+    double facc = xdecisionspeedlimit.accelerator();
+    double ftorque = xdecisionspeedlimit.torque();
+
+
+
+    iv::chassis xchassis;
+    int64_t nlastchassis = 0;
+    mmutexchassis.lock();
+    xchassis.CopyFrom(xchassis);
+    nlastchassis = mnLastChassisUpdateTime;
+    mmutexchassis.unlock();
+
+    int64_t nnow = std::chrono::system_clock::now().time_since_epoch().count();
+    if(ftorque > 0)
+    {
+        if(nlastchassis == 0)
+        {
+            ftorque = 0;
+            std::cout<<nnow<<" no chassis message, limit torque to zero."<<std::endl;
+        }
+        if(abs(nnow - nlastchassis) >  1e9)
+        {
+            ftorque = 0;
+            std::cout<<nnow<<" no chassis message more than 1 second, limit torque to zero."<<std::endl;
+        }
+        else
+        {
+            if(xchassis.vel() > mfspeedlimit)
+            {
+                ftorque = 0;
+                std::cout<<" speed more than "<<mfspeedlimit<<" ,so limit torque to zero."<<std::endl;
+            }
+        }
+    }
+
+    xdecition.set_accelerator(facc);
+    xdecition.set_brake(xdecisionspeedlimit.brake());
+    xdecition.set_leftlamp(xdecisionspeedlimit.leftlamp());
+    xdecition.set_rightlamp(xdecisionspeedlimit.rightlamp());
+    xdecition.set_speed(xdecisionspeedlimit.speed());
+    xdecition.set_wheelangle(xdecisionspeedlimit.wheelangle());
+    xdecition.set_wheelspeed(300);
+    xdecition.set_torque(ftorque);
+    xdecition.set_mode(1);
+    xdecition.set_gear(1);
+    xdecition.set_handbrake(0);
+    xdecition.set_grade(1);
+    xdecition.set_engine(0);
+    xdecition.set_brakelamp(false);
+    xdecition.set_ttc(15);
+    //    xdecition.set_air_enable(decition->air_enable);
+    //    xdecition.set_air_temp(decition->air_temp);
+    //    xdecition.set_air_mode(decition->air_mode);
+    //    xdecition.set_wind_level(decition->wind_level);
+    xdecition.set_roof_light(0);
+    xdecition.set_home_light(0);
+    //    xdecition.set_air_worktime(decition->air_worktime);
+    //    xdecition.set_air_offtime(decition->air_offtime);
+    //    xdecition.set_air_on(decition->air_on);
+    xdecition.set_door(0);
+    xdecition.set_dippedlight(0);
+
+    int nbytesize = (int)xdecition.ByteSize();
+    std::shared_ptr<char> pstr_ptr = std::shared_ptr<char>(new char[nbytesize]);
+    if(!xdecition.SerializeToArray(pstr_ptr.get(),nbytesize))
+    {
+        std::cout<<" deciton Serialize Fail. "<<std::endl;
+        return;
+    }
+    iv::modulecomm::ModuleSendMsg(mpadecision,pstr_ptr.get(),nbytesize);
+
+
+
+}

+ 38 - 0
src/decition/decition_speedlimit/decisionspeedlimit.h

@@ -0,0 +1,38 @@
+#ifndef DECISIONSPEEDLIMIT_H
+#define DECISIONSPEEDLIMIT_H
+
+#include "modulecomm.h"
+
+#include "chassis.pb.h"
+#include "decition.pb.h"
+#include "decitionspeedlimit.pb.h"
+
+#include <mutex>
+
+class decisionspeedlimit
+{
+public:
+    decisionspeedlimit(double fspeedlimit);
+    ~decisionspeedlimit();
+
+private:
+    void ListenChassis(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname);
+    void ListenDecsionSpeedLimit(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname);
+
+private:
+    void * mpachassis;
+    void * mpadecisionspeedlimit;
+    void * mpadecision;
+
+private:
+    iv::chassis mchassis;
+    int64_t mnLastChassisUpdateTime = 0;
+    std::mutex mmutexchassis;
+
+    double mfspeedlimit = 15; //speed  limit
+
+
+
+};
+
+#endif // DECISIONSPEEDLIMIT_H

+ 34 - 0
src/decition/decition_speedlimit/decition_speedlimit.pro

@@ -0,0 +1,34 @@
+QT = core
+
+CONFIG += c++17 cmdline
+
+# You can make your code fail to compile if it uses deprecated APIs.
+# In order to do so, uncomment the following line.
+#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
+
+SOURCES += \
+        ../../include/msgtype/chassis.pb.cc \
+        ../../include/msgtype/decition.pb.cc \
+        ../../include/msgtype/decitionspeedlimit.pb.cc \
+        decisionspeedlimit.cpp \
+        main.cpp
+
+
+!include(../../../include/common.pri ) {
+    error( "Couldn't find the common.pri file!" )
+}
+
+!include(../../../include/ivprotobuf.pri ) {
+    error( "Couldn't find the ivprotobuf.pri file!" )
+}
+
+# Default rules for deployment.
+qnx: target.path = /tmp/$${TARGET}/bin
+else: unix:!android: target.path = /opt/$${TARGET}/bin
+!isEmpty(target.path): INSTALLS += target
+
+HEADERS += \
+    ../../include/msgtype/chassis.pb.h \
+    ../../include/msgtype/decition.pb.h \
+    ../../include/msgtype/decitionspeedlimit.pb.h \
+    decisionspeedlimit.h

+ 5 - 0
src/decition/decition_speedlimit/decition_speedlimit.xml

@@ -0,0 +1,5 @@
+<xml>	
+	<node name="decition_speedlimit">
+		<param name="speedlimit" value="15" />
+	</node>
+</xml>

+ 32 - 0
src/decition/decition_speedlimit/main.cpp

@@ -0,0 +1,32 @@
+#include <QCoreApplication>
+
+#include "xmlparam.h"
+#include "decisionspeedlimit.h"
+
+static double gfspeedlimit = 15.0;
+
+void LoadXML(const char * strxmlpath){
+    iv::xmlparam::Xmlparam xp(strxmlpath);
+    gfspeedlimit = xp.GetParam("speedlimit",15.0);
+    if(gfspeedlimit > 15.0)gfspeedlimit = 15.0;
+    if(gfspeedlimit < 0.0)gfspeedlimit = 0.0;
+}
+
+int main(int argc, char *argv[])
+{
+    QCoreApplication a(argc, argv);
+
+    if(argc>1)
+    {
+        LoadXML(argv[1]);
+    }
+    else
+    {
+        LoadXML("./decition_speedlimit.xml");
+    }
+
+    decisionspeedlimit dsl(gfspeedlimit);
+    (void)dsl;
+
+    return a.exec();
+}

+ 15 - 0
src/include/proto/decitionspeedlimit.proto

@@ -0,0 +1,15 @@
+syntax = "proto2";
+
+package iv.brain;
+
+message decitionspeedlimit
+{
+    optional float speed = 1;                //车速
+    optional float wheelAngle = 2;           //横向转向角度
+    optional float wheelSpeed = 3;           //方向盘角速度
+    optional float brake = 4;                //刹车
+    optional float accelerator = 5;          //纵向加速度
+    optional float torque = 6;               //油门
+    optional bool  leftLamp = 7;             //左转向灯
+    optional bool  rightLamp = 8;            //右转向灯
+};

+ 2 - 2
src/python/cameradecision/cameradecision.py

@@ -1,8 +1,8 @@
 
 
-import proto.decition_pb2 as decition_pb2
 
 import proto.cameraobjectarray_pb2 as cameraobjectarray_pb2
+import proto.decitionspeedlimit_pb2 as decitionspeedlimit_pb2
 
 import math
 from typing import List  
@@ -54,7 +54,7 @@ class CameraDecision:
 
 
 
-        xdecisiion = decition_pb2.decition()
+        xdecisiion = decitionspeedlimit_pb2.decitionspeedlimit()
         xdecisiion.wheelAngle = wheel
         xdecisiion.accelerator = acc
         xdecisiion.brake = 0

+ 2 - 3
src/python/cameradecision/cameradecisionmain.py

@@ -4,9 +4,8 @@ import time
 import sys  
 
 
-
-import proto.decition_pb2 as decition_pb2
 import proto.cameraobjectarray_pb2 as cameraobjectarray_pb2
+import proto.decitionspeedlimit_pb2 as decitionspeedlimit_pb2
 
 from PyModuleCommModule import PyModuleComm
 from cameradecision import CameraDecision
@@ -65,7 +64,7 @@ def main():
     mobj = PyModuleComm("signarray")
     mobj.RegisterRecv(cameraobjectarray_callback)
 
-    md = PyModuleComm("deciton")
+    md = PyModuleComm("decitonspeedlimit")
     md.RegiseterSend(100000,1)
     # 使用while循环,只要count小于10,就继续循环  
     while count < 10:

+ 0 - 1
src/python/cameradecision/proto/cameraobjectarray_pb2.py

@@ -12,7 +12,6 @@ _sym_db = _symbol_database.Default()
 
 
 from . import cameraobject_pb2 as cameraobject__pb2
-#import cameraobject_pb2 as cameraobject__pb2
 
 
 DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x17\x63\x61meraobjectarray.proto\x12\tiv.vision\x1a\x12\x63\x61meraobject.proto\"I\n\x11\x63\x61meraobjectarray\x12$\n\x03obj\x18\x01 \x03(\x0b\x32\x17.iv.vision.cameraobject\x12\x0e\n\x06mstime\x18\x02 \x01(\x03')

+ 0 - 60
src/python/cameradecision/proto/decition.proto

@@ -1,60 +0,0 @@
-syntax = "proto2";
-
-package iv.brain;
-
-message decition
-{
-    optional float speed = 1;                //车速
-    optional float wheelAngle = 2;           //横向转向角度
-    optional float wheelSpeed = 3;           //方向盘角速度
-    optional float lateralTorque = 4;        //横向扭矩
-    optional float brake = 5;                //刹车
-    optional float accelerator = 6;          //纵向加速度
-    optional float torque = 7;               //油门
-    optional bool  leftLamp = 8;             //左转向灯
-    optional bool  rightLamp = 9;            //右转向灯
-    optional bool  doubleSpark = 10;          //双闪
-    optional bool  headLight = 11;            //前灯
-    optional bool  highBeam = 12;             //远光灯
-    optional int32  dippedLight = 13;          //近光灯
-    optional bool  tailLight = 14;            //尾灯
-    optional bool  domeLight = 15;            //顶灯
-    optional bool  fogLamp = 16;              //雾灯
-    optional bool  backupLight = 17;          //倒车灯
-    optional bool  brakeLamp = 18;            //制动灯
-    optional int32   engine = 19;               //发动机点火
-    optional int32   mode = 20;                 //模式:自动or手动
-    optional int32  handBrake = 21;            //手刹
-    optional bool  speak = 22;                //喇叭
-    optional int32  door = 23;                 //车门
-    optional int32   gear = 24;                 //挡位
-    optional int32   wiper = 25;                //雨刷
-    optional int32   grade = 26;                 //GE3使用的一个指标
-    optional float   ttc = 27;                  //预测碰撞时间 
-    optional bool   air_enable = 28;                  //空调使能 
-    optional float   air_temp = 29;                  //空调温度 
-    optional float   air_mode = 30;                  //空调模式 
-    optional float   wind_level = 31;                  //空调风力 
-    optional int32   roof_light = 32;                  //顶灯 
-    optional int32   home_light = 33;                  //日光灯 
-    optional float   air_worktime = 34;                  //空调工作时间
-    optional float   air_offtime = 35;                  //空调关闭时间 
-    optional bool   air_on = 36;                  //空调使能 
-	// vv7-tdu
-	optional bool air_ac = 37;
-	optional bool air_circle = 38;
-	optional bool air_auto = 39;
-	optional bool air_off = 40;
-	optional uint32 window_fl = 41;
-	optional uint32 window_fr = 42;
-	optional uint32 window_rl = 43;
-	optional uint32 window_rr = 44;
-    //chang_an_shen_lan
-	optional uint32 angle_mode = 45;  //横向控制激活模式
-	optional uint32 angle_active = 46; //横向控制激活,和上一条同时满足才执行横向请求角度 
-	optional uint32 acc_active = 47; //ACC扭矩请求激活(为1激活,为0不激活),不激活后不执行扭矩请求
-	optional uint32 brake_active = 48; //ACC减速激活(为1制动激活,为0制动不激活)
-	optional uint32 brake_type = 49;//ADC请求类型(制动时为1,其余情况为0)
-	optional float niuju_y = 50; //纵向扭矩
-	optional uint32 auto_mode = 51; //3为自动控制模式
-};

File diff suppressed because it is too large
+ 0 - 15
src/python/cameradecision/proto/decition_pb2.py


+ 15 - 0
src/python/cameradecision/proto/decitionspeedlimit.proto

@@ -0,0 +1,15 @@
+syntax = "proto2";
+
+package iv.brain;
+
+message decitionspeedlimit
+{
+    optional float speed = 1;                //车速
+    optional float wheelAngle = 2;           //横向转向角度
+    optional float wheelSpeed = 3;           //方向盘角速度
+    optional float brake = 4;                //刹车
+    optional float accelerator = 5;          //纵向加速度
+    optional float torque = 6;               //油门
+    optional bool  leftLamp = 7;             //左转向灯
+    optional bool  rightLamp = 8;            //右转向灯
+};

+ 25 - 0
src/python/cameradecision/proto/decitionspeedlimit_pb2.py

@@ -0,0 +1,25 @@
+# -*- coding: utf-8 -*-
+# Generated by the protocol buffer compiler.  DO NOT EDIT!
+# source: decitionspeedlimit.proto
+"""Generated protocol buffer code."""
+from google.protobuf.internal import builder as _builder
+from google.protobuf import descriptor as _descriptor
+from google.protobuf import descriptor_pool as _descriptor_pool
+from google.protobuf import symbol_database as _symbol_database
+# @@protoc_insertion_point(imports)
+
+_sym_db = _symbol_database.Default()
+
+
+
+
+DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x18\x64\x65\x63itionspeedlimit.proto\x12\x08iv.brain\"\xa4\x01\n\x12\x64\x65\x63itionspeedlimit\x12\r\n\x05speed\x18\x01 \x01(\x02\x12\x12\n\nwheelAngle\x18\x02 \x01(\x02\x12\x12\n\nwheelSpeed\x18\x03 \x01(\x02\x12\r\n\x05\x62rake\x18\x04 \x01(\x02\x12\x13\n\x0b\x61\x63\x63\x65lerator\x18\x05 \x01(\x02\x12\x0e\n\x06torque\x18\x06 \x01(\x02\x12\x10\n\x08leftLamp\x18\x07 \x01(\x08\x12\x11\n\trightLamp\x18\x08 \x01(\x08')
+
+_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, globals())
+_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'decitionspeedlimit_pb2', globals())
+if _descriptor._USE_C_DESCRIPTORS == False:
+
+  DESCRIPTOR._options = None
+  _DECITIONSPEEDLIMIT._serialized_start=39
+  _DECITIONSPEEDLIMIT._serialized_end=203
+# @@protoc_insertion_point(module_scope)

Some files were not shown because too many files changed in this diff