@@ -249,7 +249,7 @@ namespace qlibs {
249249
250250 /* *
251251 * @brief Returns the number of delay steps configured for this instance.
252- *
252+ *
253253 * @return The number of delays (equal to the template parameter).
254254 */
255255 size_t getNumberOfDelays () const noexcept {
@@ -802,6 +802,10 @@ namespace qlibs {
802802 bool setIntegrationMethod ( integrationMethod m );
803803 };
804804
805+
806+ using customProcessModel = real_t (*)(real_t , void *);
807+
808+
805809 /* *
806810 * @brief A Smith Predictor implementation for compensating time delays in
807811 * control systems.
@@ -812,10 +816,12 @@ namespace qlibs {
812816 */
813817 class smithPredictor {
814818 private:
815- ltisys *model;
819+ ltisys *model{nullptr };
820+ customProcessModel modelAlternate{ nullptr };
816821 ITransportDelay *modelDelay;
817822 ltisys *filter{ nullptr };
818823 real_t yp_hat;
824+ void *alternateData{ nullptr };
819825 public:
820826 virtual ~smithPredictor () {}
821827 /* *
@@ -835,6 +841,22 @@ namespace qlibs {
835841 const real_t initialCondition = 0 .0_re )
836842 : model(&modelTf), modelDelay(&mDelay ), yp_hat(initialCondition) {}
837843
844+ /* *
845+ * @brief Constructs a Smith Predictor with a plant model, delay model,
846+ * and optional initial output estimate.
847+ * @param[in] modelCustom Reference to the system model representing the
848+ * delay-free plant. User should define a custom function that recreates
849+ * the system dynamics.
850+ * @param[in] mDelay Reference to the transport delay block modeling the
851+ * plant’s dead time.
852+ * @param[in] initialCondition Initial value for the internal output
853+ * prediction (@c yp_hat). Default is 0.0.
854+ */
855+ smithPredictor ( customProcessModel modelCustom,
856+ ITransportDelay& mDelay ,
857+ const real_t initialCondition = 0 .0_re )
858+ : modelAlternate(modelCustom), modelDelay(&mDelay ), yp_hat(initialCondition) {}
859+
838860 /* *
839861 * @brief Constructs a Smith Predictor with a plant model, delay model,
840862 * and optional initial output estimate.
@@ -855,6 +877,27 @@ namespace qlibs {
855877 const real_t initialCondition = 0 .0_re )
856878 : model(&modelTf), modelDelay(&mDelay ), filter(&filterTf), yp_hat(initialCondition) {}
857879
880+ /* *
881+ * @brief Constructs a Smith Predictor with a plant model, delay model,
882+ * and optional initial output estimate.
883+ * @param[in] modelCustom Reference to the system model representing the
884+ * delay-free plant. User should define a custom function that recreates
885+ * the system dynamics.
886+ * @param[in] mDelay Reference to the transport delay block modeling the
887+ * plant’s dead time.
888+ * @param[in] filterTf Reference to the LTI system used as the robustness
889+ * filter.
890+ * @param[in] initialCondition Initial value for the internal output
891+ * prediction (@c yp_hat). Default is 0.0.
892+ *
893+ * @note Both the model and delay block are passed by reference and stored internally as pointers.
894+ */
895+ smithPredictor ( customProcessModel modelCustom,
896+ ITransportDelay& mDelay ,
897+ ltisys& filterTf,
898+ const real_t initialCondition = 0 .0_re )
899+ : modelAlternate(modelCustom), modelDelay(&mDelay ), filter(&filterTf), yp_hat(initialCondition) {}
900+
858901 /* *
859902 * @brief Updates the internal prediction based on control input and
860903 * measured plant output.
@@ -895,8 +938,27 @@ namespace qlibs {
895938 * and does not affect the plant or delay block directly.
896939 */
897940 bool setFilter ( ltisys& filterTf ) noexcept {
898- filter = &filterTf;
899- return true ;
941+ bool retValue = filter != &filterTf;
942+ if ( retValue ) {
943+ filter = &filterTf;
944+ }
945+ return retValue;
946+ }
947+
948+ /* *
949+ * @brief Sets the model data when alternate when a custom delay-free
950+ * plant model is used
951+ *
952+ * @param[in] data The data passed to the user-defined model at the moment
953+ * of evaluation
954+ * @return @c true on success. False otherwise
955+ */
956+ bool setModelData ( void * data ) noexcept {
957+ bool retValue = data != alternateData;
958+ if ( retValue ) {
959+ alternateData = data;
960+ }
961+ return retValue;
900962 }
901963 };
902964
0 commit comments