Skip to content

Add in support for a version tag.#133

Merged
scpeters merged 3 commits intomasterfrom
version-tag
Jan 13, 2020
Merged

Add in support for a version tag.#133
scpeters merged 3 commits intomasterfrom
version-tag

Conversation

@clalancette
Copy link
Copy Markdown
Contributor

This is already specified by the xsd, so just make sure we
implement it and enforce it in the code.

Signed-off-by: Chris Lalancette clalancette@openrobotics.org

@sloretz @scpeters FYI

This is already specified by the xsd, so just make sure we
implement it and enforce it in the code.

Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
@scpeters
Copy link
Copy Markdown
Contributor

looks good, just one minor suggestion about the error message

model->name_ = std::string(name);

float version = -1.0;
int version_ret = robot_xml->QueryFloatAttribute("version", &version);
Copy link
Copy Markdown
Contributor

@traversaro traversaro Nov 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QueryFloatAttribute uses sscanf for parsing the string to a float, so I am afraid it is not locale-safe and it will not behave correctly on system with a locale that does not use . as decimal separator, see ros/urdfdom_headers#41 and #98 .

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arg, you are right, of course. Thanks for pointing this out. But I'm going to address the bigger issue of how to store the version number from @scpeters before doing anything here.

@scpeters
Copy link
Copy Markdown
Contributor

I thought a little more about this, and do we want to parse to a float to store a version number? It won't be able to distinguish between 1.1 and 1.10

@clalancette
Copy link
Copy Markdown
Contributor Author

I thought a little more about this, and do we want to parse to a float to store a version number? It won't be able to distinguish between 1.1 and 1.10

Hm, good point. It also has the system locale problems pointed out.

I chose a float to store it since it would make comparisons (==, <, <=, >, >=) easy. Storing it as a string won't give us that property. I guess we could do a custom class where we parse the string into the part before and after the dot, then implement comparison operators on that class. What do you think of that proposal?

@traversaro
Copy link
Copy Markdown
Contributor

I thought a little more about this, and do we want to parse to a float to store a version number? It won't be able to distinguish between 1.1 and 1.10

Indeed, in the .xsd contained in the repo the type of the version attribute was already xs:string :

<xs:attribute name="version" type="xs:string" default="1.0" />
.

@scpeters
Copy link
Copy Markdown
Contributor

it would be great if c++ had a primitive type for version numbers, but without that a custom version number class sounds good to me. we already have a split_string function in urdfdom_headers:

@scpeters
Copy link
Copy Markdown
Contributor

should we add that class to urdfdom_headers or here?

The previous attempt used a float to store the version number.
That has two problems:

1.  It runs into locale issues, and
2.  The XSD specifies it as a string

This alternative introduces a class to do parsing of the version
string.  Besides conforming to the XSD, and getting us away
from the locale issues, it also allows us to provide additional
constraints on the version (like not allowing negative numbers).
The UDFVersion class ends up living in the header file so we
can write tests against it.

Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
@clalancette
Copy link
Copy Markdown
Contributor Author

So I just pushed commit 088bf6c, which implements a class for URDF version parsing. A few things to note:

  1. I left it in this repository (instead of urdfdom_headers as @scpeters proposed) because we currently don't need it outside of here. I guess we could eventually move it out of here, but I don't see the need right now.
  2. I didn't implement overloaded operators on the class. The only meaningful thing we could do with that is compare one class instance to another, and I thought it was easier to just implement an equals() method on the class where you could pass integers.
  3. I didn't implement anything but equals since we don't currently need anything else. We can add additional "operators" as needed.
  4. I ended up making the allowed version numbers more strict.
  5. I believe the hand parsing we are doing here should resolve the locale issues pointed out earlier, but verification of this would be great.

@scpeters @sloretz @traversaro Please take another look. Thanks!

Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
@scpeters
Copy link
Copy Markdown
Contributor

scpeters commented Dec 5, 2019

the equal() operator is fine while we only have one version, but I could imagine having some use for at_least and at_most functions (inspired by macros in dartsim config.hpp) once there are more versions to check against

@clalancette
Copy link
Copy Markdown
Contributor Author

the equal() operator is fine while we only have one version, but I could imagine having some use for at_least and at_most functions (inspired by macros in dartsim config.hpp) once there are more versions to check against

Right. I didn't implement them since there are no callers to them, and I don't like adding code that isn't currently used. I just figured we would implement them as we needed them. Alternatively, I guess I could add them in and just write tests for them. What do you think?

@scpeters
Copy link
Copy Markdown
Contributor

scpeters commented Dec 5, 2019

if the plan is to add them in the future when we have multiple versions, I guess that's fine

@scpeters scpeters merged commit 1aef805 into master Jan 13, 2020
@scpeters scpeters deleted the version-tag branch January 13, 2020 19:03
}

// We accept any of the following strings:
// 1
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this comment correct? It looks like the code below will throw runtime_error if the version is 1.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, that's an outdated comment. I can open a PR to fix that.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ros-discourse
Copy link
Copy Markdown

This pull request has been mentioned on ROS Discourse. There might be relevant details there:

https://discourse.ros.org/t/urdf-improvements/30520/6

@ros-discourse
Copy link
Copy Markdown

This pull request has been mentioned on ROS Discourse. There might be relevant details there:

https://discourse.ros.org/t/proposal-to-extend-jointlimits-in-urdf/42831/2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants