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 #ifndef XMLPRINTER_HPP_
00044 #define XMLPRINTER_HPP_
00045
00046 #include <labust_mission/labustMission.hpp>
00047 #include <tinyxml2.h>
00048
00049 using namespace tinyxml2;
00050 using namespace std;
00051
00052 namespace labust{
00053 namespace utils {
00054
00055
00056
00057
00058
00059 class WriteXML{
00060
00061 public:
00062
00063
00064
00065
00066
00067 WriteXML();
00068
00069 void addMission();
00070
00071 void addEvent();
00072
00073 void saveXML(string fileName);
00074
00075 void addXMLNode(XMLNode* parentNode, string nodeName, string attrName, string attrValue, double value);
00076
00077 void addGo2point_FA(double north, double east, double speed, double victoryRadius);
00078
00079 void addGo2point_UA(double north, double east, double speed, double victoryRadius);
00080
00081 void addDynamic_positioning(double north, double east, double heading);
00082
00083 void addCourse_keeping_FA(double course, double speed, double heading);
00084
00085 void addCourse_keeping_UA(double course, double speed);
00086
00087
00088
00089
00090
00091
00092 XMLDocument doc;
00093
00094 XMLNode *mission;
00095 XMLNode *main;
00096 XMLNode *primitive;
00097 XMLNode *param;
00098 XMLNode *idNode;
00099 XMLNode *events;
00100
00101 int id;
00102
00103 };
00104
00105 WriteXML::WriteXML():id(0){
00106
00107 }
00108
00109 void WriteXML::addMission(){
00110 main = doc.NewElement("main");
00111 mission = doc.NewElement("mission");
00112 doc.InsertEndChild(main);
00113 main->InsertEndChild(mission);
00114 id = 0;
00115 }
00116
00117 void WriteXML::addEvent(){
00118
00119 events = doc.NewElement("events");
00120 doc.InsertEndChild(events);
00121 }
00122
00123 void WriteXML::saveXML(string fileName){
00124
00125 doc.SaveFile( fileName.c_str() );
00126 doc.Clear();
00127 ROS_ERROR("Mission generated.");
00128 }
00129
00130
00131 void WriteXML::addXMLNode(XMLNode* parentNode, string nodeName, string attrName, string attrValue, double value){
00132
00133 XMLNode *node;
00134 string text;
00135 node = doc.NewElement(nodeName.c_str());
00136 if(attrName.empty() == 0)
00137 node->ToElement()->SetAttribute(attrName.c_str(),attrValue.c_str());
00138
00139 text.assign(static_cast<ostringstream*>( &(ostringstream() << value) )->str());
00140 node->InsertEndChild(doc.NewText(text.c_str()));
00141 parentNode->InsertEndChild(node);
00142 }
00143
00144 void WriteXML::addGo2point_UA(double north, double east, double speed, double victoryRadius){
00145
00146 id++;
00147
00148 primitive = doc.NewElement("primitive");
00149 primitive->ToElement()->SetAttribute("name","go2point_UA");
00150
00151 addXMLNode(primitive,"id","","",id);
00152
00153 addXMLNode(primitive,"param","name","north",north);
00154 addXMLNode(primitive,"param","name","east",east);
00155 addXMLNode(primitive,"param","name","speed",speed);
00156 addXMLNode(primitive,"param","name","victory_radius",victoryRadius);
00157
00158 mission->InsertEndChild(primitive);
00159 }
00160
00161 void WriteXML::addGo2point_FA(double north, double east, double speed, double victoryRadius){
00162
00163 id++;
00164
00165 primitive = doc.NewElement("primitive");
00166 primitive->ToElement()->SetAttribute("name","go2point_FA");
00167
00168 addXMLNode(primitive,"id","","",id);
00169
00170 addXMLNode(primitive,"param","name","north",north);
00171 addXMLNode(primitive,"param","name","east",east);
00172
00173 addXMLNode(primitive,"param","name","speed",speed);
00174 addXMLNode(primitive,"param","name","victory_radius",victoryRadius);
00175
00176 mission->InsertEndChild(primitive);
00177 }
00178
00179 void WriteXML::addDynamic_positioning(double north, double east, double heading){
00180
00181 id++;
00182
00183 primitive = doc.NewElement("primitive");
00184 primitive->ToElement()->SetAttribute("name","dynamic_positioning");
00185
00186 addXMLNode(primitive,"id","","",id);
00187
00188 addXMLNode(primitive,"param","name","north",north);
00189 addXMLNode(primitive,"param","name","east",east);
00190 addXMLNode(primitive,"param","name","heading",heading);
00191 addXMLNode(primitive,"param","name","timeout",0);
00192
00193 mission->InsertEndChild(primitive);
00194 }
00195
00196 void WriteXML::addCourse_keeping_FA(double course, double speed, double heading){
00197
00198 id++;
00199
00200 primitive = doc.NewElement("primitive");
00201 primitive->ToElement()->SetAttribute("name","course_keeping_FA");
00202
00203 addXMLNode(primitive,"id","","",id);
00204
00205 addXMLNode(primitive,"param","name","course",course);
00206 addXMLNode(primitive,"param","name","speed",speed);
00207 addXMLNode(primitive,"param","name","heading",heading);
00208 addXMLNode(primitive,"param","name","timeout",10);
00209
00210 mission->InsertEndChild(primitive);
00211 }
00212
00213 void WriteXML::addCourse_keeping_UA(double course, double speed){
00214
00215 id++;
00216
00217 primitive = doc.NewElement("primitive");
00218 primitive->ToElement()->SetAttribute("name","course_keeping_UA");
00219
00220 addXMLNode(primitive,"id","","",id);
00221
00222 addXMLNode(primitive,"param","name","course",course);
00223 addXMLNode(primitive,"param","name","speed",speed);
00224 addXMLNode(primitive,"param","name","timeout",10);
00225
00226 mission->InsertEndChild(primitive);
00227 }
00228 }
00229 }
00230
00231 #endif