ArmarXTimeserver.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 
30 #include <ArmarXCore/interface/core/TimeServerInterface.h>
31 
33 
34 namespace armarx
35 {
36  /**
37  * @class ArmarXTimeserverPropertyDefinitions
38  * @brief
39  */
42  {
43  public:
46  {
47  defineOptionalProperty<int>("TimeStepMS", 1, "The number of milliseconds the time advances with every step()")
48  .setMin(1);
49  }
50  };
51 
52  /**
53  * @class ArmarXTimeserver
54  * @brief simple implementation of the TimeserverInterface
55  * @ingroup VirtualTime
56  *
57  * The ArmarXTimeserver provides a global synchronized time that can be stopped, stepped and changed in speed
58  */
60  virtual public armarx::Component,
61  virtual public TimeServerInterface
62  {
63  public:
64  /**
65  * @see armarx::ManagedIceObject::getDefaultName()
66  */
67  std::string getDefaultName() const override
68  {
69  return GLOBAL_TIMESERVER_NAME;
70  }
71 
72  ~ArmarXTimeserver() override;
73 
74  protected:
75 
76  /**
77  * @brief broadcastTimeTask calls broadcastTime() periodically
78  */
80 
82 
83  /**
84  * time the clock advances dirung one call of step() in milliseconds
85  */
87 
88  /**
89  * @brief getTime returns the current (simulator) time as milliseconds (as in IceUtil::Time::toMilliSeconds)
90  * @return current time in milliseconds
91  */
92  Ice::Long getTime(const ::Ice::Current& = Ice::emptyCurrent) override;
93  void stop(const ::Ice::Current& = Ice::emptyCurrent) override;
94  void start(const ::Ice::Current& = Ice::emptyCurrent) override;
95  /**
96  * @brief step() advances the time by the value of ArmarX.ArmarXTimeserver.StepTimeMS (in milliseconds)
97  * the default step length is 1 millisecond
98  */
99  void step(const ::Ice::Current& = Ice::emptyCurrent) override;
100  void setSpeed(Ice::Float newSpeed, const ::Ice::Current& = Ice::emptyCurrent) override;
101  Ice::Float getSpeed(const ::Ice::Current& = Ice::emptyCurrent) override;
102  Ice::Int getStepTimeMS(const ::Ice::Current& = Ice::emptyCurrent) override;
103 
104  /**
105  * @brief a handle for the topic "Time"
106  */
107  TimeServerListenerPrx timeTopicPrx;
108 
109  /**
110  * @brief periodically writes the current time to the "Time" topic
111  */
112  void broadcastTime();
113 
114  /**
115  * @see armarx::ManagedIceObject::onInitComponent()
116  */
117  void onInitComponent() override;
118 
119  /**
120  * @see armarx::ManagedIceObject::onConnectComponent()
121  */
122  void onConnectComponent() override;
123 
124  /**
125  * @see armarx::ManagedIceObject::onDisconnectComponent()
126  */
127  void onDisconnectComponent() override;
128 
129  /**
130  * @see armarx::ManagedIceObject::onExitComponent()
131  */
132  void onExitComponent() override;
133 
134  /**
135  * @see PropertyUser::createPropertyDefinitions()
136  */
138  };
139 }
140 
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
TimeKeeper.h
armarx::VariantType::Float
const VariantTypeId Float
Definition: Variant.h:918
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::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:333
PeriodicTask.h
armarx::ArmarXTimeserver
simple implementation of the TimeserverInterface
Definition: ArmarXTimeserver.h:59
armarx::ArmarXTimeserverPropertyDefinitions::ArmarXTimeserverPropertyDefinitions
ArmarXTimeserverPropertyDefinitions(std::string prefix)
Definition: ArmarXTimeserver.h:44
armarx::ArmarXTimeserver::onConnectComponent
void onConnectComponent() override
Definition: ArmarXTimeserver.cpp:38
armarx::ArmarXTimeserver::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: ArmarXTimeserver.cpp:112
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::ArmarXTimeserver::getDefaultName
std::string getDefaultName() const override
Definition: ArmarXTimeserver.h:67
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::ArmarXTimeserver::setSpeed
void setSpeed(Ice::Float newSpeed, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: ArmarXTimeserver.cpp:91
Component.h
armarx::Component
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition: Component.h:95
armarx::ArmarXTimeserver::getSpeed
Ice::Float getSpeed(const ::Ice::Current &=Ice::emptyCurrent) override
Definition: ArmarXTimeserver.cpp:97
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:70
armarx::ArmarXTimeserver::onInitComponent
void onInitComponent() override
Definition: ArmarXTimeserver.cpp:30
IceUtil::Handle
Definition: forward_declarations.h:29
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::ArmarXTimeserver::timeTopicPrx
TimeServerListenerPrx timeTopicPrx
a handle for the topic "Time"
Definition: ArmarXTimeserver.h:107
armarx::ArmarXTimeserver::start
void start(const ::Ice::Current &=Ice::emptyCurrent) override
Definition: ArmarXTimeserver.cpp:80
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