RateOptions.hpp
Go to the documentation of this file.
1 /**********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2018, Remo Diethelm
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of Robotic Systems Lab nor ETH Zurich
18  * nor the names of its contributors may be used to endorse or
19  * promote products derived from this software without specific
20  * prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  */
35 
42 #pragma once
43 
44 // std
45 #include <atomic>
46 #include <cmath>
47 #include <string>
48 
49 namespace bota_worker
50 {
55 {
57  std::string name_{};
59  std::atomic<double> timeStep_{ 0.0 };
61  std::atomic<double> maxTimeStepFactorWarning_{ 1.0 };
63  std::atomic<double> maxTimeStepFactorError_{ 10.0 };
65  std::atomic<bool> enforceRate_{ true };
67  std::atomic<clockid_t> clockId_{ CLOCK_MONOTONIC };
68 
79  explicit RateOptions(std::string name = "", const double timeStep = 0.0, const double maxTimeStepFactorWarning = 1.0,
80  const double maxTimeStepFactorError = 10.0, const bool enforceRate = true,
81  const clockid_t clockId = CLOCK_MONOTONIC)
82  : name_(std::move(name))
83  , timeStep_(timeStep)
84  , maxTimeStepFactorWarning_(maxTimeStepFactorWarning)
85  , maxTimeStepFactorError_(maxTimeStepFactorError)
86  , enforceRate_(enforceRate)
87  , clockId_(clockId)
88  {
89  }
90 
95  RateOptions(const RateOptions& other)
96  {
97  *this = other;
98  }
99 
104  RateOptions(RateOptions&& other) noexcept
105  : name_(std::move(other.name_))
106  , timeStep_(other.timeStep_.load())
109  , enforceRate_(other.enforceRate_.load())
110  , clockId_(other.clockId_.load())
111  {
112  }
113 
119  {
120  name_ = other.name_;
121  timeStep_ = other.timeStep_.load();
124  enforceRate_ = other.enforceRate_.load();
125  clockId_ = other.clockId_.load();
126  return *this;
127  }
128 
132  virtual ~RateOptions() = default;
133 
138  virtual bool isValid() const
139  {
140  return (timeStep_ >= 0.0 && !std::isinf(timeStep_) && !std::isnan(timeStep_) && maxTimeStepFactorWarning_ >= 0.0 &&
141  !std::isnan(maxTimeStepFactorWarning_) && maxTimeStepFactorError_ >= 0.0 &&
142  !std::isnan(maxTimeStepFactorError_));
143  }
144 };
145 
146 } // namespace bota_worker
virtual ~RateOptions()=default
RateOptions(std::string name="", const double timeStep=0.0, const double maxTimeStepFactorWarning=1.0, const double maxTimeStepFactorError=10.0, const bool enforceRate=true, const clockid_t clockId=CLOCK_MONOTONIC)
Definition: RateOptions.hpp:79
std::atomic< double > maxTimeStepFactorError_
If the awake time is bigger than the time step multiplied by this factor, it counts as an error...
Definition: RateOptions.hpp:63
RateOptions(const RateOptions &other)
Definition: RateOptions.hpp:95
std::atomic< double > timeStep_
Time step in seconds.
Definition: RateOptions.hpp:59
virtual bool isValid() const
std::atomic< bool > enforceRate_
Boolean indicating whether the rate should be enforced.
Definition: RateOptions.hpp:65
std::string name_
Name for printing.
Definition: RateOptions.hpp:57
RateOptions(RateOptions &&other) noexcept
RateOptions & operator=(const RateOptions &other)
std::atomic< clockid_t > clockId_
Linux clock ID.
Definition: RateOptions.hpp:67
std::atomic< double > maxTimeStepFactorWarning_
If the awake time is bigger than the time step multiplied by this factor, it counts as an warning...
Definition: RateOptions.hpp:61


bota_worker
Author(s):
autogenerated on Wed Mar 3 2021 03:09:10