Visual Servoing Platform  version 3.6.1 under development (2024-06-15)
vpServoData.cpp
1 /*
2  * ViSP, open source Visual Servoing Platform software.
3  * Copyright (C) 2005 - 2023 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  * Save data during the task execution.
32  */
33 
39 // Servo
40 #include <visp3/vs/vpServo.h>
41 
42 #include <visp3/core/vpIoException.h>
43 #include <visp3/core/vpIoTools.h>
44 #include <visp3/vs/vpServoData.h>
45 
47 void vpServoData::open(const std::string &directory)
48 {
49  try {
50  if (vpIoTools::checkDirectory(directory) == false)
51  vpIoTools::makeDirectory(directory);
52 
53  std::string s;
54  s = directory + "/vel.dat";
55  velocityFile.open(s.c_str());
56  s = directory + "/error.dat";
57  errorFile.open(s.c_str());
58 
59  s = directory + "/errornorm.dat";
60  errorNormFile.open(s.c_str());
61  s = directory + "/s.dat";
62  sFile.open(s.c_str());
63  s = directory + "/sStar.dat";
64  sStarFile.open(s.c_str());
65 
66  }
67  catch (...) {
68  vpERROR_TRACE("Error caught");
69  throw;
70  }
71 }
72 
73 void vpServoData::setCmDeg() { cmDeg = true; }
74 void vpServoData::setMeterRad() { cmDeg = false; }
75 void vpServoData::save(const vpServo &task)
76 {
77  if (cmDeg == false)
78  velocityFile << task.q_dot.t();
79  else {
80  for (unsigned int i = 0; i < 3; i++)
81  velocityFile << task.q_dot[i] * 100 << " ";
82  for (unsigned int i = 4; i < 6; i++)
83  velocityFile << vpMath::deg(task.q_dot[i]) << " ";
84  velocityFile << std::endl;
85  }
86  errorFile << (task.getError()).t();
87  errorNormFile << (task.getError()).sumSquare() << std::endl;
88  vNormFile << task.q_dot.sumSquare() << std::endl;
89 
90  sFile << task.s.t();
91  sStarFile << task.sStar.t();
92 }
93 
95 {
96  if (velocityFile.is_open()) {
97  velocityFile.close();
98  }
99  if (errorFile.is_open()) {
100  errorFile.close();
101  }
102  if (errorNormFile.is_open()) {
103  errorNormFile.close();
104  }
105  if (sFile.is_open()) {
106  sFile.close();
107  }
108  if (sStarFile.is_open()) {
109  sStarFile.close();
110  }
111 }
double sumSquare() const
vpRowVector t() const
static bool checkDirectory(const std::string &dirname)
Definition: vpIoTools.cpp:837
static void makeDirectory(const std::string &dirname)
Definition: vpIoTools.cpp:986
static double deg(double rad)
Definition: vpMath.h:119
void open(const std::string &directory)
Definition: vpServoData.cpp:47
void save(const vpServo &task)
Save visual-servoing control law data.
Definition: vpServoData.cpp:75
void setMeterRad()
Velocity output are set in meter and deg (default).
Definition: vpServoData.cpp:74
void setCmDeg()
Velocity output are set in cm and deg.
Definition: vpServoData.cpp:73
void close()
Definition: vpServoData.cpp:94
vpColVector q_dot
Articular velocity.
Definition: vpServo.h:1182
vpColVector sStar
Definition: vpServo.h:1174
vpColVector s
Definition: vpServo.h:1170
vpColVector getError() const
Definition: vpServo.h:506
#define vpERROR_TRACE
Definition: vpDebug.h:385