12#include <include/qlibs_types.hpp>
13#include <include/tdl.hpp>
14#include <include/numa.hpp>
29 #if !defined( LTISYS_EVAL_MODEL_CONTROLLABLE ) || !defined( LTISYS_EVAL_MODEL_OBSERVABLE )
30 #define LTISYS_EVAL_MODEL_CONTROLLABLE
46 template<
size_t order>
52 template<
size_t order>
60 template<
size_t order>
77 static_assert( order >= 1 ,
"Order should be greater than 0" );
78 for (
size_t i = 0; i <= order; ++i ) {
79 num[ i ] = numerator[ i ];
80 den[ i ] = denominator[ i ];
113 return static_cast<size_t>( (
value/dt ) + 0.5_re);
122 return static_cast<size_t>( (
value/dt ) + 0.5_re);
155 return static_cast<size_t>( ( td.
value/dt ) + 0.5_re );
169 return static_cast<size_t>( ( Time/dt ) + 0.5_re );
183 return static_cast<size_t>( ( Time.
value/dt ) + 0.5_re );
187 class ITransportDelay {
189 virtual ~ITransportDelay() =
default;
190 virtual real_t delay(
const real_t xInput)
noexcept = 0;
191 virtual real_t operator()(
const real_t xInput)
noexcept = 0;
192 virtual size_t getNumberOfDelays() const noexcept = 0;
211 template<
size_t numberOfDelays>
214 real_t buf[ numberOfDelays + 1 ];
225 static_assert( numberOfDelays >= 1 ,
"Delay taps should be greater than 0" );
226 dl.setup( buf, initValue);
236 dl.insertSample( xInput );
237 return dl.getOldest();
247 return delay( xInput );
256 return numberOfDelays;
265 template<
size_t delay>
275 template<
size_t NB,
size_t NA>
291 for (
size_t i = 0; i < NB; ++i ) {
292 num[ i ] = numerator[ i ];
294 for (
size_t i = 0; i < NA; ++i ) {
295 den[ i ] = denominator[ i ];
315 void normalizeTransferFunction(
real_t *num,
404 bool setDelay(
real_t *
const w,
406 const real_t initVal = 0.0_re )
noexcept;
414 bool setSaturation(
const real_t minV,
415 const real_t maxV )
noexcept;
458 const size_t n_a )
noexcept
460 (void)
setup( num, den, x, n_b, n_a );
481 template<
size_t NB,
size_t NA>
486 (void)
setup( num, den, x, NB, NA );
494 template<
size_t NB,
size_t NA>
497 (void)
setup( dtf.num, dtf.den, dtf.states, NB, NA );
529 const size_t n_a )
noexcept;
550 template<
size_t NB,
size_t NA>
555 return setup( num, den, x, NB, NA );
564 template<
size_t NB,
size_t NA>
567 return setup( dtf.num, dtf.den, dtf.states, NB, NA );
588 bool setInitStates(
const real_t *xi =
nullptr )
override;
608 const real_t *
const c =
nullptr );
651 const real_t dT )
noexcept
653 (void)
setup( num, den, x, nD, dT );
662 template<
size_t order>
665 (void)
setup( ctf.num, ctf.den, ctf.states, order, dT );
688 template<
size_t systemOrder>
690 real_t (&den)[ systemOrder+1 ],
691 nState (&x)[ systemOrder ],
692 const real_t dT )
noexcept
694 (void)
setup( num, den, x, systemOrder, dT );
725 const real_t dT )
noexcept;
748 template<
size_t systemOrder>
750 real_t (&den)[ systemOrder+1 ],
751 nState (&x)[ systemOrder ],
752 const real_t dT )
noexcept
754 return setup( num, den, x, systemOrder, dT );
764 template<
size_t order>
767 return setup( ctf.num, ctf.den, ctf.states, order, dT );
788 bool setInitStates(
const real_t *xi =
nullptr )
override;
821 ITransportDelay *modelDelay;
822 ltisys *filter{
nullptr };
824 void *alternateData{
nullptr };
840 ITransportDelay& mDelay,
841 const real_t initialCondition = 0.0_re )
842 : model(&modelTf), modelDelay(&mDelay), yp_hat(initialCondition) {}
856 ITransportDelay& mDelay,
857 const real_t initialCondition = 0.0_re )
858 : modelAlternate(modelCustom), modelDelay(&mDelay), yp_hat(initialCondition) {}
875 ITransportDelay& mDelay,
877 const real_t initialCondition = 0.0_re )
878 : model(&modelTf), modelDelay(&mDelay), filter(&filterTf), yp_hat(initialCondition) {}
896 ITransportDelay& mDelay,
898 const real_t initialCondition = 0.0_re )
899 : modelAlternate(modelCustom), modelDelay(&mDelay), filter(&filterTf), yp_hat(initialCondition) {}
916 bool updatePrediction(
const real_t ut,
917 const real_t yt )
noexcept;
941 bool retValue = filter != &filterTf;
957 bool retValue = data != alternateData;
959 alternateData = data;
virtual ~continuousSystem()
Definition ltisys.hpp:622
continuousSystem(real_t(&num)[systemOrder+1], real_t(&den)[systemOrder+1], nState(&x)[systemOrder], const real_t dT) noexcept
Constructor for an instance of a LTI continuous system.
Definition ltisys.hpp:689
continuousSystem(real_t *num, real_t *den, nState *x, const size_t nD, const real_t dT) noexcept
Constructor for an instance of a LTI continuous system.
Definition ltisys.hpp:647
bool setup(real_t(&num)[systemOrder+1], real_t(&den)[systemOrder+1], nState(&x)[systemOrder], const real_t dT) noexcept
Setup and initialize an instance of a LTI continuous system.
Definition ltisys.hpp:749
continuousSystem(continuousTF< order > &ctf, const real_t dT)
Constructor for an instance of a LTI continuous system from a transfer function definition.
Definition ltisys.hpp:663
bool isInitialized(void) const override
Check if the LTI continuous system is initialized.
Definition ltisys.hpp:775
bool setup(real_t *num, real_t *den, nState *x, const size_t nD, const real_t dT) noexcept
Setup and initialize an instance of a LTI continuous system.
Definition ltisys.cpp:156
bool setup(continuousTF< order > &ctf, const real_t dT)
Setup and initialize an instance of a LTI continuous system from a transfer function definition.
Definition ltisys.hpp:765
virtual ~discreteSystem()
Definition ltisys.hpp:428
bool setup(real_t *num, real_t *den, real_t *x, const size_t n_b, const size_t n_a) noexcept
Setup and initialize an instance of the discrete LTI system.
Definition ltisys.cpp:121
discreteSystem(discreteTF< NB, NA > &dtf) noexcept
Constructor for a the discrete LTI system from a transfer function definition.
Definition ltisys.hpp:495
bool setup(discreteTF< NB, NA > &dtf) noexcept
Setup and initialize an instance of the discrete LTI system from a transfer function definition.
Definition ltisys.hpp:565
bool setup(real_t(&num)[NB], real_t(&den)[NA], real_t *x)
Setup and initialize an instance of the discrete LTI system.
Definition ltisys.hpp:551
discreteSystem(real_t *num, real_t *den, real_t *x, const size_t n_b, const size_t n_a) noexcept
Constructor for a the discrete LTI system.
Definition ltisys.hpp:454
discreteSystem(real_t(&num)[NB], real_t(&den)[NA], real_t *x) noexcept
Constructor for a the discrete LTI system.
Definition ltisys.hpp:482
bool isInitialized(void) const override
Check if the LTI discrete system is initialized.
Definition ltisys.hpp:575
A LTI system base class.
Definition ltisys.hpp:304
virtual ~ltisys()
Definition ltisys.hpp:324
virtual bool isInitialized(void) const =0
Check if the LTI system is initialized.
ltisysType getType(void) const
Get the LTI system type.
Definition ltisys.hpp:390
real_t excite(real_t u) noexcept
Drives the LTI system recursively using the provided input sample.
Definition ltisys.cpp:58
virtual bool setInitStates(const real_t *xi=nullptr)=0
Set the initial states for the given system.
real_t operator()(const real_t u)
Drives the LTI system recursively using the provided input sample.
Definition ltisys.hpp:365
A numerical state object.
Definition numa.hpp:50
smithPredictor(ltisys &modelTf, ITransportDelay &mDelay, ltisys &filterTf, const real_t initialCondition=0.0_re)
Constructs a Smith Predictor with a plant model, delay model, and optional initial output estimate.
Definition ltisys.hpp:874
bool setModelData(void *data) noexcept
Sets the model data when alternate when a custom delay-free plant model is used.
Definition ltisys.hpp:956
smithPredictor(customProcessModel modelCustom, ITransportDelay &mDelay, ltisys &filterTf, const real_t initialCondition=0.0_re)
Constructs a Smith Predictor with a plant model, delay model, and optional initial output estimate.
Definition ltisys.hpp:895
smithPredictor(ltisys &modelTf, ITransportDelay &mDelay, const real_t initialCondition=0.0_re)
Constructs a Smith Predictor with a plant model, delay model, and optional initial output estimate.
Definition ltisys.hpp:839
real_t getPrediction() const noexcept
Retrieves the current delay-free predicted output of the system.
Definition ltisys.hpp:923
virtual ~smithPredictor()
Definition ltisys.hpp:826
bool setFilter(ltisys &filterTf) noexcept
Sets an optional filter for the internal Smith Predictor model.
Definition ltisys.hpp:940
smithPredictor(customProcessModel modelCustom, ITransportDelay &mDelay, const real_t initialCondition=0.0_re)
Constructs a Smith Predictor with a plant model, delay model, and optional initial output estimate.
Definition ltisys.hpp:855
A Tapped Delay Line (TDL) object.
Definition tdl.hpp:32
Delays the input by a specified amount of time. You can use this class to simulate a time delay.
Definition ltisys.hpp:212
virtual ~transportDelay()
Definition ltisys.hpp:217
transportDelay(const real_t initValue=0.0_re)
Constructor for the transportDelay class.
Definition ltisys.hpp:223
real_t delay(const real_t xInput) noexcept override
Delays the input by a specified amount of time.
Definition ltisys.hpp:234
size_t getNumberOfDelays() const noexcept
Returns the number of delay steps configured for this instance.
Definition ltisys.hpp:255
real_t operator()(const real_t xInput) noexcept override
Delays the input by a specified amount of time.
Definition ltisys.hpp:245
ltisysType
All the possible natures of a LTI system.
Definition ltisys.hpp:37
transportDelay< delay > discreteDelay
Delays the input by a specified amount of samples. You can use this class to simulate a discrete time...
Definition ltisys.hpp:266
constexpr size_t delayFromTime(const real_t Time, const real_t dt)
Computes the number of discrete delays required for a specified amount of time using a defined time-s...
Definition ltisys.hpp:167
nState[order] continuousStates
Type to specify continuous states.
Definition ltisys.hpp:47
constexpr size_t operator,(const timeDelay td, const real_t dt)
Computes the delay in discrete steps using the comma operator.
Definition ltisys.hpp:154
real_t[order] discreteStates
Type to specify discrete states.
Definition ltisys.hpp:53
real_t(*)(real_t, void *) customProcessModel
Definition ltisys.hpp:806
@ LTISYS_TYPE_CONTINUOUS
Definition ltisys.hpp:39
@ LTISYS_TYPE_DISCRETE
Definition ltisys.hpp:40
@ LTISYS_TYPE_UNKNOWN
Definition ltisys.hpp:38
integrationMethod
An enum with all the available integration methods.
Definition numa.hpp:28
The qLibs++ library namespace.
Definition mat.hpp:18
float real_t
A type to instantiate a real variable double-precision of 64-bits IEEE 754.
Definition qlibs_types.hpp:43
Continuous transfer function for easy LTI system definition.
Definition ltisys.hpp:61
continuousTF(const real_t(&numerator)[order+1], const real_t(&denominator)[order+1])
Constructor for the continuousTF class.
Definition ltisys.hpp:75
Discrete transfer function for easy LTI system definition.
Definition ltisys.hpp:276
discreteTF(const real_t(&numerator)[NB], const real_t(&denominator)[NA])
Constructor for the discreteTF class.
Definition ltisys.hpp:290
Represents a time delay value for use in transportDelay constructor.
Definition ltisys.hpp:97
constexpr timeDelay(real_t v)
Construct a new timeDelay object.
Definition ltisys.hpp:105
real_t value
Delay duration in seconds.
Definition ltisys.hpp:99
constexpr size_t operator()(const real_t dt) const
Computes the number of discrete steps equivalent to the delay.
Definition ltisys.hpp:112
constexpr size_t operator[](const real_t dt) const
Alternate syntax to compute delay in steps using indexing operator.
Definition ltisys.hpp:121