@@ -32,7 +32,7 @@ pub struct OutputChannel {
32
32
///
33
33
/// # Value
34
34
/// See [iir::IIR#tree]
35
- pub iir : iir:: IIR < f64 > ,
35
+ pub iir : iir:: Biquad < f64 > ,
36
36
37
37
/// Thermostat input channel weights. Each input temperature of an enabled channel
38
38
/// is multiplied by its weight and the accumulated output is fed into the IIR.
@@ -55,27 +55,18 @@ impl Default for OutputChannel {
55
55
shutdown : true ,
56
56
hold : false ,
57
57
voltage_limit : 0.0 ,
58
- iir : iir:: IIR :: default ( ) ,
58
+ iir : iir:: Biquad :: default ( ) ,
59
59
weights : [ [ None ; 4 ] ; 4 ] ,
60
60
}
61
61
}
62
62
}
63
63
64
- // Global "hold" IIR to apply to a channel iir state [x0,x1,x2,y0,y1] when the output should hold.
65
- const IIR_HOLD : iir:: IIR < f64 > = iir:: IIR {
66
- ba : [ 0. , 0. , 0. , 1. , 0. ] ,
67
- y_offset : 0. ,
68
- y_min : f64:: MIN ,
69
- y_max : f64:: MAX ,
70
- } ;
71
-
72
64
impl OutputChannel {
73
65
/// compute weighted iir input, iir state and return the new output
74
66
pub fn update (
75
67
& mut self ,
76
68
channel_temperatures : & [ [ f64 ; 4 ] ; 4 ] ,
77
- iir_state : & mut iir:: Vec5 < f64 > ,
78
- hold : bool ,
69
+ iir_state : & mut [ f64 ; 4 ] ,
79
70
) -> f32 {
80
71
let weighted_temperature = channel_temperatures
81
72
. iter ( )
@@ -85,9 +76,9 @@ impl OutputChannel {
85
76
. map ( |( t, w) | t * w. unwrap_or ( 0. ) as f64 )
86
77
. sum ( ) ;
87
78
if self . shutdown || self . hold {
88
- IIR_HOLD . update ( iir_state, weighted_temperature, hold ) as f32
79
+ iir :: Biquad :: HOLD . update ( iir_state, weighted_temperature) as f32
89
80
} else {
90
- self . iir . update ( iir_state, weighted_temperature, hold ) as f32
81
+ self . iir . update ( iir_state, weighted_temperature) as f32
91
82
}
92
83
}
93
84
@@ -96,14 +87,16 @@ impl OutputChannel {
96
87
/// - Normalization of the weights
97
88
/// Returns the current limits.
98
89
pub fn finalize_settings ( & mut self ) -> [ f32 ; 2 ] {
99
- self . iir . y_max = self
100
- . iir
101
- . y_max
102
- . clamp ( -Pwm :: MAX_CURRENT_LIMIT , Pwm :: MAX_CURRENT_LIMIT ) ;
103
- self . iir . y_min = self
104
- . iir
105
- . y_min
106
- . clamp ( -Pwm :: MAX_CURRENT_LIMIT , Pwm :: MAX_CURRENT_LIMIT ) ;
90
+ self . iir . set_max (
91
+ self . iir
92
+ . max ( )
93
+ . clamp ( -Pwm :: MAX_CURRENT_LIMIT , Pwm :: MAX_CURRENT_LIMIT ) ,
94
+ ) ;
95
+ self . iir . set_min (
96
+ self . iir
97
+ . min ( )
98
+ . clamp ( -Pwm :: MAX_CURRENT_LIMIT , Pwm :: MAX_CURRENT_LIMIT ) ,
99
+ ) ;
107
100
self . voltage_limit = self . voltage_limit . clamp ( 0.0 , Pwm :: MAX_VOLTAGE_LIMIT ) ;
108
101
let divisor: f32 = self
109
102
. weights
@@ -121,8 +114,8 @@ impl OutputChannel {
121
114
[
122
115
// [Pwm::MAX_CURRENT_LIMIT] + 5% is still below 100% duty cycle for the PWM limits and therefore OK.
123
116
// Might not be OK for a different shunt resistor or different PWM setup.
124
- ( self . iir . y_max + 0.05 * Pwm :: MAX_CURRENT_LIMIT ) . max ( 0. ) as f32 ,
125
- ( self . iir . y_min - 0.05 * Pwm :: MAX_CURRENT_LIMIT ) . min ( 0. ) as f32 ,
117
+ ( self . iir . max ( ) + 0.05 * Pwm :: MAX_CURRENT_LIMIT ) . max ( 0. ) as f32 ,
118
+ ( self . iir . min ( ) - 0.05 * Pwm :: MAX_CURRENT_LIMIT ) . min ( 0. ) as f32 ,
126
119
]
127
120
}
128
121
}
0 commit comments