Laelaps  2.3.5
RoadNarrows Robotics Small Outdoor Mobile Robot Project
laePowertrain.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Package: Laelaps
4 //
5 // Library: liblaelaps
6 //
7 // File: laePowertrain.h
8 //
9 /*! \file
10  *
11  * \brief Laelaps powertrain class interfaces.
12  *
13  * There are four powertrains. A powertrain is defined as:\n
14  * motor - encoder - gears - wheel - tire.
15  *
16  * Traditional actuated articulation is called a joint. Powertrains
17  * are the near equivalent in Laelaps platforms.
18  *
19  * \author Robin Knight (robin.knight@roadnarrows.com)
20  *
21  * \par Copyright
22  * \h_copy 2015-2017. RoadNarrows LLC.\n
23  * http://www.roadnarrows.com\n
24  * All Rights Reserved
25  */
26 /*
27  * @EulaBegin@
28  *
29  * Unless otherwise stated explicitly, all materials contained are copyrighted
30  * and may not be used without RoadNarrows LLC's written consent,
31  * except as provided in these terms and conditions or in the copyright
32  * notice (documents and software) or other proprietary notice provided with
33  * the relevant materials.
34  *
35  * IN NO EVENT SHALL THE AUTHOR, ROADNARROWS LLC, OR ANY
36  * MEMBERS/EMPLOYEES/CONTRACTORS OF ROADNARROWS OR DISTRIBUTORS OF THIS SOFTWARE
37  * BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR
38  * CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS
39  * DOCUMENTATION, EVEN IF THE AUTHORS OR ANY OF THE ABOVE PARTIES HAVE BEEN
40  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41  *
42  * THE AUTHORS AND ROADNARROWS LLC SPECIFICALLY DISCLAIM ANY WARRANTIES,
43  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
44  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN
45  * "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO
46  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
47  *
48  * @EulaEnd@
49  */
50 ////////////////////////////////////////////////////////////////////////////////
51 
52 #ifndef _LAE_POWERTRAIN_H
53 #define _LAE_POWERTRAIN_H
54 
55 #include <string>
56 #include <vector>
57 
58 #include "rnr/rnrconfig.h"
59 
60 #include "Laelaps/laelaps.h"
61 #include "Laelaps/laeDesc.h"
62 #include "Laelaps/laeTune.h"
63 
64 namespace laelaps
65 {
66  // ---------------------------------------------------------------------------
67  // Class LaePowertrainAttr
68  // ---------------------------------------------------------------------------
69 
70  /*!
71  * \brief Powertrain attributes class.
72  *
73  * This class encapsulates the semi-fixed attribute data defining the
74  * characteristics of a powertrain.
75  */
77  {
78  public:
79  // (derived) attribute data
80  int m_nMotorId; ///< motor id
81  int m_nMotorCtlrId; ///< motor controller id
82  int m_nMotorIndex; ///< motor controller unique motor index
83 
84  int m_nMotorDir; ///< motor normalized direction
85  int m_eJointType; ///< joint type
86 
87  uint_t m_uPulsesPerRev; ///< encoder pulses per motor revolution
88  double m_fGearRatio; ///< gear ratio
89  double m_fMaxRps; ///< maximum rated output shaft rev/sec
90  uint_t m_uMaxQpps; ///< maximum quadrature pulses/second @max rps
91  double m_fMotorRadsPerPulse; ///< motor radians per encoder pulse
92  double m_fWheelRadsPerPulse; ///< output shaft radians per encoder pulse
93 
94  double m_fMaxAmps; ///< maximum rated amps
95  double m_fStallTorque; ///< stall torque @max amps
96 
97  double m_fTireRadius; ///< tire radius
98  double m_fTireWidth; ///< tire width
99  double m_fMetersPerPulse; ///< tire meters per encoder pulse
100  double m_fMetersPerRadian; ///< tire meters per radian
101 
102  /*!
103  * \brief Default constructor.
104  */
106 
107  /*!
108  * \brief Copy constructor.
109  */
111 
112  /*!
113  * \brief Destructor.
114  */
116  {
117  }
118 
119  /*!
120  * \brief Assignment operator.
121  *
122  * \param rhs Right hand side object.
123  *
124  * \return Returns copy of this.
125  */
127  }; // LaePowertrainAttr
128 
129 
130  // ---------------------------------------------------------------------------
131  // Class LaePowertrainState
132  // ---------------------------------------------------------------------------
133 
134  /*!
135  * \brief Powertrain state data class.
136  *
137  * This class encapsulates the current dynamic state of one powertrain.
138  */
140  {
141  public:
142  // sensed state data
143  s64_t m_nEncoder; ///< motor encoder position (quad pulses)
144  int m_nSpeed; ///< raw speed (qpps)
145  double m_fTemp; ///< motor temperature (C)
146  double m_fVolts; ///< input motor voltage (V)
147  double m_fAmps; ///< motor draw (A)
148  uint_t m_uBufLen; ///< command queue length
149  uint_t m_uAlarms; ///< motor alarms
150  uint_t m_uWarnings; ///< motor warnings
151 
152  // derived state data
153  double m_fPosition; ///< wheel angular position (radians)
154  double m_fVelocity; ///< wheel angular velocity (radians/second)
155  double m_fTorque; ///< wheel torque (N-m)
156  double m_fPe; ///< motor input electrical power (W)
157  double m_fPm; ///< motor output mechanical power (W)
158 
159  /*!
160  * \brief Default constructor.
161  */
163 
164  /*!
165  * \brief Copy constructor.
166  */
168 
169  /*!
170  * \brief Destructor.
171  */
173  {
174  }
175 
176  /*!
177  * \brief Assignment operator.
178  *
179  * \param rhs Right hand side object.
180  *
181  * \return Returns copy of this.
182  */
184  }; // class LaePowertrainState
185 
186 
187  // ---------------------------------------------------------------------------
188  // Class LaePowertrain
189  // ---------------------------------------------------------------------------
190 
191  /*!
192  * \brief Powertrain data class.
193  *
194  * This class encapsulates the fixed data and current state of one powertrain.
195  */
197  {
198  public:
199  std::string m_strName; ///< powertrain unique name (key)
200  LaePowertrainAttr m_attr; ///< semi-fixed attribute data
201  LaePowertrainState m_state; ///< dynamic state data
202 
203  /*!
204  * \brief Default constructor.
205  */
206  LaePowertrain();
207 
208  /*!
209  * \brief Copy constructor.
210  */
211  LaePowertrain(const LaePowertrain &src);
212 
213  /*!
214  * \brief Destructor.
215  */
217  {
218  }
219 
220  /*!
221  * \brief Assignment operator.
222  *
223  * \param rhs Right hand side object.
224  *
225  * \return Returns copy of this.
226  */
228 
229  /*!
230  * \brief Map motor controller id and motor index to motor id.
231  *
232  * \param nCtrlId Motor controller id.
233  * \param nMotorIndex Motor controller motor index
234  *
235  * \return Returns unique motor id.
236  */
237  static int toMotorId(const int nCtlrId, const int nMotorIndex);
238 
239  /*!
240  * \brief Map motor controller id and motor index to powertrain name (key).
241  *
242  * \param nCtrlId Motor controller id.
243  * \param nMotorIndex Motor controller motor index
244  *
245  * \return Returns key on success, empty string if unknown.
246  */
247  static std::string toKey(const int nCtlrId, const int nMotorIndex);
248 
249  /*!
250  * \brief Map motor id to powertrain name (key).
251  *
252  * \param nMotorId Motor id.
253  *
254  * \return Returns key on success, empty string if unknown.
255  */
256  static std::string toKey(const int nMotorId);
257 
258  /*!
259  * \brief Get this powertrain unique name (key).
260  *
261  * \return String.
262  */
263  std::string getName() const
264  {
265  return m_strName;
266  }
267 
268  /*!
269  * \brief Get motor id.
270  *
271  * \return Returns motor id.
272  */
273  int getMotorId() const
274  {
275  return m_attr.m_nMotorId;
276  }
277 
278  /*!
279  * \brief Get motor controller id.
280  *
281  * \return Returns controller id.
282  */
283  int getMotorCtlrId() const
284  {
285  return m_attr.m_nMotorCtlrId;
286  }
287 
288  /*!
289  * \brief Get motor controller motor index.
290  *
291  * \return Returns controller motor index.
292  */
293  int getMotorIndex() const
294  {
295  return m_attr.m_nMotorIndex;
296  }
297 
298  /*!
299  * \brief Configure powertrain from product description.
300  *
301  * \param desc Laelaps powertrain product description data.
302  *
303  * \copydoc doc_return_std
304  */
305  virtual int configure(const LaeDescPowertrain &desc);
306 
307  /*!
308  * \brief Configure powertrain from tune parameters.
309  *
310  * \param tunes Laelaps tuning parameters.
311  *
312  * \copydoc doc_return_std
313  */
314  virtual int configure(const LaeTunes &tunes);
315 
316  /*!
317  * \brief Reload tuning parameters and re-configure.
318  *
319  * \param tunes Laelaps tuning parameters.
320  *
321  * \copydoc doc_return_std
322  */
323  virtual int reload(const LaeTunes &tunes);
324 
325  /*!
326  * \brief Reset odometry to zero.
327  *
328  * All related positioning data are reset to 0.
329  *
330  * \copydoc doc_return_std
331  */
332  virtual int resetOdometer();
333 
334  /*!
335  * \brief Update state dynamics.
336  *
337  * \param nEncoder Current encoder position (quad pulses).
338  * \param nSpeed Current motor speed (qpps).
339  * \param fAmps Current motor draw (amperes).
340  * \param uBufLen Current command queue length.
341  *
342  * \copydoc doc_return_std
343  */
344  virtual int updateStateDynamics(s64_t nEncoder,
345  s32_t nSpeed,
346  double fAmps,
347  uint_t uBufLen);
348 
349  /*!
350  * \brief Update motor health state.
351  *
352  * \param fVolts Motor input voltage (V).
353  * \param fTemp Motor controller board voltage (V).
354  * \param uCtlrStatus Motor controller status bits.
355  *
356  * \copydoc doc_return_std
357  */
358  virtual int updateHealth(double fVolts, double fTemp, uint_t uCtlrStatus);
359 
360  }; // class LaePowertrain
361 
362 
363  // ---------------------------------------------------------------------------
364  // Other Types, Constants, Defines
365  // ---------------------------------------------------------------------------
366 
367  /*!
368  * \brief Map of powertrain kinodynamics.
369  *
370  * \termblock
371  * \term key: \termdata powertrain unique name \endterm
372  * \term mapped type: \termdata powertrain attribute and state data \endterm
373  * \endtermblock
374  */
375  typedef std::map<std::string, LaePowertrain> LaeMapPowertrain;
376 
377 } // namespace laelaps
378 
379 
380 #endif // _LAE_POWERTRAIN_H
double m_fAmps
motor draw (A)
int m_nMotorCtlrId
motor controller id
Definition: laePowertrain.h:81
int getMotorId() const
Get motor id.
Laelaps tuning data class.
Definition: laeTune.h:566
double m_fTemp
motor temperature (C)
int m_eJointType
joint type
Definition: laePowertrain.h:85
uint_t m_uBufLen
command queue length
double m_fGearRatio
gear ratio
Definition: laePowertrain.h:88
double m_fTorque
wheel torque (N-m)
double m_fMaxAmps
maximum rated amps
Definition: laePowertrain.h:94
std::string m_strName
powertrain unique name (key)
int m_nMotorIndex
motor controller unique motor index
Definition: laePowertrain.h:82
double m_fMaxRps
maximum rated output shaft rev/sec
Definition: laePowertrain.h:89
int m_nMotorDir
motor normalized direction
Definition: laePowertrain.h:84
double m_fTireRadius
tire radius
Definition: laePowertrain.h:97
int getMotorIndex() const
Get motor controller motor index.
double m_fPm
motor output mechanical power (W)
double m_fMotorRadsPerPulse
motor radians per encoder pulse
Definition: laePowertrain.h:91
uint_t m_uWarnings
motor warnings
Powertrain attributes class.
Definition: laePowertrain.h:76
double m_fStallTorque
stall torque amps
Definition: laePowertrain.h:95
LaePowertrainAttr m_attr
semi-fixed attribute data
Robotic powertrain description.
Definition: laeDesc.h:177
The <b><i>Laelaps</i></b> namespace encapsulates all <b><i>Laelaps</i></b> related constructs...
Definition: laeAlarms.h:64
Laelaps robotic base mobile platform description class interface.
uint_t m_uMaxQpps
maximum quadrature pulses/second rps
Definition: laePowertrain.h:90
uint_t m_uAlarms
motor alarms
std::string getName() const
Get this powertrain unique name (key).
double m_fVolts
input motor voltage (V)
std::map< std::string, LaePowertrain > LaeMapPowertrain
Map of powertrain kinodynamics.
Laelaps tuning.
LaePowertrainAttr()
Default constructor.
int getMotorCtlrId() const
Get motor controller id.
s64_t m_nEncoder
motor encoder position (quad pulses)
double m_fMetersPerRadian
tire meters per radian
double m_fMetersPerPulse
tire meters per encoder pulse
Definition: laePowertrain.h:99
~LaePowertrainState()
Destructor.
double m_fWheelRadsPerPulse
output shaft radians per encoder pulse
Definition: laePowertrain.h:92
Powertrain state data class.
LaePowertrainState m_state
dynamic state data
double m_fPe
motor input electrical power (W)
double m_fTireWidth
tire width
Definition: laePowertrain.h:98
double m_fVelocity
wheel angular velocity (radians/second)
uint_t m_uPulsesPerRev
encoder pulses per motor revolution
Definition: laePowertrain.h:87
double m_fPosition
wheel angular position (radians)
Powertrain data class.
LaePowertrainAttr operator=(const LaePowertrainAttr &rhs)
Assignment operator.
int m_nSpeed
raw speed (qpps)
~LaePowertrain()
Destructor.
Top-level package include file.
~LaePowertrainAttr()
Destructor.