10 #ifndef CROCODDYL_CORE_ACTIONS_DIFF_LQR_HPP_
11 #define CROCODDYL_CORE_ACTIONS_DIFF_LQR_HPP_
15 #include "crocoddyl/core/diff-action-base.hpp"
16 #include "crocoddyl/core/fwd.hpp"
17 #include "crocoddyl/core/states/euclidean.hpp"
46 template <
typename _Scalar>
50 typedef _Scalar Scalar;
57 typedef typename MathBase::VectorXs VectorXs;
58 typedef typename MathBase::MatrixXs MatrixXs;
71 const MatrixXs& B,
const MatrixXs& Q,
72 const MatrixXs& R,
const MatrixXs& N);
88 const MatrixXs& B,
const MatrixXs& Q,
89 const MatrixXs& R,
const MatrixXs& N,
90 const VectorXs& f,
const VectorXs& q,
111 const MatrixXs& B,
const MatrixXs& Q,
112 const MatrixXs& R,
const MatrixXs& N,
113 const MatrixXs& G,
const MatrixXs& H,
114 const VectorXs& f,
const VectorXs& q,
115 const VectorXs& r,
const VectorXs& g,
127 const bool drift_free =
true);
134 virtual void calc(
const std::shared_ptr<DifferentialActionDataAbstract>& data,
135 const Eigen::Ref<const VectorXs>& x,
136 const Eigen::Ref<const VectorXs>& u);
137 virtual void calc(
const std::shared_ptr<DifferentialActionDataAbstract>& data,
138 const Eigen::Ref<const VectorXs>& x);
140 const std::shared_ptr<DifferentialActionDataAbstract>& data,
141 const Eigen::Ref<const VectorXs>& x,
const Eigen::Ref<const VectorXs>& u);
143 const std::shared_ptr<DifferentialActionDataAbstract>& data,
144 const Eigen::Ref<const VectorXs>& x);
145 virtual std::shared_ptr<DifferentialActionDataAbstract>
createData();
147 const std::shared_ptr<DifferentialActionDataAbstract>& data);
158 const std::size_t nu,
159 const std::size_t ng = 0,
160 const std::size_t nh = 0);
218 void set_LQR(
const MatrixXs& Aq,
const MatrixXs& Av,
const MatrixXs& B,
219 const MatrixXs& Q,
const MatrixXs& R,
const MatrixXs& N,
220 const MatrixXs& G,
const MatrixXs& H,
const VectorXs& f,
221 const VectorXs& q,
const VectorXs& r,
const VectorXs& g,
224 DEPRECATED(
"Use get_Aq",
const MatrixXs& get_Fq()
const {
return get_Aq(); })
225 DEPRECATED(
"Use get_Av",
const MatrixXs& get_Fv()
const {
return get_Av(); })
226 DEPRECATED(
"Use get_B",
const MatrixXs& get_Fu()
const {
return get_B(); })
227 DEPRECATED(
"Use get_f",
const VectorXs& get_f0()
const {
return get_f(); })
228 DEPRECATED(
"Use get_q",
const VectorXs& get_lx()
const {
return get_q(); })
229 DEPRECATED(
"Use get_r",
const VectorXs& get_lu()
const {
return get_r(); })
230 DEPRECATED(
"Use get_Q",
const MatrixXs& get_Lxx()
const {
return get_Q(); })
231 DEPRECATED(
"Use get_N",
const MatrixXs& get_Lxu()
const {
return get_N(); })
232 DEPRECATED(
"Use get_R",
const MatrixXs& get_Luu()
const {
return get_R(); })
234 "Use set_LQR",
void set_Fq(
const MatrixXs& Aq) {
235 set_LQR(Aq, Av_, B_, Q_, R_, N_, G_, H_, f_, q_, r_, g_, h_);
238 "Use set_LQR",
void set_Fv(
const MatrixXs& Av) {
239 set_LQR(Aq_, Av, B_, Q_, R_, N_, G_, H_, f_, q_, r_, g_, h_);
242 "Use set_LQR",
void set_Fu(
const MatrixXs& B) {
243 set_LQR(Aq_, Av_, B, Q_, R_, N_, G_, H_, f_, q_, r_, g_, h_);
246 "Use set_LQR",
void set_f0(
const VectorXs& f) {
247 set_LQR(Aq_, Av_, B_, Q_, R_, N_, G_, H_, f, q_, r_, g_, h_);
250 "Use set_LQR",
void set_lx(
const VectorXs& q) {
251 set_LQR(Aq_, Av_, B_, Q_, R_, N_, G_, H_, f_, q, r_, g_, h_);
254 "Use set_LQR",
void set_lu(
const VectorXs& r) {
255 set_LQR(Aq_, Av_, B_, Q_, R_, N_, G_, H_, f_, q_, r, g_, h_);
258 "Use set_LQR",
void set_Lxx(
const MatrixXs& Q) {
259 set_LQR(Aq_, Av_, B_, Q, R_, N_, G_, H_, f_, q_, r_, g_, h_);
262 "Use set_LQR",
void set_Lxu(
const MatrixXs& N) {
263 set_LQR(Aq_, Av_, B_, Q_, R_, N, G_, H_, f_, q_, r_, g_, h_);
266 "Use set_LQR",
void set_Luu(
const MatrixXs& R) {
267 set_LQR(Aq_, Av_, B_, Q_, R, N_, G_, H_, f_, q_, r_, g_, h_);
275 virtual void print(std::ostream& os)
const;
302 template <
typename _Scalar>
305 typedef _Scalar Scalar;
308 typedef typename MathBase::VectorXs VectorXs;
309 typedef typename MathBase::MatrixXs MatrixXs;
311 template <
template <
typename Scalar>
class Model>
315 const std::size_t nq = model->get_state()->get_nq();
316 const std::size_t nu = model->get_nu();
317 Fx.leftCols(nq) = model->get_Aq();
318 Fx.rightCols(nq) = model->get_Av();
320 Lxx = model->get_Q();
321 Luu = model->get_R();
322 Lxu = model->get_N();
323 Gx = model->get_G().leftCols(2 * nq);
324 Gu = model->get_G().rightCols(nu);
325 Hx = model->get_H().leftCols(2 * nq);
326 Hu = model->get_H().rightCols(nu);
350 #include "crocoddyl/core/actions/diff-lqr.hxx"
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.
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.
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()
Create the differential action data.
virtual void print(std::ostream &os) const
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)
Initialize the LQR action model.
const VectorXs & get_r() const
Return the input weight vector.
DifferentialActionModelLQRTpl(const DifferentialActionModelLQRTpl ©)
Copy constructor.
virtual void calcDiff(const std::shared_ptr< DifferentialActionDataAbstract > &data, const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &u)
Compute the derivatives of the dynamics and cost functions.
virtual void calc(const std::shared_ptr< DifferentialActionDataAbstract > &data, const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &u)
Compute the system acceleration and cost value.
const VectorXs & get_h() const
Return the state-input equality constraint bias.
const MatrixXs & get_Av() const
Return the velocity matrix.
virtual bool checkData(const std::shared_ptr< DifferentialActionDataAbstract > &data)
Checks that a specific data belongs to this model.
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.
virtual void calcDiff(const std::shared_ptr< DifferentialActionDataAbstract > &data, const Eigen::Ref< const VectorXs > &x)
Compute the derivatives of the cost functions with respect to the state only.
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 calc(const std::shared_ptr< DifferentialActionDataAbstract > &data, const Eigen::Ref< const VectorXs > &x)
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 VectorXs &f, const VectorXs &q, const VectorXs &r)
Initialize the LQR action model.
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 .