Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
vpViper650.cpp
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2017 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 ADEPT Viper 650 robot.
32  *
33  * Authors:
34  * Fabien Spindler
35  *
36  *****************************************************************************/
37 
46 #include <visp3/core/vpDebug.h>
47 #include <visp3/robot/vpViper650.h>
48 #include <visp3/core/vpMath.h>
49 #include <visp3/core/vpXmlParserCamera.h>
50 
51 static const char *opt_viper650[] = {"CAMERA", "eMc_ROT_XYZ","eMc_TRANS_XYZ", NULL};
52 
53 #ifdef VISP_HAVE_VIPER650_DATA
55  std::string(VISP_VIPER650_DATA_PATH) + std::string("/include/const_eMc_MarlinF033C_without_distortion_Viper650.cnf");
56 
58  std::string(VISP_VIPER650_DATA_PATH) + std::string("/include/const_eMc_MarlinF033C_with_distortion_Viper650.cnf");
59 
61  std::string(VISP_VIPER650_DATA_PATH) + std::string("/include/const_eMc_PTGreyFlea2_without_distortion_Viper650.cnf");
62 
64  std::string(VISP_VIPER650_DATA_PATH) + std::string("/include/const_eMc_PTGreyFlea2_with_distortion_Viper650.cnf");
65 
67  std::string(VISP_VIPER650_DATA_PATH) + std::string("/include/const_eMc_schunk_gripper_without_distortion_Viper650.cnf");
68 
70  std::string(VISP_VIPER650_DATA_PATH) + std::string("/include/const_eMc_schunk_gripper_with_distortion_Viper650.cnf");
71 
73  std::string(VISP_VIPER650_DATA_PATH) + std::string("/include/const_eMc_generic_without_distortion_Viper650.cnf");
74 
76  std::string(VISP_VIPER650_DATA_PATH) + std::string("/include/const_eMc_generic_with_distortion_Viper650.cnf");
77 
78 const std::string vpViper650::CONST_CAMERA_FILENAME =
79  std::string(VISP_VIPER650_DATA_PATH) + std::string("/include/const_camera_Viper650.xml");
80 
81 #endif // VISP_HAVE_VIPER650_DATA
82 
83 const char * const vpViper650::CONST_MARLIN_F033C_CAMERA_NAME = "Marlin-F033C-12mm";
84 const char * const vpViper650::CONST_PTGREY_FLEA2_CAMERA_NAME = "PTGrey-Flea2-6mm";
85 const char * const vpViper650::CONST_SCHUNK_GRIPPER_CAMERA_NAME = "Schunk-Gripper-PTGrey-Flea2-6mm";
86 const char * const vpViper650::CONST_GENERIC_CAMERA_NAME = "Generic-camera";
87 
89 
90 
91 
99  : tool_current(vpViper650::defaultTool), projModel(vpCameraParameters::perspectiveProjWithoutDistortion)
100 {
101  // Denavit Hartenberg parameters
102  a1 = 0.075;
103  a2 = 0.270;
104  a3 = 0.090;
105  d1 = 0.335;
106  d4 = 0.295;
107  d6 = 0.080 + 0.1016; // To take into account the offset to go to the tool changer
108  c56 = -341.33 / 9102.22;
109 
110  // Software joint limits in radians
111  joint_min[0] = vpMath::rad(-170);
112  joint_min[1] = vpMath::rad(-190);
113  joint_min[2] = vpMath::rad(-29);
114  joint_min[3] = vpMath::rad(-190);
115  joint_min[4] = vpMath::rad(-120);
116  joint_min[5] = vpMath::rad(-360);
117  joint_max[0] = vpMath::rad(170);
118  joint_max[1] = vpMath::rad(45);
119  joint_max[2] = vpMath::rad(256);
120  joint_max[3] = vpMath::rad(190);
121  joint_max[4] = vpMath::rad(120);
122  joint_max[5] = vpMath::rad(360);
123 
124  init(); // Set the default tool
125 }
126 
131 void
133 {
135  return;
136 }
137 
147 void
148 vpViper650::init (const std::string &camera_extrinsic_parameters)
149 {
150  //vpTRACE ("Parse camera file \""%s\"".", camera_filename);
151  this->parseConfigFile (camera_extrinsic_parameters);
152 
153  return ;
154 }
155 
177 void
180 {
181 
182  this->projModel = proj_model;
183 
184 #ifdef VISP_HAVE_VIPER650_DATA
185  // Read the robot parameters from files
186  std::string filename_eMc;
187  switch (tool) {
189  switch(projModel) {
192  break;
195  break;
196  }
197  break;
198  }
200  switch(projModel) {
203  break;
206  break;
207  }
208  break;
209  }
211  switch(projModel) {
214  break;
217  break;
218  }
219  break;
220  }
222  switch(projModel) {
225  break;
228  break;
229  }
230  break;
231  }
234  "No predefined file available for a custom tool"
235  "You should use init(vpViper650::vpToolType, const std::string&) or"
236  "init(vpViper650::vpToolType, const vpHomogeneousMatrix&) instead");
237  }
238  default: {
239  vpERROR_TRACE ("This error should not occur!");
240  // vpERROR_TRACE ("Si elle survient malgre tout, c'est sans doute "
241  // "que les specs de la classe ont ete modifiee, "
242  // "et que le code n'a pas ete mis a jour "
243  // "correctement.");
244  // vpERROR_TRACE ("Verifiez les valeurs possibles du type "
245  // "vpViper650::vpViper650ToolType, et controlez que "
246  // "tous les cas ont ete pris en compte dans la "
247  // "fonction init(camera).");
248  break;
249  }
250  }
251 
252  this->init (filename_eMc);
253 
254 #else // VISP_HAVE_VIPER650_DATA
255 
256  // Use here default values of the robot constant parameters.
257  switch (tool) {
259  switch(projModel) {
261  erc[0] = vpMath::rad(0.07); // rx
262  erc[1] = vpMath::rad(2.76); // ry
263  erc[2] = vpMath::rad(-91.50); // rz
264  etc[0] = -0.0453; // tx
265  etc[1] = 0.0005; // ty
266  etc[2] = 0.0728; // tz
267  break;
269  erc[0] = vpMath::rad(0.26); // rx
270  erc[1] = vpMath::rad(2.12); // ry
271  erc[2] = vpMath::rad(-91.31); // rz
272  etc[0] = -0.0444; // tx
273  etc[1] = -0.0005; // ty
274  etc[2] = 0.1022; // tz
275  break;
276  }
277  break;
278  }
281  switch(projModel) {
283  erc[0] = vpMath::rad(0.15); // rx
284  erc[1] = vpMath::rad(1.28); // ry
285  erc[2] = vpMath::rad(-90.8); // rz
286  etc[0] = -0.0456; // tx
287  etc[1] = -0.0013; // ty
288  etc[2] = 0.001; // tz
289  break;
291  erc[0] = vpMath::rad(0.72); // rx
292  erc[1] = vpMath::rad(2.10); // ry
293  erc[2] = vpMath::rad(-90.5); // rz
294  etc[0] = -0.0444; // tx
295  etc[1] = -0.0012; // ty
296  etc[2] = 0.078; // tz
297  break;
298  }
299  break;
300  }
302  // Set eMc to identity
303  switch(projModel) {
306  erc[0] = 0; // rx
307  erc[1] = 0; // ry
308  erc[2] = 0; // rz
309  etc[0] = 0; // tx
310  etc[1] = 0; // ty
311  etc[2] = 0; // tz
312  break;
313  }
314  break;
315  }
318  "No predefined parameters available for a custom tool"
319  "You should use init(vpViper650::vpToolType, const std::string&) or"
320  "init(vpViper650::vpToolType, const vpHomogeneousMatrix&) instead");
321  }
322  }
323  vpRotationMatrix eRc(erc);
324  this->eMc.buildFrom(etc, eRc);
325 #endif // VISP_HAVE_VIPER650_DATA
326 
327  setToolType(tool);
328  return ;
329 }
330 
360 void
362  const std::string &filename)
363 {
364  this->setToolType(tool);
365  this->parseConfigFile(filename.c_str());
366 }
367 
382 void
384  const vpHomogeneousMatrix &eMc_)
385 {
386  this->setToolType(tool);
387  this->set_eMc(eMc_);
388 }
389 
398 void
399 vpViper650::parseConfigFile (const std::string &filename)
400 {
401  size_t dim;
402  int code;
403  char Ligne[FILENAME_MAX];
404  char namoption[100];
405  FILE * fdtask;
406  int numLn = 0;
407  vpRxyzVector rot_eMc; // rotation
408  vpTranslationVector trans_eMc; // translation
409  bool get_rot_eMc = false;
410  bool get_trans_eMc = false;
411 
412  //vpTRACE("Read the config file for constant parameters %s.", filename.c_str());
413  if ((fdtask = fopen(filename.c_str(), "r" )) == NULL) {
415  "Impossible to read the config file %s.", filename.c_str());
416  }
417 
418  while (fgets(Ligne, FILENAME_MAX, fdtask) != NULL) {
419  numLn ++;
420  if ('#' == Ligne[0]) { continue; }
421  {
422  std::stringstream ss(Ligne);
423  ss >> namoption;
424 
425  if (ss.fail()) {
426  fclose (fdtask);
428  "Cannot parse configuration file %s to retrieve option name"));
429  }
430  }
431 
432  dim = strlen(namoption);
433 
434  for (code = 0; NULL != opt_viper650[code]; ++ code) {
435  if (strncmp(opt_viper650[code], namoption, dim) == 0) {
436  break;
437  }
438  }
439 
440  switch(code) {
441  case 0:
442  break; // Nothing to do: camera name
443 
444  case 1: {
445  std::stringstream ss(Ligne);
446  ss >> namoption >> rot_eMc[0] >> rot_eMc[1] >> rot_eMc[2];
447  if (ss.fail()) {
448  fclose (fdtask);
450  "Cannot parse configuration file %s to retrieve rotation", filename.c_str()));
451  }
452 
453  // Convert rotation from degrees to radians
454  rot_eMc[0] *= M_PI / 180.0;
455  rot_eMc[1] *= M_PI / 180.0;
456  rot_eMc[2] *= M_PI / 180.0;
457  get_rot_eMc = true;
458  break;
459  }
460 
461  case 2: {
462  std::stringstream ss(Ligne);
463  ss >> namoption >> trans_eMc[0] >> trans_eMc[1] >> trans_eMc[2];
464  if (ss.fail()) {
465  fclose (fdtask);
467  "Cannot parse configuration file %s to retrieve translation", filename.c_str()));
468  }
469  get_trans_eMc = true;
470  break;
471  }
472 
473  default:
474  vpERROR_TRACE ("Bad configuration file %s "
475  "line #%d.", filename.c_str(), numLn);
476  } /* SWITCH */
477  } /* WHILE */
478 
479  fclose (fdtask);
480 
481  // Compute the eMc matrix from the translations and rotations
482  if (get_rot_eMc && get_trans_eMc) {
483  this->set_eMc(trans_eMc,rot_eMc);
484  }
485  else {
487  "Could not read translation and rotation parameters from config file %s", filename.c_str());
488  }
489 
490  return;
491 }
492 
493 
564 void
566  const unsigned int &image_width,
567  const unsigned int &image_height) const
568 {
569 #if defined(VISP_HAVE_XML2) && defined (VISP_HAVE_VIPER650_DATA)
570  vpXmlParserCamera parser;
571  switch (getToolType()) {
573  std::cout << "Get camera parameters for camera \""
574  << vpViper650::CONST_MARLIN_F033C_CAMERA_NAME << "\"" << std::endl
575  << "from the XML file: \""
576  << vpViper650::CONST_CAMERA_FILENAME << "\""<< std::endl;
577  if (parser.parse(cam,
580  projModel,
581  image_width, image_height) != vpXmlParserCamera::SEQUENCE_OK) {
583  "Impossible to read the camera parameters.");
584  }
585  break;
586  }
588  std::cout << "Get camera parameters for camera \""
589  << vpViper650::CONST_PTGREY_FLEA2_CAMERA_NAME << "\"" << std::endl
590  << "from the XML file: \""
591  << vpViper650::CONST_CAMERA_FILENAME << "\""<< std::endl;
592  if (parser.parse(cam,
595  projModel,
596  image_width, image_height) != vpXmlParserCamera::SEQUENCE_OK) {
598  "Impossible to read the camera parameters.");
599  }
600  break;
601  }
603  std::cout << "Get camera parameters for camera \""
604  << vpViper650::CONST_SCHUNK_GRIPPER_CAMERA_NAME << "\"" << std::endl
605  << "from the XML file: \""
606  << vpViper650::CONST_CAMERA_FILENAME << "\""<< std::endl;
607  if (parser.parse(cam,
610  projModel,
611  image_width, image_height) != vpXmlParserCamera::SEQUENCE_OK) {
613  "Impossible to read the camera parameters.");
614  }
615  break;
616  }
618  std::cout << "Get camera parameters for camera \""
619  << vpViper650::CONST_GENERIC_CAMERA_NAME << "\"" << std::endl
620  << "from the XML file: \""
621  << vpViper650::CONST_CAMERA_FILENAME << "\""<< std::endl;
622  if (parser.parse(cam,
625  projModel,
626  image_width, image_height) != vpXmlParserCamera::SEQUENCE_OK) {
628  "Impossible to read the camera parameters.");
629  }
630  break;
631  }
634  "No intrinsic parameters available for a custom tool");
635  }
636  default: {
637  vpERROR_TRACE ("This error should not occur!");
638  // vpERROR_TRACE ("Si elle survient malgre tout, c'est sans doute "
639  // "que les specs de la classe ont ete modifiee, "
640  // "et que le code n'a pas ete mis a jour "
641  // "correctement.");
642  // vpERROR_TRACE ("Verifiez les valeurs possibles du type "
643  // "vpViper650::vpViper650ToolType, et controlez que "
644  // "tous les cas ont ete pris en compte dans la "
645  // "fonction init(camera).");
647  "Impossible to read the camera parameters.");
648  }
649  }
650 #else
651  // Set default parameters
652  switch (getToolType()) {
654  // Set default intrinsic camera parameters for 640x480 images
655  if (image_width == 640 && image_height == 480) {
656  std::cout << "Get default camera parameters for camera \""
657  << vpViper650::CONST_MARLIN_F033C_CAMERA_NAME << "\"" << std::endl;
658  switch(this->projModel) {
660  cam.initPersProjWithoutDistortion(1232.0, 1233.0, 317.7, 253.9);
661  break;
663  cam.initPersProjWithDistortion(1214.0, 1213.0, 323.1, 240.0, -0.1824, 0.1881);
664  break;
665  }
666  }
667  else {
668  vpTRACE("Cannot get default intrinsic camera parameters for this image resolution");
670  "Impossible to read the camera parameters.");
671  }
672  break;
673  }
676  // Set default intrinsic camera parameters for 640x480 images
677  if (image_width == 640 && image_height == 480) {
678  std::cout << "Get default camera parameters for camera \""
679  << vpViper650::CONST_PTGREY_FLEA2_CAMERA_NAME << "\"" << std::endl;
680  switch(this->projModel) {
682  cam.initPersProjWithoutDistortion(868.0, 869.0, 314.8, 254.1);
683  break;
685  cam.initPersProjWithDistortion(831.3, 831.6, 322.7, 265.8, -0.1955, 0.2047);
686  break;
687  }
688  }
689  else {
690  vpTRACE("Cannot get default intrinsic camera parameters for this image resolution");
692  "Impossible to read the camera parameters.");
693  }
694  break;
695  }
697  // Set default intrinsic camera parameters for 640x480 images
698  if (image_width == 640 && image_height == 480) {
699  std::cout << "Get default camera parameters for camera \""
700  << vpViper650::CONST_GENERIC_CAMERA_NAME << "\"" << std::endl;
701  switch(this->projModel) {
703  cam.initPersProjWithoutDistortion(868.0, 869.0, 314.8, 254.1);
704  break;
706  cam.initPersProjWithDistortion(831.3, 831.6, 322.7, 265.8, -0.1955, 0.2047);
707  break;
708  }
709  }
710  else {
711  vpTRACE("Cannot get default intrinsic camera parameters for this image resolution");
713  "Impossible to read the camera parameters.");
714  }
715  break;
716  }
719  "No intrinsic parameters available for a custom tool");
720  }
721  default:
722  vpERROR_TRACE ("This error should not occur!");
724  "Impossible to read the camera parameters.");
725  break;
726  }
727 #endif
728  return;
729 }
730 
792 void
794  const vpImage<unsigned char> &I) const
795 {
797 }
860 void
862  const vpImage<vpRGBa> &I) const
863 {
865 }
double a3
for joint 3
Definition: vpViper.h:162
static const std::string CONST_EMC_GENERIC_WITH_DISTORTION_FILENAME
Definition: vpViper650.h:115
vpHomogeneousMatrix eMc
End effector to camera transformation.
Definition: vpViper.h:154
Error that can be emited by the vpRobot class and its derivates.
Perspective projection without distortion model.
unsigned int getWidth() const
Definition: vpImage.h:226
Implementation of an homogeneous matrix and operations on such kind of matrices.
#define vpERROR_TRACE
Definition: vpDebug.h:391
vpCameraParameters::vpCameraParametersProjType projModel
Definition: vpViper650.h:185
static const std::string CONST_EMC_GENERIC_WITHOUT_DISTORTION_FILENAME
Definition: vpViper650.h:114
static const std::string CONST_EMC_PTGREY_FLEA2_WITHOUT_DISTORTION_FILENAME
Definition: vpViper650.h:110
error that can be emited by ViSP classes.
Definition: vpException.h:73
vpToolType getToolType() const
Get the current tool type.
Definition: vpViper650.h:165
static const std::string CONST_EMC_PTGREY_FLEA2_WITH_DISTORTION_FILENAME
Definition: vpViper650.h:111
vpRxyzVector erc
Definition: vpViper.h:157
static const std::string CONST_EMC_SCHUNK_GRIPPER_WITH_DISTORTION_FILENAME
Definition: vpViper650.h:113
static const std::string CONST_EMC_MARLIN_F033C_WITHOUT_DISTORTION_FILENAME
Definition: vpViper650.h:108
XML parser to load and save intrinsic camera parameters.
double a2
for joint 2
Definition: vpViper.h:161
void getCameraParameters(vpCameraParameters &cam, const unsigned int &image_width, const unsigned int &image_height) const
Definition: vpViper650.cpp:565
Implementation of a rotation matrix and operations on such kind of matrices.
double d1
for joint 1
Definition: vpViper.h:160
void initPersProjWithoutDistortion(const double px, const double py, const double u0, const double v0)
double c56
Mechanical coupling between joint 5 and joint 6.
Definition: vpViper.h:166
double a1
Definition: vpViper.h:160
static const vpToolType defaultTool
Default tool attached to the robot end effector.
Definition: vpViper650.h:136
vpTranslationVector etc
Definition: vpViper.h:156
virtual void set_eMc(const vpHomogeneousMatrix &eMc_)
Definition: vpViper.cpp:1279
#define vpTRACE
Definition: vpDebug.h:414
vpColVector joint_max
Definition: vpViper.h:169
void parseConfigFile(const std::string &filename)
Definition: vpViper650.cpp:399
Generic class defining intrinsic camera parameters.
Modelisation of the ADEPT Viper 650 robot.
Definition: vpViper650.h:102
static const char *const CONST_MARLIN_F033C_CAMERA_NAME
Definition: vpViper650.h:121
void init(void)
Definition: vpViper650.cpp:132
vpToolType
List of possible tools that can be attached to the robot end-effector.
Definition: vpViper650.h:127
static const char *const CONST_PTGREY_FLEA2_CAMERA_NAME
Definition: vpViper650.h:122
Perspective projection with distortion model.
void buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)
static double rad(double deg)
Definition: vpMath.h:104
static const char *const CONST_SCHUNK_GRIPPER_CAMERA_NAME
Definition: vpViper650.h:123
static const std::string CONST_EMC_MARLIN_F033C_WITH_DISTORTION_FILENAME
Definition: vpViper650.h:109
unsigned int getHeight() const
Definition: vpImage.h:175
Implementation of a rotation vector as Euler angle minimal representation.
Definition: vpRxyzVector.h:154
double d4
for joint 4
Definition: vpViper.h:163
int parse(vpCameraParameters &cam, const std::string &filename, const std::string &camera_name, const vpCameraParameters::vpCameraParametersProjType &projModel, const unsigned int image_width=0, const unsigned int image_height=0)
void setToolType(vpViper650::vpToolType tool)
Set the current tool type.
Definition: vpViper650.h:176
static const char *const CONST_GENERIC_CAMERA_NAME
Definition: vpViper650.h:124
Class that consider the case of a translation vector.
void initPersProjWithDistortion(const double px, const double py, const double u0, const double v0, const double kud, const double kdu)
static const std::string CONST_EMC_SCHUNK_GRIPPER_WITHOUT_DISTORTION_FILENAME
Definition: vpViper650.h:112
static const std::string CONST_CAMERA_FILENAME
Definition: vpViper650.h:116
double d6
for joint 6
Definition: vpViper.h:164
vpColVector joint_min
Definition: vpViper.h:170