src
core
src
time.cpp
Go to the documentation of this file.
1
/*********************************************************************
2
*
3
* Software License Agreement
4
*
5
* Copyright (c) 2020,
6
* TU Dortmund - Institute of Control Theory and Systems Engineering.
7
* All rights reserved.
8
*
9
* This program is free software: you can redistribute it and/or modify
10
* it under the terms of the GNU General Public License as published by
11
* the Free Software Foundation, either version 3 of the License, or
12
* (at your option) any later version.
13
*
14
* This program is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU General Public License for more details.
18
*
19
* You should have received a copy of the GNU General Public License
20
* along with this program. If not, see <https://www.gnu.org/licenses/>.
21
*
22
* Authors: Christoph Rösmann
23
*********************************************************************/
24
25
#include <
corbo-core/time.h
>
26
27
namespace
corbo
{
28
29
// implementation based on ros::Rate
30
// (http://docs.ros.org/diamondback/api/rostime/html/rate_8cpp_source.html#l00040)
31
bool
Rate::sleep
()
32
{
33
Time expected_end =
_start
+
_cycle_time
;
34
Time actual_end =
Time::now
();
35
36
// backwards jump in time
37
if
(actual_end <
_start
) expected_end = actual_end +
_cycle_time
;
38
39
Duration sleep_duration = expected_end - actual_end;
40
_last_cycle_time
= actual_end -
_start
;
41
42
_start
= expected_end;
43
44
// only sleep if positive sleep duration
45
if
(sleep_duration <= Duration(0))
46
{
47
if
(actual_end > expected_end +
_cycle_time
)
_start
= actual_end;
48
return
!(sleep_duration < Duration(0));
49
}
50
sleep_duration.sleep();
51
return
true
;
52
}
53
54
Time
Duration::toTime
(
double
basis_time) {
return
Time
(basis_time) + *
this
; }
55
56
}
// namespace corbo
corbo::Time::now
static Time now()
Retrieve current system time.
Definition:
time.h:297
corbo
Definition:
communication/include/corbo-communication/utilities.h:37
corbo::Rate::sleep
bool sleep()
Sleep for the remaining duration to met the desired frequency (w.r.t previous sleep call)
Definition:
time.cpp:53
corbo::Duration::Time
friend class Time
Definition:
time.h:130
time.h
corbo::Rate::_start
Time _start
Definition:
time.h:393
corbo::Duration::toTime
Time toTime(double basis_time=0)
Definition:
time.cpp:76
corbo::Rate::_last_cycle_time
Duration _last_cycle_time
Definition:
time.h:395
corbo::Time
Representation of time stamps.
Definition:
time.h:273
corbo::Rate::_cycle_time
Duration _cycle_time
Definition:
time.h:394
control_box_rst
Author(s): Christoph Rösmann
autogenerated on Wed Mar 2 2022 00:07:06