Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions include/pyhpp/core/problem.hh
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ struct Problem {
boost::python::tuple applyConstraints(ConfigurationIn_t config);
boost::python::tuple isConfigValid(ConfigurationIn_t dofArray);
void setConstraints(hpp::core::ConstraintSetPtr_t constraints);
hpp::core::ConstraintSetPtr_t getConstraints();
void setRightHandSideFromConfig(ConfigurationIn_t configIn);

void addNumericalConstraintsToConfigProjector1(
Expand Down
3 changes: 1 addition & 2 deletions src/pyhpp/constraints/explicit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ ExplicitPtr_t createExplicit(const LiegroupSpacePtr_t& configSpace,
void exposeExplicit() {
// DocClass(Explicit)
class_<Explicit, ExplicitPtr_t, boost::noncopyable>("Explicit", no_init)
.def("create", &createExplicit)
.staticmethod("create");
.def("__init__", make_constructor(&createExplicit));
}
} // namespace constraints
} // namespace pyhpp
2 changes: 2 additions & 0 deletions src/pyhpp/constraints/generic-transformation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ void exposeGenericTransformations() {
"RelativeOrientation");
exposeRelativeGenericTransformation<RelativeTransformation>(
"RelativeTransformation");
exposeRelativeGenericTransformation<RelativeTransformationR3xSO3>(
"RelativeTransformationR3xSO3");
}
} // namespace constraints
} // namespace pyhpp
7 changes: 3 additions & 4 deletions src/pyhpp/constraints/relative-com.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,9 @@ void exposeRelativeCom() {
// DocClass(RelativeCom)
class_<RelativeCom, RelativeComPtr_t, bases<DifferentiableFunction>,
boost::noncopyable>("RelativeCom", no_init)
.def("create", &create1, DocClassMethod(create))
.def("create", &create2)
.def("create", &create3)
.staticmethod("create");
.def("__init__", &create1, DocClassMethod(create))
.def("__init__", &create2)
.def("__init__", &create3);
}
} // namespace constraints
} // namespace pyhpp
3 changes: 1 addition & 2 deletions src/pyhpp/core/parameter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ Parameter createBool(bool param) { return Parameter(param); }
void exposeParameter() {
// DocClass(Parameter)
class_<Parameter>("Parameter", no_init)
.def("create", &create)
.staticmethod("create")
.def("__init__", &create)
.def("create_bool", &createBool)
.staticmethod("create_bool")
.PYHPP_DEFINE_METHOD(Parameter, boolValue)
Expand Down
18 changes: 10 additions & 8 deletions src/pyhpp/core/path.cc
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,16 @@ void exposePath() {

class_<StraightPath, bases<Path>, StraightPathPtr_t, boost::noncopyable>(
"StraightPath", no_init)
.def("create", static_cast<StraightPathPtr_t (*)(
LiegroupSpacePtr_t, vectorIn_t, vectorIn_t, interval_t,
ConstraintSetPtr_t)>(&StraightPath::create))
.def("create",
static_cast<StraightPathPtr_t (*)(
const DevicePtr_t&, ConfigurationIn_t, ConfigurationIn_t,
interval_t, ConstraintSetPtr_t)>(&StraightPath::create))
.staticmethod("create");
.def("__init__",
make_constructor(
static_cast<StraightPathPtr_t (*)(
LiegroupSpacePtr_t, vectorIn_t, vectorIn_t, interval_t,
ConstraintSetPtr_t)>(&StraightPath::create)))
.def("__init__",
make_constructor(
static_cast<StraightPathPtr_t (*)(
const DevicePtr_t&, ConfigurationIn_t, ConfigurationIn_t,
interval_t, ConstraintSetPtr_t)>(&StraightPath::create)));
}
} // namespace core
} // namespace pyhpp
12 changes: 7 additions & 5 deletions src/pyhpp/core/path/vector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,15 @@ PathVectorPtr_t loadPathVector(const std::string& filename) {

void exposeVector() {
// DocClass(PathVector)
typedef PathVectorPtr_t (*constructor_t)(size_type, size_type);
constructor_t constructor(static_cast<constructor_t>(&PathVector::create));
class_<PathVector, PathVectorPtr_t, bases<Path>, boost::noncopyable>("Vector",
no_init)
.def("create",
static_cast<PathVectorPtr_t (*)(size_type, size_type)>(
&PathVector::create),
DocClassMethod(create))
.staticmethod("create")
.def("__init__", make_constructor(constructor),
"Create an empty path vector.\n"
" param:\n"
" inputSize dimension of the configuration space,\n"
" inputDerivativeSize dimension of the tangent space.")
.def("numberPaths", &PathVector::numberPaths, DocClassMethod(numberPaths))
.def("pathAtRank", &PathVector::pathAtRank, DocClassMethod(pathAtRank))
.def("rankAtParam", &PathVector::rankAtParam, DocClassMethod(rankAtParam))
Expand Down
9 changes: 9 additions & 0 deletions src/pyhpp/core/problem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,14 @@ void Problem::setConstraints(hpp::core::ConstraintSetPtr_t constraints) {
}
}

hpp::core::ConstraintSetPtr_t Problem::getConstraints() {
try {
return obj->constraints();
} catch (const std::exception& exc) {
throw std::logic_error(exc.what());
}
}

void Problem::setRightHandSideFromConfig(ConfigurationIn_t configIn) {
try {
hpp::core::ConfigProjectorPtr_t configProjector(
Expand Down Expand Up @@ -664,6 +672,7 @@ void exposeProblem() {
.PYHPP_DEFINE_METHOD(Problem, applyConstraints)
.PYHPP_DEFINE_METHOD(Problem, isConfigValid)
.PYHPP_DEFINE_METHOD(Problem, setConstraints)
.PYHPP_DEFINE_METHOD(Problem, getConstraints)
.PYHPP_DEFINE_METHOD(Problem, setRightHandSideFromConfig)
.def("addNumericalConstraintsToConfigProjector",
&Problem::addNumericalConstraintsToConfigProjector1)
Expand Down
2 changes: 1 addition & 1 deletion src/pyhpp/core/problem_target/goal-configurations.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void exposeGoalConfigurations() {
class_<GoalConfigurations, GoalConfigurationsPtr_t,
bases<hpp::core::ProblemTarget>, boost::noncopyable>(
"GoalConfigurations", no_init)
.def("create", &GoalConfigurations::create)
.def("__init__", make_constructor(&GoalConfigurations::create))
.PYHPP_DEFINE_METHOD(GoalConfigurations, computePath)
.PYHPP_DEFINE_METHOD(GoalConfigurations, reached)

Expand Down
20 changes: 5 additions & 15 deletions tests/unit/test_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,18 +141,14 @@ def setUpClass(cls):

def test_create_empty_path_vector(self):
"""PathVector.create should create an empty vector."""
pv = pyhpp.core.path.Vector.create(
self.robot.configSize(), self.robot.numberDof()
)
pv = pyhpp.core.path.Vector(self.robot.configSize(), self.robot.numberDof())

self.assertIsNotNone(pv)
self.assertEqual(pv.numberPaths(), 0)

def test_append_path_increases_count(self):
"""Appending paths should increase numberPaths."""
pv = pyhpp.core.path.Vector.create(
self.robot.configSize(), self.robot.numberDof()
)
pv = pyhpp.core.path.Vector(self.robot.configSize(), self.robot.numberDof())

q1 = np.array([0.0, -1.57, -1.8, 0.0, 0.8, 0.0])
q2 = np.array([0.5, -1.57, -1.8, 0.0, 0.8, 0.0])
Expand All @@ -166,9 +162,7 @@ def test_append_path_increases_count(self):

def test_path_vector_length_is_sum(self):
"""PathVector length should be sum of contained paths."""
pv = pyhpp.core.path.Vector.create(
self.robot.configSize(), self.robot.numberDof()
)
pv = pyhpp.core.path.Vector(self.robot.configSize(), self.robot.numberDof())

q1 = np.array([0.0, -1.57, -1.8, 0.0, 0.8, 0.0])
q2 = np.array([0.5, -1.57, -1.8, 0.0, 0.8, 0.0])
Expand All @@ -194,9 +188,7 @@ def setUpClass(cls):

def test_path_at_valid_index_works(self):
"""Accessing path at valid index should work."""
pv = pyhpp.core.path.Vector.create(
self.robot.configSize(), self.robot.numberDof()
)
pv = pyhpp.core.path.Vector(self.robot.configSize(), self.robot.numberDof())

q1 = np.array([0.0, -1.57, -1.8, 0.0, 0.8, 0.0])
q2 = np.array([0.5, -1.57, -1.8, 0.0, 0.8, 0.0])
Expand All @@ -211,9 +203,7 @@ def test_path_at_valid_index_works(self):

def test_empty_path_vector_has_zero_length(self):
"""Empty PathVector should have zero length."""
pv = pyhpp.core.path.Vector.create(
self.robot.configSize(), self.robot.numberDof()
)
pv = pyhpp.core.path.Vector(self.robot.configSize(), self.robot.numberDof())

self.assertEqual(pv.length(), 0.0)

Expand Down
10 changes: 5 additions & 5 deletions tests/unit/test_path_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def test_optimize_returns_path(self):
path1 = steer(q1, q2)
path2 = steer(q2, q3)

pv = pyhpp.core.path.Vector.create(robot.configSize(), robot.numberDof())
pv = pyhpp.core.path.Vector(robot.configSize(), robot.numberDof())
pv.appendPath(path1)
pv.appendPath(path2)

Expand All @@ -67,7 +67,7 @@ def test_max_iterations_settable(self):
q2 = np.array([0.5, -1.57, -1.8, 0.0, 0.8, 0.0])
steer = problem.steeringMethod()
path = steer(q1, q2)
pv = pyhpp.core.path.Vector.create(robot.configSize(), robot.numberDof())
pv = pyhpp.core.path.Vector(robot.configSize(), robot.numberDof())
pv.appendPath(path)

optimized = optimizer.optimize(pv)
Expand All @@ -85,7 +85,7 @@ def test_optimize_zero_length_path(self):
steer = problem.steeringMethod()
path = steer(q, q)

pv = pyhpp.core.path.Vector.create(robot.configSize(), robot.numberDof())
pv = pyhpp.core.path.Vector(robot.configSize(), robot.numberDof())
pv.appendPath(path)

optimizer = RandomShortcut(problem)
Expand All @@ -105,7 +105,7 @@ def test_optimize_preserves_endpoints(self):
q4 = np.array([0.6, -1.0, -1.2, 0.3, 0.5, 0.3])

steer = problem.steeringMethod()
pv = pyhpp.core.path.Vector.create(robot.configSize(), robot.numberDof())
pv = pyhpp.core.path.Vector(robot.configSize(), robot.numberDof())
pv.appendPath(steer(q1, q2))
pv.appendPath(steer(q2, q3))
pv.appendPath(steer(q3, q4))
Expand All @@ -128,7 +128,7 @@ def test_zero_iterations_returns_same_path(self):
steer = problem.steeringMethod()
path = steer(q1, q2)

pv = pyhpp.core.path.Vector.create(robot.configSize(), robot.numberDof())
pv = pyhpp.core.path.Vector(robot.configSize(), robot.numberDof())
pv.appendPath(path)
original_length = pv.length()

Expand Down