Vulcan
Aerospace Engineering Utilities Built on Janus
Loading...
Searching...
No Matches
Nonlinear.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <janus/janus.hpp>
4
5namespace vulcan::tf {
6
19template <typename Scalar>
20Scalar rate_limit(const Scalar &current, const Scalar &commanded,
21 double rate_max, double dt) {
22 Scalar delta = commanded - current;
23 Scalar max_delta = static_cast<Scalar>(rate_max * dt);
24 return current + janus::clamp(delta, -max_delta, max_delta);
25}
26
36template <typename Scalar>
37Scalar saturate(const Scalar &value, const Scalar &min, const Scalar &max) {
38 return janus::clamp(value, min, max);
39}
40
51template <typename Scalar>
52Scalar deadband(const Scalar &input, double deadband_width) {
53 Scalar db = static_cast<Scalar>(deadband_width);
54 Scalar sign_input = janus::where(input < Scalar(0), Scalar(-1), Scalar(1));
55 Scalar abs_input = janus::where(input < Scalar(0), -input, input);
56
57 return janus::where(abs_input <= db, Scalar(0),
58 sign_input * (abs_input - db));
59}
60
72template <typename Scalar>
73Scalar hysteresis(const Scalar &input, const Scalar &last_output,
74 double hysteresis_width) {
75 Scalar h = static_cast<Scalar>(hysteresis_width);
76 Scalar upper = last_output + h;
77 Scalar lower = last_output - h;
78
79 return janus::where(input > upper, input - h,
80 janus::where(input < lower, input + h, last_output));
81}
82
83} // namespace vulcan::tf
Transfer function utilities for linear systems and nonlinear elements.
Definition Discretize.hpp:5
Scalar deadband(const Scalar &input, double deadband_width)
Apply deadband (stateless).
Definition Nonlinear.hpp:52
Scalar rate_limit(const Scalar &current, const Scalar &commanded, double rate_max, double dt)
Apply rate limiting to a value change (stateless).
Definition Nonlinear.hpp:20
Scalar saturate(const Scalar &value, const Scalar &min, const Scalar &max)
Apply saturation/clamping (stateless).
Definition Nonlinear.hpp:37
Scalar hysteresis(const Scalar &input, const Scalar &last_output, double hysteresis_width)
Apply hysteresis (stateless computation).
Definition Nonlinear.hpp:73