Skip to content

Commit

Permalink
Add prefix 'Rn-' to ConstantSampler
Browse files Browse the repository at this point in the history
  • Loading branch information
jslee02 committed Apr 4, 2017
1 parent 4610d94 commit 3715bc3
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 45 deletions.
1 change: 0 additions & 1 deletion include/aikido/constraint/Sampleable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ class SampleGenerator {

using SampleablePtr = std::shared_ptr<Sampleable>;


} // namespace constraint
} // namespace aikido

Expand Down
37 changes: 27 additions & 10 deletions include/aikido/constraint/detail/JointStateSpaceHelpers-impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "../uniform/RnBoxConstraint.hpp"
#include "../uniform/SO2UniformSampler.hpp"
#include "../uniform/SO3UniformSampler.hpp"
#include "../uniform/ConstantSampler.hpp"
#include "../uniform/RnConstantSampler.hpp"
#include "../Satisfied.hpp"

namespace aikido {
Expand Down Expand Up @@ -94,6 +94,7 @@ std::unique_ptr<OutputConstraint> createBoxConstraint(
std::move(_stateSpace));
}

//=============================================================================
template <>
struct createDifferentiableFor_impl<statespace::dart::RnJoint>
{
Expand All @@ -106,6 +107,7 @@ struct createDifferentiableFor_impl<statespace::dart::RnJoint>
}
};

//=============================================================================
template <>
struct createTestableFor_impl<statespace::dart::RnJoint>
{
Expand All @@ -119,6 +121,7 @@ struct createTestableFor_impl<statespace::dart::RnJoint>
}
};

//=============================================================================
template <>
struct createProjectableFor_impl<statespace::dart::RnJoint>
{
Expand All @@ -132,6 +135,7 @@ struct createProjectableFor_impl<statespace::dart::RnJoint>
}
};

//=============================================================================
template <>
struct createSampleableFor_impl<statespace::dart::RnJoint>
{
Expand Down Expand Up @@ -170,6 +174,7 @@ struct createDifferentiableFor_impl<statespace::dart::SO2Joint>
}
};

//=============================================================================
template <>
struct createTestableFor_impl<statespace::dart::SO2Joint>
{
Expand All @@ -186,6 +191,7 @@ struct createTestableFor_impl<statespace::dart::SO2Joint>
}
};

//=============================================================================
template <>
struct createProjectableFor_impl<statespace::dart::SO2Joint>
{
Expand All @@ -202,6 +208,7 @@ struct createProjectableFor_impl<statespace::dart::SO2Joint>
}
};

//=============================================================================
template <>
struct createSampleableFor_impl<statespace::dart::SO2Joint>
{
Expand Down Expand Up @@ -237,6 +244,7 @@ struct createDifferentiableFor_impl<statespace::dart::SO3Joint>
}
};

//=============================================================================
template <>
struct createTestableFor_impl<statespace::dart::SO3Joint>
{
Expand All @@ -253,6 +261,7 @@ struct createTestableFor_impl<statespace::dart::SO3Joint>
}
};

//=============================================================================
template <>
struct createProjectableFor_impl<statespace::dart::SO3Joint>
{
Expand All @@ -269,6 +278,7 @@ struct createProjectableFor_impl<statespace::dart::SO3Joint>
}
};

//=============================================================================
template <>
struct createSampleableFor_impl<statespace::dart::SO3Joint>
{
Expand Down Expand Up @@ -300,6 +310,7 @@ struct createDifferentiableFor_impl<statespace::dart::SE2Joint>
}
};

//=============================================================================
template <>
struct createTestableFor_impl<statespace::dart::SE2Joint>
{
Expand All @@ -313,6 +324,7 @@ struct createTestableFor_impl<statespace::dart::SE2Joint>
}
};

//=============================================================================
template <>
struct createProjectableFor_impl<statespace::dart::SE2Joint>
{
Expand All @@ -326,6 +338,7 @@ struct createProjectableFor_impl<statespace::dart::SE2Joint>
}
};

//=============================================================================
template <>
struct createSampleableFor_impl<statespace::dart::SE2Joint>
{
Expand Down Expand Up @@ -354,6 +367,7 @@ struct createDifferentiableFor_impl<statespace::dart::SE3Joint>
}
};

