Skip to content

Commit 4674fe9

Browse files
committed
MPC : solver_ is now a unique_ptr
1 parent 645895b commit 4674fe9

File tree

3 files changed

+10
-19
lines changed

3 files changed

+10
-19
lines changed

bindings/expose-mpc.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include <eigenpy/deprecation-policy.hpp>
1313
#include <eigenpy/eigenpy.hpp>
14+
#include <eigenpy/std-unique-ptr.hpp>
1415
#include <eigenpy/std-vector.hpp>
1516

1617
#include "simple-mpc/mpc.hpp"
@@ -72,7 +73,7 @@ namespace simple_mpc
7273

7374
StdVectorPythonVisitor<std::vector<MapBool>, true>::expose("StdVec_MapBool");
7475

75-
bp::class_<MPC>("MPC", bp::no_init)
76+
bp::class_<MPC, boost::noncopyable>("MPC", bp::no_init)
7677
.def("__init__", bp::make_constructor(&createMPC, bp::default_call_policies()))
7778
.def("getSettings", &getSettings)
7879
.def("generateCycleHorizon", &MPC::generateCycleHorizon, bp::args("self", "contact_states"))
@@ -102,11 +103,7 @@ namespace simple_mpc
102103
.def(
103104
"getCycleHorizon", &MPC::getCycleHorizon, "self"_a, bp::return_internal_reference<>(),
104105
"Get the cycle horizon.")
105-
.def(
106-
"getSolver", &MPC::getSolver, "self"_a,
107-
eigenpy::deprecated_member<eigenpy::DeprecationType::DEPRECATION, bp::return_internal_reference<>>(),
108-
"Get the SolverProxDDP object")
109-
.def_readonly("solver", &MPC::solver_)
106+
.add_property("solver", bp::make_getter(&MPC::solver_, eigenpy::ReturnInternalStdUniquePtr{}))
110107
.add_property("xs", &MPC::xs_)
111108
.add_property("us", &MPC::us_)
112109
.add_property("Ks", &MPC::Ks_);

include/simple-mpc/mpc.hpp

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ namespace simple_mpc
7777
LocomotionType now_;
7878

7979
public:
80-
std::shared_ptr<SolverProxDDP> solver_;
80+
std::unique_ptr<SolverProxDDP> solver_;
8181
Vector6d velocity_base_;
8282
Vector7d pose_base_;
8383
Eigen::Vector3d next_pose_;
@@ -127,11 +127,6 @@ namespace simple_mpc
127127
// getters and setters
128128
TrajOptProblem & getTrajOptProblem();
129129

130-
SIMPLE_MPC_DEPRECATED_MESSAGE("The MPC::solver_ member is now public.")
131-
SolverProxDDP & getSolver()
132-
{
133-
return *solver_;
134-
}
135130
const RobotDataHandler & getDataHandler() const
136131
{
137132
return ocp_handler_->getDataHandler();
@@ -182,15 +177,14 @@ namespace simple_mpc
182177
std::map<std::string, std::vector<int>> foot_takeoff_times_, foot_land_times_;
183178

184179
// Solution vectors for state and control
185-
std::vector<Eigen::VectorXd> xs_;
186-
std::vector<Eigen::VectorXd> us_;
187-
180+
std::vector<VectorXd> xs_;
181+
std::vector<VectorXd> us_;
188182
// Riccati gains
189-
std::vector<Eigen::MatrixXd> Ks_;
183+
std::vector<MatrixXd> Ks_;
190184

191185
// Initial quantities
192-
Eigen::VectorXd x0_;
193-
Eigen::VectorXd u0_;
186+
VectorXd x0_;
187+
VectorXd u0_;
194188
};
195189

196190
} // namespace simple_mpc

src/mpc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ namespace simple_mpc
3636
foot_trajectories_.updateApex(settings.swing_apex);
3737
x0_ = ocp_handler_->getProblemState();
3838

39-
solver_ = std::make_shared<SolverProxDDP>(settings_.TOL, settings_.mu_init, maxiters, aligator::QUIET);
39+
solver_ = std::make_unique<SolverProxDDP>(settings_.TOL, settings_.mu_init, maxiters, aligator::QUIET);
4040
solver_->rollout_type_ = aligator::RolloutType::LINEAR;
4141

4242
if (settings_.num_threads > 1)

0 commit comments

Comments
 (0)