Crocoddyl
Loading...
Searching...
No Matches
state-base.hpp
1
2// BSD 3-Clause License
3//
4// Copyright (C) 2019-2025, LAAS-CNRS, University of Edinburgh, INRIA,
5// Heriot-Watt University
6// Copyright note valid unless otherwise stated in individual files.
7// All rights reserved.
9
10#ifndef CROCODDYL_CORE_STATE_BASE_HPP_
11#define CROCODDYL_CORE_STATE_BASE_HPP_
12
13#include "crocoddyl/core/fwd.hpp"
14
15namespace crocoddyl {
16
17enum Jcomponent { both = 0, first = 1, second = 2 };
18
19inline bool is_a_Jcomponent(Jcomponent firstsecond) {
20 return (firstsecond == first || firstsecond == second || firstsecond == both);
21}
22
23class StateBase {
24 public:
25 virtual ~StateBase() = default;
26
27 CROCODDYL_BASE_CAST(StateBase, StateAbstractTpl)
28};
29
47template <typename _Scalar>
48class StateAbstractTpl : public StateBase {
49 public:
50 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
51
52 typedef _Scalar Scalar;
53 typedef MathBaseTpl<Scalar> MathBase;
54 typedef typename MathBase::VectorXs VectorXs;
55 typedef typename MathBase::MatrixXs MatrixXs;
56
63 StateAbstractTpl(const std::size_t nx, const std::size_t ndx);
65 virtual ~StateAbstractTpl();
66
70 virtual VectorXs zero() const = 0;
71
75 virtual VectorXs rand() const = 0;
76
94 virtual void diff(const Eigen::Ref<const VectorXs>& x0,
95 const Eigen::Ref<const VectorXs>& x1,
96 Eigen::Ref<VectorXs> dxout) const = 0;
97
114 virtual void integrate(const Eigen::Ref<const VectorXs>& x,
115 const Eigen::Ref<const VectorXs>& dx,
116 Eigen::Ref<VectorXs> xout) const = 0;
117
126 virtual void safe_diff(const Eigen::Ref<const VectorXs>& x0,
127 const Eigen::Ref<const VectorXs>& x1,
128 Eigen::Ref<VectorXs> dxout) const;
129
138 virtual void safe_integrate(const Eigen::Ref<const VectorXs>& x,
139 const Eigen::Ref<const VectorXs>& dx,
140 Eigen::Ref<VectorXs> xout) const;
141
183 virtual void Jdiff(const Eigen::Ref<const VectorXs>& x0,
184 const Eigen::Ref<const VectorXs>& x1,
185 Eigen::Ref<MatrixXs> Jfirst, Eigen::Ref<MatrixXs> Jsecond,
186 const Jcomponent firstsecond = both) const = 0;
187
227 virtual void Jintegrate(const Eigen::Ref<const VectorXs>& x,
228 const Eigen::Ref<const VectorXs>& dx,
229 Eigen::Ref<MatrixXs> Jfirst,
230 Eigen::Ref<MatrixXs> Jsecond,
231 const Jcomponent firstsecond = both,
232 const AssignmentOp op = setto) const = 0;
233
248 virtual void JintegrateTransport(const Eigen::Ref<const VectorXs>& x,
249 const Eigen::Ref<const VectorXs>& dx,
250 Eigen::Ref<MatrixXs> Jin,
251 const Jcomponent firstsecond) const = 0;
252
261 VectorXs diff_dx(const Eigen::Ref<const VectorXs>& x0,
262 const Eigen::Ref<const VectorXs>& x1);
263
271 VectorXs integrate_x(const Eigen::Ref<const VectorXs>& x,
272 const Eigen::Ref<const VectorXs>& dx);
273
281 std::vector<MatrixXs> Jdiff_Js(const Eigen::Ref<const VectorXs>& x0,
282 const Eigen::Ref<const VectorXs>& x1,
283 const Jcomponent firstsecond = both);
284
292 std::vector<MatrixXs> Jintegrate_Js(const Eigen::Ref<const VectorXs>& x,
293 const Eigen::Ref<const VectorXs>& dx,
294 const Jcomponent firstsecond = both);
295
299 template <class Scalar>
300 friend std::ostream& operator<<(std::ostream& os,
302
308 virtual void print(std::ostream& os) const;
309
313 std::size_t get_nx() const;
314
318 std::size_t get_ndx() const;
319
323 std::size_t get_nq() const;
324
328 std::size_t get_nv() const;
329
333 const VectorXs& get_lb() const;
334
338 const VectorXs& get_ub() const;
339
343 bool get_has_limits() const;
344
348 void set_lb(const VectorXs& lb);
349
353 void set_ub(const VectorXs& ub);
354
355 protected:
356 void update_has_limits();
357
358 std::size_t nx_;
359 std::size_t ndx_;
360 std::size_t nq_;
361 std::size_t nv_;
362 VectorXs lb_;
363 VectorXs ub_;
365};
366
367} // namespace crocoddyl
368
369/* --- Details -------------------------------------------------------------- */
370/* --- Details -------------------------------------------------------------- */
371/* --- Details -------------------------------------------------------------- */
372#include "crocoddyl/core/state-base.hxx"
373
374CROCODDYL_DECLARE_EXTERN_TEMPLATE_CLASS(crocoddyl::StateAbstractTpl)
375
376#endif // CROCODDYL_CORE_STATE_BASE_HPP_
Abstract class for action model.
Abstract class for the state representation.
const VectorXs & get_ub() const
Return the state upper bound.
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)
Compute the state manifold differentiation.
virtual VectorXs rand() const =0
Generate a random state.
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.
virtual void print(std::ostream &os) const
Print relevant information of the state model.
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.
std::vector< MatrixXs > Jdiff_Js(const Eigen::Ref< const VectorXs > &x0, const Eigen::Ref< const VectorXs > &x1, const Jcomponent firstsecond=both)
virtual void safe_diff(const Eigen::Ref< const VectorXs > &x0, const Eigen::Ref< const VectorXs > &x1, Eigen::Ref< VectorXs > dxout) const
Sanitized diff operator that neutralises invalid components and propagates NaNs where the result cann...
VectorXs integrate_x(const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &dx)
Compute the state manifold integration.
const VectorXs & get_lb() const
Return the state lower bound.
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.
virtual void safe_integrate(const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &dx, Eigen::Ref< VectorXs > xout) const
Sanitized integrate operator that clamps invalid inputs and marks affected configuration or velocity ...
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.
bool get_has_limits() const
Indicate if the state has defined limits.
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.
friend std::ostream & operator<<(std::ostream &os, const ActionModelAbstractTpl< Scalar > &model)
Print information on the state model.
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.