pinocchio  1.2.6-7-g6de3e-dirty
dc-non-linear-motor-model.hpp
1 //
2 // Copyright (c) 2017 LAAS CNRS
3 //
4 // Author: Olivier Stasse
5 //
6 // This file is part of Pinocchio
7 // Pinocchio is free software: you can redistribute it
8 // and/or modify it under the terms of the GNU Lesser General Public
9 // License as published by the Free Software Foundation, either version
10 // 3 of the License, or (at your option) any later version.
11 //
12 // Pinocchio is distributed in the hope that it will be
13 // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
14 // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Lesser Public License for more details. You should have
16 // received a copy of the GNU Lesser General Public License along with
17 // Pinocchio If not, see
18 // <http://www.gnu.org/licenses/>.
19 
20 #ifndef _se3_non_linear_motor_model_hpp_
21 #define _se3_non_linear_motor_model_hpp_
22 
23 #include <iostream>
24 #include "pinocchio/macros.hpp"
25 #include "pinocchio/actuators/actuator-model.hpp"
26 
27 
28 namespace se3
29 {
129  template<typename Scalar_>
131  ActuatorDataBase<ActuatorDCNonLinearMotorData<Scalar_> >
132  {
133  public:
134  typedef Scalar_ Scalar_t;
135  typedef typename Eigen::Matrix<Scalar_, 12,1 > Parameters_t;
136  typedef typename Eigen::Matrix<Scalar_, 2,1> Observations_t;
137  typedef typename Eigen::Matrix<Scalar_, 6,1> S_t;
138  typedef typename Eigen::Matrix<Scalar_, 3,1> X_t;
139  typedef typename Eigen::Matrix<Scalar_, 3,1> dX_t;
140  typedef typename Eigen::Matrix<Scalar_, 1,1> U_t;
141 
143  const Observations_t & h() const { return h_;}
144 
146  const Parameters_t & c() const { return c_;}
147 
149  const S_t & S() const { return S_;}
150 
151  enum InternalParameters
152  {
153  P_ROTOR_INERTIA=6,
154  P_ROTOR_RESISTOR,
155  P_TORQUE_CST,
156  P_SPEED_TORQUE_GRD,
157  P_BACK_EMF,
158  P_TERMINAL_INDUCTANCE
159  };
162  void rotorInertia(Scalar_ c)
163  { c_[P_ROTOR_INERTIA] = c; updateFirstParameters();}
164 
166  void rotorResistor(Scalar_ c)
167  { c_[P_ROTOR_RESISTOR] = c; updateFirstParameters();}
168 
170  void torqueConst(Scalar_ c)
171  { c_[P_TORQUE_CST] = c; updateFirstParameters();}
172 
174  void speedTorqueGrad(Scalar_ c)
175  {c_[P_SPEED_TORQUE_GRD] = c; updateFirstParameters();}
176 
182  void backEMF(Scalar_ c)
183  {c_[P_BACK_EMF] = c;updateFirstParameters();}
184 
186  void terminalInductance(Scalar_ c)
187  {c_[P_TERMINAL_INDUCTANCE] = c; updateFirstParameters();}
188 
189 
190  void setS(S_t &S)
191  {S_ = S;}
193 
194  Observations_t & h() { return h_;}
195 
196  protected:
199  {
200  // c_1 = torque_cst
201  c_[0] = c_[P_TORQUE_CST]/c_[P_ROTOR_INERTIA];
202  // c_2 = - speedTorqueGrad/rotorInertia
203  c_[1] = -c_[P_SPEED_TORQUE_GRD]/c_[P_ROTOR_INERTIA];
204  // c_3 = -1/rotorInertia
205  c_[2] = -1/c_[P_ROTOR_INERTIA];
206  // c_4 = rotorResistor/terminalInductance
207  c_[3] = -c_[P_ROTOR_RESISTOR]/c_[P_TERMINAL_INDUCTANCE];
208  // c_5 = 1/terminalInductance
209  c_[4] = 1/c_[P_TERMINAL_INDUCTANCE];
210  // c_6 = - backEMF/terminalInductance
211  c_[5] = - c_[P_BACK_EMF]/c_[P_TERMINAL_INDUCTANCE];
212  }
213 
215  Observations_t h_;
216 
218  Parameters_t c_;
219 
221  S_t S_;
222 
223  };
224 
231  template< typename Scalar_>
232  class ActuatorDCNonLinearMotorModel : ActuatorModelBase<ActuatorDCNonLinearMotorModel<Scalar_> >
233  {
234 
235  typedef Eigen::Matrix<Scalar_,3,1,0> Vector3Scalar;
236 
237  public:
239 
240  void calc(typename ActuatorDCNonLinearMotorData<Scalar_>::dX_t & dstate,
241  typename ActuatorDCNonLinearMotorData<Scalar_>::X_t & state,
242  typename ActuatorDCNonLinearMotorData<Scalar_>::U_t & control,
243  Force & fext,
245  {
246  // Update dstate
247  // dtheta/dt = dtheta/dt
248  dstate[0] = state[1];
249  // ddtheta/ddt =
250  dstate[1] = data.c()[0] * state[2] + data.c()[1] * state[1] +
251  data.c()[2] *data.S().dot(fext.toVector());
253  dstate[2] = data.c()[3] * state[2] + control[0] - data.c()[7]* state[1];
254 
255  // Update observation
256  // Motor torque
257  data.h()[0] = data.c()[ActuatorDCNonLinearMotorData<Scalar_>::P_TORQUE_CST] *state[2];
258  // Back emf potential
259  data.h()[1] = data.c()[ActuatorDCNonLinearMotorData<Scalar_>::P_BACK_EMF] * state[1];
260  }
261 
262 
263  void get_force(ActuatorDCNonLinearMotorData<Scalar_> &data, Force &aForce) const
264  {
265  aForce.linear(Vector3Scalar::Zero(3,1));
266  aForce.angular(Vector3Scalar(0.0,0.0,data.h()[1]));
267  }
268 
269  ActuatorDCNonLinearMotorData<Scalar_> createData() const
271 
272  protected:
273 
274  // Store actuator name.
275  std::string name_;
276 
277  };
278 
279  template <typename Scalar_>
281  {
283  };
284 
285  template <typename Scalar_>
287  {
290  };
291 
292 
293 } // end of namespace se3
294 
295 #endif /* _se3_non_linear_motor_model_ */
void torqueConst(Scalar_ c)
Torque constant (Nm/A) - .
const Parameters_t & c() const
Return parameters.
Template implementing a non linear DC motor model.
void rotorInertia(Scalar_ c)
Rotor inertia (kg/m2) - .
void terminalInductance(Scalar_ c)
Terminal Inductance (Henry)
void updateFirstParameters()
Update the first three parameters of the actuators:
Concreate Class representing a force.
Definition: force.hpp:243
const Observations_t & h() const
Return observation vector.
void calc(typename ActuatorDCNonLinearMotorData< Scalar_ >::dX_t &dstate, typename ActuatorDCNonLinearMotorData< Scalar_ >::X_t &state, typename ActuatorDCNonLinearMotorData< Scalar_ >::U_t &control, Force &fext, ActuatorDCNonLinearMotorData< Scalar_ > &data)
const Vector6 & toVector() const
Return the force.
Definition: force.hpp:102
Template for handling data related to a non linear DC motor model.
ConstAngular_t angular() const
Return the angular part of the force vector.
Definition: force.hpp:64
void backEMF(Scalar_ c)
Back electro magnetic force constant It is the inverse of the speed torque gradient constant ( ) in ...
const S_t & S() const
Returns selection matrix.
void rotorResistor(Scalar_ c)
Rotor resistor (Ohm) - .
ConstLinear_t linear() const
Return the linear part of the force vector.
Definition: force.hpp:71
void speedTorqueGrad(Scalar_ c)
Speed torque gradient (rads^-1/Nm) .
Observations_t h_
Observation variables.