Line |
Branch |
Exec |
Source |
1 |
|
|
/////////////////////////////////////////////////////////////////////////////// |
2 |
|
|
// BSD 3-Clause License |
3 |
|
|
// |
4 |
|
|
// Copyright (C) 2019-2025, LAAS-CNRS, New York University, |
5 |
|
|
// Max Planck Gesellschaft, |
6 |
|
|
// University of Edinburgh, Heriot-Watt University |
7 |
|
|
// Copyright note valid unless otherwise stated in individual files. |
8 |
|
|
// All rights reserved. |
9 |
|
|
/////////////////////////////////////////////////////////////////////////////// |
10 |
|
|
|
11 |
|
|
#ifndef CROCODDYL_CORE_NUMDIFF_STATE_HPP_ |
12 |
|
|
#define CROCODDYL_CORE_NUMDIFF_STATE_HPP_ |
13 |
|
|
|
14 |
|
|
#include <memory> |
15 |
|
|
|
16 |
|
|
#include "crocoddyl/core/fwd.hpp" |
17 |
|
|
#include "crocoddyl/core/state-base.hpp" |
18 |
|
|
|
19 |
|
|
namespace crocoddyl { |
20 |
|
|
|
21 |
|
|
template <typename _Scalar> |
22 |
|
|
class StateNumDiffTpl : public StateAbstractTpl<_Scalar> { |
23 |
|
|
public: |
24 |
|
|
EIGEN_MAKE_ALIGNED_OPERATOR_NEW |
25 |
|
✗ |
CROCODDYL_DERIVED_CAST(StateBase, StateNumDiffTpl) |
26 |
|
|
|
27 |
|
|
typedef _Scalar Scalar; |
28 |
|
|
typedef MathBaseTpl<Scalar> MathBase; |
29 |
|
|
typedef StateAbstractTpl<_Scalar> Base; |
30 |
|
|
typedef typename MathBase::VectorXs VectorXs; |
31 |
|
|
typedef typename MathBase::MatrixXs MatrixXs; |
32 |
|
|
|
33 |
|
|
explicit StateNumDiffTpl(std::shared_ptr<Base> state); |
34 |
|
|
virtual ~StateNumDiffTpl(); |
35 |
|
|
|
36 |
|
|
virtual VectorXs zero() const override; |
37 |
|
|
virtual VectorXs rand() const override; |
38 |
|
|
virtual void diff(const Eigen::Ref<const VectorXs>& x0, |
39 |
|
|
const Eigen::Ref<const VectorXs>& x1, |
40 |
|
|
Eigen::Ref<VectorXs> dxout) const override; |
41 |
|
|
virtual void integrate(const Eigen::Ref<const VectorXs>& x, |
42 |
|
|
const Eigen::Ref<const VectorXs>& dx, |
43 |
|
|
Eigen::Ref<VectorXs> xout) const override; |
44 |
|
|
/** |
45 |
|
|
* @brief This computes the Jacobian of the diff method by finite |
46 |
|
|
* differentiation: |
47 |
|
|
* \f{equation}{ |
48 |
|
|
* Jfirst[:,k] = diff(int(x_1, dx_dist), x_2) - diff(x_1, x_2)/disturbance |
49 |
|
|
* \f} |
50 |
|
|
* and |
51 |
|
|
* \f{equation}{ |
52 |
|
|
* Jsecond[:,k] = diff(x_1, int(x_2, dx_dist)) - diff(x_1, x_2)/disturbance |
53 |
|
|
* \f} |
54 |
|
|
* |
55 |
|
|
* @param Jfirst |
56 |
|
|
* @param Jsecond |
57 |
|
|
* @param firstsecond |
58 |
|
|
*/ |
59 |
|
|
virtual void Jdiff(const Eigen::Ref<const VectorXs>& x0, |
60 |
|
|
const Eigen::Ref<const VectorXs>& x1, |
61 |
|
|
Eigen::Ref<MatrixXs> Jfirst, Eigen::Ref<MatrixXs> Jsecond, |
62 |
|
|
Jcomponent firstsecond = both) const override; |
63 |
|
|
/** |
64 |
|
|
* @brief This computes the Jacobian of the integrate method by finite |
65 |
|
|
* differentiation: |
66 |
|
|
* \f{equation}{ |
67 |
|
|
* Jfirst[:,k] = diff( int(x, d_x), int( int(x, dx_dist), dx) )/disturbance |
68 |
|
|
* \f} |
69 |
|
|
* and |
70 |
|
|
* \f{equation}{ |
71 |
|
|
* Jsecond[:,k] = diff( int(x, d_x), int( x, dx + dx_dist) )/disturbance |
72 |
|
|
* \f} |
73 |
|
|
* |
74 |
|
|
* @param Jfirst |
75 |
|
|
* @param Jsecond |
76 |
|
|
* @param firstsecond |
77 |
|
|
*/ |
78 |
|
|
virtual void Jintegrate(const Eigen::Ref<const VectorXs>& x, |
79 |
|
|
const Eigen::Ref<const VectorXs>& dx, |
80 |
|
|
Eigen::Ref<MatrixXs> Jfirst, |
81 |
|
|
Eigen::Ref<MatrixXs> Jsecond, |
82 |
|
|
const Jcomponent firstsecond = both, |
83 |
|
|
const AssignmentOp op = setto) const override; |
84 |
|
|
|
85 |
|
|
virtual void JintegrateTransport( |
86 |
|
|
const Eigen::Ref<const VectorXs>& x, const Eigen::Ref<const VectorXs>& dx, |
87 |
|
|
Eigen::Ref<MatrixXs> Jin, |
88 |
|
|
const Jcomponent firstsecond = both) const override; |
89 |
|
|
|
90 |
|
|
template <typename NewScalar> |
91 |
|
|
StateNumDiffTpl<NewScalar> cast() const; |
92 |
|
|
|
93 |
|
|
/** |
94 |
|
|
* @brief Return the disturbance constant used in the numerical |
95 |
|
|
* differentiation routine |
96 |
|
|
*/ |
97 |
|
|
const Scalar get_disturbance() const; |
98 |
|
|
|
99 |
|
|
/** |
100 |
|
|
* @brief Modify the disturbance constant used by the numerical |
101 |
|
|
* differentiation routine |
102 |
|
|
*/ |
103 |
|
|
void set_disturbance(const Scalar disturbance); |
104 |
|
|
|
105 |
|
|
private: |
106 |
|
|
std::shared_ptr<Base> |
107 |
|
|
state_; //!< state we need to compute the numerical differentiation |
108 |
|
|
Scalar e_jac_; //!< Constant used for computing disturbances in Jacobian |
109 |
|
|
//!< calculation |
110 |
|
|
|
111 |
|
|
protected: |
112 |
|
|
using Base::has_limits_; |
113 |
|
|
using Base::lb_; |
114 |
|
|
using Base::ndx_; |
115 |
|
|
using Base::nq_; |
116 |
|
|
using Base::nv_; |
117 |
|
|
using Base::nx_; |
118 |
|
|
using Base::ub_; |
119 |
|
|
}; |
120 |
|
|
|
121 |
|
|
} // namespace crocoddyl |
122 |
|
|
|
123 |
|
|
/* --- Details -------------------------------------------------------------- */ |
124 |
|
|
/* --- Details -------------------------------------------------------------- */ |
125 |
|
|
/* --- Details -------------------------------------------------------------- */ |
126 |
|
|
#include "crocoddyl/core/numdiff/state.hxx" |
127 |
|
|
|
128 |
|
|
CROCODDYL_DECLARE_EXTERN_TEMPLATE_CLASS(crocoddyl::StateNumDiffTpl) |
129 |
|
|
|
130 |
|
|
#endif // CROCODDYL_CORE_NUMDIFF_STATE_HPP_ |
131 |
|
|
|