Visual Servoing Platform  version 3.3.0 under development (2020-02-17)
vpViper650.cpp
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2019 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * See the file LICENSE.txt at the root directory of this source
11  * distribution for additional information about the GNU GPL.
12  *
13  * For using ViSP with software that can not be combined with the GNU
14  * GPL, please contact Inria about acquiring a ViSP Professional
15  * Edition License.
16  *
17  * See http://visp.inria.fr for more information.
18  *
19  * This software was developed at:
20  * Inria Rennes - Bretagne Atlantique
21  * Campus Universitaire de Beaulieu
22  * 35042 Rennes Cedex
23  * France
24  *
25  * If you have questions regarding the use of this file, please contact
26  * Inria at visp@inria.fr
27  *
28  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30  *
31  * Description:
32  * Interface for the ADEPT Viper 650 robot.
33  *
34  * Authors:
35  * Fabien Spindler
36  *
37  *****************************************************************************/
38 
47 #include <visp3/core/vpDebug.h>
48 #include <visp3/core/vpMath.h>
49 #include <visp3/core/vpXmlParserCamera.h>
50 #include <visp3/robot/vpViper650.h>
51 
52 static const char *opt_viper650[] = {"CAMERA", "eMc_ROT_XYZ", "eMc_TRANS_XYZ", NULL};
53 
54 #ifdef VISP_HAVE_VIPER650_DATA
56  std::string(VISP_VIPER650_DATA_PATH) +
57  std::string("/include/const_eMc_MarlinF033C_without_distortion_Viper650.cnf");
58 
60  std::string(VISP_VIPER650_DATA_PATH) + std::string("/include/const_eMc_MarlinF033C_with_distortion_Viper650.cnf");
61 
63  std::string(VISP_VIPER650_DATA_PATH) +
64  std::string("/include/const_eMc_PTGreyFlea2_without_distortion_Viper650.cnf");
65 
67  std::string(VISP_VIPER650_DATA_PATH) + std::string("/include/const_eMc_PTGreyFlea2_with_distortion_Viper650.cnf");
68 
70  std::string(VISP_VIPER650_DATA_PATH) + std::string("/include/"
71  "const_eMc_schunk_gripper_without_distortion_Viper650."
72  "cnf");
73 
75  std::string(VISP_VIPER650_DATA_PATH) +
76  std::string("/include/const_eMc_schunk_gripper_with_distortion_Viper650.cnf");
77 
79  std::string(VISP_VIPER650_DATA_PATH) + std::string("/include/const_eMc_generic_without_distortion_Viper650.cnf");
80 
82  std::string(VISP_VIPER650_DATA_PATH) + std::string("/include/const_eMc_generic_with_distortion_Viper650.cnf");
83 
84 const std::string vpViper650::CONST_CAMERA_FILENAME =
85  std::string(VISP_VIPER650_DATA_PATH) + std::string("/include/const_camera_Viper650.xml");
86 
87 #endif // VISP_HAVE_VIPER650_DATA
88 
89 const char *const vpViper650::CONST_MARLIN_F033C_CAMERA_NAME = "Marlin-F033C-12mm";
90 const char *const vpViper650::CONST_PTGREY_FLEA2_CAMERA_NAME = "PTGrey-Flea2-6mm";
91 const char *const vpViper650::CONST_SCHUNK_GRIPPER_CAMERA_NAME = "Schunk-Gripper-PTGrey-Flea2-6mm";
92 const char *const vpViper650::CONST_GENERIC_CAMERA_NAME = "Generic-camera";
93 
95 
103  : tool_current(vpViper650::defaultTool), projModel(vpCameraParameters::perspectiveProjWithoutDistortion)
104 {
105  // Denavit Hartenberg parameters
106  a1 = 0.075;
107  a2 = 0.270;
108  a3 = 0.090;
109  d1 = 0.335;
110  d4 = 0.295;
111  d6 = 0.080 + 0.1016; // To take into account the offset to go to the tool changer
112  c56 = -341.33 / 9102.22;
113 
114  // Software joint limits in radians
115  joint_min[0] = vpMath::rad(-170);
116  joint_min[1] = vpMath::rad(-190);
117  joint_min[2] = vpMath::rad(-29);
118  joint_min[3] = vpMath::rad(-190);
119  joint_min[4] = vpMath::rad(-120);
120  joint_min[5] = vpMath::rad(-360);
121  joint_max[0] = vpMath::rad(170);
122  joint_max[1] = vpMath::rad(45);
123  joint_max[2] = vpMath::rad(256);
124  joint_max[3] = vpMath::rad(190);
125  joint_max[4] = vpMath::rad(120);
126  joint_max[5] = vpMath::rad(360);
127 
128  init(); // Set the default tool
129 }
130 
136 {
138  return;
139 }
140 
150 void vpViper650::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 
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 
361 void vpViper650::init(vpViper650::vpToolType tool, const std::string &filename)
362 {
363  this->setToolType(tool);
364  this->parseConfigFile(filename.c_str());
365 }
366 
383 {
384  this->setToolType(tool);
385  this->set_eMc(eMc_);
386 }
387 
396 void vpViper650::parseConfigFile(const std::string &filename)
397 {
398  vpRxyzVector erc_; // eMc rotation
399  vpTranslationVector etc_; // eMc translation
400 
401  std::ifstream fdconfig(filename.c_str(), std::ios::in);
402 
403  if (!fdconfig.is_open()) {
404  throw vpRobotException(vpRobotException::readingParametersError, "Impossible to read the config file: %s",
405  filename.c_str());
406  }
407 
408  std::string line;
409  int lineNum = 0;
410  bool get_erc = false;
411  bool get_etc = false;
412  int code;
413 
414  while (std::getline(fdconfig, line)) {
415  lineNum++;
416  if ((line.compare(0, 1, "#") == 0) || line.empty()) { // skip comment or empty line
417  continue;
418  }
419  std::istringstream ss(line);
420  std::string key;
421  ss >> key;
422 
423  for (code = 0; NULL != opt_viper650[code]; ++code) {
424  if (key.compare(opt_viper650[code]) == 0) {
425  break;
426  }
427  }
428 
429  switch (code) {
430  case 0:
431  break; // Nothing to do: camera name
432 
433  case 1: {
434  ss >> erc_[0] >> erc_[1] >> erc_[2];
435 
436  // Convert rotation from degrees to radians
437  erc_ = erc_ * M_PI / 180.0;
438  get_erc = true;
439  break;
440  }
441 
442  case 2: {
443  ss >> etc[0] >> etc[1] >> etc[2];
444  get_etc = true;
445  break;
446  }
447 
448  default:
449  throw(vpRobotException(vpRobotException::readingParametersError, "Bad configuration file %s line #%d",
450  filename.c_str(), lineNum));
451  }
452  }
453 
454  fdconfig.close();
455 
456  // Compute the eMc matrix from the translations and rotations
457  if (get_etc && get_erc) {
458  this->set_eMc(etc_, erc_);
459  } else {
461  "Could not read translation and rotation "
462  "parameters from config file %s",
463  filename.c_str());
464  }
465 }
466 
538 void vpViper650::getCameraParameters(vpCameraParameters &cam, const unsigned int &image_width,
539  const unsigned int &image_height) const
540 {
541 #if defined(VISP_HAVE_PUGIXML) && defined(VISP_HAVE_VIPER650_DATA)
542  vpXmlParserCamera parser;
543  switch (getToolType()) {
545  std::cout << "Get camera parameters for camera \"" << vpViper650::CONST_MARLIN_F033C_CAMERA_NAME << "\""
546  << std::endl
547  << "from the XML file: \"" << vpViper650::CONST_CAMERA_FILENAME << "\"" << std::endl;
549  image_width, image_height) != vpXmlParserCamera::SEQUENCE_OK) {
550  throw vpRobotException(vpRobotException::readingParametersError, "Impossible to read the camera parameters.");
551  }
552  break;
553  }
555  std::cout << "Get camera parameters for camera \"" << vpViper650::CONST_PTGREY_FLEA2_CAMERA_NAME << "\""
556  << std::endl
557  << "from the XML file: \"" << vpViper650::CONST_CAMERA_FILENAME << "\"" << std::endl;
559  image_width, image_height) != vpXmlParserCamera::SEQUENCE_OK) {
560  throw vpRobotException(vpRobotException::readingParametersError, "Impossible to read the camera parameters.");
561  }
562  break;
563  }
565  std::cout << "Get camera parameters for camera \"" << vpViper650::CONST_SCHUNK_GRIPPER_CAMERA_NAME << "\""
566  << std::endl
567  << "from the XML file: \"" << vpViper650::CONST_CAMERA_FILENAME << "\"" << std::endl;
569  image_width, image_height) != vpXmlParserCamera::SEQUENCE_OK) {
570  throw vpRobotException(vpRobotException::readingParametersError, "Impossible to read the camera parameters.");
571  }
572  break;
573  }
575  std::cout << "Get camera parameters for camera \"" << vpViper650::CONST_GENERIC_CAMERA_NAME << "\"" << std::endl
576  << "from the XML file: \"" << vpViper650::CONST_CAMERA_FILENAME << "\"" << std::endl;
578  image_width, image_height) != vpXmlParserCamera::SEQUENCE_OK) {
579  throw vpRobotException(vpRobotException::readingParametersError, "Impossible to read the camera parameters.");
580  }
581  break;
582  }
584  throw vpRobotException(vpRobotException::badValue, "No intrinsic parameters available for a custom tool");
585  }
586  default: {
587  vpERROR_TRACE("This error should not occur!");
588  // vpERROR_TRACE ("Si elle survient malgre tout, c'est sans doute "
589  // "que les specs de la classe ont ete modifiee, "
590  // "et que le code n'a pas ete mis a jour "
591  // "correctement.");
592  // vpERROR_TRACE ("Verifiez les valeurs possibles du type "
593  // "vpViper650::vpViper650ToolType, et controlez que "
594  // "tous les cas ont ete pris en compte dans la "
595  // "fonction init(camera).");
596  throw vpRobotException(vpRobotException::readingParametersError, "Impossible to read the camera parameters.");
597  }
598  }
599 #else
600  // Set default parameters
601  switch (getToolType()) {
603  // Set default intrinsic camera parameters for 640x480 images
604  if (image_width == 640 && image_height == 480) {
605  std::cout << "Get default camera parameters for camera \"" << vpViper650::CONST_MARLIN_F033C_CAMERA_NAME << "\""
606  << std::endl;
607  switch (this->projModel) {
609  cam.initPersProjWithoutDistortion(1232.0, 1233.0, 317.7, 253.9);
610  break;
612  cam.initPersProjWithDistortion(1214.0, 1213.0, 323.1, 240.0, -0.1824, 0.1881);
613  break;
614  }
615  } else {
616  vpTRACE("Cannot get default intrinsic camera parameters for this image "
617  "resolution");
618  throw vpRobotException(vpRobotException::readingParametersError, "Impossible to read the camera parameters.");
619  }
620  break;
621  }
624  // Set default intrinsic camera parameters for 640x480 images
625  if (image_width == 640 && image_height == 480) {
626  std::cout << "Get default camera parameters for camera \"" << vpViper650::CONST_PTGREY_FLEA2_CAMERA_NAME << "\""
627  << std::endl;
628  switch (this->projModel) {
630  cam.initPersProjWithoutDistortion(868.0, 869.0, 314.8, 254.1);
631  break;
633  cam.initPersProjWithDistortion(831.3, 831.6, 322.7, 265.8, -0.1955, 0.2047);
634  break;
635  }
636  } else {
637  vpTRACE("Cannot get default intrinsic camera parameters for this image "
638  "resolution");
639  throw vpRobotException(vpRobotException::readingParametersError, "Impossible to read the camera parameters.");
640  }
641  break;
642  }
644  // Set default intrinsic camera parameters for 640x480 images
645  if (image_width == 640 && image_height == 480) {
646  std::cout << "Get default camera parameters for camera \"" << vpViper650::CONST_GENERIC_CAMERA_NAME << "\""
647  << std::endl;
648  switch (this->projModel) {
650  cam.initPersProjWithoutDistortion(868.0, 869.0, 314.8, 254.1);
651  break;
653  cam.initPersProjWithDistortion(831.3, 831.6, 322.7, 265.8, -0.1955, 0.2047);
654  break;
655  }
656  } else {
657  vpTRACE("Cannot get default intrinsic camera parameters for this image "
658  "resolution");
659  throw vpRobotException(vpRobotException::readingParametersError, "Impossible to read the camera parameters.");
660  }
661  break;
662  }
664  throw vpRobotException(vpRobotException::badValue, "No intrinsic parameters available for a custom tool");
665  }
666  }
667 #endif
668  return;
669 }
670 
734 {
735  getCameraParameters(cam, I.getWidth(), I.getHeight());
736 }
801 {
802  getCameraParameters(cam, I.getWidth(), I.getHeight());
803 }
Used to indicate that a value is not in the allowed range.
Definition: vpException.h:97
double a3
for joint 3
Definition: vpViper.h:165
static const std::string CONST_EMC_GENERIC_WITH_DISTORTION_FILENAME
Definition: vpViper650.h:115
vpHomogeneousMatrix eMc
End effector to camera transformation.
Definition: vpViper.h:157
Error that can be emited by the vpRobot class and its derivates.
Implementation of an homogeneous matrix and operations on such kind of matrices.
#define vpERROR_TRACE
Definition: vpDebug.h:393
vpCameraParameters::vpCameraParametersProjType projModel
Definition: vpViper650.h:176
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
static const std::string CONST_EMC_PTGREY_FLEA2_WITH_DISTORTION_FILENAME
Definition: vpViper650.h:111
vpRxyzVector erc
Definition: vpViper.h:160
static const std::string CONST_EMC_SCHUNK_GRIPPER_WITH_DISTORTION_FILENAME
Definition: vpViper650.h:113
void getCameraParameters(vpCameraParameters &cam, const unsigned int &image_width, const unsigned int &image_height) const
Definition: vpViper650.cpp:538
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:164
void initPersProjWithDistortion(double px, double py, double u0, double v0, double kud, double kdu)
Implementation of a rotation matrix and operations on such kind of matrices.
double d1
for joint 1
Definition: vpViper.h:163
double c56
Mechanical coupling between joint 5 and joint 6.
Definition: vpViper.h:169
double a1
Definition: vpViper.h:163
static const vpToolType defaultTool
Default tool attached to the robot end effector.
Definition: vpViper650.h:136
vpTranslationVector etc
Definition: vpViper.h:159
virtual void set_eMc(const vpHomogeneousMatrix &eMc_)
Definition: vpViper.cpp:1230
#define vpTRACE
Definition: vpDebug.h:416
vpColVector joint_max
Definition: vpViper.h:172
void parseConfigFile(const std::string &filename)
Definition: vpViper650.cpp:396
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:135
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
void buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)
static double rad(double deg)
Definition: vpMath.h:108
static const char *const CONST_SCHUNK_GRIPPER_CAMERA_NAME
Definition: vpViper650.h:123
int parse(vpCameraParameters &cam, const std::string &filename, const std::string &camera_name, const vpCameraParameters::vpCameraParametersProjType &projModel, unsigned int image_width=0, unsigned int image_height=0)
void initPersProjWithoutDistortion(double px, double py, double u0, double v0)
unsigned int getHeight() const
Definition: vpImage.h:186
static const std::string CONST_EMC_MARLIN_F033C_WITH_DISTORTION_FILENAME
Definition: vpViper650.h:109
Implementation of a rotation vector as Euler angle minimal representation.
Definition: vpRxyzVector.h:183
double d4
for joint 4
Definition: vpViper.h:166
void setToolType(vpViper650::vpToolType tool)
Set the current tool type.
Definition: vpViper650.h:169
static const char *const CONST_GENERIC_CAMERA_NAME
Definition: vpViper650.h:124
unsigned int getWidth() const
Definition: vpImage.h:244
vpToolType getToolType() const
Get the current tool type.
Definition: vpViper650.h:160
Class that consider the case of a translation vector.
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:167
vpColVector joint_min
Definition: vpViper.h:173