Skip to content

Commit 645895b

Browse files
committed
MPC : remove default ctor
1 parent f697959 commit 645895b

File tree

3 files changed

+7
-18
lines changed

3 files changed

+7
-18
lines changed

bindings/expose-mpc.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace simple_mpc
2424
namespace bp = boost::python;
2525
using eigenpy::StdVectorPythonVisitor;
2626

27-
void initialize(MPC & self, const bp::dict & settings, std::shared_ptr<OCPHandler> problem)
27+
MPC * createMPC(const bp::dict & settings, std::shared_ptr<OCPHandler> problem)
2828
{
2929
MPCSettings conf;
3030

@@ -42,7 +42,7 @@ namespace simple_mpc
4242
conf.T_contact = bp::extract<int>(settings["T_contact"]);
4343
conf.timestep = bp::extract<double>(settings["timestep"]);
4444

45-
self.initialize(conf, problem);
45+
return new MPC{conf, problem};
4646
}
4747

4848
bp::dict getSettings(MPC & self)
@@ -73,8 +73,7 @@ namespace simple_mpc
7373
StdVectorPythonVisitor<std::vector<MapBool>, true>::expose("StdVec_MapBool");
7474

7575
bp::class_<MPC>("MPC", bp::no_init)
76-
.def(bp::init<>(bp::args("self")))
77-
.def("initialize", &initialize)
76+
.def("__init__", bp::make_constructor(&createMPC, bp::default_call_policies()))
7877
.def("getSettings", &getSettings)
7978
.def("generateCycleHorizon", &MPC::generateCycleHorizon, bp::args("self", "contact_states"))
8079
.def("iterate", &MPC::iterate, bp::args("self", "x"))

include/simple-mpc/mpc.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,14 @@ namespace simple_mpc
8585
MPCSettings settings_;
8686
std::shared_ptr<OCPHandler> ocp_handler_;
8787

88-
explicit MPC();
8988
explicit MPC(const MPCSettings & settings, std::shared_ptr<OCPHandler> problem);
90-
void initialize(const MPCSettings & settings, std::shared_ptr<OCPHandler> problem);
9189

9290
// Generate the cycle walking problem along which we will iterate
9391
// the receding horizon
9492
void generateCycleHorizon(const std::vector<std::map<std::string, bool>> & contact_states);
9593

9694
// Perform one iteration of MPC
97-
void iterate(const Eigen::VectorXd & x);
95+
void iterate(const ConstVectorRef & x);
9896

9997
void updateCycleTiming(const bool updateOnlyHorizon);
10098

src/mpc.cpp

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,11 @@ namespace simple_mpc
1616
using namespace aligator;
1717
constexpr std::size_t maxiters = 100;
1818

19-
MPC::MPC()
20-
{
21-
}
22-
2319
MPC::MPC(const MPCSettings & settings, std::shared_ptr<OCPHandler> problem)
20+
: settings_(settings)
21+
, ocp_handler_(problem)
2422
{
25-
initialize(settings, problem);
26-
}
2723

28-
void MPC::initialize(const MPCSettings & settings, std::shared_ptr<OCPHandler> problem)
29-
{
30-
settings_ = settings;
31-
ocp_handler_ = problem;
3224
std::map<std::string, Eigen::Vector3d> starting_poses;
3325
for (auto const & name : ocp_handler_->getModelHandler().getFeetNames())
3426
{
@@ -188,7 +180,7 @@ namespace simple_mpc
188180
}
189181
}
190182

191-
void MPC::iterate(const Eigen::VectorXd & x)
183+
void MPC::iterate(const ConstVectorRef & x)
192184
{
193185

194186
ocp_handler_->getDataHandler().updateInternalData(x, false);

0 commit comments

Comments
 (0)