Skip to content

Commit

Permalink
Add field use_parent_model_frame that defaults to false but is set to…
Browse files Browse the repository at this point in the history
… true when converting from 1.4 to 1.5 to fix #43 (gazebo issue 494)
  • Loading branch information
scpeters committed Jan 8, 2014
1 parent bb63bd6 commit 600d4f6
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 45 deletions.
11 changes: 9 additions & 2 deletions include/sdf/Converter.hh
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,22 @@ namespace sdf
/// \param[in] _renameElem A 'convert' element that describes the rename
/// operation.
private: static void Rename(TiXmlElement *_elem,
TiXmlElement *_renameElem);
TiXmlElement *_renameElem);

/// \brief Move an element or attribute within a common ancestor element.
/// \param[in] _elem Ancestor element of the element or attribute to
/// be moved.
/// \param[in] _moveElem A 'convert' element that describes the move
/// operation.
private: static void Move(TiXmlElement *_elem,
TiXmlElement *_moveElem);
TiXmlElement *_moveElem);

/// \brief Add an element or attribute to an element.
/// \param[in] _elem The element to receive the value.
/// \param[in] _addElem A 'convert' element that describes the add
/// operation.
private: static void Add(TiXmlElement *_elem,
TiXmlElement *_addElem);

private: static const char *GetValue(const char *_valueElem,
const char *_valueAttr,
Expand Down
53 changes: 14 additions & 39 deletions sdf/1.5/1_4.convert
Original file line number Diff line number Diff line change
@@ -1,54 +1,29 @@
<convert name="sdf">
<convert name="world">
<!--
<convert name="physics">
<move>
<from element="update_rate"/>
<to element="real_time_update_rate"/>
</move>
<move>
<from element="ode::solver::dt"/>
<to element="max_step_size"/>
</move>
<move>
<from element="bullet::dt"/>
<to element="max_step_size"/>
</move>
</convert>
-->

<!-- See comments joint.sdf about poses in joints -->
<!--
<convert name="world">
<!-- Add use_parent_model_frame=true for 1.4 joints -->
<convert name="model">
<convert name="joint">
<move>
<from element="parent"/>
<to element="parent::link_name"/>
</move>
<move>
<from element="child"/>
<to element="child::link_name"/>
</move>
<convert name="axis">
<add element="use_parent_model_frame" value="true"/>
</convert>
<convert name="axis2">
<add element="use_parent_model_frame" value="true"/>
</convert>
</convert>
</convert>
-->
</convert>

<!-- for model sdfs -->
<!-- See comments joint.sdf about poses in joints -->
<!--
<convert name="model">
<convert name="joint">
<move>
<from element="parent"/>
<to element="parent::link_name"/>
</move>
<move>
<from element="child"/>
<to element="child::link_name"/>
</move>
<convert name="axis">
<add element="use_parent_model_frame" value="true"/>
</convert>
<convert name="axis2">
<add element="use_parent_model_frame" value="true"/>
</convert>
</convert>
</convert>
-->

</convert> <!-- End SDF -->
35 changes: 31 additions & 4 deletions sdf/1.5/joint.sdf
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,23 @@
</element>

<element name="axis" required="1">
<description>The joint axis specified in the parent model frame. This is the axis of rotation for revolute joints, the axis of translation for prismatic joints. The axis is currently specified in the parent model frame of reference, but this will be changed to the joint frame in future version of sdf (see gazebo issue #494).</description>
<description>
Parameters related to the axis of rotation for revolute joints,
the axis of translation for prismatic joints.
</description>
<element name="xyz" type="vector3" default="0 0 1" required="1">
<description>Represents the x,y,z components of a vector. The vector should be normalized.</description>
<description>
Represents the x,y,z components of the axis unit vector. The axis is
expressed in the child link frame unless the use_parent_model_frame
flag is set to true. The vector should be normalized.
</description>
</element>
<element name="use_parent_model_frame" type="bool" default="false" required="0">
<description>
Flag to interpret the axis xyz element in the parent model frame instead
of child link frame. Provided for Gazebo compatibility
(see https://bitbucket.org/osrf/gazebo/issue/494 ).
</description>
</element>
<element name="dynamics" required="0">
<description>An element specifying physical properties of the joint. These values are used to specify modeling properties of the joint, particularly useful for simulation.</description>
Expand Down Expand Up @@ -75,9 +89,22 @@
</element> <!-- End Axis -->

<element name="axis2" required="0">
<description>The second joint axis specified in the parent model frame. This is the second axis of rotation for revolute2 joints and universal joints. The axis is currently specified in the parent model frame of reference, but this will be changed to the joint frame in future version of sdf (see gazebo issue #494).</description>
<description>
Parameters related to the second axis of rotation for revolute2 joints and universal joints.
</description>
<element name="xyz" type="vector3" default="0 0 1" required="1">
<description>Represents the x,y,z components of a vector. The vector should be normalized.</description>
<description>
Represents the x,y,z components of the axis unit vector. The axis is
expressed in the child link frame unless the use_parent_model_frame
flag is set to true. The vector should be normalized.
</description>
</element>
<element name="use_parent_model_frame" type="bool" default="false" required="0">
<description>
Flag to interpret the axis xyz element in the parent model frame instead
of child link frame. Provided for Gazebo compatibility
(see https://bitbucket.org/osrf/gazebo/issue/494 ).
</description>
</element>
<element name="dynamics" required="0">
<description>An element specifying physical properties of the joint. These values are used to specify modeling properties of the joint, particularly useful for simulation.</description>
Expand Down
41 changes: 41 additions & 0 deletions src/Converter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,12 @@ void Converter::ConvertImpl(TiXmlElement *_elem, TiXmlElement *_convert)
{
Move(_elem, moveElem);
}

for (TiXmlElement *addElem = _convert->FirstChildElement("add");
addElem; addElem = addElem->NextSiblingElement("add"))
{
Add(_elem, addElem);
}
}

/////////////////////////////////////////////////
Expand Down Expand Up @@ -222,6 +228,41 @@ void Converter::Rename(TiXmlElement *_elem, TiXmlElement *_renameElem)
}
}

/////////////////////////////////////////////////
void Converter::Add(TiXmlElement *_elem, TiXmlElement *_addElem)
{
SDF_ASSERT(_elem != NULL, "SDF element is NULL");
SDF_ASSERT(_addElem != NULL, "Add element is NULL");

const char *attributeName = _addElem->Attribute("attribute");
const char *elementName = _addElem->Attribute("element");
const char *value = _addElem->Attribute("value");

if (!value)
{
sdferr << "No 'value' specified in <add>\n";
return;
}
if (!(attributeName == NULL ^ elementName == NULL))
{
sdferr << "Exactly one 'element' or 'attribute'"
<< " must be specified in <add>\n";
return;
}

if (attributeName)
{
_elem->SetAttribute(attributeName, value);
}
else
{
TiXmlElement *addElem = new TiXmlElement(elementName);
TiXmlText *addText = new TiXmlText(value);
addElem->LinkEndChild(addText);
_elem->LinkEndChild(addElem);
}
}

/////////////////////////////////////////////////
void Converter::Move(TiXmlElement *_elem, TiXmlElement *_moveElem)
{
Expand Down

0 comments on commit 600d4f6

Please sign in to comment.