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 
26 
28 
29 
30 namespace armarx
31 {
34  {
35  defineOptionalProperty<std::string>("TimingTestTopicName", "TimingTestTopic", "-");
36  defineOptionalProperty<int>("UpdatePeriodInMS", 10, "-");
37 
38  defineOptionalProperty<std::string>("DebugObserverName", "DebugObserver", "Name of the topic the DebugObserver listens on");
39 
40  }
41 
42 
44  {
45  return "TopicTimingServer";
46  }
47 
48 
50  {
51  offeringTopicFromProperty("TimingTestTopicName");
52 
53  offeringTopicFromProperty("DebugObserverName");
54 
55  updatePeriodInMS = getProperty<int>("UpdatePeriodInMS").getValue();
56  }
57 
58 
60  {
61  topic = getTopicFromProperty<armarx::topic_timing::TopicPrx>("TimingTestTopicName");
62 
63  debugObserver = getTopicFromProperty<DebugObserverInterfacePrx>("DebugObserverName");
64 
65  lastSmallTime = IceUtil::Time::now();
66 
67  task = new RunningTask<TopicTimingServer>(this, &TopicTimingServer::run);
68  task->start();
69  }
70 
71 
73  {
74  task->stop();
75  task = nullptr;
76  }
77 
78 
80  {
81 
82  }
83 
84 
85 
86 
88  {
91  }
92 
93  void TopicTimingServer::run()
94  {
95  CycleUtil c(updatePeriodInMS);
96  while (!task->isStopped())
97  {
98  IceUtil::Time time_now = IceUtil::Time::now();
99  {
100  topic_timing::SmallData data;
101  data.sentTimestamp = time_now.toMicroSeconds();
102 
103  topic->reportSmall(data);
104  }
105  IceUtil::Time time_sent = IceUtil::Time::now();
106 
107  IceUtil::Time dur_send = time_sent - time_now;
108 
109  IceUtil::Time dur_cycle = time_now - lastSmallTime;
110  lastSmallTime = time_now;
111 
112  StringVariantBaseMap channel;
113  channel["DurationSend"] = new Variant(dur_send.toMilliSecondsDouble());
114  channel["DurationCycle"] = new Variant(dur_cycle.toMilliSecondsDouble());
115  debugObserver->setDebugChannel("TopicTimingServerSmall", channel);
116 
117  c.waitForCycleDuration();
118  }
119  }
120 }
armarx::StringVariantBaseMap
std::map< std::string, VariantBasePtr > StringVariantBaseMap
Definition: ManagedIceObject.h:111
armarx::TopicTimingServer::onDisconnectComponent
virtual void onDisconnectComponent() override
Definition: TopicTimingServer.cpp:72
armarx::CycleUtil
This util class helps with keeping a cycle time during a control cycle.
Definition: CycleUtil.h:40
armarx::Component::offeringTopicFromProperty
void offeringTopicFromProperty(const std::string &propertyName)
Offer a topic whose name is specified by the given property.
Definition: Component.cpp:154
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
armarx::TopicTimingServerPropertyDefinitions
Definition: TopicTimingServer.h:39
armarx::RunningTask
Definition: ArmarXMultipleObjectsScheduler.h:35
armarx::TopicTimingServer::onConnectComponent
virtual void onConnectComponent() override
Definition: TopicTimingServer.cpp:59
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
armarx::TopicTimingServer::onExitComponent
virtual void onExitComponent() override
Definition: TopicTimingServer.cpp:79
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
TopicTimingServer.h
CycleUtil.h
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:74
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:70
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::TopicTimingServer::createPropertyDefinitions
virtual armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: TopicTimingServer.cpp:87
armarx::TopicTimingServer::onInitComponent
virtual void onInitComponent() override
Definition: TopicTimingServer.cpp:49
armarx::TopicTimingServerPropertyDefinitions::TopicTimingServerPropertyDefinitions
TopicTimingServerPropertyDefinitions(std::string prefix)
Definition: TopicTimingServer.cpp:32
armarx::TopicTimingServer::getDefaultName
virtual std::string getDefaultName() const override
Definition: TopicTimingServer.cpp:43
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:34
Variant.h
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28