Hekateros  3.4.3
RoadNarrows Robotics Robot Arm Project
hekateros::HekXmlTune Class Reference

HekXmlTune Hekateros XML tuning class. More...

#include <hekXmlTune.h>

Inheritance diagram for hekateros::HekXmlTune:

Public Member Functions

 HekXmlTune ()
 Default constructor.
 
virtual ~HekXmlTune ()
 Destructor.
 
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 Hekateros tuning parameters. More...
 
virtual int loadFile (const std::string &strXmlFileName=HekEtcTune)
 Load XML file into DOM. More...
 
virtual int loadFile (HekTunes &tunes, const std::string &strXmlFileName=HekEtcTune)
 Load XML file into DOM and set the Hekateros tuning parameters. More...
 
virtual int saveFile (const std::string &strXmlFileName=HekEtcTune)
 Save DOM to XML file. More...
 
virtual int saveFile (const HekTunes &tunes, const std::string &strXmlFileName=HekEtcTune)
 Set DOM from Hekateros description and save XML file. More...
 
virtual int createTemplateFile (const std::string &strXmlFileName=HekEtcTune)
 Create a template Hekateros XML configuration file. root element. More...
 
virtual int setTunesFromDOM (HekTunes &tunes)
 Set the tune parameters from the parsed DOM. More...
 
virtual int setDOMFromHekTunes (const HekTunes &tunes)
 Set the DOM from the Hekateros tune parameters. More...
 

Protected Member Functions

int setGlobalTunes (TiXmlElement *pElemSec, HekTunes &tunes)
 Set the global tune parameters from the parsed DOM. More...
 
int setJointTunes (TiXmlElement *pElemSec, HekTunes &tunes)
 Set a joint tune parameters from the parsed DOM. More...
 
int setGlobalTrajTunes (TiXmlElement *pElemSubSec, HekTunes &tunes)
 Set the global trajectory tune parameters from the parsed DOM. More...
 
int setJointPidTunes (const std::string &strJointName, TiXmlElement *pElemSubSec, HekTunesJoint &tunesJoint)
 Set a joint's PID tune parameters from the parsed DOM. More...
 
int strToDoubleWithMinimum (const std::string &strElem, const std::string &strText, const double fMin, double &fVal)
 Convert text to value with a minimum value. More...
 
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. More...
 
int strToNorm (const std::string &strElem, const std::string &strText, HekNorm &eNorm)
 Convert text to norm enum. More...
 
void warnUnknownElem (const std::string &strElem)
 Warn on unknown element. More...
 

Protected Attributes

std::string m_strMajElemTuning
 major element under 'hekateros'
 
std::string m_strSecElemGlobal
 global tuning section element
 
std::string m_strElemKinHz
 kinematics thread hz
 
std::string m_strElemClearTorqueOff
 clear over torque cond. th offset
 
std::string m_strElemVelDerate
 derated velocity
 
std::string m_strSubSecElemTraj
 trajectory subsection
 
std::string m_strElemTrajNorm
 distance norm
 
std::string m_strElemTrajEpsilon
 distance epsilon
 
std::string m_strSecElemJoint
 joint tuning section element.
 
std::string m_strAttrJointId
 joint id attribute name
 
std::string m_strElemTolPos
 position tolerance
 
std::string m_strElemTolVel
 position tolerance
 
std::string m_strElemOverTorqueTh
 over torque condition threshold
 
std::string m_strSubSecElemPid
 pos/vel pid subsection
 
std::string m_strElemPidKp
 pid proportional constant
 
std::string m_strElemPidKi
 pid integral constant
 
std::string m_strElemPidKd
 pid derivative constant
 
std::string m_strElemPidMaxDeltaV
 pid maximum delta v
 

Detailed Description

HekXmlTune Hekateros XML tuning class.

Definition at line 72 of file hekXmlTune.h.

Member Function Documentation

int HekXmlTune::createTemplateFile ( const std::string &  strXmlFileName = HekEtcTune)
virtual

Create a template Hekateros XML configuration file. root element.

Any current DOM is not accessed nor altered.

Parameters
strXmlFileNameXML file path name.
Returns
On success, HEK_OK is returned.
On error, the appropriate < 0 negated Hekateros Error Code is returned.

Definition at line 159 of file hekXmlTune.cxx.

Referenced by saveFile().

