40 #define JOINT_EPSILON .01 / 360.0
44 #define DEGS_PER_RAD 57.29577951
45 #define RADS_PER_DEG 0.017453292
60 Joint_Exception(
const char* _file,
int _line,
const char* _msg) : std::runtime_error(_msg),
file(_file),
line(_line)
86 _os <<
"Error in " << e.
getFile();
87 _os <<
" at line " << e.
getLine() <<
":" << std::endl;
88 _os <<
" " << e.
getMsg() << std::endl;
105 Joint(
unsigned int NrJoints,
bool zero =
false);
109 Joint(
unsigned int NrJoints,
const Real
d[]);
122 void set(
unsigned int i, Real
d);
125 void set(
unsigned int NrJoints, Real*
d);
132 Real
get(
unsigned int i)
const;
135 void get(
unsigned int NrJoints, Real*
d)
const;
137 unsigned int size()
const;
182 std::string
toString(
bool convert =
false)
const;
184 void fromString(
unsigned int nrjoints,
const char* str);
213 template <
class Real>
216 template <
class Real>
223 template <
class Real>
226 return (j1 - j2).length();
234 template <
class Real>
242 template <
class Real>
245 m_NrJoints = NrJoints;
246 m_Joints =
new Real[m_NrJoints];
253 template <
class Real>
259 for (
unsigned int i = 0; i < m_NrJoints; i++)
264 template <
class Real>
267 m_NrJoints = NrJoints;
268 m_Joints =
new Real[m_NrJoints];
270 for (
unsigned int i = 0; i < m_NrJoints; i++)
275 template <
class Real>
283 template <
class Real>
288 Real* old_m_Joints = m_Joints;
289 m_Joints =
new Real[NrJoints];
291 for (
unsigned int i = 0; i < NrJoints; i++)
294 m_Joints[i] = old_m_Joints[i];
300 delete[] old_m_Joints;
302 m_NrJoints = NrJoints;
306 template <
class Real>
309 for (
unsigned int i = 0; i < m_NrJoints; i++)
316 template <
class Real>
319 #ifndef JOINT_NO_RANGECHECK
320 if ((m_Joints == NULL) || (i >= m_NrJoints))
321 throw Joint_Exception(__FILE__, __LINE__,
"tried to acces an element out of Joint range!");
326 template <
class Real>
329 #ifndef JOINT_NO_RANGECHECK
330 if ((m_Joints == NULL) || (i >= m_NrJoints))
331 throw Joint_Exception(__FILE__, __LINE__,
"tried to acces an element out of Joint range!");
337 template <
class Real>
340 #ifndef JOINT_NO_RANGECHECK
341 if ((!m_Joints) || (NrJoints != m_NrJoints))
342 setNrJoints(NrJoints);
345 for (
unsigned int i = 0; i < m_NrJoints; i++)
352 template <
class Real>
355 #ifndef JOINT_NO_RANGECHECK
356 if ((m_Joints == NULL) || (i >= m_NrJoints))
357 throw Joint_Exception(__FILE__, __LINE__,
"tried to acces an element out of Joint range!");
363 template <
class Real>
370 template <
class Real>
373 #ifndef JOINT_NO_RANGECHECK
374 if ((m_Joints == NULL) || (NrJoints > m_NrJoints))
375 throw Joint_Exception(__FILE__, __LINE__,
"tried to acces an element out of Joint range!");
378 for (
unsigned int i = 0; i < m_NrJoints; i++)
383 template <
class Real>
390 template <
class Real>
393 #ifndef JOINT_NO_RANGECHECK
395 throw Joint_Exception(__FILE__, __LINE__,
"tried to call getMax on empty Joint!");
398 Real max = m_Joints[0];
399 for (
unsigned int i = 1; i < m_NrJoints; i++)
400 max = (m_Joints[i] > max) ? m_Joints[i] : max;
404 template <
class Real>
407 #ifndef JOINT_NO_RANGECHECK
409 throw Joint_Exception(__FILE__, __LINE__,
"tried to call getMin on empty Joint!");
412 Real min = m_Joints[0];
413 for (
unsigned int i = 1; i < m_NrJoints; i++)
414 min = (m_Joints[i] < min) ? m_Joints[i] : min;
419 template <
class Real>
422 #ifndef JOINT_NO_RANGECHECK
424 throw Joint_Exception(__FILE__, __LINE__,
"tried to call getMaxInd on empty Joint!");
427 Real max = m_Joints[0];
428 unsigned int maxI = 0;
430 for (
unsigned int i = 1; i < m_NrJoints; i++)
432 if (m_Joints[i] > max)
441 template <
class Real>
444 #ifndef JOINT_NO_RANGECHECK
446 throw Joint_Exception(__FILE__, __LINE__,
"tried to call getMinInd on empty Joint!");
449 Real min = m_Joints[0];
450 unsigned int minI = 0;
452 for (
unsigned int i = 1; i < m_NrJoints; i++)
454 if (m_Joints[i] < min)
464 template <
class Real>
467 #ifndef JOINT_NO_RANGECHECK
468 if ((m_Joints == NULL) || (j2.
size() != m_NrJoints))
469 throw Joint_Exception(__FILE__, __LINE__,
"Joint dimensions mismatch in interpolate!");
474 for (
unsigned int i = 0; i < m_NrJoints; i++)
475 result[i] = m_Joints[i] + (j2[i] - m_Joints[i]) *
f;
481 template <
class Real>
484 #ifndef JOINT_NO_RANGECHECK
486 throw Joint_Exception(__FILE__, __LINE__,
"Joint dimensions mismatch in interpolate!");
491 for (
unsigned int i = 0; i < j1.
size(); i++)
492 result[i] = j1[i] +
f * (j2[i] - j1[i]);
498 template <
class Real>
501 for (
unsigned int i = 0; i < m_NrJoints; i++)
505 template <
class Real>
508 for (
unsigned int i = 0; i < m_NrJoints; i++)
516 template <
class Real>
519 if (joint.
size() != m_NrJoints)
520 setNrJoints(joint.
size());
522 for (
unsigned int i = 0; i < m_NrJoints; i++)
523 m_Joints[i] = joint[i];
529 template <
class Real>
532 #ifndef JOINT_NO_RANGECHECK
533 if (m_NrJoints != joint2.
size())
546 #ifndef JOINT_NO_RANGECHECK
552 template <
class Real>
555 #ifndef JOINT_NO_RANGECHECK
556 if (m_NrJoints != rhs.
size())
557 throw Joint_Exception(__FILE__, __LINE__,
"Joint dimensions mismatch in operator+ !");
561 for (
unsigned int i = 0; i < m_NrJoints; i++)
568 template <
class Real>
571 #ifndef JOINT_NO_RANGECHECK
572 if (m_NrJoints != rhs.
size())
573 throw Joint_Exception(__FILE__, __LINE__,
"Joint dimensions mismatch in operator- !");
577 for (
unsigned int i = 0; i < m_NrJoints; i++)
584 template <
class Real>
588 for (
unsigned int i = 0; i < m_NrJoints; i++)
593 template <
class Real>
597 if (fabs(
s) > std::numeric_limits<Real>::epsilon())
598 for (
unsigned int i = 0; i < m_NrJoints; i++)
601 throw Joint_Exception(__FILE__, __LINE__,
"Attempt to divide by zero in operator/ !");
607 template <
class Real>
610 #ifndef JOINT_NO_RANGECHECK
611 if (m_NrJoints != rhs.
size())
612 throw Joint_Exception(__FILE__, __LINE__,
"Joint dimensions mismatch in operator+= !");
615 for (
unsigned int i = 0; i < m_NrJoints; i++)
617 m_Joints[i] += rhs[i];
621 template <
class Real>
624 #ifndef JOINT_NO_RANGECHECK
625 if (m_NrJoints != rhs.
size())
626 throw Joint_Exception(__FILE__, __LINE__,
"Joint dimensions mismatch in operator-= !");
629 for (
unsigned int i = 0; i < m_NrJoints; i++)
631 m_Joints[i] -= rhs[i];
635 template <
class Real>
638 for (
unsigned int i = 0; i < m_NrJoints; i++)
642 template <
class Real>
645 if (fabs(
s) > std::numeric_limits<Real>::epsilon())
646 for (
unsigned int i = 0; i < m_NrJoints; i++)
649 throw Joint_Exception(__FILE__, __LINE__,
"Attempt to divide by zero in operator/= !");
654 template <
class Real>
658 for (
unsigned int i = 0; i < getNrJoints(); i++)
660 l += m_Joints[i] * m_Joints[i];
665 template <
class Real>
668 return sqrt(lengthSqr());
673 template <
class Real>
677 std::string str(
"(");
678 for (
unsigned int i = 0; i < m_NrJoints; i++)
685 sprintf(out,
"%3.6lf", m_Joints[i]);
686 str += std::string(out);
693 template <
class Real>
697 if (nrjoints != m_NrJoints)
698 setNrJoints(nrjoints);
700 const char*
start = strrchr(str,
'(');
701 const char* end = strrchr(str,
')');
705 char* numbers =
new char[n];
706 strncpy(numbers,
start + 1, n - 1);
707 char* pch = strtok(numbers,
",");
709 while (pch != NULL && i < nrjoints)
714 pch = strtok(NULL,
",");
721 template <
class Real>
724 std::vector<Real> vec;
726 const char*
start = strrchr(str,
'(');
727 const char* end = strrchr(str,
')');
731 char* numbers =
new char[n];
732 strncpy(numbers,
start + 1, n - 1);
733 char* pch = strtok(numbers,
",");
738 vec.push_back(atof(pch));
739 pch = strtok(NULL,
",");
743 setNrJoints(vec.size());
744 for (
unsigned int i = 0; i < m_NrJoints; i++)
745 m_Joints[i] = vec[i];
749 template <
class Real>
752 for (
unsigned int i = 0; i < m_NrJoints; i++)
753 printf(
"%f ",
get(i));
757 template <
class Real>
766 template <
class Real>
779 %include Source/Manipulation/ManipUtil/datastructsManipulator.h
780 %include Source/Manipulation/ManipUtil/Trajectory.h
784 %include
"std_vector.i"