- 3.0.2 rigid body dynamics module.
SEADynamicsFirstOrder-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  : k_(SCALAR(k_spring)), r_(SCALAR(gear_ratio))
14 {
15 }
16 
17 template <size_t NJOINTS, typename SCALAR>
19 {
20 }
21 
22 template <size_t NJOINTS, typename SCALAR>
24 {
25  return new SEADynamicsFirstOrder(*this);
26 }
27 
28 template <size_t NJOINTS, typename SCALAR>
31  const SCALAR& t,
34 {
35  // the gear velocity is the motor velocity divided by the gear ratio:
36  derivative.template head<NJOINTS>() = control.template head<NJOINTS>() / r_;
37 }
38 
39 template <size_t NJOINTS, typename SCALAR>
41  const JointState<NJOINTS, SCALAR>& robotJointState,
42  const typename BASE::act_state_vector_t& actState)
43 {
44  // compute joint torque as a function of the deflection between joint position and gear position
45  return (actState.template topRows<NJOINTS>() - robotJointState.getPositions()) * k_;
46 }
47 
48 template <size_t NJOINTS, typename SCALAR>
50  const JointState<NJOINTS, SCALAR>& refRobotJointState,
51  const core::ControlVector<NJOINTS, SCALAR>& refControl)
52 {
53  // compute desired gear position from current joint position and desired torque
54  return refRobotJointState.getPositions() + refControl.toImplementation() / k_;
55 }
56 
57 } // namespace rbd
58 } // namespace ct
virtual void computeActuatorDynamics(const JointState< NJOINTS, SCALAR > &robotJointState, const ct::core::StateVector< NJOINTS, SCALAR > &state, const SCALAR &t, const ct::core::ControlVector< NJOINTS, SCALAR > &control, ct::core::StateVector< NJOINTS, SCALAR > &derivative) override
Definition: SEADynamicsFirstOrder-impl.h:29
joint state and joint velocity
Definition: JointState.h:21
virtual ~SEADynamicsFirstOrder()
destructor
Definition: SEADynamicsFirstOrder-impl.h:18
SEADynamicsFirstOrder(double k_spring, double gear_ratio)
constructor assuming unit amplification
Definition: SEADynamicsFirstOrder-impl.h:12
CppAD::AD< CppAD::cg::CG< double > > SCALAR
virtual SEADynamicsFirstOrder< NJOINTS, SCALAR > * clone() const override
deep cloning
Definition: SEADynamicsFirstOrder-impl.h:23
virtual core::ControlVector< NJOINTS, SCALAR > computeControlOutput(const JointState< NJOINTS, SCALAR > &robotJointState, const typename BASE::act_state_vector_t &actState) override
Definition: SEADynamicsFirstOrder-impl.h:40
JointPositionBlock getPositions()
get joint state
Definition: JointState.h:76
virtual ct::core::StateVector< 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: SEADynamicsFirstOrder-impl.h:49
Definition: SEADynamicsFirstOrder.h:25