I'm editing an open-source codebase which uses PyBind11, found here: https://github.com/erwincoumans/motion_imitation/blob/master/mpc_controller/mpc_osqp.cc
I wanted to add another public method and then call that method in Python in a different file. The method literally just returns an int, it's just meant to be a test for now. However, when I try to do so, I get the following error: AttributeError: 'mpc_osqp.ConvexMpc' object has no attribute 'test'.
I added a new line at the end to the following to the PyBind Module:
PYBIND11_MODULE(mpc_osqp, m) {
m.doc() = R"pbdoc(
MPC using OSQP Python Bindings
-----------------------
.. currentmodule:: mpc_osqp
.. autosummary::
:toctree: _generate
)pbdoc";
py::enum_<QPSolverName>(m, "QPSolverName")
.value("OSQP", OSQP, "OSQP")
.value("QPOASES", QPOASES, "QPOASES")
.export_values();
py::class_<ConvexMpc>(m, "ConvexMpc")
.def(py::init<double, const std::vector<double>&, int,
int , double ,const std::vector<double>&, double,QPSolverName>())
.def("compute_contact_forces", &ConvexMpc::ComputeContactForces)
.def("reset_solver", &ConvexMpc::ResetSolver )
.def("test", &ConvexMpc::Test); // THIS IS NEW
Where the final .def is the only edit I made. But it doesn't recognise the attribute .test
What am I missing? Thank you.