Crocoddyl
state.hpp
1 // BSD 3-Clause License
3 //
4 // Copyright (C) 2019-2023, LAAS-CNRS, New York University, Max Planck
5 // Gesellschaft,
6 // University of Edinburgh, Heriot-Watt University
7 // Copyright note valid unless otherwise stated in individual files.
8 // All rights reserved.
10 
11 #ifndef CROCODDYL_CORE_NUMDIFF_STATE_HPP_
12 #define CROCODDYL_CORE_NUMDIFF_STATE_HPP_
13 
14 #include <boost/make_shared.hpp>
15 #include <boost/shared_ptr.hpp>
16 
17 #include "crocoddyl/core/fwd.hpp"
18 #include "crocoddyl/core/state-base.hpp"
19 
20 namespace crocoddyl {
21 
22 template <typename _Scalar>
23 class StateNumDiffTpl : public StateAbstractTpl<_Scalar> {
24  public:
25  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
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(boost::shared_ptr<Base> state);
34  virtual ~StateNumDiffTpl();
35 
36  virtual VectorXs zero() const;
37  virtual VectorXs rand() const;
38  virtual void diff(const Eigen::Ref<const VectorXs>& x0,
39  const Eigen::Ref<const VectorXs>& x1,
40  Eigen::Ref<VectorXs> dxout) const;
41  virtual void integrate(const Eigen::Ref<const VectorXs>& x,
42  const Eigen::Ref<const VectorXs>& dx,
43  Eigen::Ref<VectorXs> xout) const;
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;
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;
84 
85  virtual void JintegrateTransport(const Eigen::Ref<const VectorXs>& x,
86  const Eigen::Ref<const VectorXs>& dx,
87  Eigen::Ref<MatrixXs> Jin,
88  const Jcomponent firstsecond = both) const;
89 
94  const Scalar get_disturbance() const;
95 
100  void set_disturbance(const Scalar disturbance);
101 
102  private:
103  boost::shared_ptr<Base>
104  state_;
105  Scalar e_jac_;
106 
108  protected:
109  using Base::has_limits_;
110  using Base::lb_;
111  using Base::ndx_;
112  using Base::nq_;
113  using Base::nv_;
114  using Base::nx_;
115  using Base::ub_;
116 };
117 
118 } // namespace crocoddyl
119 
120 /* --- Details -------------------------------------------------------------- */
121 /* --- Details -------------------------------------------------------------- */
122 /* --- Details -------------------------------------------------------------- */
123 #include "crocoddyl/core/numdiff/state.hxx"
124 
125 #endif // CROCODDYL_CORE_NUMDIFF_STATE_HPP_
crocoddyl::StateAbstractTpl::lb_
VectorXs lb_
Lower state limits.
Definition: state-base.hpp:322
crocoddyl::StateNumDiffTpl::set_disturbance
void set_disturbance(const Scalar disturbance)
Modify the disturbance constant used by the numerical differentiation routine.
crocoddyl::StateAbstractTpl::has_limits_
bool has_limits_
Indicates whether any of the state limits is finite.
Definition: state-base.hpp:324
crocoddyl::StateAbstractTpl::ub_
VectorXs ub_
Upper state limits.
Definition: state-base.hpp:323
crocoddyl::StateAbstractTpl::nx_
std::size_t nx_
State dimension.
Definition: state-base.hpp:318
crocoddyl::StateAbstractTpl::nv_
std::size_t nv_
Velocity dimension.
Definition: state-base.hpp:321
crocoddyl::StateNumDiffTpl::get_disturbance
const Scalar get_disturbance() const
Return the disturbance constant used in the numerical differentiation routine.
crocoddyl::StateNumDiffTpl::Jintegrate
virtual void Jintegrate(const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &dx, Eigen::Ref< MatrixXs > Jfirst, Eigen::Ref< MatrixXs > Jsecond, const Jcomponent firstsecond=both, const AssignmentOp op=setto) const
This computes the Jacobian of the integrate method by finite differentiation:
crocoddyl::StateAbstractTpl::ndx_
std::size_t ndx_
State rate dimension.
Definition: state-base.hpp:319
crocoddyl::StateAbstractTpl::nq_
std::size_t nq_
Configuration dimension.
Definition: state-base.hpp:320
crocoddyl::StateNumDiffTpl::Jdiff
virtual void Jdiff(const Eigen::Ref< const VectorXs > &x0, const Eigen::Ref< const VectorXs > &x1, Eigen::Ref< MatrixXs > Jfirst, Eigen::Ref< MatrixXs > Jsecond, Jcomponent firstsecond=both) const
This computes the Jacobian of the diff method by finite differentiation: