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

Joint velocity/ servo speed lookup table class. More...

#include <hekKinJoint.h>

Public Types

typedef std::vector< VelSpeedTupleVelSpeedTbl
 Velocity-speed table type.
 

Public Member Functions

 VelSpeedLookupTbl ()
 Default constructor.
 
 ~VelSpeedLookupTbl ()
 Destructor.
 
VelSpeedLookupTbl operator= (const VelSpeedLookupTbl &rhs)
 Assignment operator. More...
 
void create (double fJointMaxVel, double fBucketSize)
 Create lookup table. More...
 
int hash (double fJointVel)
 Hash joint velocity to table index. More...
 
void update (double fJointVel, int nServoSpeed)
 Update lookup table entry. More...
 
int estimate (double fJointGoalVel)
 Estimate servo goal speed. More...
 
int getLookupTableSize ()
 Get the lookup table fixed size. More...
 
int getNumLookupTableEntries ()
 Get the number of populated entries in lookup table. More...
 
void enableDebugging (const std::string &strId)
 Enable table debugging. More...
 
void disableDebugging ()
 Disable table debugging.
 
void dumpTable (const std::string &strId)
 Dump lookup table entries. More...
 

Static Public Attributes

static const int NO_ENTRY = -1
 No table entry value.
 
static const int MIN_NON_ZERO_SPEED = 10
 Minimum servo speed for non-zero velocities.
 

Protected Attributes

double m_fBucketSize
 table entry size (degrees/second)
 
int m_nMaxIndex
 maximum index into table
 
int m_nNumEntries
 number of populated table entries.
 
VelSpeedTbl m_tbl
 dynamic interpolation table
 
std::string m_strDbgId
 debugging id
 
bool m_bDbg
 enable [disable] debugging
 

Detailed Description

Joint velocity/ servo speed lookup table class.

A table of associated joint velocities to servo speed is dynamically built and updated to provide:

  • Good estimates of servo speed given the goal velocity through linear interpolation.
  • Adaptive kinodynamics.

Definition at line 249 of file hekKinJoint.h.

Member Function Documentation

void VelSpeedLookupTbl::create ( double  fJointMaxVel,
double  fBucketSize 
)

Create lookup table.

Parameters
fJointMaxVelJoint maximum velocity (radians/second).
fBucketSizeTable bucket size (radians/second).

Definition at line 197 of file hekKinJoint.cxx.

Referenced by hekateros::HekKinJoint::HekKinJoint().

198 {
199  size_t nElems;
200  VelSpeedTuple noentry(0.0, NO_ENTRY);
201 
202  fJointMaxVel = fabs(fJointMaxVel);
203  m_fBucketSize = fabs(fBucketSize);
204 
205  nElems = (int)(fJointMaxVel / m_fBucketSize);
206  if( (double)nElems * m_fBucketSize < fJointMaxVel )
207  {
208  ++nElems; // round up
209  }
210  ++nElems; // include zero entry
211 
212  m_tbl.insert(m_tbl.begin(), nElems, noentry);
213 
214  m_nMaxIndex = (int)m_tbl.size() - 1;
215 
216  m_tbl[0] = VelSpeedTuple(0.0, 0);
217  m_tbl[m_nMaxIndex] = VelSpeedTuple(fJointMaxVel, DYNA_SPEED_MAX_RAW);
218 
219  m_nNumEntries = 2;
220 
221  if( m_bDbg )
222  {
223  fprintf(stderr, "DBG: %s(): %s: tbl_size=%zu, num_entries=%d\n",
224  LOGFUNCNAME,
225  m_strDbgId.c_str(), m_tbl.size(), m_nNumEntries);
226  }
227 }
VelSpeedTbl m_tbl
dynamic interpolation table
Definition: hekKinJoint.h:366
static const int NO_ENTRY
No table entry value.
Definition: hekKinJoint.h:256
int m_nNumEntries
number of populated table entries.
Definition: hekKinJoint.h:365
int m_nMaxIndex
maximum index into table
Definition: hekKinJoint.h:364
std::string m_strDbgId
debugging id
Definition: hekKinJoint.h:367
double m_fBucketSize
table entry size (degrees/second)
Definition: hekKinJoint.h:363
bool m_bDbg
enable [disable] debugging
Definition: hekKinJoint.h:368
Joint velocity to servo speed tuple class.
Definition: hekKinJoint.h:195
void VelSpeedLookupTbl::dumpTable ( const std::string &  strId)