//=============================================================================
template <>
struct createTestableFor_impl<statespace::dart::SE3Joint>
{
Expand All @@ -367,6 +381,7 @@ struct createTestableFor_impl<statespace::dart::SE3Joint>
}
};

//=============================================================================
template <>
struct createProjectableFor_impl<statespace::dart::SE3Joint>
{
Expand All @@ -380,6 +395,7 @@ struct createProjectableFor_impl<statespace::dart::SE3Joint>
}
};

//=============================================================================
template <>
struct createSampleableFor_impl<statespace::dart::SE3Joint>
{
Expand All @@ -398,12 +414,12 @@ struct createSampleableFor_impl<statespace::dart::SE3Joint>
template <class OutputConstraint>
std::unique_ptr<OutputConstraint> createBoxConstraint(
std::shared_ptr<statespace::dart::WeldJoint> _stateSpace,
std::unique_ptr<util::RNG> _rng)
std::unique_ptr<util::RNG> /*_rng*/)
{
return dart::common::make_unique<Satisfied>(
std::move(_stateSpace));
return dart::common::make_unique<Satisfied>(std::move(_stateSpace));
}

//=============================================================================
template <>
struct createDifferentiableFor_impl<statespace::dart::WeldJoint>
{
Expand All @@ -416,6 +432,7 @@ struct createDifferentiableFor_impl<statespace::dart::WeldJoint>
}
};

//=============================================================================
template <>
struct createTestableFor_impl<statespace::dart::WeldJoint>
{
Expand All @@ -424,11 +441,11 @@ struct createTestableFor_impl<statespace::dart::WeldJoint>

static std::unique_ptr<Testable> create(StateSpacePtr _stateSpace)
{
return createBoxConstraint<Testable>(
std::move(_stateSpace), nullptr);
return createBoxConstraint<Testable>(std::move(_stateSpace), nullptr);
}
};

//=============================================================================
template <>
struct createProjectableFor_impl<statespace::dart::WeldJoint>
{
Expand All @@ -437,24 +454,24 @@ struct createProjectableFor_impl<statespace::dart::WeldJoint>

static std::unique_ptr<Projectable> create(StateSpacePtr _stateSpace)
{
return createBoxConstraint<Projectable>(
std::move(_stateSpace), nullptr);
return createBoxConstraint<Projectable>(std::move(_stateSpace), nullptr);
}
};

