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