MOOS 0.2375
|
00001 #include "VariableHeadingTask.h" 00002 00003 #define SETPOINT_TIMEOUT 5.0 00004 00005 CVariableHeadingTask::CVariableHeadingTask(void) 00006 { 00007 m_YawDOF.SetDesired(0); 00008 m_dfThrust = 0; 00009 00010 m_SetPointTimes["DESIRED_YAW"] = -1.0; 00011 m_SetPointTimes["DESIRED_THRUST"] = -1.0; 00012 00013 } 00014 00015 CVariableHeadingTask::~CVariableHeadingTask(void) 00016 { 00017 } 00018 00019 00020 bool CVariableHeadingTask::OnNewMail(MOOSMSG_LIST &NewMail) 00021 { 00022 00023 CMOOSMsg Msg; 00024 if(PeekMail(NewMail,"VARIABLE_YAW",Msg)) 00025 { 00026 if(!Msg.IsSkewed(GetTimeNow())) 00027 { 00028 m_YawDOF.SetDesired(Msg.GetDouble()); 00029 m_SetPointTimes[Msg.GetKey()] = Msg.GetTime(); 00030 } 00031 } 00032 00033 00034 if(PeekMail(NewMail,"VARIABLE_THRUST",Msg)) 00035 { 00036 if(!Msg.IsSkewed(GetTimeNow())) 00037 { 00038 m_dfThrust = Msg.GetDouble(); 00039 m_SetPointTimes[Msg.GetKey()] = Msg.GetTime(); 00040 m_bThrustSet = true; 00041 } 00042 } 00043 00044 return BASE::OnNewMail(NewMail); 00045 00046 } 00047 bool CVariableHeadingTask::Run(CPathAction &DesiredAction) 00048 { 00049 return BASE::Run(DesiredAction); 00050 } 00051 00052 bool CVariableHeadingTask::GetRegistrations(STRING_LIST &List) 00053 { 00054 List.push_back("VARIABLE_YAW"); 00055 List.push_back("VARIABLE_THRUST"); 00056 00057 return BASE::GetRegistrations(List); 00058 } 00059 bool CVariableHeadingTask::RegularMailDelivery(double dfTimeNow) 00060 { 00061 std::map<std::string,double>::iterator q; 00062 00063 for(q = m_SetPointTimes.begin();q!=m_SetPointTimes.end();q++) 00064 { 00065 double dfLastMail = q->second; 00066 00067 //case 1: No mail at all... 00068 if(dfLastMail ==-1 && (dfTimeNow-GetStartTime() > SETPOINT_TIMEOUT)) 00069 return MOOSFail("No %s setpoints received for %f seconds",q->first.c_str(),SETPOINT_TIMEOUT); 00070 00071 //case 2: Had mail but it has stopped.. 00072 if(dfLastMail>0 && dfTimeNow-dfLastMail>SETPOINT_TIMEOUT) 00073 return MOOSFail("No %s setpoints received for %f seconds",q->first.c_str(),SETPOINT_TIMEOUT); 00074 } 00075 00076 return BASE::RegularMailDelivery(dfTimeNow); 00077 } 00078