corelib
src
SensorCapture.cpp
Go to the documentation of this file.
1
/*
2
Copyright (c) 2010-2016, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
3
All rights reserved.
4
5
Redistribution and use in source and binary forms, with or without
6
modification, are permitted provided that the following conditions are met:
7
* Redistributions of source code must retain the above copyright
8
notice, this list of conditions and the following disclaimer.
9
* Redistributions in binary form must reproduce the above copyright
10
notice, this list of conditions and the following disclaimer in the
11
documentation and/or other materials provided with the distribution.
12
* Neither the name of the Universite de Sherbrooke nor the
13
names of its contributors may be used to endorse or promote products
14
derived from this software without specific prior written permission.
15
16
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
20
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
*/
27
28
#include "
rtabmap/core/SensorCapture.h
"
29
30
#include <
rtabmap/utilite/UEventsManager.h
>
31
#include <
rtabmap/utilite/UConversion.h
>
32
#include <
rtabmap/utilite/UStl.h
>
33
#include <
rtabmap/utilite/UConversion.h
>
34
#include <
rtabmap/utilite/UFile.h
>
35
#include <
rtabmap/utilite/UDirectory.h
>
36
#include <
rtabmap/utilite/UTimer.h
>
37
38
#include <opencv2/imgproc/imgproc.hpp>
39
40
#include <iostream>
41
#include <cmath>
42
43
namespace
rtabmap
44
{
45
46
SensorCapture::SensorCapture
(
float
frameRate,
const
Transform
& localTransform) :
47
_frameRate(frameRate),
48
_localTransform(localTransform),
49
_frameRateTimer(new
UTimer
()),
50
_seq(0)
51
{
52
}
53
54
SensorCapture::~SensorCapture
()
55
{
56
delete
_frameRateTimer
;
57
}
58
59
void
SensorCapture::resetTimer
()
60
{
61
_frameRateTimer
->
start
();
62
}
63
64
SensorData
SensorCapture::takeData
(
SensorCaptureInfo
* info)
65
{
66
bool
warnFrameRateTooHigh =
false
;
67
float
actualFrameRate = 0;
68
float
frameRate =
_frameRate
;
69
if
(frameRate>0)
70
{
71
int
sleepTime = (1000.0f/frameRate - 1000.0f*
_frameRateTimer
->
getElapsedTime
());
72
if
(sleepTime > 2)
73
{
74
uSleep
(sleepTime-2);
75
}
76
else
if
(sleepTime < 0)
77
{
78
warnFrameRateTooHigh =
true
;
79
actualFrameRate = 1.0/(
_frameRateTimer
->
getElapsedTime
());
80
}
81
82
// Add precision at the cost of a small overhead
83
while
(
_frameRateTimer
->
getElapsedTime
() < 1.0/double(frameRate)-0.000001)
84
{
85
//
86
}
87
88
double
slept =
_frameRateTimer
->
getElapsedTime
();
89
_frameRateTimer
->
start
();
90
UDEBUG
(
"slept=%fs vs target=%fs"
, slept, 1.0/
double
(frameRate));
91
}
92
93
UTimer
timer
;
94
SensorData
data
= this->
captureData
(info);
95
double
captureTime =
timer
.ticks();
96
if
(warnFrameRateTooHigh)
97
{
98
UWARN
(
"Camera: Cannot reach target frame rate %f Hz, current rate is %f Hz and capture time = %f s."
,
99
frameRate, actualFrameRate, captureTime);
100
}
101
else
102
{
103
UDEBUG
(
"Time capturing data = %fs"
, captureTime);
104
}
105
if
(
info
)
106
{
107
info
->id =
data
.id();
108
info
->stamp =
data
.stamp();
109
info
->timeCapture = captureTime;
110
}
111
return
data
;
112
}
113
114
}
// namespace rtabmap
rtabmap::SensorData
Definition:
SensorData.h:51
rtabmap::SensorCapture::SensorCapture
SensorCapture(float frameRate=0, const Transform &localTransform=Transform::getIdentity())
Definition:
SensorCapture.cpp:46
timer
UDirectory.h
rtabmap::SensorCapture::resetTimer
void resetTimer()
Definition:
SensorCapture.cpp:59
UTimer::start
void start()
Definition:
UTimer.cpp:87
rtabmap::SensorCapture::_frameRateTimer
UTimer * _frameRateTimer
Definition:
SensorCapture.h:88
UTimer.h
rtabmap::SensorCaptureInfo
Definition:
SensorCaptureInfo.h:36
rtabmap::SensorCapture::_frameRate
float _frameRate
Definition:
SensorCapture.h:86
data
int data[]
UConversion.h
Some conversion functions.
rtabmap::SensorCapture::takeData
SensorData takeData(SensorCaptureInfo *info=0)
Definition:
SensorCapture.cpp:64
info
else if n * info
SensorCapture.h
UWARN
#define UWARN(...)
rtabmap::SensorCapture::captureData
virtual SensorData captureData(SensorCaptureInfo *info=0)=0
rtabmap::Transform
Definition:
Transform.h:41
UStl.h
Wrappers of STL for convenient functions.
UDEBUG
#define UDEBUG(...)
uSleep
void uSleep(unsigned int ms)
Definition:
Posix/UThreadC.h:23
rtabmap::SensorCapture::~SensorCapture
virtual ~SensorCapture()
Definition:
SensorCapture.cpp:54
UTimer
Definition:
UTimer.h:46
UTimer::getElapsedTime
double getElapsedTime()
Definition:
UTimer.cpp:97
UFile.h
rtabmap
Definition:
CameraARCore.cpp:35
UEventsManager.h
rtabmap
Author(s): Mathieu Labbe
autogenerated on Thu Jul 25 2024 02:50:15