Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpViper650.cpp
1/*
2 * ViSP, open source Visual Servoing Platform software.
3 * Copyright (C) 2005 - 2025 by Inria. All rights reserved.
4 *
5 * This software is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 https://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
41
42#include <visp3/core/vpDebug.h>
43#include <visp3/core/vpMath.h>
44#include <visp3/core/vpXmlParserCamera.h>
45#include <visp3/robot/vpViper650.h>
46
47static const char *opt_viper650[] = { "CAMERA", "eMc_ROT_XYZ", "eMc_TRANS_XYZ", nullptr };
48
50#ifdef VISP_HAVE_VIPER650_DATA
52std::string(VISP_VIPER650_DATA_PATH) +
53std::string("/include/const_eMc_MarlinF033C_without_distortion_Viper650.cnf");
54
56std::string(VISP_VIPER650_DATA_PATH) + std::string("/include/const_eMc_MarlinF033C_with_distortion_Viper650.cnf");
57
59std::string(VISP_VIPER650_DATA_PATH) +
60std::string("/include/const_eMc_PTGreyFlea2_without_distortion_Viper650.cnf");
61
63std::string(VISP_VIPER650_DATA_PATH) + std::string("/include/const_eMc_PTGreyFlea2_with_distortion_Viper650.cnf");
64
66std::string(VISP_VIPER650_DATA_PATH) + std::string("/include/"
67 "const_eMc_schunk_gripper_without_distortion_Viper650."
68 "cnf");
69
71std::string(VISP_VIPER650_DATA_PATH) +
72std::string("/include/const_eMc_schunk_gripper_with_distortion_Viper650.cnf");
73
75std::string(VISP_VIPER650_DATA_PATH) + std::string("/include/const_eMc_generic_without_distortion_Viper650.cnf");
76
78std::string(VISP_VIPER650_DATA_PATH) + std::string("/include/const_eMc_generic_with_distortion_Viper650.cnf");
79
80const std::string vpViper650::CONST_CAMERA_FILENAME =
81std::string(VISP_VIPER650_DATA_PATH) + std::string("/include/const_camera_Viper650.xml");
82
83#endif // VISP_HAVE_VIPER650_DATA
84
85const char *const vpViper650::CONST_MARLIN_F033C_CAMERA_NAME = "Marlin-F033C-12mm";
86const char *const vpViper650::CONST_PTGREY_FLEA2_CAMERA_NAME = "PTGrey-Flea2-6mm";
87const char *const vpViper650::CONST_SCHUNK_GRIPPER_CAMERA_NAME = "Schunk-Gripper-PTGrey-Flea2-6mm";
88const char *const vpViper650::CONST_GENERIC_CAMERA_NAME = "Generic-camera";
89
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
132{
134 return;
135}
136
146void vpViper650::init(const std::string &camera_extrinsic_parameters)
147{
148 // vpTRACE ("Parse camera file \""%s\"".", camera_filename);
149 this->parseConfigFile(camera_extrinsic_parameters);
150
151 return;
152}
153
176{
177
178 this->projModel = proj_model;
179
180#ifdef VISP_HAVE_VIPER650_DATA
181 // Read the robot parameters from files
182 std::string filename_eMc;
183 switch (tool) {
185 switch (projModel) {
188 break;
191 break;
194 "Feature TOOL_MARLIN_F033C_CAMERA is not implemented for Kannala-Brandt projection model yet.");
195 }
196 break;
197 }
199 switch (projModel) {
202 break;
205 break;
208 "Feature TOOL_PTGREY_FLEA2_CAMERA is not implemented for Kannala-Brandt projection model yet.");
209 }
210 break;
211 }
213 switch (projModel) {
216 break;
219 break;
221 throw vpException(
223 "Feature TOOL_SCHUNK_GRIPPER_CAMERA is not implemented for Kannala-Brandt projection model yet.");
224 }
225 break;
226 }
228 switch (projModel) {
231 break;
234 break;
237 "Feature TOOL_GENERIC_CAMERA is not implemented for Kannala-Brandt projection model yet.");
238 }
239 break;
240 }
243 "No predefined file available for a custom tool"
244 "You should use init(vpViper650::vpToolType, const std::string&) or"
245 "init(vpViper650::vpToolType, const vpHomogeneousMatrix&) instead");
246 }
247 default: {
248 vpERROR_TRACE("This error should not occur!");
249 break;
250 }
251 }
252
253 this->init(filename_eMc);
254
255#else // VISP_HAVE_VIPER650_DATA
256
257 // Use here default values of the robot constant parameters.
258 switch (tool) {
260 switch (projModel) {
262 erc[0] = vpMath::rad(0.07); // rx
263 erc[1] = vpMath::rad(2.76); // ry
264 erc[2] = vpMath::rad(-91.50); // rz
265 etc[0] = -0.0453; // tx
266 etc[1] = 0.0005; // ty
267 etc[2] = 0.0728; // tz
268 break;
270 erc[0] = vpMath::rad(0.26); // rx
271 erc[1] = vpMath::rad(2.12); // ry
272 erc[2] = vpMath::rad(-91.31); // rz
273 etc[0] = -0.0444; // tx
274 etc[1] = -0.0005; // ty
275 etc[2] = 0.1022; // tz
276 break;
278 default:
280 "Feature TOOL_MARLIN_F033C_CAMERA is not implemented for Kannala-Brandt projection model yet.");
281 }
282 break;
283 }
286 switch (projModel) {
288 erc[0] = vpMath::rad(0.15); // rx
289 erc[1] = vpMath::rad(1.28); // ry
290 erc[2] = vpMath::rad(-90.8); // rz
291 etc[0] = -0.0456; // tx
292 etc[1] = -0.0013; // ty
293 etc[2] = 0.001; // tz
294 break;
296 erc[0] = vpMath::rad(0.72); // rx
297 erc[1] = vpMath::rad(2.10); // ry
298 erc[2] = vpMath::rad(-90.5); // rz
299 etc[0] = -0.0444; // tx
300 etc[1] = -0.0012; // ty
301 etc[2] = 0.078; // tz
302 break;
304 default:
306 "Feature TOOL_PTGREY_FLEA2_CAMERA is not implemented for Kannala-Brandt projection model yet.");
307 }
308 break;
309 }
311 // Set eMc to identity
312 switch (projModel) {
315 erc[0] = 0; // rx
316 erc[1] = 0; // ry
317 erc[2] = 0; // rz
318 etc[0] = 0; // tx
319 etc[1] = 0; // ty
320 etc[2] = 0; // tz
321 break;
323 default:
325 "Feature TOOL_GENERIC_CAMERA is not implemented for Kannala-Brandt projection model yet.");
326 }
327 break;
328 }
331 "No predefined parameters available for a custom tool"
332 "You should use init(vpViper650::vpToolType, const std::string&) or"
333 "init(vpViper650::vpToolType, const vpHomogeneousMatrix&) instead");
334 }
335 default:
336 throw vpRobotException(vpRobotException::badValue, "No extrinsic parameters available for viper 850 specified tool");
337 }
339 this->eMc.buildFrom(etc, eRc);
340#endif // VISP_HAVE_VIPER650_DATA
341
342 setToolType(tool);
343 return;
344}
345
374void vpViper650::init(vpViper650::vpToolType tool, const std::string &filename)
375{
376 this->setToolType(tool);
377 this->parseConfigFile(filename.c_str());
378}
379
396{
397 this->setToolType(tool);
398 this->set_eMc(eMc_);
399}
400
409void vpViper650::parseConfigFile(const std::string &filename)
410{
411 vpRxyzVector erc_; // eMc rotation
412 vpTranslationVector etc_; // eMc translation
413
414 std::ifstream fdconfig(filename.c_str(), std::ios::in);
415
416 if (!fdconfig.is_open()) {
417 throw vpRobotException(vpRobotException::readingParametersError, "Impossible to read the config file: %s",
418 filename.c_str());
419 }
420
421 std::string line;
422 int lineNum = 0;
423 bool get_erc = false;
424 bool get_etc = false;
425 int code;
426
427 while (std::getline(fdconfig, line)) {
428 lineNum++;
429 if ((line.compare(0, 1, "#") == 0) || line.empty()) { // skip comment or empty line
430 continue;
431 }
432 std::istringstream ss(line);
433 std::string key;
434 ss >> key;
435
436 for (code = 0; nullptr != opt_viper650[code]; ++code) {
437 if (key.compare(opt_viper650[code]) == 0) {
438 break;
439 }
440 }
441
442 switch (code) {
443 case 0:
444 break; // Nothing to do: camera name
445
446 case 1: {
447 ss >> erc_[0] >> erc_[1] >> erc_[2];
448
449 // Convert rotation from degrees to radians
450 erc_ = erc_ * M_PI / 180.0;
451 get_erc = true;
452 break;
453 }
454
455 case 2: {
456 ss >> etc_[0] >> etc_[1] >> etc_[2];
457 get_etc = true;
458 break;
459 }
460
461 default:
462 throw(vpRobotException(vpRobotException::readingParametersError, "Bad configuration file %s line #%d",
463 filename.c_str(), lineNum));
464 }
465 }
466 fdconfig.close();
467
468 // Compute the eMc matrix from the translations and rotations
469 if (get_etc && get_erc) {
470 this->set_eMc(etc_, erc_);
471 }
472 else {
474 "Could not read translation and rotation "
475 "parameters from config file %s",
476 filename.c_str());
477 }
478}
479
552
553void vpViper650::getCameraParameters(vpCameraParameters &cam, const unsigned int &image_width,
554 const unsigned int &image_height) const
555{
556#if defined(VISP_HAVE_VIPER650_DATA) && defined(VISP_HAVE_PUGIXML)
557 vpXmlParserCamera parser;
558 switch (getToolType()) {
560 std::cout << "Get camera parameters for camera \"" << vpViper650::CONST_MARLIN_F033C_CAMERA_NAME << "\""
561 << std::endl
562 << "from the XML file: \"" << vpViper650::CONST_CAMERA_FILENAME << "\"" << std::endl;
564 image_width, image_height) != vpXmlParserCamera::SEQUENCE_OK) {
565 throw vpRobotException(vpRobotException::readingParametersError, "Impossible to read the camera parameters.");
566 }
567 break;
568 }
570 std::cout << "Get camera parameters for camera \"" << vpViper650::CONST_PTGREY_FLEA2_CAMERA_NAME << "\""
571 << std::endl
572 << "from the XML file: \"" << vpViper650::CONST_CAMERA_FILENAME << "\"" << std::endl;
574 image_width, image_height) != vpXmlParserCamera::SEQUENCE_OK) {
575 throw vpRobotException(vpRobotException::readingParametersError, "Impossible to read the camera parameters.");
576 }
577 break;
578 }
580 std::cout << "Get camera parameters for camera \"" << vpViper650::CONST_SCHUNK_GRIPPER_CAMERA_NAME << "\""
581 << std::endl
582 << "from the XML file: \"" << vpViper650::CONST_CAMERA_FILENAME << "\"" << std::endl;
584 image_width, image_height) != vpXmlParserCamera::SEQUENCE_OK) {
585 throw vpRobotException(vpRobotException::readingParametersError, "Impossible to read the camera parameters.");
586 }
587 break;
588 }
590 std::cout << "Get camera parameters for camera \"" << vpViper650::CONST_GENERIC_CAMERA_NAME << "\"" << std::endl
591 << "from the XML file: \"" << vpViper650::CONST_CAMERA_FILENAME << "\"" << std::endl;
593 image_width, image_height) != vpXmlParserCamera::SEQUENCE_OK) {
594 throw vpRobotException(vpRobotException::readingParametersError, "Impossible to read the camera parameters.");
595 }
596 break;
597 }
599 throw vpRobotException(vpRobotException::badValue, "No intrinsic parameters available for a custom tool");
600 }
601 default: {
602 vpERROR_TRACE("This error should not occur!");
603 // vpERROR_TRACE ("Si elle survient malgre tout, c'est sans doute "
604 // "que les specs de la classe ont ete modifiee, "
605 // "et que le code n'a pas ete mis a jour "
606 // "correctement.");
607 // vpERROR_TRACE ("Verifiez les valeurs possibles du type "
608 // "vpViper650::vpViper650ToolType, et controlez que "
609 // "tous les cas ont ete pris en compte dans la "
610 // "fonction init(camera).");
611 throw vpRobotException(vpRobotException::readingParametersError, "Impossible to read the camera parameters.");
612 }
613 }
614#else
615 // Set default parameters
616 switch (getToolType()) {
618 // Set default intrinsic camera parameters for 640x480 images
619 if (image_width == 640 && image_height == 480) {
620 std::cout << "Get default camera parameters for camera \"" << vpViper650::CONST_MARLIN_F033C_CAMERA_NAME << "\""
621 << std::endl;
622 switch (this->projModel) {
624 cam.initPersProjWithoutDistortion(1232.0, 1233.0, 317.7, 253.9);
625 break;
627 cam.initPersProjWithDistortion(1214.0, 1213.0, 323.1, 240.0, -0.1824, 0.1881);
628 break;
630 default:
632 "Feature getCameraParameters is not implemented for Kannala-Brandt projection model yet.");
633 }
634 }
635 else {
636 vpTRACE("Cannot get default intrinsic camera parameters for this image "
637 "resolution");
638 throw vpRobotException(vpRobotException::readingParametersError, "Impossible to read the camera parameters.");
639 }
640 break;
641 }
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_PTGREY_FLEA2_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;
656 default:
658 "Feature getCameraParameters is not implemented for Kannala-Brandt projection model yet.");
659 }
660 }
661 else {
662 vpTRACE("Cannot get default intrinsic camera parameters for this image "
663 "resolution");
664 throw vpRobotException(vpRobotException::readingParametersError, "Impossible to read the camera parameters.");
665 }
666 break;
667 }
669 // Set default intrinsic camera parameters for 640x480 images
670 if (image_width == 640 && image_height == 480) {
671 std::cout << "Get default camera parameters for camera \"" << vpViper650::CONST_GENERIC_CAMERA_NAME << "\""
672 << std::endl;
673 switch (this->projModel) {
675 cam.initPersProjWithoutDistortion(868.0, 869.0, 314.8, 254.1);
676 break;
678 cam.initPersProjWithDistortion(831.3, 831.6, 322.7, 265.8, -0.1955, 0.2047);
679 break;
681 default:
683 "Feature getCameraParameters is not implemented for Kannala-Brandt projection model yet.");
684 }
685 }
686 else {
687 vpTRACE("Cannot get default intrinsic camera parameters for this image "
688 "resolution");
689 throw vpRobotException(vpRobotException::readingParametersError, "Impossible to read the camera parameters.");
690 }
691 break;
692 }
694 throw vpRobotException(vpRobotException::badValue, "No intrinsic parameters available for a custom tool");
695 }
696 default:
697 throw vpRobotException(vpRobotException::badValue, "No intrinsic parameters available for viper 850 specified tool");
698 }
699#endif
700 return;
701}
702
767{
768 getCameraParameters(cam, I.getWidth(), I.getHeight());
769}
770
834
836{
837 getCameraParameters(cam, I.getWidth(), I.getHeight());
838}
839END_VISP_NAMESPACE
Generic class defining intrinsic camera parameters.
@ perspectiveProjWithDistortion
Perspective projection with distortion model.
@ ProjWithKannalaBrandtDistortion
Projection with Kannala-Brandt distortion model.
@ perspectiveProjWithoutDistortion
Perspective projection without distortion model.
error that can be emitted by ViSP classes.
Definition vpException.h:60
@ badValue
Used to indicate that a value is not in the allowed range.
Definition vpException.h:73
@ notImplementedError
Not implemented.
Definition vpException.h:69
Implementation of an homogeneous matrix and operations on such kind of matrices.
Definition of the vpImage class member functions.
Definition vpImage.h:131
static double rad(double deg)
Definition vpMath.h:129
Error that can be emitted by the vpRobot class and its derivatives.
@ readingParametersError
Cannot parse parameters.
Implementation of a rotation matrix and operations on such kind of matrices.
Implementation of a rotation vector as Euler angle minimal representation.
Class that consider the case of a translation vector.
static const std::string CONST_EMC_GENERIC_WITHOUT_DISTORTION_FILENAME
Definition vpViper650.h:106
static const char *const CONST_PTGREY_FLEA2_CAMERA_NAME
Definition vpViper650.h:114
vpCameraParameters::vpCameraParametersProjType projModel
Definition vpViper650.h:168
static const std::string CONST_EMC_SCHUNK_GRIPPER_WITHOUT_DISTORTION_FILENAME
Definition vpViper650.h:104
static const vpToolType defaultTool
Default tool attached to the robot end effector.
Definition vpViper650.h:129
static const std::string CONST_EMC_SCHUNK_GRIPPER_WITH_DISTORTION_FILENAME
Definition vpViper650.h:105
vpToolType getToolType() const
Get the current tool type.
Definition vpViper650.h:152
vpToolType tool_current
Current tool in use.
Definition vpViper650.h:166
static const std::string CONST_EMC_GENERIC_WITH_DISTORTION_FILENAME
Definition vpViper650.h:107
void parseConfigFile(const std::string &filename)
void getCameraParameters(vpCameraParameters &cam, const unsigned int &image_width, const unsigned int &image_height) const
static const char *const CONST_GENERIC_CAMERA_NAME
Definition vpViper650.h:116
void init(void)
static const std::string CONST_EMC_MARLIN_F033C_WITHOUT_DISTORTION_FILENAME
Definition vpViper650.h:100
static const std::string CONST_EMC_MARLIN_F033C_WITH_DISTORTION_FILENAME
Definition vpViper650.h:101
void setToolType(vpViper650::vpToolType tool)
Set the current tool type.
Definition vpViper650.h:161
vpToolType
List of possible tools that can be attached to the robot end-effector.
Definition vpViper650.h:120
@ TOOL_MARLIN_F033C_CAMERA
Definition vpViper650.h:121
@ TOOL_SCHUNK_GRIPPER_CAMERA
Definition vpViper650.h:123
@ TOOL_GENERIC_CAMERA
Definition vpViper650.h:124
@ TOOL_PTGREY_FLEA2_CAMERA
Definition vpViper650.h:122
static const char *const CONST_MARLIN_F033C_CAMERA_NAME
Definition vpViper650.h:113
static const std::string CONST_EMC_PTGREY_FLEA2_WITHOUT_DISTORTION_FILENAME
Definition vpViper650.h:102
static const std::string CONST_EMC_PTGREY_FLEA2_WITH_DISTORTION_FILENAME
Definition vpViper650.h:103
static const std::string CONST_CAMERA_FILENAME
Definition vpViper650.h:108
static const char *const CONST_SCHUNK_GRIPPER_CAMERA_NAME
Definition vpViper650.h:115
virtual void set_eMc(const vpHomogeneousMatrix &eMc_)
Definition vpViper.cpp:1250
vpTranslationVector etc
Definition vpViper.h:158
double d6
for joint 6
Definition vpViper.h:166
double a3
for joint 3
Definition vpViper.h:164
double d4
for joint 4
Definition vpViper.h:165
vpColVector joint_max
Definition vpViper.h:171
double c56
Mechanical coupling between joint 5 and joint 6.
Definition vpViper.h:168
vpHomogeneousMatrix eMc
End effector to camera transformation.
Definition vpViper.h:156
double a1
Definition vpViper.h:162
vpRxyzVector erc
Definition vpViper.h:159
vpColVector joint_min
Definition vpViper.h:172
double a2
for joint 2
Definition vpViper.h:163
double d1
for joint 1
Definition vpViper.h:162
XML parser to load and save intrinsic camera parameters.
#define vpTRACE
Definition vpDebug.h:450
#define vpERROR_TRACE
Definition vpDebug.h:423