summaryrefslogtreecommitdiff
path: root/src/hal/components/deadzone.comp
blob: 45099fc2fd319e557dfa5a0e80094811d1a25ff3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
component deadzone "Return the center if within the threshold";
param rw float center = 0.0 "The center of the dead zone";
param rw float threshhold = 1.0 "The dead zone is \\fBcenter\\fR \\(+- (\\fBthreshhold\\fR/2)";
pin in float in;
pin out float out;

function _ "Update \\fBout\\fR based on \\fBin\\fR and the parameters.";

license "GPL";
;;
FUNCTION(_) {
    double th2 = threshhold / 2;
    double lo = center - th2;
    double hi = center + th2;
    double in_ = in;
    
    if(in_ < lo) out = in_ + th2;
    else if(in_ > hi) out = in_ - th2;
    else out = center;
}