iCub-main
Loading...
Searching...
No Matches
PeriodicEventsVerifier.cpp
Go to the documentation of this file.
1/******************************************************************************
2 * *
3 * Copyright (C) 2019 Fondazione Istituto Italiano di Tecnologia (IIT) *
4 * All Rights Reserved. *
5 * *
6 ******************************************************************************/
7
8
16#include "../include/PeriodicEventsVerifier.h"
17#include "embot_tools.h"
18#include <yarp/os/LogStream.h>
19
20
21using yarp::os::Log;
22
23
24
25// --------------------------------------------------------------------------------------------------------------------
26// - pimpl: private implementation (see scott meyers: item 22 of effective modern c++, item 31 of effective c++
27// --------------------------------------------------------------------------------------------------------------------
28
30{
31
33 std::string name;
34
36 {
37
38 }
39
40 bool init(double period, double tolerance, double min, double max, double step, double reportPeriod, const std::string& name = {})
41 {
42 // now transform each parameter expressed in seconds to microseconds
43 uint64_t period_us=period*1000000;
44 uint64_t tolerance_us=tolerance*1000000;
45 uint64_t min_us=min*1000000;
46 uint64_t max_us=max*1000000;
47 uint32_t step_us=step*1000000;
48 uint64_t reportPeriod_us=reportPeriod*1000000;
49 this->name=name;
50
51 return m_perVal.init({period_us, period_us+tolerance_us, reportPeriod_us,
52 {min_us, max_us, step_us}});
53
54 }
55
56 void tick(double currentTime)
57 {
58
59 uint64_t tnow = static_cast<std::uint64_t>(currentTime * 1000000);
60 uint64_t delta = 0;
61 m_perVal.tick(tnow, delta);
62 if(true == m_perVal.report())
63 {
64 std::vector<double> vect_prob;
66 uint32_t min = m_perVal.histogram()->getconfig()->min;
67 uint32_t step = m_perVal.histogram()->getconfig()->step;
68 yWarning() << "---------- PRINT HISTO" << name << "---------------";
69 for(int i=0; i<vect_prob.size(); i++)
70 {
71 if(vect_prob[i]==0)
72 continue;
73
74 yWarning() << "-- histo" << name << "[" << min+step*i << "]="<< vect_prob[i];
75 }
76 yWarning() << "---------- END PRINT HISTO" << name << "---------------";
78 }
79
80 }
81
82}; //end Tools::Emb_PeriodicEventVerifier::Impl
83
85{
87 std::string name;
88
90 {
91 }
92
93 bool init(double desiredResponseTime, double tolerance, double min, double max, double step, double reportPeriod, const std::string& name = {})
94 {
95
96 // now transform each parameter expressed in seconds to microseconds
97 uint64_t desiredResponseTime_us=desiredResponseTime*1000000;
98 uint64_t tolerance_us=tolerance*1000000;
99 uint64_t min_us=min*1000000;
100 uint64_t max_us=max*1000000;
101 uint32_t step_us=step*1000000;
102 uint64_t reportPeriod_us=reportPeriod*1000000;
103 this->name = name;
104 return m_roundTripVal.init({desiredResponseTime_us, desiredResponseTime_us+tolerance_us, reportPeriod_us,
105 {min_us, max_us, step_us}});
106 }
107
108
109
110 void tick(double currentResponseTime, double requestTime)
111 {
112 m_roundTripVal.tick(currentResponseTime, static_cast<std::uint64_t>(1000000.0*requestTime));
113
114 if(true == m_roundTripVal.report())
115 {
117 const embot::tools::Histogram::Values* val=histo->getvalues();
118
119 std::vector<double> vect_prob;
121 uint32_t min = m_roundTripVal.histogram()->getconfig()->min;
122 uint32_t step = m_roundTripVal.histogram()->getconfig()->step;
123 yInfo() << "---------- PRINT HISTO" << name << "---------------";
124 for(int i=0; i<vect_prob.size(); i++)
125 {
126 if(vect_prob[i]==0)
127 continue;
128 yInfo() << "-- histo PID [" << min+step*i << "]="<< vect_prob[i];
129 }
130 yInfo() << "---------- END PRINT HISTO" << name << "---------------";
132 }
133 }
134
135};
136
137// --------------------------------------------------------------------------------------------------------------------
138// - all the rest
139// --------------------------------------------------------------------------------------------------------------------
140
141
142
145
150
151
152bool Tools::Emb_PeriodicEventVerifier::init(double period, double tolerance, double min, double max, double step, double reportPeriod, const std::string& name)
153{
154 return pImpl->init(period, tolerance, min, max, step, reportPeriod, name);
155}
156
158{
159 pImpl->tick(currentTime);
160}
161
162
165
170
171
172bool Tools::Emb_RensponseTimingVerifier::init(double desiredResponseTime, double tolerance, double min, double max, double step, double reportPeriod, const std::string& name)
173{
174 return pImpl->init(desiredResponseTime, tolerance, min, max, step, reportPeriod, name);
175}
176
177
178void Tools::Emb_RensponseTimingVerifier::tick(double currentResponseTime, double requestTime)
179{
180 return pImpl->tick(currentResponseTime, requestTime);
181}
182
183
184
185// - end-of-file (leave a blank line after)----------------------------------------------------------------------------
constexpr double tolerance
void tick(double currentTime)
Signals occurrence of the event to the object.
bool init(double period, double tolerance, double min, double max, double step, double reportPeriod, const std::string &name={})
Initializes the object with custom parameters.
bool init(double desiredResponseTime, double tolerance, double min, double max, double step, double reportPeriod, const std::string &name={})
Initializes the object with custom parameters.
void tick(double currentResponseTime, double requestTime)
Adds the current response time to the collection of data of the object.
const embot::tools::Histogram::Values * getvalues() const
const embot::tools::Histogram::Config * getconfig() const
bool probabilitydensityfunction(std::vector< std::uint32_t > &values, const std::uint32_t scale) const
bool init(const Config &config)
const embot::tools::Histogram * histogram() const
bool tick(std::uint64_t currtime_usec, std::uint64_t &deltatime_usec)
bool init(const Config &config)
const embot::tools::Histogram * histogram() const
bool tick(std::uint64_t deltatime_usec, std::uint64_t timestamp)
bool init(double period, double tolerance, double min, double max, double step, double reportPeriod, const std::string &name={})
embot::tools::RoundTripValidator m_roundTripVal
void tick(double currentResponseTime, double requestTime)
bool init(double desiredResponseTime, double tolerance, double min, double max, double step, double reportPeriod, const std::string &name={})