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 
27 namespace armarx
28 {
30  {
31  reset();
32  running = false;
33  }
34 
36  {
37 
38  if (running)
39  {
40  return offset + (IceUtil::Time::now() - startTime) * speed;
41  }
42  else
43  {
44  return offset;
45  }
46  }
47 
49  {
50  offset = IceUtil::Time::microSeconds(0);
51  startTime = IceUtil::Time::now();
52  speed = 1;
53  }
54 
55  void TimeKeeper::setSpeed(float newSpeed)
56  {
57  offset = getTime();
58  startTime = IceUtil::Time::now();
59  speed = newSpeed;
60  }
61 
63  {
64  return speed;
65  }
66 
68  {
69  if (!running)
70  {
71  startTime = IceUtil::Time::now();
72  running = true;
73  }
74  }
75 
77  {
78  if (running)
79  {
80  offset = getTime();
81  running = false;
82  }
83  }
84 
86  {
87  offset += stepSize;
88  }
89 }
TimeKeeper.h
armarx::TimeKeeper::stop
void stop()
stops the clock.
Definition: TimeKeeper.cpp:76
armarx::TimeKeeper::step
void step(IceUtil::Time stepSize)
adds a timedelta to the current time
Definition: TimeKeeper.cpp:85
armarx::TimeKeeper::setSpeed
void setSpeed(float newSpeed)
sets the speed factor of the clock
Definition: TimeKeeper.cpp:55
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
armarx::TimeKeeper::reset
void reset()
resets the clock
Definition: TimeKeeper.cpp:48
armarx::TimeKeeper::getTime
IceUtil::Time getTime() const
get the current time of this clock
Definition: TimeKeeper.cpp:35
armarx::TimeKeeper::getSpeed
float getSpeed()
Definition: TimeKeeper.cpp:62
armarx::TimeKeeper::TimeKeeper
TimeKeeper()
Definition: TimeKeeper.cpp:29
armarx::TimeKeeper::start
void start()
starts the clock
Definition: TimeKeeper.cpp:67
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28