Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpForceTorqueAtiSensor.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 * ATI Force torque interface.
32 */
33
34#include <visp3/core/vpConfig.h>
35
36#if defined(VISP_HAVE_ATIDAQ) && defined(VISP_HAVE_COMEDI)
37
38#include <ftconfig.h> // atidaq private library
39
40#include <visp3/core/vpException.h>
41#include <visp3/sensor/vpForceTorqueAtiSensor.h>
42
43static Calibration *s_calibinfo = nullptr;
44
52
58{
59 // Open access to device
62}
63
69{
70 open();
71
72 // Get FT from device
74
75 if (m_sample_bias.size() != m_num_channels)
76 throw vpException(vpException::fatalError, "Physical data size (%d) and number of channels (%d) doesn't match",
78
79 float *sample_bias = new float[m_num_channels];
80 for (unsigned int i = 0; i < m_num_channels; i++)
81 sample_bias[i] = m_sample_bias[i];
82
83 Bias(s_calibinfo, sample_bias);
84
85 delete[] sample_bias;
86}
87
93{
94 open();
95
96 // Get FT from device
98
99 // Reset sample bias
100 m_sample_bias = 0;
101
102 if (m_sample_bias.size() != m_num_channels)
103 throw vpException(vpException::fatalError, "Physical data size (%d) and number of channels (%d) doesn't match",
105
106 float *sample_bias = new float[m_num_channels];
107 for (unsigned int i = 0; i < m_num_channels; i++)
108 sample_bias[i] = m_sample_bias[i];
109
110 Bias(s_calibinfo, sample_bias);
111
112 delete[] sample_bias;
113}
114
120{
121 if (s_calibinfo != nullptr) {
122 // free memory allocated to calibration structure
123 destroyCalibration(s_calibinfo);
124 s_calibinfo = nullptr;
125 }
127}
128
138{
140
141 if (phydata.size() != m_num_channels)
142 throw vpException(vpException::fatalError, "Physical data size (%d) and number of channels (%d) doesn't match",
143 phydata.size(), m_num_channels);
144
145 float *voltage = new float[m_num_channels];
146 float *ft = new float[m_num_axes];
147
148 for (unsigned int i = 0; i < m_num_channels; i++) {
149 voltage[i] = phydata[i];
150 }
151
152 // convert a loaded measurement into forces and torques
153 ConvertToFT(s_calibinfo, voltage, ft);
154
155 vpColVector sample(m_num_axes);
156 for (unsigned int i = 0; i < m_num_axes; i++)
157 sample[i] = ft[i];
158
159 delete[] voltage;
160 delete[] ft;
161
162 return sample;
163}
164
169{
170 std::string units(s_calibinfo->ForceUnits);
171 return units;
172}
173
177{
178 std::string units(s_calibinfo->TorqueUnits);
179 return units;
180}
181
186
193void vpForceTorqueAtiSensor::setCalibrationFile(const std::string &calibfile, unsigned short index)
194{
195 m_calibfile = calibfile;
196 m_index = index;
197
198 if (s_calibinfo)
199 destroyCalibration(s_calibinfo);
200
201 // Create calibration struct
202 s_calibinfo = createCalibration(m_calibfile.c_str(), m_index);
203 if (s_calibinfo == nullptr) {
204 throw vpException(vpException::fatalError, "Calibration file %s couldn't be loaded", m_calibfile.c_str());
205 }
206
207 m_num_channels = s_calibinfo->rt.NumChannels;
208 m_num_axes = s_calibinfo->rt.NumAxes;
209}
210
234std::ostream &operator<<(std::ostream &os, const vpForceTorqueAtiSensor &ati)
235{
236 if (s_calibinfo == nullptr) {
237 os << "Calibration Information is not available" << std::endl;
238 return os;
239 }
240
241 // display info from calibration file
242 os << "Calibration Information for " << ati.m_calibfile << ", index #" << ati.m_index << ":" << std::endl;
243 os << " Serial: " << s_calibinfo->Serial << std::endl;
244 os << " Body Style: " << s_calibinfo->BodyStyle << std::endl;
245 os << " Calibration: " << s_calibinfo->PartNumber << std::endl;
246 os << " Calibration Date: " << s_calibinfo->CalDate << std::endl;
247 os << " Family: " << s_calibinfo->Family << std::endl;
248 os << " # Channels: " << s_calibinfo->rt.NumChannels << std::endl;
249 os << " # Axes: " << s_calibinfo->rt.NumAxes << std::endl;
250 os << " Force Units: " << s_calibinfo->ForceUnits << std::endl;
251 os << " Torque Units: " << s_calibinfo->TorqueUnits << std::endl;
252 os << "Temperature Compensation: " << (s_calibinfo->TempCompAvailable ? "Yes" : "No") << std::endl;
253
254 // print maximum loads of axes
255 os << "\nRated Loads:" << std::endl;
256 for (unsigned short i = 0; i < s_calibinfo->rt.NumAxes; i++) {
257 char *units;
258 if ((s_calibinfo->AxisNames[i])[0] == 'F') {
259 units = s_calibinfo->ForceUnits;
260 }
261 else
262 units = s_calibinfo->TorqueUnits;
263 os << s_calibinfo->AxisNames[i] << ": " << s_calibinfo->MaxLoads[i] << " " << units << std::endl;
264 }
265
266 // print temperature compensation information, if available
267 if (s_calibinfo->TempCompAvailable) {
268 os << "\nTemperature Compensation Information:" << std::endl;
269 os << "BS: ";
270 for (unsigned short i = 0; i < s_calibinfo->rt.NumChannels - 1; i++) {
271 os << s_calibinfo->rt.bias_slopes[i] << " ";
272 }
273 os << "\nGS: ";
274 for (unsigned short i = 0; i < s_calibinfo->rt.NumChannels - 1; i++) {
275 os << s_calibinfo->rt.gain_slopes[i] << " ";
276 }
277 os << "\nTherm: " << s_calibinfo->rt.thermistor << std::endl;
278 }
279
280 return os;
281}
282END_VISP_NAMESPACE
283#elif !defined(VISP_BUILD_SHARED_LIBS)
284// Work around to avoid warning:
285// libvisp_sensor.a(vpForceTorqueAtiSensor.cpp.o) has no symbols
286void dummy_vpForceTorqueAtiSensor() { }
287#endif
unsigned int size() const
Return the number of elements of the 2D array.
Definition vpArray2D.h:435
Implementation of column vector and the associated operations.
void setChannelNumbers(const unsigned int &nchannel)
Definition vpComedi.h:148
vpColVector getPhyData() const
Definition vpComedi.cpp:131
void open()
Definition vpComedi.cpp:61
void close()
Definition vpComedi.cpp:88
error that can be emitted by ViSP classes.
Definition vpException.h:60
@ fatalError
Fatal error.
Definition vpException.h:72
unsigned short m_index
Index of calibration in file (default: 1).
unsigned short m_num_axes
Number of axis or gages available from the sensor.
friend VISP_EXPORT std::ostream & operator<<(std::ostream &os, const vpForceTorqueAtiSensor &ati)
std::string m_calibfile
ATI calibration file FT*.cal.
vpColVector m_sample_bias
Sample value used for bias.
void setCalibrationFile(const std::string &calibfile, unsigned short index=1)
virtual ~vpForceTorqueAtiSensor() VP_OVERRIDE
unsigned short m_num_channels
Number of channels available from the sensor.