crocoddyl  1.9.0
Contact RObot COntrol by Differential DYnamic programming Library (Crocoddyl)
state-base.hpp
1 // BSD 3-Clause License
3 //
4 // Copyright (C) 2019-2020, LAAS-CNRS, University of Edinburgh, INRIA
5 // Copyright note valid unless otherwise stated in individual files.
6 // All rights reserved.
8 
9 #ifndef CROCODDYL_CORE_STATE_BASE_HPP_
10 #define CROCODDYL_CORE_STATE_BASE_HPP_
11 
12 #include <vector>
13 #include <string>
14 #include <stdexcept>
15 
16 #include "crocoddyl/core/fwd.hpp"
17 #include "crocoddyl/core/mathbase.hpp"
18 #include "crocoddyl/core/utils/exception.hpp"
19 
20 namespace crocoddyl {
21 
22 enum Jcomponent { both = 0, first = 1, second = 2 };
23 
24 inline bool is_a_Jcomponent(Jcomponent firstsecond) {
25  return (firstsecond == first || firstsecond == second || firstsecond == both);
26 }
27 
41 template <typename _Scalar>
43  public:
44  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
45 
46  typedef _Scalar Scalar;
48  typedef typename MathBase::VectorXs VectorXs;
49  typedef typename MathBase::MatrixXs MatrixXs;
50 
57  StateAbstractTpl(const std::size_t nx, const std::size_t ndx);
59  virtual ~StateAbstractTpl();
60 
64  virtual VectorXs zero() const = 0;
65 
69  virtual VectorXs rand() const = 0;
70 
86  virtual void diff(const Eigen::Ref<const VectorXs>& x0, const Eigen::Ref<const VectorXs>& x1,
87  Eigen::Ref<VectorXs> dxout) const = 0;
88 
104  virtual void integrate(const Eigen::Ref<const VectorXs>& x, const Eigen::Ref<const VectorXs>& dx,
105  Eigen::Ref<VectorXs> xout) const = 0;
106 
141  virtual void Jdiff(const Eigen::Ref<const VectorXs>& x0, const Eigen::Ref<const VectorXs>& x1,
142  Eigen::Ref<MatrixXs> Jfirst, Eigen::Ref<MatrixXs> Jsecond,
143  const Jcomponent firstsecond = both) const = 0;
144 
177  virtual void Jintegrate(const Eigen::Ref<const VectorXs>& x, const Eigen::Ref<const VectorXs>& dx,
178  Eigen::Ref<MatrixXs> Jfirst, Eigen::Ref<MatrixXs> Jsecond,
179  const Jcomponent firstsecond = both, const AssignmentOp op = setto) const = 0;
180 
193  virtual void JintegrateTransport(const Eigen::Ref<const VectorXs>& x, const Eigen::Ref<const VectorXs>& dx,
194  Eigen::Ref<MatrixXs> Jin, const Jcomponent firstsecond) const = 0;
195 
203  VectorXs diff_dx(const Eigen::Ref<const VectorXs>& x0, const Eigen::Ref<const VectorXs>& x1);
204 
212  VectorXs integrate_x(const Eigen::Ref<const VectorXs>& x, const Eigen::Ref<const VectorXs>& dx);
213 
221  std::vector<MatrixXs> Jdiff_Js(const Eigen::Ref<const VectorXs>& x0, const Eigen::Ref<const VectorXs>& x1,
222  const Jcomponent firstsecond = both);
223 
231  std::vector<MatrixXs> Jintegrate_Js(const Eigen::Ref<const VectorXs>& x, const Eigen::Ref<const VectorXs>& dx,
232  const Jcomponent firstsecond = both);
233 
237  std::size_t get_nx() const;
238 
242  std::size_t get_ndx() const;
243 
247  std::size_t get_nq() const;
248 
252  std::size_t get_nv() const;
253 
257  const VectorXs& get_lb() const;
258 
262  const VectorXs& get_ub() const;
263 
267  bool get_has_limits() const;
268 
272  void set_lb(const VectorXs& lb);
273 
277  void set_ub(const VectorXs& ub);
278 
279  protected:
280  void update_has_limits();
281 
282  std::size_t nx_;
283  std::size_t ndx_;
284  std::size_t nq_;
285  std::size_t nv_;
286  VectorXs lb_;
287  VectorXs ub_;
288  bool has_limits_;
289 };
290 
291 } // namespace crocoddyl
292 
293 /* --- Details -------------------------------------------------------------- */
294 /* --- Details -------------------------------------------------------------- */
295 /* --- Details -------------------------------------------------------------- */
296 #include "crocoddyl/core/state-base.hxx"
297 
298 #endif // CROCODDYL_CORE_STATE_BASE_HPP_
Abstract class for the state representation.
Definition: state-base.hpp:42
virtual void Jdiff(const Eigen::Ref< const VectorXs > &x0, const Eigen::Ref< const VectorXs > &x1, Eigen::Ref< MatrixXs > Jfirst, Eigen::Ref< MatrixXs > Jsecond, const Jcomponent firstsecond=both) const =0
Compute the Jacobian of the state manifold differentiation.
std::vector< MatrixXs > Jdiff_Js(const Eigen::Ref< const VectorXs > &x0, const Eigen::Ref< const VectorXs > &x1, const Jcomponent firstsecond=both)
std::vector< MatrixXs > Jintegrate_Js(const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &dx, const Jcomponent firstsecond=both)
Compute the Jacobian of the state manifold integration.
VectorXs diff_dx(const Eigen::Ref< const VectorXs > &x0, const Eigen::Ref< const VectorXs > &x1)
Compute the state manifold differentiation.
virtual VectorXs rand() const =0
Generate a random state.
std::size_t nv_
Velocity dimension.
Definition: state-base.hpp:285
virtual void JintegrateTransport(const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &dx, Eigen::Ref< MatrixXs > Jin, const Jcomponent firstsecond) const =0
Parallel transport from integrate(x, dx) to x.
std::size_t get_nq() const
Return the dimension of the configuration tuple.
std::size_t get_ndx() const
Return the dimension of the tangent space of the state manifold.
std::size_t get_nv() const
Return the dimension of tangent space of the configuration manifold.
const VectorXs & get_lb() const
Return the state lower bound.
std::size_t nx_
State dimension.
Definition: state-base.hpp:282
VectorXs integrate_x(const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &dx)
Compute the state manifold integration.
const VectorXs & get_ub() const
Return the state upper bound.
bool has_limits_
Indicates whether any of the state limits is finite.
Definition: state-base.hpp:288
virtual void diff(const Eigen::Ref< const VectorXs > &x0, const Eigen::Ref< const VectorXs > &x1, Eigen::Ref< VectorXs > dxout) const =0
Compute the state manifold differentiation.
virtual VectorXs zero() const =0
Generate a zero state.
StateAbstractTpl(const std::size_t nx, const std::size_t ndx)
Initialize the state dimensions.
std::size_t nq_
Configuration dimension.
Definition: state-base.hpp:284
bool get_has_limits() const
Indicate if the state has defined limits.
VectorXs lb_
Lower state limits.
Definition: state-base.hpp:286
void set_ub(const VectorXs &ub)
Modify the state upper bound.
virtual void integrate(const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &dx, Eigen::Ref< VectorXs > xout) const =0
Compute the state manifold integration.
VectorXs ub_
Upper state limits.
Definition: state-base.hpp:287
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 =0
Compute the Jacobian of the state manifold integration.
std::size_t get_nx() const
Return the dimension of the state tuple.
void set_lb(const VectorXs &lb)
Modify the state lower bound.
std::size_t ndx_
State rate dimension.
Definition: state-base.hpp:283