00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifdef HAVE_CONFIG_H
00014 #include <config.h>
00015 #endif
00016
00017 #ifndef CONFIGXMLPARSER_H_
00018 #define CONFIGXMLPARSER_H_
00019
00020 #include "SimulatedDevices.h"
00021 #include <libxml++/libxml++.h>
00022 #include <urdf/model.h>
00023
00024 #include <iostream>
00025 using namespace std;
00026 #include <cstdlib>
00027 #include <list>
00028
00029 struct ROSInterfaceInfo
00030 {
00031 typedef enum
00032 {
00033 Unknown, ROSOdomToPAT, PATToROSOdom, ROSJointStateToArm, ArmToROSJointState, VirtualCameraToROSImage,
00034 RangeSensorToROSRange, ROSImageToHUD, ROSTwistToPAT, ROSPoseToPAT, ImuToROSImu, PressureSensorToROS, GPSSensorToROS,
00035 DVLSensorToROS, RangeImageSensorToROSImage, multibeamSensorToLaserScan, SimulatedDevice, contactSensorToROS, WorldToROSTF,
00036 ROSPointCloudLoader
00037 } type_t;
00038 string subtype;
00039 std::map<std::string, std::string> values;
00040 string topic, infoTopic, targetName, rootName;
00041 type_t type;
00042 int rate;
00043 unsigned int w, h;
00044 unsigned int posx, posy, depth, blackWhite, enableObjects;
00045 double scale;
00046 bool del;
00047 };
00048
00049 struct Parameters
00050 {
00051 double fx, fy, x0, y0, f, n, k;
00052 };
00053
00054 struct Vcam
00055 {
00056 string name;
00057 string linkName, roscam, roscaminfo;
00058 std::string frameId;
00059 int resw, resh, link, range, bw;
00060 double showpath;
00061 double position[3], orientation[3];
00062 double baseLine;
00063 double fov;
00064 double std;
00065 boost::shared_ptr<Parameters> parameters;
00066 void init()
00067 {
00068 name = "";
00069 linkName = "";
00070 roscam = "";
00071 roscaminfo = "";
00072 resw = 160;
00073 resh = 120;
00074 position[0] = 0;
00075 position[1] = 0;
00076 position[2] = 0;
00077 orientation[0] = 0;
00078 orientation[1] = 0;
00079 orientation[2] = 0;
00080 baseLine = 0.0;
00081 frameId = "";
00082 showpath = 0;
00083 parameters.reset();
00084 range = 0;
00085 bw = 0;
00086 fov=50;
00087 std=0.005;
00088 }
00089 };
00090
00091 struct slProjector
00092 {
00093 string name;
00094 string linkName;
00095 string image_name;
00096 double position[3], orientation[3];
00097 double fov;
00098 int laser;
00099 int link;
00100 void init()
00101 {
00102 name = "";
00103 linkName = "";
00104 image_name = "";
00105 position[0] = 0;
00106 position[1] = 0;
00107 position[2] = 0;
00108 orientation[0] = 0;
00109 orientation[1] = 0;
00110 orientation[2] = 0;
00111 fov = 0;
00112 laser = 1;
00113 }
00114 };
00115
00116 struct rangeSensor
00117 {
00118 string name;
00119 string linkName;
00120 double position[3], orientation[3];
00121 double range;
00122 int visible;
00123 int link;
00124 void init()
00125 {
00126 name = "";
00127 linkName = "";
00128 position[0] = 0;
00129 position[1] = 0;
00130 position[2] = 0;
00131 orientation[0] = 0;
00132 orientation[1] = 0;
00133 orientation[2] = 0;
00134 range = 0;
00135 visible = 0;
00136 }
00137 };
00138
00139 struct Imu
00140 {
00141 string name;
00142 string linkName;
00143 double std;
00144 double position[3], orientation[3];
00145 int link;
00146 void init()
00147 {
00148 name = "";
00149 linkName = "";
00150 std = 0.0;
00151 position[0] = 0;
00152 position[1] = 0;
00153 position[2] = 0;
00154 orientation[0] = 0;
00155 orientation[1] = 0;
00156 orientation[2] = 0;
00157 }
00158 };
00159
00160 struct XMLPressureSensor
00161 {
00162 string name;
00163 string linkName;
00164 double std;
00165 double position[3], orientation[3];
00166 int link;
00167 void init()
00168 {
00169 name = "";
00170 linkName = "";
00171 std = 0.0;
00172 position[0] = 0;
00173 position[1] = 0;
00174 position[2] = 0;
00175 orientation[0] = 0;
00176 orientation[1] = 0;
00177 orientation[2] = 0;
00178 }
00179 };
00180
00181 struct XMLGPSSensor
00182 {
00183 string name;
00184 string linkName;
00185 double std;
00186 double position[3], orientation[3];
00187 int link;
00188 void init()
00189 {
00190 name = "";
00191 linkName = "";
00192 std = 0.0;
00193 position[0] = 0;
00194 position[1] = 0;
00195 position[2] = 0;
00196 orientation[0] = 0;
00197 orientation[1] = 0;
00198 orientation[2] = 0;
00199 }
00200 };
00201
00202 struct XMLDVLSensor
00203 {
00204 string name;
00205 string linkName;
00206 double std;
00207 double position[3], orientation[3];
00208 int link;
00209 void init()
00210 {
00211 name = "";
00212 linkName = "";
00213 std = 0.0;
00214 position[0] = 0;
00215 position[1] = 0;
00216 position[2] = 0;
00217 orientation[0] = 0;
00218 orientation[1] = 0;
00219 orientation[2] = 0;
00220 }
00221 };
00222
00223 struct XMLMultibeamSensor
00224 {
00225 string name;
00226 string linkName;
00227 double position[3], orientation[3];
00228 int link;
00229 int visible;
00230 double initAngle, finalAngle, angleIncr, range;
00231 bool underwaterParticles;
00232 void init()
00233 {
00234 name = "";
00235 linkName = "";
00236 position[0] = 0;
00237 position[1] = 0;
00238 position[2] = 0;
00239 orientation[0] = 0;
00240 orientation[1] = 0;
00241 orientation[2] = 0;
00242 underwaterParticles=false;
00243 visible = 0;
00244 }
00245 };
00246
00247 struct Mimic
00248 {
00249 string jointName;
00250 double offset, multiplier;
00251 };
00252
00253 struct Geometry
00254 {
00255 int type;
00256 double boxSize[3];
00257 double length, radius;
00258 string file;
00259 double scale[3];
00260 };
00261
00262 struct Link
00263 {
00264 string name;
00265 double position[3];
00266 double rpy[3];
00267 double quat[4];
00268 std::string material;
00269 boost::shared_ptr<Geometry> cs, geom;
00270 double mass;
00271 };
00272
00273 struct Joint
00274 {
00275 string name;
00276 int parent, child;
00277 int mimicp, type;
00278 float lowLimit, upLimit;
00279 boost::shared_ptr<Mimic> mimic;
00280 double position[3];
00281 double rpy[3];
00282 double axis[3];
00283 double quat[4];
00284 };
00285
00286 struct Material
00287 {
00288 string name;
00289 double r, g, b, a;
00290 };
00291
00292 struct Vehicle
00293 {
00294 string name;
00295 std::vector<Link> links;
00296 std::vector<Joint> joints;
00297 int nlinks;
00298 int njoints;
00299 int ninitJoints;
00300 double position[3];
00301 double orientation[3];
00302 double scale[3];
00303 std::vector<double> jointValues;
00304 std::map<std::string, Material> materials;
00305 std::list<Vcam> Vcams;
00306 std::list<Vcam> VRangecams;
00307 std::list<slProjector> sls_projectors;
00308 std::list<rangeSensor> range_sensors, object_pickers;
00309 std::list<Imu> imus;
00310 std::list<XMLPressureSensor> pressure_sensors;
00311 std::list<XMLGPSSensor> gps_sensors;
00312 std::list<XMLDVLSensor> dvl_sensors;
00313 std::list<XMLMultibeamSensor> multibeam_sensors;
00314 std::vector<uwsim::SimulatedDeviceConfig::Ptr> simulated_devices;
00315 std::string URDFFile;
00316 };
00317
00318 struct PhysicProperties
00319 {
00320 double mass;
00321 double inertia[3];
00322 double linearDamping;
00323 double angularDamping;
00324 double minLinearLimit[3];
00325 double maxLinearLimit[3];
00326 double minAngularLimit[3];
00327 double maxAngularLimit[3];
00328 int isKinematic;
00329 std::string csType, cs;
00330 void init()
00331 {
00332 mass = 1;
00333 inertia[0] = 0;
00334 inertia[1] = 0;
00335 inertia[2] = 0;
00336 csType = "box";
00337 cs = "";
00338 linearDamping = 0;
00339 angularDamping = 0;
00340 minLinearLimit[0] = 1;
00341 minLinearLimit[1] = 1;
00342 minLinearLimit[2] = 1;
00343 maxLinearLimit[0] = 0;
00344 maxLinearLimit[1] = 0;
00345 maxLinearLimit[2] = 0;
00346 isKinematic = 0;
00347 minAngularLimit[0] = 1;
00348 minAngularLimit[1] = 1;
00349 minAngularLimit[2] = 1;
00350 maxAngularLimit[0] = 0;
00351 maxAngularLimit[1] = 0;
00352 maxAngularLimit[2] = 0;
00353 }
00354 ;
00355 };
00356
00357 struct Object
00358 {
00359 string name, file;
00360 double position[3];
00361 double orientation[3];
00362 double scale[3];
00363 double offsetp[3];
00364 double offsetr[3];
00365 double buried;
00366 boost::shared_ptr<PhysicProperties> physicProperties;
00367 };
00368
00369 struct ShowTrajectory
00370 {
00371 std::string target;
00372 double color[3];
00373 int lineStyle;
00374 double timeWindow;
00375 void init()
00376 {
00377 target="";
00378 color[0]= 1; color[1]= 0; color[2] = 0;
00379 lineStyle=1;
00380 timeWindow=-1;
00381 }
00382 };
00383
00384 struct PhysicsConfig
00385 {
00386 typedef enum
00387 {
00388 Dantzig,SolveProjectedGauss,SequentialImpulse
00389 } solver_type;
00390 double gravity[3];
00391 double frequency;
00392 int subSteps;
00393 solver_type solver;
00394
00395 void init()
00396 {
00397 memset(gravity, 0, 3 * sizeof(double));
00398 frequency = 60;
00399 subSteps = 0;
00400 solver=Dantzig;
00401 }
00402
00403 };
00404
00405 class ConfigFile
00406 {
00407 public:
00408
00409
00410 void esPi(string in, double ¶m);
00411
00412 void extractFloatChar(const xmlpp::Node* node, double ¶m);
00413 void extractIntChar(const xmlpp::Node* node, int ¶m);
00414 void extractUIntChar(const xmlpp::Node* node, unsigned int ¶m);
00415 void extractStringChar(const xmlpp::Node* node, string ¶m);
00416 void extractPositionOrColor(const xmlpp::Node* node, double param[3]);
00417 void extractOrientation(const xmlpp::Node* node, double param[3]);
00418
00419 void processFog(const xmlpp::Node* node);
00420 void processOceanState(const xmlpp::Node* node);
00421 void processSimParams(const xmlpp::Node* node);
00422 void processShowTrajectory(const xmlpp::Node* node, ShowTrajectory & trajectory);
00423 void processParameters(const xmlpp::Node*, Parameters *params);
00424 void processVcam(const xmlpp::Node* node, Vcam &vcam);
00425 void processSLProjector(const xmlpp::Node* node, slProjector &slp);
00426 void processRangeSensor(const xmlpp::Node* node, rangeSensor &rs);
00427 void processImu(const xmlpp::Node* node, Imu &rs);
00428 void processPressureSensor(const xmlpp::Node* node, XMLPressureSensor &ps);
00429 void processDVLSensor(const xmlpp::Node* node, XMLDVLSensor &s);
00430 void processGPSSensor(const xmlpp::Node* node, XMLGPSSensor &s);
00431 void processMultibeamSensor(const xmlpp::Node* node, XMLMultibeamSensor &s);
00432 void processCamera(const xmlpp::Node* node);
00433 void processJointValues(const xmlpp::Node* node, std::vector<double> &jointValues, int &ninitJoints);
00434 void processVehicle(const xmlpp::Node* node, Vehicle &vehicle);
00435 void processPhysicProperties(const xmlpp::Node* node, PhysicProperties &pp);
00436 void processObject(const xmlpp::Node* node, Object &object);
00437 void processROSInterface(const xmlpp::Node* node, ROSInterfaceInfo &rosInterface);
00438 void processROSInterfaces(const xmlpp::Node* node);
00439 void processXML(const xmlpp::Node* node);
00440
00441 void processGeometry(urdf::Geometry * geometry, Geometry * geom);
00442 void processPose(urdf::Pose pose, double position[3], double rpy[3], double quat[4]);
00443 void processVisual(boost::shared_ptr<const urdf::Visual> visual, Link &link,
00444 std::map<std::string, Material> &materials);
00445 void processJoint(boost::shared_ptr<const urdf::Joint> joint, Joint &jointVehicle, int parentLink, int childLink);
00446 int processLink(boost::shared_ptr<const urdf::Link> link, Vehicle &vehicle, int nlink, int njoint,
00447 std::map<std::string, Material> &materials);
00448 int processURDFFile(string file, Vehicle &vehicle);
00449
00450 void postprocessVehicle(Vehicle &vehicle);
00451
00452 public:
00453 double windx, windy, windSpeed, depth, reflectionDamping, waveScale, choppyFactor, crestFoamHeight,
00454 oceanSurfaceHeight, fogDensity, lightRate;
00455 int isNotChoppy, disableShaders, eye_in_hand, freeMotion, resw, resh, enablePhysics;
00456 string arm, vehicleToTrack;
00457 double camPosition[3], camLookAt[3], fogColor[3], color[3], attenuation[3], offsetr[3], offsetp[3];
00458 double camFov, camAspectRatio, camNear, camFar;
00459 list<Vehicle> vehicles;
00460 list<Object> objects;
00461 list<ROSInterfaceInfo> ROSInterfaces;
00462 list<ROSInterfaceInfo> ROSPhysInterfaces;
00463 list<ShowTrajectory> trajectories;
00464 PhysicsConfig physicsConfig;
00465
00466
00467 ConfigFile(const std::string &fName);
00468 };
00469
00470 #endif