- 3.0.2 rigid body dynamics module.
FloatingBaseRobotState.h
Go to the documentation of this file.
1 /**********************************************************************************************************************
2 This file is part of the Control Toolbox (https://github.com/ethz-adrl/control-toolbox), copyright by ETH Zurich.
3 Licensed under the BSD-2 license (see LICENSE file in main directory)
4 **********************************************************************************************************************/
5 
6 #pragma once
7 
8 #include "RBDState.h"
9 
10 namespace ct {
11 namespace rbd {
12 
23 template <size_t NJOINTS, size_t ACT_STATE_DIM = 0, typename SCALAR = double>
24 class FloatingBaseRobotState : public RBDState<NJOINTS, SCALAR>
25 {
26 public:
27  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
28 
31 
36 
38  static const size_t NDOF = Base_t::NDOF;
39  static const size_t NSTATE = Base_t::NSTATE + ACT_STATE_DIM;
40  static const size_t NSTATE_QUAT = NSTATE + 1;
41 
44 
45 
47  FloatingBaseRobotState(const STORAGE_TYPE storage = STORAGE_TYPE::EULER)
48  : Base_t(storage), act_state_(actuator_state_vector_t::Zero())
49  {
50  }
51 
54  const actuator_state_vector_t& act_state = actuator_state_vector_t::Zero())
55  : Base_t(rbdState), act_state_(act_state)
56  {
57  }
58 
61  const JointState_t& jointState,
62  const actuator_state_vector_t& act_state = actuator_state_vector_t::Zero())
63  : Base_t(baseState, jointState), act_state_(act_state)
64  {
65  }
66 
72  RBDState_t& rbdState() { return *this; }
74  const RBDState_t& rbdState() const { return *this; }
80  template <typename T = state_vector_quat_t>
81  typename std::enable_if<(ACT_STATE_DIM > 0), T>::type toStateVectorQuaternion() const
82  {
83  // assemble overall state from RBDState and actuator state
84  state_vector_quat_t state;
86  return state;
87  }
88  template <typename T = state_vector_quat_t>
89  typename std::enable_if<(ACT_STATE_DIM == 0), T>::type toStateVectorQuaternion() const
90  {
91  // transcribe RBDState only
93  }
94 
96  template <typename T = state_vector_euler_t>
97  typename std::enable_if<(ACT_STATE_DIM > 0), T>::type toStateVectorEulerXyzUnique() const
98  {
99  // assemble overall state from RBDState and actuator state
100  state_vector_euler_t state;
102  return state;
103  }
104  template <typename T = state_vector_euler_t>
105  typename std::enable_if<(ACT_STATE_DIM == 0), T>::type toStateVectorEulerXyzUnique() const
106  {
107  // transcribe RBDState only
109  }
110 
112  template <typename T = state_vector_euler_t>
113  typename std::enable_if<(ACT_STATE_DIM > 0), T>::type toStateVectorEulerXyz() const
114  {
115  // the overall state consists of RBDState and actuator state
116  state_vector_euler_t state;
118  return state;
119  }
120  template <typename T = state_vector_euler_t>
121  typename std::enable_if<(ACT_STATE_DIM == 0), T>::type toStateVectorEulerXyz() const
122  {
123  // transcribe RBDState only
125  }
126 
128  template <typename T = void>
129  typename std::enable_if<(ACT_STATE_DIM > 0), T>::type fromStateVectorQuaternion(const state_vector_quat_t& state)
130  {
131  // transcribe the first part of the state in to the RBDState and the second part into the actuator state
132  Eigen::VectorBlock<const Eigen::Matrix<SCALAR, NSTATE_QUAT, 1>, Base_t::NSTATE_QUAT> stateBase =
133  state.template head<Base_t::NSTATE_QUAT>();
135  act_state_ = state.template tail<ACT_STATE_DIM>();
136  }
137  template <typename T = void>
138  typename std::enable_if<(ACT_STATE_DIM == 0), T>::type fromStateVectorQuaternion(const state_vector_quat_t& state)
139  {
140  // transcribe RBDState only
142  }
143 
145  template <typename T = void>
146  typename std::enable_if<(ACT_STATE_DIM > 0), T>::type fromStateVectorEulerXyz(const state_vector_euler_t& state)
147  {
148  // transcribe the first part of the state in to the RBDState and the second part into the actuator state
149  Eigen::VectorBlock<const Eigen::Matrix<SCALAR, NSTATE, 1>, Base_t::NSTATE> stateBase =
150  state.template head<Base_t::NSTATE>();
152  act_state_ = state.template tail<ACT_STATE_DIM>();
153  }
154  template <typename T = void>
155  typename std::enable_if<(ACT_STATE_DIM == 0), T>::type fromStateVectorEulerXyz(const state_vector_euler_t& state)
156  {
157  // transcribe RBDState only
159  }
160 
166  void setZero()
167  {
168  act_state_.setZero();
169  Base_t::setZero();
170  }
171 
172 protected:
174 
175 private:
176  /*the following methods are not to be called from the Robot state. They can be accessed via rbdState(). */
180 };
181 
182 } // namespace rbd
183 } // namespace ct
FloatingBaseRobotState(const RBDState_t &rbdState, const actuator_state_vector_t &act_state=actuator_state_vector_t::Zero())
constructor with actuator state as parameter
Definition: FloatingBaseRobotState.h:53
void fromStateVectorRaw(const state_vector_quat_t &state)
a convenience method
Definition: FloatingBaseRobotState.h:162
state_vector_euler_t toStateVectorEulerXyz() const
Definition: RBDState.h:161
std::enable_if<(ACT_STATE_DIM==0), T >::type fromStateVectorEulerXyz(const state_vector_euler_t &state)
Definition: FloatingBaseRobotState.h:155
std::enable_if<(ACT_STATE_DIM > 0), T >::type fromStateVectorQuaternion(const state_vector_quat_t &state)
reconstruct robot state from an Eigen state-vector with quaternion representation ...
Definition: FloatingBaseRobotState.h:129
STORAGE_TYPE
the orientation can either be stored as EulerAngles or as quaternion.
Definition: RigidBodyPose.h:38
std::enable_if<(ACT_STATE_DIM==0), T >::type toStateVectorEulerXyzUnique() const
Definition: FloatingBaseRobotState.h:105
Pose of a single rigid body.
Definition: RigidBodyPose.h:29
static const size_t NSTATE_QUAT
Definition: FloatingBaseRobotState.h:40
joint state and joint velocity
Definition: JointState.h:21
actuator_state_vector_t & actuatorState()
accessor to actuator state
Definition: FloatingBaseRobotState.h:76
coordinate_vector_t toCoordinatePositionUnique() const
Definition: RBDState.h:128
joint states and base states
Definition: RBDState.h:27
coordinate_vector_t toCoordinatePosition() const
Definition: RBDState.h:136
static const size_t NSTATE_QUAT
Definition: RBDState.h:34
std::enable_if<(ACT_STATE_DIM > 0), T >::type fromStateVectorEulerXyz(const state_vector_euler_t &state)
reconstruct robot state from an Eigen state-vector with euler representation
Definition: FloatingBaseRobotState.h:146
std::enable_if<(ACT_STATE_DIM > 0), T >::type toStateVectorEulerXyzUnique() const
get unique state vector with euler coordinates
Definition: FloatingBaseRobotState.h:97
std::enable_if<(ACT_STATE_DIM > 0), T >::type toStateVectorEulerXyz() const
get state vector in euler coordinates
Definition: FloatingBaseRobotState.h:113
std::enable_if<(ACT_STATE_DIM > 0), T >::type toStateVectorQuaternion() const
compute state vector including with quaternion representation
Definition: FloatingBaseRobotState.h:81
void fromStateVectorRaw(const state_vector_euler_t &state)
a convenience method
Definition: FloatingBaseRobotState.h:164
FloatingBaseRobotState(const RigidBodyState_t &baseState, const JointState_t &jointState, const actuator_state_vector_t &act_state=actuator_state_vector_t::Zero())
constructor with base, jonit and actuator state as parameters
Definition: FloatingBaseRobotState.h:60
void setZero()
set all zero
Definition: FloatingBaseRobotState.h:166
static const size_t NSTATE
Definition: FloatingBaseRobotState.h:39
FloatingBaseRobotState(const FloatingBaseRobotState &other)
copy constructor
Definition: FloatingBaseRobotState.h:68
std::enable_if<(ACT_STATE_DIM==0), T >::type fromStateVectorQuaternion(const state_vector_quat_t &state)
Definition: FloatingBaseRobotState.h:138
static const size_t NSTATE
Definition: RBDState.h:33
~FloatingBaseRobotState()
destructor
Definition: FloatingBaseRobotState.h:70
const RBDState_t & rbdState() const
accessor to base class RBDState
Definition: FloatingBaseRobotState.h:74
ct::core::StateVector< NSTATE, SCALAR > state_vector_euler_t
Definition: RBDState.h:39
void fromStateVectorEulerXyz(const state_vector_euler_t &state)
Definition: RBDState.h:180
static const size_t NDOF
Definition: FloatingBaseRobotState.h:38
const actuator_state_vector_t & actuatorState() const
accessor to actuator state
Definition: FloatingBaseRobotState.h:78
FloatingBaseRobotState(const STORAGE_TYPE storage=STORAGE_TYPE::EULER)
default constructor
Definition: FloatingBaseRobotState.h:47
State (pose and velocities) of a single rigid body.
Definition: RigidBodyState.h:22
void fromStateVectorQuaternion(const state_vector_quat_t &state)
Definition: RBDState.h:170
state_vector_quat_t toStateVectorQuaternion() const
Definition: RBDState.h:115
whole robot state, i.e. RBDState and Actuator Dynamics
Definition: FloatingBaseRobotState.h:24
std::enable_if<(ACT_STATE_DIM==0), T >::type toStateVectorEulerXyz() const
Definition: FloatingBaseRobotState.h:121
typename RigidBodyPose_t::STORAGE_TYPE STORAGE_TYPE
Definition: FloatingBaseRobotState.h:35
actuator_state_vector_t act_state_
Definition: FloatingBaseRobotState.h:173
RBDState_t & rbdState()
accessor to base class RBDState
Definition: FloatingBaseRobotState.h:72
static EIGEN_MAKE_ALIGNED_OPERATOR_NEW const size_t NDOF
Definition: RBDState.h:32
std::enable_if<(ACT_STATE_DIM==0), T >::type toStateVectorQuaternion() const
Definition: FloatingBaseRobotState.h:89
state_vector_euler_t toStateVectorEulerXyzUnique() const
Definition: RBDState.h:152
void setZero()
Definition: RBDState.h:198
coordinate_vector_t toCoordinateVelocity() const
Definition: RBDState.h:144