duration_status.h
Go to the documentation of this file.
1 #pragma once
2 
11 #include <memory>
12 #include <mutex>
13 #include <string>
14 #include <vector>
15 
18 #include <ros/duration.h>
19 #include <ros/time.h>
20 
25 
26 namespace cras
27 {
28 
35 {
36 public:
43  DurationStatus(const ::std::string& name, const ::cras::DurationStatusParam& params);
44 
55  explicit DurationStatus(const ::std::string& name,
56  const ::ros::Duration& minDuration = {0, 0}, const ::ros::Duration& maxDuration = ::ros::DURATION_MAX,
57  double tolerance = 0.1, size_t windowSize = 5u, bool noEventsIsOk = true);
58 
64  DurationStatus(const ::std::string& name, const ::cras::SimpleDurationStatusParam& params);
65 
66  DurationStatus(const ::std::string& name, const ::cras::BoundParamHelperPtr& params,
67  const ::cras::DurationStatusParam& defaultParams);
68 
69  DurationStatus(const ::std::string& name, const ::cras::BoundParamHelperPtr& params,
70  const ::cras::SimpleDurationStatusParam& defaultParams);
71 
72  ~DurationStatus() override;
73 
78  void start(const ::ros::Time& time = ::ros::Time::now());
79 
84  void start(const ::ros::WallTime& time);
85 
90  void stop(const ::ros::Time& time = ::ros::Time::now());
91 
96  void stop(const ::ros::WallTime& time);
97 
98  void run(::diagnostic_updater::DiagnosticStatusWrapper& stat) override;
99 
104  const ::ros::Duration& getMinDuration() const;
105 
110  const ::ros::Duration& getMaxDuration() const;
111 
116  double getTolerance() const;
117 
122  size_t getWindowSize() const;
123 
124 protected:
127 
128  bool wallTimeMode {false};
129  size_t count {0u};
131  ::cras::optional<::ros::Time> lastStartTime;
132  ::std::vector<::ros::Duration> minDurations;
133  ::std::vector<::ros::Duration> maxDurations;
134  ::std::vector<::ros::Time> historyTimes;
135  ::std::vector<::cras::RunningStats<::ros::Duration>> historyStats;
136  size_t historyIndex {0u};
137  ::std::mutex lock;
138 };
139 
140 using DurationStatusPtr = ::std::shared_ptr<::cras::DurationStatus>;
141 
142 }
Template specializations of RunningStats for ros::Duration and ros::WallDuration. ...
Parameters of DurationStatus diagnostic task.
::cras::RunningStats<::ros::Duration > stats
::std::vector<::cras::RunningStats<::ros::Duration > > historyStats
A C++11 shim for std::optional. Uses std::optional when used in C++17 mode.
Definitions of parameters for a DurationStatus diagnostic task.
~DurationStatus() override
const ::ros::Duration & getMinDuration() const
Minimum allowed duration.
DurationStatus(const ::std::string &name, const ::cras::DurationStatusParam &params)
Create the diagnostic task for a header-less message (checking frequency only).
::cras::optional<::ros::Time > lastStartTime
::std::vector<::ros::Duration > maxDurations
size_t getWindowSize() const
Number of updates during which the duration is computed.
void stop(const ::ros::Time &time=::ros::Time::now())
Stop a single duration measurement.
double getTolerance() const
Tolerance of duration.
const ::ros::Duration & getMaxDuration() const
Maximum allowed duration.
::std::shared_ptr<::cras::BoundParamHelper > BoundParamHelperPtr
::std::shared_ptr<::cras::DurationStatus > DurationStatusPtr
Diagnostic task for topic frequency and timestamp delay (combining FrequencyStatus and TimeStampStatu...
Computation of running average and variance using Welford&#39;s algorithm.
::std::vector<::ros::Time > historyTimes
::std::vector<::ros::Duration > minDurations
::cras::DurationStatusParam params
The parameters via which this task has been configured.
Definition: any.hpp:15
void run(::diagnostic_updater::DiagnosticStatusWrapper &stat) override
static Time now()
void start(const ::ros::Time &time=::ros::Time::now())
Start a single duration measurement.
Bound param helper (allows omitting the param adapter in each getParam call).


cras_cpp_common
Author(s): Martin Pecka
autogenerated on Sat Jun 17 2023 02:32:53