ros / urdf

Repository for URDF parsing code
63 stars 41 forks source link

Only the integer part of the float matters in sizes! #21

Closed gstavrinos closed 6 years ago

gstavrinos commented 6 years ago

A simple example to show this bug is the following:

`

<link name="base_link">

  <visual>

    <geometry>

      <box size="1 1 1"/>

    </geometry>

    <origin xyz="0 0 0"/>

    <material name="black"/>

  </visual>

</link>

`

The example above works like a charm. If you use the following, the y dimension is equal to 0, even though it should be 0.9:

`

<link name="base_link">

  <visual>

    <geometry>

      <box size="1 0.9 1"/>

    </geometry>

    <origin xyz="0 0 0"/>

    <material name="black"/>

  </visual>

</link>

`

Finally, with this description the box is completely invisible:

`

<link name="base_link">

  <visual>

    <geometry>

      <box size="0.3 0.9 0.2"/>

    </geometry>

    <origin xyz="0 0 0"/>

    <material name="black"/>

  </visual>

</link>`

I am using a super vanilla version of ROS Melodic.

gstavrinos commented 6 years ago

I just realized that I am experiencing the same bug for origin values too!

sloretz commented 6 years ago

Hi @gstavrinos, would you mind posting steps to reproduce? I'm unable to reproduce it.

I added this test to one of the test files.

TEST(model_parser_initxml, floating_point_values)
{
static const std::string good_robot{"<robot name=\"myrobot\">"
                                    "  <link name=\"one_link\">"
                                    "    <visual>"
                                    "      <origin xyz=\"1.2 1.3 1.4\" rpy=\"0.2 0.3 0.4\"/>"
                                    "      <geometry>"
                                    "        <box size=\"1.2 1.3 1.4\"/>"
                                    "      </geometry>"
                                    "    </visual>"
                                    "  </link>"
                                    "</robot>"};
  urdf::Model model;
  ASSERT_TRUE(model.initString(good_robot));

  auto pose = model.getLink("one_link")->visual->origin;
  EXPECT_DOUBLE_EQ(1.2, pose.position.x);
  EXPECT_DOUBLE_EQ(1.3, pose.position.y);
  EXPECT_DOUBLE_EQ(1.4, pose.position.z);

  auto * box_geometry = dynamic_cast<urdf::Box *>(model.getLink("one_link")->visual->geometry.get());

  EXPECT_DOUBLE_EQ(1.2, box_geometry->dim.x);
  EXPECT_DOUBLE_EQ(1.3, box_geometry->dim.y);
  EXPECT_DOUBLE_EQ(1.4, box_geometry->dim.z);
}

And it appears to work fine when running catkin run_tests

[ RUN      ] model_parser_initxml.floating_point_values
[       OK ] model_parser_initxml.floating_point_values (0 ms)
mikaelarguedas commented 6 years ago

Are you using a locale that uses , instead of . for decimal points? this looks related to https://github.com/ros/urdfdom_headers/issues/45

There is also a workaround at https://github.com/ros-visualization/rviz/issues/1151#issuecomment-345687074

gstavrinos commented 6 years ago

I am currently in a ROS Kinetic machine, and I can't reproduce the problem. I will post a proper comment as soon as I get my hands on my ROS Melodic machine.

What I can say for now, is that the same urdf file was working on Kinetic but wasn't on Melodic. It could be a locale thingy of the OS setup. I will check that too, and get back to both of you. Thanks for your help, guys.

gstavrinos commented 6 years ago

I confirm that the links Mike sent are related to the bug I am experiencing. The workaround is not working, but at least I know where to look for a future fix. Seems like Kinetic will have to stay for some time!

Thanks you both!