Vulcan
Aerospace Engineering Utilities Built on Janus
Loading...
Searching...
No Matches
FirstOrder.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> struct FirstOrderCoeffs {
20 Scalar a;
21 Scalar b;
22 double tau;
23 double K;
24 double dt;
25};
26
36template <typename Scalar>
37FirstOrderCoeffs<Scalar> first_order(double tau, double K, double dt) {
38 double a = std::exp(-dt / tau);
39 double b = K * (1.0 - a);
40 return FirstOrderCoeffs<Scalar>{static_cast<Scalar>(a),
41 static_cast<Scalar>(b), tau, K, dt};
42}
43
55template <typename Scalar>
57 const Scalar &state, const Scalar &input) {
58 return coeffs.a * state + coeffs.b * input;
59}
60
72template <typename Scalar>
73Scalar first_order_response(double tau, double K, const Scalar &t) {
74 return static_cast<Scalar>(K) * (1.0 - janus::exp(-t / tau));
75}
76
77} // namespace vulcan::tf
Transfer function utilities for linear systems and nonlinear elements.
Definition Discretize.hpp:5
FirstOrderCoeffs< Scalar > first_order(double tau, double K, double dt)
Compute first-order discrete-time system coefficients.
Definition FirstOrder.hpp:37
Scalar first_order_response(double tau, double K, const Scalar &t)
Compute analytical step response at time t.
Definition FirstOrder.hpp:73
Scalar first_order_step(const FirstOrderCoeffs< Scalar > &coeffs, const Scalar &state, const Scalar &input)
Compute next state for first-order system (stateless).
Definition FirstOrder.hpp:56
First-order discrete-time system coefficients.
Definition FirstOrder.hpp:19
Scalar a
State coefficient: exp(-dt/τ).
Definition FirstOrder.hpp:20
double tau
Time constant [s].
Definition FirstOrder.hpp:22
double K
DC gain.
Definition FirstOrder.hpp:23
double dt
Sample time [s].
Definition FirstOrder.hpp:24
Scalar b
Input coefficient: K*(1 - a).
Definition FirstOrder.hpp:21