28 #ifdef EMLABCPP_USE_NLOHMANN_JSON
29 #include <nlohmann/json.hpp>
59 template <
typename TimeType >
79 template <
typename TimeType >
87 template <
typename TimeType >
106 template <
typename TimeType >
112 auto t_diff =
static_cast< float >( now -
pid.
last_time );
116 float const error = desired - measured;
117 pid.
i_sum += coeff.
i * ( error * t_diff );
130 template <
typename TimeType >
139 #ifdef EMLABCPP_USE_NLOHMANN_JSON
142 struct nlohmann::adl_serializer<
emlabcpp::pid_coefficients >
146 static void to_json( nlohmann::json& j, cfg_type
const& cfg )
153 static cfg_type from_json( nlohmann::json
const& j )
164 struct nlohmann::adl_serializer<
emlabcpp::pid_config >
168 static void to_json( nlohmann::json& j, cfg_type
const& cfg )
171 j[
"limits"] = cfg.limits;
174 static cfg_type from_json( nlohmann::json
const& j )
178 cfg.limits = j[
"limits"];
MIT License.
Definition: impl.h:31
pid_coefficients coefficients
Definition: pid.h:46
min_max< float > limits
limits the output of the pid regulator and internal anti-windup mechanism
Definition: pid.h:49
float d
Definition: pid.h:40
float update(pid< TimeType > &pid, TimeType now, float measured, float desired)
Call this reularly, the meaning of time value 'now' is up to you, just be consistent.
Definition: pid.h:107
void reset(pid< TimeType > &pid, TimeType now, float last_measured)
Definition: pid.h:131
constexpr T const & clamp(T const &x, min_max< T > const &mm, Compare &&comp)
Definition: min_max.h:69
float i
Definition: pid.h:39
void update_limits(pid< TimeType > &pid, min_max< float > lim)
Definition: pid.h:80
float p
coeficients
Definition: pid.h:38
void update_output(pid< TimeType > &pid, float output)
Definition: pid.h:88
Structure to configure the pid regulator.
Definition: pid.h:45
Implementation of PID regulator, the object should be constructed and populated with pid<T>::conf str...
Definition: pid.h:61
pid(time_type now, config const &conf=config{})
Definition: pid.h:71
TimeType time_type
Definition: pid.h:62
float last_measured
Definition: pid.h:67
time_type last_time
Definition: pid.h:68
float output
Definition: pid.h:69
config cfg
Definition: pid.h:65
float i_sum
Definition: pid.h:66