ArmarXTimeserver.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 "ArmarXTimeserver.h"
26 
27 namespace armarx
28 {
29  void
31  {
32  offeringTopic(TIME_TOPIC_NAME);
33  clock = TimeKeeper();
34  stepTimeMS = getProperty<int>("TimeStepMS").getValue();
35  }
36 
37  void
39  {
40  clock.start();
41  timeTopicPrx = armarx::ManagedIceObject::getTopic<TimeServerListenerPrx>(TIME_TOPIC_NAME);
42 
44  {
45  broadcastTimeTask->stop();
46  }
47 
49  this, &ArmarXTimeserver::broadcastTime, 1, false, "SpammingTimeServer::Broadcast");
50  broadcastTimeTask->start();
51  }
52 
53  void
55  {
56  }
57 
58  void
60  {
61  }
62 
63  Ice::Long
64  ArmarXTimeserver::getTime(const ::Ice::Current&)
65  {
66  return static_cast<Ice::Long>(clock.getTime().toMilliSeconds());
67  }
68 
69  void
71  {
72  timeTopicPrx->reportTime(getTime());
73  }
74 
75  void
76  ArmarXTimeserver::stop(const ::Ice::Current&)
77  {
78  ARMARX_DEBUG << "TimeServer clock has stopped";
79  clock.stop();
80  }
81 
82  void
83  ArmarXTimeserver::start(const ::Ice::Current&)
84  {
85  ARMARX_DEBUG << "TimeServer clock started";
86  clock.start();
87  }
88 
89  void
90  ArmarXTimeserver::step(const ::Ice::Current&)
91  {
92  clock.step(IceUtil::Time::milliSeconds(stepTimeMS));
93  }
94 
95  void
96  ArmarXTimeserver::setSpeed(Ice::Float newSpeed, const ::Ice::Current&)
97  {
98  ARMARX_DEBUG << "Setting TimeServer clock speed to " << newSpeed;
99  clock.setSpeed(newSpeed);
100  }
101 
102  Ice::Float
103  ArmarXTimeserver::getSpeed(const Ice::Current&)
104  {
105  return clock.getSpeed();
106  }
107 
108  Ice::Int
109  ArmarXTimeserver::getStepTimeMS(const ::Ice::Current&)
110  {
111  return stepTimeMS;
112  }
113 
115  {
116  broadcastTimeTask->stop();
117  }
118 
121  {
123  getConfigDomain() + "." +
124  "ArmarXTimeserver")); // not using defaultName since it has to be GLOBAL_TIMESERVER_NAME (="MasterTimeServer") for all timeservers
125  }
126 } // namespace armarx
armarx::TimeKeeper
The TimeKeeper class tracks the passing of time and allows to stop it, restart it,...
Definition: TimeKeeper.h:41
armarx::ArmarXTimeserver::broadcastTime
void broadcastTime()
periodically writes the current time to the "Time" topic
Definition: ArmarXTimeserver.cpp:70
armarx::ArmarXTimeserver::broadcastTimeTask
PeriodicTask< ArmarXTimeserver >::pointer_type broadcastTimeTask
broadcastTimeTask calls broadcastTime() periodically
Definition: ArmarXTimeserver.h:76
armarx::VariantType::Float
const VariantTypeId Float
Definition: Variant.h:919
armarx::TimeKeeper::stop
void stop()
stops the clock.
Definition: TimeKeeper.cpp:82
armarx::ArmarXTimeserver::onDisconnectComponent
void onDisconnectComponent() override
Definition: ArmarXTimeserver.cpp:54
armarx::ArmarXTimeserver::onExitComponent
void onExitComponent() override
Definition: ArmarXTimeserver.cpp:59
armarx::ArmarXTimeserver::stop
void stop(const ::Ice::Current &=Ice::emptyCurrent) override
Definition: ArmarXTimeserver.cpp:76
armarx::ArmarXTimeserver::~ArmarXTimeserver
~ArmarXTimeserver() override
Definition: ArmarXTimeserver.cpp:114
armarx::TimeKeeper::step
void step(IceUtil::Time stepSize)
adds a timedelta to the current time
Definition: TimeKeeper.cpp:92
ArmarXTimeserver.h
armarx::ArmarXTimeserver::onConnectComponent
void onConnectComponent() override
Definition: ArmarXTimeserver.cpp:38
armarx::ArmarXTimeserver::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: ArmarXTimeserver.cpp:120
armarx::TimeKeeper::setSpeed
void setSpeed(float newSpeed)
sets the speed factor of the clock
Definition: TimeKeeper.cpp:58
armarx::ArmarXTimeserver::getTime
Ice::Long getTime(const ::Ice::Current &=Ice::emptyCurrent) override
getTime returns the current (simulator) time as milliseconds (as in IceUtil::Time::toMilliSeconds)
Definition: ArmarXTimeserver.cpp:64
ARMARX_DEBUG
#define ARMARX_DEBUG
Definition: Logging.h:184
armarx::ArmarXTimeserverPropertyDefinitions
Definition: ArmarXTimeserver.h:39
armarx::VariantType::Long
const VariantTypeId Long
Definition: Variant.h:918
armarx::ArmarXTimeserver::stepTimeMS
int stepTimeMS
time the clock advances dirung one call of step() in milliseconds
Definition: ArmarXTimeserver.h:83
armarx::ArmarXTimeserver::clock
TimeKeeper clock
Definition: ArmarXTimeserver.h:78
armarx::Component::getConfigDomain
std::string getConfigDomain()
Retrieve config domain for this component as set in constructor.
Definition: Component.cpp:65
armarx::ArmarXTimeserver::setSpeed
void setSpeed(Ice::Float newSpeed, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: ArmarXTimeserver.cpp:96
armarx::TimeKeeper::getTime
IceUtil::Time getTime() const
get the current time of this clock
Definition: TimeKeeper.cpp:36
armarx::ArmarXTimeserver::getSpeed
Ice::Float getSpeed(const ::Ice::Current &=Ice::emptyCurrent) override
Definition: ArmarXTimeserver.cpp:103
armarx::TimeKeeper::getSpeed
float getSpeed()
Definition: TimeKeeper.cpp:66
armarx::ManagedIceObject::offeringTopic
void offeringTopic(const std::string &name)
Registers a topic for retrival after initialization.
Definition: ManagedIceObject.cpp:300
armarx::ArmarXTimeserver::onInitComponent
void onInitComponent() override
Definition: ArmarXTimeserver.cpp:30
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::VariantType::Int
const VariantTypeId Int
Definition: Variant.h:917
armarx::ArmarXTimeserver::step
void step(const ::Ice::Current &=Ice::emptyCurrent) override
step() advances the time by the value of ArmarX.ArmarXTimeserver.StepTimeMS (in milliseconds) the def...
Definition: ArmarXTimeserver.cpp:90
armarx::PeriodicTask
Definition: ArmarXManager.h:70
armarx::ArmarXTimeserver::timeTopicPrx
TimeServerListenerPrx timeTopicPrx
a handle for the topic "Time"
Definition: ArmarXTimeserver.h:104
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:35
armarx::ArmarXTimeserver::start
void start(const ::Ice::Current &=Ice::emptyCurrent) override
Definition: ArmarXTimeserver.cpp:83
armarx::TimeKeeper::start
void start()
starts the clock
Definition: TimeKeeper.cpp:72
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
armarx::ArmarXTimeserver::getStepTimeMS
Ice::Int getStepTimeMS(const ::Ice::Current &=Ice::emptyCurrent) override
Definition: ArmarXTimeserver.cpp:109