Anti-Sway Capstone 1.0
Loading...
Searching...
No Matches
discrete-lib.c File Reference

Discrete Control Law Implementation Library. More...

#include <stdlib.h>
#include "discrete-lib.h"
Include dependency graph for discrete-lib.c:

Macros

#define SATURATE(val, lo, hi)   val < lo ? lo : (val > hi ? hi : val)
 Saturates a value.
 

Functions

static double EvaluateBiquad (Biquad *sys, double input)
 
void IntegratorInit (Proportional gain, double timestep, Integrator *result)
 
void DifferentiatorInit (Proportional gain, double timestep, Differentiator *result)
 
double Cascade (double input, Biquad sys[], int size, double lower_lim, double upper_lim)
 
double Integrate (double input, Integrator *term, double lower_lim, double upper_lim)
 
double Differentiate (double input, Differentiator *term, double lower_lim, double upper_lim)
 
double PID (double input, Proportional *p, Integrator *i, Differentiator *d, double lower_lim, double upper_lim)
 

Detailed Description

Discrete Control Law Implementation Library.

Author
Anti-Sway Team: Nguyen, Tri; Espinola, Malachi; Tevy, Vattanary; Hokenstad, Ethan; Neff, Callen)
Version
0.1
Date
2024-06-03

Macro Definition Documentation

◆ SATURATE

#define SATURATE ( val,
lo,
hi )   val < lo ? lo : (val > hi ? hi : val)

Saturates a value.

Saturates a value to be between some low and high value

Parameters
valThe numerical value to saturate
loThe numerical lower limit
hiThe numerical upper limit

Evaluates to val iff lo <= val <= hi, lo iff val < lo and hi iff val > hi

Function Documentation

◆ Cascade()

double Cascade ( double input,
Biquad sys[],
int size,
double lower_lim,
double upper_lim )
inline

Executes a dynamic, discrete time system by using its biquad decomposition.

Parameters
inputThe input to the system
sysThe system, as an array of biquads
sizeThe size of sys
lower_limThe lower saturation limit of the system
upper_limThe upper saturation limit of the system
Returns
The output of the system given the input
Precondition
The input is the next sampled value of the input to the system
Postcondition
The system is updated with current/past calculated values
Here is the call graph for this function:

◆ Differentiate()

double Differentiate ( double input,
Differentiator * term,
double lower_lim,
double upper_lim )
inline

Timesteps a Differentiation

Parameters
inputThe input to the differentiator
termA pointer to an differentiator term
lower_limThe lower saturation limit of the system
upper_limThe upper saturation limit of the system
Returns
The output of the differentiator given the input
Precondition
The input is the next sampled value of the input to the system
Postcondition
term is updated with current/past calculated values

◆ DifferentiatorInit()

void DifferentiatorInit ( Proportional gain,
double timestep,
Differentiator * result )

Initializes a Differentiator

Parameters
gainThe gain to assign the differentiator
timestepThe timestep to approximate the differentiator
resultA return parameter, which becomes the differentiator with the gain and timestep
Returns
result, which will be an differentiator with a gain gain, and the timestep

◆ EvaluateBiquad()

static double EvaluateBiquad ( Biquad * sys,
double input )
inlinestatic

Evaluates a singular dynamic distrete time biquad within a system, which itself is a system.

Parameters
sysThe system
inputThe system's input
Returns
The output of the system
Precondition
The input is the next sampled value of the input to the system
Postcondition
The system is updated with current/past calculated values

◆ Integrate()

double Integrate ( double input,
Integrator * term,
double lower_lim,
double upper_lim )
inline

Timesteps an Integration

Parameters
inputThe input to the integrator
termA pointer to an integrator term
lower_limThe lower saturation limit of the system
upper_limThe upper saturation limit of the system
Returns
The output of the integrator given the input
Precondition
The input is the next sampled value of the input to the system
Postcondition
term is updated with current/past calculated values

◆ IntegratorInit()

void IntegratorInit ( Proportional gain,
double timestep,
Integrator * result )

Initializes an Integrator

Parameters
gainThe gain to assign the integrator
timestepThe timestep to approximate the integrator
resultA return parameter, which becomes the integrator with the gain and timestep
Returns
result, which will be an integrator with a gain gain, and the timestep

◆ PID()

double PID ( double input,
Proportional * p,
Integrator * i,
Differentiator * d,
double lower_lim,
double upper_lim )
inline

Timesteps a PID Controller

Parameters
inputThe input to the PID Controller
pA pointer to the proportional term
iA pointer to the integrator term
dA pointer to the differentiator term
lower_limThe lower saturation limit of the system
upper_limThe upper saturation limit of the system
Returns
The output of the PID Controller given the input
Precondition
The input is the next sampled value of the input to all non-NULL Control Blocks
If p, i or d is NULL, then those NULL terms don't contribute
if p, i and d are all NULL, then the output is 0.0
Postcondition
i and d are updated with current/past calculated values
Here is the call graph for this function: