TopicTimingServer.cpp
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @package RobotAPI::ArmarXObjects::TopicTimingServer
17 * @author Fabian Paus ( fabian dot paus at kit dot edu )
18 * @date 2019
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22
23#include "TopicTimingServer.h"
24
27
28namespace armarx
29{
32 {
33 defineOptionalProperty<std::string>("TimingTestTopicName", "TimingTestTopic", "-");
34 defineOptionalProperty<int>("UpdatePeriodInMS", 10, "-");
35
37 "DebugObserverName", "DebugObserver", "Name of the topic the DebugObserver listens on");
38 }
39
40 std::string
42 {
43 return "TopicTimingServer";
44 }
45
46 void
48 {
49 offeringTopicFromProperty("TimingTestTopicName");
50
51 offeringTopicFromProperty("DebugObserverName");
52
53 updatePeriodInMS = getProperty<int>("UpdatePeriodInMS").getValue();
54 }
55
56 void
58 {
59 topic = getTopicFromProperty<armarx::topic_timing::TopicPrx>("TimingTestTopicName");
60
61 debugObserver = getTopicFromProperty<DebugObserverInterfacePrx>("DebugObserverName");
62
63 lastSmallTime = IceUtil::Time::now();
64
65 task = new RunningTask<TopicTimingServer>(this, &TopicTimingServer::run);
66 task->start();
67 }
68
69 void
71 {
72 task->stop();
73 task = nullptr;
74 }
75
76 void
80
87
88 void
89 TopicTimingServer::run()
90 {
91 CycleUtil c(updatePeriodInMS);
92 while (!task->isStopped())
93 {
94 IceUtil::Time time_now = IceUtil::Time::now();
95 {
96 topic_timing::SmallData data;
97 data.sentTimestamp = time_now.toMicroSeconds();
98
99 topic->reportSmall(data);
100 }
101 IceUtil::Time time_sent = IceUtil::Time::now();
102
103 IceUtil::Time dur_send = time_sent - time_now;
104
105 IceUtil::Time dur_cycle = time_now - lastSmallTime;
106 lastSmallTime = time_now;
107
108 StringVariantBaseMap channel;
109 channel["DurationSend"] = new Variant(dur_send.toMilliSecondsDouble());
110 channel["DurationCycle"] = new Variant(dur_cycle.toMilliSecondsDouble());
111 debugObserver->setDebugChannel("TopicTimingServerSmall", channel);
112
113 c.waitForCycleDuration();
114 }
115 }
116} // namespace armarx
constexpr T c
ComponentPropertyDefinitions(std::string prefix, bool hasObjectNameParameter=true)
Definition Component.cpp:46
TopicProxyType getTopicFromProperty(const std::string &propertyName)
Get a topic proxy whose name is specified by the given property.
Definition Component.h:221
void offeringTopicFromProperty(const std::string &propertyName)
Offer a topic whose name is specified by the given property.
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition Component.cpp:90
Property< PropertyType > getProperty(const std::string &name)
This util class helps with keeping a cycle time during a control cycle.
Definition CycleUtil.h:41
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)
virtual void onInitComponent() override
virtual void onDisconnectComponent() override
virtual armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
virtual void onConnectComponent() override
virtual void onExitComponent() override
virtual std::string getDefaultName() const override
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::map< std::string, VariantBasePtr > StringVariantBaseMap
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.