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