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