Dump lookup table entries.

Debugging is printed to stderr.

Parameters
strIdDebug identification string.

Definition at line 374 of file hekKinJoint.cxx.

References hekateros::radToDeg().

375 {
376  fprintf(stderr, "DBG: %s: bucket_size=%.2lf deg, lookup table[%zu] =\n{\n",
377  strId.c_str(), radToDeg(m_fBucketSize), m_tbl.size());
378 
379  for(int i=0; i<m_tbl.size(); ++i)
380  {
381  if( m_tbl[i].m_nServoSpeed != NO_ENTRY )
382  {
383  fprintf(stderr, " [%3d]: vel=%7.3lf (%6.2lf deg), speed=%4d\n",
384  i, m_tbl[i].m_fJointVel, radToDeg(m_tbl[i].m_fJointVel),
385  m_tbl[i].m_nServoSpeed);
386  }
387  }
388  fprintf(stderr, "}\n");
389 }
VelSpeedTbl m_tbl
dynamic interpolation table
Definition: hekKinJoint.h:366
static const int NO_ENTRY
No table entry value.
Definition: hekKinJoint.h:256
double radToDeg(double r)
Convert radians to degrees.
Definition: hekUtils.h:137
double m_fBucketSize
table entry size (degrees/second)
Definition: hekKinJoint.h:363
void VelSpeedLookupTbl::enableDebugging ( const std::string &  strId)

Enable table debugging.

Debugging is printed to stderr.

Parameters
strIdDebug identification string.

Definition at line 363 of file hekKinJoint.cxx.

364 {
365  m_strDbgId = strId;
366  m_bDbg = true;
367 }
std::string m_strDbgId
debugging id
Definition: hekKinJoint.h:367
bool m_bDbg
enable [disable] debugging
Definition: hekKinJoint.h:368
int VelSpeedLookupTbl::estimate ( double  fJointGoalVel)

Estimate servo goal speed.

Linear interpolation is performed between the two nearest neighbors in the lookup table.

Parameters
fJointGoalVelJoint goal velocity (radians/second).
Returns
Servo speed estimate.

Definition at line 266 of file hekKinJoint.cxx.

Referenced by hekateros::HekKinJoint::estimateServoTgtSpeed().

