Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
vpViper850.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 850 robot.
32  *
33  * Authors:
34  * Fabien Spindler
35  *
36  *****************************************************************************/
37 
46 #include <visp3/core/vpDebug.h>
47 #include <visp3/robot/vpViper850.h>
48 #include <visp3/core/vpMath.h>
49 #include <visp3/core/vpXmlParserCamera.h>
50 
51 static const char *opt_viper850[] = {"CAMERA", "eMc_ROT_XYZ","eMc_TRANS_XYZ",
52  NULL};
53 
54 #ifdef VISP_HAVE_VIPER850_DATA
56  std::string(VISP_VIPER850_DATA_PATH) + std::string("/include/const_eMc_MarlinF033C_without_distortion_Viper850.cnf");
57 
59  std::string(VISP_VIPER850_DATA_PATH) + std::string("/include/const_eMc_MarlinF033C_with_distortion_Viper850.cnf");
60 
62  std::string(VISP_VIPER850_DATA_PATH) + std::string("/include/const_eMc_PTGreyFlea2_without_distortion_Viper850.cnf");
63 
65  std::string(VISP_VIPER850_DATA_PATH) + std::string("/include/const_eMc_PTGreyFlea2_with_distortion_Viper850.cnf");
66 
68  std::string(VISP_VIPER850_DATA_PATH) + std::string("/include/const_eMc_schunk_gripper_without_distortion_Viper850.cnf");
69 
71  std::string(VISP_VIPER850_DATA_PATH) + std::string("/include/const_eMc_schunk_gripper_with_distortion_Viper850.cnf");
72 
74  std::string(VISP_VIPER850_DATA_PATH) + std::string("/include/const_eMc_generic_without_distortion_Viper850.cnf");
75 
77  std::string(VISP_VIPER850_DATA_PATH) + std::string("/include/const_eMc_generic_with_distortion_Viper850.cnf");
78 
79 const std::string vpViper850::CONST_CAMERA_FILENAME =
80  std::string(VISP_VIPER850_DATA_PATH) + std::string("/include/const_camera_Viper850.xml");
81 
82 #endif // VISP_HAVE_VIPER850_DATA
83 
84 const char * const vpViper850::CONST_MARLIN_F033C_CAMERA_NAME = "Marlin-F033C-12mm";
85 const char * const vpViper850::CONST_PTGREY_FLEA2_CAMERA_NAME = "PTGrey-Flea2-6mm";
86 const char * const vpViper850::CONST_SCHUNK_GRIPPER_CAMERA_NAME = "Schunk-Gripper-PTGrey-Flea2-6mm";
87 const char * const vpViper850::CONST_GENERIC_CAMERA_NAME = "Generic-camera";
88 
90 
91 
92 
100  : tool_current(vpViper850::defaultTool), projModel(vpCameraParameters::perspectiveProjWithoutDistortion)
101 
102 {
103  // Denavit Hartenberg parameters
104  a1 = 0.075;
105  a2 = 0.365;
106  a3 = 0.090;
107  d1 = 0.335;
108  d4 = 0.405;
109  d6 = 0.080 + 0.1016; // To take into account the offset to go to the tool changer
110  c56 = -341.33 / 9102.22;
111 
112  // Software joint limits in radians
113  joint_min[0] = vpMath::rad(-170);
114  joint_min[1] = vpMath::rad(-190);
115  joint_min[2] = vpMath::rad(-29);
116  joint_min[3] = vpMath::rad(-190);
117  joint_min[4] = vpMath::rad(-120);
118  joint_min[5] = vpMath::rad(-360);
119  joint_max[0] = vpMath::rad(170);
120  joint_max[1] = vpMath::rad(45);
121  joint_max[2] = vpMath::rad(256);
122  joint_max[3] = vpMath::rad(190);
123  joint_max[4] = vpMath::rad(120);
124  joint_max[5] = vpMath::rad(360);
125 
126  init(); // Set the default tool
127 }
128 
133 void
135 {
137  return;
138 }
139 
149 void
150 vpViper850::init (const std::string &camera_extrinsic_parameters)
151 {
152  //vpTRACE ("Parse camera file \""%s\"".", camera_filename);
153  this->parseConfigFile (camera_extrinsic_parameters);
154 
155  return ;
156 }
157 
179 void
182 {
183 
184  this->projModel = proj_model;
185 
186 #ifdef VISP_HAVE_VIPER850_DATA
187  // Read the robot parameters from files
188  std::string filename_eMc;
189  switch (tool) {
191  switch(projModel) {
194  break;
197  break;
198  }
199  break;
200  }
202  switch(projModel) {
205  break;
208  break;
209  }
210  break;
211  }
213  switch(projModel) {
216  break;
219  break;
220  }
221  break;
222  }
224  switch(projModel) {
227  break;
230  break;
231  }
232  break;
233  }
236  "No predefined file available for a custom tool"
237  "You should use init(vpViper850::vpToolType, const std::string&) or"
238  "init(vpViper850::vpToolType, const vpHomogeneousMatrix&) instead");
239  }
240  default: {
241  vpERROR_TRACE ("This error should not occur!");
242  // vpERROR_TRACE ("Si elle survient malgre tout, c'est sans doute "
243  // "que les specs de la classe ont ete modifiee, "
244  // "et que le code n'a pas ete mis a jour "
245  // "correctement.");
246  // vpERROR_TRACE ("Verifiez les valeurs possibles du type "
247  // "vpViper850::vpViper850ToolType, et controlez que "
248  // "tous les cas ont ete pris en compte dans la "
249  // "fonction init(camera).");
250  break;
251  }
252  }
253 
254  this->init (filename_eMc);
255 
256 #else // VISP_HAVE_VIPER850_DATA
257 
258  // Use here default values of the robot constant parameters.
259  switch (tool) {
261  switch(projModel) {
263  erc[0] = vpMath::rad(0.07); // rx
264  erc[1] = vpMath::rad(2.76); // ry
265  erc[2] = vpMath::rad(-91.50); // rz
266  etc[0] = -0.0453; // tx
267  etc[1] = 0.0005; // ty
268  etc[2] = 0.0728; // tz
269  break;
271  erc[0] = vpMath::rad(0.26); // rx
272  erc[1] = vpMath::rad(2.12); // ry
273  erc[2] = vpMath::rad(-91.31); // rz
274  etc[0] = -0.0444; // tx
275  etc[1] = -0.0005; // ty
276  etc[2] = 0.1022; // tz
277  break;
278  }
279  break;
280  }
283  switch(projModel) {
285  erc[0] = vpMath::rad(0.15); // rx
286  erc[1] = vpMath::rad(1.28); // ry
287  erc[2] = vpMath::rad(-90.8); // rz
288  etc[0] = -0.0456; // tx
289  etc[1] = -0.0013; // ty
290  etc[2] = 0.001; // tz
291  break;
293  erc[0] = vpMath::rad(0.72); // rx
294  erc[1] = vpMath::rad(2.10); // ry
295  erc[2] = vpMath::rad(-90.5); // rz
296  etc[0] = -0.0444; // tx
297  etc[1] = -0.0012; // ty
298  etc[2] = 0.078; // tz
299  break;
300  }
301  break;
302  }
304  // Set eMc to identity
305  switch(projModel) {
308  erc[0] = 0; // rx
309  erc[1] = 0; // ry
310  erc[2] = 0; // rz
311  etc[0] = 0; // tx
312  etc[1] = 0; // ty
313  etc[2] = 0; // tz
314  break;
315  }
316  break;
317  }
320  "No predefined parameters available for a custom tool"
321  "You should use init(vpViper850::vpToolType, const std::string&) or"
322  "init(vpViper850::vpToolType, const vpHomogeneousMatrix&) instead");
323  }
324  }
325  vpRotationMatrix eRc(erc);
326  this->eMc.buildFrom(etc, eRc);
327 #endif // VISP_HAVE_VIPER850_DATA
328 
329  setToolType(tool);
330  return ;
331 }
332 
362 void
363 vpViper850::init(vpViper850::vpToolType tool, const std::string &filename)
364 {
365  this->setToolType(tool);
366  this->parseConfigFile(filename.c_str());
367 }
368 
383 void
385 {
386  this->setToolType(tool);
387  this->set_eMc(eMc_);
388 }
389 
398 void
399 vpViper850::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 
419  while (fgets(Ligne, FILENAME_MAX, fdtask) != NULL) {
420  numLn ++;
421  if ('#' == Ligne[0]) { continue; }
422  {
423  std::stringstream ss(Ligne);
424  ss >> namoption;
425 
426  if (ss.fail()) {
427  fclose (fdtask);
429  "Cannot parse configuration file %s to retrieve option name", filename.c_str()));
430  }
431  }
432 
433  dim = strlen(namoption);
434 
435  for (code = 0; NULL != opt_viper850[code]; ++ code) {
436  if (strncmp(opt_viper850[code], namoption, dim) == 0) {
437  break;
438  }
439  }
440 
441  switch(code) {
442  case 0:
443  break; // Nothing to do: camera name
444 
445  case 1: {
446  std::stringstream ss(Ligne);
447  ss >> namoption >> rot_eMc[0] >> rot_eMc[1] >> rot_eMc[2];
448  if (ss.fail()) {
449  fclose (fdtask);
451  "Cannot parse configuration file %s to retrieve rotation", filename.c_str()));
452  }
453 
454  // Convert rotation from degrees to radians
455  rot_eMc[0] *= M_PI / 180.0;
456  rot_eMc[1] *= M_PI / 180.0;
457  rot_eMc[2] *= M_PI / 180.0;
458  get_rot_eMc = true;
459  break;
460  }
461 
462  case 2: {
463  std::stringstream ss(Ligne);
464  ss >> namoption >> trans_eMc[0] >> trans_eMc[1] >> trans_eMc[2];
465  if (ss.fail()) {
466  fclose (fdtask);
468  "Cannot parse configuration file %s to retrieve translation", filename.c_str()));
469  }
470  get_trans_eMc = true;
471  break;
472  }
473  default:
474  vpERROR_TRACE ("Bad configuration file %s "
475  "ligne #%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 
563 void
565  const unsigned int &image_width,
566  const unsigned int &image_height) const
567 {
568 #if defined(VISP_HAVE_XML2) && defined (VISP_HAVE_VIPER850_DATA)
569  vpXmlParserCamera parser;
570  switch (getToolType()) {
572  std::cout << "Get camera parameters for camera \""
573  << vpViper850::CONST_MARLIN_F033C_CAMERA_NAME << "\"" << std::endl
574  << "from the XML file: \""
575  << vpViper850::CONST_CAMERA_FILENAME << "\""<< std::endl;
576  if (parser.parse(cam,
579  projModel,
580  image_width, image_height) != vpXmlParserCamera::SEQUENCE_OK) {
582  "Impossible to read the camera parameters.");
583  }
584  break;
585  }
587  std::cout << "Get camera parameters for camera \""
588  << vpViper850::CONST_PTGREY_FLEA2_CAMERA_NAME << "\"" << std::endl
589  << "from the XML file: \""
590  << vpViper850::CONST_CAMERA_FILENAME << "\""<< std::endl;
591  if (parser.parse(cam,
594  projModel,
595  image_width, image_height) != vpXmlParserCamera::SEQUENCE_OK) {
597  "Impossible to read the camera parameters.");
598  }
599  break;
600  }
602  std::cout << "Get camera parameters for camera \""
603  << vpViper850::CONST_SCHUNK_GRIPPER_CAMERA_NAME << "\"" << std::endl
604  << "from the XML file: \""
605  << vpViper850::CONST_CAMERA_FILENAME << "\""<< std::endl;
606  if (parser.parse(cam,
609  projModel,
610  image_width, image_height) != vpXmlParserCamera::SEQUENCE_OK) {
612  "Impossible to read the camera parameters.");
613  }
614  break;
615  }
617  std::cout << "Get camera parameters for camera \""
618  << vpViper850::CONST_GENERIC_CAMERA_NAME << "\"" << std::endl
619  << "from the XML file: \""
620  << vpViper850::CONST_CAMERA_FILENAME << "\""<< std::endl;
621  if (parser.parse(cam,
624  projModel,
625  image_width, image_height) != vpXmlParserCamera::SEQUENCE_OK) {
627  "Impossible to read the camera parameters.");
628  }
629  break;
630  }
633  "No intrinsic parameters available for a custom tool");
634  }
635  default: {
636  vpERROR_TRACE ("This error should not occur!");
637  // vpERROR_TRACE ("Si elle survient malgre tout, c'est sans doute "
638  // "que les specs de la classe ont ete modifiee, "
639  // "et que le code n'a pas ete mis a jour "
640  // "correctement.");
641  // vpERROR_TRACE ("Verifiez les valeurs possibles du type "
642  // "vpViper850::vpViper850ToolType, et controlez que "
643  // "tous les cas ont ete pris en compte dans la "
644  // "fonction init(camera).");
646  "Impossible to read the camera parameters.");
647  }
648  }
649 #else
650  // Set default parameters
651  switch (getToolType()) {
653  // Set default intrinsic camera parameters for 640x480 images
654  if (image_width == 640 && image_height == 480) {
655  std::cout << "Get default camera parameters for camera \""
656  << vpViper850::CONST_MARLIN_F033C_CAMERA_NAME << "\"" << std::endl;
657  switch(this->projModel) {
659  cam.initPersProjWithoutDistortion(1232.0, 1233.0, 317.7, 253.9);
660  break;
662  cam.initPersProjWithDistortion(1214.0, 1213.0, 323.1, 240.0, -0.1824, 0.1881);
663  break;
664  }
665  }
666  else {
667  vpTRACE("Cannot get default intrinsic camera parameters for this image resolution");
669  "Impossible to read the camera parameters.");
670  }
671  break;
672  }
675  // Set default intrinsic camera parameters for 640x480 images
676  if (image_width == 640 && image_height == 480) {
677  std::cout << "Get default camera parameters for camera \""
678  << vpViper850::CONST_PTGREY_FLEA2_CAMERA_NAME << "\"" << std::endl;
679  switch(this->projModel) {
681  cam.initPersProjWithoutDistortion(868.0, 869.0, 314.8, 254.1);
682  break;
684  cam.initPersProjWithDistortion(831.3, 831.6, 322.7, 265.8, -0.1955, 0.2047);
685  break;
686  }
687  }
688  else {
689  vpTRACE("Cannot get default intrinsic camera parameters for this image resolution");
691  "Impossible to read the camera parameters.");
692  }
693  break;
694  }
696  // Set default intrinsic camera parameters for 640x480 images
697  if (image_width == 640 && image_height == 480) {
698  std::cout << "Get default camera parameters for camera \""
699  << vpViper850::CONST_GENERIC_CAMERA_NAME << "\"" << std::endl;
700  switch(this->projModel) {
702  cam.initPersProjWithoutDistortion(868.0, 869.0, 314.8, 254.1);
703  break;
705  cam.initPersProjWithDistortion(831.3, 831.6, 322.7, 265.8, -0.1955, 0.2047);
706  break;
707  }
708  }
709  else {
710  vpTRACE("Cannot get default intrinsic camera parameters for this image resolution");
712  "Impossible to read the camera parameters.");
713  }
714  break;
715  }
718  "No intrinsic parameters available for a custom tool");
719  }
720  default:
721  vpERROR_TRACE ("This error should not occur!");
723  "Impossible to read the camera parameters.");
724  }
725 #endif
726  return;
727 }
728 
790 void
792  const vpImage<unsigned char> &I) const
793 {
795 }
858 void
860  const vpImage<vpRGBa> &I) const
861 {
863 }
double a3
for joint 3
Definition: vpViper.h:162
vpHomogeneousMatrix eMc
End effector to camera transformation.
Definition: vpViper.h:154
Error that can be emited by the vpRobot class and its derivates.
static const std::string CONST_EMC_PTGREY_FLEA2_WITH_DISTORTION_FILENAME
Definition: vpViper850.h:112
Perspective projection without distortion model.
void parseConfigFile(const std::string &filename)
Definition: vpViper850.cpp:399
static const vpToolType defaultTool
Default tool attached to the robot end effector.
Definition: vpViper850.h:137
unsigned int getWidth() const
Definition: vpImage.h:226
static const std::string CONST_EMC_GENERIC_WITH_DISTORTION_FILENAME
Definition: vpViper850.h:116
Implementation of an homogeneous matrix and operations on such kind of matrices.
void getCameraParameters(vpCameraParameters &cam, const unsigned int &image_width, const unsigned int &image_height) const
Definition: vpViper850.cpp:564
#define vpERROR_TRACE
Definition: vpDebug.h:391
static const std::string CONST_CAMERA_FILENAME
Definition: vpViper850.h:117
error that can be emited by ViSP classes.
Definition: vpException.h:73
vpRxyzVector erc
Definition: vpViper.h:157
static const char *const CONST_MARLIN_F033C_CAMERA_NAME
Definition: vpViper850.h:122
XML parser to load and save intrinsic camera parameters.
static const char *const CONST_SCHUNK_GRIPPER_CAMERA_NAME
Definition: vpViper850.h:124
double a2
for joint 2
Definition: vpViper.h:161
Implementation of a rotation matrix and operations on such kind of matrices.
static const std::string CONST_EMC_MARLIN_F033C_WITH_DISTORTION_FILENAME
Definition: vpViper850.h:110
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
void setToolType(vpViper850::vpToolType tool)
Set the current tool type.
Definition: vpViper850.h:176
vpTranslationVector etc
Definition: vpViper.h:156
virtual void set_eMc(const vpHomogeneousMatrix &eMc_)
Definition: vpViper.cpp:1279
#define vpTRACE
Definition: vpDebug.h:414
static const char *const CONST_GENERIC_CAMERA_NAME
Definition: vpViper850.h:125
vpColVector joint_max
Definition: vpViper.h:169
vpToolType
List of possible tools that can be attached to the robot end-effector.
Definition: vpViper850.h:128
static const std::string CONST_EMC_GENERIC_WITHOUT_DISTORTION_FILENAME
Definition: vpViper850.h:115
Generic class defining intrinsic camera parameters.
Modelisation of the ADEPT Viper 850 robot.
Definition: vpViper850.h:103
vpToolType getToolType() const
Get the current tool type.
Definition: vpViper850.h:165
static const std::string CONST_EMC_MARLIN_F033C_WITHOUT_DISTORTION_FILENAME
Definition: vpViper850.h:109
Perspective projection with distortion model.
void buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)
static double rad(double deg)
Definition: vpMath.h:104
static const std::string CONST_EMC_SCHUNK_GRIPPER_WITHOUT_DISTORTION_FILENAME
Definition: vpViper850.h:113
static const std::string CONST_EMC_PTGREY_FLEA2_WITHOUT_DISTORTION_FILENAME
Definition: vpViper850.h:111
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
vpCameraParameters::vpCameraParametersProjType projModel
Definition: vpViper850.h:185
void init(void)
Definition: vpViper850.cpp:134
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)
static const std::string CONST_EMC_SCHUNK_GRIPPER_WITH_DISTORTION_FILENAME
Definition: vpViper850.h:114
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 char *const CONST_PTGREY_FLEA2_CAMERA_NAME
Definition: vpViper850.h:123
double d6
for joint 6
Definition: vpViper.h:164
vpColVector joint_min
Definition: vpViper.h:170