forked from M-Labs/thermostat
PwmSummary: max -> user_value
This commit is contained in:
parent
23979d25d0
commit
0d48e0df43
@ -16,6 +16,7 @@ use uom::si::{
|
|||||||
use crate::{
|
use crate::{
|
||||||
ad7172,
|
ad7172,
|
||||||
pid,
|
pid,
|
||||||
|
pwm_limits::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: ElectricPotential::new::<volt>(0.0),
|
||||||
|
max_i_pos: ElectricCurrent::new::<ampere>(0.0),
|
||||||
|
max_i_neg: ElectricCurrent::new::<ampere>(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(),
|
||||||
|
@ -139,7 +139,7 @@ impl Channels {
|
|||||||
let r_sense = ElectricalResistance::new::<ohm>(R_SENSE);
|
let r_sense = ElectricalResistance::new::<ohm>(R_SENSE);
|
||||||
let voltage = self.get_dac(channel);
|
let voltage = self.get_dac(channel);
|
||||||
let i_set = (voltage - center_point) / (10.0 * r_sense);
|
let i_set = (voltage - center_point) / (10.0 * r_sense);
|
||||||
(i_set, MAX_TEC_I)
|
(i_set, self.channel_state(channel).i_set)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// i_set DAC
|
/// i_set DAC
|
||||||
@ -393,19 +393,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, 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, 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, self.channel_state(channel).pwm_limits.max_i_neg)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get current passing through TEC
|
// Get current passing through TEC
|
||||||
@ -449,6 +449,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;
|
||||||
(duty * max, max)
|
(duty * max, max)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -456,6 +457,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;
|
||||||
(duty * max, max)
|
(duty * max, max)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -463,6 +465,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;
|
||||||
(duty * max, max)
|
(duty * max, max)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -609,12 +612,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,
|
user_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, user_value): (T, T)) -> Self {
|
||||||
PwmSummaryField { value, max }
|
PwmSummaryField { value, user_value }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user