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

Add StateSaver class. #184

Merged
merged 9 commits into from
Apr 23, 2017
42 changes: 42 additions & 0 deletions include/aikido/statespace/dart/MetaSkeletonStateSpaceSaver.hpp
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_
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);
Copy link
Member

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 the MetaSkeleton (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.

}

} // namespace dart
} // namespace statespace
} // namespace aikido