Rate limiter class.
Dependents: BLDC_mainProgram L298N-Breakout-Test HBridgeDCMotor STMF302R8_MotorDrive ... more
Revision 0:d735360f91f9, committed 2015-01-14
- Comitter:
- tbjazic
- Date:
- Wed Jan 14 08:49:46 2015 +0000
- Commit message:
- Initial commit.
Changed in this revision
| RateLimiter.cpp | Show annotated file Show diff for this revision Revisions of this file |
| RateLimiter.h | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/RateLimiter.cpp Wed Jan 14 08:49:46 2015 +0000
@@ -0,0 +1,53 @@
+#include "RateLimiter.h"
+
+RateLimiter::RateLimiter () {
+ setLimits(1, -1, 0, 10e-3);
+}
+
+RateLimiter::RateLimiter (float R, float F, float y0, float T_d) {
+ setLimits(R, F, y0, T_d);
+}
+
+void RateLimiter::reset() {
+ y0 = 0;
+}
+
+void RateLimiter::setLimits(float R, float F) {
+ if (R < 0) {
+ R = -R;
+ }
+ if (F > 0) {
+ F = -F;
+ }
+ this->R = R;
+ this->F = F;
+}
+
+void RateLimiter::setLimits(float R, float F, float y0, float T_d) {
+ if (R < 0) {
+ R = -R;
+ }
+ if (F > 0) {
+ F = -F;
+ }
+ if (T_d <= 1e-6) {
+ T_d = 1e-3;
+ }
+ this->T_d = T_d;
+ this->y0 = y0;
+ this->R = R;
+ this->F = F;
+}
+
+float RateLimiter::out (float u) {
+ rate = (u - y0) / T_d;
+ if (rate > R) {
+ y = R * T_d + y0;
+ } else if (rate < F) {
+ y = F * T_d + y0;
+ } else {
+ y = u;
+ }
+ y0 = y;
+ return y;
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/RateLimiter.h Wed Jan 14 08:49:46 2015 +0000
@@ -0,0 +1,29 @@
+#ifndef RATE_LIMITER_H
+#define RATE_LIMITER_H
+
+#include "mbed.h"
+
+/** A rate limiter class.
+ *
+ * Author(s): TVZ Mechatronics Team
+ *
+ */
+class RateLimiter {
+ public:
+ /** Default constructor */
+ RateLimiter ();
+ /** Constructor receives rising (R) and falling (F) rate limits,
+ * initial condition of the output and sample time in seconds. */
+ RateLimiter (float R, float F, float initialCondition, float sampleTime);
+ /** Setting the rate limits R and F. */
+ void setLimits (float R, float F);
+ void setLimits (float R, float F, float initialCondition, float sampleTime);
+ /** Calculating the output of the rate limiter for the given input. */
+ float out (float input);
+ /** Reset the output of the rate limiter to zero. */
+ void reset();
+ private:
+ float R, F, y0, y, T_d, rate;
+};
+
+#endif // RATE_LIMITER_H
\ No newline at end of file