#include #include #include #include "cddp_core/constraint.hpp" namespace py = pybind11; class PyConstraint : public cddp::Constraint { public: using cddp::Constraint::Constraint; int getDualDim() const override { PYBIND11_OVERRIDE_NAME(int, cddp::Constraint, "get_dual_dim", getDualDim); } Eigen::VectorXd evaluate(const Eigen::VectorXd &state, const Eigen::VectorXd &control, int index) const override { PYBIND11_OVERRIDE_PURE_NAME(Eigen::VectorXd, cddp::Constraint, "evaluate", evaluate, state, control, index); } Eigen::VectorXd getLowerBound() const override { PYBIND11_OVERRIDE_PURE_NAME(Eigen::VectorXd, cddp::Constraint, "get_lower_bound", getLowerBound); } Eigen::VectorXd getUpperBound() const override { PYBIND11_OVERRIDE_PURE_NAME(Eigen::VectorXd, cddp::Constraint, "get_upper_bound", getUpperBound); } Eigen::MatrixXd getStateJacobian(const Eigen::VectorXd &state, const Eigen::VectorXd &control, int index) const override { PYBIND11_OVERRIDE_PURE_NAME(Eigen::MatrixXd, cddp::Constraint, "get_state_jacobian", getStateJacobian, state, control, index); } Eigen::MatrixXd getControlJacobian(const Eigen::VectorXd &state, const Eigen::VectorXd &control, int index) const override { PYBIND11_OVERRIDE_PURE_NAME(Eigen::MatrixXd, cddp::Constraint, "get_control_jacobian", getControlJacobian, state, control, index); } double computeViolation(const Eigen::VectorXd &state, const Eigen::VectorXd &control, int index) const override { PYBIND11_OVERRIDE_PURE_NAME(double, cddp::Constraint, "compute_violation", computeViolation, state, control, index); } double computeViolationFromValue(const Eigen::VectorXd &g) const override { PYBIND11_OVERRIDE_PURE_NAME(double, cddp::Constraint, "compute_violation_from_value", computeViolationFromValue, g); } Eigen::VectorXd getCenter() const override { PYBIND11_OVERRIDE_NAME(Eigen::VectorXd, cddp::Constraint, "get_center", getCenter); } std::vector getStateHessian(const Eigen::VectorXd &state, const Eigen::VectorXd &control, int index) const override { PYBIND11_OVERRIDE_NAME(std::vector, cddp::Constraint, "get_state_hessian", getStateHessian, state, control, index); } std::vector getControlHessian(const Eigen::VectorXd &state, const Eigen::VectorXd &control, int index) const override { PYBIND11_OVERRIDE_NAME(std::vector, cddp::Constraint, "get_control_hessian", getControlHessian, state, control, index); } std::vector getCrossHessian(const Eigen::VectorXd &state, const Eigen::VectorXd &control, int index) const override { PYBIND11_OVERRIDE_NAME(std::vector, cddp::Constraint, "get_cross_hessian", getCrossHessian, state, control, index); } }; void bind_constraints(py::module_& m) { py::class_(m, "Constraint") .def(py::init(), py::arg("name")) .def("evaluate", &cddp::Constraint::evaluate, py::arg("state"), py::arg("control"), py::arg("index") = 0) .def("get_lower_bound", &cddp::Constraint::getLowerBound) .def("get_upper_bound", &cddp::Constraint::getUpperBound) .def("get_state_jacobian", &cddp::Constraint::getStateJacobian, py::arg("state"), py::arg("control"), py::arg("index") = 0) .def("get_control_jacobian", &cddp::Constraint::getControlJacobian, py::arg("state"), py::arg("control"), py::arg("index") = 0) .def("compute_violation", &cddp::Constraint::computeViolation, py::arg("state"), py::arg("control"), py::arg("index") = 0) .def("compute_violation_from_value", &cddp::Constraint::computeViolationFromValue, py::arg("g")) .def("get_center", &cddp::Constraint::getCenter) .def("get_state_hessian", &cddp::Constraint::getStateHessian, py::arg("state"), py::arg("control"), py::arg("index") = 0) .def("get_control_hessian", &cddp::Constraint::getControlHessian, py::arg("state"), py::arg("control"), py::arg("index") = 0) .def("get_cross_hessian", &cddp::Constraint::getCrossHessian, py::arg("state"), py::arg("control"), py::arg("index") = 0) .def("get_dual_dim", &cddp::Constraint::getDualDim) .def_property_readonly("name", &cddp::Constraint::getName); py::class_(m, "ControlConstraint") .def(py::init(), py::arg("lower_bound"), py::arg("upper_bound"), py::arg("scale_factor") = 1.0); py::class_(m, "StateConstraint") .def(py::init(), py::arg("lower_bound"), py::arg("upper_bound"), py::arg("scale_factor") = 1.0); py::class_(m, "LinearConstraint") .def(py::init(), py::arg("A"), py::arg("b"), py::arg("scale_factor") = 1.0); py::class_(m, "BallConstraint") .def(py::init(), py::arg("radius"), py::arg("center"), py::arg("scale_factor") = 1.0) .def("get_center", &cddp::BallConstraint::getCenter); py::class_(m, "PoleConstraint") .def(py::init(), py::arg("center"), py::arg("direction"), py::arg("radius"), py::arg("length"), py::arg("scale_factor") = 1.0); py::class_(m, "SecondOrderConeConstraint") .def(py::init(), py::arg("cone_origin"), py::arg("opening_direction"), py::arg("cone_angle_fov"), py::arg("epsilon") = 1e-6, py::arg("name") = "SecondOrderConeConstraint"); py::class_(m, "ThrustMagnitudeConstraint") .def(py::init(), py::arg("min_thrust"), py::arg("max_thrust"), py::arg("epsilon") = 1e-6); py::class_(m, "MaxThrustMagnitudeConstraint") .def(py::init(), py::arg("max_thrust"), py::arg("epsilon") = 1e-6); }