Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #include<labust_mission/labustMission.hpp>
00044 #include<labust_mission/dataManager.hpp>
00045 #include<labust_mission/eventEvaluation.hpp>
00046
00047
00048
00049
00050
00051 class DataEventManager{
00052
00053 public:
00054 DataEventManager():missionLoaded(false){
00055
00056 ros::NodeHandle nh;
00057
00059 subStateHatAbs = nh.subscribe<auv_msgs::NavSts>("stateHatAbs",1,&DataEventManager::onStateHat,this);
00060 subMissionSetup = nh.subscribe<misc_msgs::MissionSetup>("missionSetup",1,&DataEventManager::onMissionSetup,this);
00061 subExternalEvents= nh.subscribe<misc_msgs::ExternalEvent>("externalEvent",1, &DataEventManager::onExternalEvent, this);
00062 subEventString = nh.subscribe<std_msgs::String>("eventString",1, &DataEventManager::onEventString, this);
00063
00065 pubDataEventsContainer = nh.advertise<misc_msgs::DataEventsContainer>("dataEventsContainer",1);
00066
00068 srvEvaluateExpression = nh.advertiseService("evaluate_expression", &DataEventManager::expressionEvaluationService,this);
00069 }
00070
00072 void onStateHat(const auv_msgs::NavSts::ConstPtr& data){
00073
00075 DM.updateStateVar(data);
00076
00077 if(missionLoaded){
00079 EE.updateSymbolTable(DM.getStateVar(),DM.getMissionVar(),DM.getMissionVarNames());
00080 DM.updateEventsVar(EE.evaluateEvents(eventsContainer));
00081
00083 publishDataEvent(DM.getStateVar(), DM.getMissionVar(), DM.getEventsVar());
00084 }
00085 }
00086
00088 void publishDataEvent(vector<double> stateVar, vector<double> missionVar, vector<uint8_t> eventsVar){
00089
00090 misc_msgs::DataEventsContainer dataEventsContainer;
00091 dataEventsContainer.stateVar.data = stateVar;
00092 dataEventsContainer.eventsVar = eventsVar;
00093 dataEventsContainer.missionVar.data = missionVar;
00094
00095 pubDataEventsContainer.publish(dataEventsContainer);
00096 }
00097
00099 void onExternalEvent(const misc_msgs::ExternalEvent::ConstPtr& data){
00100
00101 if((data->id > 0) && (data->id <= DM.getMissionVar().size()))
00102 DM.updateMissionVar(data->id, data->value);
00103 }
00104
00106 void onMissionSetup(const misc_msgs::MissionSetup::ConstPtr& data){
00107
00108 parseMissionParam(data->missionParams.c_str());
00109 parseMissionEvents(data->missionEvents.c_str());
00110
00112 EE.initializeSymbolTable(DM.getStateVar(), DM.getMissionVar(), DM.getMissionVarNames());
00113
00114 ROS_ERROR("Mission successfully loaded");
00115 missionLoaded = true;
00116 }
00117
00118 void onEventString(const std_msgs::String::ConstPtr& msg){
00119
00120 ROS_INFO("EventString: %s",msg->data.c_str());
00121 if(strcmp(msg->data.c_str(),"/STOP") == 0){
00122 missionLoaded = false;
00123 DM.reset();
00124 EE.resetSymbolTable();
00125 }
00126 }
00127
00129 bool expressionEvaluationService(misc_msgs::EvaluateExpression::Request &req, misc_msgs::EvaluateExpression::Response &res){
00130
00131 res.result = EE.evaluateStringExpression(req.expression);
00132 return true;
00133 }
00134
00135
00136
00137
00138
00140 void parseMissionParam(string missionParamString){
00141
00142 if(missionParamString.empty() == 0){
00143
00144 vector<string> tmp;
00145 tmp = labust::utilities::split(missionParamString.c_str(), ':');
00146
00147 for(vector<string>::iterator it = tmp.begin(); it != tmp.end(); it=it+2){
00148
00149 DM.setMissionVarNames((*(it)).c_str());
00150 DM.setMissionVar(atof((*(it+1)).c_str()));
00151 }
00152 }
00153 }
00154
00156 void parseMissionEvents(string missionEventsString){
00157
00158 if(missionEventsString.empty() == 0){
00159 eventsContainer = labust::utilities::split(missionEventsString.c_str(), ':');
00160 vector<uint8_t> tmp(eventsContainer.size(),0);
00161 DM.updateEventsVar(tmp);
00162 }
00163 }
00164
00165
00166
00167
00168
00169 private:
00170
00172 labust::data::DataManager DM;
00173
00175 labust::event::EventEvaluation EE;
00176
00178 ros::Subscriber subStateHatAbs, subMissionSetup, subExternalEvents, subEventString;
00179
00181 ros::Publisher pubDataEvent, pubDataEventsContainer;
00182
00184 ros::ServiceServer srvEvaluateExpression;
00185
00187 vector<string> eventsContainer;
00188
00190 bool missionLoaded;
00191 };
00192
00193
00194
00195
00196
00197 int main(int argc, char **argv){
00198
00199 ros::init(argc, argv, "data_event_manager");
00200 ros::NodeHandle nh;
00201 DataEventManager DEM;
00202 ros::spin();
00203 return 0;
00204 }
00205
00206