forked from M-Labs/thermostat
PwmSummary: Show set value instead of max
Show in summary the set value, before all PWM duty calculations instead of the maximum value. Putting the maximum in PwmSummary has little use - the maximum never changes throughout the runtime of the firmware and can be replaced by documentation elsewhere.
This commit is contained in:
parent
c6040899dd
commit
aff03fa7b0
@ -16,6 +16,7 @@ use uom::si::{
|
|||||||
use crate::{
|
use crate::{
|
||||||
ad7172,
|
ad7172,
|
||||||
pid,
|
pid,
|
||||||
|
config::PwmLimits,
|
||||||
steinhart_hart as sh,
|
steinhart_hart as sh,
|
||||||
command_parser::CenterPoint,
|
command_parser::CenterPoint,
|
||||||
};
|
};
|
||||||
@ -32,6 +33,7 @@ pub struct ChannelState {
|
|||||||
pub center: CenterPoint,
|
pub center: CenterPoint,
|
||||||
pub dac_value: ElectricPotential,
|
pub dac_value: ElectricPotential,
|
||||||
pub i_set: ElectricCurrent,
|
pub i_set: ElectricCurrent,
|
||||||
|
pub pwm_limits: PwmLimits,
|
||||||
pub pid_engaged: bool,
|
pub pid_engaged: bool,
|
||||||
pub pid: pid::Controller,
|
pub pid: pid::Controller,
|
||||||
pub sh: sh::Parameters,
|
pub sh: sh::Parameters,
|
||||||
@ -48,6 +50,11 @@ impl ChannelState {
|
|||||||
center: CenterPoint::Vref,
|
center: CenterPoint::Vref,
|
||||||
dac_value: ElectricPotential::new::<volt>(0.0),
|
dac_value: ElectricPotential::new::<volt>(0.0),
|
||||||
i_set: ElectricCurrent::new::<ampere>(0.0),
|
i_set: ElectricCurrent::new::<ampere>(0.0),
|
||||||
|
pwm_limits: PwmLimits {
|
||||||
|
max_v: 0.0,
|
||||||
|
max_i_pos: 0.0,
|
||||||
|
max_i_neg: 0.0,
|
||||||
|
},
|
||||||
pid_engaged: false,
|
pid_engaged: false,
|
||||||
pid: pid::Controller::new(pid::Parameters::default()),
|
pid: pid::Controller::new(pid::Parameters::default()),
|
||||||
sh: sh::Parameters::default(),
|
sh: sh::Parameters::default(),
|
||||||
|
@ -390,19 +390,19 @@ impl Channels {
|
|||||||
pub fn get_max_v(&mut self, channel: usize) -> (ElectricPotential, ElectricPotential) {
|
pub fn get_max_v(&mut self, channel: usize) -> (ElectricPotential, ElectricPotential) {
|
||||||
let max = 4.0 * ElectricPotential::new::<volt>(3.3);
|
let max = 4.0 * ElectricPotential::new::<volt>(3.3);
|
||||||
let duty = self.get_pwm(channel, PwmPin::MaxV);
|
let duty = self.get_pwm(channel, PwmPin::MaxV);
|
||||||
(duty * max, MAX_TEC_V)
|
(duty * max, ElectricPotential::new::<volt>(self.channel_state(channel).pwm_limits.max_v))
|
||||||
}
|
}
|
||||||
|
|
||||||
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, ElectricCurrent::new::<ampere>(self.channel_state(channel).pwm_limits.max_i_pos))
|
||||||
}
|
}
|
||||||
|
|
||||||
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, ElectricCurrent::new::<ampere>(self.channel_state(channel).pwm_limits.max_i_neg))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get current passing through TEC
|
// Get current passing through TEC
|
||||||
@ -446,6 +446,7 @@ impl Channels {
|
|||||||
let max = 4.0 * ElectricPotential::new::<volt>(3.3);
|
let max = 4.0 * ElectricPotential::new::<volt>(3.3);
|
||||||
let duty = (max_v.min(MAX_TEC_V).max(ElectricPotential::zero()) / max).get::<ratio>();
|
let duty = (max_v.min(MAX_TEC_V).max(ElectricPotential::zero()) / max).get::<ratio>();
|
||||||
let duty = self.set_pwm(channel, PwmPin::MaxV, duty);
|
let duty = self.set_pwm(channel, PwmPin::MaxV, duty);
|
||||||
|
self.channel_state(channel).pwm_limits.max_v = max_v.get::<volt>();
|
||||||
(duty * max, max)
|
(duty * max, max)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -453,6 +454,7 @@ impl Channels {
|
|||||||
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_TEC_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);
|
||||||
|
self.channel_state(channel).pwm_limits.max_i_pos = max_i_pos.get::<ampere>();
|
||||||
(duty * max, max)
|
(duty * max, max)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -460,6 +462,7 @@ impl Channels {
|
|||||||
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_TEC_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);
|
||||||
|
self.channel_state(channel).pwm_limits.max_i_neg = max_i_neg.get::<ampere>();
|
||||||
(duty * max, max)
|
(duty * max, max)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -518,7 +521,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(channel), MAX_TEC_I).into(),
|
i_set: (self.get_i(channel), self.channel_state(channel).i_set).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(),
|
||||||
@ -606,12 +609,12 @@ impl Serialize for CenterPointJson {
|
|||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
pub struct PwmSummaryField<T: Serialize> {
|
pub struct PwmSummaryField<T: Serialize> {
|
||||||
value: T,
|
value: T,
|
||||||
max: T,
|
set_value: T,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Serialize> From<(T, T)> for PwmSummaryField<T> {
|
impl<T: Serialize> From<(T, T)> for PwmSummaryField<T> {
|
||||||
fn from((value, max): (T, T)) -> Self {
|
fn from((value, set_value): (T, T)) -> Self {
|
||||||
PwmSummaryField { value, max }
|
PwmSummaryField { value, set_value }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,10 +72,10 @@ impl ChannelConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||||
struct PwmLimits {
|
pub struct PwmLimits {
|
||||||
max_v: f64,
|
pub max_v: f64,
|
||||||
max_i_pos: f64,
|
pub max_i_pos: f64,
|
||||||
max_i_neg: f64,
|
pub max_i_neg: f64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PwmLimits {
|
impl PwmLimits {
|
||||||
|
Loading…
Reference in New Issue
Block a user