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

New pose proposal: support rotation in degrees (#252) #589

Merged
merged 36 commits into from
Sep 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
7d251f9
Added rotation type attribute to pose, handled parsing in param
aaronchongth Jun 11, 2021
6874cf7
Using degrees boolean attribute in pose instead, added tests and test…
aaronchongth Jun 11, 2021
582f80f
Fix code check
aaronchongth Jun 11, 2021
863b5c7
Changed attribute to @rotation_type, modified tests, added delimiters
aaronchongth Jun 28, 2021
81f7087
Passing attributes into param value parsing, reverted Utils loadPose …
aaronchongth Jul 8, 2021
347ae2e
Reverted location of parsing nested sdf
aaronchongth Jul 8, 2021
ec4a1a9
Added parent element for param, more tests
aaronchongth Jul 16, 2021
f3e091e
Const ref for GetAttributes and it's relevant calls
aaronchongth Jul 26, 2021
af8c132
Reverting clone and copy behavior without reallocating memory, using …
aaronchongth Jul 26, 2021
b15c01a
Compared parent element pointers instead of just the names
aaronchongth Jul 26, 2021
5fc22ae
Removed redundant reset, checked for null parent before printing error
aaronchongth Jul 26, 2021
a16a8b8
Moved tests from integration/param_parent_element to Param_TEST
aaronchongth Jul 26, 2021
3dab3f8
Reverting urdf.sdf, adding new pose_without_frames.sdf, using that in…
aaronchongth Jul 26, 2021
47257c2
Fixed typo, added explicit named default variable, made rotation type…
aaronchongth Jul 26, 2021
002cc42
Added comment in pose_1_9.sdf that each pose is independent
aaronchongth Jul 26, 2021
45c243e
Removed use of parsing by string, modified tests to reflect changed b…
aaronchongth Jul 26, 2021
00265ec
Reverted changes made to schema for poses that do not handle relative…
aaronchongth Jul 26, 2021
3e42314
ComCompare degrees more explicitly in tests instead of using IGN_DTOR
aaronchongth Jul 26, 2021
8c77695
Using consistent notation for reporting rotation_type attribute, modi…
aaronchongth Jul 26, 2021
3f14eed
Using instead of typedef for forward declaration, error strings inclu…
aaronchongth Jul 30, 2021
8fca41f
Using RedirectConsoleStream and ScopeExit, using Root and Root::LoadS…
aaronchongth Jul 30, 2021
9036104
Added Reparse function for Param, relevant tests regarding rotation_t…
aaronchongth Aug 3, 2021
8216bbb
Reducing changes to just the degrees attribute, modifying tests becau…
aaronchongth Aug 17, 2021
e970120
Merge branch 'main' into aaron/pose-configurable-rotation
aaronchongth Aug 18, 2021
99d8f99
Merge branch 'main' into aaron/pose-configurable-rotation
aaronchongth Aug 23, 2021
8251275
Fixed stale brief and comment, breaking for loops early
aaronchongth Aug 27, 2021
70e44e2
Changed 'required' of @relative_to and @degrees to 0, and modified de…
aaronchongth Aug 27, 2021
fbe2193
Modified reparsing tests in Param_TEST, added another test using Pose
aaronchongth Aug 27, 2021
6f148fa
Using alias Pose instead of full type name, added check for parent el…
aaronchongth Aug 27, 2021
9ac3504
Support printing pose elements in degrees, added tests
aaronchongth Aug 31, 2021
2099a3c
Removed const for SetParentElement
aaronchongth Sep 2, 2021
8602180
Adding additional documentation for the behavior between Set<T> and R…
aaronchongth Sep 2, 2021
b0daab5
Storing parsed tokens in array instead of vector
aaronchongth Sep 2, 2021
dabf47a
Used explicit Get<boo> for degrees attribute
aaronchongth Sep 2, 2021
181e925
Fixed missing array include for windows build
aaronchongth Sep 2, 2021
95c292e
Check for valueIndex, instead of array size
aaronchongth Sep 2, 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
4 changes: 4 additions & 0 deletions include/sdf/Element.hh
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,10 @@ namespace sdf
/// \return The number of attributes.
public: size_t GetAttributeCount() const;

/// \brief Get all the attribute params.
/// \return The vector of parameter attributes.
public: const Param_V &GetAttributes() const;

/// \brief Get an attribute using an index.
/// \param[in] _index the index of the attribute to get.
/// \return A Param pointer to the attribute.
Expand Down
54 changes: 53 additions & 1 deletion include/sdf/Param.hh
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ namespace sdf
inline namespace SDF_VERSION_NAMESPACE {
//

class SDFORMAT_VISIBLE Element;
using ElementPtr = std::shared_ptr<Element>;
using ElementWeakPtr = std::weak_ptr<Element>;

class SDFORMAT_VISIBLE Param;

/// \def ParamPtr
Expand Down Expand Up @@ -180,13 +184,44 @@ namespace sdf
/// of the parameter. nullopt otherwise.
public: std::optional<std::string> GetMaxValueAsString() const;

/// \brief Set the parameter value from a string.
/// \param[in] _value New value for the parameter in string form.
/// \param[in] _ignoreParentAttributes Whether to ignore parent element
/// attributes when parsing value from string as well as subsequent
/// reparses.
public: bool SetFromString(const std::string &_value,
bool _ignoreParentAttributes);

/// \brief Set the parameter value from a string.
/// \param[in] _value New value for the parameter in string form.
public: bool SetFromString(const std::string &_value);

/// \brief Get the parent Element of this Param.
/// \return Pointer to this Param's parent Element, nullptr if there is no
/// parent Element.
public: ElementPtr GetParentElement() const;

/// \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);

/// \brief Reset the parameter to the default value.
public: void Reset();

/// \brief Reparse the parameter value. This should be called after the
/// parent element's attributes have been modified, in the event that the
/// value was set using SetFromString or posesses a default value, and that
/// the final parsed value is dependent on the attributes of the parent
/// element. For example, the rotation component of a pose element can
/// be parsed as degrees or radians, depending on the attribute @degrees
/// of the parent element. If however the value was explicitly set using the
/// Set<T> function, reparsing would not change the value.
/// \return True if the parameter value has been reparsed successfully.
/// \sa bool SetFromString(const std::string &_value)
/// \sa bool Set(const T &_value)
public: bool Reparse();

/// \brief Get the key value.
/// \return The key.
public: const std::string &GetKey() const;
Expand All @@ -209,6 +244,12 @@ namespace sdf
/// \return True if the parameter has been set.
public: bool GetSet() const;

/// \brief Return true if the parameter ignores the parent element's
/// attributes, or if the parameter has no parent element.
/// \return True if the parameter ignores the parent element's attributes,
/// or if the parameter has no parent element.
public: bool IgnoresParentElementAttribute() const;

/// \brief Clone the parameter.
/// \return A new parameter that is the clone of this.
public: ParamPtr Clone() const;
Expand Down Expand Up @@ -301,6 +342,9 @@ namespace sdf
/// \brief Description of the parameter.
public: std::string description;

/// \brief Parent element.
public: ElementWeakPtr parentElement;

/// \brief Update function pointer.
public: std::function<std::any ()> updateFunc;

Expand All @@ -319,6 +363,14 @@ namespace sdf
/// \brief This parameter's value
public: ParamVariant value;

/// \brief True if the value has been parsed while ignoring its parent
/// element's attributes, and will continue to ignore them for subsequent
/// reparses.
public: bool ignoreParentAttributes;

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

/// \brief This parameter's default value
public: ParamVariant defaultValue;

Expand Down Expand Up @@ -399,7 +451,7 @@ namespace sdf
{
std::stringstream ss;
ss << _value;
return this->SetFromString(ss.str());
return this->SetFromString(ss.str(), true);
}
catch(...)
{
Expand Down
14 changes: 11 additions & 3 deletions sdf/1.9/pose.sdf
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
<!-- Pose -->
<element name="pose" type="pose" default="0 0 0 0 0 0" required="0">
<description>A position(x,y,z) and orientation(roll, pitch yaw) with respect to the frame named in the relative_to attribute.</description>
<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 intrinsic Euler rotations.
</description>

<attribute name="relative_to" type="string" default="" required="*">
<attribute name="relative_to" type="string" default="" required="0">
<description>
Name of frame relative to which the pose is applied.
</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> <!-- End Pose -->
20 changes: 17 additions & 3 deletions src/Element.cc
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ 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());
}

/////////////////////////////////////////////////
Expand All @@ -161,8 +162,10 @@ ParamPtr Element::CreateParam(const std::string &_key,
bool _required,
const std::string &_description)
{
return ParamPtr(
new Param(_key, _type, _defaultValue, _required, _description));
ParamPtr param = std::make_shared<Param>(
_key, _type, _defaultValue, _required, _description);
param->SetParentElement(shared_from_this());
return param;
}

/////////////////////////////////////////////////
Expand Down Expand Up @@ -195,7 +198,9 @@ ElementPtr Element::Clone() const
for (aiter = this->dataPtr->attributes.begin();
aiter != this->dataPtr->attributes.end(); ++aiter)
{
clone->dataPtr->attributes.push_back((*aiter)->Clone());
auto clonedAttribute = (*aiter)->Clone();
clonedAttribute->SetParentElement(clone);
clone->dataPtr->attributes.push_back(clonedAttribute);
}

ElementPtr_V::const_iterator eiter;
Expand All @@ -215,6 +220,7 @@ ElementPtr Element::Clone() const
if (this->dataPtr->value)
{
clone->dataPtr->value = this->dataPtr->value->Clone();
clone->dataPtr->value->SetParentElement(clone);
}

if (this->dataPtr->includeElement)
Expand Down Expand Up @@ -248,6 +254,7 @@ void Element::Copy(const ElementPtr _elem)
}
ParamPtr param = this->GetAttribute((*iter)->GetKey());
(*param) = (**iter);
param->SetParentElement(shared_from_this());
}

if (_elem->GetValue())
Expand All @@ -260,6 +267,7 @@ void Element::Copy(const ElementPtr _elem)
{
*(this->dataPtr->value) = *(_elem->GetValue());
}
this->dataPtr->value->SetParentElement(shared_from_this());
}

this->dataPtr->elementDescriptions.clear();
Expand Down Expand Up @@ -657,6 +665,12 @@ size_t Element::GetAttributeCount() const
return this->dataPtr->attributes.size();
}

/////////////////////////////////////////////////
const Param_V &Element::GetAttributes() const
{
return this->dataPtr->attributes;
}

/////////////////////////////////////////////////
ParamPtr Element::GetAttribute(unsigned int _index) const
{
Expand Down
Loading