Privacy
An open-source, flexible 3D physical simulation framework
smurf.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2011, 2012, 2014, DFKI GmbH Robotics Innovation Center
3  *
4  * This file is part of the MARS simulation framework.
5  *
6  * MARS is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License
8  * as published by the Free Software Foundation, either version 3
9  * of the License, or (at your option) any later version.
10  *
11  * MARS is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with MARS. If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 #include "smurf.h"
22 
23 #include <mars/data_broker/DataBrokerInterface.h>
24 
25 #include <mars/interfaces/sim/EntityManagerInterface.h>
26 #include <mars/interfaces/sim/SimulatorInterface.h>
27 #include <mars/interfaces/sim/NodeManagerInterface.h>
28 #include <mars/interfaces/sim/JointManagerInterface.h>
29 #include <mars/interfaces/sim/SensorManagerInterface.h>
30 #include <mars/interfaces/sim/MotorManagerInterface.h>
31 #include <mars/interfaces/sim/ControllerManagerInterface.h>
32 #include <mars/interfaces/graphics/GraphicsManagerInterface.h>
33 #include <mars/sim/SimEntity.h>
34 #include <mars/sim/SimMotor.h>
35 #include <mars/entity_generation/entity_factory/EntityFactoryManager.h>
36 #include <mars/interfaces/Logging.hpp>
37 
38 #include <mars/utils/misc.h>
39 #include <mars/utils/mathUtils.h>
40 #include <smurf_parser/SMURFParser.h>
41 
42 //#define DEBUG_PARSE_SENSOR 1
43 //#define DEBUG_SCENE_MAP
44 
45 /*
46  * remarks:
47  *
48  * - we need some special handling because the representation
49  * in MARS is different then in URDF with is marked in the source with:
50  * ** special case handling **
51  *
52  * - if we load and save a file we might lose names of
53  * collision and visual objects
54  *
55  */
56 
57 namespace mars {
58  namespace smurf {
59 
60  using namespace std;
61  using namespace interfaces;
62  using namespace utils;
63  using namespace configmaps;
64 
65  SMURF::SMURF(lib_manager::LibManager *theManager): MarsPluginTemplate(theManager, "SMURF"),
66  entity_generation::EntityFactoryInterface("smurf, urdf") {
69  "mars_entity_factory");
70  factoryManager->registerFactory("smurf", this);
71  factoryManager->registerFactory("urdf", this);
72  factoryManager->registerFactory("particle", this); // At the moment particles are smurfs with instancing
73  theManager->releaseLibrary("mars_entity_factory");
74  }
75 
77  }
78 
79  void SMURF::init() {
81 
82  reset();
83  }
84 
85  void SMURF::reset() {
87  nextNodeID = 1;
88  nextJointID = 1;
89  nextMaterialID = 1;
90  nextMotorID = 1;
91  nextSensorID = 1;
92  nextControllerID = 1;
93  // TODO: this needs checking for potential doubling (see above nextGroupID)
95 
96  nodeList.clear();
97  jointList.clear();
98  motorList.clear();
99  sensorList.clear();
100  controllerList.clear();
101  materialList.clear();
102  lightList.clear();
103  graphicList.clear();
104 
105  linkIDMap.clear();
106  nodeIDMap.clear();
107  jointIDMap.clear();
108  sensorIDMap.clear();
109  motorIDMap.clear();
110  materialMap.clear();
111  collisionNameMap.clear();
112  visualNameMap.clear();
113 
114  robotname = "";
115  model.reset();
116 
117  entity = NULL;
118  entityconfig.clear();
119  debugMap.clear();
120  }
121 
122  void SMURF::update(sReal time_ms) {
123  }
124 
125  void SMURF::handleURI(ConfigMap *map, std::string uri) {
127  handleURIs(&map2);
128  map->append(map2);
129  }
130 
132  if (map->find("URI") != map->end()) {
133  std::string file = (*map)["URI"];
134  if (!file.empty() && file[0] != '/') {
135  file = tmpPath + file;
136  }
137  handleURI(map, file);
138  }
139  if (map->find("URIs") != map->end()) {
140  ConfigVector::iterator vIt = (*map)["URIs"].begin();
141  for (; vIt != (*map)["URIs"].end(); ++vIt) {
142  std::string file = (std::string) (*vIt);
143  if (!file.empty() && file[0] != '/') {
144  file = tmpPath + file;
145  }
146  handleURI(map, file);
147  }
148  }
149  }
150 
152  ConfigVector::iterator it;
153  // TODO: check if objects exist in maps
154 
155  if (map->find("link") != map->end()) {
156  (*map)["nodeID"] = nodeIDMap[(*map)["link"]];
157  }
158  if (map->find("joint") != map->end()) {
159  (*map)["jointID"] = jointIDMap[(*map)["joint"]];
160  }
161  if (map->find("links") != map->end()) {
162  for (it = (*map)["links"].begin(); it != (*map)["links"].end(); ++it) {
163  (*map)["id"] += nodeIDMap[*it];
164  }
165  }
166  if (map->find("collisions") != map->end()) {
167  for (it = (*map)["collisions"].begin();
168  it != (*map)["collisions"].end(); ++it) {
169  (*map)["id"] += nodeIDMap[*it];
170  }
171  }
172  if (map->find("joints") != map->end()) {
173  for (it = (*map)["joints"].begin(); it != (*map)["joints"].end(); ++it) {
174  (*map)["id"].push_back(jointIDMap[*it]);
175  }
176  }
177  if (map->find("motors") != map->end()) {
178  for (it = (*map)["motors"].begin(); it != (*map)["motors"].end(); ++it) {
179  (*map)["id"].push_back(motorIDMap[*it]);
180  }
181  }
182  }
183 
185  reset();
186  entityconfig = config;
187  std::string path = (std::string)entityconfig["path"];
188  tmpPath = path;
189  std::string filename = (std::string)entityconfig["file"];
190  fprintf(stderr, "SMURF::createEntity: Creating entity of type %s\n", ((std::string)entityconfig["type"]).c_str());
191  if((std::string)entityconfig["type"] == "smurf" || entityconfig["type"].getString() == "particle") {
192  model = smurf_parser::parseFile(&entityconfig, path, filename, true);
193 #ifdef DEBUG_SCENE_MAP
194  debugMap.append(entityconfig);
195 #endif
196  // TODO: we should have a system that first loads the URDF and then the other files in
197  // order of priority (or sort the contents in a way as to avoid errors upon loading).
198 
199  entity = new sim::SimEntity(control, entityconfig);
200  bool fixed = false;
201  if (entityconfig.find("parent") != entityconfig.end())
202  if ((std::string)entityconfig["parent"] == "world")
203  fixed = true;
204  createModel(fixed);
205 
207 #ifdef DEBUG_SCENE_MAP
208  entityconfig.toYamlFile("entityconfig.yml");
209 #endif
210  for (it = entityconfig.begin(); it != entityconfig.end(); ++it) {
211  fprintf(stderr, " ...loading smurf data section %s.\n", it->first.c_str());
212  ConfigMap tmpconfig;
213  tmpconfig[it->first] = it->second;
214  addConfigMap(tmpconfig);
215  }
216  } else { // if type is "urdf"
217  std::string urdfpath = path + filename;
218  fprintf(stderr, " ...loading urdf data from %s.\n", urdfpath.c_str());
219  fprintf(stderr, "parsing model...\n");
220  parseURDF(urdfpath);
221  entity = new sim::SimEntity(control, entityconfig);
222  createModel(false);
223  }
224 
225  // node mapping and name checking
226  std::string robotname = (std::string)entityconfig["name"];
227  if (robotname == "")
228  robotname = "unknown_robot";
229  entityconfig["name"] = robotname; //(std::string)entityconfig["modelname"];
230  // add finalized config to entity
231  entity->appendConfig(entityconfig);
232 
233  if(control->loadCenter->getMappedSceneByName(robotname) == 0) {
235  }
237  fprintf(stderr, "mapIndex: %d\n", mapIndex);
238 
239  load();
240 
241  return entity;
242  }
243 
245  ConfigVector::iterator it;
246  for (it = config["motors"].begin(); it != config["motors"].end(); ++it) {
247  handleURIs(*it);
248  (*it)["index"] = nextMotorID++;
249  motorIDMap[(*it)["name"]] = nextMotorID - 1;
250  (*it)["axis"] = 1;
251  (*it)["jointIndex"] = jointIDMap[(*it)["joint"]];
252  motorList.push_back(*it);
253 #ifdef DEBUG_SCENE_MAP
254  debugMap["motors"] += *it;
255 #endif
256  }
257  std::map<std::string, unsigned long> * idmap;
258  std::map<std::string, std::string> *namemap;
259  for (it = config["sensors"].begin(); it != config["sensors"].end(); ++it) {
260  handleURIs(*it);
261  ConfigMap &tmpmap = *it;
262  tmpmap["attached_node"] = (unsigned long) nodeIDMap[(std::string) tmpmap["link"]];
263  //FIXME: tmpmap["mapIndex"] = mapIndex;
264  if ((std::string) tmpmap["type"] == "Joint6DOF") {
265  std::string linkname = (std::string) tmpmap["link"];
266  fprintf(stderr, "addConfig: %s\n", linkname.c_str());
267  std::string jointname = model->getLink(linkname)->parent_joint->name;
268  fprintf(stderr, "addConfig: %s\n", jointname.c_str());
269  tmpmap["nodeID"] = nodeIDMap[linkname];
270  tmpmap["jointID"] = jointIDMap[jointname];
271  // todo: change DataPackage to compelte for joint
272  std::vector<ConfigMap>::iterator it = jointList.begin();
273  for(; it!=jointList.end(); ++it) {
274  if((NodeId)(*it)["index"] == (NodeId)tmpmap["jointID"]) {
275  (*it)["reducedDataPackage"] = false;
276  break;
277  }
278  }
279  fprintf(stderr, "creating Joint6DOF..., %lu, %lu\n", (unsigned long) tmpmap["nodeID"],
280  (unsigned long) tmpmap["jointID"]);
281  }
282  idmap = 0;
283  namemap = 0;
284  if (tmpmap.find("id") != tmpmap.end()) {
285  ConfigVector tmpids;
286  if (((std::string) tmpmap["type"]).find("Joint") != std::string::npos) {
287  idmap = &jointIDMap;
288  }
289  if (((std::string) tmpmap["type"]).find("Node") != std::string::npos) {
290  idmap = &nodeIDMap;
291  if (((std::string) tmpmap["type"]).find("Contact") != std::string::npos)
292  namemap = &collisionNameMap;
293  }
294  if (((std::string) tmpmap["type"]).find("Motor") != std::string::npos) {
295  idmap = &motorIDMap;
296  }
297  for (ConfigVector::iterator idit = tmpmap["id"].begin();
298  idit != tmpmap["id"].end(); ++idit) {
299  if (idmap) {
300  //(*idit) = (unsigned long)nodeIDMap[idit->getString()];
301  if (namemap) {
302  tmpids.append(ConfigAtom((unsigned long) (*idmap)[(*namemap)[(std::string) (*idit)]]));
303  } else {
304  tmpids += ConfigAtom((unsigned long) (*idmap)[(std::string) (*idit)]);
305  }
306  } else {
307  fprintf(stderr, "Found sensor with id list, but of no known category.\n");
308  }
309  }
310  tmpmap["id"] = tmpids;
311  }
312  tmpmap["index"] = nextSensorID++;
313  sensorIDMap[tmpmap["name"]] = nextSensorID - 1;
314  getSensorIDList(&tmpmap);
315  sensorList.push_back(tmpmap);
316 #ifdef DEBUG_SCENE_MAP
317  debugMap["sensors"] += tmpmap;
318 #endif
319  }
320  for (it = config["materials"].begin(); it != config["materials"].end(); ++it) {
321  handleURIs(*it);
322  std::vector<ConfigMap>::iterator mIt = materialList.begin();
323  for (; mIt != materialList.end(); ++mIt) {
324  if ((std::string) (*mIt)["name"] == (std::string) (*it)["name"]) {
325  mIt->append(*it);
326  break;
327  }
328  }
329  }
330  for (it = config["nodes"].begin(); it != config["nodes"].end(); ++it) {
331  handleURIs(*it);
332  std::vector<ConfigMap>::iterator nIt = nodeList.begin();
333  for (; nIt != nodeList.end(); ++nIt) {
334  if ((std::string) (*nIt)["name"] == (std::string) (*it)["name"]) {
335  ConfigMap::iterator cIt = it->beginMap();
336  for (; cIt != it->endMap(); ++cIt) {
337  (*nIt)[cIt->first] = cIt->second;
338  }
339  break;
340  }
341  }
342  }
343  for (it = config["joint"].begin(); it != config["joint"].end(); ++it) {
344  handleURIs(*it);
345  std::vector<ConfigMap>::iterator nIt = jointList.begin();
346  for (; nIt != jointList.end(); ++nIt) {
347  if ((std::string) (*nIt)["name"] == (std::string) (*it)["name"]) {
348  ConfigMap::iterator cIt = it->beginMap();
349  for (; cIt != it->endMap(); ++cIt) {
350  (*nIt)[cIt->first] = cIt->second;
351  }
352  break;
353  }
354  }
355  }
356 
357  for (it = config["visuals"].begin(); it != config["visuals"].end(); ++it) {
358  handleURIs(*it);
359  std::string cmpName = (std::string) (*it)["name"];
360  std::vector<ConfigMap>::iterator nIt = nodeList.begin();
361  if (visualNameMap.find(cmpName) != visualNameMap.end()) {
362  cmpName = visualNameMap[cmpName];
363  for (; nIt != nodeList.end(); ++nIt) {
364  if ((std::string) (*nIt)["name"] == cmpName) {
365  ConfigMap::iterator cIt = it->beginMap();
366  for (; cIt != it->endMap(); ++cIt) {
367  if (cIt->first != "name") {
368  (*nIt)[cIt->first] = cIt->second;
369  }
370  }
371  break;
372  }
373  }
374  }
375  else
376  fprintf(stderr, "visual: couldn't find %s\n", cmpName.c_str());
377  }
378 
379  for (it = config["collision"].begin(); it != config["collision"].end(); ++it) {
380  handleURIs(*it);
381  std::string cmpName = (std::string) (*it)["name"];
382  std::vector<ConfigMap>::iterator nIt = nodeList.begin();
383  if (collisionNameMap.find(cmpName) != collisionNameMap.end()) {
384  cmpName = collisionNameMap[cmpName];
385  for (; nIt != nodeList.end(); ++nIt) {
386  if ((std::string) (*nIt)["name"] == cmpName) {
387  ConfigMap::iterator cIt = it->beginMap();
388  for (; cIt != it->endMap(); ++cIt) {
389  if (cIt->first != "name") {
390  if (cIt->first == "bitmask") {
391  (*nIt)["coll_bitmask"] = (int) cIt->second;
392  } else {
393  (*nIt)[cIt->first] = cIt->second;
394  }
395  }
396  }
397  break;
398  }
399  }
400  }
401  }
402 
403  for (it = config["lights"].begin(); it != config["lights"].end(); ++it) {
404  handleURIs(*it);
405  lightList.push_back(*it);
406 #ifdef DEBUG_SCENE_MAP
407  debugMap["lights"] += *it;
408 #endif
409  }
410  for (it = config["graphics"].begin(); it != config["graphics"].end(); ++it) {
411  handleURIs(*it);
412  graphicList.push_back(*it);
413 #ifdef DEBUG_SCENE_MAP
414  debugMap["graphics"] += *it;
415 #endif
416  }
417  for (it = config["controllers"].begin(); it != config["controllers"].end(); ++it) {
418  handleURIs(*it);
419  (*it)["index"] = nextControllerID++;
420  // convert names to ids
421  ConfigVector::iterator it2;
422  if (it->hasKey("sensors")) {
423  for (it2 = (*it)["sensors"].begin(); it2 != (*it)["sensors"].end(); ++it2) {
424  (*it)["sensorid"].push_back(sensorIDMap[(std::string) *it2]);
425  }
426  }
427  if (it->hasKey("motors")) {
428  for (it2 = (*it)["motors"].begin(); it2 != (*it)["motors"].end(); ++it2) {
429  (*it)["motorid"] += motorIDMap[(std::string) *it2];
430  }
431  }
432  controllerList.push_back(*it);
433 #ifdef DEBUG_SCENE_MAP
434  debugMap["controllers"] += *it;
435 #endif
436  }
437  }
438 
439  void SMURF::convertPose(const urdf::Pose &pose, const urdf::Pose &toPose, Vector *v,
440  Quaternion *q) {
441  urdf::Pose pose_ = pose;
442  urdf::Pose toPose_ = toPose;
443  urdf::Vector3 p;
444  urdf::Rotation r;
445 
446  // we need the inverse of toPose_.position
447  toPose_.position.x *= -1;
448  toPose_.position.y *= -1;
449  toPose_.position.z *= -1;
450  p = pose_.position + toPose_.position;
451  p = toPose_.rotation.GetInverse() * p;
452  r = (toPose_.rotation.GetInverse() * pose_.rotation);
453  *v = Vector(p.x, p.y, p.z);
454  *q = quaternionFromMembers(r);
455  }
456 
457  void SMURF::poseToVectorAndQuaternion(const urdf::Pose &pose, Vector *v, Quaternion*q) {
458  *v = Vector(pose.position.x, pose.position.y, pose.position.z);
459  *q = quaternionFromMembers(pose.rotation); //Quaternion(pose.rotation.x, pose.rotation.y, pose.rotation.z, pose.rotation.w);
460  }
461 
462 
463 
464  bool SMURF::isEqualPos(const urdf::Pose &p1, const urdf::Pose p2) {
465  bool equal = true;
466  double epsilon = 0.00000000001;
467  if (fabs(p1.position.x - p2.position.x) > epsilon)
468  equal = false;
469  if (fabs(p1.position.y - p2.position.y) > epsilon)
470  equal = false;
471  if (fabs(p1.position.z - p2.position.z) > epsilon)
472  equal = false;
473  if (fabs(p1.rotation.x - p2.rotation.x) > epsilon)
474  equal = false;
475  if (fabs(p1.rotation.y - p2.rotation.y) > epsilon)
476  equal = false;
477  if (fabs(p1.rotation.z - p2.rotation.z) > epsilon)
478  equal = false;
479  if (fabs(p1.rotation.w - p2.rotation.w) > epsilon)
480  equal = false;
481  return equal;
482  }
483 
484  bool SMURF::isNullPos(const urdf::Pose &p) {
485  bool zero = true;
486  double epsilon = 0.0000000001;
487  if (p.position.x > epsilon || p.position.x < -epsilon)
488  zero = false;
489  if (p.position.y > epsilon || p.position.y < -epsilon)
490  zero = false;
491  if (p.position.z > epsilon || p.position.z < -epsilon)
492  zero = false;
493  if (p.rotation.x > epsilon || p.position.x < -epsilon)
494  zero = false;
495  if (p.rotation.y > epsilon || p.position.y < -epsilon)
496  zero = false;
497  if (p.rotation.z > epsilon || p.position.z < -epsilon)
498  zero = false;
499  if (p.rotation.w > 1 + epsilon || p.rotation.w < 1 - epsilon)
500  zero = false;
501  return zero;
502  }
503 
505  ConfigMap config;
506 
507  config["id"] = nextMaterialID++;
508  config["name"] = "_emptyVisualMaterial";
509  config["exists"] = true;
510  config["diffuseFront"]["a"] = 1.0;
511  config["diffuseFront"]["r"] = 1.0;
512  config["diffuseFront"]["g"] = 0.0;
513  config["diffuseFront"]["b"] = 0.0;
514  config["texturename"] = "";
515  //config["cullMask"] = 0; // this makes the object invisible
516 #ifdef DEBUG_SCENE_MAP
517  debugMap["materials"] += config;
518 #endif
519  materialList.push_back(config);
520  }
521 
523  ConfigMap config;
524 
525  config["id"] = nextMaterialID++;
526  config["name"] = "_originMaterial";
527  config["exists"] = true;
528  config["diffuseFront"]["a"] = 1.0;
529  config["diffuseFront"]["r"] = 0.0;
530  config["diffuseFront"]["g"] = 0.0;
531  config["diffuseFront"]["b"] = 1.0;
532  config["texturename"] = "";
533  config["cullMask"] = 0;
534 #ifdef DEBUG_SCENE_MAP
535  debugMap["materials"] += config;
536 #endif
537  materialList.push_back(config);
538  }
539 
540 
542  (*map)["origname"] = "";
543  (*map)["materialName"] = "_emptyVisualMaterial";
544  (*map)["visualType"] = "empty";
545  }
546 
548  Vector size(0.01, 0.01, 0.01);
549  (*map)["physicmode"] = "box";
550  (*map)["coll_bitmask"] = 0;
551  vectorToConfigItem(&(*map)["extend"], &size);
552  }
553 
554  void SMURF::createOrigin(const urdf::LinkSharedPtr &link, bool fixed) {
555  ConfigMap config;
556  std::string name;
557  if (link->name.empty()) {
558  name = "link_"; // FIXME
559  } else {
560  name = link->name;
561  }
562  if (link->parent_joint) {
563  config["relativeid"] = linkIDMap[link->parent_joint->parent_link_name];
564  } else {
565  config["relativeid"] = (unsigned long) 0;
566  }
567 
568  // init node
569  config["name"] = name;
570  config["index"] = nextNodeID++;
571  linkIDMap[name] = nextNodeID - 1;
572  nodeIDMap[name] = nextNodeID - 1;
574  config["groupid"] = groupID;
575  config["movable"] = !fixed;
576 
577  // pose
578  Vector v;
579  Quaternion q;
580  urdf::Pose pose;
581  if (link->parent_joint)
582  pose = link->parent_joint->parent_to_joint_origin_transform;
583  poseToVectorAndQuaternion(pose, &v, &q);
584  vectorToConfigItem(&config["position"], &v);
585  quaternionToConfigItem(&config["rotation"], &q);
586 
587  // complete node
588  addEmptyVisualToNode(&config);
589  addEmptyCollisionToNode(&config);
590 
591  config["origname"] = "sphere";
592  config["material"] = "_originMaterial";
593 
594 #ifdef DEBUG_SCENE_MAP
595  debugMap["nodes"] += config;
596 #endif
597  nodeList.push_back(config);
598  }
599 
600  void SMURF::createInertial(const urdf::LinkSharedPtr &link) {
601  ConfigMap config;
602  std::string name;
603  if (link->name.empty()) {
604  name = "inertial_"; // FIXME
605  } else {
606  name = "inertial_" + link->name;
607  }
608 
609  // init node
610  config["name"] = name;
611  config["index"] = nextNodeID++;
612  nodeIDMap[name] = nextNodeID - 1;
613  config["groupid"] = groupID;
614  config["movable"] = true;
615  config["relativeid"] = currentNodeID;
616 
617  // reduce DataBroker load
618  config["noDataPackage"] = true;
619 
620  // add inertial information
621 
622  config["density"] = 0.0;
623  config["mass"] = link->inertial->mass;
624  config["inertia"] = true;
625  config["i00"] = link->inertial->ixx;
626  config["i01"] = link->inertial->ixy;
627  config["i02"] = link->inertial->ixz;
628  config["i10"] = link->inertial->ixy;
629  config["i11"] = link->inertial->iyy;
630  config["i12"] = link->inertial->iyz;
631  config["i20"] = link->inertial->ixz;
632  config["i21"] = link->inertial->iyz;
633  config["i22"] = link->inertial->izz;
634 
635  // pose
636  Vector v;
637  Quaternion q;
638  urdf::Pose pose;
639  pose = link->inertial->origin;
640  poseToVectorAndQuaternion(pose, &v, &q);
641  vectorToConfigItem(&config["position"], &v);
642  quaternionToConfigItem(&config["rotation"], &q);
643 
644  // complete node
645  addEmptyVisualToNode(&config);
646  addEmptyCollisionToNode(&config);
647 
648 #ifdef DEBUG_SCENE_MAP
649  debugMap["nodes"] += config;
650 #endif
651  nodeList.push_back(config);
652  }
653 
654  void SMURF::createCollision(const urdf::CollisionSharedPtr &collision, bool fixed=false) {
655  ConfigMap config;
656  std::string name;
657  if (collision->name.empty()) {
658  name = "collision_"; // FIXME
659  } else {
660  name = collision->name;
661  }
662 
663  // init node
664  config["name"] = name;
665  config["index"] = nextNodeID++;
666  nodeIDMap[name] = nextNodeID - 1;
667  config["groupid"] = groupID;
668  config["movable"] = !fixed;
669  config["relativeid"] = currentNodeID;
670  config["mass"] = 0.001;
671  config["density"] = 0.0;
672 
673  // parse geometry
674  urdf::GeometrySharedPtr tmpGeometry = collision->geometry;
675  Vector size(0.0, 0.0, 0.0);
676  Vector scale(1.0, 1.0, 1.0);
677  urdf::Vector3 tmpV;
678  switch (tmpGeometry->type) {
679  case urdf::Geometry::SPHERE:
680  size.x() = ((urdf::Sphere*) tmpGeometry.get())->radius;
681  config["physicmode"] = "sphere";
682  break;
683  case urdf::Geometry::BOX:
684  tmpV = ((urdf::Box*) tmpGeometry.get())->dim;
685  size = Vector(tmpV.x, tmpV.y, tmpV.z);
686  config["physicmode"] = "box";
687  break;
688  case urdf::Geometry::CYLINDER:
689  size.x() = ((urdf::Cylinder*) tmpGeometry.get())->radius;
690  size.y() = ((urdf::Cylinder*) tmpGeometry.get())->length;
691  config["physicmode"] = "cylinder";
692  break;
693  case urdf::Geometry::MESH:
694  tmpV = ((urdf::Mesh*) tmpGeometry.get())->scale;
695  scale = Vector(tmpV.x, tmpV.y, tmpV.z);
696  vectorToConfigItem(&config["physicalScale"], &scale);
697  config["filename"] = ((urdf::Mesh*) tmpGeometry.get())->filename;
698  config["origname"] = "";
699  config["physicmode"] = "mesh";
700  config["loadSizeFromMesh"] = true;
701  break;
702  default:
703  config["physicmode"] = "undefined";
704  break;
705  }
706  vectorToConfigItem(&config["extend"], &size);
707  vectorToConfigItem(&config["scale"], &scale);
708  // FIXME: We need to correctly deal with scale and size in MARS
709  // if we have a mesh here, as a first hack we use the scale as size
710 
711  // pose
712  Vector v;
713  Quaternion q;
714  poseToVectorAndQuaternion(collision->origin, &v, &q);
715  vectorToConfigItem(&config["position"], &v);
716  quaternionToConfigItem(&config["rotation"], &q);
717 
718  collisionNameMap[name] = name;
719  addEmptyVisualToNode(&config);
720 
721 #ifdef DEBUG_SCENE_MAP
722  debugMap["nodes"] += config;
723 #endif
724  nodeList.push_back(config);
725  }
726 
727  void SMURF::createVisual(const urdf::VisualSharedPtr &visual, bool fixed=false) {
728  ConfigMap config;
729  std::string name;
730  if (visual->name.empty()) {
731  name = "visual_"; // FIXME
732  } else {
733  name = visual->name;
734  }
735 
736  // init node
737  config["name"] = name;
738  config["index"] = nextNodeID++;
739  nodeIDMap[name] = nextNodeID - 1;
740  config["groupid"] = groupID;
741  config["movable"] = !fixed;
742  config["relativeid"] = currentNodeID;
743  config["mass"] = 0.001;
744  config["density"] = 0.0;
745  Vector v(0.001, 0.001, 0.001);
746  vectorToConfigItem(&config["extend"], &v);
747 
748  // parse position
749  Quaternion q;
750  poseToVectorAndQuaternion(visual->origin, &v, &q);
751  vectorToConfigItem(&config["position"], &v);
752  quaternionToConfigItem(&config["rotation"], &q);
753 
754  // parse geometry
755  urdf::GeometrySharedPtr tmpGeometry = visual->geometry;
756  Vector size(0.0, 0.0, 0.0);
757  Vector scale(1.0, 1.0, 1.0);
758  urdf::Vector3 tmpV;
759  config["filename"] = "PRIMITIVE";
760  switch (tmpGeometry->type) {
761  case urdf::Geometry::SPHERE:
762  size.x() = 2.0*((urdf::Sphere*) tmpGeometry.get())->radius;
763  size.y() = 2.0*((urdf::Sphere*) tmpGeometry.get())->radius;
764  size.z() = 2.0*((urdf::Sphere*) tmpGeometry.get())->radius;
765  config["origname"] = "sphere";
766  break;
767  case urdf::Geometry::BOX:
768  tmpV = ((urdf::Box*) tmpGeometry.get())->dim;
769  size = Vector(tmpV.x, tmpV.y, tmpV.z);
770  config["origname"] = "box";
771  break;
772  case urdf::Geometry::CYLINDER:
773  size.x() = 2.0*((urdf::Cylinder*) tmpGeometry.get())->radius;
774  size.y() = 2.0*((urdf::Cylinder*) tmpGeometry.get())->radius;
775  size.z() = ((urdf::Cylinder*) tmpGeometry.get())->length;
776  config["origname"] = "cylinder";
777  break;
778  case urdf::Geometry::MESH:
779  tmpV = ((urdf::Mesh*) tmpGeometry.get())->scale;
780  scale = Vector(tmpV.x, tmpV.y, tmpV.z);
781  config["filename"] = ((urdf::Mesh*) tmpGeometry.get())->filename;
782  config["origname"] = "";
783  break;
784  default:
785  break;
786  }
787  vectorToConfigItem(&config["visualsize"], &size);
788  vectorToConfigItem(&config["visualscale"], &scale);
789  config["materialName"] = visual->material_name;
790 
791  addEmptyCollisionToNode(&config);
792  config["vizLink"] = currentNodeID;
793  config["noPhysical"] = true;
794  config["noDataPackage"] = true;
795 
796  visualNameMap[name] = name;
797 
798 #ifdef DEBUG_SCENE_MAP
799  debugMap["nodes"] += config;
800 #endif
801  nodeList.push_back(config);
802  }
803 
804  void SMURF::translateLink(urdf::LinkSharedPtr link, bool fixed=false) {
805  Vector v;
806  Quaternion q;
807 
808  groupID++;
809 
810  createOrigin(link, fixed);
811 
812  if (link->parent_joint)
813  translateJoint(link);
814 
815  // inertial
816  if (link->inertial && !fixed) {
817  createInertial(link);
818  }
819 
820  // collision
821  if (link->collision) {
822  for (std::vector<urdf::CollisionSharedPtr >::iterator it = link->collision_array.begin();
823  it != link->collision_array.end(); ++it) {
824  createCollision(*it, fixed);
825  }
826  }
827 
828  // visual
829  if (link->visual) {
830  for (std::vector<urdf::VisualSharedPtr >::iterator it = link->visual_array.begin();
831  it != link->visual_array.end(); ++it) {
832  createVisual(*it, fixed);
833  }
834  }
835 
836  for (std::vector<urdf::LinkSharedPtr >::iterator it = link->child_links.begin();
837  it != link->child_links.end(); ++it) {
838  fprintf(stderr, "parsing link %s->%s..\n", (link->name).c_str(), ((*it)->name).c_str());
839  translateLink(*it);
840  }
841 
842  }
843 
844  void SMURF::translateJoint(urdf::LinkSharedPtr childlink) {
845  ConfigMap config;
846  urdf::JointSharedPtr joint = childlink->parent_joint;
847  config["name"] = joint->name;
848  config["index"] = nextJointID++;
849  jointIDMap[joint->name] = nextJointID - 1;
850  config["nodeindex1"] = nodeIDMap[joint->parent_link_name];
851  config["nodeindex2"] = nodeIDMap[joint->child_link_name];
852  config["anchorpos"] = "node2"; // always use the child_link as the anchor since joint and child_link are in the same frame
853  // FIXME: reading in the limits was discarded until further notice as joint
854  // limits can lead ODE to become unstable
855  // if (link->parent_joint->limits) {
856  // joint["lowStopAxis1"] = link->parent_joint->limits->lower;
857  // joint["highStopAxis1"] = link->parent_joint->limits->upper;
858  // }
859  // FIXME: we do not at this point read the joint "maxeffort" and "maxvelocity"
860  // limits as they are effectively motor values and should be used only
861  // if there are no explicit motor values defined
862  if (joint->type == urdf::Joint::REVOLUTE
863  || joint->type == urdf::Joint::CONTINUOUS) {
864  config["type"] = "hinge";
865  } else if (joint->type == urdf::Joint::PRISMATIC) {
866  config["type"] = "slider";
867  } else if (joint->type == urdf::Joint::FIXED) {
868  config["type"] = "fixed";
869  } else {
870  // we don't support the type yet and use a fixed joint
871  config["type"] = "fixed";
872  }
873 
874  // transform the joint's axis into global coordinates
875  urdf::Pose pose = getGlobalPose(childlink);
876  urdf::Pose axispose;
877 // axispose.position = childlink->parent_joint->parent_to_joint_origin_transform.rotation * joint->axis;
878  axispose.position = pose.rotation * joint->axis;
879  Vector v;
880  v = Vector(axispose.position.x, axispose.position.y, axispose.position.z);
881  vectorToConfigItem(&config["axis1"], &v);
882 
883  // add to debug and joint list
884 #ifdef DEBUG_SCENE_MAP
885  debugMap["joints"] += config;
886 #endif
887  // reduce DataBroker load
888  config["reducedDataPackage"] = true;
889  jointList.push_back(config);
890  }
891 
892  urdf::Pose SMURF::getGlobalPose(const urdf::LinkSharedPtr &link) {
893  urdf::Pose globalPose;
894  urdf::LinkSharedPtr pLink = link->getParent();
895  if (link->parent_joint) {
896  globalPose = link->parent_joint->parent_to_joint_origin_transform;
897  }
898  if (pLink) {
899  urdf::Pose parentPose = getGlobalPose(pLink);
900  globalPose.position = parentPose.rotation * globalPose.position;
901  globalPose.position = globalPose.position + parentPose.position;
902  globalPose.rotation = parentPose.rotation * globalPose.rotation;
903  }
904  return globalPose;
905  }
906 
907  void SMURF::createMaterial(urdf::MaterialSharedPtr material) {
908  ConfigMap config;
909 
910  config["id"] = nextMaterialID++;
911  config["name"] = material->name;
912  config["exists"] = true;
913  config["diffuseFront"]["a"] = (double) material->color.a;
914  config["diffuseFront"]["r"] = (double) material->color.r;
915  config["diffuseFront"]["g"] = (double) material->color.g;
916  config["diffuseFront"]["b"] = (double) material->color.b;
917  config["texturename"] = material->texture_filename;
918 
919  // add to debug and material list
920 #ifdef DEBUG_SCENE_MAP
921  debugMap["materials"] += config;
922 #endif
923  materialList.push_back(config);
924  }
925 
926  unsigned int SMURF::parseURDF(std::string filename) {
927  if(!utils::pathExists(filename)) {
928  fprintf(stderr, "ERROR: SMURF:parseURDF no such file: %s\n",
929  filename.c_str());
930  return 0;
931  }
932  model = urdf::parseURDFFile(filename);
933  if (!model) {
934  return 0;
935  }
936  return 1;
937  }
938 
939  void SMURF::createModel(bool fixed=false) {
940 
941  if (robotname == "") {
942  robotname = model.get()->name_;
943  }
944 
947  std::map<std::string, urdf::MaterialSharedPtr >::iterator it;
948  for (it = model->materials_.begin(); it != model->materials_.end(); ++it) {
949  createMaterial(it->second);
950  }
951 
952  translateLink(model->root_link_, fixed);
953  }
954 
955  unsigned int SMURF::load() {
956  fprintf(stderr, "smurfing robot: %s...\n", robotname.c_str());
957 #ifdef DEBUG_SCENE_MAP
958  debugMap.toYamlFile("debugMap.yml");
959 #endif
960  for (unsigned int i = 0; i < materialList.size(); ++i)
961  if (!loadMaterial(materialList[i]))
962  return 0;
963  for (unsigned int i = 0; i < nodeList.size(); ++i)
964  if (!loadNode(nodeList[i])) {
965  fprintf(stderr, "Couldn't load node %lu, %s..\n'", (unsigned long)nodeList[i]["index"], ((std::string)nodeList[i]["name"]).c_str());
966  return 0;
967  }
968 
969 
970  for (unsigned int i = 0; i < jointList.size(); ++i)
971  if (!loadJoint(jointList[i]))
972  return 0;
973 
974  for (unsigned int i = 0; i < motorList.size(); ++i)
975  if (!loadMotor(motorList[i]))
976  return 0;
977 
979 
980  for (unsigned int i = 0; i < sensorList.size(); ++i)
981  if (!loadSensor(sensorList[i]))
982  return 0;
983 
984  for (unsigned int i = 0; i < controllerList.size(); ++i)
986  return 0;
987 
988  for (unsigned int i = 0; i < lightList.size(); ++i)
989  if (!loadLight(lightList[i]))
990  return 0;
991 
992  for (unsigned int i = 0; i < graphicList.size(); ++i)
993  if (!loadGraphic(graphicList[i]))
994  return 0;
995 
996  // set model pose
997  ConfigMap map;
998  map["rootNode"] = model->root_link_->name;
999  entity->appendConfig(map);
1001 
1002  control->nodes->printNodeMasses(true);
1003 
1004  return 1;
1005  }
1006 
1007  unsigned int SMURF::loadNode(ConfigMap config) {
1008  NodeData node;
1009  config["mapIndex"] = mapIndex;
1010  string suffix, tmpfilename;
1011 
1012  // check if we can use .bobj
1013  tmpfilename = trim(config.get("filename", tmpfilename));
1014  // if we have an actual file name
1015  if (!tmpfilename.empty()) {
1016  suffix = getFilenameSuffix(tmpfilename);
1017  if (suffix == ".obj" || suffix == ".OBJ") {
1018  // turn our relative filename into an absolute filename
1019  removeFilenameSuffix(&tmpfilename);
1020  tmpfilename.append(".bobj");
1021  string tmpfilename2 = tmpfilename;
1022  handleFilenamePrefix(&tmpfilename, tmpPath);
1023  // replace if that file exists
1024  if (pathExists(tmpfilename)) {
1025  fprintf(stderr, "Loading .bobj instead of .obj for file: %s\n", tmpfilename.c_str());
1026  config["filename"] = tmpfilename2;
1027  }
1028  else {
1029  // check if bobj files are in parallel folder
1030  int index = tmpfilename2.find("obj/");
1031  if (index != string::npos) {
1032  string newfilename = replaceString(tmpfilename2, "obj/", "bobj/");
1033  string tmpfilename2 = newfilename;
1034  handleFilenamePrefix(&newfilename, tmpPath);
1035  if (pathExists(newfilename)) {
1036  fprintf(stderr, "Loading .bobj instead of .obj for file: %s\n", newfilename.c_str());
1037  config["filename"] = tmpfilename2;
1038  }
1039  }
1040  }
1041  }
1042  }
1043 
1044  int valid = node.fromConfigMap(&config, tmpPath, control->loadCenter);
1045  if (!valid)
1046  return 0;
1047 
1048  if ((std::string) config["materialName"] != std::string("")) {
1049  std::map<std::string, MaterialData>::iterator it;
1050  it = materialMap.find(config["materialName"]);
1051  if (it != materialMap.end()) {
1052  node.material = it->second;
1053  }
1054  } else {
1055  node.material.diffuseFront = Color(0.4, 0.4, 0.4, 1.0);
1056  }
1057 
1058  // check if meshes are stored as `.stl` file
1059  suffix = getFilenameSuffix(node.filename);
1060  if (suffix == ".stl" || suffix == ".STL") {
1061  // add an additional rotation of -90.0 degree due to wrong definition
1062  // of which direction is up within .stl (for .stl -Y is up and in MARS
1063  // Z is up)
1064  node.visual_offset_rot *= eulerToQuaternion(Vector(-90.0, 0.0, 0.0));
1065  }
1066 
1067 
1068  NodeId oldId = node.index;
1069 #ifdef DEBUG_SCENE_MAP
1070  config.toYamlFile("SMURFNode.yml");
1071 #endif
1072  NodeId newId = control->nodes->addNode(&node);
1073  if (!newId) {
1074  LOG_ERROR("addNode returned 0");
1075  return 0;
1076  }
1078  entity->addNode(node.index, node.name);
1079  return 1;
1080  }
1081 
1082  unsigned int SMURF::loadMaterial(ConfigMap config) {
1083  MaterialData material;
1084  int valid = material.fromConfigMap(&config, tmpPath);
1085  materialMap[config["name"]] = material;
1086 
1087  return valid;
1088  }
1089 
1090  unsigned int SMURF::loadJoint(ConfigMap config) {
1091  JointData joint;
1092  joint.invertAxis = true;
1093  config["mapIndex"] = mapIndex;
1094  int valid = joint.fromConfigMap(&config, tmpPath, control->loadCenter);
1095  if (!valid) {
1096  fprintf(stderr, "SMURF: error while smurfing joint\n");
1097  return 0;
1098  }
1099 
1100  JointId oldId = joint.index;
1101  JointId newId = control->joints->addJoint(&joint);
1102  if (!newId) {
1103  LOG_ERROR("addJoint returned 0");
1104  return 0;
1105  }
1107 
1108  entity->addJoint(joint.index, joint.name);
1109  return true;
1110  }
1111 
1112  unsigned int SMURF::loadMotor(ConfigMap config) {
1113  MotorData motor;
1114  config["mapIndex"] = mapIndex;
1115 
1116  int valid = motor.fromConfigMap(&config, tmpPath, control->loadCenter);
1117  if (!valid) {
1118  fprintf(stderr, "SMURF: error while smurfing motor\n");
1119  return 0;
1120  }
1121 
1122  MotorId oldId = motor.index;
1123  MotorId newId = control->motors->addMotor(&motor);
1124  if (!newId) {
1125  LOG_ERROR("addMotor returned 0");
1126  return 0;
1127  }
1129 
1130  entity->addMotor(motor.index, motor.name);
1131 
1132  return true;
1133  }
1134 
1136  config["mapIndex"] = mapIndex;
1137  BaseSensor *sensor = control->sensors->createAndAddSensor(&config);
1138  if (sensor != 0) {
1139  control->loadCenter->setMappedID(config["index"], sensor->getID(), MAP_TYPE_SENSOR,
1140  mapIndex);
1141  }
1142 
1143  return sensor;
1144  }
1145 
1146  unsigned int SMURF::loadGraphic(ConfigMap config) {
1147  GraphicData graphic;
1148  config["mapIndex"] = mapIndex;
1149  int valid = graphic.fromConfigMap(&config, tmpPath, control->loadCenter);
1150  if (!valid) {
1151  fprintf(stderr, "SMURF: error while smurfing graphic\n");
1152  return 0;
1153  }
1154 
1155  if (control->graphics)
1156  control->graphics->setGraphicOptions(graphic);
1157 
1158  return 1;
1159  }
1160 
1161  unsigned int SMURF::loadLight(ConfigMap config) {
1162  LightData light;
1163  config["mapIndex"] = mapIndex;
1164  int valid = light.fromConfigMap(&config, tmpPath, control->loadCenter);
1165  if (!valid) {
1166  fprintf(stderr, "SMURF: error while smurfing light\n");
1167  return 0;
1168  }
1169  control->sim->addLight(light);
1170  return true;
1171  }
1172 
1173  unsigned int SMURF::loadController(ConfigMap config) {
1174  ControllerData controller;
1175  config["mapIndex"] = mapIndex;
1176 
1177  int valid = controller.fromConfigMap(&config, tmpPath, control->loadCenter);
1178  if (!valid) {
1179  fprintf(stderr, "SMURF: error while smurfing Controller\n");
1180  return 0;
1181  }
1182 
1183  MotorId oldId = controller.id;
1184  MotorId newId = control->controllers->addController(controller);
1185  if (!newId) {
1186  LOG_ERROR("SMURF: addController returned 0");
1187  return 0;
1188  }
1190  entity->addController(newId);
1191  return 1;
1192  }
1193 
1194  std::string SMURF::getRobotname() {
1195  return robotname;
1196  }
1197 
1198  } // end of namespace smurf
1199 } // end of namespace mars
1200 
MotorData is a struct to exchange motor information between the GUI and the simulation.
Definition: MotorData.h:37
NodeManagerInterface * nodes
Definition: ControlCenter.h:98
std::map< std::string, std::string > collisionNameMap
Definition: smurf.h:105
LightData is a struct to exchange light information between the Dialog_Add_Light, the MainWindow and ...
Definition: LightData.h:40
std::map< std::string, unsigned long > jointIDMap
Definition: smurf.h:101
unsigned long nextGroupID
Definition: smurf.h:92
JointData is a class to exchange joint information between the simulation modules.
Definition: JointData.h:40
void createVisual(const urdf::VisualSharedPtr &visual, bool fixed)
Definition: smurf.cpp:727
configmaps::ConfigMap debugMap
Definition: smurf.h:108
void appendConfig(const configmaps::ConfigMap &parameters)
Definition: SimEntity.cpp:61
GraphicsManagerInterface * graphics
std::string getFilenameSuffix(const std::string &file)
given a filename "foobar.baz" this will return ".baz"
Definition: misc.cpp:144
bool isNullPos(const urdf::Pose &p)
Definition: smurf.cpp:484
unsigned int getMappedSceneByName(const std::string &scenename) const
Definition: LoadCenter.cpp:43
unsigned int loadMaterial(configmaps::ConfigMap config)
Definition: smurf.cpp:1082
bool fromConfigMap(configmaps::ConfigMap *config, std::string filenamePrefix, LoadCenter *loadCenter=0)
Definition: JointData.cpp:88
std::vector< configmaps::ConfigMap > motorList
Definition: smurf.h:82
void getSensorIDList(configmaps::ConfigMap *map)
Definition: smurf.cpp:151
sim::SimEntity * entity
Definition: smurf.h:112
bool fromConfigMap(configmaps::ConfigMap *config, std::string filenamePrefix)
SensorManagerInterface * sensors
void createInertial(const urdf::LinkSharedPtr &link)
Definition: smurf.cpp:600
unsigned long MotorId
Definition: MARSDefs.h:47
MotorManagerInterface * motors
std::string trim(const std::string &str)
remove leading and trailing whitespaces
Definition: misc.cpp:94
unsigned int setMappedID(unsigned long id_old, unsigned long id_new, unsigned int indextype, unsigned int source)
Definition: LoadCenter.cpp:90
virtual unsigned long getMaxGroupID()=0
NodeData is a struct to exchange node information between the GUI and the simulation.
Definition: NodeData.h:52
u_int8_t r
Definition: CameraSensor.h:41
bool fromConfigMap(configmaps::ConfigMap *config, std::string filenamePrefix, LoadCenter *loadCenter=0)
Definition: LightData.cpp:45
void toYamlFile(const std::string &filename) const
Definition: ConfigBase.cpp:19
ControllerManagerInterface * controllers
virtual unsigned long addJoint(JointData *jointS, bool reload=false)=0
Add a joint to the joint pool of the simulation.
std::string filename
The filename of the node to load the visual representation from.
Definition: NodeData.h:159
unsigned int loadController(configmaps::ConfigMap config)
Definition: smurf.cpp:1173
std::vector< configmaps::ConfigMap > graphicList
Definition: smurf.h:85
unsigned int loadMotor(configmaps::ConfigMap config)
Definition: smurf.cpp:1112
std::map< std::string, unsigned long > motorIDMap
Definition: smurf.h:103
MaterialData is a struct to exchange material information of nodes.
Definition: MaterialData.h:35
unsigned int loadNode(configmaps::ConfigMap config)
Definition: smurf.cpp:1007
SMURF(lib_manager::LibManager *theManager)
Definition: smurf.cpp:65
virtual void switchPluginUpdateMode(int mode, PluginInterface *pl)=0
void vectorToConfigItem(ConfigItem *item, Vector *v)
Definition: mathUtils.cpp:274
static ConfigMap fromYamlFile(const std::string &filename, bool loadURI=false)
Definition: ConfigMap.cpp:54
virtual NodeId addNode(NodeData *nodeS, bool reload=false, bool loadGraphics=true)=0
Add a node to the node pool of the simulation.
virtual BaseSensor * createAndAddSensor(configmaps::ConfigMap *config, bool reload=true)=0
Adds an sensor to the known sensors list.
void addMotor(unsigned long motorId, const std::string &name)
Definition: SimEntity.cpp:78
std::list< FIFOItem< std::string, ConfigItem > >::iterator iterator
Definition: FIFOMap.h:57
utils::Quaternion visual_offset_rot
In the same way as the visual_offset_pos, this quaternion can be used to differentiate the orientatio...
Definition: NodeData.h:313
void createOriginMaterial()
Definition: smurf.cpp:522
unsigned long JointId
Definition: MARSDefs.h:46
std::map< std::string, interfaces::MaterialData > materialMap
Definition: smurf.h:104
void poseToVectorAndQuaternion(const urdf::Pose &pose, utils::Vector *v, utils::Quaternion *q)
Definition: smurf.cpp:457
Quaternion quaternionFromMembers(T q)
Definition: mathUtils.h:119
Quaternion eulerToQuaternion(const Vector &euler_v)
Definition: mathUtils.cpp:133
bool fromConfigMap(configmaps::ConfigMap *config, std::string filenamePrefix, LoadCenter *loadCenter=0)
Definition: GraphicData.cpp:55
std::map< std::string, unsigned long > nodeIDMap
Definition: smurf.h:100
virtual void registerFactory(const std::string type, EntityFactoryInterface *factory)
interfaces::BaseSensor * loadSensor(configmaps::ConfigMap config)
Definition: smurf.cpp:1135
std::vector< configmaps::ConfigMap > jointList
Definition: smurf.h:81
void handleURIs(configmaps::ConfigMap *map)
Definition: smurf.cpp:131
void translateJoint(urdf::LinkSharedPtr childlink)
Definition: smurf.cpp:844
void setMappedSceneName(const std::string &scenename)
Definition: LoadCenter.cpp:52
double sReal
Definition: MARSDefs.h:49
void createModel(bool fixed)
Definition: smurf.cpp:939
unsigned long getID() const
Definition: sensor_bases.h:69
unsigned int loadGraphic(configmaps::ConfigMap config)
Definition: smurf.cpp:1146
unsigned int mapIndex
Definition: smurf.h:90
std::vector< configmaps::ConfigMap > lightList
Definition: smurf.h:86
bool fromConfigMap(configmaps::ConfigMap *config, std::string filenamePrefix, LoadCenter *loadCenter=0)
Definition: MotorData.cpp:95
DESTROY_LIB(mars::smurf::SMURF)
bool fromConfigMap(configmaps::ConfigMap *config, std::string filenamePrefix, LoadCenter *loadCenter=0)
Definition: NodeData.cpp:98
std::vector< configmaps::ConfigMap > sensorList
Definition: smurf.h:83
unsigned long nextMaterialID
Definition: smurf.h:95
void createCollision(const urdf::CollisionSharedPtr &collision, bool fixed)
Definition: smurf.cpp:654
T * acquireLibraryAs(const std::string &libName, bool load=false)
Definition: LibManager.hpp:113
std::vector< configmaps::ConfigMap > controllerList
Definition: smurf.h:84
void createOrigin(const urdf::LinkSharedPtr &link, bool fixed)
Definition: smurf.cpp:554
void quaternionToConfigItem(ConfigItem *item, Quaternion *q)
Definition: mathUtils.cpp:288
Copyright 2012, DFKI GmbH Robotics Innovation Center.
void addEmptyVisualToNode(configmaps::ConfigMap *map)
Definition: smurf.cpp:541
void translateLink(urdf::LinkSharedPtr link, bool fixed)
Definition: smurf.cpp:804
JointManagerInterface * joints
Definition: ControlCenter.h:99
virtual unsigned long addMotor(MotorData *motorS, bool reload=false)=0
Add a motor to the simulation.
Eigen::Matrix< double, 3, 1, Eigen::DontAlign > Vector
Definition: Vector.h:43
std::string robotname
Definition: smurf.h:110
Eigen::Quaternion< double, Eigen::DontAlign > Quaternion
Definition: Quaternion.h:56
CREATE_LIB(mars::smurf::SMURF)
unsigned long nextMotorID
Definition: smurf.h:96
std::map< std::string, std::string > visualNameMap
Definition: smurf.h:105
void createEmptyVisualMaterial()
Definition: smurf.cpp:504
unsigned long nextControllerID
Definition: smurf.h:98
void handleURI(configmaps::ConfigMap *map, std::string uri)
Definition: smurf.cpp:125
void removeFilenameSuffix(std::string *file)
given a filename "foobar.baz" this will remove the extension (including the dot ".") resulting in "foobar".
Definition: misc.cpp:136
unsigned long nextSensorID
Definition: smurf.h:97
unsigned long nextNodeID
Definition: smurf.h:91
bool pathExists(const std::string &path)
check whether a file or directory exists.
Definition: misc.h:112
virtual unsigned long addController(const ControllerData &controllerData)=0
Add a controller to the simulation.
void addJoint(long unsigned int jointId, const std::string &name)
Definition: SimEntity.cpp:86
std::string getRobotname()
Definition: smurf.cpp:1194
unsigned int loadLight(configmaps::ConfigMap config)
Definition: smurf.cpp:1161
std::vector< configmaps::ConfigMap > nodeList
Definition: smurf.h:80
void addNode(unsigned long nodeId, const std::string &name)
Definition: SimEntity.cpp:74
unsigned int load()
Definition: smurf.cpp:955
void addConfigMap(configmaps::ConfigMap &config)
Definition: smurf.cpp:244
bool isEqualPos(const urdf::Pose &p1, const urdf::Pose p2)
Definition: smurf.cpp:464
std::string name
The name of the node.
Definition: NodeData.h:143
virtual sim::SimEntity * createEntity(const configmaps::ConfigMap &config)
Definition: smurf.cpp:184
virtual void addLight(LightData light)=0
urdf::Pose getGlobalPose(const urdf::LinkSharedPtr &link)
Definition: smurf.cpp:892
virtual void setGraphicOptions(const GraphicData &options, bool ignoreClearColor=false)=0
MaterialData material
The material struct defines the visual material of the node.
Definition: NodeData.h:262
unsigned int loadJoint(configmaps::ConfigMap config)
Definition: smurf.cpp:1090
bool fromConfigMap(configmaps::ConfigMap *config, std::string filenamePrefix, LoadCenter *loadCenter=0)
void update(mars::interfaces::sReal time_ms)
Definition: smurf.cpp:122
std::map< std::string, unsigned long > linkIDMap
Definition: smurf.h:99
std::string tmpPath
Definition: smurf.h:106
std::string replaceString(const std::string &source, const std::string &s1, const std::string &s2)
Definition: misc.cpp:236
void addEmptyCollisionToNode(configmaps::ConfigMap *map)
Definition: smurf.cpp:547
unsigned long NodeId
Definition: MARSDefs.h:45
configmaps::ConfigMap entityconfig
Definition: smurf.h:109
unsigned long nextJointID
Definition: smurf.h:94
virtual void printNodeMasses(bool onlysum)=0
size_t append(const ConfigItem &item)
unsigned long index
The unique index of the node.
Definition: NodeData.h:172
void addController(unsigned long controllerId)
Definition: SimEntity.cpp:82
unsigned int parseURDF(std::string filename)
Definition: smurf.cpp:926
void convertPose(const urdf::Pose &pose, const urdf::Pose &toPose, utils::Vector *v, utils::Quaternion *q)
Definition: smurf.cpp:439
#define LOG_ERROR(...)
Definition: Logging.hpp:21
T get(const std::string &key, const T &defaultValue)
Definition: ConfigMap.hpp:104
unsigned long currentNodeID
Definition: smurf.h:93
urdf::ModelInterfaceSharedPtr model
Definition: smurf.h:111
void handleFilenamePrefix(std::string *file, const std::string &prefix)
Definition: misc.cpp:108
ErrorNumber releaseLibrary(const std::string &libName)
Releases a previously acquired library.
Definition: LibManager.cpp:311
std::map< std::string, unsigned long > sensorIDMap
Definition: smurf.h:102
void setInitialPose(bool reset=false)
Definition: SimEntity.cpp:182
void createMaterial(const urdf::MaterialSharedPtr material)
Definition: smurf.cpp:907
std::vector< configmaps::ConfigMap > materialList
Definition: smurf.h:79