10 #ifndef CROCODDYL_CORE_ACTIONS_DIFF_LQR_HPP_
11 #define CROCODDYL_CORE_ACTIONS_DIFF_LQR_HPP_
13 #include "crocoddyl/core/diff-action-base.hpp"
14 #include "crocoddyl/core/fwd.hpp"
15 #include "crocoddyl/core/states/euclidean.hpp"
44 template <
typename _Scalar>
48 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
52 typedef _Scalar Scalar;
59 typedef typename MathBase::VectorXs VectorXs;
60 typedef typename MathBase::MatrixXs MatrixXs;
73 const MatrixXs& B,
const MatrixXs& Q,
74 const MatrixXs& R,
const MatrixXs& N);
90 const MatrixXs& B,
const MatrixXs& Q,
91 const MatrixXs& R,
const MatrixXs& N,
92 const VectorXs& f,
const VectorXs& q,
113 const MatrixXs& B,
const MatrixXs& Q,
114 const MatrixXs& R,
const MatrixXs& N,
115 const MatrixXs& G,
const MatrixXs& H,
116 const VectorXs& f,
const VectorXs& q,
117 const VectorXs& r,
const VectorXs& g,
129 const bool drift_free =
true);
136 virtual void calc(
const std::shared_ptr<DifferentialActionDataAbstract>& data,
137 const Eigen::Ref<const VectorXs>& x,
138 const Eigen::Ref<const VectorXs>& u)
override;
139 virtual void calc(
const std::shared_ptr<DifferentialActionDataAbstract>& data,
140 const Eigen::Ref<const VectorXs>& x)
override;
142 const std::shared_ptr<DifferentialActionDataAbstract>& data,
143 const Eigen::Ref<const VectorXs>& x,
144 const Eigen::Ref<const VectorXs>& u)
override;
146 const std::shared_ptr<DifferentialActionDataAbstract>& data,
147 const Eigen::Ref<const VectorXs>& x)
override;
148 virtual std::shared_ptr<DifferentialActionDataAbstract>
createData()
override;
159 template <
typename NewScalar>
163 const std::shared_ptr<DifferentialActionDataAbstract>& data)
override;
174 const std::size_t nu,
175 const std::size_t ng = 0,
176 const std::size_t nh = 0);
234 void set_LQR(
const MatrixXs& Aq,
const MatrixXs& Av,
const MatrixXs& B,
235 const MatrixXs& Q,
const MatrixXs& R,
const MatrixXs& N,
236 const MatrixXs& G,
const MatrixXs& H,
const VectorXs& f,
237 const VectorXs& q,
const VectorXs& r,
const VectorXs& g,
240 DEPRECATED(
"Use get_Aq",
const MatrixXs& get_Fq()
const {
return get_Aq(); })
241 DEPRECATED(
"Use get_Av",
const MatrixXs& get_Fv()
const {
return get_Av(); })
242 DEPRECATED(
"Use get_B",
const MatrixXs& get_Fu()
const {
return get_B(); })
243 DEPRECATED(
"Use get_f",
const VectorXs& get_f0()
const {
return get_f(); })
244 DEPRECATED(
"Use get_q",
const VectorXs& get_lx()
const {
return get_q(); })
245 DEPRECATED(
"Use get_r",
const VectorXs& get_lu()
const {
return get_r(); })
246 DEPRECATED(
"Use get_Q",
const MatrixXs& get_Lxx()
const {
return get_Q(); })
247 DEPRECATED(
"Use get_N",
const MatrixXs& get_Lxu()
const {
return get_N(); })
248 DEPRECATED(
"Use get_R",
const MatrixXs& get_Luu()
const {
return get_R(); })
250 "Use set_LQR",
void set_Fq(
const MatrixXs& Aq) {
251 set_LQR(Aq, Av_, B_, Q_, R_, N_, G_, H_, f_, q_, r_, g_, h_);
254 "Use set_LQR",
void set_Fv(
const MatrixXs& Av) {
255 set_LQR(Aq_, Av, B_, Q_, R_, N_, G_, H_, f_, q_, r_, g_, h_);
258 "Use set_LQR",
void set_Fu(
const MatrixXs& B) {
259 set_LQR(Aq_, Av_, B, Q_, R_, N_, G_, H_, f_, q_, r_, g_, h_);
262 "Use set_LQR",
void set_f0(
const VectorXs& f) {
263 set_LQR(Aq_, Av_, B_, Q_, R_, N_, G_, H_, f, q_, r_, g_, h_);
266 "Use set_LQR",
void set_lx(
const VectorXs& q) {
267 set_LQR(Aq_, Av_, B_, Q_, R_, N_, G_, H_, f_, q, r_, g_, h_);
270 "Use set_LQR",
void set_lu(
const VectorXs& r) {
271 set_LQR(Aq_, Av_, B_, Q_, R_, N_, G_, H_, f_, q_, r, g_, h_);
274 "Use set_LQR",
void set_Lxx(
const MatrixXs& Q) {
275 set_LQR(Aq_, Av_, B_, Q, R_, N_, G_, H_, f_, q_, r_, g_, h_);
278 "Use set_LQR",
void set_Lxu(
const MatrixXs& N) {
279 set_LQR(Aq_, Av_, B_, Q_, R_, N, G_, H_, f_, q_, r_, g_, h_);
282 "Use set_LQR",
void set_Luu(
const MatrixXs& R) {
283 set_LQR(Aq_, Av_, B_, Q_, R, N_, G_, H_, f_, q_, r_, g_, h_);
291 virtual void print(std::ostream& os)
const override;
318 template <
typename _Scalar>
321 typedef _Scalar Scalar;
324 typedef typename MathBase::VectorXs VectorXs;
325 typedef typename MathBase::MatrixXs MatrixXs;
327 template <
template <
typename Scalar>
class Model>
331 const std::size_t nq = model->get_state()->get_nq();
332 const std::size_t nu = model->get_nu();
333 Fx.leftCols(nq) = model->get_Aq();
334 Fx.rightCols(nq) = model->get_Av();
336 Lxx = model->get_Q();
337 Luu = model->get_R();
338 Lxu = model->get_N();
339 Gx = model->get_G().leftCols(2 * nq);
340 Gu = model->get_G().rightCols(nu);
341 Hx = model->get_H().leftCols(2 * nq);
342 Hu = model->get_H().rightCols(nu);
367 #include "crocoddyl/core/actions/diff-lqr.hxx"
369 CROCODDYL_DECLARE_EXTERN_TEMPLATE_CLASS(
371 CROCODDYL_DECLARE_EXTERN_TEMPLATE_STRUCT(
Abstract class for differential action model.
std::shared_ptr< StateAbstract > state_
Model of the state.
std::size_t nu_
Control dimension.
std::size_t nh_
Number of equality constraints.
std::size_t ng_
Number of inequality constraints.
Linear-quadratic regulator (LQR) differential action model.
virtual bool checkData(const std::shared_ptr< DifferentialActionDataAbstract > &data) override
Checks that a specific data belongs to this model.
virtual void calcDiff(const std::shared_ptr< DifferentialActionDataAbstract > &data, const Eigen::Ref< const VectorXs > &x) override
Compute the derivatives of the cost functions with respect to the state only.
const MatrixXs & get_R() const
Return the input weight matrix.
const VectorXs & get_q() const
Return the state weight vector.
void set_LQR(const MatrixXs &Aq, const MatrixXs &Av, const MatrixXs &B, const MatrixXs &Q, const MatrixXs &R, const MatrixXs &N, const MatrixXs &G, const MatrixXs &H, const VectorXs &f, const VectorXs &q, const VectorXs &r, const VectorXs &g, const VectorXs &h)
Modify the LQR action model.
virtual void calc(const std::shared_ptr< DifferentialActionDataAbstract > &data, const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &u) override
Compute the system acceleration and cost value.
static DifferentialActionModelLQRTpl Random(const std::size_t nq, const std::size_t nu, const std::size_t ng=0, const std::size_t nh=0)
Create a random LQR model.
const VectorXs & get_f() const
Return the dynamics drift.
virtual std::shared_ptr< DifferentialActionDataAbstract > createData() override
Create the differential action data.
DifferentialActionModelLQRTpl(const MatrixXs &Aq, const MatrixXs &Av, const MatrixXs &B, const MatrixXs &Q, const MatrixXs &R, const MatrixXs &N)
Initialize the LQR action model.
const VectorXs & get_r() const
Return the input weight vector.
DifferentialActionModelLQRTpl(const DifferentialActionModelLQRTpl ©)
Copy constructor.
const VectorXs & get_h() const
Return the state-input equality constraint bias.
const MatrixXs & get_Av() const
Return the velocity matrix.
virtual void calc(const std::shared_ptr< DifferentialActionDataAbstract > &data, const Eigen::Ref< const VectorXs > &x) override
Compute the total cost value for nodes that depends only on the state.
DifferentialActionModelLQRTpl(const MatrixXs &Aq, const MatrixXs &Av, const MatrixXs &B, const MatrixXs &Q, const MatrixXs &R, const MatrixXs &N, const MatrixXs &G, const MatrixXs &H, const VectorXs &f, const VectorXs &q, const VectorXs &r, const VectorXs &g, const VectorXs &h)
Initialize the LQR action model.
const VectorXs & get_g() const
Return the state-input inequality constraint bias.
DifferentialActionModelLQRTpl(const std::size_t nq, const std::size_t nu, const bool drift_free=true)
Initialize the LQR action model.
const MatrixXs & get_N() const
Return the state-input weight matrix.
DifferentialActionModelLQRTpl< NewScalar > cast() const
Cast the differential-LQR model to a different scalar type.
const MatrixXs & get_G() const
Return the state-input inequality constraint matrix.
const MatrixXs & get_B() const
Return the input matrix.
const MatrixXs & get_Aq() const
Return the position matrix.
virtual void print(std::ostream &os) const override
Print relevant information of the LQR model.
DifferentialActionModelLQRTpl(const MatrixXs &Aq, const MatrixXs &Av, const MatrixXs &B, const MatrixXs &Q, const MatrixXs &R, const MatrixXs &N, const VectorXs &f, const VectorXs &q, const VectorXs &r)
Initialize the LQR action model.
virtual void calcDiff(const std::shared_ptr< DifferentialActionDataAbstract > &data, const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &u) override
Compute the derivatives of the dynamics and cost functions.
const MatrixXs & get_Q() const
Return the state weight matrix.
const MatrixXs & get_H() const
Return the state-input equality constraint matrix.
MatrixXs Fx
Jacobian of the dynamics w.r.t. the state .
MatrixXs Fu
Jacobian of the dynamics w.r.t. the control .
MatrixXs Luu
Hessian of the cost w.r.t. the control .
VectorXs Lx
Jacobian of the cost w.r.t. the state .
MatrixXs Lxx
Hessian of the cost w.r.t. the state .
VectorXs Lu
Jacobian of the cost w.r.t. the control .
VectorXs xout
evolution state
MatrixXs Fx
Jacobian of the dynamics w.r.t. the state .
MatrixXs Fu
Jacobian of the dynamics w.r.t. the control .
MatrixXs Luu
Hessian of the cost w.r.t. the control .
MatrixXs Lxx
Hessian of the cost w.r.t. the state .