GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: include/crocoddyl/core/residuals/control.hpp Lines: 0 1 0.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) 2019-2024, LAAS-CNRS, University of Edinburgh,
5
//                          Heriot-Watt University
6
// Copyright note valid unless otherwise stated in individual files.
7
// All rights reserved.
8
///////////////////////////////////////////////////////////////////////////////
9
10
#ifndef CROCODDYL_CORE_RESIDUALS_CONTROL_HPP_
11
#define CROCODDYL_CORE_RESIDUALS_CONTROL_HPP_
12
13
#include "crocoddyl/core/fwd.hpp"
14
#include "crocoddyl/core/residual-base.hpp"
15
16
namespace crocoddyl {
17
18
/**
19
 * @brief Define a control residual
20
 *
21
 * This residual function is defined as
22
 * \f$\mathbf{r}=\mathbf{u}-\mathbf{u}^*\f$, where
23
 * \f$\mathbf{u},\mathbf{u}^*\in~\mathbb{R}^{nu}\f$ are the current and
24
 * reference control inputs, respectively. Note that the dimension of the
25
 * residual vector is obtained from `nu`.
26
 *
27
 * Both residual and residual Jacobians are computed analytically.
28
 *
29
 * As described in ResidualModelAbstractTpl(), the residual value and its
30
 * Jacobians are calculated by `calc` and `calcDiff`, respectively.
31
 *
32
 * \sa `ResidualModelAbstractTpl`, `calc()`, `calcDiff()`, `createData()`
33
 */
34
template <typename _Scalar>
35
class ResidualModelControlTpl : public ResidualModelAbstractTpl<_Scalar> {
36
 public:
37
  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
38
39
  typedef _Scalar Scalar;
40
  typedef MathBaseTpl<Scalar> MathBase;
41
  typedef ResidualModelAbstractTpl<Scalar> Base;
42
  typedef ResidualDataAbstractTpl<Scalar> ResidualDataAbstract;
43
  typedef DataCollectorAbstractTpl<Scalar> DataCollectorAbstract;
44
  typedef typename MathBase::VectorXs VectorXs;
45
  typedef typename MathBase::MatrixXs MatrixXs;
46
47
  /**
48
   * @brief Initialize the control residual model
49
   *
50
   * The default `nu` value is obtained from `StateAbstractTpl::get_nv()`.
51
   *
52
   * @param[in] state  State of the multibody system
53
   * @param[in] uref   Reference control input
54
   */
55
  ResidualModelControlTpl(boost::shared_ptr<typename Base::StateAbstract> state,
56
                          const VectorXs& uref);
57
58
  /**
59
   * @brief Initialize the control residual model
60
   *
61
   * The default `nu` value is obtained from `StateAbstractTpl::get_nv()`.
62
   *
63
   * @param[in] state  State of the multibody system
64
   * @param[in] nu     Dimension of the control vector
65
   */
66
  ResidualModelControlTpl(boost::shared_ptr<typename Base::StateAbstract> state,
67
                          const std::size_t nu);
68
69
  /**
70
   * @brief Initialize the control residual model
71
   *
72
   * The default reference control is obtained from
73
   * `MathBaseTpl<>::VectorXs::Zero(nu)`.
74
   *
75
   * @param[in] state  State of the multibody system
76
   */
77
  explicit ResidualModelControlTpl(
78
      boost::shared_ptr<typename Base::StateAbstract> state);
79
  virtual ~ResidualModelControlTpl();
80
81
  /**
82
   * @brief Compute the control residual
83
   *
84
   * @param[in] data  Control residual data
85
   * @param[in] x     State point \f$\mathbf{x}\in\mathbb{R}^{ndx}\f$
86
   * @param[in] u     Control input \f$\mathbf{u}\in\mathbb{R}^{nu}\f$
87
   */
88
  virtual void calc(const boost::shared_ptr<ResidualDataAbstract>& data,
89
                    const Eigen::Ref<const VectorXs>& x,
90
                    const Eigen::Ref<const VectorXs>& u);
91
92
  /**
93
   * @brief @copydoc Base::calc(const boost::shared_ptr<ResidualDataAbstract>&
94
   * data, const Eigen::Ref<const VectorXs>& x)
95
   */
96
  virtual void calc(const boost::shared_ptr<ResidualDataAbstract>& data,
97
                    const Eigen::Ref<const VectorXs>& x);
98
99
  /**
100
   * @brief Compute the derivatives of the control residual
101
   *
102
   * @param[in] data  Control residual data
103
   * @param[in] x     State point \f$\mathbf{x}\in\mathbb{R}^{ndx}\f$
104
   * @param[in] u     Control input \f$\mathbf{u}\in\mathbb{R}^{nu}\f$
105
   */
106
  virtual void calcDiff(const boost::shared_ptr<ResidualDataAbstract>& data,
107
                        const Eigen::Ref<const VectorXs>& x,
108
                        const Eigen::Ref<const VectorXs>& u);
109
110
  /**
111
   * @brief Create the control residual data
112
   */
113
  virtual boost::shared_ptr<ResidualDataAbstract> createData(
114
      DataCollectorAbstract* const data);
115
116
  /**
117
   * @brief Compute the derivative of the control-cost function
118
   *
119
   * This function assumes that the derivatives of the activation and residual
120
   * are computed via calcDiff functions.
121
   *
122
   * @param cdata     Cost data
123
   * @param rdata     Residual data
124
   * @param adata     Activation data
125
   * @param update_u  Update the derivative of the cost function w.r.t. to the
126
   * control if True.
127
   */
128
  virtual void calcCostDiff(
129
      const boost::shared_ptr<CostDataAbstract>& cdata,
130
      const boost::shared_ptr<ResidualDataAbstract>& rdata,
131
      const boost::shared_ptr<ActivationDataAbstract>& adata,
132
      const bool update_u = true);
133
134
  /**
135
   * @brief Return the reference control vector
136
   */
137
  const VectorXs& get_reference() const;
138
139
  /**
140
   * @brief Modify the reference control vector
141
   */
142
  void set_reference(const VectorXs& reference);
143
144
  /**
145
   * @brief Print relevant information of the control residual
146
   *
147
   * @param[out] os  Output stream object
148
   */
149
  virtual void print(std::ostream& os) const;
150
151
 protected:
152
  using Base::nu_;
153
  using Base::state_;
154
155
 private:
156
  VectorXs uref_;  //!< Reference control input
157
};
158
159
}  // namespace crocoddyl
160
161
/* --- Details -------------------------------------------------------------- */
162
/* --- Details -------------------------------------------------------------- */
163
/* --- Details -------------------------------------------------------------- */
164
#include "crocoddyl/core/residuals/control.hxx"
165
166
#endif  // CROCODDYL_CORE_RESIDUALS_CONTROL_HPP_