|
@@ -5,8 +5,24 @@
|
|
|
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);
|
|
|
+ // 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",[this](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;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(xchassis.has_vel())
|
|
|
+ {
|
|
|
+ mfNowSpeed = xchassis.vel();
|
|
|
+ mnLastChassisUpdateTime = std::chrono::system_clock::now().time_since_epoch().count();
|
|
|
+ }
|
|
|
+
|
|
|
+ (void)index;(void)dt;(void)strmemname;
|
|
|
+ });
|
|
|
|
|
|
mpadecision = iv::modulecomm::RegisterSend("deciton",1000,1);
|
|
|
|
|
@@ -22,24 +38,30 @@ decisionspeedlimit::~decisionspeedlimit(){
|
|
|
}
|
|
|
|
|
|
|
|
|
-void decisionspeedlimit::ListenChassis(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname){
|
|
|
+//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;
|
|
|
- }
|
|
|
+// 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();
|
|
|
+// mmutexchassis.lock();
|
|
|
+// mnLastChassisUpdateTime = std::chrono::system_clock::now().time_since_epoch().count();
|
|
|
+// mchassis.CopyFrom(xchassis);
|
|
|
+// if(mchassis.has_vel())
|
|
|
+// {
|
|
|
+// mfNowSpeed = mchassis.vel();
|
|
|
+// }
|
|
|
+// mmutexchassis.unlock();
|
|
|
|
|
|
- (void)index;
|
|
|
- (void)dt;
|
|
|
- (void)strmemname;
|
|
|
-}
|
|
|
+
|
|
|
+
|
|
|
+// (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;
|
|
@@ -60,31 +82,32 @@ void decisionspeedlimit::ListenDecsionSpeedLimit(const char * strdata,const unsi
|
|
|
|
|
|
|
|
|
|
|
|
- iv::chassis xchassis;
|
|
|
- int64_t nlastchassis = 0;
|
|
|
- mmutexchassis.lock();
|
|
|
- xchassis.CopyFrom(xchassis);
|
|
|
- nlastchassis = mnLastChassisUpdateTime;
|
|
|
- mmutexchassis.unlock();
|
|
|
+// 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)
|
|
|
+ if(mnLastChassisUpdateTime == 0)
|
|
|
{
|
|
|
ftorque = 0;
|
|
|
std::cout<<nnow<<" no chassis message, limit torque to zero."<<std::endl;
|
|
|
}
|
|
|
- if(abs(nnow - nlastchassis) > 1e9)
|
|
|
+ if(abs(nnow - mnLastChassisUpdateTime) > 1e9)
|
|
|
{
|
|
|
ftorque = 0;
|
|
|
std::cout<<nnow<<" no chassis message more than 1 second, limit torque to zero."<<std::endl;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- if(xchassis.vel() > mfspeedlimit)
|
|
|
+ if(mfNowSpeed > mfspeedlimit)
|
|
|
{
|
|
|
ftorque = 0;
|
|
|
+ std::cout<<std::chrono::system_clock::now().time_since_epoch().count()<<" Now Speed: "<<mfNowSpeed<<std::endl;
|
|
|
std::cout<<" speed more than "<<mfspeedlimit<<" ,so limit torque to zero."<<std::endl;
|
|
|
}
|
|
|
}
|