33#include " numerical/controllers/interfaces/PidController.hpp"
44#include " numerical/controllers/interfaces/PidDriver.hpp"
55#include " numerical/math/CompilerOptimizations.hpp"
6- #include < optional>
6+
7+ #if defined(__GNUC__) || defined(__clang__)
8+ #pragma GCC optimize("O3", "fast-math")
9+ #endif
710
811namespace controllers
912{
@@ -15,6 +18,7 @@ namespace controllers
1518 void SetLimits (PidLimits<QNumberType> limits);
1619 void SetTunings (PidTunings<QNumberType> tunnings);
1720 void Enable ();
21+ void Disable ();
1822 QNumberType Process (QNumberType processVariable);
1923
2024 protected:
@@ -24,7 +28,8 @@ namespace controllers
2428 QNumberType Clamp (QNumberType input);
2529
2630 private:
27- std::optional<QNumberType> setPoint;
31+ QNumberType setPointValue{};
32+ bool hasSetPoint = false ;
2833 PidLimits<QNumberType> limits;
2934 QNumberType a0 = 0 ;
3035 QNumberType a1 = 0 ;
@@ -90,7 +95,8 @@ namespace controllers
9095 template <class QNumberType >
9196 void PidIncrementalBase<QNumberType>::SetPoint(QNumberType _setPoint)
9297 {
93- this ->setPoint .emplace (_setPoint);
98+ this ->setPointValue = _setPoint;
99+ this ->hasSetPoint = true ;
94100 }
95101
96102 template <class QNumberType >
@@ -104,6 +110,12 @@ namespace controllers
104110 e_2 = QNumberType (0 .0f );
105111 }
106112
113+ template <class QNumberType >
114+ void PidIncrementalBase<QNumberType>::Disable()
115+ {
116+ hasSetPoint = false ;
117+ }
118+
107119 template <class QNumberType >
108120 void PidIncrementalBase<QNumberType>::SetLimits(PidLimits<QNumberType> _limits)
109121 {
@@ -139,13 +151,13 @@ namespace controllers
139151 QNumberType
140152 PidIncrementalBase<QNumberType>::Process(QNumberType processVariable)
141153 {
142- if (!setPoint. has_value ())
154+ if (!hasSetPoint) [[unlikely]]
143155 return processVariable;
144156
145157 u_1 = u;
146158 e_2 = e_1;
147159 e_1 = e;
148- e = *setPoint - processVariable;
160+ e = setPointValue - processVariable;
149161 u = Clamp (u_1 + a0 * e + a1 * e_1 + a2 * e_2);
150162
151163 return u;
@@ -227,6 +239,7 @@ namespace controllers
227239 template <class QNumberType >
228240 void PidIncrementalSynchronous<QNumberType>::Disable()
229241 {
242+ PidIncrementalBase<QNumberType>::Disable ();
230243 }
231244
232245 template <class QNumberType >
@@ -236,4 +249,16 @@ namespace controllers
236249 {
237250 return PidIncrementalBase<QNumberType>::Process (processVariable);
238251 }
252+
253+ extern template class PidIncrementalBase <float >;
254+ extern template class PidIncrementalBase <math::Q15 >;
255+ extern template class PidIncrementalBase <math::Q31 >;
256+
257+ extern template class PidIncrementalAsynchronous <float >;
258+ extern template class PidIncrementalAsynchronous <math::Q15 >;
259+ extern template class PidIncrementalAsynchronous <math::Q31 >;
260+
261+ extern template class PidIncrementalSynchronous <float >;
262+ extern template class PidIncrementalSynchronous <math::Q15 >;
263+ extern template class PidIncrementalSynchronous <math::Q31 >;
239264}
0 commit comments