Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpViper850.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 850 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/vpViper850.h>
46
47static const char *opt_viper850[] = { "CAMERA", "eMc_ROT_XYZ", "eMc_TRANS_XYZ", nullptr };
48
50#ifdef VISP_HAVE_VIPER850_DATA
52std::string(VISP_VIPER850_DATA_PATH) +
53std::string("/include/const_eMc_MarlinF033C_without_distortion_Viper850.cnf");
54
56std::string(VISP_VIPER850_DATA_PATH) + std::string("/include/const_eMc_MarlinF033C_with_distortion_Viper850.cnf");
57
59std::string(VISP_VIPER850_DATA_PATH) +
60std::string("/include/const_eMc_PTGreyFlea2_without_distortion_Viper850.cnf");
61
63std::string(VISP_VIPER850_DATA_PATH) + std::string("/include/const_eMc_PTGreyFlea2_with_distortion_Viper850.cnf");
64
66std::string(VISP_VIPER850_DATA_PATH) + std::string("/include/"
67 "const_eMc_schunk_gripper_without_distortion_Viper850."
68 "cnf");
69
71std::string(VISP_VIPER850_DATA_PATH) +
72std::string("/include/const_eMc_schunk_gripper_with_distortion_Viper850.cnf");
73
75std::string(VISP_VIPER850_DATA_PATH) + std::string("/include/const_eMc_generic_without_distortion_Viper850.cnf");
76
78std::string(VISP_VIPER850_DATA_PATH) + std::string("/include/const_eMc_generic_with_distortion_Viper850.cnf");
79
80const std::string vpViper850::CONST_CAMERA_FILENAME =
81std::string(VISP_VIPER850_DATA_PATH) + std::string("/include/const_camera_Viper850.xml");
82
83#endif // VISP_HAVE_VIPER850_DATA
84
85const char *const vpViper850::CONST_MARLIN_F033C_CAMERA_NAME = "Marlin-F033C-12mm";
86const char *const vpViper850::CONST_PTGREY_FLEA2_CAMERA_NAME = "PTGrey-Flea2-6mm";
87const char *const vpViper850::CONST_SCHUNK_GRIPPER_CAMERA_NAME = "Schunk-Gripper-PTGrey-Flea2-6mm";
88const char *const vpViper850::CONST_GENERIC_CAMERA_NAME = "Generic-camera";
89
91
99 : tool_current(vpViper850::defaultTool), projModel(vpCameraParameters::perspectiveProjWithoutDistortion)
100
101{
102 // Denavit-Hartenberg parameters
103 a1 = 0.075;
104 a2 = 0.365;
105 a3 = 0.090;
106 d1 = 0.335;
107 d4 = 0.405;
108 d6 = 0.080 + 0.1016; // To take into account the offset to go to the tool changer
109 c56 = -341.33 / 9102.22;
110
111 // Software joint limits in radians
112 joint_min[0] = vpMath::rad(-170);
113 joint_min[1] = vpMath::rad(-190);
114 joint_min[2] = vpMath::rad(-29);
115 joint_min[3] = vpMath::rad(-190);
116 joint_min[4] = vpMath::rad(-120);
117 joint_min[5] = vpMath::rad(-360);
118 joint_max[0] = vpMath::rad(170);
119 joint_max[1] = vpMath::rad(45);
120 joint_max[2] = vpMath::rad(256);
121 joint_max[3] = vpMath::rad(190);
122 joint_max[4] = vpMath::rad(120);
123 joint_max[5] = vpMath::rad(360);
124
125 init(); // Set the default tool
126}
127
133{
135 return;
136}
137
147void vpViper850::init(const std::string &camera_extrinsic_parameters)
148{
149 // vpTRACE ("Parse camera file \""%s\"".", camera_filename);
150 this->parseConfigFile(camera_extrinsic_parameters);
151
152 return;
153}
154
177{
178
179 this->projModel = proj_model;
180
181#ifdef VISP_HAVE_VIPER850_DATA
182 // Read the robot parameters from files
183 std::string filename_eMc;
184 switch (tool) {
186 switch (projModel) {
189 break;
192 break;
195 "Feature TOOL_MARLIN_F033C_CAMERA is not implemented for Kannala-Brandt projection model yet.");
196 break;
197 }
198 break;
199 }
201 switch (projModel) {
204 break;
207 break;
210 "Feature TOOL_PTGREY_FLEA2_CAMERA is not implemented for Kannala-Brandt projection model yet.");
211 }
212 break;
213 }
215 switch (projModel) {
218 break;
221 break;
223 throw vpException(
225 "Feature TOOL_SCHUNK_GRIPPER_CAMERA is not implemented for Kannala-Brandt projection model yet.");
226 }
227 break;
228 }
230 switch (projModel) {
233 break;
236 break;
239 "Feature TOOL_GENERIC_CAMERA is not implemented for Kannala-Brandt projection model yet.");
240 }
241 break;
242 }
245 "No predefined file available for a custom tool"
246 "You should use init(vpViper850::vpToolType, const std::string&) or"
247 "init(vpViper850::vpToolType, const vpHomogeneousMatrix&) instead");
248 }
249 default: {
250 vpERROR_TRACE("This error should not occur!");
251 break;
252 }
253 }
254
255 this->init(filename_eMc);
256
257#else // VISP_HAVE_VIPER850_DATA
258
259 // Use here default values of the robot constant parameters.
260 switch (tool) {
262 switch (projModel) {
264 erc[0] = vpMath::rad(0.07); // rx
265 erc[1] = vpMath::rad(2.76); // ry
266 erc[2] = vpMath::rad(-91.50); // rz
267 etc[0] = -0.0453; // tx
268 etc[1] = 0.0005; // ty
269 etc[2] = 0.0728; // tz
270 break;
272 erc[0] = vpMath::rad(0.26); // rx
273 erc[1] = vpMath::rad(2.12); // ry
274 erc[2] = vpMath::rad(-91.31); // rz
275 etc[0] = -0.0444; // tx
276 etc[1] = -0.0005; // ty
277 etc[2] = 0.1022; // tz
278 break;
281 "Feature TOOL_MARLIN_F033C_CAMERA is not implemented for Kannala-Brandt projection model yet.");
282 }
283 break;
284 }
287 switch (projModel) {
289 erc[0] = vpMath::rad(0.15); // rx
290 erc[1] = vpMath::rad(1.28); // ry
291 erc[2] = vpMath::rad(-90.8); // rz
292 etc[0] = -0.0456; // tx
293 etc[1] = -0.0013; // ty
294 etc[2] = 0.001; // tz
295 break;
297 erc[0] = vpMath::rad(0.72); // rx
298 erc[1] = vpMath::rad(2.10); // ry
299 erc[2] = vpMath::rad(-90.5); // rz
300 etc[0] = -0.0444; // tx
301 etc[1] = -0.0012; // ty
302 etc[2] = 0.078; // tz
303 break;
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;
324 "Feature TOOL_GENERIC_CAMERA is not implemented for Kannala-Brandt projection model yet.");
325 }
326 break;
327 }
330 "No predefined parameters available for a custom tool"
331 "You should use init(vpViper850::vpToolType, const std::string&) or"
332 "init(vpViper850::vpToolType, const vpHomogeneousMatrix&) instead");
333 }
334 }
336 this->eMc.buildFrom(etc, eRc);
337#endif // VISP_HAVE_VIPER850_DATA
338
339 setToolType(tool);
340 return;
341}
342
373void vpViper850::init(vpViper850::vpToolType tool, const std::string &filename)
374{
375 this->setToolType(tool);
376 this->parseConfigFile(filename.c_str());
377}
378
395{
396 this->setToolType(tool);
397 this->set_eMc(eMc_);
398}
399
408void vpViper850::parseConfigFile(const std::string &filename)
409{
410 vpRxyzVector erc_; // eMc rotation
411 vpTranslationVector etc_; // eMc translation
412
413 std::ifstream fdconfig(filename.c_str(), std::ios::in);
414
415 if (!fdconfig.is_open()) {
416 throw vpRobotException(vpRobotException::readingParametersError, "Impossible to read the config file: %s",
417 filename.c_str());
418 }
419
420 std::string line;
421 int lineNum = 0;
422 bool get_erc = false;
423 bool get_etc = false;
424 int code;
425
426 while (std::getline(fdconfig, line)) {
427 lineNum++;
428 if ((line.compare(0, 1, "#") == 0) || line.empty()) { // skip comment or empty line
429 continue;
430 }
431 std::istringstream ss(line);
432 std::string key;
433 ss >> key;
434
435 for (code = 0; nullptr != opt_viper850[code]; ++code) {
436 if (key.compare(opt_viper850[code]) == 0) {
437 break;
438 }
439 }
440
441 switch (code) {
442 case 0:
443 break; // Nothing to do: camera name
444
445 case 1: {
446 ss >> erc_[0] >> erc_[1] >> erc_[2];
447
448 // Convert rotation from degrees to radians
449 erc_ = erc_ * M_PI / 180.0;
450 get_erc = true;
451 break;
452 }
453
454 case 2: {
455 ss >> etc_[0] >> etc_[1] >> etc_[2];
456 get_etc = true;
457 break;
458 }
459
460 default:
461 throw(vpRobotException(vpRobotException::readingParametersError, "Bad configuration file %s line #%d",
462 filename.c_str(), lineNum));
463 }
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 vpViper850::getCameraParameters(vpCameraParameters &cam, const unsigned int &image_width,
554 const unsigned int &image_height) const
555{
556#if defined(VISP_HAVE_VIPER850_DATA) && defined(VISP_HAVE_PUGIXML)
557 vpXmlParserCamera parser;
558 switch (getToolType()) {
560 std::cout << "Get camera parameters for camera \"" << vpViper850::CONST_MARLIN_F033C_CAMERA_NAME << "\""
561 << std::endl
562 << "from the XML file: \"" << vpViper850::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 \"" << vpViper850::CONST_PTGREY_FLEA2_CAMERA_NAME << "\""
571 << std::endl
572 << "from the XML file: \"" << vpViper850::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 \"" << vpViper850::CONST_SCHUNK_GRIPPER_CAMERA_NAME << "\""
581 << std::endl
582 << "from the XML file: \"" << vpViper850::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 \"" << vpViper850::CONST_GENERIC_CAMERA_NAME << "\"" << std::endl
591 << "from the XML file: \"" << vpViper850::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 // "vpViper850::vpViper850ToolType, 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 \"" << vpViper850::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;
631 "Feature getCameraParameters is not implemented for Kannala-Brandt projection model yet.");
632 break;
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 \"" << vpViper850::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;
657 "Feature getCameraParameters is not implemented for Kannala-Brandt projection model yet.");
658 break;
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 \"" << vpViper850::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;
682 "Feature getCameraParameters is not implemented for Kannala-Brandt projection model yet.");
683 break;
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 vpERROR_TRACE("This error should not occur!");
698 throw vpRobotException(vpRobotException::readingParametersError, "Impossible to read the camera parameters.");
699 }
700#endif
701 return;
702}
703
765{
766 getCameraParameters(cam, I.getWidth(), I.getHeight());
767}
768
832
834{
835 getCameraParameters(cam, I.getWidth(), I.getHeight());
836}
837END_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 char *const CONST_PTGREY_FLEA2_CAMERA_NAME
Definition vpViper850.h:114
void setToolType(vpViper850::vpToolType tool)
Set the current tool type.
Definition vpViper850.h:161
static const std::string CONST_CAMERA_FILENAME
Definition vpViper850.h:108
static const std::string CONST_EMC_MARLIN_F033C_WITHOUT_DISTORTION_FILENAME
Definition vpViper850.h:100
static const vpToolType defaultTool
Default tool attached to the robot end effector.
Definition vpViper850.h:129
static const char *const CONST_SCHUNK_GRIPPER_CAMERA_NAME
Definition vpViper850.h:115
static const std::string CONST_EMC_GENERIC_WITH_DISTORTION_FILENAME
Definition vpViper850.h:107
void parseConfigFile(const std::string &filename)
static const std::string CONST_EMC_SCHUNK_GRIPPER_WITHOUT_DISTORTION_FILENAME
Definition vpViper850.h:104
static const std::string CONST_EMC_SCHUNK_GRIPPER_WITH_DISTORTION_FILENAME
Definition vpViper850.h:105
static const char *const CONST_GENERIC_CAMERA_NAME
Definition vpViper850.h:116
void getCameraParameters(vpCameraParameters &cam, const unsigned int &image_width, const unsigned int &image_height) const
vpToolType tool_current
Current tool in use.
Definition vpViper850.h:166
vpCameraParameters::vpCameraParametersProjType projModel
Definition vpViper850.h:168
static const std::string CONST_EMC_MARLIN_F033C_WITH_DISTORTION_FILENAME
Definition vpViper850.h:101
static const std::string CONST_EMC_PTGREY_FLEA2_WITHOUT_DISTORTION_FILENAME
Definition vpViper850.h:102
vpToolType getToolType() const
Get the current tool type.
Definition vpViper850.h:152
vpToolType
List of possible tools that can be attached to the robot end-effector.
Definition vpViper850.h:120
@ TOOL_SCHUNK_GRIPPER_CAMERA
Definition vpViper850.h:123
@ TOOL_PTGREY_FLEA2_CAMERA
Definition vpViper850.h:122
@ TOOL_MARLIN_F033C_CAMERA
Definition vpViper850.h:121
@ TOOL_GENERIC_CAMERA
Definition vpViper850.h:124
static const char *const CONST_MARLIN_F033C_CAMERA_NAME
Definition vpViper850.h:113
static const std::string CONST_EMC_PTGREY_FLEA2_WITH_DISTORTION_FILENAME
Definition vpViper850.h:103
void init(void)
static const std::string CONST_EMC_GENERIC_WITHOUT_DISTORTION_FILENAME
Definition vpViper850.h:106
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