SDF environment model in DART

Hi,
I’d like to know how to load an environment to DART and visualize it. I’m already parsing a robot skeleton, controlling it and visualizing the motion so I just want to add an environment around it. I’m trying in this way

dart::utils::DartLoader urdfLoader;

auto moon = urdfLoader.parseWorld("/home/filippo/BackUp_Ubuntu16/UNIV/intrinsically_stable_moonwalk_ENHANCED/apollo15_landing_site_1000x1000/model-1_4.sdf");

but it gives me the warning

Warning [urdf_world_parser.cpp:79] [parseWorldURDF] ERROR: Could not find a element in XML, exiting and not loading!
Warning [DartLoader.cpp:156] [DartLoader::parseWorldString] Failed loading URDF.

which clearly depends on the fact that I’m trying to upload a SDF file.
I’ve also tried with

dart::utils::SdfParser::readSdfFile("/home/filippo/BackUp_Ubuntu16/UNIV/intrinsically_stable_moonwalk_ENHANCED/apollo15_landing_site_1000x1000/model-1_4.sdf");

but the code doesn’t compile since it tells me that it is deprecated. Is there a way to do this, could you help me or link me an example?
Thank you very much
Filippo

It should still be able to compile and run with a deprecation warning, unless your build system is set up to issue compilation errors at deprecation warnings.

But how about replacing it with this:

dart::utils::SdfParser::readWorld("/home/filippo/BackUp_Ubuntu16/UNIV/intrinsically_stable_moonwalk_ENHANCED/apollo15_landing_site_1000x1000/model-1_4.sdf");

I think that’s the function that’s meant to replace the deprecated readSdfFile(~).

Thank you very much for the answer. In this way it reads it and compile, but then how to visualize it or add it to the world?
Thank you very much,
Filippo

That function will return a dart::simulation::WorldPtr which you can pass along to one of the rendering libraries that dartsim provides. I recommend using dart::gui::osg, like in this example: https://github.com/dartsim/dart/blob/07fd1a15a9dfd16d71903baea7ed515a7106924d/examples/operational_space_control/main.cpp#L327-L329

I’m trying to emulate the example in this way

auto moon = dart::utils::SdfParser::readWorld("/home/filippo/BackUp_Ubuntu16/UNIV/intrinsically_stable_moonwalk_ENHANCED/apollo15_landing_site_1000x1000/model-1_4.sdf");
viewer.addWorldNode(moon);

but the error now is

error: no matching function for call to ‘dart::gui::osg::ImGuiViewer::addWorldNode(std::shared_ptrdart::simulation::World&)’

and it also tells me

note: no known conversion for argument 1 from ‘std::shared_ptrdart::simulation::World’ to ‘dart::gui::osg::WorldNode*’

how to solve?
Thank you

Try the following:

  auto moon = dart::utils::SdfParser::readWorld("/home/filippo/BackUp_Ubuntu16/UNIV/intrinsically_stable_moonwalk_ENHANCED/apollo15_landing_site_1000x1000/model-1_4.sdf");
  dart::gui::osg::Viewer viewer;
  viewer.addWorldNode(new dart::gui::osg::WorldNode(moon));
  viewer.simulate(true);

You need to put the dart::dynamics::WorldPtr into a dart::gui::osg::WorldNode instance.

1 Like