- 3.0.2 rigid body dynamics module.
SecondOrderActuatorDynamics-impl.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 namespace ct {
9 namespace rbd {
10 
11 template <size_t NJOINTS, typename SCALAR>
13  : oscillators_(NJOINTS, ct::core::tpl::SecondOrderSystem<SCALAR>((SCALAR)w_n, (SCALAR)zeta, (SCALAR)(w_n * w_n)))
14 {
15 }
16 
17 template <size_t NJOINTS, typename SCALAR>
19  : oscillators_(NJOINTS, ct::core::tpl::SecondOrderSystem<SCALAR>((SCALAR)w_n, (SCALAR)zeta, (SCALAR)g_dc))
20 {
21 }
22 
23 template <size_t NJOINTS, typename SCALAR>
25  std::vector<double> zeta)
26 {
27  if ((w_n.size() != NJOINTS) || (zeta.size() != NJOINTS))
28  throw std::runtime_error("SecondOrderActuatorDynamics: w_n or zeta is not correct size");
29 
30  oscillators_.resize(NJOINTS);
31  for (size_t i = 0; i < NJOINTS; i++)
32  oscillators_[i] =
33  ct::core::tpl::SecondOrderSystem<SCALAR>((SCALAR)w_n[i], (SCALAR)zeta[i], (SCALAR)(w_n[i] * w_n[i]));
34 }
35 
36 template <size_t NJOINTS, typename SCALAR>
38  std::vector<double> zeta,
39  std::vector<double> g_dc)
40 {
41  if ((w_n.size() != NJOINTS) || (zeta.size() != NJOINTS) || (g_dc.size() != NJOINTS))
42  throw std::runtime_error("SecondOrderActuatorDynamics: w_n, zeta or g_dc is not correct size");
43 
44  oscillators_.resize(NJOINTS);
45  for (size_t i = 0; i < NJOINTS; i++)
46  oscillators_[i] = ct::core::tpl::SecondOrderSystem<SCALAR>((SCALAR)w_n[i], (SCALAR)zeta[i], (SCALAR)g_dc[i]);
47 }
48 
49 template <size_t NJOINTS, typename SCALAR>
51 {
52 }
53 
54 template <size_t NJOINTS, typename SCALAR>
56 {
57  return new SecondOrderActuatorDynamics(*this);
58 }
59 
60 template <size_t NJOINTS, typename SCALAR>
62  const JointState<NJOINTS, SCALAR>& robotJointState,
64  const SCALAR& t,
67 {
68  // evaluate oscillator dynamics for each joint
69  for (size_t i = 0; i < NJOINTS; i++)
70  {
71  core::StateVector<2, SCALAR> secondOrderState;
72  core::StateVector<2, SCALAR> secondOrderStateDerivative;
74  inputCtrl(0) = control(i);
75 
76  secondOrderState << state(i), state(i + NJOINTS);
77 
78  oscillators_[i].computeControlledDynamics(secondOrderState, SCALAR(0.0), inputCtrl, secondOrderStateDerivative);
79 
80  derivative(i) = state(i + NJOINTS);
81  derivative(i + NJOINTS) = secondOrderStateDerivative(1);
82  }
83 }
84 
85 template <size_t NJOINTS, typename SCALAR>
87  const JointState<NJOINTS, SCALAR>& robotJointState,
88  const typename BASE::act_state_vector_t& actState)
89 {
90  // for this simple actuator dynamics model, the controlOutput is just the "position" coordinates of the actuator state
91  return actState.template topRows<NJOINTS>();
92 }
93 
94 template <size_t NJOINTS, typename SCALAR>
96  const JointState<NJOINTS, SCALAR>& refRobotJointState,
97  const core::ControlVector<NJOINTS, SCALAR>& refControl)
98 {
100  refState.setZero();
101  refState.template topRows<NJOINTS>() = refControl.toImplementation();
102  return refState;
103 }
104 
105 } // namespace rbd
106 } // namespace ct
joint state and joint velocity
Definition: JointState.h:21
virtual core::ControlVector< NJOINTS, SCALAR > computeControlOutput(const JointState< NJOINTS, SCALAR > &robotJointState, const typename BASE::act_state_vector_t &actState) override
Definition: SecondOrderActuatorDynamics-impl.h:86
virtual ct::core::StateVector< 2 *NJOINTS, SCALAR > computeStateFromOutput(const JointState< NJOINTS, SCALAR > &refRobotJointState, const core::ControlVector< NJOINTS, SCALAR > &refControl) override
reconstruct actuator state from a desired control output and robot joint state (e.g. for initialization)
Definition: SecondOrderActuatorDynamics-impl.h:95
SecondOrderActuatorDynamics(double w_n, double zeta)
constructor assuming unit amplification
Definition: SecondOrderActuatorDynamics-impl.h:12
virtual SecondOrderActuatorDynamics< NJOINTS, SCALAR > * clone() const override
deep cloning
Definition: SecondOrderActuatorDynamics-impl.h:55
tpl::SecondOrderSystem< double > SecondOrderSystem
virtual void computeActuatorDynamics(const JointState< NJOINTS, SCALAR > &robotJointState, const ct::core::StateVector< 2 *NJOINTS, SCALAR > &state, const SCALAR &t, const ct::core::ControlVector< NJOINTS, SCALAR > &control, ct::core::StateVector< 2 *NJOINTS, SCALAR > &derivative) override
Definition: SecondOrderActuatorDynamics-impl.h:61
CppAD::AD< CppAD::cg::CG< double > > SCALAR
for i
Definition: SecondOrderActuatorDynamics.h:19
virtual ~SecondOrderActuatorDynamics()
destructor
Definition: SecondOrderActuatorDynamics-impl.h:50