Home | Tutorials | Wiki | Issues
Ask Your Question
0

how to "save world as" programatically with c++

asked 2014-10-26 08:07:14 -0500

shpower gravatar image

Hey,

I want to be able to save the world several times during the simulation, programmatically in c++ gazebo plugin. I mean to get the same file as if I press "save world as" in the gazebo gui.

thanks in advance,

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2014-10-27 00:26:28 -0500

scpeters gravatar image

Pressing "Save world as" invokes the MainWindow::Save function, which creates a "world_sdf" request message that is fulfilled by the gazebo server. The following is a paraphrase of the code in MainWindow::Save that places sdf file as a string in msgData:


  // Get the latest world in SDF.
  boost::shared_ptr<msgs::response> response =
    transport::request(get_world(), "world_sdf");

  msgs::GzString msg;

  // Make sure the response is correct
  if (response->response() != "error" && response->type() == msg.GetTypeName())
  {
    // Parse the response message
    msg.ParseFromString(response->serialized_data());
  }
  std::string msgData = msg.data();

I say it's a paraphrase because MainWindow::Save, as part of the gui, also tries to parse the sdf file and insert a <gui> element with information about the gui state (primarily camera position).

There is also a World::Save function that I think can be called from the same process as the server (WorldPlugin's and ModelPlugin's), but I'm not exactly sure how thread-safe it is.

edit flag offensive delete link more

Comments

I have a question about the code. the "world_sdf" is the name of the request, correct? Is there a list of requests

shpower gravatar imageshpower ( 2014-10-27 07:40:59 -0500 )edit

I have a question about the code. the "world_sdf" is the name of the request, correct? Is there a list of requests

shpower gravatar imageshpower ( 2014-10-27 07:41:00 -0500 )edit

and of course thanks a lot!

shpower gravatar imageshpower ( 2014-10-27 07:41:34 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2014-10-26 08:07:14 -0500

Seen: 262 times

Last updated: Oct 27 '14