TimeKeeper.h
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#pragma once
26
27#include <IceUtil/Time.h>
28
29namespace armarx
30{
31 /**
32 * @class TimeKeeper
33 * @brief The TimeKeeper class tracks the passing of time and allows to stop it, restart it, and adjust its speed (only used by ArmarXTimeServer).
34 * @ingroup VirtualTime
35 *
36 * Internally the current time is represented as a combination of start time, speed and an offset.
37 * The current time (i.e. the output of getTime()) is always `(IceUtil::Time::now() - startTime) * speed + offset`.
38 * When the timer is paused and unpaused or the speed changes, `offset` gets increased by `(IceUtil::Time::now() - starttime) * speed`
39 * and `starttime` gets reset to the current time.
40 */
42 {
43 public:
44 TimeKeeper();
45 /**
46 * @brief starts the clock
47 */
48 void start();
49 /**
50 * @brief stops the clock. This does not reset the clock.
51 */
52 void stop();
53 /**
54 * @brief resets the clock
55 */
56 void reset();
57 /**
58 * @brief get the current time of this clock
59 * @return the current time. In most cases this should be interpreted as a timedelta, not a datetime.
60 */
61 IceUtil::Time getTime() const;
62 /**
63 * @brief sets the speed factor of the clock
64 * @param newSpeed new speed factor
65 *
66 * Sets how fast the clock is running.
67 * e.g. a value of 0.5 means that the clock only ticks with half the speed of the system clock.
68 */
69 void setSpeed(float newSpeed);
70 float getSpeed();
71 /**
72 * @brief adds a timedelta to the current time
73 * @param stepSize how much to add
74 */
75 void step(IceUtil::Time stepSize);
76
77 private:
78 /**
79 * @brief offset that is added to the current time
80 */
81 IceUtil::Time offset;
82 /**
83 * @brief the time the clock was started (in local system time)
84 */
85 IceUtil::Time startTime;
86 /**
87 * @brief speed factor for the clock
88 */
89 float speed;
90 /**
91 * @brief if the clock is running
92 */
93 bool running;
94 };
95} // 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.