Cheetah Software  1.0
ActuatorModel.h
Go to the documentation of this file.
1 
10 #ifndef PROJECT_ACTUATORMODEL_H
11 #define PROJECT_ACTUATORMODEL_H
12 
13 #include "Utilities/utilities.h"
14 
15 template <typename T>
17  public:
18  ActuatorModel(T gearRatio, T motorKT, T motorR, T batteryV, T damping,
19  T dryFriction, T tauMax)
20  : _gr(gearRatio),
21  _kt(motorKT),
22  _R(motorR),
23  _V(batteryV),
24  _damping(damping),
25  _dryFriction(dryFriction),
26  _tauMax(tauMax) {}
27 
29 
30  // compute actual actuator torque, given desired torque and speed.
31  // takes into account friction (dry and damping), voltage limits, and torque
32  // limits
33  T getTorque(T tauDes, T qd) {
34  // compute motor torque
35  T tauDesMotor = tauDes / _gr; // motor torque
36  T iDes = tauDesMotor / (_kt * 1.5); // i = tau / KT
37  // T bemf = qd * _gr * _kt * 1.732; // back emf
38  T bemf = qd * _gr * _kt * 2.; // back emf
39  T vDes = iDes * _R + bemf; // v = I*R + emf
40  T vActual = coerce(vDes, -_V, _V); // limit to battery voltage
41  T tauActMotor =
42  1.5 * _kt * (vActual - bemf) / _R; // tau = Kt * I = Kt * V / R
43  T tauAct = _gr * coerce(tauActMotor, -_tauMax, _tauMax);
44 
45  // add damping and dry friction
46  if (_frictionEnabled)
47  tauAct = tauAct - _damping * qd - _dryFriction * sgn(qd);
48 
49  return tauAct;
50  }
51 
52  void setFriction(bool enabled) { _frictionEnabled = enabled; }
53 
54  private:
56  bool _frictionEnabled = true;
57 };
58 
59 #endif // PROJECT_ACTUATORMODEL_H
T getTorque(T tauDes, T qd)
Definition: ActuatorModel.h:33
bool _frictionEnabled
Definition: ActuatorModel.h:56
T coerce(T in, T min, T max)
Definition: utilities.h:35
int sgn(T val)
Definition: utilities.h:65
ActuatorModel(T gearRatio, T motorKT, T motorR, T batteryV, T damping, T dryFriction, T tauMax)
Definition: ActuatorModel.h:18
void setFriction(bool enabled)
Definition: ActuatorModel.h:52