TopicTimingClient.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::TopicTimingClient
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 "TopicTimingClient.h"
24 
26 
27 
28 namespace armarx
29 {
32  {
33  defineOptionalProperty<std::string>("TimingTestTopicName", "TimingTestTopic", "-");
34  defineOptionalProperty<int>("SimulateWorkForMS", 20, "Sleeps until it returns from the topic call");
35 
36  defineOptionalProperty<std::string>("DebugObserverName", "DebugObserver", "Name of the topic the DebugObserver listens on");
37 
38  }
39 
40 
42  {
43  return "TopicTimingClient";
44  }
45 
46 
48  {
49  usingTopicFromProperty("TimingTestTopicName");
50 
51  offeringTopicFromProperty("DebugObserverName");
52  }
53 
54 
56  {
57  // Get topics and proxies here. Pass the *InterfacePrx type as template argument.
58  debugObserver = getTopicFromProperty<DebugObserverInterfacePrx>("DebugObserverName");
59  // debugDrawer.getTopic(*this); // Calls this->getTopic().
60 
61  // getProxyFromProperty<MyProxyInterfacePrx>("MyProxyName");
62 
63  lastSmallTime = IceUtil::Time::now();
64 
65  updateTimes = boost::circular_buffer<IceUtil::Time>(11);
66 
67  simulateWorkForMS = getProperty<int>("SimulateWorkForMS").getValue();
68  }
69 
70 
72  {
73 
74  }
75 
76 
78  {
79 
80  }
81 
82 
83 
84 
86  {
89  }
90 }
91 
92 
93 void armarx::TopicTimingClient::reportSmall(const topic_timing::SmallData& data, const Ice::Current&)
94 {
95  IceUtil::Time time_now = IceUtil::Time::now();
96 
97  IceUtil::Time time_sent = IceUtil::Time::microSeconds(data.sentTimestamp);
98 
99  IceUtil::Time dur_transfer = time_now - time_sent;
100 
101  IceUtil::Time dur_cycle;
102  {
103  std::unique_lock<std::mutex> lock(mutex);
104  dur_cycle = time_now - lastSmallTime;
105  lastSmallTime = time_now;
106  updateTimes.push_back(time_now);
107 
108  usleep(simulateWorkForMS * 1000);
109  }
110 
111  // Calculate updates per second
112  float updatesPerSecond = 0.0f;
113  IceUtil::Time duration = IceUtil::Time::microSeconds(0);
114  if (updateTimes.size() > 1)
115  {
116  duration = updateTimes.back() - updateTimes.front();
117  updatesPerSecond = (updateTimes.size() - 1) / duration.toSecondsDouble();
118  }
119 
120  StringVariantBaseMap channel;
121  channel["DurationTransfer"] = new Variant(dur_transfer.toMilliSecondsDouble());
122  channel["DurationCycle"] = new Variant(dur_cycle.toMilliSecondsDouble());
123  channel["Duration10"] = new Variant(duration.toMilliSecondsDouble());
124  channel["UpdatesPerSecond"] = new Variant(updatesPerSecond);
125  debugObserver->setDebugChannel("TopicTimingClientSmall-" + getName(), channel);
126 }
127 
128 void armarx::TopicTimingClient::reportBig(const topic_timing::BigData& data, const Ice::Current&)
129 {
130  IceUtil::Time sentTime = IceUtil::Time::microSeconds(data.sentTimestamp);
131  (void) sentTime;
132 }
armarx::TopicTimingClient::createPropertyDefinitions
virtual armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: TopicTimingClient.cpp:85
armarx::Variant
The Variant class is described here: Variants.
Definition: Variant.h:224
armarx::StringVariantBaseMap
std::map< std::string, VariantBasePtr > StringVariantBaseMap
Definition: ManagedIceObject.h:111
armarx::TopicTimingClient::reportBig
void reportBig(const topic_timing::BigData &data, const Ice::Current &) override
Definition: TopicTimingClient.cpp:128
armarx::Component::offeringTopicFromProperty
void offeringTopicFromProperty(const std::string &propertyName)
Offer a topic whose name is specified by the given property.
Definition: Component.cpp:154
armarx::TopicTimingClient::onDisconnectComponent
virtual void onDisconnectComponent() override
Definition: TopicTimingClient.cpp:71
armarx::TopicTimingClient::onConnectComponent
virtual void onConnectComponent() override
Definition: TopicTimingClient.cpp:55
armarx::TopicTimingClient::onExitComponent
virtual void onExitComponent() override
Definition: TopicTimingClient.cpp:77
armarx::TopicTimingClient::reportSmall
void reportSmall(const topic_timing::SmallData &data, const Ice::Current &) override
Definition: TopicTimingClient.cpp:93
armarx::TopicTimingClient::getDefaultName
virtual std::string getDefaultName() const override
Definition: TopicTimingClient.cpp:41
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
armarx::Component::usingTopicFromProperty
void usingTopicFromProperty(const std::string &propertyName, bool orderedPublishing=false)
Use a topic whose name is specified by the given property.
Definition: Component.cpp:160
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
TopicTimingClient.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::TopicTimingClient::onInitComponent
virtual void onInitComponent() override
Definition: TopicTimingClient.cpp:47
armarx::ManagedIceObject::getName
std::string getName() const
Retrieve name of object.
Definition: ManagedIceObject.cpp:107
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:34
armarx::TopicTimingClientPropertyDefinitions
Definition: TopicTimingClient.h:42
Variant.h
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::TopicTimingClientPropertyDefinitions::TopicTimingClientPropertyDefinitions
TopicTimingClientPropertyDefinitions(std::string prefix)
Definition: TopicTimingClient.cpp:30