- 3.0.2 rigid body dynamics module.
ProjectedFDSystem.h
Go to the documentation of this file.
1 
2 #pragma once
3 
6 
7 #include "RBDSystem.h"
8 
9 namespace ct {
10 namespace rbd {
11 
55 template <class RBDDynamics, bool QUAT_INTEGRATION = false>
56 class ProjectedFDSystem : public RBDSystem<RBDDynamics, QUAT_INTEGRATION>,
57  public core::ControlledSystem<RBDDynamics::NSTATE + QUAT_INTEGRATION,
58  RBDDynamics::NJOINTS,
59  typename RBDDynamics::SCALAR>
60 {
61 public:
62  using Dynamics = RBDDynamics;
64 
65  typedef typename RBDDynamics::SCALAR SCALAR;
66 
67  const static size_t N_EE = RBDDynamics::N_EE;
68  const static size_t STATE_DIM = RBDDynamics::NSTATE + QUAT_INTEGRATION;
69  const static size_t CONTROL_DIM = RBDDynamics::NJOINTS;
70 
73 
75 
76  ProjectedFDSystem(typename RBDDynamics::EE_in_contact_t eeInContact = true) : eeInContact_(eeInContact){};
77 
78  virtual ~ProjectedFDSystem(){};
79 
80  virtual RBDDynamics& dynamics() override { return dynamics_; }
81  virtual const RBDDynamics& dynamics() const override { return dynamics_; }
82  virtual void computeControlledDynamics(const StateVector& state,
83  const SCALAR& t,
84  const ControlVector& control,
85  StateVector& derivative) override
86  {
87  typename RBDDynamics::RBDState_t x = RBDStateFromVector(state);
88  typename RBDDynamics::RBDAcceleration_t xd;
89 
90  dynamics_.ProjectedForwardDynamics(eeInContact_, x, control, xd);
91  derivative = toStateDerivative<QUAT_INTEGRATION>(xd, x);
92  }
93 
94  void setEEInContact(typename RBDDynamics::EE_in_contact_t& eeInContact) { eeInContact_ = eeInContact; }
95  typename RBDDynamics::RBDState_t RBDStateFromVector(const StateVector& state)
96  {
97  return RBDStateFromVectorImpl<QUAT_INTEGRATION>(state);
98  }
99 
100  template <bool T>
101  typename RBDDynamics::RBDState_t RBDStateFromVectorImpl(const StateVector& state,
102  typename std::enable_if<T, bool>::type = true)
103  {
104  typename RBDDynamics::RBDState_t x(tpl::RigidBodyPose<SCALAR>::QUAT);
105  x.fromStateVectorQuaternion(state);
106  return x;
107  }
108 
109  template <bool T>
110  typename RBDDynamics::RBDState_t RBDStateFromVectorImpl(const StateVector& state,
111  typename std::enable_if<!T, bool>::type = true)
112  {
113  typename RBDDynamics::RBDState_t x(tpl::RigidBodyPose<SCALAR>::EULER);
114  x.fromStateVectorEulerXyz(state);
115  return x;
116  }
117 
118  template <bool T>
119  StateVector toStateDerivative(const typename RBDDynamics::RBDAcceleration_t& acceleration,
120  const typename RBDDynamics::RBDState_t& state,
121  typename std::enable_if<T, bool>::type = true)
122  {
123  return acceleration.toStateUpdateVectorQuaternion(state);
124  }
125 
126  template <bool T>
127  StateVector toStateDerivative(const typename RBDDynamics::RBDAcceleration_t& acceleration,
128  const typename RBDDynamics::RBDState_t& state,
129  typename std::enable_if<!T, bool>::type = true)
130  {
131  return acceleration.toStateUpdateVectorEulerXyz(state);
132  }
133 
134 
136  {
137  throw std::runtime_error("clone not implemented");
138  }
139 
140 private:
141  typename RBDDynamics::EE_in_contact_t eeInContact_;
142 
143  RBDDynamics dynamics_;
144 };
145 
146 } // namespace rbd
147 } // namespace ct
RBDDynamics::RBDState_t RBDStateFromVector(const StateVector &state)
Definition: ProjectedFDSystem.h:95
core::ControlledSystem< RBDDynamics::RBDState_t::NSTATE+QUAT_INTEGRATION, RBDDynamics::NJOINTS > Base
Definition: ProjectedFDSystem.h:74
StateVector toStateDerivative(const typename RBDDynamics::RBDAcceleration_t &acceleration, const typename RBDDynamics::RBDState_t &state, typename std::enable_if< T, bool >::type=true)
Definition: ProjectedFDSystem.h:119
static const size_t CONTROL_DIM
Definition: ProjectedFDSystem.h:69
Pose of a single rigid body.
Definition: RigidBodyPose.h:29
RBDDynamics::RBDState_t RBDStateFromVectorImpl(const StateVector &state, typename std::enable_if< T, bool >::type=true)
Definition: ProjectedFDSystem.h:101
core::StateVector< STATE_DIM, SCALAR > StateVector
Definition: ProjectedFDSystem.h:71
core::ControlVector< CONTROL_DIM, SCALAR > ControlVector
Definition: ProjectedFDSystem.h:72
RBDDynamics Dynamics
Definition: ProjectedFDSystem.h:62
ProjectedFDSystem(typename RBDDynamics::EE_in_contact_t eeInContact=true)
Definition: ProjectedFDSystem.h:76
RBDDynamics::SCALAR SCALAR
Definition: ProjectedFDSystem.h:65
virtual ProjectedFDSystem< RBDDynamics, QUAT_INTEGRATION > * clone() const override
Definition: ProjectedFDSystem.h:135
ct::rbd::TestIrb4600::tpl::Kinematics< double > Kinematics_t
Definition: FixBaseIKTest.cpp:14
virtual void computeControlledDynamics(const StateVector &state, const SCALAR &t, const ControlVector &control, StateVector &derivative) override
Definition: ProjectedFDSystem.h:82
StateVector toStateDerivative(const typename RBDDynamics::RBDAcceleration_t &acceleration, const typename RBDDynamics::RBDState_t &state, typename std::enable_if<!T, bool >::type=true)
Definition: ProjectedFDSystem.h:127
This is a common interface class for an RBDSystem.
Definition: RBDSystem.h:15
void setEEInContact(typename RBDDynamics::EE_in_contact_t &eeInContact)
Definition: ProjectedFDSystem.h:94
virtual RBDDynamics & dynamics() override
Definition: ProjectedFDSystem.h:80
ct::core::StateVector< state_dim > x
static const size_t STATE_DIM
Definition: ProjectedFDSystem.h:68
A floating base rigid body system that uses forward dynamics. The input vector is assumed to consist ...
Definition: ProjectedFDSystem.h:56
typename RBDDynamics::Kinematics_t Kinematics
Definition: ProjectedFDSystem.h:63
virtual ~ProjectedFDSystem()
Definition: ProjectedFDSystem.h:78
static const size_t N_EE
Definition: ProjectedFDSystem.h:67
RBDDynamics::RBDState_t RBDStateFromVectorImpl(const StateVector &state, typename std::enable_if<!T, bool >::type=true)
Definition: ProjectedFDSystem.h:110
virtual const RBDDynamics & dynamics() const override
Definition: ProjectedFDSystem.h:81