-
Notifications
You must be signed in to change notification settings - Fork 30
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
Add StateSaver class. #184
Merged
Merged
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ce5372c
Add RAII StateSaver class to save position.
brianhou 2068061
Rename and move class to aikido::statespace::dart.
brianhou c6d21d7
Merge branch 'master' into enhancement/brianhou/state-saver
jslee02 acae85d
Add some error-checking for StateSaver.
brianhou 0a0de98
Merge branch 'enhancement/brianhou/state-saver' of github.com:persona…
brianhou e5e1b8d
Merge branch 'master' into enhancement/brianhou/state-saver
brianhou 7ec3194
Fix bugs.
brianhou 87344e3
Merge branch 'enhancement/brianhou/state-saver' of github.com:persona…
brianhou 412feea
Merge branch 'master' into enhancement/brianhou/state-saver
mkoval File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
include/aikido/statespace/dart/MetaSkeletonStateSpaceSaver.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#ifndef AIKIDO_STATESPACE_DART_METASKELETONSTATESPACESAVER_HPP_ | ||
#define AIKIDO_STATESPACE_DART_METASKELETONSTATESPACESAVER_HPP_ | ||
#include "MetaSkeletonStateSpace.hpp" | ||
|
||
namespace aikido { | ||
namespace statespace { | ||
namespace dart { | ||
|
||
/// RAII class to save and restore a MetaSkeletonStateSpace's state. | ||
/// FIXME: currently only saves position. | ||
class MetaSkeletonStateSpaceSaver | ||
{ | ||
public: | ||
|
||
/// Construct a MetaSkeletonStateSpaceSaver and save the current state of the | ||
/// \c MetaSkeletonStateSpace. This state will be restored when | ||
/// MetaSkeletonStateSpaceSaver is destructed. | ||
/// | ||
/// \param _space MetaSkeletonStateSpace to save/restore | ||
explicit MetaSkeletonStateSpaceSaver(MetaSkeletonStateSpacePtr _space); | ||
|
||
virtual ~MetaSkeletonStateSpaceSaver(); | ||
|
||
// MetaSkeletonStateSpaceSaver is uncopyable, must use std::move | ||
MetaSkeletonStateSpaceSaver(const MetaSkeletonStateSpaceSaver&) = delete; | ||
MetaSkeletonStateSpaceSaver& operator =(const MetaSkeletonStateSpaceSaver&) = delete; | ||
|
||
MetaSkeletonStateSpaceSaver(MetaSkeletonStateSpaceSaver&&) = default; | ||
MetaSkeletonStateSpaceSaver& operator =(MetaSkeletonStateSpaceSaver&&) = default; | ||
|
||
private: | ||
MetaSkeletonStateSpacePtr mSpace; | ||
Eigen::VectorXd mPositions; | ||
}; | ||
|
||
} // namespace dart | ||
} // namespace statespace | ||
} // namespace aikido | ||
|
||
#include "detail/MetaSkeletonStateSpaceSaver-impl.hpp" | ||
|
||
#endif // ifndef AIKIDO_STATESPACE_DART_METASKELETONSTATESPACESAVER_HPP_ |
23 changes: 23 additions & 0 deletions
23
include/aikido/statespace/dart/detail/MetaSkeletonStateSpaceSaver-impl.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
namespace aikido { | ||
namespace statespace { | ||
namespace dart { | ||
|
||
MetaSkeletonStateSpaceSaver::MetaSkeletonStateSpaceSaver(MetaSkeletonStateSpacePtr _space) | ||
: mSpace(std::move(_space)) | ||
, mPositions(mSpace->getMetaSkeleton()->getPositions()) | ||
{ | ||
} | ||
|
||
MetaSkeletonStateSpaceSaver::~MetaSkeletonStateSpaceSaver() | ||
{ | ||
if (mPositions.size() != mSpace->getMetaSkeleton().getNumDofs()) | ||
{ | ||
dtwarn << "[MetaSkeletonStateSpaceSaver] The number of DOFs in the " | ||
<< "MetaSkeleton does not match the saved state."; | ||
} | ||
mSpace->getMetaSkeleton()->setPositions(mPositions); | ||
} | ||
|
||
} // namespace dart | ||
} // namespace statespace | ||
} // namespace aikido |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: It would be nice if we have a simple validity check whether the size of
mPositions
is still equal to the dofs of theMetaSkeleton
(if not, we print a warning). I understand it wouldn't be able to catch other structural changes such as changing the joint type with the same dofs, but at least we could catch dimension changing cases.