crocoddyl  1.8.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 enum AssignmentOp { setto, addto, rmfrom };
24 
25 inline bool is_a_Jcomponent(Jcomponent firstsecond) {
26  return (firstsecond == first || firstsecond == second || firstsecond == both);
27 }
28 
29 inline bool is_a_AssignmentOp(AssignmentOp op) { return (op == setto || op == addto || op == rmfrom); }
30 
44 template <typename _Scalar>
45 class StateAbstractTpl {
46  public:
47  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
48 
49  typedef _Scalar Scalar;
50  typedef MathBaseTpl<Scalar> MathBase;
51  typedef typename MathBase::VectorXs VectorXs;
52  typedef typename MathBase::MatrixXs MatrixXs;
53 
60  StateAbstractTpl(const std::size_t nx, const std::size_t ndx);
62  virtual ~StateAbstractTpl();
63 
67  virtual VectorXs zero() const = 0;
68 
72  virtual VectorXs rand() const = 0;
73 
89  virtual void diff(const Eigen::Ref<const VectorXs>& x0, const Eigen::Ref<const VectorXs>& x1,
90  Eigen::Ref<VectorXs> dxout) const = 0;
91 
107  virtual void integrate(const Eigen::Ref<const VectorXs>& x, const Eigen::Ref<const VectorXs>& dx,
108  Eigen::Ref<VectorXs> xout) const = 0;
109 
144  virtual void Jdiff(const Eigen::Ref<const VectorXs>& x0, const Eigen::Ref<const VectorXs>& x1,
145  Eigen::Ref<MatrixXs> Jfirst, Eigen::Ref<MatrixXs> Jsecond,
146  const Jcomponent firstsecond = both) const = 0;
147 
180  virtual void Jintegrate(const Eigen::Ref<const VectorXs>& x, const Eigen::Ref<const VectorXs>& dx,
181  Eigen::Ref<MatrixXs> Jfirst, Eigen::Ref<MatrixXs> Jsecond,
182  const Jcomponent firstsecond = both, const AssignmentOp op = setto) const = 0;
183 
196  virtual void JintegrateTransport(const Eigen::Ref<const VectorXs>& x, const Eigen::Ref<const VectorXs>& dx,
197  Eigen::Ref<MatrixXs> Jin, const Jcomponent firstsecond) const = 0;
198 
206  VectorXs diff_dx(const Eigen::Ref<const VectorXs>& x0, const Eigen::Ref<const VectorXs>& x1);
207 
215  VectorXs integrate_x(const Eigen::Ref<const VectorXs>& x, const Eigen::Ref<const VectorXs>& dx);
216 
224  std::vector<MatrixXs> Jdiff_Js(const Eigen::Ref<const VectorXs>& x0, const Eigen::Ref<const VectorXs>& x1,
225  const Jcomponent firstsecond = both);
226 
234  std::vector<MatrixXs> Jintegrate_Js(const Eigen::Ref<const VectorXs>& x, const Eigen::Ref<const VectorXs>& dx,
235  const Jcomponent firstsecond = both);
236 
240  std::size_t get_nx() const;
241 
245  std::size_t get_ndx() const;
246 
250  std::size_t get_nq() const;
251 
255  std::size_t get_nv() const;
256 
260  const VectorXs& get_lb() const;
261 
265  const VectorXs& get_ub() const;
266 
270  bool get_has_limits() const;
271 
275  void set_lb(const VectorXs& lb);
276 
280  void set_ub(const VectorXs& ub);
281 
282  protected:
283  void update_has_limits();
284 
285  std::size_t nx_;
286  std::size_t ndx_;
287  std::size_t nq_;
288  std::size_t nv_;
289  VectorXs lb_;
290  VectorXs ub_;
291  bool has_limits_;
292 };
293 
294 } // namespace crocoddyl
295 
296 /* --- Details -------------------------------------------------------------- */
297 /* --- Details -------------------------------------------------------------- */
298 /* --- Details -------------------------------------------------------------- */
299 #include "crocoddyl/core/state-base.hxx"
300 
301 #endif // CROCODDYL_CORE_STATE_BASE_HPP_
void set_lb(const VectorXs &lb)
Modify the state lower bound.
void set_ub(const VectorXs &ub)
Modify the state upper bound.
VectorXs lb_
Lower state limits.
Definition: state-base.hpp:289
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.
VectorXs ub_
Upper state limits.
Definition: state-base.hpp:290
std::size_t get_ndx() const
Return the dimension of the tangent space of the state manifold.
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.
const VectorXs & get_lb() const
Return the state lower bound.
virtual VectorXs zero() const =0
Generate a zero state.
std::vector< MatrixXs > Jintegrate_Js(const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &dx, const Jcomponent firstsecond=both)
std::vector< MatrixXs > Jdiff_Js(const Eigen::Ref< const VectorXs > &x0, const Eigen::Ref< const VectorXs > &x1, const Jcomponent firstsecond=both)
std::size_t get_nq() const
Return the dimension of the configuration tuple.
StateAbstractTpl(const std::size_t nx, const std::size_t ndx)
Initialize the state dimensions.
bool has_limits_
Indicates whether any of the state limits is finite.
Definition: state-base.hpp:291
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.
VectorXs diff_dx(const Eigen::Ref< const VectorXs > &x0, const Eigen::Ref< const VectorXs > &x1)
std::size_t get_nx() const
Return the dimension of the state tuple.
std::size_t nx_
State dimension.
Definition: state-base.hpp:285
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.
std::size_t nv_
Velocity dimension.
Definition: state-base.hpp:288
std::size_t get_nv() const
Return the dimension of tangent space of the configuration manifold.
VectorXs integrate_x(const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &dx)
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 x + dx to x.
std::size_t ndx_
State rate dimension.
Definition: state-base.hpp:286
std::size_t nq_
Configuration dimension.
Definition: state-base.hpp:287
const VectorXs & get_ub() const
Return the state upper bound.
bool get_has_limits() const
Indicate if the state has defined limits.
virtual VectorXs rand() const =0
Generate a random state.