Skip to content

Commit 39e2fdb

Browse files
committed
MPC : solver_ is now a unique_ptr
1 parent b8d7ea4 commit 39e2fdb

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
@@ -79,7 +79,7 @@ namespace simple_mpc
7979
std::shared_ptr<RobotDataHandler> data_handler_;
8080

8181
public:
82-
std::shared_ptr<SolverProxDDP> solver_;
82+
std::unique_ptr<SolverProxDDP> solver_;
8383
Vector6d velocity_base_;
8484
Vector7d pose_base_;
8585
Eigen::Vector3d next_pose_;
@@ -129,11 +129,6 @@ namespace simple_mpc
129129
// getters and setters
130130
TrajOptProblem & getTrajOptProblem();
131131

132-
SIMPLE_MPC_DEPRECATED_MESSAGE("The MPC::solver_ member is now public.")
133-
SolverProxDDP & getSolver()
134-
{
135-
return *solver_;
136-
}
137132
const RobotDataHandler & getDataHandler() const
138133
{
139134
return *data_handler_;
@@ -184,15 +179,14 @@ namespace simple_mpc
184179
std::map<std::string, std::vector<int>> foot_takeoff_times_, foot_land_times_;
185180

186181
// Solution vectors for state and control
187-
std::vector<Eigen::VectorXd> xs_;
188-
std::vector<Eigen::VectorXd> us_;
189-
182+
std::vector<VectorXd> xs_;
183+
std::vector<VectorXd> us_;
190184
// Riccati gains
191-
std::vector<Eigen::MatrixXd> Ks_;
185+
std::vector<MatrixXd> Ks_;
192186

193187
// Initial quantities
194-
Eigen::VectorXd x0_;
195-
Eigen::VectorXd u0_;
188+
VectorXd x0_;
189+
VectorXd u0_;
196190
};
197191

198192
} // namespace simple_mpc

src/mpc.cpp

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

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

4343
if (settings_.num_threads > 1)

0 commit comments

Comments
 (0)