Hekateros  3.4.3
RoadNarrows Robotics Robot Arm Project
hekXmlTune.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Package: Hekateros
4 //
5 // Library: libhekateros
6 //
7 // File: hekXmlTune.h
8 //
9 /*! \file
10  *
11  * $LastChangedDate: 2015-06-03 15:37:18 -0600 (Wed, 03 Jun 2015) $
12  * $Rev: 4012 $
13  *
14  * \brief \h_hek XML tuning class interface.
15  *
16  * \author Robin Knight (robin.knight@roadnarrows.com)
17  *
18  * \copyright
19  * \h_copy 2014-2017. RoadNarrows LLC.\n
20  * http://www.roadnarrows.com\n
21  * All Rights Reserved
22  */
23 /*
24  * @EulaBegin@
25  *
26  * Unless otherwise stated explicitly, all materials contained are copyrighted
27  * and may not be used without RoadNarrows LLC's written consent,
28  * except as provided in these terms and conditions or in the copyright
29  * notice (documents and software) or other proprietary notice provided with
30  * the relevant materials.
31  *
32  * IN NO EVENT SHALL THE AUTHOR, ROADNARROWS LLC, OR ANY
33  * MEMBERS/EMPLOYEES/CONTRACTORS OF ROADNARROWS OR DISTRIBUTORS OF THIS SOFTWARE
34  * BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR
35  * CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS
36  * DOCUMENTATION, EVEN IF THE AUTHORS OR ANY OF THE ABOVE PARTIES HAVE BEEN
37  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38  *
39  * THE AUTHORS AND ROADNARROWS LLC SPECIFICALLY DISCLAIM ANY WARRANTIES,
40  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
41  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN
42  * "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO
43  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
44  *
45  * @EulaEnd@
46  */
47 ////////////////////////////////////////////////////////////////////////////////
48 
49 #ifndef _HEK_XML_TUNE_H
50 #define _HEK_XML_TUNE_H
51 
52 #include <string>
53 
54 #include "rnr/rnrconfig.h"
55 #include "rnr/log.h"
56 #include "rnr/appkit/Xml.h"
57 #include "rnr/tinyxml/tinyxml.h"
58 
59 #include "Hekateros/hekateros.h"
60 #include "Hekateros/hekTune.h"
61 #include "Hekateros/hekJoint.h"
62 
63 namespace hekateros
64 {
65  //----------------------------------------------------------------------------
66  // HekXmlTune Class
67  //----------------------------------------------------------------------------
68 
69  /*!
70  * \brief HekXmlTune \h_hek XML tuning class.
71  */
72  class HekXmlTune : public rnr::Xml
73  {
74  public:
75  /*!
76  * \brief Default constructor.
77  */
79  Xml("hekateros", HekXsiUrl, HekXslUrl),
80 
81  m_strMajElemTuning("tuning"),
82  m_strSecElemGlobal("global"),
83  m_strElemKinHz("kinematic_hz"),
84  m_strElemClearTorqueOff("clear_torque_offset"),
85  m_strElemVelDerate("velocity_derate"),
86  m_strSubSecElemTraj("trajectory"),
87  m_strElemTrajNorm("norm"),
88  m_strElemTrajEpsilon("epsilon"),
89 
90  m_strSecElemJoint("joint"),
91  m_strAttrJointId("name"),
92  m_strElemTolPos("position_tolerance"),
93  m_strElemTolVel("velocity_tolerance"),
94  m_strElemOverTorqueTh("over_torque_threshold"),
95  m_strSubSecElemPid("pid"),
96  m_strElemPidKp("Kp"),
97  m_strElemPidKi("Ki"),
98  m_strElemPidKd("Kd"),
99  m_strElemPidMaxDeltaV("max_delta_v")
100  {
101  }
102 
103  /*!
104  * \brief Destructor.
105  */
106  virtual ~HekXmlTune()
107  {
108  }
109 
110  /*!
111  * \brief Load XML file into DOM and set the \h_hek tuning parameters.
112  *
113  * \param [out] tunes \h_hek tuning.
114  * \param strSearchPath Search path of directory paths.
115  * \param strXmlFileName XML file name.
116  * \param bAllInstances Do [not] load and set all instances of XML files
117  * found.
118  *
119  * \copydoc doc_return_std
120  */
121  virtual int load(HekTunes &tunes,
122  const std::string &strSearchPath=HekSysCfgPath,
123  const std::string &strXmlFileName=HekEtcTune,
124  bool bAllInstances=false);
125 
126  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
127  // I/O Methods
128  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
129 
130  /*!
131  * \brief Load XML file into DOM.
132  *
133  * \param strXmlFileName XML file path name.
134  *
135  * \copydoc doc_return_std
136  */
137  virtual int loadFile(const std::string &strXmlFileName=HekEtcTune);
138 
139  /*!
140  * \brief Load XML file into DOM and set the \h_hek tuning parameters.
141  *
142  * \param [out] tunes \h_hek tuning.
143  * \param strXmlFileName XML file path name.
144  *
145  * \copydoc doc_return_std
146  */
147  virtual int loadFile(HekTunes &tunes,
148  const std::string &strXmlFileName=HekEtcTune)
149  {
150  int rc;
151 
152  if( (rc = loadFile(strXmlFileName)) == HEK_OK )
153  {
154  rc = setTunesFromDOM(tunes);
155  }
156 
157  return rc < 0? -HEK_ECODE_XML: HEK_OK;
158  }
159 
160  /*!
161  * \brief Save DOM to XML file.
162  *
163  * \param strXmlFileName XML file path name.
164  *
165  * \copydoc doc_return_std
166  */
167  virtual int saveFile(const std::string &strXmlFileName=HekEtcTune)
168  {
169  int rc = Xml::saveFile(strXmlFileName);
170 
171  return rc < 0? -HEK_ECODE_XML: HEK_OK;
172  }
173 
174  /*!
175  * \brief Set DOM from \h_hek description and save XML file.
176  *
177  * \param [in] tunes \h_hek tuning.
178  * \param strXmlFileName XML file path name.
179  *
180  * \copydoc doc_return_std
181  */
182  virtual int saveFile(const HekTunes &tunes,
183  const std::string &strXmlFileName=HekEtcTune)
184  {
185  int rc;
186 
187  if( (rc = setDOMFromHekTunes(tunes)) == HEK_OK )
188  {
189  rc = Xml::saveFile(strXmlFileName);
190  }
191 
192  return rc < 0? -HEK_ECODE_XML: HEK_OK;
193  }
194 
195  /*!
196  * \brief Create a template \h_hek XML configuration file.
197  * root element.
198  *
199  * Any current DOM is not accessed nor altered.
200  *
201  * \param strXmlFileName XML file path name.
202  *
203  * \copydoc doc_return_std
204  */
205  virtual int createTemplateFile(const std::string &strXmlFileName =
206  HekEtcTune);
207 
208  /*!
209  * \brief Set the tune parameters from the parsed DOM.
210  *
211  * \param [out] tunes \h_hek tuning.
212  *
213  * \copydoc doc_return_std
214  */
215  virtual int setTunesFromDOM(HekTunes &tunes);
216 
217  /*!
218  * \brief Set the DOM from the \h_hek tune parameters.
219  *
220  * \param [in] tunes \h_hek tuning.
221  *
222  * \copydoc doc_return_std
223  */
224  virtual int setDOMFromHekTunes(const HekTunes &tunes);
225 
226  protected:
227  std::string m_strMajElemTuning; ///< major element under 'hekateros'
228 
229  std::string m_strSecElemGlobal; ///< global tuning section element
230  std::string m_strElemKinHz; ///< kinematics thread hz
231  std::string m_strElemClearTorqueOff;///< clear over torque cond. th offset
232  std::string m_strElemVelDerate; ///< derated velocity
233  std::string m_strSubSecElemTraj; ///< trajectory subsection
234  std::string m_strElemTrajNorm; ///< distance norm
235  std::string m_strElemTrajEpsilon; ///< distance epsilon
236 
237  std::string m_strSecElemJoint; ///< joint tuning section element.
238  std::string m_strAttrJointId; ///< joint id attribute name
239  std::string m_strElemTolPos; ///< position tolerance
240  std::string m_strElemTolVel; ///< position tolerance
241  std::string m_strElemOverTorqueTh;///< over torque condition threshold
242  std::string m_strSubSecElemPid; ///< pos/vel pid subsection
243  std::string m_strElemPidKp; ///< pid proportional constant
244  std::string m_strElemPidKi; ///< pid integral constant
245  std::string m_strElemPidKd; ///< pid derivative constant
246  std::string m_strElemPidMaxDeltaV;///< pid maximum delta v
247 
248  /*!
249  * \brief Set the global tune parameters from the parsed DOM.
250  *
251  * \param pElemSec Parent enclosing section element.
252  * \param [out] tunes \h_hek tuning.
253  *
254  * \copydoc doc_return_std
255  */
256  int setGlobalTunes(TiXmlElement *pElemSec, HekTunes &tunes);
257 
258  /*!
259  * \brief Set a joint tune parameters from the parsed DOM.
260  *
261  * \param pElemSec Parent enclosing section element.
262  * \param [out] tunes \h_hek tuning.
263  *
264  * \copydoc doc_return_std
265  */
266  int setJointTunes(TiXmlElement *pElemSec, HekTunes &tunes);
267 
268  /*!
269  * \brief Set the global trajectory tune parameters from the parsed DOM.
270  *
271  * \param pElemSubSec Parent enclosing subsection element.
272  * \param [out] tunes \h_hek tuning.
273  *
274  * \copydoc doc_return_std
275  */
276  int setGlobalTrajTunes(TiXmlElement *pElemSubSec, HekTunes &tunes);
277 
278  /*!
279  * \brief Set a joint's PID tune parameters from the parsed DOM.
280  *
281  * \param strJointName Joint name.
282  * \param pElemSubSec Parent enclosing subsection element.
283  * \param [out] tunesJoint \h_hek joint specific tuning.
284  *
285  * \copydoc doc_return_std
286  */
287  int setJointPidTunes(const std::string &strJointName,
288  TiXmlElement *pElemSubSec,
289  HekTunesJoint &tunesJoint);
290 
291  /*!
292  * \brief Convert text to value with a minimum value.
293  *
294  * If the converted value is \h_lt the minimum, it will be set to the
295  * minimum.
296  *
297  * If the text is empty or if a conversion error occurs, the value is not
298  * set.
299  *
300  * \param strElem XML element name.
301  * \param strText XML element text. <elem>TEXT</elem>
302  * \param fMin Minimum value allowed.
303  * \param [out] fVal Converted value.
304  *
305  * \copydoc doc_return_std
306  */
307  int strToDoubleWithMinimum(const std::string &strElem,
308  const std::string &strText,
309  const double fMin,
310  double &fVal);
311 
312  /*!
313  * \brief Convert text to value within minimum,maximum range.
314  *
315  * If the converted value is out of range, it will be set to the appropriate
316  * boundry value.
317  *
318  * If the text is empty or if a conversion error occurs, the value is not
319  * set.
320  *
321  * \param strElem XML element name.
322  * \param strText XML element text. <elem>TEXT</elem>
323  * \param fMin Minimum value allowed.
324  * \param fMax Maximum value allowed.
325  * \param [out] fVal Converted value.
326  *
327  * \copydoc doc_return_std
328  */
329  int strToDoubleWithinRange(const std::string &strElem,
330  const std::string &strText,
331  const double fMin,
332  const double fMax,
333  double &fVal);
334 
335  /*!
336  * \brief Convert text to norm enum.
337  *
338  * If the text is empty or if a conversion error occurs, the value is not
339  * set.
340  *
341  * \param strElem XML element name.
342  * \param strText XML element text. <elem>TEXT</elem>
343  * \param [out] eNorm Converted value.
344  *
345  * \copydoc doc_return_std
346  */
347  int strToNorm(const std::string &strElem,
348  const std::string &strText,
349  HekNorm &eNorm);
350 
351 
352  /*!
353  * \brief Warn on unknown element.
354  *
355  * \param strElem Element name.
356  */
357  void warnUnknownElem(const std::string &strElem)
358  {
359  setErrorMsg("%s: Element <%s> unknown - ignoring.",
360  m_strXmlFileName.c_str(), strElem.c_str());
361  LOGWARN("%s", m_bufErrMsg);
362  }
363  };
364 
365 } // hekateros namespace
366 
367 #endif // _HEK_XML_TUNE_H
std::string m_strElemPidKd
pid derivative constant
Definition: hekXmlTune.h:245
const char *const HekSysCfgPath
System configuration search path.
Definition: hekateros.h:322
HekXmlTune()
Default constructor.
Definition: hekXmlTune.h:78
int setJointPidTunes(const std::string &strJointName, TiXmlElement *pElemSubSec, HekTunesJoint &tunesJoint)
Set a joint&#39;s PID tune parameters from the parsed DOM.
Definition: hekXmlTune.cxx:555
static const int HEK_OK
not an error, success
Definition: hekateros.h:70
std::string m_strElemTrajNorm
distance norm
Definition: hekXmlTune.h:234
const char *const HekXsiUrl
xml schema instance url
Definition: hekateros.h:371
int strToNorm(const std::string &strElem, const std::string &strText, HekNorm &eNorm)
Convert text to norm enum.
Definition: hekXmlTune.cxx:694
std::string m_strSecElemJoint
joint tuning section element.
Definition: hekXmlTune.h:237
int setGlobalTunes(TiXmlElement *pElemSec, HekTunes &tunes)
Set the global tune parameters from the parsed DOM.
Definition: hekXmlTune.cxx:319
std::string m_strMajElemTuning
major element under &#39;hekateros&#39;
Definition: hekXmlTune.h:227
Hekateros tuning per joint data class.
Definition: hekTune.h:367
std::string m_strAttrJointId
joint id attribute name
Definition: hekXmlTune.h:238
std::string m_strElemOverTorqueTh
over torque condition threshold
Definition: hekXmlTune.h:241
virtual int saveFile(const HekTunes &tunes, const std::string &strXmlFileName=HekEtcTune)
Set DOM from <b><i>Hekateros</i></b> description and save XML file.
Definition: hekXmlTune.h:182
std::string m_strElemTolVel
position tolerance
Definition: hekXmlTune.h:240
virtual int saveFile(const std::string &strXmlFileName=HekEtcTune)
Save DOM to XML file.
Definition: hekXmlTune.h:167
Hekateros tuning data class.
Definition: hekTune.h:408
std::string m_strElemPidMaxDeltaV
pid maximum delta v
Definition: hekXmlTune.h:246
virtual int createTemplateFile(const std::string &strXmlFileName=HekEtcTune)
Create a template <b><i>Hekateros</i></b> XML configuration file. root element.
Definition: hekXmlTune.cxx:159
std::string m_strElemTolPos
position tolerance
Definition: hekXmlTune.h:239
virtual int loadFile(const std::string &strXmlFileName=HekEtcTune)
Load XML file into DOM.
Definition: hekXmlTune.cxx:130
virtual ~HekXmlTune()
Destructor.
Definition: hekXmlTune.h:106
static const int HEK_ECODE_XML
XML error.
Definition: hekateros.h:91
int setJointTunes(TiXmlElement *pElemSec, HekTunes &tunes)
Set a joint tune parameters from the parsed DOM.
Definition: hekXmlTune.cxx:395
int setGlobalTrajTunes(TiXmlElement *pElemSubSec, HekTunes &tunes)
Set the global trajectory tune parameters from the parsed DOM.
Definition: hekXmlTune.cxx:501
HekXmlTune <b><i>Hekateros</i></b> XML tuning class.
Definition: hekXmlTune.h:72
Hekateros joint classes interfaces.
const char *const HekXslUrl
xml stylesheet url
Definition: hekateros.h:360
std::string m_strElemVelDerate
derated velocity
Definition: hekXmlTune.h:232
void warnUnknownElem(const std::string &strElem)
Warn on unknown element.
Definition: hekXmlTune.h:357
std::string m_strSubSecElemTraj
trajectory subsection
Definition: hekXmlTune.h:233
std::string m_strElemKinHz
kinematics thread hz
Definition: hekXmlTune.h:230
std::string m_strSecElemGlobal
global tuning section element
Definition: hekXmlTune.h:229
std::string m_strElemClearTorqueOff
clear over torque cond. th offset
Definition: hekXmlTune.h:231
const char *const HekEtcTune
xml tune file
Definition: hekateros.h:343
std::string m_strSubSecElemPid
pos/vel pid subsection
Definition: hekXmlTune.h:242
int strToDoubleWithinRange(const std::string &strElem, const std::string &strText, const double fMin, const double fMax, double &fVal)
Convert text to value within minimum,maximum range.
Definition: hekXmlTune.cxx:656
Top-level package include file.
std::string m_strElemPidKp
pid proportional constant
Definition: hekXmlTune.h:243
HekNorm
Length/Distance Norm.
Definition: hekateros.h:535
virtual int load(HekTunes &tunes, const std::string &strSearchPath=HekSysCfgPath, const std::string &strXmlFileName=HekEtcTune, bool bAllInstances=false)
Load XML file into DOM and set the <b><i>Hekateros</i></b> tuning parameters.
Definition: hekXmlTune.cxx:72
Hekateros tuning.
virtual int loadFile(HekTunes &tunes, const std::string &strXmlFileName=HekEtcTune)
Load XML file into DOM and set the <b><i>Hekateros</i></b> tuning parameters.
Definition: hekXmlTune.h:147
std::string m_strElemPidKi
pid integral constant
Definition: hekXmlTune.h:244
std::string m_strElemTrajEpsilon
distance epsilon
Definition: hekXmlTune.h:235
int strToDoubleWithMinimum(const std::string &strElem, const std::string &strText, const double fMin, double &fVal)
Convert text to value with a minimum value.
Definition: hekXmlTune.cxx:627
virtual int setTunesFromDOM(HekTunes &tunes)
Set the tune parameters from the parsed DOM.
Definition: hekXmlTune.cxx:247
The <b><i>Hekateros</i></b> namespace encapsulates all <b><i>Hekateros</i></b> related constructs...
Definition: hekateros.h:56
virtual int setDOMFromHekTunes(const HekTunes &tunes)
Set the DOM from the <b><i>Hekateros</i></b> tune parameters.
Definition: hekXmlTune.cxx:313