crocoddyl  1.9.0
Contact RObot COntrol by Differential DYnamic programming Library (Crocoddyl)
activation.hpp
1 // BSD 3-Clause License
3 //
4 // Copyright (C) 2019-2020, LAAS-CNRS, New York University,
5 // Max Planck Gesellschaft, University of Edinburgh
6 // Copyright note valid unless otherwise stated in individual files.
7 // All rights reserved.
9 
10 #ifndef CROCODDYL_CORE_NUMDIFF_ACTIVATION_HPP_
11 #define CROCODDYL_CORE_NUMDIFF_ACTIVATION_HPP_
12 
13 #include <vector>
14 #include <iostream>
15 
16 #include "crocoddyl/core/fwd.hpp"
17 #include "crocoddyl/core/activation-base.hpp"
18 
19 namespace crocoddyl {
20 
21 template <typename _Scalar>
22 class ActivationModelNumDiffTpl : public ActivationModelAbstractTpl<_Scalar> {
23  public:
24  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
25 
26  typedef _Scalar Scalar;
27  typedef MathBaseTpl<Scalar> MathBase;
28  typedef ActivationModelAbstractTpl<Scalar> Base;
29  typedef ActivationDataNumDiffTpl<Scalar> Data;
30  typedef ActivationDataAbstractTpl<Scalar> ActivationDataAbstract;
31  typedef typename MathBase::VectorXs VectorXs;
32  typedef typename MathBase::MatrixXs MatrixXs;
33 
39  explicit ActivationModelNumDiffTpl(boost::shared_ptr<Base> model);
40 
45 
49  virtual void calc(const boost::shared_ptr<ActivationDataAbstract>& data, const Eigen::Ref<const VectorXs>& r);
50 
54  virtual void calcDiff(const boost::shared_ptr<ActivationDataAbstract>& data, const Eigen::Ref<const VectorXs>& r);
55 
61  virtual boost::shared_ptr<ActivationDataAbstract> createData();
62 
68  const boost::shared_ptr<Base>& get_model() const;
69 
75  const Scalar get_disturbance() const;
76 
82  void set_disturbance(const Scalar disturbance);
83 
84  private:
88  boost::shared_ptr<Base> model_;
89 
94  Scalar disturbance_;
95 
96  protected:
97  using Base::nr_;
98 };
99 
100 template <typename _Scalar>
101 struct ActivationDataNumDiffTpl : public ActivationDataAbstractTpl<_Scalar> {
102  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
103 
104  typedef _Scalar Scalar;
105  typedef MathBaseTpl<Scalar> MathBase;
106  typedef typename MathBase::VectorXs VectorXs;
107  typedef ActivationDataAbstractTpl<Scalar> Base;
108  typedef typename MathBase::MatrixXs MatrixXs;
109 
116  template <template <typename Scalar> class Model>
117  explicit ActivationDataNumDiffTpl(Model<Scalar>* const model)
118  : Base(model), dr(model->get_model()->get_nr()), rp(model->get_model()->get_nr()), Arr_(Arr.rows(), Arr.cols()) {
119  dr.setZero();
120  rp.setZero();
121  Arr_.setZero();
122  data_0 = model->get_model()->createData();
123  const std::size_t nr = model->get_model()->get_nr();
124  data_rp.clear();
125  for (std::size_t i = 0; i < nr; ++i) {
126  data_rp.push_back(model->get_model()->createData());
127  }
128 
129  data_r2p.clear();
130  for (std::size_t i = 0; i < 4; ++i) {
131  data_r2p.push_back(model->get_model()->createData());
132  }
133  }
134 
135  VectorXs dr;
136  VectorXs rp;
137  boost::shared_ptr<Base> data_0;
138  std::vector<boost::shared_ptr<Base> > data_rp;
139  std::vector<boost::shared_ptr<Base> > data_r2p;
140 
141  MatrixXs Arr_;
142  using Base::a_value;
143  using Base::Ar;
144  using Base::Arr;
145 };
146 
147 } // namespace crocoddyl
148 
149 /* --- Details -------------------------------------------------------------- */
150 /* --- Details -------------------------------------------------------------- */
151 /* --- Details -------------------------------------------------------------- */
152 #include "crocoddyl/core/numdiff/activation.hxx"
153 
154 #endif // CROCODDYL_CORE_NUMDIFF_ACTIVATION_HPP_
crocoddyl::ActivationModelNumDiffTpl::~ActivationModelNumDiffTpl
virtual ~ActivationModelNumDiffTpl()
Destroy the ActivationModelNumDiff object.
crocoddyl::ActivationDataNumDiffTpl::data_0
boost::shared_ptr< Base > data_0
The data that contains the final results.
Definition: activation.hpp:137
crocoddyl::ActivationDataNumDiffTpl::ActivationDataNumDiffTpl
ActivationDataNumDiffTpl(Model< Scalar > *const model)
Construct a new ActivationDataNumDiff object.
Definition: activation.hpp:117
crocoddyl::ActivationDataNumDiffTpl::rp
VectorXs rp
The input + the disturbance on one DoF "\f$ r^+ = rp = \int r + dr \f$".
Definition: activation.hpp:136
crocoddyl::ActivationModelNumDiffTpl::calc
virtual void calc(const boost::shared_ptr< ActivationDataAbstract > &data, const Eigen::Ref< const VectorXs > &r)
crocoddyl::ActivationModelNumDiffTpl::ActivationModelNumDiffTpl
ActivationModelNumDiffTpl(boost::shared_ptr< Base > model)
Construct a new ActivationModelNumDiff object.
crocoddyl::ActivationDataNumDiffTpl::data_r2p
std::vector< boost::shared_ptr< Base > > data_r2p
The temporary data associated with the input variation.
Definition: activation.hpp:139
crocoddyl::ActivationModelNumDiffTpl::createData
virtual boost::shared_ptr< ActivationDataAbstract > createData()
Create a Data object from the given model.
crocoddyl::ActivationModelNumDiffTpl::get_disturbance
const Scalar get_disturbance() const
Get the disturbance_ object.
crocoddyl::ActivationDataNumDiffTpl::dr
VectorXs dr
disturbance:
Definition: activation.hpp:135
crocoddyl::ActivationModelNumDiffTpl::get_model
const boost::shared_ptr< Base > & get_model() const
Get the model_ object.
crocoddyl::ActivationModelNumDiffTpl::set_disturbance
void set_disturbance(const Scalar disturbance)
Set the disturbance_ object.
crocoddyl::ActivationDataNumDiffTpl::data_rp
std::vector< boost::shared_ptr< Base > > data_rp
The temporary data associated with the input variation.
Definition: activation.hpp:138
crocoddyl::ActivationModelNumDiffTpl::calcDiff
virtual void calcDiff(const boost::shared_ptr< ActivationDataAbstract > &data, const Eigen::Ref< const VectorXs > &r)
crocoddyl::ActivationDataAbstractTpl< Scalar >