|
@@ -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);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|