Gazebo | Ignition | Community
Ask Your Question
0

Insert multiple copies of the same model file?

asked 2012-11-06 15:15:56 -0500

mcevoy.andy gravatar image

Following the tutorial I spawn a model using option 3.

Is there a way to spawn multiple models that use the same model file using this method?

using GetModel->SetName before spawning a new model doesn't seem to work... the names never update in the gazebo gui and the previous model just disappears.

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
0

answered 2012-11-07 13:55:41 -0500

nkoenig gravatar image

This feature doesn't exist, but I've created a ticket for it.

edit flag offensive delete link more
1

answered 2012-11-07 16:58:53 -0500

Wenguo Liu gravatar image

updated 2012-11-07 17:00:11 -0500

     this code works for me

      for(int i=0;i<num_robots;i++)
      {
          sdf::SDFPtr modelSDF;
          modelSDF.reset(new sdf::SDF);  
          sdf::initFile("gazebo.sdf", modelSDF);
          sdf::readFile("models/wbr.model", modelSDF);
          sdf::ElementPtr modelElem = modelSDF->root->GetElement("model");
          std::string modelName = modelElem->GetValueString("name");
          modelName = modelElem->GetValueString("name") + "_" +
              boost::lexical_cast<std::string>(i); ;
          modelElem->GetAttribute("name")->Set(modelName);
          modelElem->GetElement("pose")->Set(
                  math::Pose(math::Vector3(i, 0, 0), math::Quaternion(0, 0, 0)));

          //TODO: find sensors'name
          sdf::ElementPtr sensorElem = modelSDF->root->GetElement("model")->GetElement("link")->GetElement("sensor");
          if(sensorElem)
          {
              sensorElem->GetAttribute("name")->Set(modelElem->GetValueString("name") +"::"+ sensorElem->GetValueString("name")  );
          }
          _parent->InsertModelSDF(*modelSDF);
      }
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2012-11-06 15:15:56 -0500

Seen: 1,897 times

Last updated: Nov 07 '12