Hekateros  3.4.3
RoadNarrows Robotics Robot Arm Project
hekTune.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Package: Hekateros
4 //
5 // Library: libhekateros
6 //
7 // File: hekTune.h
8 //
9 /*! \file
10  *
11  * $LastChangedDate: 2015-06-03 15:37:18 -0600 (Wed, 03 Jun 2015) $
12  * $Rev: 4012 $
13  *
14  * \brief Hekateros tuning.
15  *
16  * All tuning defaults defined below can be overridden in the
17  * /etc/hek_tune.conf XML file.
18  *
19  * \author Robin Knight (robin.knight@roadnarrows.com)
20  *
21  * \copyright
22  * \h_copy 2014-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 _HEK_TUNE_H
53 #define _HEK_TUNE_H
54 
55 #include <iostream>
56 #include <string>
57 #include <map>
58 
59 #include "rnr/rnrconfig.h"
60 
61 #include "Hekateros/hekateros.h"
62 #include "Hekateros/hekUtils.h"
63 
64 namespace hekateros
65 {
66  //----------------------------------------------------------------------------
67  // Hekateros Tuning Defaults
68  //----------------------------------------------------------------------------
69 
70  /*!
71  * defgroup hek_tunes
72  * \{
73  */
74 
75  // . .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .
76  // Kinematics Thread Run Rate Tuning
77 
78  /*!
79  * \brief Default kinematics thread cycle rate (Hertz).
80  *
81  * All dynamics and kinematics tasks exectute per each cycle.
82  *
83  * \verbatim
84  * kin_hz = tune_kin_hz
85  * T_task = 1/kin_hz * 1/(numof_joints + 1)
86  * Where each joint dynamics is monitored and controlled each cycle and the
87  * extra task is for health monitoring.
88  * \endverbatim
89  *
90  * Range: \h_ge \ref HekTuneKinHzMin
91  * Scope: global
92  */
93  static const double HekTuneKinHzDft = 30.0;
94 
95  /*!
96  * \brief Minimum kinematics thread cycle rate (Hertz).
97  *
98  * Gotta give me something boys!
99  */
100  static const double HekTuneKinHzMin = 0.1;
101 
102 
103  // . .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .
104  // Over Torque Threshold Tuning
105 
106  /*!
107  * \brief Default joint over torque threshold (% of maximum)
108  *
109  * Default default for all arm joints excluding end effector. The actual
110  * defaults are specified in the compiled product spec on a per joint basis.
111  *
112  * The working value is converted to raw motor load values internally.
113  *
114  * \verbatim
115  * over_torque_th = tune_over_torque_th / 100.0 * max_motor_load(joint)
116  * \endverbatim
117  *
118  * Range: [\ref HekTuneOverTorqueThMin, \ref HekTuneOverTorqueThMax]
119  * Scope: per joint
120  */
121  static const double HekTuneOverTorqueThDft = 80.0;
122 
123  /*!
124  * \brief Default end effector over torque threshold (% of maximum)
125  *
126  * Default default for all end effector joints. The actual defaults are
127  * specified in the compiled product spec on a per joint basis.
128  *
129  * The working value is converted to raw motor load values internally.
130  *
131  * \verbatim
132  * over_torque_th = tune_over_torque_th / 100.0 * max_motor_load(joint)
133  * \endverbatim
134  *
135  * Range: [\ref HekTuneOverTorqueThMin, \ref HekTuneOverTorqueThMax]
136  * Scope: global
137  */
138  static const double HekTuneEEOverTorqueThDft = 40.0;
139 
140  /*!
141  * \brief Minimum joint over torque threshold (% of maximum)
142  */
143  static const double HekTuneOverTorqueThMin = 10.0;
144 
145  /*!
146  * \brief Maximum joint over torque threshold (% of maximum)
147  */
148  static const double HekTuneOverTorqueThMax = 100.0;
149 
150 
151  // . .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .
152  // Clear Over Torque Condition Threshold Offset Tuning
153 
154  /*!
155  * \brief Default clear torque condition hysteresis threshhold offset
156  * (% of over torque threshold).
157  *
158  * The fraction is of the joint's over torque threshold. Once the servos
159  * associtated with a joint enter the over torque condition, the condition
160  * does not clear until torque is below the clear torque threshold.
161  *
162  * The working value is converted to raw motor load values internally.
163  *
164  * \verbatim
165  * clear_torque_offset = tune_clear_torque_offset / 100.0
166  * clear_over_torque_cond_th = over_torque_th * clear_torque_offset
167  * \endverbatim
168  *
169  * Range: [\ref HekTuneClearTorqueOffsetMin, \ref HekTuneClearTorqueOffsetMax]
170  * Scope: global
171  */
172  static const double HekTuneClearTorqueOffsetDft = 90.0;
173 
174  /*!
175  * \brief Minimum clear torque condition hysteresis threshhold offset
176  * (% of over torque threshold).
177  */
178  static const double HekTuneClearTorqueOffsetMin = 10.0;
179 
180  /*!
181  * \brief Maximum clear torque condition hysteresis threshhold offset
182  * (% of over torque threshold).
183  */
184  static const double HekTuneClearTorqueOffsetMax = 99.5;
185 
186 
187  // . .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .
188  // Derated Velocity Tuning
189 
190  /*!
191  * \brief Default Hekateros robot velocity derate (% of goal velocities).
192  *
193  * When a new move command is received, all of the goal velocities are
194  * multiplied by this derated value.
195  *
196  * The working value is converted to a normalized value internally.
197  *
198  * \verbatim
199  * velocity_derate = tune_velocity_derate / 100.0
200  * joint_goal_vel = joint_goal_vel * velocity_derate
201  * \endverbatim
202  *
203  * Range: [\ref HekTuneVelDerateMin, \ref HekTuneVelDerateMax]
204  * Scope: global
205  */
206  static const double HekTuneVelDerateDft = 100.0;
207 
208  /*!
209  * \brief Minimum robot velocity derate (% of goal velocities).
210  */
211  static const double HekTuneVelDerateMin = 10.0;
212 
213  /*!
214  * \brief Maximum robot velocity derate (% of goal velocities).
215  */
216  static const double HekTuneVelDerateMax = 100.0;
217 
218 
219  // . .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .
220  // Position Tolerance Tuning
221 
222  /*!
223  * \brief Default joint position control tolerance (degrees).
224  *
225  * A joint goal position that is within the position tolerance of the current
226  * joint position is considered identical. If the joint was moving to the
227  * goal position, the joint will be automatically stopped.
228  *
229  * The working value is converted to radians internally.
230  *
231  * \verbatim
232  * tol_pos = deg_to_rad(tune_tol_pos)
233  * |joint_goal_pos - joint_cur_pos| < tol_pos <==> same position.
234  * \endverbatim
235  *
236  * Range: \h_ge \ref HekTuneTolPosMin
237  * Scope: per joint
238  */
239  static const double HekTuneTolPosDft = 0.2;
240 
241  /*!
242  * \brief Minimum joint position control tolerance (degrees).
243  */
244  static const double HekTuneTolPosMin = 0.0;
245 
246 
247  // . .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .
248  // Velocity Tolerance Tuning
249 
250  /*!
251  * \brief Default joint velocity control tolerance (degrees/second).
252  *
253  * A joint goal velocity that is within the velocity tolerance of the current
254  * joint velocity is considered identical. No speed updates will be written
255  * to the servo contoller.
256  *
257  * The working value is converted to radians/second internally.
258  *
259  *
260  * \verbatim
261  * tol_vel = deg_to_rad(tune_tol_vel)
262  * |joint_goal_vel - joint_cur_vel| < tol_vel <==> same velocity.
263  * \endverbatim
264  *
265  * Range: \h_ge \ref HekTuneTolVelMin
266  * Scope: per joint
267  */
268  static const double HekTuneTolVelDft = 1.0;
269 
270  /*!
271  * \brief Minimum joint velocition control tolerance (degrees/second).
272  */
273  static const double HekTuneTolVelMin = 0.0;
274 
275 
276  // . .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .
277  // Position and Velocity PID Tuning
278 
279  /*!
280  * \brief Default joint position and velocity PID proportional constant.
281  *
282  * Range: \h_ge \ref HekTunePidKMin
283  * Scope: per joint
284  */
285  static const double HekTunePidKpDft = 3.0;
286 
287  /*!
288  * \brief Default joint position and velocity PID integral constant.
289  *
290  * Range: \h_ge \ref HekTunePidKMin
291  * Scope: per joint
292  */
293  static const double HekTunePidKiDft = 0.05;
294 
295  /*!
296  * \brief Default joint position and velocity PID derivative constant.
297  *
298  * Range: \h_ge \ref HekTunePidKMin
299  * Scope: per joint
300  */
301  static const double HekTunePidKdDft = 0.1;
302 
303  /*!
304  * \brief Minimum PID K constant value.
305  */
306  static const double HekTunePidKMin = 0.0;
307 
308  /*!
309  * \brief Maximum PID delta V output (degrees/second)
310  *
311  * Range: \ref HekTunePidDeltaVNoMax or \h_gt 0.0
312  * Scope: per joint
313  */
314  static const double HekTunePidMaxDeltaVDft = 30.0;
315 
316  /*!
317  * \brief No maximum PID delta V output special value.
318  */
319  static const double HekTunePidDeltaVNoMax = 0;
320 
321 
322  // . .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .
323  // Trajectory Tuning
324 
325  /*!
326  * \brief Default trajectory norm.
327  *
328  * Range: \ref HekNormL1, \ref HekNormL2, \ref HekNormLinf
329  * Scope: global
330  */
332 
333  /*!
334  * \brief Default trajectory distance epsilon (degrees).
335  *
336  * Trajectory waypoints distances within epsilon are considered reached.
337  *
338  * The working value is converted to radians internally.
339  *
340  * \verbatim
341  * ||WP-P|| < epsilon <==> waypoint reached
342  * Where WP is the vector of joint waypoint positions and P is the vector
343  * of current joint positions.
344  * \endverbatim
345  *
346  * Range: \h_ge \ref HekTuneTrajEpsilonMin
347  */
348  static const double HekTuneTrajEpsilonDft = 20.0;
349 
350  /*!
351  * \brief Minimum epsilon value.
352  */
353  static const double HekTuneTrajEpsilonMin = 0.0;
354 
355  /*!
356  * \}
357  */
358 
359 
360  //----------------------------------------------------------------------------
361  // HekTunesJoint Class
362  //----------------------------------------------------------------------------
363 
364  /*!
365  * \brief Hekateros tuning per joint data class.
366  */
368  {
369  public:
370  double m_fTolPos; ///< position tolerance (radians)
371  double m_fTolVel; ///< velocitiy tolerance (radians/second)
372  double m_fPidKp; ///< position and velocity PID proportional const
373  double m_fPidKi; ///< position and velocity PID integral constant
374  double m_fPidKd; ///< position and velocity PID derivative constant
375  double m_fPidMaxDeltaV; ///< max output delta v (radians/second)
376  double m_fOverTorqueTh; ///< over torque conditon threshold (fraction)
377 
378  /*!
379  * \brief Default constructor.
380  */
381  HekTunesJoint();
382 
383  /*!
384  * \brief Destructor.
385  */
387  {
388  }
389 
390  /*!
391  * \brief Assignment operator
392  *
393  * \param rhs Right hand side object.
394  *
395  * \return *this
396  */
398  };
399 
400 
401  //----------------------------------------------------------------------------
402  // HekTunes Class
403  //----------------------------------------------------------------------------
404 
405  /*!
406  * \brief Hekateros tuning data class.
407  */
408  class HekTunes
409  {
410  public:
411  /*! Map of joint tuning parameters. */
412  typedef std::map<std::string, HekTunesJoint> MapJointTunes;
413 
414  // global tuning
415  double m_fKinematicsHz; ///< kinematic thread rate (hertz)
416  double m_fClearTorqueOffset; ///< clear over torque condition offset (frac)
417  double m_fVelDerate; ///< velocity derate (fraction)
418  HekNorm m_eTrajNorm; ///< trajectory distanct norm
419  double m_fTrajEpsilon; ///< trajectory epsilon distance (radians)
420 
421  // per joint tuning
422  MapJointTunes m_mapJointTunes; ///< per joint tuning
423 
424  /*!
425  * \brief Default constructor.
426  */
427  HekTunes();
428 
429  /*!
430  * \brief Destructor.
431  */
433  {
434  }
435 
436  /*!
437  * \brief Get kinematics thread cycle rate tune parameter (hertz).
438  *
439  * \return Hertz.
440  */
441  double getKinematicsHz() const
442  {
443  return m_fKinematicsHz;
444  }
445 
446  /*!
447  * \brief Get derated velocity tune parameter (normalized).
448  *
449  * \return Derated value [0, 1].
450  */
451  double getVelocityDerate() const
452  {
453  return m_fVelDerate;
454  }
455 
456  /*!
457  * \brief Get trajectory tune parameters.
458  *
459  * \param [out] eNorm Distance norm.
460  * \param [out] fEpsilon Waypoint precision (radians)
461  */
462  void getTrajectoryParams(HekNorm &eNorm, double &fEpsilon) const
463  {
464  eNorm = m_eTrajNorm;
465  fEpsilon = m_fTrajEpsilon;
466  }
467 
468  /*!
469  * \brief Get joint tolerance tune parameters.
470  *
471  * \param strJointName Name of joint.
472  * \param [out] fTolPos Position tolerance (radians)
473  * \param [out] fTolVel Velocity tolerance (radians/second)
474  */
475  void getToleranceParams(const std::string &strJointName,
476  double &fTolPos, double &fTolVel) const;
477 
478  /*!
479  * \brief Get joint PID K tune parameters.
480  *
481  * \param strJointName Name of joint.
482  * \param [out] fKp Proportional constant.
483  * \param [out] fKi Integral constant.
484  * \param [out] fKd Derivative constant.
485  */
486  void getPidKParams(const std::string &strJointName,
487  double &fKp, double &fKi, double &fKd) const;
488 
489  /*!
490  * \brief Get joint PID maximum delta v (radians/second) tune parameter.
491  *
492  * \param strJointName Name of joint.
493  *
494  * \return Maximum output delta velocity (radians/second).
495  */
496  double getPidMaxDeltaV(const std::string &strJointName) const;
497 
498  /*!
499  * \brief Get joint torque parameters
500  *
501  * \param strJointName Name of joint.
502  * \param [out] fOverTorqueTh Over torque threshold (normalized).
503  * \param [out] fClearTorqueTh Clear over torque condition threshold
504  * (normalized).
505  */
506  void getTorqueParams(const std::string &strJointName,
507  double &fOverTorqueTh,
508  double &fClearTorqueTh) const;
509  };
510 
511 } // hekateros namespace
512 
513 #endif // _HEK_TUNE_H
static const double HekTuneTolVelMin
Minimum joint velocition control tolerance (degrees/second).
Definition: hekTune.h:273
static const double HekTuneTrajEpsilonMin
Minimum epsilon value.
Definition: hekTune.h:353
static const double HekTuneKinHzDft
Default kinematics thread cycle rate (Hertz).
Definition: hekTune.h:93
static const double HekTuneClearTorqueOffsetDft
Default clear torque condition hysteresis threshhold offset (% of over torque threshold).
Definition: hekTune.h:172
static const double HekTuneTolPosMin
Minimum joint position control tolerance (degrees).
Definition: hekTune.h:244
double m_fPidKi
position and velocity PID integral constant
Definition: hekTune.h:373
static const double HekTuneEEOverTorqueThDft
Default end effector over torque threshold (% of maximum)
Definition: hekTune.h:138
static const double HekTunePidKpDft
Default joint position and velocity PID proportional constant.
Definition: hekTune.h:285
static const double HekTunePidDeltaVNoMax
No maximum PID delta V output special value.
Definition: hekTune.h:319
double m_fPidKp
position and velocity PID proportional const
Definition: hekTune.h:372
static const double HekTunePidKdDft
Default joint position and velocity PID derivative constant.
Definition: hekTune.h:301
double m_fTolVel
velocitiy tolerance (radians/second)
Definition: hekTune.h:371
double m_fVelDerate
velocity derate (fraction)
Definition: hekTune.h:417
Hekateros tuning per joint data class.
Definition: hekTune.h:367
static const double HekTunePidMaxDeltaVDft
Maximum PID delta V output (degrees/second)
Definition: hekTune.h:314
double getVelocityDerate() const
Get derated velocity tune parameter (normalized).
Definition: hekTune.h:451
double m_fTrajEpsilon
trajectory epsilon distance (radians)
Definition: hekTune.h:419
HekTunesJoint & operator=(const HekTunesJoint &rhs)
Assignment operator.
Definition: hekTune.cxx:76
Hekateros tuning data class.
Definition: hekTune.h:408
static const double HekTuneKinHzMin
Minimum kinematics thread cycle rate (Hertz).
Definition: hekTune.h:100
double m_fOverTorqueTh
over torque conditon threshold (fraction)
Definition: hekTune.h:376
std::map< std::string, HekTunesJoint > MapJointTunes
Definition: hekTune.h:412
HekTunesJoint()
Default constructor.
Definition: hekTune.cxx:65
double m_fKinematicsHz
kinematic thread rate (hertz)
Definition: hekTune.h:415
void getTrajectoryParams(HekNorm &eNorm, double &fEpsilon) const
Get trajectory tune parameters.
Definition: hekTune.h:462
~HekTunesJoint()
Destructor.
Definition: hekTune.h:386
static const double HekTuneClearTorqueOffsetMax
Maximum clear torque condition hysteresis threshhold offset (% of over torque threshold).
Definition: hekTune.h:184
static const double HekTuneVelDerateDft
Default Hekateros robot velocity derate (% of goal velocities).
Definition: hekTune.h:206
double m_fPidKd
position and velocity PID derivative constant
Definition: hekTune.h:374
static const HekNorm HekTuneTrajNormDft
Default trajectory norm.
Definition: hekTune.h:331
static const double HekTunePidKiDft
Default joint position and velocity PID integral constant.
Definition: hekTune.h:293
static const double HekTuneTrajEpsilonDft
Default trajectory distance epsilon (degrees).
Definition: hekTune.h:348
double m_fPidMaxDeltaV
max output delta v (radians/second)
Definition: hekTune.h:375
static const double HekTuneVelDerateMin
Minimum robot velocity derate (% of goal velocities).
Definition: hekTune.h:211
HekNorm m_eTrajNorm
trajectory distanct norm
Definition: hekTune.h:418
static const double HekTuneTolVelDft
Default joint velocity control tolerance (degrees/second).
Definition: hekTune.h:268
static const double HekTuneOverTorqueThDft
Default joint over torque threshold (% of maximum)
Definition: hekTune.h:121
Top-level package include file.
Linf norm (maximum, infinity, or supremum norm)
Definition: hekateros.h:539
static const double HekTuneTolPosDft
Default joint position control tolerance (degrees).
Definition: hekTune.h:239
double getKinematicsHz() const
Get kinematics thread cycle rate tune parameter (hertz).
Definition: hekTune.h:441
static const double HekTuneVelDerateMax
Maximum robot velocity derate (% of goal velocities).
Definition: hekTune.h:216
static const double HekTuneClearTorqueOffsetMin
Minimum clear torque condition hysteresis threshhold offset (% of over torque threshold).
Definition: hekTune.h:178
static const double HekTuneOverTorqueThMin
Minimum joint over torque threshold (% of maximum)
Definition: hekTune.h:143
HekNorm
Length/Distance Norm.
Definition: hekateros.h:535
MapJointTunes m_mapJointTunes
per joint tuning
Definition: hekTune.h:422
static const double HekTunePidKMin
Minimum PID K constant value.
Definition: hekTune.h:306
Hekateros common utilities.
double m_fClearTorqueOffset
clear over torque condition offset (frac)
Definition: hekTune.h:416
~HekTunes()
Destructor.
Definition: hekTune.h:432
static const double HekTuneOverTorqueThMax
Maximum joint over torque threshold (% of maximum)
Definition: hekTune.h:148
The <b><i>Hekateros</i></b> namespace encapsulates all <b><i>Hekateros</i></b> related constructs...
Definition: hekateros.h:56
double m_fTolPos
position tolerance (radians)
Definition: hekTune.h:370