GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: include/crocoddyl/core/integ-action-base.hpp Lines: 3 5 60.0 %
Date: 2024-02-13 11:12:33 Branches: 0 0 - %

Line Branch Exec Source
1
///////////////////////////////////////////////////////////////////////////////
2
// BSD 3-Clause License
3
//
4
// Copyright (C) 2021-2024, LAAS-CNRS, University of Edinburgh,
5
//                          University of Oxford, University of Trento,
6
//                          Heriot-Watt University
7
// Copyright note valid unless otherwise stated in individual files.
8
// All rights reserved.
9
///////////////////////////////////////////////////////////////////////////////
10
11
#ifndef CROCODDYL_CORE_INTEGRATED_ACTION_BASE_HPP_
12
#define CROCODDYL_CORE_INTEGRATED_ACTION_BASE_HPP_
13
14
#include "crocoddyl/core/action-base.hpp"
15
#include "crocoddyl/core/control-base.hpp"
16
#include "crocoddyl/core/diff-action-base.hpp"
17
#include "crocoddyl/core/fwd.hpp"
18
#include "crocoddyl/core/utils/deprecate.hpp"
19
20
namespace crocoddyl {
21
22
/**
23
 * @brief Abstract class for an integrated action model
24
 *
25
 * An integrated action model is a special kind of action model that is obtained
26
 * by applying  a numerical integration scheme to a differential (i.e.,
27
 * continuous time) action model. Different integration schemes can be
28
 * implemented inheriting from this base class.
29
 *
30
 * The numerical integration introduces also the possibility to parametrize the
31
 * control trajectory inside an integration step, for instance using
32
 * polynomials. This requires introducing some notation to clarify the
33
 * difference between the control inputs of the differential model and the
34
 * control inputs to the integrated model. We have decided to use
35
 * \f$\mathbf{w}\f$ to refer to the control inputs of the differential model and
36
 * \f$\mathbf{u}\f$ for the control inputs of the integrated action model.
37
 *
38
 * \sa `calc()`, `calcDiff()`, `createData()`
39
 */
40
template <typename _Scalar>
41
class IntegratedActionModelAbstractTpl
42
    : public ActionModelAbstractTpl<_Scalar> {
43
 public:
44
  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
45
46
  typedef _Scalar Scalar;
47
  typedef MathBaseTpl<Scalar> MathBase;
48
  typedef ActionModelAbstractTpl<Scalar> Base;
49
  typedef IntegratedActionDataAbstractTpl<Scalar> Data;
50
  typedef ActionDataAbstractTpl<Scalar> ActionDataAbstract;
51
  typedef DifferentialActionModelAbstractTpl<Scalar>
52
      DifferentialActionModelAbstract;
53
  typedef ControlParametrizationModelAbstractTpl<Scalar>
54
      ControlParametrizationModelAbstract;
55
  typedef typename MathBase::VectorXs VectorXs;
56
  typedef typename MathBase::MatrixXs MatrixXs;
57
58
  /**
59
   * @brief Initialize the integrator
60
   *
61
   * @param[in] model      Differential action model
62
   * @param[in] control    Control parametrization
63
   * @param[in] time_step  Step time (default 1e-3)
64
   * @param[in] with_cost_residual  Compute cost residual (default true)
65
   */
66
  IntegratedActionModelAbstractTpl(
67
      boost::shared_ptr<DifferentialActionModelAbstract> model,
68
      boost::shared_ptr<ControlParametrizationModelAbstract> control,
69
      const Scalar time_step = Scalar(1e-3),
70
      const bool with_cost_residual = true);
71
72
  /**
73
   * @brief Initialize the integrator
74
   *
75
   * This initialization uses `ControlParametrizationPolyZeroTpl` for the
76
   * control parametrization.
77
   *
78
   * @param[in] model      Differential action model
79
   * @param[in] time_step  Step time (default 1e-3)
80
   * @param[in] with_cost_residual  Compute cost residual (default true)
81
   */
82
  IntegratedActionModelAbstractTpl(
83
      boost::shared_ptr<DifferentialActionModelAbstract> model,
84
      const Scalar time_step = Scalar(1e-3),
85
      const bool with_cost_residual = true);
86
  virtual ~IntegratedActionModelAbstractTpl();
87
88
  /**
89
   * @brief Create the integrator data
90
   *
91
   * @return the sympletic integrator data
92
   */
93
  virtual boost::shared_ptr<ActionDataAbstract> createData();
94
95
  /**
96
   * @brief Return the number of inequality constraints
97
   */
98
  virtual std::size_t get_ng() const;
99
100
  /**
101
   * @brief Return the number of equality constraints
102
   */
103
  virtual std::size_t get_nh() const;
104
105
  /**
106
   * @brief Return the lower bound of the inequality constraints
107
   */
108
  virtual const VectorXs& get_g_lb() const;
109
110
  /**
111
   * @brief Return the upper bound of the inequality constraints
112
   */
113
  virtual const VectorXs& get_g_ub() const;
114
115
  /**
116
   * @brief Return the differential action model associated to this integrated
117
   * action model
118
   */
119
  const boost::shared_ptr<DifferentialActionModelAbstract>& get_differential()
120
      const;
121
122
  /**
123
   * @brief Return the control parametrization model associated to this
124
   * integrated action model
125
   */
126
  const boost::shared_ptr<ControlParametrizationModelAbstract>& get_control()
127
      const;
128
129
  /**
130
   * @brief Return the time step used for the integration
131
   */
132
  const Scalar get_dt() const;
133
134
  /**
135
   * @brief Set the time step for the integration
136
   */
137
  void set_dt(const Scalar dt);
138
139
  DEPRECATED("The DifferentialActionModel should be set at construction time",
140
             void set_differential(
141
                 boost::shared_ptr<DifferentialActionModelAbstract> model));
142
143
 protected:
144
  using Base::has_control_limits_;  //!< Indicates whether any of the control
145
                                    //!< limits are active
146
  using Base::nr_;                  //!< Dimension of the cost residual
147
  using Base::nu_;                  //!< Dimension of the control
148
  using Base::state_;               //!< Model of the state
149
  using Base::u_lb_;                //!< Lower control limits
150
  using Base::u_ub_;                //!< Upper control limits
151
152
  void init();
153
154
  boost::shared_ptr<DifferentialActionModelAbstract>
155
      differential_;  //!< Differential action model that is integrated
156
  boost::shared_ptr<ControlParametrizationModelAbstract>
157
      control_;  //!< Model of the control parametrization
158
159
  Scalar time_step_;   //!< Time step used for integration
160
  Scalar time_step2_;  //!< Square of the time step used for integration
161
  bool
162
      with_cost_residual_;  //!< Flag indicating whether a cost residual is used
163
};
164
165
template <typename _Scalar>
166
struct IntegratedActionDataAbstractTpl : public ActionDataAbstractTpl<_Scalar> {
167
  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
168
169
  typedef _Scalar Scalar;
170
  typedef MathBaseTpl<Scalar> MathBase;
171
  typedef ActionDataAbstractTpl<Scalar> Base;
172
  typedef typename MathBase::VectorXs VectorXs;
173
  typedef typename MathBase::MatrixXs MatrixXs;
174
175
  template <template <typename Scalar> class Model>
176
73896
  explicit IntegratedActionDataAbstractTpl(Model<Scalar>* const model)
177
73896
      : Base(model) {}
178
37540
  virtual ~IntegratedActionDataAbstractTpl() {}
179
180
  using Base::cost;
181
  using Base::Fu;
182
  using Base::Fx;
183
  using Base::Lu;
184
  using Base::Luu;
185
  using Base::Lx;
186
  using Base::Lxu;
187
  using Base::Lxx;
188
  using Base::r;
189
  using Base::xnext;
190
};
191
192
}  // namespace crocoddyl
193
194
/* --- Details -------------------------------------------------------------- */
195
/* --- Details -------------------------------------------------------------- */
196
/* --- Details -------------------------------------------------------------- */
197
#include "crocoddyl/core/integ-action-base.hxx"
198
199
#endif  // CROCODDYL_CORE_INTEGRATED_ACTION_BASE_HPP_