- 3.0.2 rigid body dynamics module.
FixBaseRobotState.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 
25 template <size_t NJOINTS, size_t ACT_STATE_DIM = 0, typename SCALAR = double>
27 {
28 public:
29  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
30 
34 
35  static const size_t NDOF = NJOINTS;
36  static const size_t NSTATE = 2 * NJOINTS + ACT_STATE_DIM;
37 
40 
45  const actuator_state_vector_t& actState = actuator_state_vector_t::Zero())
46  : joints_(joints), act_state_(actState)
47  {
48  }
49 
51  FixBaseRobotState(const state_vector_t& robotState) : joints_(), act_state_() { fromStateVector(robotState); }
57  static const JointState_t jointStateFromVector(const state_vector_t& robotState)
58  {
59  JointState_t jointState;
60  jointState.getPositions() = robotState.template head<NJOINTS>();
61  jointState.getVelocities() = robotState.template segment<NJOINTS>(NJOINTS);
62  return jointState;
63  }
64 
66  static const RBDState_t rbdStateFromVector(const state_vector_t& robotState,
67  const RigidBodyPose_t& basePose = RigidBodyPose_t())
68  {
69  RBDState_t rbdState;
70  rbdState.setZero();
71  rbdState.basePose() = basePose;
72  rbdState.joints() = jointStateFromVector(robotState);
73  return rbdState;
74  }
75 
78  {
79  actuator_state_vector_t actState = robotState.template tail<ACT_STATE_DIM>();
80  return actState;
81  }
82 
85  const actuator_state_vector_t& x_act = actuator_state_vector_t::Zero())
86  {
87  state_vector_t robotState;
88  robotState.template head<2 * NJOINTS>() = jointState.template head<2 * NJOINTS>();
89  robotState.template tail<ACT_STATE_DIM>() = x_act;
90  return robotState;
91  }
92 
98  SCALAR& actuatorState(size_t i) { return act_state_(i); }
100  const SCALAR& actuatorState(size_t i) const { return act_state_(i); }
102  JointState_t& joints() { return joints_; }
104  const JointState_t& joints() const { return joints_; }
105  void setZero()
106  {
107  joints_.setZero();
108  act_state_.setZero();
109  }
110 
112  template <typename T = void>
113  typename std::enable_if<(ACT_STATE_DIM == 0), T>::type fromStateVector(const state_vector_t& robotState)
114  {
115  joints_.getPositions() = robotState.template head<NJOINTS>();
116  joints_.getVelocities() = robotState.template segment<NJOINTS>(NJOINTS);
117  }
118 
119  template <typename T = void>
120  typename std::enable_if<(ACT_STATE_DIM > 0), T>::type fromStateVector(const state_vector_t& robotState)
121  {
122  joints_.getPositions() = robotState.template head<NJOINTS>();
123  joints_.getVelocities() = robotState.template segment<NJOINTS>(NJOINTS);
124  act_state_ = robotState.template tail<ACT_STATE_DIM>();
125  }
126 
128  template <typename T = state_vector_t>
129  typename std::enable_if<(ACT_STATE_DIM == 0), T>::type toStateVector() const
130  {
131  state_vector_t robotState;
132  robotState.template head<NJOINTS>() = joints_.getPositions();
133  robotState.template segment<NJOINTS>(NJOINTS) = joints_.getVelocities();
134  return robotState;
135  }
136  template <typename T = state_vector_t>
137  typename std::enable_if<(ACT_STATE_DIM > 0), T>::type toStateVector() const
138  {
139  state_vector_t robotState;
140  robotState.template head<NJOINTS>() = joints_.getPositions();
141  robotState.template segment<NJOINTS>(NJOINTS) = joints_.getVelocities();
142  robotState.template tail<ACT_STATE_DIM>() = act_state_;
143  return robotState;
144  }
145 
148  {
149  RBDState_t rbdState;
150  rbdState.setZero();
151  rbdState.basePose() = basePose;
152  rbdState.joints() = joints_;
153  return rbdState;
154  }
155 
156 protected:
161 };
162 
163 } // namespace rbd
164 } // namespace ct
RigidBodyPose_t & basePose()
get base pose
Definition: RBDState.h:67
std::enable_if<(ACT_STATE_DIM==0), T >::type toStateVector() const
conversion from RobotState to dense state vector
Definition: FixBaseRobotState.h:129
tpl::RigidBodyPose< SCALAR > RigidBodyPose_t
Definition: FixBaseRobotState.h:31
static const size_t NSTATE
Definition: FixBaseRobotState.h:36
static const actuator_state_vector_t actuatorStateFromVector(const state_vector_t &robotState)
transform full robot state to a actuator state (static)
Definition: FixBaseRobotState.h:77
Pose of a single rigid body.
Definition: RigidBodyPose.h:29
joint state and joint velocity
Definition: JointState.h:21
static const JointState_t jointStateFromVector(const state_vector_t &robotState)
full state vector to JointState (static)
Definition: FixBaseRobotState.h:57
const JointState_t & joints() const
accessor to joint state
Definition: FixBaseRobotState.h:104
std::enable_if<(ACT_STATE_DIM > 0), T >::type toStateVector() const
Definition: FixBaseRobotState.h:137
joint states and base states
Definition: RBDState.h:27
std::enable_if<(ACT_STATE_DIM==0), T >::type fromStateVector(const state_vector_t &robotState)
conversion from dense state vector to a RobotState
Definition: FixBaseRobotState.h:113
FixBaseRobotState(const FixBaseRobotState &other)
constructor
Definition: FixBaseRobotState.h:53
SCALAR & actuatorState(size_t i)
accessor to single element of actuator state
Definition: FixBaseRobotState.h:98
FixBaseRobotState()
constructor
Definition: FixBaseRobotState.h:42
actuator_state_vector_t & actuatorState()
accessor to actuator state
Definition: FixBaseRobotState.h:94
FixBaseRobotState(const JointState_t &joints, const actuator_state_vector_t &actState=actuator_state_vector_t::Zero())
constructor
Definition: FixBaseRobotState.h:44
CppAD::AD< CppAD::cg::CG< double > > SCALAR
const SCALAR & actuatorState(size_t i) const
accessor to single element of actuator state
Definition: FixBaseRobotState.h:100
JointPositionBlock getVelocities()
get joint velocity
Definition: JointState.h:131
RBDState_t toRBDState(const RigidBodyPose_t &basePose=RigidBodyPose_t())
transform full robot state to RBDState
Definition: FixBaseRobotState.h:147
static const size_t NDOF
Definition: FixBaseRobotState.h:35
std::enable_if<(ACT_STATE_DIM > 0), T >::type fromStateVector(const state_vector_t &robotState)
Definition: FixBaseRobotState.h:120
void setZero()
Definition: FixBaseRobotState.h:105
whole fix base robot state, i.e. Joint state, Actuator Dynamics (and fix-base pose) ...
Definition: FixBaseRobotState.h:26
static const state_vector_t toFullState(const ct::core::StateVector< 2 *NJOINTS, SCALAR > &jointState, const actuator_state_vector_t &x_act=actuator_state_vector_t::Zero())
transform from joint and actuator state to full state
Definition: FixBaseRobotState.h:84
~FixBaseRobotState()
destructor
Definition: FixBaseRobotState.h:55
JointState_t joints_
the joint state
Definition: FixBaseRobotState.h:158
void setZero()
set states to zero
Definition: JointState.h:164
const actuator_state_vector_t & actuatorState() const
accessor to actuator state
Definition: FixBaseRobotState.h:96
static const RBDState_t rbdStateFromVector(const state_vector_t &robotState, const RigidBodyPose_t &basePose=RigidBodyPose_t())
transform full robot state to RBDState (static)
Definition: FixBaseRobotState.h:66
JointState< NJOINTS, SCALAR > & joints()
get joint states
Definition: RBDState.h:94
JointPositionBlock getPositions()
get joint state
Definition: JointState.h:76
void setZero()
Definition: RBDState.h:198
JointState_t & joints()
accessor to joint state
Definition: FixBaseRobotState.h:102
FixBaseRobotState(const state_vector_t &robotState)
constructor
Definition: FixBaseRobotState.h:51
actuator_state_vector_t act_state_
the actuator state vector
Definition: FixBaseRobotState.h:160