123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595 |
- #include <QCoreApplication>
- #include <QTime>
- #include <QMutex>
- #include "control/control_status.h"
- #include "control/controller.h"
- #include "xmlparam.h"
- #include "modulecomm.h"
- #include "ivbacktrace.h"
- #include "ivversion.h"
- #include "canmsg.pb.h"
- #include "decition.pb.h"
- #include "chassis.pb.h"
- #include "torquebrake.h"
- #include <thread>
- void * gpacansend;
- void * gpadecition;
- void * gpachassis;
- std::string gstrmemdecition;
- std::string gstrmemcansend;
- std::string gstrmemchassis;
- bool gbSendRun = true;
- bool gbChassisEPS = false;
- iv::brain::decition gdecition_def;
- iv::brain::decition gdecition;
- QTime gTime;
- int gnLastSendTime = 0;
- int gnLastRecvDecTime = -1000;
- int gnDecitionNum = 0; //when is zero,send default;
- const int gnDecitionNumMax = 100;
- int gnIndex = 0;
- static bool gbHaveVehSpd = false;
- static double gfVehSpd = 0.0;
- boost::shared_ptr<iv::control::Controller> gcontroller; //实际车辆控制器
- static QMutex gMutex;
- // signal: @ACC_LatAngReq //更改CANid
- #define ECU_1C4_ACC_LatAngReq_CovFactor (0.1)
- // conversion value to CAN signal
- #define ECU_1C4_ACC_LatAngReq_toS(x) ((int16_t)((x) / 0.1 + 7200))
- // signal: @ACC_MotorTorqueMaxLimitRequest
- #define ECU_1C4_ACC_MotorTorqueMaxLimitRequest_CovFactor (0.02)
- // conversion value to CAN signal
- #define ECU_1C4_ACC_MotorTorqueMaxLimitRequest_toS(x) ((int16_t)((x) / 0.02 + 1024))
- // signal: @ACC_MotorTorqueMinLimitRequest
- #define ECU_1C4_ACC_MotorTorqueMinLimitRequest_CovFactor (0.02)
- // conversion value to CAN signal
- #define ECU_1C4_ACC_MotorTorqueMinLimitRequest_toS(x) ((int16_t)((x) / 0.02 + 1024))
- typedef struct
- {
- int16_t ACC_LatAngReq;
- //uint8_t ADS_Reqmode; //20221102, 新车没有此信号
- int16_t ACC_MotorTorqueMaxLimitRequest;
- uint8_t ACC_LatAngReqActive;
- int16_t ACC_MotorTorqueMinLimitRequest;
- //uint8_t ACC_ADCReqType; //20221102, 新车没有此信号
- } ECU_1C4_t;
- // signal: @ACC_AccTrqReq
- #define ECU_24E_ACC_AccTrqReq_CovFactor (1)
- // conversion value to CAN signal
- #define ECU_24E_ACC_AccTrqReq_toS(x) ((int16_t)((x) + 16384))
- // signal: @ACC_ACCTargetAcceleration
- #define ECU_24E_ACC_ACCTargetAcceleration_CovFactor (0.05)
- // conversion value to CAN signal
- #define ECU_24E_ACC_ACCTargetAcceleration_toS(x) ((int16_t)((x) / 0.05 + 200))
- // signal: @ACC_AEBTargetDeceleration
- #define ECU_24E_ACC_AEBTargetDeceleration_CovFactor (0.0005)
- // conversion value to CAN signal
- #define ECU_24E_ACC_AEBTargetDeceleration_toS(x) ((int32_t)((x) / 0.0005 + 32000))
- typedef struct
- {
- int16_t ACC_AccTrqReq;
- uint8_t ACC_AccTrqReqActive;
- int16_t ACC_ACCTargetAcceleration;
- int32_t ACC_AEBTargetDeceleration;
- uint8_t ACC_AEBVehilceHoldReq;
- uint8_t ADCReqMode;
- uint8_t ACC_AEBActive;
- uint8_t ACC_Driveoff_Request;
- uint8_t ACC_DecToStop;
- uint8_t ACC_CDDActive;
- uint8_t ACC_ACCMode;
- } ECU_24E_t;
- typedef struct
- {
- uint8_t ADS_UDLCTurnLightReq;
- } ECU_36E_t;
- unsigned char byte_1C4[64];//byte_144[8];
- unsigned char byte_24E[64];
- unsigned char byte_36E[64];
- ECU_1C4_t _m1C4 = {0,0,0,0};
- ECU_24E_t _m24E = {0,0,0,0,0,0,0,0,0,0,0};
- ECU_36E_t _m36E = {0};
- void ExecSend();
- void executeDecition(const iv::brain::decition &decition)
- {
- static int xieya = 50;
- // std::cout<<"acc is "<<decition.torque()<<" ang is "<<decition.wheelangle()<<std::endl;
- // std::cout<<"angle_mode is "<<decition.angle_mode()<<" angle_active is "<<decition.angle_active()<<std::endl;
- // std::cout<<"brake_type is "<<decition.brake_type()<<" acc_active is "<<decition.acc_active()<<std::endl;
- // std::cout<<"brake is "<<decition.brake()<<" brake_active is "<<decition.brake_active()<<std::endl;
- // std::cout<<"auto_mode is "<<decition.auto_mode()<<" rightlamp is "<<decition.rightlamp()<<std::endl;
- _m1C4.ACC_LatAngReq = ECU_1C4_ACC_LatAngReq_toS(decition.wheelangle());
- //_m1C4.ADS_Reqmode = decition.angle_mode(); //20221102,新车没有此信号
- _m1C4.ACC_MotorTorqueMaxLimitRequest = ECU_1C4_ACC_MotorTorqueMaxLimitRequest_toS(10);
- _m1C4.ACC_LatAngReqActive = decition.angle_active();
- _m1C4.ACC_MotorTorqueMinLimitRequest = ECU_1C4_ACC_MotorTorqueMinLimitRequest_toS(-10);
- // _m144.ACC_ADCReqType = decition.brake_type();//ADC请求类型(制动时为1,其余情况为0)
- if(decition.brake()>(-0.0000001))
- {
- //_m144.ACC_ADCReqType = 0;//ADC请求类型(制动时为1,其余情况为0)//20221102,新车没有此信号
- // _m24B.ADCReqMode = 0;//20221102,新车没有此信号
- _m24E.ACC_DecToStop =0;
- }
- else
- {
- //_m144.ACC_ADCReqType = 1;//20221102,新车没有此信号
- // _m24B.ADCReqMode = 1;//20221102,新车没有此信号
- _m24E.ACC_DecToStop =1;
- }
- // std::cout<<" type: "<<(int)_m144.ACC_ADCReqType<<std::endl;
- /*制动过程用的减速度,加速用扭矩*/
- _m24E.ACC_AccTrqReq = ECU_24E_ACC_AccTrqReq_toS(decition.torque());
- _m24E.ACC_AccTrqReqActive = decition.acc_active();
- if(decition.brake()<(-0.5))
- {
- _m24E.ACC_ACCTargetAcceleration = ECU_24E_ACC_ACCTargetAcceleration_toS(-0.5);
- }
- else
- _m24E.ACC_ACCTargetAcceleration = ECU_24E_ACC_ACCTargetAcceleration_toS(decition.brake());
- // std::cout<<" brake : "<<decition.brake()<<std::endl;
- // std::cout<<"brake acctive. "<<decition.brake_active()<<std::endl;
- if(decition.brake()>(-0.0000001))
- {
- if(xieya > 0)
- {
- _m24E.ACC_CDDActive = 1;
- _m24E.ACC_ACCTargetAcceleration = ECU_24E_ACC_ACCTargetAcceleration_toS(0.5);
- _m24E.ACC_AccTrqReq = ECU_24E_ACC_AccTrqReq_toS(0);
- _m24E.ACC_Driveoff_Request = 1;
- //_m144.ACC_ADCReqType = 1;//20221102,新车没有此信号
- //_m24B.ADCReqMode = 1; //20221102,新车没有此信号
- _m24E.ACC_DecToStop =1;
- xieya--;
- std::cout<<" xieya. now veh speed: "<<gfVehSpd<<std::endl;
- }
- else
- {
- _m24E.ACC_CDDActive = 0;
- _m24E.ACC_ACCTargetAcceleration = ECU_24E_ACC_ACCTargetAcceleration_toS(0);
- _m24E.ACC_Driveoff_Request = 0;
- }
- }
- else
- {
- _m24E.ACC_CDDActive = 1;
- _m24E.ACC_Driveoff_Request = 0;
- }
- // _m24B.ACC_CDDActive = decition.brake_active();
- // std::cout<<" req mode: "<<_m144.ADS_Reqmode<<std::endl;
- //byte_144[0] = ((_m144.ACC_LatAngReq >> 9) & (0x1FU)) | ((_m144.ADS_Reqmode & (0x07U)) << 5);
- // qDebug(" req mode: %d byte: %02X ",_m144.ADS_Reqmode, byte_144[0]);
- // byte_144[1] = ((_m144.ACC_LatAngReq >> 1) & (0xFFU));
- //byte_144[2] = ((_m144.ACC_LatAngReq & (0x01U)) << 7) | ((_m144.ACC_MotorTorqueMaxLimitRequest >> 5) & (0x3FU)) | ((_m144.ACC_LatAngReqActive & (0x01U)) << 6);
- //byte_144[3] = ((_m144.ACC_MotorTorqueMaxLimitRequest & (0x1FU)) << 3) | ((_m144.ACC_MotorTorqueMinLimitRequest >> 8) & (0x07U));
- //byte_144[4] = (_m144.ACC_MotorTorqueMinLimitRequest & (0xFFU));
- //byte_144[5] = ((_m144.ACC_ADCReqType & (0x03U)) << 6);
- byte_1C4[0] = ((_m1C4.ACC_MotorTorqueMaxLimitRequest >> 3) & (0xFFU));
- // qDebug(" req mode: %d byte: %02X ",_m144.ADS_Reqmode, byte_144[0]);
- byte_1C4[1] = ((_m1C4.ACC_MotorTorqueMaxLimitRequest & (0x07U)) << 5) | ((_m1C4.ACC_MotorTorqueMinLimitRequest >> 6) & (0x1FU));
- byte_1C4[2] = ((_m1C4.ACC_MotorTorqueMinLimitRequest & (0x3FU)) << 2) | ((_m1C4.ACC_LatAngReq >> 12) & (0x03U));
- byte_1C4[3] = (((_m1C4.ACC_LatAngReq>>4 )& (0xFFU)));
- // byte_1C4[4] = (((_m1C4.ACC_LatAngReq<<4) & (0xF0U)))|((_m1C4.ACC_LatAngReqActive&(0x01U))<<3);
- byte_1C4[4] = (((_m1C4.ACC_LatAngReq)& (0x0fU))<<4)|((_m1C4.ACC_LatAngReqActive&(0x01U))<<3);
- //byte_1C4[5] = ((_m144.ACC_ADCReqType & (0x03U)) << 6);
- // _m24B.ACC_AEBTargetDeceleration = 0;
- // _m24B.ACC_AEBVehilceHoldReq = 0;
- // _m24B.ADCReqMode = 0;
- // _m24B.ACC_AEBActive = 0;
- // _m24B.ACC_Driveoff_Request = 0;
- // _m24B.ACC_DecToStop = 0;
- // std::cout<<" brake : "<<decition.brake()<<std::endl;
- // std::cout<<"brake acctive. "<<decition.brake_active()<<std::endl;
- if(decition.brake()>(-0.0000001))
- {
- _m24E.ACC_CDDActive = 0;
- _m24E.ACC_Driveoff_Request = 1;
- if(xieya > 0)
- {
- _m24E.ACC_ACCTargetAcceleration = ECU_24E_ACC_ACCTargetAcceleration_toS(0.5);
- xieya--;
- }
- else
- {
- _m24E.ACC_ACCTargetAcceleration = ECU_24E_ACC_ACCTargetAcceleration_toS(0);
- }
- }
- else
- {
- _m24E.ACC_CDDActive = 1;
- _m24E.ACC_Driveoff_Request = 0;
- if(gbHaveVehSpd)
- {
- if(gfVehSpd < 0.01)
- {
- if(xieya != 50)std::cout<<"need xieya. "<<std::endl;
- xieya = 50;
- }
- }
- }
- // _m24B.ACC_CDDActive = decition.brake_active();
- _m24E.ACC_ACCMode = decition.auto_mode();
- // std::cout<<"acc mode: "<<(int)_m24B.ACC_ACCMode<<std::endl;
- // byte_24B[0] = ((_m24B.ACC_AccTrqReq >> 7) & (0xFFU));
- //byte_24B[1] = ((_m24B.ACC_AccTrqReq & (0x7FU)) << 1) | (_m24B.ACC_AccTrqReqActive & (0x01U));
- //byte_24B[2] = ((_m24B.ACC_ACCTargetAcceleration >> 3) & (0x1FU));
- //byte_24B[3] = ((_m24B.ACC_ACCTargetAcceleration & (0x07U)) << 5) | ((_m24B.ACC_AEBTargetDeceleration >> 15) & (0x01U));
- //byte_24B[4] = ((_m24B.ACC_AEBTargetDeceleration >> 7) & (0xFFU));
- //byte_24B[5] = ((_m24B.ACC_AEBTargetDeceleration & (0x7FU)) << 1) | (_m24B.ACC_AEBVehilceHoldReq & (0x01U));
- //byte_24B[6] = ((_m24B.ADCReqMode & (0x03U)) << 1) | ((_m24B.ACC_AEBActive & (0x01U)) << 3) | ((_m24B.ACC_Driveoff_Request & (0x01U)) << 5) | ((_m24B.ACC_DecToStop & (0x01U)) << 6) | ((_m24B.ACC_CDDActive & (0x01U)) << 7);
- //byte_24B[7] = (_m24B.ACC_ACCMode & (0x07U));
- byte_24E[0] = ((_m24E.ACC_ACCTargetAcceleration) & (0xFFU));
- //byte_24E[1] = ((_m24B.ACC_AccTrqReq & (0x7FU)) << 1) | (_m24B.ACC_AccTrqReqActive & (0x01U));
- //byte_24E[2] = ((_m24B.ACC_ACCTargetAcceleration >> 3) & (0x1FU));
- byte_24E[3] = ((_m24E.ACC_DecToStop & (0x01U)) << 7);// | ((_m24B.ACC_AEBTargetDeceleration >> 15) & (0x01U));
- //byte_24E[4] = ((_m24B.ACC_AEBTargetDeceleration >> 7) & (0xFFU));
- byte_24E[5] = ((_m24E.ACC_CDDActive & (0x01U)) << 4);//((_m24E.ACC_AEBTargetDeceleration & (0x7FU)) << 1) | (_m24E.ACC_AEBVehilceHoldReq & (0x01U));
- byte_24E[6] = ((_m24E.ACC_Driveoff_Request & (0x01U)) << 7)|((_m24E.ACC_ACCMode & (0x07U))<<4);//((_m24E.ADCReqMode & (0x03U)) << 1) | ((_m24E.ACC_AEBActive & (0x01U)) << 3) | ((_m24E.ACC_Driveoff_Request & (0x01U)) << 5) | ((_m24E.ACC_DecToStop & (0x01U)) << 6) | ((_m24E.ACC_CDDActive & (0x01U)) << 7);
- byte_24E[8] = ((_m24E.ACC_AEBTargetDeceleration>>8) & (0xFFU));
- byte_24E[9] = ((_m24E.ACC_AEBTargetDeceleration) & (0xFFU));
- byte_24E[10] = ((_m24E.ACC_AEBActive & (0x01U)) << 7);
- byte_24E[11] = ((_m24E.ACC_AccTrqReq>>13 )& (0x03U));
- byte_24E[12] = ((_m24E.ACC_AccTrqReq>>5 )& (0xFFU));
- //byte_24E[13] = ((_m24E.ACC_AccTrqReq & (0x1FU)<<3))| ((_m24E.ACC_AccTrqReqActive & (0x01U)) << 2);
- byte_24E[13] = (((_m24E.ACC_AccTrqReq & (0x1FU))<<3))| ((_m24E.ACC_AccTrqReqActive & (0x01U)) << 2);
- // if(decition.leftlamp() == true && decition.rightlamp() == false)
- // _m36E.ADS_UDLCTurnLightReq = 3;
- // else if(decition.leftlamp() == false && decition.rightlamp() == true)
- // _m36E.ADS_UDLCTurnLightReq = 4;
- // else
- // _m36E.ADS_UDLCTurnLightReq = 0;
- // byte_36E[0] = ((_m36E.ADS_UDLCTurnLightReq & (0x07U)) << 5);
- }
- void Activate()
- {
- std::this_thread::sleep_for(std::chrono::milliseconds(100));
- iv::brain::decition xdecition;
- // for(int j=0;j<100000;j++)
- // {
- std::cout<<" run "<<std::endl;
- for(int i = 0; i < 10; i++){
- xdecition.set_wheelangle(0.0);
- xdecition.set_angle_mode(0);
- xdecition.set_angle_active(0);
- xdecition.set_acc_active(0);
- xdecition.set_brake_active(0);
- // xdecition.set_brake_type(0);
- xdecition.set_auto_mode(0);
- executeDecition(xdecition);
- ExecSend();
- std::this_thread::sleep_for(std::chrono::milliseconds(10));
- }
- for(int i = 0; i < 10; i++){
- xdecition.set_wheelangle(0.0);
- 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);
- executeDecition(xdecition);
- ExecSend();
- std::this_thread::sleep_for(std::chrono::milliseconds(10));
- }
- // }
- }
- void UnAcitvate()
- {
- iv::brain::decition xdecition;
- for(int i = 0; i < 10; i++){
- xdecition.set_wheelangle(0);
- 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);
- executeDecition(xdecition);
- ExecSend();
- std::this_thread::sleep_for(std::chrono::milliseconds(10));
- }
- for(int i = 0; i < 10; i++){
- xdecition.set_wheelangle(0);
- xdecition.set_angle_mode(0);
- xdecition.set_angle_active(0);
- xdecition.set_acc_active(0);
- xdecition.set_brake_active(0);
- // xdecition.set_brake_type(0);
- xdecition.set_auto_mode(0);
- executeDecition(xdecition);
- ExecSend();
- std::this_thread::sleep_for(std::chrono::milliseconds(10));
- }
- }
- void UpdateChassis(const char *strdata, const unsigned int nSize, const unsigned int index, const QDateTime *dt, const char *strmemname)
- {
- (void)index;
- (void)dt;
- (void)strmemname;
- iv::chassis xchassis;
- // static int ncount = 0;
- if(!xchassis.ParseFromArray(strdata,nSize))
- {
- std::cout<<"iv::decition::BrainDecition::UpdateChassis ParseFrom Array Error."<<std::endl;
- return;
- }
- if(xchassis.has_epsmode())
- {
- if(xchassis.epsmode() == 0)
- {
- gbChassisEPS = true;
- }
- }
- if(xchassis.has_vel())
- {
- gfVehSpd = xchassis.vel();
- gbHaveVehSpd = true;
- // std::cout<<" gf Veh speed : "<<gfVehSpd<<std::endl;
- }
- }
- void ListenDeciton(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
- {
- (void)index;
- (void)dt;
- (void)strmemname;
- static qint64 oldtime = QDateTime::currentMSecsSinceEpoch();
- iv::brain::decition xdecition;
- if(!xdecition.ParseFromArray(strdata,nSize))
- {
- std::cout<<"ListenDecition parse error."<<std::endl;
- return;
- }
- // if(xdecition.gear() != 4)
- // {
- // qDebug("not D");
- // }
- 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);
- if((oldtime - QDateTime::currentMSecsSinceEpoch())<-100)qDebug("dection time is %lld diff is %lld ",QDateTime::currentMSecsSinceEpoch(),oldtime - QDateTime::currentMSecsSinceEpoch());
- oldtime = QDateTime::currentMSecsSinceEpoch();
- gMutex.lock();
- gdecition.CopyFrom(xdecition);
- gMutex.unlock();
- gnDecitionNum = gnDecitionNumMax;
- gbChassisEPS = false;
- }
- void ExecSend()
- {
- static int nCount = 0;
- nCount++;
- iv::can::canmsg xmsg;
- iv::can::canraw xraw;
- // unsigned char * strp = (unsigned char *)&(ServiceControlStatus.command10.byte[0]);
- // qDebug("%02x %02x %02x %02x %02x %02x %02x %02x",strp[0],strp[1],strp[2],strp[3],strp[4],strp[5],strp[6],strp[7]);
- xraw.set_id(0x1C4);
- xraw.set_data(byte_1C4,64);
- xraw.set_bext(false);
- xraw.set_bremote(false);
- xraw.set_len(64);
- iv::can::canraw * pxraw1C4 = xmsg.add_rawmsg();
- pxraw1C4->CopyFrom(xraw);
- // qDebug(" 0x144: %02X %02X %02X %02X %02X %02X %02X %02X",byte_144[0],byte_144[1],byte_144[2],byte_144[3],
- // byte_144[4],byte_144[5],byte_144[6],byte_144[7]);
- xmsg.set_channel(0);
- xmsg.set_index(gnIndex);
- xraw.set_id(0x24E);
- xraw.set_data(byte_24E,64);
- xraw.set_bext(false);
- xraw.set_bremote(false);
- xraw.set_len(64);
- if(nCount%2 == 1)
- {
- iv::can::canraw * pxraw24E = xmsg.add_rawmsg();
- pxraw24E->CopyFrom(xraw);
- }
- xmsg.set_channel(0);
- xmsg.set_index(gnIndex);
- // xraw.set_id(0x36E);
- // xraw.set_data(byte_36E,8);
- // xraw.set_bext(false);
- // xraw.set_bremote(false);
- // xraw.set_len(8);
- // if(nCount == 10)
- // {
- // iv::can::canraw * pxraw36E = xmsg.add_rawmsg();
- // pxraw36E->CopyFrom(xraw);
- // nCount = 0;
- // }
- // xmsg.set_channel(0);
- // xmsg.set_index(gnIndex);
- gnIndex++;
- xmsg.set_mstime(QDateTime::currentMSecsSinceEpoch());
- int ndatasize = xmsg.ByteSize();
- char * strser = new char[ndatasize];
- std::shared_ptr<char> pstrser;
- pstrser.reset(strser);
- if(xmsg.SerializeToArray(strser,ndatasize))
- {
- iv::modulecomm::ModuleSendMsg(gpacansend,strser,ndatasize);
- }
- else
- {
- std::cout<<"MainWindow::onTimer serialize error."<<std::endl;
- }
- }
- void initial()
- {
- for (uint8_t i = 0; i < 64; i++) //CAN to canfd
- {
- byte_1C4[i] = 0;
- byte_24E[i] = 0;
- //byte_36E[i] = 0;
- }
- }
- void sendthread()
- {
- initial();
- iv::brain::decition xdecition;
- UnAcitvate();
- // UnAcitvate();
- int nstate = 0; //0 Un 1 Activate
- // Activate();
- while(gbSendRun)
- {
- if(gnDecitionNum <= 0)
- {
- if(nstate == 1)
- {
- UnAcitvate();
- nstate = 0;
- }
- xdecition.CopyFrom(gdecition_def);
- }
- else
- {
- if(nstate == 0)
- {
- Activate();
- nstate = 1;
- }
- gMutex.lock();
- xdecition.CopyFrom(gdecition);
- gMutex.unlock();
- gnDecitionNum--;
- }
- executeDecition(xdecition);
- if(gbChassisEPS == false) ExecSend();
- std::this_thread::sleep_for(std::chrono::milliseconds(10));
- }
- }
- int main(int argc, char *argv[])
- {
- RegisterIVBackTrace();
- showversion("controller_changan_shenlan");
- QCoreApplication a(argc, argv);
- QString strpath = QCoreApplication::applicationDirPath();
- if(argc < 2)
- strpath = strpath + "/controller_changan_shenlan.xml";
- else
- strpath = argv[1];
- std::cout<<strpath.toStdString()<<std::endl;
- // gdecition_def.set_accelerator(-0.5);
- gdecition_def.set_brake(0);
- gdecition_def.set_rightlamp(false);
- gdecition_def.set_leftlamp(false);
- gdecition_def.set_wheelangle(0);
- gdecition_def.set_angle_mode(0);
- gdecition_def.set_angle_active(0);
- gdecition_def.set_acc_active(0);
- // gdecition_def.set_brake_active(1);
- gdecition_def.set_brake_type(0);
- gdecition_def.set_auto_mode(0);
- // gdecition_def.set_angle_mode(0);
- // gdecition_def.set_angle_active(0);
- // gdecition_def.set_acc_active(0);
- // gdecition_def.set_brake_active(0);
- // gdecition_def.set_brake_type(0);
- // gdecition_def.set_auto_mode(0);
- gTime.start();
- gcontroller = boost::shared_ptr<iv::control::Controller>(new iv::control::Controller());
- iv::xmlparam::Xmlparam xp(strpath.toStdString());
- gstrmemcansend = xp.GetParam("cansend","cansend0");
- gstrmemdecition = xp.GetParam("dection","deciton");
- gstrmemchassis = xp.GetParam("chassismsgname","chassis");
- gpacansend = iv::modulecomm::RegisterSend(gstrmemcansend.data(),10000,1);
- 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();
- }
|