Laelaps  2.3.5
RoadNarrows Robotics Small Outdoor Mobile Robot Project
laeXmlTune.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Package: Laelaps
4 //
5 // Library: liblaelaps
6 //
7 // File: laeXmlTune.h
8 //
9 /*! \file
10  *
11  * $LastChangedDate: 2016-01-21 16:50:25 -0700 (Thu, 21 Jan 2016) $
12  * $Rev: 4268 $
13  *
14  * \brief \h_laelaps XML tuning class interface.
15  *
16  * \author Robin Knight (robin.knight@roadnarrows.com)
17  *
18  * \par Copyright
19  * \h_copy 2015-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 _LAE_XML_TUNE_H
50 #define _LAE_XML_TUNE_H
51 
52 #include <string>
53 
54 #include "rnr/rnrconfig.h"
55 #include "rnr/appkit/Xml.h"
56 #include "rnr/log.h"
57 #include "rnr/tinyxml/tinyxml.h"
58 
59 #include "Laelaps/laelaps.h"
60 #include "Laelaps/laeTune.h"
61 
62 namespace laelaps
63 {
64  //----------------------------------------------------------------------------
65  // LaeXmlTune Class
66  //----------------------------------------------------------------------------
67 
68  /*!
69  * \brief LaeXmlTune \h_laelaps XML tuning class.
70  */
71  class LaeXmlTune : public rnr::Xml
72  {
73  public:
74  /*!
75  * \brief Default constructor.
76  */
78  Xml("laelaps", LaeXsiUrl, LaeXslUrl),
79  m_strMajElemTuning("tuning"),
80  m_strSecElemGlobal("global"),
81  m_strSecElemBattery("battery"),
82  m_strSecElemPowertrains("powertrains"),
83  m_strSecElemRangeSensor("range_sensor")
84  {
85  }
86 
87  /*!
88  * \brief Destructor.
89  */
90  virtual ~LaeXmlTune()
91  {
92  }
93 
94  /*!
95  * \brief Load XML file into DOM and set the \h_laelaps tuning parameters.
96  *
97  * \param [out] tunes \h_laelaps tuning.
98  * \param strSearchPath Search path of directory paths.
99  * \param strXmlFileName XML file name.
100  * \param bAllInstances Do [not] load and set all instances of XML files
101  * found.
102  *
103  * \copydoc doc_return_std
104  */
105  virtual int load(LaeTunes &tunes,
106  const std::string &strSearchPath=LaeSysCfgPath,
107  const std::string &strXmlFileName=LaeEtcTune,
108  bool bAllInstances=false);
109 
110  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
111  // I/O Methods
112  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
113 
114  /*!
115  * \brief Load XML file into DOM.
116  *
117  * \param strXmlFileName XML file path name.
118  *
119  * \copydoc doc_return_std
120  */
121  virtual int loadFile(const std::string &strXmlFileName=LaeEtcTune);
122 
123  /*!
124  * \brief Load XML file into DOM and set the \h_laelaps tuning parameters.
125  *
126  * \param [out] tunes \h_laelaps tuning.
127  * \param strXmlFileName XML file path name.
128  *
129  * \copydoc doc_return_std
130  */
131  virtual int loadFile(LaeTunes &tunes,
132  const std::string &strXmlFileName=LaeEtcTune);
133 
134  /*!
135  * \brief Save DOM to XML file.
136  *
137  * \param strXmlFileName XML file path name.
138  *
139  * \copydoc doc_return_std
140  */
141  virtual int saveFile(const std::string &strXmlFileName=LaeEtcTune)
142  {
143  int rc = Xml::saveFile(strXmlFileName);
144 
145  return rc < 0? -LAE_ECODE_XML: LAE_OK;
146  }
147 
148  /*!
149  * \brief Set DOM from \h_laelaps tuning parameters and save XML file.
150  *
151  * \param [in] tunes \h_laelaps tuning.
152  * \param strXmlFileName XML file path name.
153  *
154  * \copydoc doc_return_std
155  */
156  virtual int saveFile(const LaeTunes &tunes,
157  const std::string &strXmlFileName=LaeEtcTune)
158  {
159  int rc;
160 
161  if( (rc = setDOMFromTunes(tunes)) == LAE_OK )
162  {
163  rc = Xml::saveFile(strXmlFileName);
164  }
165 
166  return rc < 0? -LAE_ECODE_XML: LAE_OK;
167  }
168 
169  /*!
170  * \brief Create a template \h_laelaps XML configuration file.
171  * root element.
172  *
173  * Any current DOM is not accessed nor altered.
174  *
175  * \param strXmlFileName XML file path name.
176  *
177  * \copydoc doc_return_std
178  */
179  virtual int createTemplateFile(const std::string &strXmlFileName =
180  LaeEtcTune);
181 
182  /*!
183  * \brief Set the tune parameters from the parsed DOM.
184  *
185  * \param [out] tunes \h_laelaps tuning.
186  *
187  * \copydoc doc_return_std
188  */
189  virtual int setTunesFromDOM(LaeTunes &tunes);
190 
191  /*!
192  * \brief Set the DOM from the \h_laelaps tune parameters.
193  *
194  * \param [in] tunes \h_laelaps tuning.
195  *
196  * \copydoc doc_return_std
197  */
198  virtual int setDOMFromTunes(const LaeTunes &tunes);
199 
200  protected:
201  // <tuning> ... </tuning>
202  std::string m_strMajElemTuning; ///< major element under 'laelaps'
203  std::string m_strSecElemGlobal; ///< global tuning section element
204  std::string m_strSecElemBattery; ///< battery section element name
205  std::string m_strSecElemPowertrains; ///< powertrain section element name
206  std::string m_strSecElemRangeSensor; ///< range sensor section elem name
207 
208  /*!
209  * \brief Set the global tune parameters from the parsed DOM.
210  *
211  * \param pElemSec Parent enclosing section element.
212  * \param [out] tunes \h_laelaps tuning.
213  *
214  * \copydoc doc_return_std
215  */
216  int setGlobalTunes(TiXmlElement *pElemSec, LaeTunes &tunes);
217 
218  /*!
219  * \brief Set the global threads tune parameters from the parsed DOM.
220  *
221  * \param pElemSubSec Parent enclosing subsection element.
222  * \param [out] tunes \h_laelaps tuning.
223  *
224  * \copydoc doc_return_std
225  */
226  int setGlobalThreadTunes(TiXmlElement *pElemSubSec, LaeTunes &tunes);
227 
228  /*!
229  * \brief Set the global trajectory tune parameters from the parsed DOM.
230  *
231  * \param pElemSubSec Parent enclosing subsection element.
232  * \param [out] tunes \h_laelaps tuning.
233  *
234  * \copydoc doc_return_std
235  */
236  int setGlobalTrajTunes(TiXmlElement *pElemSubSec, LaeTunes &tunes);
237 
238  /*!
239  * \brief Set \h_laelaps battery tune parameters from the parsed DOM.
240  *
241  * \param pElemSec Parent enclosing section element.
242  * \param [out] tunes \h_laelaps tuning.
243  *
244  * \copydoc doc_return_std
245  */
246  virtual int setBatteryTunes(TiXmlElement *pElemSec, LaeTunes &tunes);
247 
248  /*!
249  * \brief Set \h_laelaps powertrain tuning parameters from the parsed DOM.
250  *
251  * \param pElemSec Parent enclosing section element.
252  * \param [out] tunes \h_laelaps tuning.
253  *
254  * \copydoc doc_return_std
255  */
256  virtual int setPowertrainTunes(TiXmlElement *pElemSec, LaeTunes &tunes);
257 
258  /*!
259  * \brief Set a powertrain pair's velocity PID tune parameters from the
260  * parsed DOM.
261  *
262  * \param strLoc Powertrain pair location (and key).
263  * \param pElemSubSec Parent enclosing subsection element.
264  * \param [out] tunes \h_laelaps tuning.
265  *
266  * \copydoc doc_return_std
267  */
268  int setPowertrainVelPidTunes(const std::string &strLoc,
269  TiXmlElement *pElemSubSec,
270  LaeTunes &tunes);
271 
272  /*!
273  * \brief Set a powertrain pair's tire tune parameters from the parsed DOM.
274  *
275  * \param strLoc Powertrain pair location (and key).
276  * \param pElemSubSec Parent enclosing subsection element.
277  * \param [out] tunes \h_laelaps tuning.
278  *
279  * \copydoc doc_return_std
280  */
281  int setPowertrainTireTunes(const std::string &strLoc,
282  TiXmlElement *pElemSubSec,
283  LaeTunes &tunes);
284 
285  /*!
286  * \brief Set \h_laelaps range sensor tuning parameters from DOM.
287  *
288  * \param pElemSec Parent enclosing section element.
289  * \param [out] tunes \h_laelaps tuning.
290  *
291  * \copydoc doc_return_std
292  */
293  virtual int setRangeSensorTunes(TiXmlElement *pElemSec, LaeTunes &tunes);
294 
295  /*!
296  * \brief Set \h_laelaps VL6180 range sensor tuning parameters from DOM.
297  *
298  * \param pElemSec Parent enclosing section element.
299  * \param strAttrType Type of range sensor.
300  * \param strAttrLoc Location of range sensor (key).
301  * \param [out] tunes \h_laelaps tuning.
302  *
303  * \copydoc doc_return_std
304  */
305  int setVL6180Tunes(TiXmlElement *pElemSec,
306  std::string &strAttrType,
307  std::string &strAttrLoc,
308  LaeTunes &tunes);
309 
310  /*!
311  * \brief Convert text to value with a minimum value.
312  *
313  * If the converted value is \h_lt the minimum, it will be set to the
314  * minimum.
315  *
316  * If the text is empty or if a conversion error occurs, the value is not
317  * set.
318  *
319  * \param strElem XML element name.
320  * \param strText XML element text. <elem>TEXT</elem>
321  * \param fMin Minimum value allowed.
322  * \param [out] fVal Converted value.
323  *
324  * \copydoc doc_return_std
325  */
326  int strToDoubleWithMinimum(const std::string &strElem,
327  const std::string &strText,
328  const double fMin,
329  double &fVal);
330 
331  /*!
332  * \brief Convert text to FPN value within minimum,maximum range.
333  *
334  * If the converted value is out of range, it will be set to the appropriate
335  * boundry value.
336  *
337  * If the text is empty or if a conversion error occurs, the value is not
338  * set.
339  *
340  * \param strElem XML element name.
341  * \param strText XML element text. <elem>TEXT</elem>
342  * \param fMin Minimum value allowed.
343  * \param fMax Maximum value allowed.
344  * \param [out] fVal Converted value.
345  *
346  * \copydoc doc_return_std
347  */
348  int strToDoubleWithinRange(const std::string &strElem,
349  const std::string &strText,
350  const double fMin,
351  const double fMax,
352  double &fVal);
353 
354  /*!
355  * \brief Convert text to integer value within minimum,maximum range.
356  *
357  * If the converted value is out of range, it will be set to the appropriate
358  * boundry value.
359  *
360  * If the text is empty or if a conversion error occurs, the value is not
361  * set.
362  *
363  * \param strElem XML element name.
364  * \param strText XML element text. <elem>TEXT</elem>
365  * \param nMin Minimum value allowed.
366  * \param nMax Maximum value allowed.
367  * \param [out] nVal Converted value.
368  *
369  * \copydoc doc_return_std
370  */
371  int strToIntWithinRange(const std::string &strElem,
372  const std::string &strText,
373  const int nMin,
374  const int nMax,
375  int &nVal);
376 
377  /*!
378  * \brief Convert text to norm enum.
379  *
380  * If the text is empty or if a conversion error occurs, the value is not
381  * set.
382  *
383  * \param strElem XML element name.
384  * \param strText XML element text. <elem>TEXT</elem>
385  * \param [out] eNorm Converted value.
386  *
387  * \copydoc doc_return_std
388  */
389  int strToNorm(const std::string &strElem,
390  const std::string &strText,
391  LaeNorm &eNorm);
392 
393 
394  /*!
395  * \brief Warn on unknown element.
396  *
397  * \param strElem Element name.
398  */
399  void warnUnknownElem(const std::string &strElem)
400  {
401  setErrorMsg("%s: Element <%s> unknown - ignoring.",
402  m_strXmlFileName.c_str(), strElem.c_str());
403  LOGWARN("%s", m_bufErrMsg);
404  }
405  };
406 
407 } // laelaps namespace
408 
409 #endif // _LAE_XML_TUNE_H
std::string m_strSecElemRangeSensor
range sensor section elem name
Definition: laeXmlTune.h:206
Laelaps tuning data class.
Definition: laeTune.h:566
LaeXmlTune <b><i>Laelaps</i></b> XML tuning class.
Definition: laeXmlTune.h:71
const char *const LaeEtcTune
xml tune file
Definition: laelaps.h:247
virtual int saveFile(const LaeTunes &tunes, const std::string &strXmlFileName=LaeEtcTune)
Set DOM from <b><i>Laelaps</i></b> tuning parameters and save XML file.
Definition: laeXmlTune.h:156
virtual int loadFile(const std::string &strXmlFileName=LaeEtcTune)
Load XML file into DOM.
Definition: laeXmlTune.cxx:128
int strToDoubleWithMinimum(const std::string &strElem, const std::string &strText, const double fMin, double &fVal)
Convert text to value with a minimum value.
int strToNorm(const std::string &strElem, const std::string &strText, LaeNorm &eNorm)
Convert text to norm enum.
virtual int createTemplateFile(const std::string &strXmlFileName=LaeEtcTune)
Create a template <b><i>Laelaps</i></b> XML configuration file. root element.
Definition: laeXmlTune.cxx:169
int setGlobalThreadTunes(TiXmlElement *pElemSubSec, LaeTunes &tunes)
Set the global threads tune parameters from the parsed DOM.
Definition: laeXmlTune.cxx:393
void warnUnknownElem(const std::string &strElem)
Warn on unknown element.
Definition: laeXmlTune.h:399
int setVL6180Tunes(TiXmlElement *pElemSec, std::string &strAttrType, std::string &strAttrLoc, LaeTunes &tunes)
Set <b><i>Laelaps</i></b> VL6180 range sensor tuning parameters from DOM.
Definition: laeXmlTune.cxx:962
int setPowertrainVelPidTunes(const std::string &strLoc, TiXmlElement *pElemSubSec, LaeTunes &tunes)
Set a powertrain pair&#39;s velocity PID tune parameters from the parsed DOM.
Definition: laeXmlTune.cxx:763
virtual int setTunesFromDOM(LaeTunes &tunes)
Set the tune parameters from the parsed DOM.
Definition: laeXmlTune.cxx:222
const char *const LaeSysCfgPath
System configuration search path.
Definition: laelaps.h:226
virtual int load(LaeTunes &tunes, const std::string &strSearchPath=LaeSysCfgPath, const std::string &strXmlFileName=LaeEtcTune, bool bAllInstances=false)
Load XML file into DOM and set the <b><i>Laelaps</i></b> tuning parameters.
Definition: laeXmlTune.cxx:71
The <b><i>Laelaps</i></b> namespace encapsulates all <b><i>Laelaps</i></b> related constructs...
Definition: laeAlarms.h:64
virtual int setBatteryTunes(TiXmlElement *pElemSec, LaeTunes &tunes)
Set <b><i>Laelaps</i></b> battery tune parameters from the parsed DOM.
Definition: laeXmlTune.cxx:517
const char *const LaeXsiUrl
xml schema instance url
Definition: laelaps.h:275
virtual int setPowertrainTunes(TiXmlElement *pElemSec, LaeTunes &tunes)
Set <b><i>Laelaps</i></b> powertrain tuning parameters from the parsed DOM.
Definition: laeXmlTune.cxx:670
std::string m_strSecElemPowertrains
powertrain section element name
Definition: laeXmlTune.h:205
const char *const LaeXslUrl
xml stylesheet url
Definition: laelaps.h:264
virtual ~LaeXmlTune()
Destructor.
Definition: laeXmlTune.h:90
int strToDoubleWithinRange(const std::string &strElem, const std::string &strText, const double fMin, const double fMax, double &fVal)
Convert text to FPN value within minimum,maximum range.
virtual int setRangeSensorTunes(TiXmlElement *pElemSec, LaeTunes &tunes)
Set <b><i>Laelaps</i></b> range sensor tuning parameters from DOM.
Definition: laeXmlTune.cxx:923
Laelaps tuning.
int setPowertrainTireTunes(const std::string &strLoc, TiXmlElement *pElemSubSec, LaeTunes &tunes)
Set a powertrain pair&#39;s tire tune parameters from the parsed DOM.
Definition: laeXmlTune.cxx:845
int setGlobalTunes(TiXmlElement *pElemSec, LaeTunes &tunes)
Set the global tune parameters from the parsed DOM.
Definition: laeXmlTune.cxx:313
LaeXmlTune()
Default constructor.
Definition: laeXmlTune.h:77
std::string m_strMajElemTuning
major element under &#39;laelaps&#39;
Definition: laeXmlTune.h:202
virtual int saveFile(const std::string &strXmlFileName=LaeEtcTune)
Save DOM to XML file.
Definition: laeXmlTune.h:141
static const int LAE_ECODE_XML
XML error.
Definition: laelaps.h:92
int setGlobalTrajTunes(TiXmlElement *pElemSubSec, LaeTunes &tunes)
Set the global trajectory tune parameters from the parsed DOM.
Definition: laeXmlTune.cxx:454
virtual int setDOMFromTunes(const LaeTunes &tunes)
Set the DOM from the <b><i>Laelaps</i></b> tune parameters.
Definition: laeXmlTune.cxx:302
std::string m_strSecElemBattery
battery section element name
Definition: laeXmlTune.h:204
std::string m_strSecElemGlobal
global tuning section element
Definition: laeXmlTune.h:203
LaeNorm
Length/Distance Norm.
Definition: laelaps.h:356
int strToIntWithinRange(const std::string &strElem, const std::string &strText, const int nMin, const int nMax, int &nVal)
Convert text to integer value within minimum,maximum range.
Top-level package include file.
static const int LAE_OK
not an error, success
Definition: laelaps.h:71