Skip to content

Commit

Permalink
just use 0 weight, no need for option
Browse files Browse the repository at this point in the history
  • Loading branch information
jordens committed Feb 2, 2024
1 parent 6f89dea commit d0b4f8c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
5 changes: 3 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,11 @@ mod app {
if thermostat.adc_channels[phy_i][ch_i] {
telemetry.alarm[phy_i][ch_i] = Some(false);
telemetry.statistics[phy_i][ch_i] = Some(Default::default());
settings.alarm.temperature_limits[phy_i][ch_i] = Some([f32::MIN, f32::MAX]);
settings.alarm.temperature_limits[phy_i][ch_i] =
Some([f32::NEG_INFINITY, f32::INFINITY]);
// Initialize the output weights.
for ch in settings.output_channel.iter_mut() {
ch.weights[phy_i][ch_i] = Some(0.);
ch.weights[phy_i][ch_i] = 0.;
}
}
}
Expand Down
16 changes: 7 additions & 9 deletions src/output_channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub struct OutputChannel {
/// # Value
/// f32
#[tree(depth(2))]
pub weights: [[Option<f32>; 4]; 4],
pub weights: [[f32; 4]; 4],
}

impl Default for OutputChannel {
Expand All @@ -56,7 +56,7 @@ impl Default for OutputChannel {
hold: false,
voltage_limit: 0.0,
iir: iir::Biquad::default(),
weights: [[None; 4]; 4],
weights: [[0.0; 4]; 4],
}
}
}
Expand All @@ -73,7 +73,7 @@ impl OutputChannel {
.flatten()
.zip(self.weights.iter().flatten())
// weight is `None` if temperature is invalid (phy cfg absent)
.map(|(t, w)| t * w.unwrap_or(0.) as f64)
.map(|(t, w)| t * *w as f64)
.sum();
if self.shutdown || self.hold {
iir::Biquad::HOLD.update(iir_state, weighted_temperature) as f32
Expand Down Expand Up @@ -101,15 +101,13 @@ impl OutputChannel {
let divisor: f32 = self
.weights
.iter()
.map(|w| w.iter().map(|w| w.unwrap_or(0.).abs()).sum::<f32>())
.map(|w| w.iter().map(|w| w.abs()).sum::<f32>())
.sum();
// Note: The weights which are not 'None' should always affect an enabled channel and therefore count for normalization.
if divisor != 0.0 {
self.weights.iter_mut().flatten().for_each(|w| {
if let Some(w) = w {
*w /= divisor
}
});
for w in self.weights.iter_mut().flatten() {
*w /= divisor;
}
}
[
// [Pwm::MAX_CURRENT_LIMIT] + 5% is still below 100% duty cycle for the PWM limits and therefore OK.
Expand Down

0 comments on commit d0b4f8c

Please sign in to comment.