Line |
Branch |
Exec |
Source |
1 |
|
|
/////////////////////////////////////////////////////////////////////////////// |
2 |
|
|
// BSD 3-Clause License |
3 |
|
|
// |
4 |
|
|
// Copyright (C) 2019-2025, LAAS-CNRS, University of Edinburgh, |
5 |
|
|
// Heriot-Watt University |
6 |
|
|
// Copyright note valid unless otherwise stated in individual files. |
7 |
|
|
// All rights reserved. |
8 |
|
|
/////////////////////////////////////////////////////////////////////////////// |
9 |
|
|
|
10 |
|
|
#ifndef CROCODDYL_MULTIBODY_STATES_MULTIBODY_HPP_ |
11 |
|
|
#define CROCODDYL_MULTIBODY_STATES_MULTIBODY_HPP_ |
12 |
|
|
|
13 |
|
|
#include "crocoddyl/core/state-base.hpp" |
14 |
|
|
#include "crocoddyl/multibody/fwd.hpp" |
15 |
|
|
|
16 |
|
|
namespace crocoddyl { |
17 |
|
|
|
18 |
|
|
/** |
19 |
|
|
* @brief State multibody representation |
20 |
|
|
* |
21 |
|
|
* A multibody state is described by the configuration point and its tangential |
22 |
|
|
* velocity, or in other words, by the generalized position and velocity |
23 |
|
|
* coordinates of a rigid-body system. For this state, we describe its |
24 |
|
|
* operators: difference, integrates, transport and their derivatives for any |
25 |
|
|
* Pinocchio model. |
26 |
|
|
* |
27 |
|
|
* For more details about these operators, please read the documentation of the |
28 |
|
|
* `StateAbstractTpl` class. |
29 |
|
|
* |
30 |
|
|
* \sa `diff()`, `integrate()`, `Jdiff()`, `Jintegrate()` and |
31 |
|
|
* `JintegrateTransport()` |
32 |
|
|
*/ |
33 |
|
|
template <typename _Scalar> |
34 |
|
|
class StateMultibodyTpl : public StateAbstractTpl<_Scalar> { |
35 |
|
|
public: |
36 |
|
|
EIGEN_MAKE_ALIGNED_OPERATOR_NEW |
37 |
|
✗ |
CROCODDYL_DERIVED_CAST(StateBase, StateMultibodyTpl) |
38 |
|
|
|
39 |
|
|
typedef _Scalar Scalar; |
40 |
|
|
typedef MathBaseTpl<Scalar> MathBase; |
41 |
|
|
typedef StateAbstractTpl<Scalar> Base; |
42 |
|
|
typedef pinocchio::ModelTpl<Scalar> PinocchioModel; |
43 |
|
|
typedef typename MathBase::VectorXs VectorXs; |
44 |
|
|
typedef typename MathBase::MatrixXs MatrixXs; |
45 |
|
|
|
46 |
|
|
/** |
47 |
|
|
* @brief Initialize the multibody state |
48 |
|
|
* |
49 |
|
|
* @param[in] model Pinocchio model |
50 |
|
|
*/ |
51 |
|
|
explicit StateMultibodyTpl(std::shared_ptr<PinocchioModel> model); |
52 |
|
|
StateMultibodyTpl(); |
53 |
|
|
virtual ~StateMultibodyTpl(); |
54 |
|
|
|
55 |
|
|
/** |
56 |
|
|
* @brief Generate a zero state. |
57 |
|
|
* |
58 |
|
|
* Note that the zero configuration is computed using `pinocchio::neutral`. |
59 |
|
|
*/ |
60 |
|
|
virtual VectorXs zero() const override; |
61 |
|
|
|
62 |
|
|
/** |
63 |
|
|
* @brief Generate a random state |
64 |
|
|
* |
65 |
|
|
* Note that the random configuration is computed using `pinocchio::random` |
66 |
|
|
* which satisfies the manifold definition (e.g., the quaterion definition) |
67 |
|
|
*/ |
68 |
|
|
virtual VectorXs rand() const override; |
69 |
|
|
|
70 |
|
|
virtual void diff(const Eigen::Ref<const VectorXs>& x0, |
71 |
|
|
const Eigen::Ref<const VectorXs>& x1, |
72 |
|
|
Eigen::Ref<VectorXs> dxout) const override; |
73 |
|
|
virtual void integrate(const Eigen::Ref<const VectorXs>& x, |
74 |
|
|
const Eigen::Ref<const VectorXs>& dx, |
75 |
|
|
Eigen::Ref<VectorXs> xout) const override; |
76 |
|
|
virtual void Jdiff(const Eigen::Ref<const VectorXs>&, |
77 |
|
|
const Eigen::Ref<const VectorXs>&, |
78 |
|
|
Eigen::Ref<MatrixXs> Jfirst, Eigen::Ref<MatrixXs> Jsecond, |
79 |
|
|
const Jcomponent firstsecond = both) const override; |
80 |
|
|
|
81 |
|
|
virtual void Jintegrate(const Eigen::Ref<const VectorXs>& x, |
82 |
|
|
const Eigen::Ref<const VectorXs>& dx, |
83 |
|
|
Eigen::Ref<MatrixXs> Jfirst, |
84 |
|
|
Eigen::Ref<MatrixXs> Jsecond, |
85 |
|
|
const Jcomponent firstsecond = both, |
86 |
|
|
const AssignmentOp = setto) const override; |
87 |
|
|
virtual void JintegrateTransport(const Eigen::Ref<const VectorXs>& x, |
88 |
|
|
const Eigen::Ref<const VectorXs>& dx, |
89 |
|
|
Eigen::Ref<MatrixXs> Jin, |
90 |
|
|
const Jcomponent firstsecond) const override; |
91 |
|
|
|
92 |
|
|
/** |
93 |
|
|
* @brief Return the Pinocchio model (i.e., model of the rigid body system) |
94 |
|
|
*/ |
95 |
|
|
const std::shared_ptr<PinocchioModel>& get_pinocchio() const; |
96 |
|
|
|
97 |
|
|
template <typename NewScalar> |
98 |
|
|
StateMultibodyTpl<NewScalar> cast() const; |
99 |
|
|
|
100 |
|
|
/** |
101 |
|
|
* @brief Print relevant information of the state multibody |
102 |
|
|
* |
103 |
|
|
* @param[out] os Output stream object |
104 |
|
|
*/ |
105 |
|
|
virtual void print(std::ostream& os) const override; |
106 |
|
|
|
107 |
|
|
protected: |
108 |
|
|
using Base::has_limits_; |
109 |
|
|
using Base::lb_; |
110 |
|
|
using Base::ndx_; |
111 |
|
|
using Base::nq_; |
112 |
|
|
using Base::nv_; |
113 |
|
|
using Base::nx_; |
114 |
|
|
using Base::ub_; |
115 |
|
|
|
116 |
|
|
private: |
117 |
|
|
std::shared_ptr<PinocchioModel> pinocchio_; //!< Pinocchio model |
118 |
|
|
VectorXs x0_; //!< Zero state |
119 |
|
|
}; |
120 |
|
|
|
121 |
|
|
} // namespace crocoddyl |
122 |
|
|
|
123 |
|
|
/* --- Details -------------------------------------------------------------- */ |
124 |
|
|
/* --- Details -------------------------------------------------------------- */ |
125 |
|
|
/* --- Details -------------------------------------------------------------- */ |
126 |
|
|
#include "crocoddyl/multibody/states/multibody.hxx" |
127 |
|
|
|
128 |
|
|
extern template class CROCODDYL_EXPLICIT_INSTANTIATION_DECLARATION_DLLAPI |
129 |
|
|
crocoddyl::StateMultibodyTpl<double>; |
130 |
|
|
extern template class CROCODDYL_EXPLICIT_INSTANTIATION_DECLARATION_DLLAPI |
131 |
|
|
crocoddyl::StateMultibodyTpl<float>; |
132 |
|
|
|
133 |
|
|
#endif // CROCODDYL_MULTIBODY_STATES_MULTIBODY_HPP_ |
134 |
|
|
|