diff --git a/include/pyhpp/core/problem.hh b/include/pyhpp/core/problem.hh index 595aa686..8d79f967 100644 --- a/include/pyhpp/core/problem.hh +++ b/include/pyhpp/core/problem.hh @@ -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( diff --git a/src/pyhpp/constraints/explicit.cc b/src/pyhpp/constraints/explicit.cc index fe6c9cfb..68bf9ae0 100644 --- a/src/pyhpp/constraints/explicit.cc +++ b/src/pyhpp/constraints/explicit.cc @@ -65,8 +65,7 @@ ExplicitPtr_t createExplicit(const LiegroupSpacePtr_t& configSpace, void exposeExplicit() { // DocClass(Explicit) class_("Explicit", no_init) - .def("create", &createExplicit) - .staticmethod("create"); + .def("__init__", make_constructor(&createExplicit)); } } // namespace constraints } // namespace pyhpp diff --git a/src/pyhpp/constraints/generic-transformation.cc b/src/pyhpp/constraints/generic-transformation.cc index ddc98398..707fe71d 100644 --- a/src/pyhpp/constraints/generic-transformation.cc +++ b/src/pyhpp/constraints/generic-transformation.cc @@ -108,6 +108,8 @@ void exposeGenericTransformations() { "RelativeOrientation"); exposeRelativeGenericTransformation( "RelativeTransformation"); + exposeRelativeGenericTransformation( + "RelativeTransformationR3xSO3"); } } // namespace constraints } // namespace pyhpp diff --git a/src/pyhpp/constraints/relative-com.cc b/src/pyhpp/constraints/relative-com.cc index 5672a0c8..7288d0f4 100644 --- a/src/pyhpp/constraints/relative-com.cc +++ b/src/pyhpp/constraints/relative-com.cc @@ -70,10 +70,9 @@ void exposeRelativeCom() { // DocClass(RelativeCom) class_, 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 diff --git a/src/pyhpp/core/parameter.cc b/src/pyhpp/core/parameter.cc index 36dc3a46..f20525d8 100644 --- a/src/pyhpp/core/parameter.cc +++ b/src/pyhpp/core/parameter.cc @@ -84,8 +84,7 @@ Parameter createBool(bool param) { return Parameter(param); } void exposeParameter() { // DocClass(Parameter) class_("Parameter", no_init) - .def("create", &create) - .staticmethod("create") + .def("__init__", &create) .def("create_bool", &createBool) .staticmethod("create_bool") .PYHPP_DEFINE_METHOD(Parameter, boolValue) diff --git a/src/pyhpp/core/path.cc b/src/pyhpp/core/path.cc index 9892e68c..8110fc8b 100644 --- a/src/pyhpp/core/path.cc +++ b/src/pyhpp/core/path.cc @@ -201,14 +201,16 @@ void exposePath() { class_, StraightPathPtr_t, boost::noncopyable>( "StraightPath", no_init) - .def("create", static_cast(&StraightPath::create)) - .def("create", - static_cast(&StraightPath::create)) - .staticmethod("create"); + .def("__init__", + make_constructor( + static_cast(&StraightPath::create))) + .def("__init__", + make_constructor( + static_cast(&StraightPath::create))); } } // namespace core } // namespace pyhpp diff --git a/src/pyhpp/core/path/vector.cc b/src/pyhpp/core/path/vector.cc index d08b368e..a26f0565 100644 --- a/src/pyhpp/core/path/vector.cc +++ b/src/pyhpp/core/path/vector.cc @@ -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(&PathVector::create)); class_, boost::noncopyable>("Vector", no_init) - .def("create", - static_cast( - &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)) diff --git a/src/pyhpp/core/problem.cc b/src/pyhpp/core/problem.cc index e6dcb0f8..b6b6ee07 100644 --- a/src/pyhpp/core/problem.cc +++ b/src/pyhpp/core/problem.cc @@ -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( @@ -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) diff --git a/src/pyhpp/core/problem_target/goal-configurations.cc b/src/pyhpp/core/problem_target/goal-configurations.cc index 6ab2c11d..15a2230b 100644 --- a/src/pyhpp/core/problem_target/goal-configurations.cc +++ b/src/pyhpp/core/problem_target/goal-configurations.cc @@ -43,7 +43,7 @@ void exposeGoalConfigurations() { class_, 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) diff --git a/tests/unit/test_path.py b/tests/unit/test_path.py index 9fa863ed..5e488315 100644 --- a/tests/unit/test_path.py +++ b/tests/unit/test_path.py @@ -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]) @@ -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]) @@ -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]) @@ -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) diff --git a/tests/unit/test_path_optimizer.py b/tests/unit/test_path_optimizer.py index 588f8834..51b52db3 100644 --- a/tests/unit/test_path_optimizer.py +++ b/tests/unit/test_path_optimizer.py @@ -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) @@ -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) @@ -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) @@ -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)) @@ -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()