Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support quaternions representation for poses #690

Merged
merged 25 commits into from
Sep 21, 2021
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
83449e5
Added attribute @rotation_format to //pose, supporting rpy and q_wxyz
aaronchongth Sep 7, 2021
dc2da47
Param parsing rotation_format
aaronchongth Sep 14, 2021
22a6614
Added rotation_format to testing sdf and added integration test
aaronchongth Sep 14, 2021
2059da8
SetParentElement to return bool, added tests to handle quat_wxyz
aaronchongth Sep 14, 2021
a23dad4
Fixed tests comparing string outputs, added else case to parsing empt…
aaronchongth Sep 15, 2021
9ace44d
Added asserts to setting parent elements to params
aaronchongth Sep 16, 2021
6f94f1d
Added further tests for SetParentElement API and switching between ro…
aaronchongth Sep 16, 2021
3c151fa
Switched to quat_xyzw
aaronchongth Sep 16, 2021
df7ee2c
Fixed missing degrees attribute test
aaronchongth Sep 16, 2021
ea6729f
Added other representations in include tests
aaronchongth Sep 16, 2021
d59b65f
Reverted removed curly braces, added quotations to rotation formats i…
aaronchongth Sep 17, 2021
ae796a6
Reverted modifications of past tests that may break downstream tests
aaronchongth Sep 19, 2021
7e017fc
Changing name of test to be more explicit
aaronchongth Sep 20, 2021
d78976a
Correcting pose parsing logic, checking attributes at the start, remo…
aaronchongth Sep 20, 2021
0fdcd97
Added defaultValueStr field for use in Reset, changed strValue to std…
aaronchongth Sep 20, 2021
2250af4
Added checks for attributes in readXml, as there are pose elements th…
aaronchongth Sep 20, 2021
23fce80
Fixing tests to expect default values as defined in sdf/1.9/*.sdf
aaronchongth Sep 20, 2021
c600f48
Changing default rotation_format as empty string to test setting to e…
aaronchongth Sep 20, 2021
40d670a
Reparsing if no value was stated in xml, only modifying strValue if t…
aaronchongth Sep 20, 2021
7b09f70
Adding tests for bad pose representations, removing bad representatio…
aaronchongth Sep 20, 2021
fcac14d
Add @rotation_format and @degrees to //inertial/pose
azeey Sep 20, 2021
69a0f57
Merge remote-tracking branch 'upstream/main' into aaron/pose-quaterni…
azeey Sep 20, 2021
1f542c4
Address reviewer feedback
azeey Sep 20, 2021
ae929b5
Change ASSERT_EQ to EXPECT_EQ
azeey Sep 20, 2021
697d143
Fix test models
azeey Sep 21, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions include/sdf/Param.hh
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,9 @@ namespace sdf
/// \brief Set the parent Element of this Param.
/// \param[in] _parentElement Pointer to new parent Element. A nullptr can
/// provided to remove the current parent Element.
public: void SetParentElement(ElementPtr _parentElement);
/// \return True if the parent Element was set and the value was reparsed
/// successfully.
public: bool SetParentElement(ElementPtr _parentElement);

/// \brief Reset the parameter to the default value.
public: void Reset();
Expand Down Expand Up @@ -371,7 +373,10 @@ namespace sdf
public: bool ignoreParentAttributes;

/// \brief This parameter's value that was provided as a string
public: std::optional<std::string> strValue;
public: std::string strValue;

/// \brief This parameter's default value that was provided as a string
public: std::string defaultStrValue;

/// \brief This parameter's default value
public: ParamVariant defaultValue;
Expand Down
18 changes: 17 additions & 1 deletion sdf/1.9/inertial.sdf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,23 @@
</element>

<element name="pose" type="pose" default="0 0 0 0 0 0" required="0">
<description>This is the pose of the inertial reference frame. The origin of the inertial reference frame needs to be at the center of gravity. The axes of the inertial reference frame do not need to be aligned with the principal axes of the inertia.</description>
<description>
A pose (translation, rotation) expressed in the frame of the link. The first three components (x, y, z) represent the position of the element's origin (in the @relative_to frame). The rotation component represent the orientation of the element as either a sequence of Euler rotations (r, p, y), see http://sdformat.org/tutorials?tut=specify_pose, or as a quaternion (x, y, z, w), where w is the real component.
</description>

<attribute name="rotation_format" type="string" default="euler_rpy" required="0">
<description>'euler_rpy' by default. Supported rotation formats are
'euler_rpy', Euler angles representation in roll, pitch, yaw. The pose is expected to have 6 values.
'quat_xyzw', Quaternion representation in x, y, z, w. The pose is expected to have 7 values.
</description>
</attribute>

<attribute name="degrees" type="bool" default="false" required="0">
<description>
Whether or not the euler angles are in degrees, otherwise they will be interpreted as radians by default.
</description>
</attribute>

</element>

<element name="inertia" required="0">
Expand Down
11 changes: 9 additions & 2 deletions sdf/1.9/pose.sdf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!-- Pose -->
<element name="pose" type="pose" default="0 0 0 0 0 0" required="0">
<element name="pose" type="pose" default="0 0 0 0 0 0" required="0">
<description>
A pose (x, y, z, r, p, y) expressed in the frame named by @relative_to. The first three components (x, y, z) represent the position of the element's origin (in the @relative_to frame) and the last three components (roll, pitch, yaw) represent the orientation of the element as a sequence of Euler rotations. See http://sdformat.org/tutorials?tut=specify_pose.
A pose (translation, rotation) expressed in the frame named by @relative_to. The first three components (x, y, z) represent the position of the element's origin (in the @relative_to frame). The rotation component represent the orientation of the element as either a sequence of Euler rotations (r, p, y), see http://sdformat.org/tutorials?tut=specify_pose, or as a quaternion (x, y, z, w), where w is the real component.
</description>

<attribute name="relative_to" type="string" default="" required="0">
Expand All @@ -10,6 +10,13 @@
</description>
</attribute>

<attribute name="rotation_format" type="string" default="euler_rpy" required="0">
<description>'euler_rpy' by default. Supported rotation formats are
'euler_rpy', Euler angles representation in roll, pitch, yaw. The pose is expected to have 6 values.
'quat_xyzw', Quaternion representation in x, y, z, w. The pose is expected to have 7 values.
</description>
</attribute>

<attribute name="degrees" type="bool" default="false" required="0">
<description>
Whether or not the euler angles are in degrees, otherwise they will be interpreted as radians by default.
Expand Down
19 changes: 13 additions & 6 deletions src/Element.cc
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ void Element::AddValue(const std::string &_type,
this->dataPtr->value =
std::make_shared<Param>(this->dataPtr->name, _type, _defaultValue,
_required, _minValue, _maxValue, _description);
this->dataPtr->value->SetParentElement(shared_from_this());
SDF_ASSERT(this->dataPtr->value->SetParentElement(shared_from_this()),
"Cannot set parent Element of value to itself.");
}

/////////////////////////////////////////////////
Expand All @@ -164,7 +165,8 @@ ParamPtr Element::CreateParam(const std::string &_key,
{
ParamPtr param = std::make_shared<Param>(
_key, _type, _defaultValue, _required, _description);
param->SetParentElement(shared_from_this());
SDF_ASSERT(param->SetParentElement(shared_from_this()),
"Cannot set parent Element of created Param to itself.");
return param;
}

Expand Down Expand Up @@ -199,7 +201,9 @@ ElementPtr Element::Clone() const
aiter != this->dataPtr->attributes.end(); ++aiter)
{
auto clonedAttribute = (*aiter)->Clone();
clonedAttribute->SetParentElement(clone);
SDF_ASSERT(clonedAttribute->SetParentElement(clone),
"Cannot set parent Element of cloned attribute Param to cloned "
"Element.");
clone->dataPtr->attributes.push_back(clonedAttribute);
}

Expand All @@ -220,7 +224,8 @@ ElementPtr Element::Clone() const
if (this->dataPtr->value)
{
clone->dataPtr->value = this->dataPtr->value->Clone();
clone->dataPtr->value->SetParentElement(clone);
SDF_ASSERT(clone->dataPtr->value->SetParentElement(clone),
"Cannot set parent Element of cloned value Param to cloned Element.");
}

if (this->dataPtr->includeElement)
Expand Down Expand Up @@ -254,7 +259,8 @@ void Element::Copy(const ElementPtr _elem)
}
ParamPtr param = this->GetAttribute((*iter)->GetKey());
(*param) = (**iter);
param->SetParentElement(shared_from_this());
SDF_ASSERT(param->SetParentElement(shared_from_this()),
"Cannot set parent Element of copied attribute Param to itself.");
}

if (_elem->GetValue())
Expand All @@ -267,7 +273,8 @@ void Element::Copy(const ElementPtr _elem)
{
*(this->dataPtr->value) = *(_elem->GetValue());
}
this->dataPtr->value->SetParentElement(shared_from_this());
SDF_ASSERT(this->dataPtr->value->SetParentElement(shared_from_this()),
"Cannot set parent Element of copied value Param to itself.");
}

this->dataPtr->elementDescriptions.clear();
Expand Down
Loading