82 #define RC_FILTER_INITIALIZER {\    86         .num            = RC_VECTOR_INITIALIZER,\    87         .den            = RC_VECTOR_INITIALIZER,\    94         .in_buf         = RC_RINGBUF_INITIALIZER,\    95         .out_buf        = RC_RINGBUF_INITIALIZER,\    97         .newest_output  = 0.0,\   158                                                         double* 
den,
int denlen);
   556 #endif // RC_FILTER_H int rc_filter_pid(rc_filter_t *f, double kp, double ki, double kd, double Tf, double dt)
Creates a discrete-time implementation of a parallel PID controller with high-frequency rolloff using...
 
int rc_filter_first_order_lowpass(rc_filter_t *f, double dt, double tc)
Creates a first order low pass filter. 
 
rc_vector_t den
denominator coefficients 
Definition: filter.h:50
 
int rc_filter_multiply_three(rc_filter_t f1, rc_filter_t f2, rc_filter_t f3, rc_filter_t *out)
Creates a new filter 'out' by multiplying f1*f2*f3. 
 
int rc_filter_alloc_from_arrays(rc_filter_t *f, double dt, double *num, int numlen, double *den, int denlen)
Like rc_filter_alloc(), but takes arrays for the numerator and denominator coefficients instead of ve...
 
int sat_flag
1 if saturated on the last step 
Definition: filter.h:58
 
int ss_en
set to 1 by enbale_soft_start() 
Definition: filter.h:63
 
double rc_filter_march(rc_filter_t *f, double new_input)
March a filter forward one step with new input provided as an argument. 
 
int rc_filter_enable_saturation(rc_filter_t *f, double min, double max)
Enables saturation between bounds min and max. 
 
double gain
Additional gain multiplier, usually 1.0. 
Definition: filter.h:48
 
int rc_filter_multiply(rc_filter_t f1, rc_filter_t f2, rc_filter_t *out)
Creates a new filter 'out' by multiplying f1*f2. 
 
int rc_filter_moving_average(rc_filter_t *f, int samples, double dt)
Makes a FIR moving average filter that averages over specified number of samples. ...
 
int rc_filter_prefill_outputs(rc_filter_t *f, double out)
Fills all previous outputs of the filter as if they had been equal to 'out'. 
 
int rc_filter_duplicate(rc_filter_t *f, rc_filter_t old)
duplicates a filter 
 
int rc_filter_integrator(rc_filter_t *f, double dt)
Creates a first order integrator. 
 
double sat_max
upper saturation limit 
Definition: filter.h:57
 
int rc_filter_third_order_complement(rc_filter_t *lp, rc_filter_t *hp, double freq, double damp, double dt)
Creates a third order symmetric complementary pair of high/low pass filters. 
 
double ss_steps
steps before full output allowed 
Definition: filter.h:64
 
int initialized
initialization flag 
Definition: filter.h:78
 
Struct containing the state of a vector and a pointer to dynamically allocated memory to hold its con...
Definition: vector.h:41
 
rc_ringbuf_t in_buf
Definition: filter.h:69
 
Struct containing configuration and state of a SISO filter. 
Definition: filter.h:43
 
int sat_en
set to 1 by enable_saturation() 
Definition: filter.h:55
 
int rc_filter_c2d_tustin(rc_filter_t *f, double dt, rc_vector_t num, rc_vector_t den, double w)
Creates a discrete time filter with similar dynamics to a provided continuous time transfer function ...
 
uint64_t step
steps since last reset 
Definition: filter.h:77
 
Struct containing state of a ringbuffer and pointer to dynamically allocated memory. 
Definition: ring_buffer.h:34
 
int rc_filter_double_integrator(rc_filter_t *f, double dt)
Creates a second order double integrator. 
 
int rc_filter_reset(rc_filter_t *f)
Resets all previous inputs and outputs to 0. Also resets the step counter & saturation flag...
 
struct rc_filter_t rc_filter_t
Struct containing configuration and state of a SISO filter. 
 
int rc_filter_normalize(rc_filter_t *f)
Normalizes a discrete time filter so that the leading demoninator coefficient is 1. 
 
int rc_filter_print(rc_filter_t f)
Prints the transfer function and other statistic of a filter to the screen. 
 
int rc_filter_prefill_inputs(rc_filter_t *f, double in)
Fills all previous inputs to the filter as if they had been equal to 'in'. 
 
rc_filter_t rc_filter_empty(void)
Critical function for initializing rc_filter_t structs. 
 
#define min(a, b)
Definition: rc_usefulincludes.h:73
 
double rc_filter_previous_output(rc_filter_t *f, int steps)
Returns the output 'steps' back in time. Steps = 0 returns most recent output. 
 
int rc_filter_alloc(rc_filter_t *f, rc_vector_t num, rc_vector_t den, double dt)
Allocate memory for a discrete-time filter & populates it with the transfer function coefficients pro...
 
double sat_min
lower saturation limit 
Definition: filter.h:56
 
int rc_filter_free(rc_filter_t *f)
Frees the memory allocated by a filter's buffers and coefficient vectors. Also resets all filter prop...
 
int order
transfer function order 
Definition: filter.h:46
 
int rc_filter_enable_soft_start(rc_filter_t *f, double seconds)
Enables soft start functionality where the output bound is gradually opened linearly from 0 to the no...
 
int rc_filter_first_order_highpass(rc_filter_t *f, double dt, double tc)
Creates a first order high pass filter. 
 
double dt
timestep in seconds 
Definition: filter.h:47
 
rc_vector_t num
numerator coefficients 
Definition: filter.h:49
 
int rc_filter_butterworth_highpass(rc_filter_t *f, int order, double dt, double wc)
Creates a Butterworth high pass filter of specified order and cutoff frequency. 
 
int rc_filter_butterworth_lowpass(rc_filter_t *f, int order, double dt, double wc)
Creates a Butterworth low pass filter of specified order and cutoff frequency. 
 
double newest_input
shortcut for the most recent input 
Definition: filter.h:75
 
int rc_filter_get_saturation_flag(rc_filter_t *f)
Checks if the filter saturated the last time step. 
 
rc_ringbuf_t out_buf
Definition: filter.h:70
 
double newest_output
shortcut for the most recent output 
Definition: filter.h:76
 
double rc_filter_previous_input(rc_filter_t *f, int steps)
Returns the input 'steps' back in time. Steps=0 returns most recent input.