SDF readFile not parsing world file [closed]

asked 2018-03-20 09:19:57 -0600

dhindhimathai gravatar image

I am using ROS Indigo with Ubuntu 14.04.

I need to parse the elements of a simple_environment.world file using sdf::readFile. The simple_environment.world file is as follows:

<?xml version="1.0" ?>
<sdf version="1.4">
  <world name="default">
    <include>
      <uri>model://ground_plane</uri>
    </include>
    <include>
      <uri>model://sun</uri>
    </include>

    <model name="box">
    <pose>1.4 0.8 0.14 0 0 0</pose>
    <static>true</static>
    <link name='link_box'>
        <pose>0 0 0 0 0 0</pose>
        <collision name="collision_box">
            <pose>0 0 0 0 0 0</pose>
            <geometry>
                  <box>
                    <size>1 2 1.3</size>
                  </box>
                </geometry>
            </collision>

            <visual name="visual_box">
            <geometry>
                  <box>
                    <size>1 2 1.3</size>
                  </box>
                </geometry>
            </visual>

        <self_collide>0</self_collide>      
        <gravity>1</gravity>
    </link>
    </model>

  </world>
</sdf>

In a portion of my C++ code I try to parse the content of the world file as follows:

// Read the sdf
sdf::SDFPtr sdfParsed(new sdf::SDF());
sdf::init(sdfParsed);

const std::string sdfStringPath(argv[1]);

assert(sdf::readFile(sdfStringPath, sdfParsed));

But this does not seem to function as expected because if I try to print sdfParsed with

cout << "THE PARSED SDF IS: " << sdfParsed->ToString() << endl;

the output is the following:

THE PARSED SDF IS: <?xml version='1.0'?> <sdf version='1.5'/>

The argv[1] is clearly the path to the above mentioned .world file. What's wrong with my code?

Thanks in advance.

edit retag flag offensive reopen merge delete

Closed for the following reason Gazebo Question: The Gazebo community prefers to answer questions at: http://answers.gazebosim.org by gvdhoorn
close date 2018-03-20 09:50:33.666206

Comments

While not immediately about Gazebo itself, sdf is Gazebo's file format for simulations and the Gazebo devs are its developers. I recommend you post your question on their support forum as that will probably lead to better answers, faster.

gvdhoorn gravatar image gvdhoorn  ( 2018-03-20 09:51:27 -0600 )edit
1

Please do post a link to your question on Gazebo Answers, so we keep things connected.

gvdhoorn gravatar image gvdhoorn  ( 2018-03-20 09:51:43 -0600 )edit

https://answers.gazebosim.org//questi... the post on Gazebo Answers.

David-Alexandre gravatar image David-Alexandre  ( 2022-06-13 09:40:25 -0600 )edit