//=============================================================================
template <>
struct createSampleableFor_impl<statespace::dart::WeldJoint>
{
using StateSpace = statespace::dart::WeldJoint;
using StateSpacePtr = std::shared_ptr<StateSpace>;

static std::unique_ptr<Sampleable> create(
StateSpacePtr _stateSpace, std::unique_ptr<util::RNG> _rng)
StateSpacePtr _stateSpace, std::unique_ptr<util::RNG> /*_rng*/)
{
const auto joint = _stateSpace->getJoint();
Eigen::VectorXd positions = joint->getPositions();

return dart::common::make_unique<ConstantSampler>(
return dart::common::make_unique<RnConstantSampler>(
std::move(_stateSpace), positions);
}
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef AIKIDO_CONSTRAINT_CONSTANTSAMPLER_H_
#define AIKIDO_CONSTRAINT_CONSTANTSAMPLER_H_
#ifndef AIKIDO_CONSTRAINT_RNCONSTANTSAMPLER_HPP_
#define AIKIDO_CONSTRAINT_RNCONSTANTSAMPLER_HPP_
#include "../../statespace/Rn.hpp"
#include "../Sampleable.hpp"

Expand All @@ -8,15 +8,13 @@ namespace constraint {

/// ConstantSampler for RealVectorStates.
/// Stub sampler for WeldJoint or any fixed constant state space.
class ConstantSampler
: public constraint::Sampleable
class RnConstantSampler : public constraint::Sampleable
{
public:

/// Constructor.
/// \param _space Space in which this constraint operates.
/// \param _value Value to return when sampled.
ConstantSampler(
RnConstantSampler(
std::shared_ptr<statespace::Rn> _space,
const Eigen::VectorXd& _value);

Expand All @@ -35,5 +33,5 @@ class ConstantSampler
} // namespace constraint
} // namespace aikido

#endif // AIKIDO_CONSTRAINT_CONSTANTSAMPLER_H_
#endif // AIKIDO_CONSTRAINT_RNCONSTANTSAMPLER_HPP_

2 changes: 1 addition & 1 deletion src/constraint/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
set(sources
uniform/RnBoxConstraint.cpp
uniform/RnConstantSampler.cpp
uniform/SO2UniformSampler.cpp
uniform/SO3UniformSampler.cpp
uniform/ConstantSampler.cpp
CartesianProductProjectable.cpp
CartesianProductSampleable.cpp
CartesianProductTestable.cpp
Expand Down
3 changes: 1 addition & 2 deletions src/constraint/uniform/RnBoxConstraint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ namespace constraint {
using constraint::ConstraintType;

//=============================================================================
class RnBoxConstraintSampleGenerator
: public constraint::SampleGenerator
class RnBoxConstraintSampleGenerator : public constraint::SampleGenerator
{
public:
statespace::StateSpacePtr getStateSpace() const override;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
#include <aikido/constraint/uniform/RnConstantSampler.hpp>

#include <stdexcept>
#include <aikido/constraint/uniform/ConstantSampler.hpp>

#include <dart/dart.hpp>

namespace aikido {
namespace constraint {

namespace {

//=============================================================================
class ConstantSamplerSampleGenerator
: public constraint::SampleGenerator
class RnConstantSamplerSampleGenerator : public constraint::SampleGenerator
{
public:
RnConstantSamplerSampleGenerator(
std::shared_ptr<statespace::Rn> _space,
const Eigen::VectorXd& _value);

statespace::StateSpacePtr getStateSpace() const override;

bool sample(statespace::StateSpace::State* _state) override;
Expand All @@ -18,58 +26,54 @@ class ConstantSamplerSampleGenerator
bool canSample() const override;

private:
ConstantSamplerSampleGenerator(
std::shared_ptr<statespace::Rn> _space,
const Eigen::VectorXd& _value);

std::shared_ptr<statespace::Rn> mSpace;
Eigen::VectorXd mValue;

friend class ConstantSampler;
};

//=============================================================================
ConstantSamplerSampleGenerator::ConstantSamplerSampleGenerator(
RnConstantSamplerSampleGenerator::RnConstantSamplerSampleGenerator(
std::shared_ptr<statespace::Rn> _space,
const Eigen::VectorXd& _value)
: mSpace(std::move(_space))
, mValue(_value)
{
// Do nothing
}

//=============================================================================
statespace::StateSpacePtr
ConstantSamplerSampleGenerator::getStateSpace() const
RnConstantSamplerSampleGenerator::getStateSpace() const
{
return mSpace;
}

//=============================================================================
bool ConstantSamplerSampleGenerator::sample(
statespace::StateSpace::State* _state)
bool RnConstantSamplerSampleGenerator::sample(
statespace::StateSpace::State* _state)
{
mSpace->setValue(static_cast<statespace::Rn::State*>(_state), mValue);

return true;
}

//=============================================================================
int ConstantSamplerSampleGenerator::getNumSamples() const
int RnConstantSamplerSampleGenerator::getNumSamples() const
{
return NO_LIMIT;
}

//=============================================================================
bool ConstantSamplerSampleGenerator::canSample() const
bool RnConstantSamplerSampleGenerator::canSample() const
{
return true;
}

} // namespace anonymous

//=============================================================================
ConstantSampler
::ConstantSampler(
std::shared_ptr<statespace::Rn> _space,
const Eigen::VectorXd& _value)
RnConstantSampler::RnConstantSampler(
std::shared_ptr<statespace::Rn> _space,
const Eigen::VectorXd& _value)
: mSpace(std::move(_space))
, mValue(_value)
{
Expand All @@ -86,18 +90,17 @@ ConstantSampler
}

//=============================================================================
statespace::StateSpacePtr ConstantSampler::getStateSpace() const
statespace::StateSpacePtr RnConstantSampler::getStateSpace() const
{
return mSpace;
}

//=============================================================================
std::unique_ptr<constraint::SampleGenerator>
ConstantSampler::createSampleGenerator() const
RnConstantSampler::createSampleGenerator() const
{
return std::unique_ptr<ConstantSamplerSampleGenerator>(
new ConstantSamplerSampleGenerator(
mSpace, mValue));
return dart::common::make_unique<RnConstantSamplerSampleGenerator>(
mSpace, mValue);
}

} // namespace constraint
Expand Down

0 comments on commit 3715bc3

Please sign in to comment.