Visual Servoing Platform
version 3.7.0
Toggle main menu visibility
Loading...
Searching...
No Matches
vpForceTorqueIitSensor.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
* Wrapper over IIT force-torque sensor.
32
*
33
* Authors:
34
* Alexander Oliva
35
*/
36
41
42
#include <visp3/sensor/vpForceTorqueIitSensor.h>
43
44
#if defined(VISP_HAVE_FT_IIT_SDK) && defined(VISP_HAVE_THREADS)
45
46
BEGIN_VISP_NAMESPACE
52
vpForceTorqueIitSensor::vpForceTorqueIitSensor
()
53
:
m_ftLib
(),
m_numSensorsInLib
(0),
m_ft
(6, 0),
m_ft_filt
(6, 0),
m_ftSensorsData
(),
m_acquisitionEnabled
(false),
54
m_dataValid
(false),
m_connected
(false),
m_acquisitionThread
(),
m_timeCur
(),
m_timePrev
(),
m_mutex
(),
55
m_warmupMilliseconds
(500)
56
{
57
// Get number of connected in library sensors
58
m_numSensorsInLib
=
m_ftLib
._getNumberOfConnectedSensors();
59
60
/*
61
* Initialize Communication with sensor(-s):
62
*
63
* streaming is configured with "storeOption=0",
64
* which means that data will be stored in the library's main thread
65
* and will be given in an output file.
66
*
67
* "storeDataFlag" is initialized as "false", so that the
68
* recording will not start with the streaming thread, but
69
* the moment for when the recording will start & stop.
70
*/
71
if
(
m_ftLib
._configureStreaming(
false
, 0) == 0) {
72
// Start the main acquisition thread
73
m_ftLib._startStreamingThread();
74
75
m_connected = true;
76
}
77
}
78
82
void
vpForceTorqueIitSensor::close
()
83
{
84
m_ftLib
._stopStreamingThread();
85
m_acquisitionEnabled
=
false
;
86
m_dataValid
=
false
;
87
}
88
92
vpForceTorqueIitSensor::~vpForceTorqueIitSensor
() { this->
close
(); }
93
97
void
vpForceTorqueIitSensor::join
()
98
{
99
if
(
m_acquisitionThread
.joinable()) {
100
m_acquisitionThread
.join();
101
}
102
}
103
107
void
vpForceTorqueIitSensor::acquisitionLoop
()
108
{
109
m_timePrev
=
m_timeCur
= std::chrono::system_clock::now();
110
111
// Main thread
112
auto
time_init = std::chrono::system_clock::now();
113
while
(
m_acquisitionEnabled
) {
114
115
// Get time passed since the last acquired sample
116
m_timeCur
= std::chrono::system_clock::now();
117
118
// Calculate delta time
119
auto
elapsed_milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(
m_timeCur
-
m_timePrev
).count();
120
121
if
(elapsed_milliseconds >= 1) {
122
/*
123
* Once a new aquisition started,
124
* reset loop timers to keep a relatively fixed sampling time
125
*/
126
// Update previous time
127
m_timePrev
=
m_timeCur
;
128
129
/*
130
* get all connected sensors' data:
131
* call to a mutex method allowing to access the ftsensors' data
132
* in streaming mode (1 sample / packet / sensor)
133
*/
134
m_ftSensorsData
=
m_ftLib
._getFTSensorsData();
135
136
// Warm up the sensor. At the beginning we experienced that values returned in m_ftSensorsData.ftSensor->ft
137
// are completly wrong like the following:
138
// 2.237378396e+11 207.3293304 14291.07715 1.479413346e+19 13.26593399 3380.078613
139
auto
warmup_milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(
m_timeCur
- time_init).count();
140
if
(warmup_milliseconds >
m_warmupMilliseconds
) {
141
m_dataValid
=
true
;
142
}
143
else
{
144
continue
;
145
}
146
147
const
std::lock_guard<std::mutex> lock(
m_mutex
);
148
for
(
unsigned
int
i = 0; i < 6; i++) {
149
m_ft
[i] =
m_ftSensorsData
.ftSensor->ft[i];
150
m_ft_filt
[i] =
m_ftSensorsData
.ftSensor->filt_ft[i];
151
}
152
}
153
}
154
}
155
159
void
vpForceTorqueIitSensor::bias
() {
m_ftLib
._biasAllFTSensorsTCP(); }
160
172
bool
vpForceTorqueIitSensor::connected
(
int
timeout_ms)
const
173
{
174
vpChrono
chrono;
175
chrono.
start
();
176
while
(!
m_connected
&& chrono.
getDurationMs
() < timeout_ms) {
177
vpTime::sleepMs
(1);
178
}
179
180
return
m_connected
;
181
}
182
205
vpColVector
vpForceTorqueIitSensor::getForceTorque
(
bool
filtered)
206
{
207
const
std::lock_guard<std::mutex> lock(
m_mutex
);
208
if
(filtered) {
209
return
m_ft_filt
;
210
}
211
else
{
212
return
m_ft
;
213
}
214
}
215
219
void
vpForceTorqueIitSensor::startStreaming
()
220
{
221
m_acquisitionEnabled
=
true
;
222
m_acquisitionThread
= std::thread([
this
] { this->
acquisitionLoop
(); });
223
224
while
(!
m_dataValid
) {
225
vpTime::wait
(10);
226
}
227
}
228
232
void
vpForceTorqueIitSensor::stopStreaming
()
233
{
234
m_acquisitionEnabled
=
false
;
235
if
(
m_acquisitionThread
.joinable()) {
236
m_acquisitionThread
.join();
237
}
238
}
239
END_VISP_NAMESPACE
240
#else
241
// Work around to avoid warning:
242
// libvisp_sensor.a(vpForceTorqueIitSensor.cpp.o) has no symbols
243
void
dummy_vpForceTorqueIitSensor() { }
244
#endif
vpChrono
Definition
vpTime.h:90
vpChrono::start
void start(bool reset=true)
Definition
vpTime.cpp:411
vpChrono::getDurationMs
double getDurationMs()
Definition
vpTime.cpp:400
vpColVector
Implementation of column vector and the associated operations.
Definition
vpColVector.h:191
vpForceTorqueIitSensor::acquisitionLoop
void acquisitionLoop()
Definition
vpForceTorqueIitSensor.cpp:107
vpForceTorqueIitSensor::vpForceTorqueIitSensor
vpForceTorqueIitSensor()
Definition
vpForceTorqueIitSensor.cpp:52
vpForceTorqueIitSensor::m_connected
bool m_connected
Definition
vpForceTorqueIitSensor.h:181
vpForceTorqueIitSensor::m_timePrev
std::chrono::time_point< std::chrono::system_clock > m_timePrev
Definition
vpForceTorqueIitSensor.h:184
vpForceTorqueIitSensor::m_ft
vpColVector m_ft
Definition
vpForceTorqueIitSensor.h:174
vpForceTorqueIitSensor::close
void close()
Definition
vpForceTorqueIitSensor.cpp:82
vpForceTorqueIitSensor::m_numSensorsInLib
int m_numSensorsInLib
Definition
vpForceTorqueIitSensor.h:172
vpForceTorqueIitSensor::~vpForceTorqueIitSensor
~vpForceTorqueIitSensor()
Definition
vpForceTorqueIitSensor.cpp:92
vpForceTorqueIitSensor::m_dataValid
std::atomic< bool > m_dataValid
Definition
vpForceTorqueIitSensor.h:180
vpForceTorqueIitSensor::connected
bool connected(int timeout_ms=0) const
Definition
vpForceTorqueIitSensor.cpp:172
vpForceTorqueIitSensor::startStreaming
void startStreaming()
Definition
vpForceTorqueIitSensor.cpp:219
vpForceTorqueIitSensor::m_ftLib
ftSensorLib m_ftLib
Definition
vpForceTorqueIitSensor.h:171
vpForceTorqueIitSensor::bias
void bias()
Definition
vpForceTorqueIitSensor.cpp:159
vpForceTorqueIitSensor::stopStreaming
void stopStreaming()
Definition
vpForceTorqueIitSensor.cpp:232
vpForceTorqueIitSensor::m_warmupMilliseconds
int m_warmupMilliseconds
Definition
vpForceTorqueIitSensor.h:187
vpForceTorqueIitSensor::m_timeCur
std::chrono::time_point< std::chrono::system_clock > m_timeCur
Definition
vpForceTorqueIitSensor.h:184
vpForceTorqueIitSensor::m_acquisitionThread
std::thread m_acquisitionThread
Definition
vpForceTorqueIitSensor.h:183
vpForceTorqueIitSensor::join
void join()
Definition
vpForceTorqueIitSensor.cpp:97
vpForceTorqueIitSensor::m_ft_filt
vpColVector m_ft_filt
Definition
vpForceTorqueIitSensor.h:175
vpForceTorqueIitSensor::m_ftSensorsData
ftSensorsConnected m_ftSensorsData
Definition
vpForceTorqueIitSensor.h:177
vpForceTorqueIitSensor::getForceTorque
vpColVector getForceTorque(bool filtered=false)
Definition
vpForceTorqueIitSensor.cpp:205
vpForceTorqueIitSensor::m_mutex
std::mutex m_mutex
Definition
vpForceTorqueIitSensor.h:186
vpForceTorqueIitSensor::m_acquisitionEnabled
std::atomic< bool > m_acquisitionEnabled
Definition
vpForceTorqueIitSensor.h:179
BEGIN_VISP_NAMESPACE
Definition
vpMbtDistanceCircle.cpp:55
vpTime::wait
VISP_EXPORT int wait(double t0, double t)
vpTime::sleepMs
VISP_EXPORT void sleepMs(double t)
modules
sensor
src
force-torque
vpForceTorqueIitSensor.cpp
Generated by
1.17.0