46 #include <visp3/core/vpCameraParameters.h>
47 #include <visp3/core/vpDebug.h>
48 #include <visp3/core/vpRotationMatrix.h>
49 #include <visp3/core/vpRxyzVector.h>
50 #include <visp3/core/vpTranslationVector.h>
51 #include <visp3/core/vpVelocityTwistMatrix.h>
52 #include <visp3/robot/vpRobotException.h>
53 #include <visp3/robot/vpViper.h>
64 : eMc(), etc(), erc(), a1(0), d1(0), a2(), a3(), d4(0), d6(0), d7(0), c56(0), joint_max(), joint_min()
76 c56 = -341.33 / 9102.22;
141 bool vpViper::convertJointPositionInLimits(
unsigned int joint,
const double &q,
double &q_mod,
142 const bool &verbose)
const
150 q_mod = q + 2 * M_PI;
155 q_mod = q - 2 * M_PI;
161 std::cout <<
"Joint " << joint <<
" not in limits: " << this->
joint_min[joint] <<
" < " << q <<
" < "
221 const bool &verbose)
const
225 for (
unsigned int i = 0; i < 8; i++)
228 double c1[8] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
229 double s1[8] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
230 double c3[8] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
231 double s3[8] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
232 double c23[8] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
233 double s23[8] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
234 double c4[8] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
235 double s4[8] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
236 double c5[8] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
237 double s5[8] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
238 double c6[8] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
239 double s6[8] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
246 for (
unsigned int i = 0; i < 8; i++)
249 double px = fMw[0][3];
250 double py = fMw[1][3];
251 double pz = fMw[2][3];
254 double a_2 = px * px + py * py;
256 if (std::fabs(a_2) <= std::numeric_limits<double>::epsilon()) {
259 c1[4] = cos(q[0] + M_PI);
260 s1[4] = sin(q[0] + M_PI);
263 double a = sqrt(a_2);
271 for (
unsigned int i = 0; i < 8; i += 4) {
272 q_sol[i][0] = atan2(s1[i], c1[i]);
273 if (convertJointPositionInLimits(0, q_sol[i][0], q1_mod, verbose) ==
true) {
274 q_sol[i][0] = q1_mod;
275 for (
unsigned int j = 1; j < 4; j++) {
278 q_sol[i + j][0] = q_sol[i][0];
282 for (
unsigned int j = 1; j < 4; j++)
289 for (
unsigned int i = 0; i < 8; i += 4) {
292 2 * (
a1 * c1[i] * px +
a1 * s1[i] * py +
d1 * pz)) /
294 double d4_a3_K =
d4 *
d4 +
a3 *
a3 - K * K;
296 q_sol[i][2] = atan2(
a3,
d4) + atan2(K, sqrt(d4_a3_K));
297 q_sol[i + 2][2] = atan2(
a3,
d4) + atan2(K, -sqrt(d4_a3_K));
299 for (
unsigned int j = 0; j < 4; j += 2) {
301 for (
unsigned int k = 0; k < 2; k++)
302 ok[i + j + k] =
false;
305 if (convertJointPositionInLimits(2, q_sol[i + j][2], q3_mod, verbose) ==
true) {
306 for (
unsigned int k = 0; k < 2; k++) {
307 q_sol[i + j + k][2] = q3_mod;
308 c3[i + j + k] = cos(q3_mod);
309 s3[i + j + k] = sin(q3_mod);
313 for (
unsigned int k = 0; k < 2; k++)
314 ok[i + j + k] =
false;
326 double q23[8], q2_mod;
327 for (
unsigned int i = 0; i < 8; i += 2) {
330 c23[i] = (-(
a3 -
a2 * c3[i]) * (c1[i] * px + s1[i] * py -
a1) - (
d1 - pz) * (
d4 +
a2 * s3[i])) /
331 ((c1[i] * px + s1[i] * py -
a1) * (c1[i] * px + s1[i] * py -
a1) + (
d1 - pz) * (
d1 - pz));
332 s23[i] = ((
d4 +
a2 * s3[i]) * (c1[i] * px + s1[i] * py -
a1) - (
d1 - pz) * (
a3 -
a2 * c3[i])) /
333 ((c1[i] * px + s1[i] * py -
a1) * (c1[i] * px + s1[i] * py -
a1) + (
d1 - pz) * (
d1 - pz));
334 q23[i] = atan2(s23[i], c23[i]);
338 q_sol[i][1] = q23[i] - q_sol[i][2];
340 if (convertJointPositionInLimits(1, q_sol[i][1], q2_mod, verbose) ==
true) {
341 for (
unsigned int j = 0; j < 2; j++) {
342 q_sol[i + j][1] = q2_mod;
348 for (
unsigned int j = 0; j < 2; j++)
359 double r13 = fMw[0][2];
360 double r23 = fMw[1][2];
361 double r33 = fMw[2][2];
362 double s4s5, c4s5, q4_mod, q5_mod;
363 for (
unsigned int i = 0; i < 8; i += 2) {
365 s4s5 = -s1[i] * r13 + c1[i] * r23;
366 c4s5 = c1[i] * c23[i] * r13 + s1[i] * c23[i] * r23 - s23[i] * r33;
369 c5[i] = c1[i] * s23[i] * r13 + s1[i] * s23[i] * r23 + c23[i] * r33;
376 if (convertJointPositionInLimits(4, q_sol[i][4], q5_mod, verbose) ==
true) {
377 for (
unsigned int j = 0; j < 2; j++) {
378 q_sol[i + j][3] = q[3];
379 q_sol[i + j][4] = q5_mod;
380 c4[i] = cos(q_sol[i + j][3]);
381 s4[i] = sin(q_sol[i + j][3]);
385 for (
unsigned int j = 0; j < 2; j++)
393 if (std::fabs(c4s5) <= std::numeric_limits<double>::epsilon()) {
397 q_sol[i][3] = atan2(s4s5, c4s5);
400 q_sol[i][3] = atan2(s4s5, c4s5);
403 q_sol[i][3] = atan2(s4s5, c4s5);
405 if (convertJointPositionInLimits(3, q_sol[i][3], q4_mod, verbose) ==
true) {
406 q_sol[i][3] = q4_mod;
413 if (q_sol[i][3] > 0.)
414 q_sol[i + 1][3] = q_sol[i][3] + M_PI;
416 q_sol[i + 1][3] = q_sol[i][3] - M_PI;
417 if (convertJointPositionInLimits(3, q_sol[i + 1][3], q4_mod, verbose) ==
true) {
418 q_sol[i + 1][3] = q4_mod;
419 c4[i + 1] = cos(q4_mod);
420 s4[i + 1] = sin(q4_mod);
427 for (
unsigned int j = 0; j < 2; j++) {
428 if (ok[i + j] ==
true) {
429 c5[i + j] = c1[i + j] * s23[i + j] * r13 + s1[i + j] * s23[i + j] * r23 + c23[i + j] * r33;
430 s5[i + j] = (c1[i + j] * c23[i + j] * c4[i + j] - s1[i + j] * s4[i + j]) * r13 +
431 (s1[i + j] * c23[i + j] * c4[i + j] + c1[i + j] * s4[i + j]) * r23 -
432 s23[i + j] * c4[i + j] * r33;
434 q_sol[i + j][4] = atan2(s5[i + j], c5[i + j]);
435 if (convertJointPositionInLimits(4, q_sol[i + j][4], q5_mod, verbose) ==
true) {
436 q_sol[i + j][4] = q5_mod;
450 double r12 = fMw[0][1];
451 double r22 = fMw[1][1];
452 double r32 = fMw[2][1];
454 for (
unsigned int i = 0; i < 8; i++) {
455 c6[i] = -(c1[i] * c23[i] * s4[i] + s1[i] * c4[i]) * r12 + (c1[i] * c4[i] - s1[i] * c23[i] * s4[i]) * r22 +
456 s23[i] * s4[i] * r32;
457 s6[i] = -(c1[i] * c23[i] * c4[i] * c5[i] - c1[i] * s23[i] * s5[i] - s1[i] * s4[i] * c5[i]) * r12 -
458 (s1[i] * c23[i] * c4[i] * c5[i] - s1[i] * s23[i] * s5[i] + c1[i] * s4[i] * c5[i]) * r22 +
459 (c23[i] * s5[i] + s23[i] * c4[i] * c5[i]) * r32;
461 q_sol[i][5] = atan2(s6[i], c6[i]);
462 if (convertJointPositionInLimits(5, q_sol[i][5], q6_mod, verbose) ==
true) {
463 q_sol[i][5] = q6_mod;
471 unsigned int nbsol = 0;
472 unsigned int sol = 0;
474 for (
unsigned int i = 0; i < 8; i++) {
481 weight[1] = weight[2] = 4;
483 for (
unsigned int j = 0; j < 6; j++) {
484 double rought_dist = q[j] - q_sol[i][j];
485 double modulo_dist = rought_dist;
486 if (rought_dist > 0) {
487 if (fabs(rought_dist - 2 * M_PI) < fabs(rought_dist))
488 modulo_dist = rought_dist - 2 * M_PI;
491 if (fabs(rought_dist + 2 * M_PI) < fabs(rought_dist))
492 modulo_dist = rought_dist + 2 * M_PI;
502 for (
unsigned int i = 0; i < 8; i++) {
504 if (dist[i] < dist[sol])
643 fMc = fMe * this->
eMc;
749 double c23 = cos(q2 + q3);
750 double s23 = sin(q2 + q3);
752 fMe[0][0] = c1 * (c23 * (c4 * c5 * c6 - s4 * s6) - s23 * s5 * c6) - s1 * (s4 * c5 * c6 + c4 * s6);
753 fMe[1][0] = -s1 * (c23 * (-c4 * c5 * c6 + s4 * s6) + s23 * s5 * c6) + c1 * (s4 * c5 * c6 + c4 * s6);
754 fMe[2][0] = s23 * (s4 * s6 - c4 * c5 * c6) - c23 * s5 * c6;
756 fMe[0][1] = -c1 * (c23 * (c4 * c5 * s6 + s4 * c6) - s23 * s5 * s6) + s1 * (s4 * c5 * s6 - c4 * c6);
757 fMe[1][1] = -s1 * (c23 * (c4 * c5 * s6 + s4 * c6) - s23 * s5 * s6) - c1 * (s4 * c5 * s6 - c4 * c6);
758 fMe[2][1] = s23 * (c4 * c5 * s6 + s4 * c6) + c23 * s5 * s6;
760 fMe[0][2] = c1 * (c23 * c4 * s5 + s23 * c5) - s1 * s4 * s5;
761 fMe[1][2] = s1 * (c23 * c4 * s5 + s23 * c5) + c1 * s4 * s5;
762 fMe[2][2] = -s23 * c4 * s5 + c23 * c5;
764 fMe[0][3] = c1 * (c23 * (c4 * s5 *
d6 -
a3) + s23 * (c5 *
d6 +
d4) +
a1 +
a2 * c2) - s1 * s4 * s5 *
d6;
765 fMe[1][3] = s1 * (c23 * (c4 * s5 *
d6 -
a3) + s23 * (c5 *
d6 +
d4) +
a1 +
a2 * c2) + c1 * s4 * s5 *
d6;
766 fMe[2][3] = s23 * (
a3 - c4 * s5 *
d6) + c23 * (c5 *
d6 +
d4) -
a2 * s2 +
d1;
839 double c23 = cos(q2 + q3);
840 double s23 = sin(q2 + q3);
842 fMw[0][0] = c1 * (c23 * (c4 * c5 * c6 - s4 * s6) - s23 * s5 * c6) - s1 * (s4 * c5 * c6 + c4 * s6);
843 fMw[1][0] = -s1 * (c23 * (-c4 * c5 * c6 + s4 * s6) + s23 * s5 * c6) + c1 * (s4 * c5 * c6 + c4 * s6);
844 fMw[2][0] = s23 * (s4 * s6 - c4 * c5 * c6) - c23 * s5 * c6;
846 fMw[0][1] = -c1 * (c23 * (c4 * c5 * s6 + s4 * c6) - s23 * s5 * s6) + s1 * (s4 * c5 * s6 - c4 * c6);
847 fMw[1][1] = -s1 * (c23 * (c4 * c5 * s6 + s4 * c6) - s23 * s5 * s6) - c1 * (s4 * c5 * s6 - c4 * c6);
848 fMw[2][1] = s23 * (c4 * c5 * s6 + s4 * c6) + c23 * s5 * s6;
850 fMw[0][2] = c1 * (c23 * c4 * s5 + s23 * c5) - s1 * s4 * s5;
851 fMw[1][2] = s1 * (c23 * c4 * s5 + s23 * c5) + c1 * s4 * s5;
852 fMw[2][2] = -s23 * c4 * s5 + c23 * c5;
854 fMw[0][3] = c1 * (-c23 *
a3 + s23 *
d4 +
a1 +
a2 * c2);
855 fMw[1][3] = s1 * (-c23 *
a3 + s23 *
d4 +
a1 +
a2 * c2);
856 fMw[2][3] = s23 *
a3 + c23 *
d4 -
a2 * s2 +
d1;
980 for (
unsigned int i = 0; i < 3; i++) {
981 for (
unsigned int j = 0; j < 3; j++) {
982 V[i][j] = V[i + 3][j + 3] = wRf[i][j];
993 for (
unsigned int i = 0; i < 3; i++) {
994 for (
unsigned int j = 0; j < 3; j++) {
995 V[i][j + 3] = block2[i][j];
1061 double c1 = cos(q1);
1062 double s1 = sin(q1);
1063 double c2 = cos(q2);
1064 double s2 = sin(q2);
1065 double c3 = cos(q3);
1066 double s3 = sin(q3);
1067 double c4 = cos(q4);
1068 double s4 = sin(q4);
1069 double c5 = cos(q5);
1070 double s5 = sin(q5);
1071 double c23 = cos(q2 + q3);
1072 double s23 = sin(q2 + q3);
1082 J1[0] = -s1 * (-c23 *
a3 + s23 *
d4 +
a1 +
a2 * c2);
1083 J1[1] = c1 * (-c23 *
a3 + s23 *
d4 +
a1 +
a2 * c2);
1089 J2[0] = c1 * (s23 *
a3 + c23 *
d4 -
a2 * s2);
1090 J2[1] = s1 * (s23 *
a3 + c23 *
d4 -
a2 * s2);
1091 J2[2] = c23 *
a3 - s23 *
d4 -
a2 * c2;
1096 J3[0] = c1 * (
a3 * (s2 * c3 + c2 * s3) + (-s2 * s3 + c2 * c3) *
d4);
1097 J3[1] = s1 * (
a3 * (s2 * c3 + c2 * s3) + (-s2 * s3 + c2 * c3) *
d4);
1098 J3[2] = -
a3 * (s2 * s3 - c2 * c3) -
d4 * (s2 * c3 + c2 * s3);
1113 J5[3] = -c23 * c1 * s4 - s1 * c4;
1114 J5[4] = c1 * c4 - c23 * s1 * s4;
1120 J6[3] = (c1 * c23 * c4 - s1 * s4) * s5 + c1 * s23 * c5;
1121 J6[4] = (s1 * c23 * c4 + c1 * s4) * s5 + s1 * s23 * c5;
1122 J6[5] = -s23 * c4 * s5 + c23 * c5;
1125 for (
unsigned int i = 0; i < 6; i++) {
1163 for (
unsigned int i = 0; i < 6; i++)
1177 vpMatrix block2 = (fRw * etw).skew();
1179 for (
unsigned int i = 0; i < 3; i++)
1180 for (
unsigned int j = 0; j < 3; j++)
1181 V[i][j + 3] = block2[i][j];
1276 os <<
"Joint Max (deg):" << std::endl
1277 <<
"\t" << jmax.
t() << std::endl
1279 <<
"Joint Min (deg): " << std::endl
1280 <<
"\t" << jmin.
t() << std::endl
1282 <<
"Coupling 5-6:" << std::endl
1283 <<
"\t" << viper.
c56 << std::endl
1285 <<
"eMc: " << std::endl
1286 <<
"\tTranslation (m): " << viper.
eMc[0][3] <<
" " << viper.
eMc[1][3] <<
" " << viper.
eMc[2][3] <<
"\t"
1288 <<
"\tRotation Rxyz (rad) : " << rxyz[0] <<
" " << rxyz[1] <<
" " << rxyz[2] <<
"\t" << std::endl
1290 <<
"\t" << std::endl;
void resize(unsigned int nrows, unsigned int ncols, bool flagNullify=true, bool recopy_=true)
friend std::ostream & operator<<(std::ostream &s, const vpArray2D< Type > &A)
unsigned int getRows() const
Implementation of column vector and the associated operations.
void resize(unsigned int i, bool flagNullify=true)
Implementation of an homogeneous matrix and operations on such kind of matrices.
vpHomogeneousMatrix & buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)
vpHomogeneousMatrix inverse() const
void extract(vpRotationMatrix &R) const
static double rad(double deg)
static double sqr(double x)
static double deg(double rad)
Implementation of a matrix and operations on matrices.
Implementation of a rotation matrix and operations on such kind of matrices.
vpRotationMatrix inverse() const
Implementation of a rotation vector as Euler angle minimal representation.
vpRxyzVector & buildFrom(const vpRotationMatrix &R)
Class that consider the case of a translation vector.
vpVelocityTwistMatrix & buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)
Modelization of the ADEPT Viper robot.
double getCoupl56() const
void get_fJw(const vpColVector &q, vpMatrix &fJw) const
virtual void set_eMc(const vpHomogeneousMatrix &eMc_)
vpHomogeneousMatrix getForwardKinematics(const vpColVector &q) const
void get_fMw(const vpColVector &q, vpHomogeneousMatrix &fMw) const
static const unsigned int njoint
Number of joint.
void get_cMe(vpHomogeneousMatrix &cMe) const
void get_fJe(const vpColVector &q, vpMatrix &fJe) const
unsigned int getInverseKinematics(const vpHomogeneousMatrix &fMc, vpColVector &q, const bool &verbose=false) const
double c56
Mechanical coupling between joint 5 and joint 6.
vpColVector getJointMin() const
void get_eMc(vpHomogeneousMatrix &eMc) const
vpHomogeneousMatrix eMc
End effector to camera transformation.
vpColVector getJointMax() const
void get_eMs(vpHomogeneousMatrix &eMs) const
void get_wMe(vpHomogeneousMatrix &wMe) const
unsigned int getInverseKinematicsWrist(const vpHomogeneousMatrix &fMw, vpColVector &q, const bool &verbose=false) const
void get_eJe(const vpColVector &q, vpMatrix &eJe) const
void get_fMe(const vpColVector &q, vpHomogeneousMatrix &fMe) const
void get_cVe(vpVelocityTwistMatrix &cVe) const
double d7
for force/torque location
vpHomogeneousMatrix get_fMc(const vpColVector &q) const