crocoddyl  1.3.0
Contact RObot COntrol by Differential DYnamic programming Library (Crocoddyl)
contact-fwddyn.hpp
1 // BSD 3-Clause License
3 //
4 // Copyright (C) 2018-2020, LAAS-CNRS, University of Edinburgh
5 // Copyright note valid unless otherwise stated in individual files.
6 // All rights reserved.
8 
9 #ifndef CROCODDYL_MULTIBODY_ACTIONS_CONTACT_FWDDYN_HPP_
10 #define CROCODDYL_MULTIBODY_ACTIONS_CONTACT_FWDDYN_HPP_
11 
12 #include <stdexcept>
13 
14 #include "crocoddyl/multibody/fwd.hpp"
15 #include "crocoddyl/core/diff-action-base.hpp"
16 #include "crocoddyl/multibody/states/multibody.hpp"
17 #include "crocoddyl/multibody/actuations/floating-base.hpp"
18 #include "crocoddyl/multibody/contacts/multiple-contacts.hpp"
19 #include "crocoddyl/multibody/data/contacts.hpp"
20 #include "crocoddyl/multibody/costs/cost-sum.hpp"
21 
22 namespace crocoddyl {
23 
24 template <typename _Scalar>
26  public:
27  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
28 
29  typedef _Scalar Scalar;
38  typedef typename MathBase::VectorXs VectorXs;
39  typedef typename MathBase::MatrixXs MatrixXs;
40 
41  DifferentialActionModelContactFwdDynamicsTpl(boost::shared_ptr<StateMultibody> state,
42  boost::shared_ptr<ActuationModelFloatingBase> actuation,
43  boost::shared_ptr<ContactModelMultiple> contacts,
44  boost::shared_ptr<CostModelSum> costs,
45  const Scalar& JMinvJt_damping = Scalar(0.),
46  const bool& enable_force = false);
48 
49  virtual void calc(const boost::shared_ptr<DifferentialActionDataAbstract>& data, const Eigen::Ref<const VectorXs>& x,
50  const Eigen::Ref<const VectorXs>& u);
51  virtual void calcDiff(const boost::shared_ptr<DifferentialActionDataAbstract>& data,
52  const Eigen::Ref<const VectorXs>& x, const Eigen::Ref<const VectorXs>& u);
53  virtual boost::shared_ptr<DifferentialActionDataAbstract> createData();
54 
55  const boost::shared_ptr<ActuationModelFloatingBase>& get_actuation() const;
56  const boost::shared_ptr<ContactModelMultiple>& get_contacts() const;
57  const boost::shared_ptr<CostModelSum>& get_costs() const;
58  pinocchio::ModelTpl<Scalar>& get_pinocchio() const;
59  const VectorXs& get_armature() const;
60  const Scalar& get_damping_factor() const;
61 
62  void set_armature(const VectorXs& armature);
63  void set_damping_factor(const Scalar& damping);
64 
65  protected:
67  using Base::nr_;
68  using Base::nu_;
69  using Base::state_;
70  using Base::u_lb_;
71  using Base::u_ub_;
72  using Base::unone_;
73 
74  private:
75  boost::shared_ptr<ActuationModelFloatingBase> actuation_;
76  boost::shared_ptr<ContactModelMultiple> contacts_;
77  boost::shared_ptr<CostModelSum> costs_;
78  pinocchio::ModelTpl<Scalar>& pinocchio_;
79  bool with_armature_;
80  VectorXs armature_;
81  Scalar JMinvJt_damping_;
82  bool enable_force_;
83 };
84 
85 template <typename _Scalar>
87  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
88  typedef _Scalar Scalar;
91  typedef typename MathBase::VectorXs VectorXs;
92  typedef typename MathBase::MatrixXs MatrixXs;
93 
94  template <template <typename Scalar> class Model>
95  explicit DifferentialActionDataContactFwdDynamicsTpl(Model<Scalar>* const model)
96  : Base(model),
97  pinocchio(pinocchio::DataTpl<Scalar>(model->get_pinocchio())),
98  multibody(&pinocchio, model->get_actuation()->createData(), model->get_contacts()->createData(&pinocchio)),
99  costs(model->get_costs()->createData(&multibody)),
100  Kinv(model->get_state()->get_nv() + model->get_contacts()->get_nc_total(),
101  model->get_state()->get_nv() + model->get_contacts()->get_nc_total()),
102  df_dx(model->get_contacts()->get_nc_total(), model->get_state()->get_ndx()),
103  df_du(model->get_contacts()->get_nc_total(), model->get_nu()) {
104  costs->shareMemory(this);
105  Kinv.setZero();
106  df_dx.setZero();
107  df_du.setZero();
108  }
109 
110  pinocchio::DataTpl<Scalar> pinocchio;
112  boost::shared_ptr<CostDataSumTpl<Scalar> > costs;
113  MatrixXs Kinv;
114  MatrixXs df_dx;
115  MatrixXs df_du;
116 
117  using Base::cost;
118  using Base::Fu;
119  using Base::Fx;
120  using Base::Lu;
121  using Base::Luu;
122  using Base::Lx;
123  using Base::Lxu;
124  using Base::Lxx;
125  using Base::r;
126  using Base::xout;
127 };
128 
129 } // namespace crocoddyl
130 
131 /* --- Details -------------------------------------------------------------- */
132 /* --- Details -------------------------------------------------------------- */
133 /* --- Details -------------------------------------------------------------- */
134 #include <crocoddyl/multibody/actions/contact-fwddyn.hxx>
135 
136 #endif // CROCODDYL_MULTIBODY_ACTIONS_CONTACT_FWDDYN_HPP_
This class DifferentialActionModelAbstract represents a first-order ODE, i.e. where and represents ...
std::size_t nr_
Dimension of the cost residual.
bool has_control_limits_
Indicates whether any of the control limits is finite.
boost::shared_ptr< StateAbstract > state_
Model of the state.