Bioscara
DALSA's DIY SCARA Robot Arm.
Loading...
Searching...
No Matches
filters.h
Go to the documentation of this file.
1
13#include <stdlib.h>
14
16
21class Lowpass {
22
23protected:
24 float K;
25 float Ts;
26 float tau;
27 float x;
28
29public:
30
38 Lowpass(float gain = 1, float sampleTime = 0.1, float timeconstant = 1.0) {
39 this->K = gain;
40 this->Ts = sampleTime;
41 this->tau = timeconstant;
42 x = 0.0;
43 }
44
49 float updateState(float u) {
50 x = (1 - (Ts / tau)) * x + K * (Ts / tau) * u;
51 return x;
52 }
53
58 void resetState(void) {
59 x = 0.0;
60 }
61};
62
68class MovMax {
69
70protected:
71 unsigned int M = 200;
72
73 float *cb_data;
74 unsigned int cb_index;
75
76
77public:
85 MovMax(float windowSize)
86 : M(windowSize), cb_index(0), cb_data(0) {
87
88 cb_data = (float *)malloc(windowSize * sizeof(float)); // allocate memory for buffer
89 }
90
95 float updateState(float u) {
96
97 cb_data[cb_index] = u;
98 cb_index = (cb_index + 1) % M;
99
100
101 float max = 0;
102 for (size_t i = 0; i < M; i++) {
103 if (cb_data[i] > max) {
104 max = cb_data[i];
105 }
106 }
107
108 return max;
109 }
110};
111}
Simple discrete IIR lowpass filter.
Definition filters.h:21
float updateState(float u)
Update the filter state. Must be called with the constant period Ts.
Definition filters.h:49
Lowpass(float gain=1, float sampleTime=0.1, float timeconstant=1.0)
Constucts and initializes the Lowpass filter.
Definition filters.h:38
void resetState(void)
Resets the filter state x to 0.0.
Definition filters.h:58
float tau
Filter timeconstant.
Definition filters.h:26
float K
Filter gain.
Definition filters.h:24
float x
Filter state.
Definition filters.h:27
float Ts
Filter sampling time.
Definition filters.h:25
Simple FIR moving maximum filter.
Definition filters.h:68
float * cb_data
Pointer to ring buffer holding the data.
Definition filters.h:73
unsigned int cb_index
Current ringbuffer index.
Definition filters.h:74
unsigned int M
Window Size.
Definition filters.h:71
MovMax(float windowSize)
Constucts and initializes the MovMax filter.
Definition filters.h:85
float updateState(float u)
Update and return the filter state.
Definition filters.h:95
Joint firmware.
Definition filters.h:15