Crocoddyl
activation.hpp
1 // BSD 3-Clause License
3 //
4 // Copyright (C) 2019-2023, 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 <iostream>
14 #include <vector>
15 
16 #include "crocoddyl/core/activation-base.hpp"
17 #include "crocoddyl/core/fwd.hpp"
18 
19 namespace crocoddyl {
20 
21 template <typename _Scalar>
23  public:
24  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
25 
26  typedef _Scalar Scalar;
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,
50  const Eigen::Ref<const VectorXs>& r);
51 
55  virtual void calcDiff(const boost::shared_ptr<ActivationDataAbstract>& data,
56  const Eigen::Ref<const VectorXs>& r);
57 
63  virtual boost::shared_ptr<ActivationDataAbstract> createData();
64 
70  const boost::shared_ptr<Base>& get_model() const;
71 
76  const Scalar get_disturbance() const;
77 
82  void set_disturbance(const Scalar disturbance);
83 
84  private:
85  boost::shared_ptr<Base>
86  model_;
87  Scalar e_jac_;
89 
90  protected:
91  using Base::nr_;
92 };
93 
94 template <typename _Scalar>
96  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
97 
98  typedef _Scalar Scalar;
100  typedef typename MathBase::VectorXs VectorXs;
102  typedef typename MathBase::MatrixXs MatrixXs;
103 
110  template <template <typename Scalar> class Model>
111  explicit ActivationDataNumDiffTpl(Model<Scalar>* const model)
112  : Base(model),
113  dr(model->get_model()->get_nr()),
114  rp(model->get_model()->get_nr()),
115  Arr_(Arr.rows(), Arr.cols()) {
116  dr.setZero();
117  rp.setZero();
118  Arr_.setZero();
119  data_0 = model->get_model()->createData();
120  const std::size_t nr = model->get_model()->get_nr();
121  data_rp.clear();
122  for (std::size_t i = 0; i < nr; ++i) {
123  data_rp.push_back(model->get_model()->createData());
124  }
125 
126  data_r2p.clear();
127  for (std::size_t i = 0; i < 4; ++i) {
128  data_r2p.push_back(model->get_model()->createData());
129  }
130  }
131 
132  VectorXs dr;
133  VectorXs rp;
135  boost::shared_ptr<Base> data_0;
136  std::vector<boost::shared_ptr<Base> >
138  std::vector<boost::shared_ptr<Base> >
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_
virtual boost::shared_ptr< ActivationDataAbstract > createData()
Create a Data object from the given model.
const Scalar get_disturbance() const
Return the disturbance constant used in the numerical differentiation routine.
virtual void calc(const boost::shared_ptr< ActivationDataAbstract > &data, const Eigen::Ref< const VectorXs > &r)
void set_disturbance(const Scalar disturbance)
Modify the disturbance constant used in the numerical differentiation routine.
ActivationModelNumDiffTpl(boost::shared_ptr< Base > model)
Construct a new ActivationModelNumDiff object.
virtual void calcDiff(const boost::shared_ptr< ActivationDataAbstract > &data, const Eigen::Ref< const VectorXs > &r)
const boost::shared_ptr< Base > & get_model() const
Get the model_ object.
virtual ~ActivationModelNumDiffTpl()
Destroy the ActivationModelNumDiff object.
boost::shared_ptr< Base > data_0
The data that contains the final results.
Definition: activation.hpp:135
std::vector< boost::shared_ptr< Base > > data_rp
The temporary data associated with the input variation.
Definition: activation.hpp:137
ActivationDataNumDiffTpl(Model< Scalar > *const model)
Construct a new ActivationDataNumDiff object.
Definition: activation.hpp:111
std::vector< boost::shared_ptr< Base > > data_r2p
The temporary data associated with the input variation.
Definition: activation.hpp:139