267 {
268  double fJointAbsVel = fabs(fJointGoalVel);
269 
270  // zero is 0
271  if( fJointAbsVel == 0.0 )
272  {
273  return m_tbl[0].m_nServoSpeed;
274  }
275  // maximum velocity
276  else if( fJointAbsVel >= m_tbl[m_nMaxIndex].m_fJointVel )
277  {
278  return m_tbl[m_nMaxIndex].m_nServoSpeed;
279  }
280 
281  double fMinVel;
282  int nMinSpeed;
283  double fMaxVel;
284  int nMaxSpeed;
285 
286  int index = hash(fJointAbsVel);
287 
288  // no entry at hashed location
289  if( m_tbl[index].m_nServoSpeed == NO_ENTRY )
290  {
291  nMinSpeed = NO_ENTRY;
292  nMaxSpeed = NO_ENTRY;
293  }
294  // go lucky - no interpolation needed
295  else if( m_tbl[index].m_fJointVel == fJointAbsVel )
296  {
297  return m_tbl[index].m_nServoSpeed;
298  }
299  // hashed location is minimum neighbor
300  else if( m_tbl[index].m_fJointVel < fJointAbsVel )
301  {
302  fMinVel = m_tbl[index].m_fJointVel;
303  nMinSpeed = m_tbl[index].m_nServoSpeed;
304  nMaxSpeed = NO_ENTRY;
305  }
306  // hashed location is maximum neighbor
307  else
308  {
309  nMinSpeed = NO_ENTRY;
310  fMaxVel = m_tbl[index].m_fJointVel;
311  nMaxSpeed = m_tbl[index].m_nServoSpeed;
312  }
313 
314  // no minimum neighbor - search downward
315  if( nMinSpeed == NO_ENTRY )
316  {
317  for(int i = index-1; i >= 0; --i)
318  {
319  if( m_tbl[i].m_nServoSpeed == NO_ENTRY )
320  {
321  continue;
322  }
323  else if( m_tbl[i].m_fJointVel < fJointAbsVel )
324  {
325  fMinVel = m_tbl[i].m_fJointVel;
326  nMinSpeed = m_tbl[i].m_nServoSpeed;
327  break;
328  }
329  }
330  }
331  if( nMinSpeed == NO_ENTRY )
332  {
333  return m_tbl[0].m_nServoSpeed;
334  }
335 
336  // no maximum neighbor - search upward
337  if( nMaxSpeed == NO_ENTRY )
338  {
339  for(int i = index+1; i <= m_nMaxIndex; ++i)
340  {
341  if( m_tbl[i].m_nServoSpeed == NO_ENTRY )
342  {
343  continue;
344  }
345  else if( m_tbl[i].m_fJointVel > fJointAbsVel )
346  {
347  fMaxVel = m_tbl[i].m_fJointVel;
348  nMaxSpeed = m_tbl[i].m_nServoSpeed;
349  break;
350  }
351  }
352  }
353  if( nMaxSpeed == NO_ENTRY )
354  {
355  return m_tbl[m_nMaxIndex].m_nServoSpeed;
356  }
357 
358  // interpolate
359  return (int)((double)nMinSpeed + fabs(nMaxSpeed - nMinSpeed) *
360  (fJointAbsVel - fMinVel) / (fMaxVel - fMinVel));
361 }
VelSpeedTbl m_tbl
dynamic interpolation table
Definition: hekKinJoint.h:366
static const int NO_ENTRY
No table entry value.
Definition: hekKinJoint.h:256
int m_nMaxIndex
maximum index into table
Definition: hekKinJoint.h:364
int hash(double fJointVel)
Hash joint velocity to table index.
int hekateros::VelSpeedLookupTbl::getLookupTableSize ( )
inline

Get the lookup table fixed size.

Returns
int

Definition at line 324 of file hekKinJoint.h.

325  {
326  return (int)m_tbl.size();
327  }
VelSpeedTbl m_tbl
dynamic interpolation table
Definition: hekKinJoint.h:366
int hekateros::VelSpeedLookupTbl::getNumLookupTableEntries ( )
inline

Get the number of populated entries in lookup table.

Returns
int

Definition at line 334 of file hekKinJoint.h.

335  {
336  return m_nNumEntries;
337  }
int m_nNumEntries
number of populated table entries.
Definition: hekKinJoint.h:365
int VelSpeedLookupTbl::hash ( double  fJointVel)

Hash joint velocity to table index.

Parameters
fJointVelJoint velocity (radians/second).
Returns
Table index.

Definition at line 229 of file hekKinJoint.cxx.

References hekateros::cap().

230 {
231  int index = (int)(fabs(fJointVel)/m_fBucketSize);
232  return cap(index, 0, m_nMaxIndex);
233 }
int m_nMaxIndex
maximum index into table
Definition: hekKinJoint.h:364
int cap(int a, int min, int max)
Cap value within limits [min, max].
Definition: hekUtils.h:177
double m_fBucketSize
table entry size (degrees/second)
Definition: hekKinJoint.h:363
VelSpeedLookupTbl VelSpeedLookupTbl::operator= ( const VelSpeedLookupTbl rhs)

