10 #ifndef CROCODDYL_CORE_ACTIONS_LQR_HPP_
11 #define CROCODDYL_CORE_ACTIONS_LQR_HPP_
15 #include "crocoddyl/core/action-base.hpp"
16 #include "crocoddyl/core/fwd.hpp"
17 #include "crocoddyl/core/states/euclidean.hpp"
46 template <
typename _Scalar>
49 typedef _Scalar Scalar;
55 typedef typename MathBase::VectorXs VectorXs;
56 typedef typename MathBase::MatrixXs MatrixXs;
68 const MatrixXs& R,
const MatrixXs& N);
83 const MatrixXs& R,
const MatrixXs& N,
const VectorXs& f,
84 const VectorXs& q,
const VectorXs& r);
103 const MatrixXs& R,
const MatrixXs& N,
const MatrixXs& G,
104 const MatrixXs& H,
const VectorXs& f,
const VectorXs& q,
105 const VectorXs& r,
const VectorXs& g,
const VectorXs& h);
116 const bool drift_free =
true);
123 virtual void calc(
const boost::shared_ptr<ActionDataAbstract>& data,
124 const Eigen::Ref<const VectorXs>& x,
125 const Eigen::Ref<const VectorXs>& u);
126 virtual void calc(
const boost::shared_ptr<ActionDataAbstract>& data,
127 const Eigen::Ref<const VectorXs>& x);
128 virtual void calcDiff(
const boost::shared_ptr<ActionDataAbstract>& data,
129 const Eigen::Ref<const VectorXs>& x,
130 const Eigen::Ref<const VectorXs>& u);
131 virtual void calcDiff(
const boost::shared_ptr<ActionDataAbstract>& data,
132 const Eigen::Ref<const VectorXs>& x);
134 virtual bool checkData(
const boost::shared_ptr<ActionDataAbstract>& data);
145 const std::size_t ng = 0,
146 const std::size_t nh = 0);
200 void set_LQR(
const MatrixXs& A,
const MatrixXs& B,
const MatrixXs& Q,
201 const MatrixXs& R,
const MatrixXs& N,
const MatrixXs& G,
202 const MatrixXs& H,
const VectorXs& f,
const VectorXs& q,
203 const VectorXs& r,
const VectorXs& g,
const VectorXs& h);
205 DEPRECATED(
"Use get_A",
const MatrixXs& get_Fx()
const {
return get_A(); })
206 DEPRECATED(
"Use get_B",
const MatrixXs& get_Fu()
const {
return get_B(); })
207 DEPRECATED(
"Use get_f",
const VectorXs& get_f0()
const {
return get_f(); })
208 DEPRECATED(
"Use get_q",
const VectorXs& get_lx()
const {
return get_q(); })
209 DEPRECATED(
"Use get_r",
const VectorXs& get_lu()
const {
return get_r(); })
210 DEPRECATED(
"Use get_Q",
const MatrixXs& get_Lxx()
const {
return get_Q(); })
211 DEPRECATED(
"Use get_R",
const MatrixXs& get_Lxu()
const {
return get_R(); })
212 DEPRECATED(
"Use get_N",
const MatrixXs& get_Luu()
const {
return get_N(); })
214 "Use set_LQR",
void set_Fx(
const MatrixXs& A) {
215 set_LQR(A, B_, Q_, R_, N_, G_, H_, f_, q_, r_, g_, h_);
218 "Use set_LQR",
void set_Fu(
const MatrixXs& B) {
219 set_LQR(A_, B, Q_, R_, N_, G_, H_, f_, q_, r_, g_, h_);
222 "Use set_LQR",
void set_f0(
const VectorXs& f) {
223 set_LQR(A_, B_, Q_, R_, N_, G_, H_, f, q_, r_, g_, h_);
226 "Use set_LQR",
void set_lx(
const VectorXs& q) {
227 set_LQR(A_, B_, Q_, R_, N_, G_, H_, f_, q, r_, g_, h_);
230 "Use set_LQR",
void set_lu(
const VectorXs& r) {
231 set_LQR(A_, B_, Q_, R_, N_, G_, H_, f_, q_, r, g_, h_);
234 "Use set_LQR",
void set_Lxx(
const MatrixXs& Q) {
235 set_LQR(A_, B_, Q, R_, N_, G_, H_, f_, q_, r_, g_, h_);
238 "Use set_LQR",
void set_Luu(
const MatrixXs& R) {
239 set_LQR(A_, B_, Q_, R, N_, G_, H_, f_, q_, r_, g_, h_);
242 "Use set_LQR",
void set_Lxu(
const MatrixXs& N) {
243 set_LQR(A_, B_, Q_, R_, N, G_, H_, f_, q_, r_, g_, h_);
251 virtual void print(std::ostream& os)
const;
277 template <
typename _Scalar>
279 typedef _Scalar Scalar;
282 typedef typename MathBase::VectorXs VectorXs;
284 template <
template <
typename Scalar>
class Model>
287 R_u_tmp(VectorXs::Zero(
static_cast<Eigen::Index
>(model->get_nu()))),
288 Q_x_tmp(VectorXs::Zero(
289 static_cast<Eigen::Index
>(model->get_state()->get_ndx()))) {
291 const std::size_t nq = model->get_state()->get_nq();
292 const std::size_t nu = model->get_nu();
295 Lxx = model->get_Q();
296 Luu = model->get_R();
297 Lxu = model->get_N();
298 Gx = model->get_G().leftCols(2 * nq);
299 Gu = model->get_G().rightCols(nu);
300 Hx = model->get_H().leftCols(2 * nq);
301 Hu = model->get_H().rightCols(nu);
330 #include "crocoddyl/core/actions/lqr.hxx"
Abstract class for action model.
boost::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.
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.
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.
virtual void print(std::ostream &os) const
Print relevant information of the LQR model.
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.
virtual void calc(const boost::shared_ptr< ActionDataAbstract > &data, const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &u)
Compute the next state and cost value.
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 calcDiff(const boost::shared_ptr< ActionDataAbstract > &data, const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &u)
Compute the derivatives of the dynamics and cost functions.
const VectorXs & get_g() const
Return the state-input inequality constraint bias.
virtual bool checkData(const boost::shared_ptr< ActionDataAbstract > &data)
Checks that a specific data belongs to this model.
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.
const MatrixXs & get_G() const
Return the state-input inequality constraint matrix.
const MatrixXs & get_B() const
Return the input matrix.
virtual void calc(const boost::shared_ptr< ActionDataAbstract > &data, const Eigen::Ref< const VectorXs > &x)
Compute the total cost value for nodes that depends only on the state.
virtual void calcDiff(const boost::shared_ptr< ActionDataAbstract > &data, const Eigen::Ref< const VectorXs > &x)
Compute the derivatives of the cost functions with respect to the state only.
virtual boost::shared_ptr< ActionDataAbstract > createData()
Create the action data.
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 .