Skip to content

Commit

Permalink
Use std::numeric_limits<double>::quiet_NaN()
Browse files Browse the repository at this point in the history
  • Loading branch information
christophfroehlich committed Nov 18, 2024
1 parent 023f317 commit 5f17790
Showing 1 changed file with 25 additions and 16 deletions.
41 changes: 25 additions & 16 deletions include/control_toolbox/rate_limiter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#define CONTROL_TOOLBOX__RATE_LIMITER_HPP_

#include <cmath>
#include <limits>

#include <algorithm>
#include <stdexcept>
Expand Down Expand Up @@ -48,10 +49,14 @@ class RateLimiter
* If min_first_derivative_pos/max_first_derivative_neg values are NAN, symmetric limits are used
*/
RateLimiter(
T min_value = NAN, T max_value = NAN,
T min_first_derivative_neg = NAN, T max_first_derivative_pos = NAN,
T min_first_derivative_pos = NAN, T max_first_derivative_neg = NAN,
T min_second_derivative = NAN, T max_second_derivative = NAN);
T min_value = std::numeric_limits<double>::quiet_NaN(),
T max_value = std::numeric_limits<double>::quiet_NaN(),
T min_first_derivative_neg = std::numeric_limits<double>::quiet_NaN(),
T max_first_derivative_pos = std::numeric_limits<double>::quiet_NaN(),
T min_first_derivative_pos = std::numeric_limits<double>::quiet_NaN(),
T max_first_derivative_neg = std::numeric_limits<double>::quiet_NaN(),
T min_second_derivative = std::numeric_limits<double>::quiet_NaN(),
T max_second_derivative = std::numeric_limits<double>::quiet_NaN());

/**
* \brief Limit the value and first_derivative
Expand Down Expand Up @@ -109,10 +114,14 @@ class RateLimiter
* If min_first_derivative_pos/max_first_derivative_neg values are NAN, symmetric limits are used
*/
void set_params(
T min_value = NAN, T max_value = NAN,
T min_first_derivative_neg = NAN, T max_first_derivative_pos = NAN,
T min_first_derivative_pos = NAN, T max_first_derivative_neg = NAN,
T min_second_derivative = NAN, T max_second_derivative = NAN);
T min_value = std::numeric_limits<double>::quiet_NaN(),
T max_value = std::numeric_limits<double>::quiet_NaN(),
T min_first_derivative_neg = std::numeric_limits<double>::quiet_NaN(),
T max_first_derivative_pos = std::numeric_limits<double>::quiet_NaN(),
T min_first_derivative_pos = std::numeric_limits<double>::quiet_NaN(),
T max_first_derivative_neg = std::numeric_limits<double>::quiet_NaN(),
T min_second_derivative = std::numeric_limits<double>::quiet_NaN(),
T max_second_derivative = std::numeric_limits<double>::quiet_NaN());

private:
// Enable/Disable value/first_derivative/second_derivative limits:
Expand All @@ -121,18 +130,18 @@ class RateLimiter
bool has_second_derivative_limits_ = true;

// value limits:
T min_value_ = NAN;
T max_value_ = NAN;
T min_value_ = std::numeric_limits<double>::quiet_NaN();
T max_value_ = std::numeric_limits<double>::quiet_NaN();

// first_derivative limits:
T min_first_derivative_neg_ = NAN;
T max_first_derivative_pos_ = NAN;
T min_first_derivative_pos_ = NAN;
T max_first_derivative_neg_ = NAN;
T min_first_derivative_neg_ = std::numeric_limits<double>::quiet_NaN();
T max_first_derivative_pos_ = std::numeric_limits<double>::quiet_NaN();
T min_first_derivative_pos_ = std::numeric_limits<double>::quiet_NaN();
T max_first_derivative_neg_ = std::numeric_limits<double>::quiet_NaN();

// second_derivative limits:
T min_second_derivative_ = NAN;
T max_second_derivative_ = NAN;
T min_second_derivative_ = std::numeric_limits<double>::quiet_NaN();
T max_second_derivative_ = std::numeric_limits<double>::quiet_NaN();
};

template <typename T>
Expand Down

0 comments on commit 5f17790

Please sign in to comment.