Assignment operator.

Parameters
rhsRight hand side object.
Returns
Returns copy of this.

Definition at line 187 of file hekKinJoint.cxx.

References m_bDbg, m_fBucketSize, m_nMaxIndex, m_nNumEntries, m_strDbgId, and m_tbl.

188 {
190  m_nMaxIndex = rhs.m_nMaxIndex;
192  m_tbl = rhs.m_tbl;
193  m_strDbgId = rhs.m_strDbgId;
194  m_bDbg = rhs.m_bDbg;
195 }
VelSpeedTbl m_tbl
dynamic interpolation table
Definition: hekKinJoint.h:366
int m_nNumEntries
number of populated table entries.
Definition: hekKinJoint.h:365
int m_nMaxIndex
maximum index into table
Definition: hekKinJoint.h:364
std::string m_strDbgId
debugging id
Definition: hekKinJoint.h:367
double m_fBucketSize
table entry size (degrees/second)
Definition: hekKinJoint.h:363
bool m_bDbg
enable [disable] debugging
Definition: hekKinJoint.h:368
void VelSpeedLookupTbl::update ( double  fJointVel,
int  nServoSpeed 
)

Update lookup table entry.

Parameters
fJointVelJoint velocity (radians/second).
nServoSpeedServo speed (raw unitless).

Definition at line 235 of file hekKinJoint.cxx.

References hekateros::iabs(), and hekateros::radToDeg().

Referenced by hekateros::HekKinJoint::updateAssoc(), and hekateros::HekKinJointWristRot::updateAssoc().

236 {
237  int index = hash(fJointVel);
238 
239  if( (index > 0) && (index < m_nMaxIndex) )
240  {
241  int nOldCnt = m_nNumEntries;
242 
243  if( m_tbl[index].m_nServoSpeed == NO_ENTRY )
244  {
245  ++m_nNumEntries;
246  }
247 
248  m_tbl[index].m_fJointVel = fabs(fJointVel);
249  m_tbl[index].m_nServoSpeed = iabs(nServoSpeed);
250  if( m_tbl[index].m_nServoSpeed < MIN_NON_ZERO_SPEED )
251  {
252  m_tbl[index].m_nServoSpeed = MIN_NON_ZERO_SPEED;
253  }
254 
255  if( m_bDbg && (m_nNumEntries != nOldCnt) )
256  {
257  fprintf(stderr, "DBG: %s(): %s: "
258  "num_entries=%d, index=%d, vel=%lf, speed=%d\n",
259  LOGFUNCNAME,
260  m_strDbgId.c_str(), m_nNumEntries, index,
261  radToDeg(m_tbl[index].m_fJointVel), m_tbl[index].m_nServoSpeed);
262  }
263  }
264 }
VelSpeedTbl m_tbl
dynamic interpolation table
Definition: hekKinJoint.h:366
static const int NO_ENTRY
No table entry value.
Definition: hekKinJoint.h:256
int m_nNumEntries
number of populated table entries.
Definition: hekKinJoint.h:365
int m_nMaxIndex
maximum index into table
Definition: hekKinJoint.h:364
double radToDeg(double r)
Convert radians to degrees.
Definition: hekUtils.h:137
std::string m_strDbgId
debugging id
Definition: hekKinJoint.h:367
int iabs(int a)
Integer absolute value.
Definition: hekUtils.h:149
static const int MIN_NON_ZERO_SPEED
Minimum servo speed for non-zero velocities.
Definition: hekKinJoint.h:259
int hash(double fJointVel)
Hash joint velocity to table index.
bool m_bDbg
enable [disable] debugging
Definition: hekKinJoint.h:368

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