TimeKeeper.cpp
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5 *
6 * ArmarX is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * ArmarX is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * @package ArmarXCore::application::ArmarXTimeserver
19 * @author Clemens Wallrath ( uagzs at student dot kit dot edu )
20 * @date 2015
21 * @copyright http://www.gnu.org/licenses/gpl.txt
22 * GNU General Public License
23 */
24
25#include "TimeKeeper.h"
26
27namespace armarx
28{
30 {
31 reset();
32 running = false;
33 }
34
35 IceUtil::Time
37 {
38
39 if (running)
40 {
41 return offset + (IceUtil::Time::now() - startTime) * speed;
42 }
43 else
44 {
45 return offset;
46 }
47 }
48
49 void
51 {
52 offset = IceUtil::Time::microSeconds(0);
53 startTime = IceUtil::Time::now();
54 speed = 1;
55 }
56
57 void
58 TimeKeeper::setSpeed(float newSpeed)
59 {
60 offset = getTime();
61 startTime = IceUtil::Time::now();
62 speed = newSpeed;
63 }
64
65 float
67 {
68 return speed;
69 }
70
71 void
73 {
74 if (!running)
75 {
76 startTime = IceUtil::Time::now();
77 running = true;
78 }
79 }
80
81 void
83 {
84 if (running)
85 {
86 offset = getTime();
87 running = false;
88 }
89 }
90
91 void
92 TimeKeeper::step(IceUtil::Time stepSize)
93 {
94 offset += stepSize;
95 }
96} // namespace armarx
void start()
starts the clock
void step(IceUtil::Time stepSize)
adds a timedelta to the current time
void stop()
stops the clock.
IceUtil::Time getTime() const
get the current time of this clock
void reset()
resets the clock
void setSpeed(float newSpeed)
sets the speed factor of the clock
This file offers overloads of toIce() and fromIce() functions for STL container types.