10 #ifndef CROCODDYL_CORE_ACTIONS_LQR_HPP_
11 #define CROCODDYL_CORE_ACTIONS_LQR_HPP_
13 #include "crocoddyl/core/action-base.hpp"
14 #include "crocoddyl/core/fwd.hpp"
15 #include "crocoddyl/core/states/euclidean.hpp"
44 template <
typename _Scalar>
47 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
50 typedef _Scalar Scalar;
56 typedef typename MathBase::VectorXs VectorXs;
57 typedef typename MathBase::MatrixXs MatrixXs;
69 const MatrixXs& R,
const MatrixXs& N);
84 const MatrixXs& R,
const MatrixXs& N,
const VectorXs& f,
85 const VectorXs& q,
const VectorXs& r);
104 const MatrixXs& R,
const MatrixXs& N,
const MatrixXs& G,
105 const MatrixXs& H,
const VectorXs& f,
const VectorXs& q,
106 const VectorXs& r,
const VectorXs& g,
const VectorXs& h);
117 const bool drift_free =
true);
124 virtual void calc(
const std::shared_ptr<ActionDataAbstract>& data,
125 const Eigen::Ref<const VectorXs>& x,
126 const Eigen::Ref<const VectorXs>& u)
override;
127 virtual void calc(
const std::shared_ptr<ActionDataAbstract>& data,
128 const Eigen::Ref<const VectorXs>& x)
override;
129 virtual void calcDiff(
const std::shared_ptr<ActionDataAbstract>& data,
130 const Eigen::Ref<const VectorXs>& x,
131 const Eigen::Ref<const VectorXs>& u)
override;
132 virtual void calcDiff(
const std::shared_ptr<ActionDataAbstract>& data,
133 const Eigen::Ref<const VectorXs>& x)
override;
134 virtual std::shared_ptr<ActionDataAbstract>
createData()
override;
145 template <
typename NewScalar>
149 const std::shared_ptr<ActionDataAbstract>& data)
override;
160 const std::size_t ng = 0,
161 const std::size_t nh = 0);
215 void set_LQR(
const MatrixXs& A,
const MatrixXs& B,
const MatrixXs& Q,
216 const MatrixXs& R,
const MatrixXs& N,
const MatrixXs& G,
217 const MatrixXs& H,
const VectorXs& f,
const VectorXs& q,
218 const VectorXs& r,
const VectorXs& g,
const VectorXs& h);
220 DEPRECATED(
"Use get_A",
const MatrixXs& get_Fx()
const {
return get_A(); })
221 DEPRECATED(
"Use get_B",
const MatrixXs& get_Fu()
const {
return get_B(); })
222 DEPRECATED(
"Use get_f",
const VectorXs& get_f0()
const {
return get_f(); })
223 DEPRECATED(
"Use get_q",
const VectorXs& get_lx()
const {
return get_q(); })
224 DEPRECATED(
"Use get_r",
const VectorXs& get_lu()
const {
return get_r(); })
225 DEPRECATED(
"Use get_Q",
const MatrixXs& get_Lxx()
const {
return get_Q(); })
226 DEPRECATED(
"Use get_R",
const MatrixXs& get_Lxu()
const {
return get_R(); })
227 DEPRECATED(
"Use get_N",
const MatrixXs& get_Luu()
const {
return get_N(); })
229 "Use set_LQR",
void set_Fx(
const MatrixXs& A) {
230 set_LQR(A, B_, Q_, R_, N_, G_, H_, f_, q_, r_, g_, h_);
233 "Use set_LQR",
void set_Fu(
const MatrixXs& B) {
234 set_LQR(A_, B, Q_, R_, N_, G_, H_, f_, q_, r_, g_, h_);
237 "Use set_LQR",
void set_f0(
const VectorXs& f) {
238 set_LQR(A_, B_, Q_, R_, N_, G_, H_, f, q_, r_, g_, h_);
241 "Use set_LQR",
void set_lx(
const VectorXs& q) {
242 set_LQR(A_, B_, Q_, R_, N_, G_, H_, f_, q, r_, g_, h_);
245 "Use set_LQR",
void set_lu(
const VectorXs& r) {
246 set_LQR(A_, B_, Q_, R_, N_, G_, H_, f_, q_, r, g_, h_);
249 "Use set_LQR",
void set_Lxx(
const MatrixXs& Q) {
250 set_LQR(A_, B_, Q, R_, N_, G_, H_, f_, q_, r_, g_, h_);
253 "Use set_LQR",
void set_Luu(
const MatrixXs& R) {
254 set_LQR(A_, B_, Q_, R, N_, G_, H_, f_, q_, r_, g_, h_);
257 "Use set_LQR",
void set_Lxu(
const MatrixXs& N) {
258 set_LQR(A_, B_, Q_, R_, N, G_, H_, f_, q_, r_, g_, h_);
266 virtual void print(std::ostream& os)
const override;
292 template <
typename _Scalar>
294 typedef _Scalar Scalar;
297 typedef typename MathBase::VectorXs VectorXs;
299 template <
template <
typename Scalar>
class Model>
302 R_u_tmp(VectorXs::Zero(
static_cast<Eigen::Index
>(model->get_nu()))),
303 Q_x_tmp(VectorXs::Zero(
304 static_cast<Eigen::Index
>(model->get_state()->get_ndx()))) {
306 const std::size_t nq = model->get_state()->get_nq();
307 const std::size_t nu = model->get_nu();
310 Lxx = model->get_Q();
311 Luu = model->get_R();
312 Lxu = model->get_N();
313 Gx = model->get_G().leftCols(2 * nq);
314 Gu = model->get_G().rightCols(nu);
315 Hx = model->get_H().leftCols(2 * nq);
316 Hu = model->get_H().rightCols(nu);
346 #include "crocoddyl/core/actions/lqr.hxx"
Abstract class for 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) action model.
virtual void calc(const std::shared_ptr< ActionDataAbstract > &data, const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &u) override
Compute the next state and cost value.
const MatrixXs & get_R() const
Return the input weight matrix.
const VectorXs & get_q() const
Return the state weight vector.
const MatrixXs & get_A() const
Return the state matrix.
virtual std::shared_ptr< ActionDataAbstract > createData() override
Create the action data.
virtual void calcDiff(const std::shared_ptr< ActionDataAbstract > &data, const Eigen::Ref< const VectorXs > &x) override
Compute the derivatives of the cost functions with respect to the state only.
virtual bool checkData(const std::shared_ptr< ActionDataAbstract > &data) override
Checks that a specific data belongs to this model.
const VectorXs & get_f() const
Return the dynamics drift.
void set_LQR(const MatrixXs &A, 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.
ActionModelLQRTpl(const ActionModelLQRTpl ©)
Copy constructor.
const VectorXs & get_r() const
Return the input weight vector.
ActionModelLQRTpl(const MatrixXs &A, 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.
ActionModelLQRTpl(const MatrixXs &A, const MatrixXs &B, const MatrixXs &Q, const MatrixXs &R, const MatrixXs &N)
Initialize the LQR action model.
ActionModelLQRTpl(const MatrixXs &A, 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.
static ActionModelLQRTpl Random(const std::size_t nx, 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_h() const
Return the state-input equality constraint bias.
virtual void calc(const std::shared_ptr< ActionDataAbstract > &data, const Eigen::Ref< const VectorXs > &x) override
Compute the total cost value for nodes that depends only on the state.
ActionModelLQRTpl< NewScalar > cast() const
Cast the LQR model to a different scalar type.
const VectorXs & get_g() const
Return the state-input inequality constraint bias.
const MatrixXs & get_N() const
Return the state-input weight matrix.
ActionModelLQRTpl(const std::size_t nx, const std::size_t nu, const bool drift_free=true)
Initialize the LQR action model.
virtual void calcDiff(const std::shared_ptr< ActionDataAbstract > &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_G() const
Return the state-input inequality constraint matrix.
const MatrixXs & get_B() const
Return the input matrix.
virtual void print(std::ostream &os) const override
Print relevant information of the LQR model.
const MatrixXs & get_Q() const
Return the state weight matrix.
const MatrixXs & get_H() const
Return the state-input equality constraint matrix.
VectorXs xnext
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 .
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 .
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 .