160 {
161  FILE *fp; // opened file pointer
162 
163  if( strXmlFileName.empty() )
164  {
165  setErrorMsg("No file name.");
166  LOGERROR("%s", m_bufErrMsg);
167  return -HEK_ECODE_XML;
168  }
169 
170  m_strXmlFileName = strXmlFileName;
171 
172  // open file
173  if( (fp = fopen(m_strXmlFileName.c_str(), "w+")) == NULL )
174  {
175  setErrorMsg("%s: %s(errno=%d).",
176  m_strXmlFileName.c_str(), strerror(errno), errno);
177  LOGERROR("%s", m_bufErrMsg);
178  return -HEK_ECODE_XML;
179  }
180 
181  makeXmlHead();
182  makeXmlTail();
183 
184  //
185  // XML head.
186  //
187  fprintf(fp, " <!-- RoadNarrows Hekateros Tuning Configuration -->\n");
188  fprintf(fp, "%s", m_strXmlHead.c_str());
189 
190  //
191  // Robotic base major element.
192  //
193  fprintf(fp, " <!-- Hekateros tuning -->\n");
194  fprintf(fp, " <%s>\n", m_strMajElemTuning.c_str());
195 
196  fprintf(fp, " <!-- global tunes -->\n");
197  fprintf(fp, " <%s>\n", m_strSecElemGlobal.c_str());
198  fprintf(fp, " <%s>HZ</%s>\n",
199  m_strElemKinHz.c_str(), m_strElemKinHz.c_str());
200  fprintf(fp, " <%s>OFFSET_PCT</%s>\n",
202  fprintf(fp, " <%s>DERATE_PCT</%s>\n",
203  m_strElemVelDerate.c_str(), m_strElemVelDerate.c_str());
204  fprintf(fp, " <%s>\n", m_strSubSecElemTraj.c_str());
205  fprintf(fp, " <%s>NORM</%s>\n",
206  m_strElemTrajNorm.c_str(), m_strElemTrajNorm.c_str());
207  fprintf(fp, " <%s>E_DEG</%s>\n",
208  m_strElemTrajEpsilon.c_str(), m_strElemTrajEpsilon.c_str());
209  fprintf(fp, " </%s>\n", m_strSubSecElemTraj.c_str());
210  fprintf(fp, " </%s>\n", m_strSecElemGlobal.c_str());
211 
212  fprintf(fp, " <!-- joint tunes -->\n");
213  fprintf(fp, " <%s %s=\"JOINT_NAME\">\n",
214  m_strSecElemJoint.c_str(), m_strAttrJointId.c_str());
215  fprintf(fp, " <%s>POS_TOL_DEG</%s>\n",
216  m_strElemTolPos.c_str(), m_strElemTolPos.c_str());
217  fprintf(fp, " <%s>VEL_TOL_DEG_PER_SEC</%s>\n",
218  m_strElemTolVel.c_str(), m_strElemTolVel.c_str());
219  fprintf(fp, " <%s>OVER_TORQUE_TH_PCT</%s>\n",
221  fprintf(fp, " <%s>\n", m_strSubSecElemPid.c_str());
222  fprintf(fp, " <%s>FPN</%s>\n",
223  m_strElemPidKp.c_str(), m_strElemPidKp.c_str());
224  fprintf(fp, " <%s>FPN</%s>\n",
225  m_strElemPidKi.c_str(), m_strElemPidKi.c_str());
226  fprintf(fp, " <%s>FPN</%s>\n",
227  m_strElemPidKd.c_str(), m_strElemPidKd.c_str());
228  fprintf(fp, " <%s>FPN</%s>\n",
230  fprintf(fp, " </%s>\n", m_strSubSecElemPid.c_str());
231  fprintf(fp, " </%s>\n", m_strSecElemJoint.c_str());
232 
233  fprintf(fp, " </%s>\n\n", m_strMajElemTuning.c_str());
234 
235  //
236  // XML tail
237  //
238  fprintf(fp, "%s", m_strXmlTail.c_str());
239 
240  fclose(fp);
241 
242  LOGDIAG3("Created file %s.", m_strXmlFileName.c_str());
243 
244  return HEK_OK;
245 }
std::string m_strElemPidKd
pid derivative constant
Definition: hekXmlTune.h:245
static const int HEK_OK
not an error, success
Definition: hekateros.h:70
std::string m_strElemTrajNorm
distance norm
Definition: hekXmlTune.h:234
std::string m_strSecElemJoint
joint tuning section element.
Definition: hekXmlTune.h:237
std::string m_strMajElemTuning
major element under &#39;hekateros&#39;
Definition: hekXmlTune.h:227
std::string m_strAttrJointId
joint id attribute name
Definition: hekXmlTune.h:238
std::string m_strElemOverTorqueTh
over torque condition threshold
Definition: hekXmlTune.h:241
std::string m_strElemTolVel
position tolerance
Definition: hekXmlTune.h:240
std::string m_strElemPidMaxDeltaV
pid maximum delta v
Definition: hekXmlTune.h:246
std::string m_strElemTolPos
position tolerance
Definition: hekXmlTune.h:239
static const int HEK_ECODE_XML
XML error.
Definition: hekateros.h:91
std::string m_strElemVelDerate
derated velocity
Definition: hekXmlTune.h:232
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
std::string m_strSubSecElemPid
pos/vel pid subsection
Definition: hekXmlTune.h:242
std::string m_strElemPidKp
pid proportional constant
Definition: hekXmlTune.h:243
std::string m_strElemPidKi
pid integral constant
Definition: hekXmlTune.h:244
std::string m_strElemTrajEpsilon
distance epsilon
Definition: hekXmlTune.h:235
int HekXmlTune::load ( HekTunes tunes,
const std::string &  strSearchPath = HekSysCfgPath,
const std::string &  strXmlFileName = HekEtcTune,
bool  bAllInstances = false 
)
virtual

Load XML file into DOM and set the Hekateros tuning parameters.

Parameters
[out]tunes

Definition at line 72 of file hekXmlTune.cxx.

References hekateros::split().

Referenced by hekateros::HekRobot::connect(), hekateros::HekRobot::reload(), and ~HekXmlTune().

76 {
77  vector<string> vecPath; // vector of search paths
78  string fqname; // fully qualified file name
79  bool bFoundInstance; // [not] found instance
80  size_t i; // working index
81  int rc; // return code
82 
83  split(strSearchPath, ':', vecPath);
84 
85  bFoundInstance = false;
86  rc = HEK_OK;
87 
88  for(i=0; i<vecPath.size(); ++i)
89  {
90  fqname = vecPath[i] + '/' + strXmlFileName;
91  if( access(fqname.c_str(), F_OK) == 0 )
92  {
93  LOGDIAG3("Loading tune XML file: %s.", fqname.c_str());
94 
95  bFoundInstance = true;
96 
97  if( (rc = Xml::loadFile(fqname)) < 0 )
98  {
99  LOGERROR("Parse of tune parameters from XML file %s failed.",
100  fqname.c_str());
101  rc = -HEK_ECODE_XML;
102  }
103  else
104  {
105  rc = setTunesFromDOM(tunes);
106  }
107 
108  if( rc == HEK_OK )
109  {
110  LOGDIAG2("Tuning parameters from XML file %s loaded.",
111  fqname.c_str());
112  }
113 
114  if( !bAllInstances )
115  {
116  break;
117  }
118  }
119  }
120 
121  if( !bFoundInstance )
122  {
123  LOGDIAG2("Optional XML file %s not found - ignoring.",
124  strXmlFileName.c_str());
125  }
126 
127  return rc;
128 }
static const int HEK_OK
not an error, success
Definition: hekateros.h:70
static const int HEK_ECODE_XML
XML error.
Definition: hekateros.h:91
std::vector< std::string > & split(const std::string &s, char delim, std::vector< std::string > &elems)
Split string at the delimiter character.
virtual int setTunesFromDOM(HekTunes &tunes)
Set the tune parameters from the parsed DOM.
Definition: hekXmlTune.cxx:247
int HekXmlTune::loadFile ( const std::string &  strXmlFileName = HekEtcTune)
virtual

Load XML file into DOM.

Parameters
strXmlFileNameXML file path name.
Returns
On success, HEK_OK is returned.
On error, the appropriate < 0 negated Hekateros Error Code is returned.

Definition at line 130 of file hekXmlTune.cxx.

Referenced by loadFile(), and ~HekXmlTune().

131 {
132  int rc;
133 
134  // test existence of optional tuning file
135  if( access(strXmlFileName.c_str(), F_OK) < 0 )
136  {
137  LOGDIAG2("Optional XML file %s does not exist - ignoring.",
138  strXmlFileName.c_str());
139  rc = -HEK_ECODE_XML;
140  }
141 
142  // parse
143  else if( (rc = Xml::loadFile(strXmlFileName)) < 0 )
144  {
145  LOGERROR("Parse of tune parameters from XML file %s failed - ignoring.",
146  strXmlFileName.c_str());
147  rc = -HEK_ECODE_XML;
148  }
149 
150  // success
151  else
152  {
153  rc = HEK_OK;
154  }
155 
156  return rc;
157 }
static const int HEK_OK
not an error, success
Definition: hekateros.h:70
static const int HEK_ECODE_XML
XML error.
Definition: hekateros.h:91
virtual int hekateros::HekXmlTune::loadFile ( HekTunes tunes,
const std::string &  strXmlFileName = HekEtcTune 
)
inlinevirtual

Load XML file into DOM and set the Hekateros tuning parameters.

Parameters
[out]tunes

Definition at line 147 of file hekXmlTune.h.

References hekateros::HEK_ECODE_XML, hekateros::HEK_OK, loadFile(), and setTunesFromDOM().

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  }
static const int HEK_OK
not an error, success
Definition: hekateros.h:70
virtual int loadFile(const std::string &strXmlFileName=HekEtcTune)
Load XML file into DOM.
Definition: hekXmlTune.cxx:130
static const int HEK_ECODE_XML
XML error.
Definition: hekateros.h:91
virtual int setTunesFromDOM(HekTunes &tunes)
Set the tune parameters from the parsed DOM.
Definition: hekXmlTune.cxx:247
virtual int hekateros::HekXmlTune::saveFile ( const std::string &  strXmlFileName = HekEtcTune)
inlinevirtual

Save DOM to XML file.

Parameters
strXmlFileNameXML file path name.
Returns
On success, HEK_OK is returned.
On error, the appropriate < 0 negated Hekateros Error Code is returned.

Definition at line 167 of file hekXmlTune.h.

References hekateros::HEK_ECODE_XML, and hekateros::HEK_OK.

168  {
169  int rc = Xml::saveFile(strXmlFileName);
170 
171  return rc < 0? -HEK_ECODE_XML: HEK_OK;
172  }
static const int HEK_OK
not an error, success
Definition: hekateros.h:70
static const int HEK_ECODE_XML
XML error.
Definition: hekateros.h:91
virtual int hekateros::HekXmlTune::saveFile ( const HekTunes tunes,
const std::string &  strXmlFileName = HekEtcTune 
)
inlinevirtual

Set DOM from Hekateros description and save XML file.

Parameters
[in]tunes

Definition at line 182 of file hekXmlTune.h.

References createTemplateFile(), hekateros::HEK_ECODE_XML, hekateros::HEK_OK, hekateros::HekEtcTune, setDOMFromHekTunes(), and setTunesFromDOM().

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  }
static const int HEK_OK
not an error, success
Definition: hekateros.h:70
static const int HEK_ECODE_XML
XML error.
Definition: hekateros.h:91
virtual int setDOMFromHekTunes(const HekTunes &tunes)
Set the DOM from the <b><i>Hekateros</i></b> tune parameters.
Definition: hekXmlTune.cxx:313
int HekXmlTune::setDOMFromHekTunes ( const HekTunes tunes)
virtual

Set the DOM from the Hekateros tune parameters.

Parameters
[in]tunes

Definition at line 313 of file hekXmlTune.cxx.

Referenced by saveFile().

314 {
315  // TODO
316  return -HEK_ECODE_GEN;
317 }
static const int HEK_ECODE_GEN
general, unspecified error
Definition: hekateros.h:72
int HekXmlTune::setGlobalTrajTunes ( TiXmlElement *  pElemSubSec,
HekTunes tunes 
)
protected

Set the global trajectory tune parameters from the parsed DOM.

Parameters
pElemSubSecParent enclosing subsection element.
[out]tunes

Definition at line 501 of file hekXmlTune.cxx.

References hekateros::degToRad(), hekateros::HekTunes::m_eTrajNorm, and hekateros::HekTunes::m_fTrajEpsilon.

502 {
503  TiXmlElement *pElem; // working xml element
504  const char *sValue; // working xml element name
505  int rc; // return code
506 
507  //
508  // Walk through child elements and convert.
509  //
510  for(pElem = pElemSubSec->FirstChildElement(), rc = HEK_OK;
511  (pElem != NULL) && (rc == HEK_OK);
512  pElem = pElem->NextSiblingElement())
513  {
514  // element name
515  if( (sValue = pElem->Value()) == NULL )
516  {
517  continue;
518  }
519 
520  // norm
521  else if( !strcasecmp(sValue, m_strElemTrajNorm.c_str()) )
522  {
523  strToNorm(m_strElemTrajNorm, elemText(pElem), tunes.m_eTrajNorm);
524  }
525 
526  // epsilon
527  else if( !strcasecmp(sValue, m_strElemTrajEpsilon.c_str()) )
528  {
529  rc = strToDoubleWithMinimum(m_strElemTrajEpsilon, elemText(pElem),
531 
532  // xml units are degrees - convert to radians
533  if( rc == HEK_OK )
534  {
535  tunes.m_fTrajEpsilon = degToRad(tunes.m_fTrajEpsilon);
536  }
537  }
538 
539  // unknown
540  else
541  {
542  warnUnknownElem(sValue);
543  }
544  }
545 
546  if( rc == HEK_OK )
547  {
548  LOGDIAG3("%s: Hekateros global trajectory tune parameters set.",
549  m_strXmlFileName.c_str());
550  }
551 
552  return rc;
553 }
static const double HekTuneTrajEpsilonMin
Minimum epsilon value.
Definition: hekTune.h:353
static const int HEK_OK
not an error, success
Definition: hekateros.h:70
std::string m_strElemTrajNorm
distance norm
Definition: hekXmlTune.h:234
int strToNorm(const std::string &strElem, const std::string &strText, HekNorm &eNorm)
Convert text to norm enum.
Definition: hekXmlTune.cxx:694
double m_fTrajEpsilon
trajectory epsilon distance (radians)
Definition: hekTune.h:419
void warnUnknownElem(const std::string &strElem)
Warn on unknown element.
Definition: hekXmlTune.h:357
HekNorm m_eTrajNorm
trajectory distanct norm
Definition: hekTune.h:418
double degToRad(double d)
Convert degrees to radians.
Definition: hekUtils.h:125
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
int HekXmlTune::setGlobalTunes ( TiXmlElement *  pElemSec,
HekTunes tunes 
)
protected

Set the global tune parameters from the parsed DOM.

Parameters
pElemSecParent enclosing section element.
[out]tunes

Definition at line 319 of file hekXmlTune.cxx.

References hekateros::HekTunes::m_fClearTorqueOffset, hekateros::HekTunes::m_fKinematicsHz, and hekateros::HekTunes::m_fVelDerate.

320 {
321  TiXmlElement *pElem; // working xml element
322  const char *sValue; // working xml element name
323  int rc; // return code
324 
325  //
326  // Walk through child elements and convert.
327  //
328  for(pElem = pElemSec->FirstChildElement(), rc = HEK_OK;
329  (pElem != NULL) && (rc == HEK_OK);
330  pElem = pElem->NextSiblingElement())
331  {
332  // element name
333  if( (sValue = pElem->Value()) == NULL )
334  {
335  continue;
336  }
337 
338  // kinematic hz
339  else if( !strcasecmp(sValue, m_strElemKinHz.c_str()) )
340  {
341  rc = strToDoubleWithMinimum(m_strElemKinHz, elemText(pElem),
343  }
344 
345  // clear over torque condition threshold offset
346  else if( !strcasecmp(sValue, m_strElemClearTorqueOff.c_str()) )
347  {
348  rc = strToDoubleWithinRange(m_strElemClearTorqueOff, elemText(pElem),
350  tunes.m_fClearTorqueOffset);
351 
352  // xml units are percentages - normalize
353  if( rc == HEK_OK )
354  {
355  tunes.m_fClearTorqueOffset /= 100.0;
356  }
357  }
358 
359  // velocity derate
360  else if( !strcasecmp(sValue, m_strElemVelDerate.c_str()) )
361  {
362  rc = strToDoubleWithinRange(m_strElemVelDerate, elemText(pElem),
364  tunes.m_fVelDerate);
365 
366  // xml units are percentages - normalize
367  if( rc == HEK_OK )
368  {
369  tunes.m_fVelDerate /= 100.0;
370  }
371  }
372 
373  // trajectory tune parameters
374  else if( !strcasecmp(sValue, m_strSubSecElemTraj.c_str()) )
375  {
376  rc = setGlobalTrajTunes(pElem, tunes);
377  }
378 
379  // unknown
380  else
381  {
382  warnUnknownElem(sValue);
383  }
384  }
385 
386  if( rc == HEK_OK )
387  {
388  LOGDIAG3("%s: Hekateros global tune parameters set.",
389  m_strXmlFileName.c_str());
390  }
391 
392  return rc;
393 }
static const int HEK_OK
not an error, success
Definition: hekateros.h:70
double m_fVelDerate
velocity derate (fraction)
Definition: hekTune.h:417
static const double HekTuneKinHzMin
Minimum kinematics thread cycle rate (Hertz).
Definition: hekTune.h:100
int setGlobalTrajTunes(TiXmlElement *pElemSubSec, HekTunes &tunes)
Set the global trajectory tune parameters from the parsed DOM.
Definition: hekXmlTune.cxx:501
double m_fKinematicsHz
kinematic thread rate (hertz)
Definition: hekTune.h:415
static const double HekTuneClearTorqueOffsetMax
Maximum clear torque condition hysteresis threshhold offset (% of over torque threshold).
Definition: hekTune.h:184
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_strElemClearTorqueOff
clear over torque cond. th offset
Definition: hekXmlTune.h:231
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
static const double HekTuneVelDerateMin
Minimum robot velocity derate (% of goal velocities).
Definition: hekTune.h:211
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
double m_fClearTorqueOffset
clear over torque condition offset (frac)
Definition: hekTune.h:416
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
int HekXmlTune::setJointPidTunes ( const std::string &  strJointName,
TiXmlElement *  pElemSubSec,
HekTunesJoint tunesJoint 
)
protected

Set a joint's PID tune parameters from the parsed DOM.

Parameters
strJointNameJoint name.
pElemSubSecParent enclosing subsection element.
[out]tunesJoint

Definition at line 555 of file hekXmlTune.cxx.

References hekateros::degToRad(), hekateros::HekTunesJoint::m_fPidKd, hekateros::HekTunesJoint::m_fPidKi, hekateros::HekTunesJoint::m_fPidKp, and hekateros::HekTunesJoint::m_fPidMaxDeltaV.

558 {
559  TiXmlElement *pElem; // working xml element
560  const char *sValue; // working xml element name
561  int rc; // return code
562 
563  //
564  // Walk through child elements and convert.
565  //
566  for(pElem = pElemSubSec->FirstChildElement(), rc = HEK_OK;
567  (pElem != NULL) && (rc == HEK_OK);
568  pElem = pElem->NextSiblingElement())
569  {
570  // element name
571  if( (sValue = pElem->Value()) == NULL )
572  {
573  continue;
574  }
575 
576  // Kp
577  else if( !strcasecmp(sValue, m_strElemPidKp.c_str()) )
578  {
579  rc = strToDoubleWithMinimum(m_strElemPidKp, elemText(pElem),
580  HekTunePidKMin, tunesJoint.m_fPidKp);
581  }
582 
583  // Ki
584  else if( !strcasecmp(sValue, m_strElemPidKi.c_str()) )
585  {
586  rc = strToDoubleWithMinimum(m_strElemPidKi, elemText(pElem),
587  HekTunePidKMin, tunesJoint.m_fPidKi);
588  }
589 
590  // Kd
591  else if( !strcasecmp(sValue, m_strElemPidKd.c_str()) )
592  {
593  rc = strToDoubleWithMinimum(m_strElemPidKd, elemText(pElem),
594  HekTunePidKMin, tunesJoint.m_fPidKd);
595  }
596 
597  // max_delta_v
598  else if( !strcasecmp(sValue, m_strElemPidMaxDeltaV.c_str()) )
599  {
600  rc = strToDoubleWithMinimum(m_strElemPidMaxDeltaV, elemText(pElem),
602  tunesJoint.m_fPidMaxDeltaV);
603 
604  // xml units are degrees - convert to radians
605  if( rc == HEK_OK )
606  {
607  tunesJoint.m_fPidMaxDeltaV = degToRad(tunesJoint.m_fPidMaxDeltaV);
608  }
609  }
610 
611  // unknown
612  else
613  {
614  warnUnknownElem(sValue);
615  }
616  }
617 
618  if( rc == HEK_OK )
619  {
620  LOGDIAG3("%s: Hekateros joint %s PID tune parameters set.",
621  m_strXmlFileName.c_str(), strJointName.c_str());
622  }
623 
624  return rc;
625 }
std::string m_strElemPidKd
pid derivative constant
Definition: hekXmlTune.h:245
double m_fPidKi
position and velocity PID integral constant
Definition: hekTune.h:373
static const int HEK_OK
not an error, success
Definition: hekateros.h:70
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
std::string m_strElemPidMaxDeltaV
pid maximum delta v
Definition: hekXmlTune.h:246
void warnUnknownElem(const std::string &strElem)
Warn on unknown element.
Definition: hekXmlTune.h:357
double m_fPidKd
position and velocity PID derivative constant
Definition: hekTune.h:374
double m_fPidMaxDeltaV
max output delta v (radians/second)
Definition: hekTune.h:375
double degToRad(double d)
Convert degrees to radians.
Definition: hekUtils.h:125
std::string m_strElemPidKp
pid proportional constant
Definition: hekXmlTune.h:243
static const double HekTunePidKMin
Minimum PID K constant value.
Definition: hekTune.h:306
std::string m_strElemPidKi
pid integral constant
Definition: hekXmlTune.h:244
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
int HekXmlTune::setJointTunes ( TiXmlElement *  pElemSec,
HekTunes tunes 
)
protected

Set a joint tune parameters from the parsed DOM.

Parameters
pElemSecParent enclosing section element.
[out]tunes

Definition at line 395 of file hekXmlTune.cxx.

References hekateros::degToRad(), hekateros::HekTunesJoint::m_fOverTorqueTh, hekateros::HekTunesJoint::m_fTolPos, hekateros::HekTunesJoint::m_fTolVel, and hekateros::HekTunes::m_mapJointTunes.

396 {
397  string strJointName; // joint name
398  HekTunesJoint tunesJoint; // initialzed with default defaults
399  TiXmlElement *pElem; // working xml element
400  const char *sValue; // working xml element name
401  int rc; // return code
402 
403  strJointName = elemAttr(pElemSec, m_strAttrJointId);
404 
405  if( strJointName.empty() )
406  {
407  setErrorMsg("%s: No %s attribute of <%s> found.",
408  m_strXmlFileName.c_str(),
409  m_strAttrJointId.c_str(),
410  m_strSecElemJoint.c_str());
411  LOGERROR("%s", m_bufErrMsg);
412  return -HEK_ECODE_XML;
413  }
414 
415  // joint tuning entry already present - use as the starting tuning values
416  if( tunes.m_mapJointTunes.find(strJointName) != tunes.m_mapJointTunes.end() )
417  {
418  tunesJoint = tunes.m_mapJointTunes[strJointName];
419  }
420 
421  //
422  // Walk through child elements and convert.
423  //
424  for(pElem = pElemSec->FirstChildElement(), rc = HEK_OK;
425  (pElem != NULL) && (rc == HEK_OK);
426  pElem = pElem->NextSiblingElement())
427  {
428  // element name
429  if( (sValue = pElem->Value()) == NULL )
430  {
431  continue;
432  }
433 
434  // position tolerance
435  else if( !strcasecmp(sValue, m_strElemTolPos.c_str()) )
436  {
437  rc = strToDoubleWithMinimum(m_strElemTolPos, elemText(pElem),
439  tunesJoint.m_fTolPos);
440 
441  // xml units are degrees - convert to radians
442  if( rc == HEK_OK )
443  {
444  tunesJoint.m_fTolPos = degToRad(tunesJoint.m_fTolPos);
445  }
446  }
447 
448  // velocity tolerance
449  else if( !strcasecmp(sValue, m_strElemTolVel.c_str()) )
450  {
451  rc = strToDoubleWithMinimum(m_strElemTolVel, elemText(pElem),
453  tunesJoint.m_fTolVel);
454 
455  // xml units are degrees/second - convert to radians/second
456  if( rc == HEK_OK )
457  {
458  tunesJoint.m_fTolVel = degToRad(tunesJoint.m_fTolVel);
459  }
460  }
461 
462  // over torque threshold
463  else if( !strcasecmp(sValue, m_strElemOverTorqueTh.c_str()) )
464  {
465  rc = strToDoubleWithinRange(m_strElemOverTorqueTh, elemText(pElem),
467  tunesJoint.m_fOverTorqueTh);
468 
469  // xml units are percentages - normalize
470  if( rc == HEK_OK )
471  {
472  tunesJoint.m_fOverTorqueTh /= 100.0;
473  }
474  }
475 
476  // position and velocity PID tune parameters
477  else if( !strcasecmp(sValue, m_strSubSecElemPid.c_str()) )
478  {
479  rc = setJointPidTunes(strJointName, pElem, tunesJoint);
480  }
481 
482  // unknown
483  else
484  {
485  warnUnknownElem(sValue);
486  }
487  }
488 
489  if( rc == HEK_OK )
490  {
491  // add new joint tuning or overwrite existing
492  tunes.m_mapJointTunes[strJointName] = tunesJoint;
493 
494  LOGDIAG3("%s: Hekateros joint %s tune parameters set.",
495  m_strXmlFileName.c_str(), strJointName.c_str());
496  }
497 
498  return rc;
499 }
static const double HekTuneTolVelMin
Minimum joint velocition control tolerance (degrees/second).
Definition: hekTune.h:273
static const double HekTuneTolPosMin
Minimum joint position control tolerance (degrees).
Definition: hekTune.h:244
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_strSecElemJoint
joint tuning section element.
Definition: hekXmlTune.h:237
double m_fTolVel
velocitiy tolerance (radians/second)
Definition: hekTune.h:371
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
std::string m_strElemTolVel
position tolerance
Definition: hekXmlTune.h:240
std::string m_strElemTolPos
position tolerance
Definition: hekXmlTune.h:239
double m_fOverTorqueTh
over torque conditon threshold (fraction)
Definition: hekTune.h:376
static const int HEK_ECODE_XML
XML error.
Definition: hekateros.h:91
void warnUnknownElem(const std::string &strElem)
Warn on unknown element.
Definition: hekXmlTune.h:357
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
double degToRad(double d)
Convert degrees to radians.
Definition: hekUtils.h:125
static const double HekTuneOverTorqueThMin
Minimum joint over torque threshold (% of maximum)
Definition: hekTune.h:143
MapJointTunes m_mapJointTunes
per joint tuning
Definition: hekTune.h:422
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
static const double HekTuneOverTorqueThMax
Maximum joint over torque threshold (% of maximum)
Definition: hekTune.h:148
double m_fTolPos
position tolerance (radians)
Definition: hekTune.h:370
int HekXmlTune::setTunesFromDOM ( HekTunes tunes)
virtual

Set the tune parameters from the parsed DOM.

Parameters
[out]tunes

Definition at line 247 of file hekXmlTune.cxx.

Referenced by loadFile(), and saveFile().

248 {
249  TiXmlElement *pElem1, *pElem2; // working xml elements
250  const char *sValue; // working xml element name
251  int rc; // return code
252 
253  // root element
254  if( m_pElemRoot == NULL )
255  {
256  setErrorMsg("Missing DOM and/or <%s> root element missing.",
257  m_strRootElemName.c_str());
258  LOGERROR("%s", m_bufErrMsg);
259  return -HEK_ECODE_XML;
260  }
261 
262  // search for major element
263  for(pElem1 = m_pElemRoot->FirstChildElement(), rc = HEK_OK;
264  (pElem1 != NULL) && (rc == HEK_OK);
265  pElem1 = pElem1->NextSiblingElement())
266  {
267  // element name
268  if( (sValue = pElem1->Value()) == NULL )
269  {
270  continue;
271  }
272 
273  //
274  // Tuning major element. Walk through child elements and convert.
275  //
276  else if( !strcasecmp(sValue, m_strMajElemTuning.c_str()) )
277  {
278  // search for section elements
279  for(pElem2 = pElem1->FirstChildElement();
280  (pElem2 != NULL) && (rc == HEK_OK);
281  pElem2 = pElem2->NextSiblingElement())
282  {
283  // child element name
284  if( (sValue = pElem2->Value()) == NULL )
285  {
286  continue;
287  }
288 
289  // global tuning section
290  else if( !strcasecmp(sValue, m_strSecElemGlobal.c_str()) )
291  {
292  rc = setGlobalTunes(pElem2, tunes);
293  }
294 
295  // joint X tuning section
296  else if( !strcasecmp(sValue, m_strSecElemJoint.c_str()) )
297  {
298  rc = setJointTunes(pElem2, tunes);
299  }
300 
301  // unknown
302  else
303  {
304  warnUnknownElem(sValue);
305  }
306  }
307  }
308  }
309 
310  return HEK_OK;
311 }
static const int HEK_OK
not an error, success
Definition: hekateros.h:70
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
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
void warnUnknownElem(const std::string &strElem)
Warn on unknown element.
Definition: hekXmlTune.h:357
std::string m_strSecElemGlobal
global tuning section element
Definition: hekXmlTune.h:229
int HekXmlTune::strToDoubleWithinRange ( const std::string &  strElem,
const std::string &  strText,
const double  fMin,
const double  fMax,
double &  fVal 
)
protected

Convert text to value within minimum,maximum range.

If the converted value is out of range, it will be set to the appropriate boundry value.

If the text is empty or if a conversion error occurs, the value is not set.

Parameters
strElemXML element name.
strTextXML element text. <elem>TEXT</elem>
fMinMinimum value allowed.
fMaxMaximum value allowed.
[out]fValConverted value.
Returns
On success, HEK_OK is returned.
On error, the appropriate < 0 negated Hekateros Error Code is returned.

Definition at line 656 of file hekXmlTune.cxx.

661 {
662  int rc = HEK_OK; // return code
663 
664  if( !strText.empty() )
665  {
666  if( (rc = strToDouble(strText, fVal)) < 0 )
667  {
668  setErrorMsg("%s: Element <%s> text \"%s\" not a FPN.",
669  m_strXmlFileName.c_str(), strElem.c_str(), strText.c_str());
670  LOGERROR("%s", m_bufErrMsg);
671  rc = -HEK_ECODE_XML;
672  }
673 
674  else if( fVal < fMin )
675  {
676  setErrorMsg("%s: Element <%s> value %lf < than minimum of %lf.",
677  m_strXmlFileName.c_str(), strElem.c_str(), fVal, fMin);
678  LOGWARN("%s", m_bufErrMsg);
679  fVal = fMin;
680  }
681 
682  else if( fVal > fMax )
683  {
684  setErrorMsg("%s: Element <%s> value %lf > than maximum of %lf.",
685  m_strXmlFileName.c_str(), strElem.c_str(), fVal, fMax);
686  LOGWARN("%s", m_bufErrMsg);
687  fVal = fMax;
688  }
689  }
690 
691  return rc;
692 }
static const int HEK_OK
not an error, success
Definition: hekateros.h:70
static const int HEK_ECODE_XML
XML error.
Definition: hekateros.h:91
int HekXmlTune::strToDoubleWithMinimum ( const std::string &  strElem,
const std::string &  strText,
const double  fMin,
double &  fVal 
)
protected

Convert text to value with a minimum value.

If the converted value is < the minimum, it will be set to the minimum.

If the text is empty or if a conversion error occurs, the value is not set.

Parameters
strElemXML element name.
strTextXML element text. <elem>TEXT</elem>
fMinMinimum value allowed.
[out]fValConverted value.
Returns
On success, HEK_OK is returned.
On error, the appropriate < 0 negated Hekateros Error Code is returned.

Definition at line 627 of file hekXmlTune.cxx.

631 {
632  int rc = HEK_OK; // return code
633 
634  if( !strText.empty() )
635  {
636  if( (rc = strToDouble(strText, fVal)) < 0 )
637  {
638  setErrorMsg("%s: Element <%s> text \"%s\" not a FPN.",
639  m_strXmlFileName.c_str(), strElem.c_str(), strText.c_str());
640  LOGERROR("%s", m_bufErrMsg);
641  rc = -HEK_ECODE_XML;
642  }
643 
644  else if( fVal < fMin )
645  {
646  setErrorMsg("%s: Element <%s> value %lf < than minimum of %lf.",
647  m_strXmlFileName.c_str(), strElem.c_str(), fVal, fMin);
648  LOGWARN("%s", m_bufErrMsg);
649  fVal = fMin;
650  }
651  }
652 
653  return rc;
654 }
static const int HEK_OK
not an error, success
Definition: hekateros.h:70
static const int HEK_ECODE_XML
XML error.
Definition: hekateros.h:91
int HekXmlTune::strToNorm ( const std::string &  strElem,
const std::string &  strText,
HekNorm eNorm 
)
protected

Convert text to norm enum.

If the text is empty or if a conversion error occurs, the value is not set.

Parameters
strElemXML element name.
strTextXML element text. <elem>TEXT</elem>
[out]eNormConverted value.
Returns
On success, HEK_OK is returned.
On error, the appropriate < 0 negated Hekateros Error Code is returned.

Definition at line 694 of file hekXmlTune.cxx.

697 {
698  if( strText.empty() )
699  {
700  return HEK_OK;
701  }
702  else if( !strcasecmp(strText.c_str(), "L1") )
703  {
704  eNorm = HekNormL1;
705  return HEK_OK;
706  }
707  else if( !strcasecmp(strText.c_str(), "L2") )
708  {
709  eNorm = HekNormL2;
710  return HEK_OK;
711  }
712  else if( !strcasecmp(strText.c_str(), "Linf") )
713  {
714  eNorm = HekNormLinf;
715  return HEK_OK;
716  }
717  else
718  {
719  setErrorMsg("%s: Element <%s> text \"%s\" not a recognized norm.",
720  m_strXmlFileName.c_str(), strElem.c_str(), strText.c_str());
721  LOGERROR("%s", m_bufErrMsg);
722  return -HEK_ECODE_XML;
723  }
724 }
static const int HEK_OK
not an error, success
Definition: hekateros.h:70
L2 norm (Euclidean norm)
Definition: hekateros.h:538
static const int HEK_ECODE_XML
XML error.
Definition: hekateros.h:91
Linf norm (maximum, infinity, or supremum norm)
Definition: hekateros.h:539
L1 norm (taxicab or manhattan norm)
Definition: hekateros.h:537
void hekateros::HekXmlTune::warnUnknownElem ( const std::string &  strElem)
inlineprotected

Warn on unknown element.

Parameters
strElemElement name.

Definition at line 357 of file hekXmlTune.h.

358  {
359  setErrorMsg("%s: Element <%s> unknown - ignoring.",
360  m_strXmlFileName.c_str(), strElem.c_str());
361  LOGWARN("%s", m_bufErrMsg);
362  }

The documentation for this class was generated from the following files: