MAX_TEC_I -> MAX_I

This commit is contained in:
atse 2024-08-06 12:54:13 +08:00
parent cee633845e
commit 7e6013b07b
3 changed files with 10 additions and 10 deletions

View File

@ -281,6 +281,6 @@ Fan control commands are available for thermostat revisions with an integrated f
2. `fan auto` - enable auto speed controller mode, where fan speed is controlled by the fan curve `fcurve`. 2. `fan auto` - enable auto speed controller mode, where fan speed is controlled by the fan curve `fcurve`.
3. `fan <value>` - set the fan power with the value from `1` to `100` and disable auto mode. There is no way to completely disable the fan. 3. `fan <value>` - set the fan power with the value from `1` to `100` and disable auto mode. There is no way to completely disable the fan.
Please note that power doesn't correlate with the actual speed linearly. Please note that power doesn't correlate with the actual speed linearly.
4. `fcurve <a> <b> <c>` - set coefficients of the controlling curve `a*x^2 + b*x + c`, where `x` is `max_abs_i_measured/MAX_TEC_I`, a normalized value in range [0,1], 4. `fcurve <a> <b> <c>` - set coefficients of the controlling curve `a*x^2 + b*x + c`, where `x` is `max_abs_i_measured/MAX_I`, a normalized value in range [0,1],
i.e. the (linear) proportion of current output capacity used, on the channel with the largest current flow. The controlling curve is also clamped to [0,1]. i.e. the (linear) proportion of current output capacity used, on the channel with the largest current flow. The controlling curve is also clamped to [0,1].
5. `fcurve default` - restore fan curve coefficients to defaults: `a = 1.0, b = 0.0, c = 0.0`. 5. `fcurve default` - restore fan curve coefficients to defaults: `a = 1.0, b = 0.0, c = 0.0`.

View File

@ -33,7 +33,7 @@ pub const CHANNELS: usize = 2;
const R_SENSE: f64 = 0.05; const R_SENSE: f64 = 0.05;
// From design specs // From design specs
pub const MAX_TEC_I: ElectricCurrent = ElectricCurrent { pub const MAX_I: ElectricCurrent = ElectricCurrent {
dimension: PhantomData, dimension: PhantomData,
units: PhantomData, units: PhantomData,
value: 2.0, value: 2.0,
@ -157,7 +157,7 @@ impl Channels {
} }
pub fn set_i(&mut self, channel: usize, i_set: ElectricCurrent) -> ElectricCurrent { pub fn set_i(&mut self, channel: usize, i_set: ElectricCurrent) -> ElectricCurrent {
let i_set = i_set.min(MAX_TEC_I).max(-MAX_TEC_I); let i_set = i_set.min(MAX_I).max(-MAX_I);
let vref_meas = match channel { let vref_meas = match channel {
0 => self.channel0.vref_meas, 0 => self.channel0.vref_meas,
1 => self.channel1.vref_meas, 1 => self.channel1.vref_meas,
@ -399,13 +399,13 @@ impl Channels {
pub fn get_max_i_pos(&mut self, channel: usize) -> (ElectricCurrent, ElectricCurrent) { pub fn get_max_i_pos(&mut self, channel: usize) -> (ElectricCurrent, ElectricCurrent) {
let max = ElectricCurrent::new::<ampere>(3.0); let max = ElectricCurrent::new::<ampere>(3.0);
let duty = self.get_pwm(channel, PwmPin::MaxIPos); let duty = self.get_pwm(channel, PwmPin::MaxIPos);
(duty * max, MAX_TEC_I) (duty * max, MAX_I)
} }
pub fn get_max_i_neg(&mut self, channel: usize) -> (ElectricCurrent, ElectricCurrent) { pub fn get_max_i_neg(&mut self, channel: usize) -> (ElectricCurrent, ElectricCurrent) {
let max = ElectricCurrent::new::<ampere>(3.0); let max = ElectricCurrent::new::<ampere>(3.0);
let duty = self.get_pwm(channel, PwmPin::MaxINeg); let duty = self.get_pwm(channel, PwmPin::MaxINeg);
(duty * max, MAX_TEC_I) (duty * max, MAX_I)
} }
// Measure current passing through TEC // Measure current passing through TEC
@ -457,7 +457,7 @@ impl Channels {
max_i_pos: ElectricCurrent, max_i_pos: ElectricCurrent,
) -> (ElectricCurrent, ElectricCurrent) { ) -> (ElectricCurrent, ElectricCurrent) {
let max = ElectricCurrent::new::<ampere>(3.0); let max = ElectricCurrent::new::<ampere>(3.0);
let duty = (max_i_pos.min(MAX_TEC_I).max(ElectricCurrent::zero()) / max).get::<ratio>(); let duty = (max_i_pos.min(MAX_I).max(ElectricCurrent::zero()) / max).get::<ratio>();
let duty = self.set_pwm(channel, PwmPin::MaxIPos, duty); let duty = self.set_pwm(channel, PwmPin::MaxIPos, duty);
(duty * max, max) (duty * max, max)
} }
@ -468,7 +468,7 @@ impl Channels {
max_i_neg: ElectricCurrent, max_i_neg: ElectricCurrent,
) -> (ElectricCurrent, ElectricCurrent) { ) -> (ElectricCurrent, ElectricCurrent) {
let max = ElectricCurrent::new::<ampere>(3.0); let max = ElectricCurrent::new::<ampere>(3.0);
let duty = (max_i_neg.min(MAX_TEC_I).max(ElectricCurrent::zero()) / max).get::<ratio>(); let duty = (max_i_neg.min(MAX_I).max(ElectricCurrent::zero()) / max).get::<ratio>();
let duty = self.set_pwm(channel, PwmPin::MaxINeg, duty); let duty = self.set_pwm(channel, PwmPin::MaxINeg, duty);
(duty * max, max) (duty * max, max)
} }
@ -524,7 +524,7 @@ impl Channels {
PwmSummary { PwmSummary {
channel, channel,
center: CenterPointJson(self.channel_state(channel).center.clone()), center: CenterPointJson(self.channel_state(channel).center.clone()),
i_set: (self.get_i_set(channel), MAX_TEC_I).into(), i_set: (self.get_i_set(channel), MAX_I).into(),
max_v: self.get_max_v(channel).into(), max_v: self.get_max_v(channel).into(),
max_i_pos: self.get_max_i_pos(channel).into(), max_i_pos: self.get_max_i_pos(channel).into(),
max_i_neg: self.get_max_i_neg(channel).into(), max_i_neg: self.get_max_i_neg(channel).into(),

View File

@ -1,4 +1,4 @@
use crate::{channels::MAX_TEC_I, command_handler::JsonBuffer, hw_rev::HWSettings}; use crate::{channels::MAX_I, command_handler::JsonBuffer, hw_rev::HWSettings};
use num_traits::Float; use num_traits::Float;
use serde::Serialize; use serde::Serialize;
use stm32f4xx_hal::{ use stm32f4xx_hal::{
@ -46,7 +46,7 @@ impl FanCtrl {
pub fn cycle(&mut self, max_abs_i_measured: ElectricCurrent) { pub fn cycle(&mut self, max_abs_i_measured: ElectricCurrent) {
self.max_abs_i_measured = max_abs_i_measured.get::<ampere>() as f32; self.max_abs_i_measured = max_abs_i_measured.get::<ampere>() as f32;
if self.fan_auto && self.hw_settings.fan_available { if self.fan_auto && self.hw_settings.fan_available {
let scaled_current = self.max_abs_i_measured / MAX_TEC_I.get::<ampere>() as f32; let scaled_current = self.max_abs_i_measured / MAX_I.get::<ampere>() as f32;
// do not limit upper bound, as it will be limited in the set_pwm() // do not limit upper bound, as it will be limited in the set_pwm()
let pwm = (MAX_USER_FAN_PWM let pwm = (MAX_USER_FAN_PWM
* (scaled_current * (scaled_current * self.k_a + self.k_b) + self.k_c)) * (scaled_current * (scaled_current * self.k_a + self.k_b) + self.k_c))