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
33namespace armarx
34{
35 /**
36 * @class ArmarXTimeserverPropertyDefinitions
37 * @brief
38 */
40 {
41 public:
44 {
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
simple implementation of the TimeserverInterface
void setSpeed(Ice::Float newSpeed, const ::Ice::Current &=Ice::emptyCurrent) override
void broadcastTime()
periodically writes the current time to the "Time" topic
Ice::Int getStepTimeMS(const ::Ice::Current &=Ice::emptyCurrent) override
void onDisconnectComponent() override
void start(const ::Ice::Current &=Ice::emptyCurrent) override
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
PeriodicTask< ArmarXTimeserver >::pointer_type broadcastTimeTask
broadcastTimeTask calls broadcastTime() periodically
int stepTimeMS
time the clock advances dirung one call of step() in milliseconds
void onConnectComponent() override
Ice::Float getSpeed(const ::Ice::Current &=Ice::emptyCurrent) override
TimeServerListenerPrx timeTopicPrx
a handle for the topic "Time"
void stop(const ::Ice::Current &=Ice::emptyCurrent) override
Ice::Long getTime(const ::Ice::Current &=Ice::emptyCurrent) override
getTime returns the current (simulator) time as milliseconds (as in IceUtil::Time::toMilliSeconds)
std::string getDefaultName() const override
void step(const ::Ice::Current &=Ice::emptyCurrent) override
step() advances the time by the value of ArmarX.ArmarXTimeserver.StepTimeMS (in milliseconds) the def...
Default component property definition container.
Definition Component.h:70
ComponentPropertyDefinitions(std::string prefix, bool hasObjectNameParameter=true)
Definition Component.cpp:46
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition Component.h:94
IceUtil::Handle< PeriodicTask< T > > pointer_type
Shared pointer type for convenience.
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
PropertyDefinition< PropertyType > & defineOptionalProperty(const std::string &name, PropertyType defaultValue, const std::string &description="", PropertyDefinitionBase::PropertyConstness constness=PropertyDefinitionBase::eConstant)
The TimeKeeper class tracks the passing of time and allows to stop it, restart it,...
Definition TimeKeeper.h:42
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.