Visual Servoing Platform  version 3.0.0
vpAfma4.cpp
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2015 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ViSP with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * See http://visp.inria.fr for more information.
17  *
18  * This software was developed at:
19  * Inria Rennes - Bretagne Atlantique
20  * Campus Universitaire de Beaulieu
21  * 35042 Rennes Cedex
22  * France
23  *
24  * If you have questions regarding the use of this file, please contact
25  * Inria at visp@inria.fr
26  *
27  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29  *
30  * Description:
31  * Interface for the Irisa's Afma4 robot.
32  *
33  * Authors:
34  * Fabien Spindler
35  *
36  *****************************************************************************/
37 
46 #include <visp3/core/vpDebug.h>
47 #include <visp3/core/vpVelocityTwistMatrix.h>
48 #include <visp3/robot/vpRobotException.h>
49 #include <visp3/core/vpCameraParameters.h>
50 #include <visp3/core/vpRxyzVector.h>
51 #include <visp3/core/vpTranslationVector.h>
52 #include <visp3/core/vpRotationMatrix.h>
53 #include <visp3/robot/vpAfma4.h>
54 
55 
56 /* ----------------------------------------------------------------------- */
57 /* --- STATIC ------------------------------------------------------------ */
58 /* ---------------------------------------------------------------------- */
59 const unsigned int vpAfma4::njoint = 4;
60 
61 
68  : _a1(0), _d3(0), _d4(0), _etc(), _erc(), _eMc()
69 {
70  // Set the default parameters in case of the config files on the NAS
71  // at Inria are not available.
72 
73  //
74  // Geometric model constant parameters
75  //
76  this->_a1 = 0.205; // distance along x2
77  this->_d3 = 0.403; // distance along z2
78  this->_d4 = 0.14; // distance along z3
79 
80  // Maximal value of the joints
81  this->_joint_max[0] = 1.8; // rad
82  this->_joint_max[1] = 0.9; // meter
83  this->_joint_max[2] = 0.9; // rad
84  this->_joint_max[3] = 0.76; // rad
85  // Minimal value of the joints
86  this->_joint_min[0] = -1.5; // rad
87  this->_joint_min[1] = -0.9; // meter
88  this->_joint_min[2] = -3.5; // rad
89  this->_joint_min[3] = -0.76;// rad
90 
91  // Camera extrinsic parameters: effector to camera frame
92  this->_etc[0] = 0.; // Translation
93  this->_etc[1] = 0.;
94  this->_etc[2] = 0.;
95  this->_erc[0] = 0.; // Rotation
96  this->_erc[1] = -M_PI/2.;
97  this->_erc[2] = 0;
98 
100  this->_eMc.buildFrom(_etc, eRc);
101 
102  init();
103 }
104 
105 
110 void
112 {
113  return;
114 }
115 
149 {
151  fMc = get_fMc(q);
152 
153  return fMc;
154 }
155 
186 vpAfma4::get_fMc (const vpColVector & q) const
187 {
189  get_fMc(q, fMc);
190 
191  return fMc;
192 }
193 
220 void
222 {
223 
224  // Compute the direct geometric model: fMe = transformation between
225  // fix and end effector frame.
227 
228  get_fMe(q, fMe);
229 
230  fMc = fMe * this->_eMc;
231 
232  return;
233 }
234 
268 void
270 {
271  double q1 = q[0]; // rot touret
272  double q2 = q[1]; // vertical translation
273  double q4 = q[2]; // pan
274  double q5 = q[3]; // tilt
275 
276  double c1 = cos(q1);
277  double s1 = sin(q1);
278  double c4 = cos(q4);
279  double s4 = sin(q4);
280  double c5 = cos(q5);
281  double s5 = sin(q5);
282 
283  /* Calcul du modele d'apres les angles. */
284  fMe[0][0] = c1*s4*c5 + s1*c4*c5;
285  fMe[0][1] = -c1*s4*s5 - s1*c4*s5;
286  fMe[0][2] = c1*c4 - s1*s4;
287  fMe[0][3] = c1*this->_a1 - s1*(this->_d3);
288 
289  fMe[1][0] = s1*s4*c5 - c1*c4*c5;
290  fMe[1][1] = -s1*s4*s5 + c1*c4*s5;
291  fMe[1][2] = s1*c4+c1*s4;
292  fMe[1][3] = s1*this->_a1 + c1*(this->_d3);
293 
294  fMe[2][0] = -s5;
295  fMe[2][1] = -c5;
296  fMe[2][2] = 0.f;
297  fMe[2][3] = this->_d4 + q2;
298 
299  fMe[3][0] = 0.f;
300  fMe[3][1] = 0.f;
301  fMe[3][2] = 0.f;
302  fMe[3][3] = 1;
303 
304  // vpCTRACE << "Effector position fMe: " << std::endl << fMe;
305 
306  return;
307 }
308 
319 void
321 {
322  cMe = this->_eMc.inverse();
323 }
324 
334 void
336 {
337  vpHomogeneousMatrix cMe ;
338  get_cMe(cMe) ;
339 
340  cVe.buildFrom(cMe) ;
341 
342  return;
343 }
344 
363 void
365 {
366  vpHomogeneousMatrix fMc, cMf ;
367  get_fMc(q, fMc) ;
368  cMf = fMc.inverse();
369 
370  cVf.buildFrom(cMf) ;
371 
372  return;
373 }
374 
411 void
412 vpAfma4::get_eJe(const vpColVector &q, vpMatrix &eJe) const
413 {
414  double q4 = q[2]; // pan
415  double q5 = q[3]; // tilt
416 
417  double c4 = cos(q4);
418  double s4 = sin(q4);
419  double c5 = cos(q5);
420  double s5 = sin(q5);
421 
422  eJe.resize(6, 4);
423 
424  eJe = 0;
425 
426  eJe[0][0] = -(this->_a1*c4 + this->_d3*s4)*c5; eJe[0][1] = -s5;
427  eJe[1][0] = (this->_a1*c4 + this->_d3*s4)*s5; eJe[1][1] = -c5;
428  eJe[2][0] = (this->_a1*s4 - this->_d3*c4);
429  eJe[3][0] = eJe[3][2] = -s5;
430  eJe[4][0] = eJe[4][2] = -c5;
431  eJe[5][3] = 1.;
432 }
433 
465 void
466 vpAfma4::get_fJe(const vpColVector &q, vpMatrix &fJe) const
467 {
468  fJe.resize(6,4) ;
469 
470  double q1 = q[0]; // rot touret
471  double q4 = q[2]; // pan
472 
473  double c1 = cos(q1);
474  double s1 = sin(q1);
475  double c14 = cos(q1 + q4);
476  double s14 = sin(q1 + q4);
477 
478  fJe = 0;
479 
480  fJe[0][0] = -s1*this->_a1 - c1*this->_d3;
481 
482  fJe[1][0] = c1*this->_a1 - s1*this->_d3;
483 
484  fJe[2][1] = 1.0;
485 
486  fJe[3][3] = c14;
487 
488  fJe[4][3] = s14;
489 
490  fJe[5][0] = fJe[5][2] = 1.0;
491 }
492 
522 void vpAfma4::get_fJe_inverse(const vpColVector &q, vpMatrix &fJe_inverse) const
523 {
524  fJe_inverse.resize(4, 6) ;
525  fJe_inverse = 0;
526 
527  double q1 = q[0]; // rot touret
528  double q4 = q[2]; // pan
529 
530  double c1 = cos(q1);
531  double s1 = sin(q1);
532  double c14 = cos(q1 + q4);
533  double s14 = sin(q1 + q4);
534 
535  double det = this->_a1 * this->_a1 + this->_d3 * this->_d3;
536 
537  fJe_inverse[0][0] = (-s1*this->_a1 - c1*this->_d3)/det;
538  fJe_inverse[0][1] = (c1*this->_a1 - s1*this->_d3)/det;
539 
540  fJe_inverse[1][2] = fJe_inverse[2][5] = 1.;
541 
542  fJe_inverse[2][0] = - fJe_inverse[0][0];
543  fJe_inverse[2][1] = - fJe_inverse[0][1];
544 
545  fJe_inverse[3][3] = c14;
546  fJe_inverse[3][4] = s14;
547 }
548 
559 {
560  vpColVector qmin(4);
561  for (unsigned int i=0; i < 4; i ++)
562  qmin[i] = this->_joint_min[i];
563  return qmin;
564 }
565 
576 {
577  vpColVector qmax(4);
578  for (unsigned int i=0; i < 4; i ++)
579  qmax[i] = this->_joint_max[i];
580  return qmax;
581 }
582 
583 
584 
594 VISP_EXPORT std::ostream & operator << (std::ostream & os,
595  const vpAfma4 & afma4)
596 {
597  vpRotationMatrix eRc;
598  afma4._eMc.extract(eRc);
599  vpRxyzVector rxyz(eRc);
600 
601  os
602  << "Joint Max:" << std::endl
603  << "\t" << afma4._joint_max[0]
604  << "\t" << afma4._joint_max[1]
605  << "\t" << afma4._joint_max[2]
606  << "\t" << afma4._joint_max[3]
607  << "\t" << std::endl
608 
609  << "Joint Min: " << std::endl
610  << "\t" << afma4._joint_min[0]
611  << "\t" << afma4._joint_min[1]
612  << "\t" << afma4._joint_min[2]
613  << "\t" << afma4._joint_min[3]
614  << "\t" << std::endl
615 
616  << "a1: " << std::endl
617  << "\t" << afma4._a1
618  << "\t" << std::endl
619 
620  << "d3: " << std::endl
621  << "\t" << afma4._d3
622  << "\t" << std::endl
623 
624  << "d4: " << std::endl
625  << "\t" << afma4._d4
626  << "\t" << std::endl
627 
628  << "eMc: "<< std::endl
629  << "\tTranslation (m): "
630  << afma4._eMc[0][3] << " "
631  << afma4._eMc[1][3] << " "
632  << afma4._eMc[2][3]
633  << "\t" << std::endl
634  << "\tRotation Rxyz (rad) : "
635  << rxyz[0] << " "
636  << rxyz[1] << " "
637  << rxyz[2]
638  << "\t" << std::endl
639  << "\tRotation Rxyz (deg) : "
640  << vpMath::deg(rxyz[0]) << " "
641  << vpMath::deg(rxyz[1]) << " "
642  << vpMath::deg(rxyz[2])
643  << "\t" << std::endl;
644 
645  return os;
646 }
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:92
double _a1
Definition: vpAfma4.h:142
vpHomogeneousMatrix get_fMc(const vpColVector &q) const
Definition: vpAfma4.cpp:186
void get_fMe(const vpColVector &q, vpHomogeneousMatrix &fMe) const
Definition: vpAfma4.cpp:269
void get_cMe(vpHomogeneousMatrix &cMe) const
Definition: vpAfma4.cpp:320
void resize(const unsigned int nrows, const unsigned int ncols, const bool flagNullify=true)
Definition: vpArray2D.h:167
Implementation of an homogeneous matrix and operations on such kind of matrices.
vpHomogeneousMatrix _eMc
Definition: vpAfma4.h:152
vpColVector getJointMax() const
Definition: vpAfma4.cpp:575
double _d4
Definition: vpAfma4.h:144
void get_cVe(vpVelocityTwistMatrix &cVe) const
Definition: vpAfma4.cpp:335
void init(void)
Definition: vpAfma4.cpp:111
vpAfma4()
Definition: vpAfma4.cpp:67
void get_cVf(const vpColVector &q, vpVelocityTwistMatrix &cVf) const
Definition: vpAfma4.cpp:364
void get_eJe(const vpColVector &q, vpMatrix &eJe) const
Definition: vpAfma4.cpp:412
Implementation of a rotation matrix and operations on such kind of matrices.
double _joint_max[4]
Definition: vpAfma4.h:145
vpVelocityTwistMatrix buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)
vpTranslationVector _etc
Definition: vpAfma4.h:149
double _joint_min[4]
Definition: vpAfma4.h:146
static const unsigned int njoint
Number of joint.
Definition: vpAfma4.h:138
Modelisation of Irisa's cylindrical robot named Afma4.
Definition: vpAfma4.h:108
void extract(vpRotationMatrix &R) const
friend std::ostream & operator<<(std::ostream &s, const vpArray2D< Type > &A)
Definition: vpArray2D.h:267
Implementation of a velocity twist matrix and operations on such kind of matrices.
void buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)
vpHomogeneousMatrix getForwardKinematics(const vpColVector &q) const
Definition: vpAfma4.cpp:148
vpRxyzVector _erc
Definition: vpAfma4.h:150
static double deg(double rad)
Definition: vpMath.h:97
Implementation of column vector and the associated operations.
Definition: vpColVector.h:72
vpColVector getJointMin() const
Definition: vpAfma4.cpp:558
vpHomogeneousMatrix inverse() const
void get_fJe_inverse(const vpColVector &q, vpMatrix &fJe_inverse) const
Definition: vpAfma4.cpp:522
Implementation of a rotation vector as Euler angle minimal representation.
Definition: vpRxyzVector.h:154
double _d3
Definition: vpAfma4.h:143
void get_fJe(const vpColVector &q, vpMatrix &fJe) const
Definition: vpAfma4.cpp:466