Compare commits

..

2 Commits

Author SHA1 Message Date
linuswck c214e4182d temp_mon: fix limits not effective at stable temp
- previously, temp is stable, temp limits are not checked
2024-08-07 12:12:07 +08:00
linuswck fb69ae3306 main: Don't change temp ctrl mode at otp 2024-08-07 11:26:47 +08:00
2 changed files with 13 additions and 6 deletions

View File

@ -160,7 +160,6 @@ fn main() -> ! {
thermostat.update_pid(); thermostat.update_pid();
if thermostat.get_temp_mon_status().over_temp_alarm { if thermostat.get_temp_mon_status().over_temp_alarm {
laser.power_down(); laser.power_down();
thermostat.set_pid_engaged(false);
thermostat.power_down(); thermostat.power_down();
} }

View File

@ -32,6 +32,7 @@ pub struct TempMon {
state: State, state: State,
count: u32, count: u32,
is_set_point_changed: bool, is_set_point_changed: bool,
is_limit_changed: bool,
} }
impl Default for TempMon { impl Default for TempMon {
@ -48,6 +49,7 @@ impl Default for TempMon {
count: 0, count: 0,
// stable_temp_count: 0, // stable_temp_count: 0,
is_set_point_changed: false, is_set_point_changed: false,
is_limit_changed: false,
} }
} }
} }
@ -68,6 +70,7 @@ impl TempMon {
pub fn set_upper_limit(&mut self, upper_limit: ThermodynamicTemperature) { pub fn set_upper_limit(&mut self, upper_limit: ThermodynamicTemperature) {
self.upper_limit = upper_limit; self.upper_limit = upper_limit;
self.is_limit_changed = true;
} }
pub fn get_upper_limit(&mut self) -> ThermodynamicTemperature { pub fn get_upper_limit(&mut self) -> ThermodynamicTemperature {
@ -76,6 +79,7 @@ impl TempMon {
pub fn set_lower_limit(&mut self, lower_limit: ThermodynamicTemperature) { pub fn set_lower_limit(&mut self, lower_limit: ThermodynamicTemperature) {
self.lower_limit = lower_limit; self.lower_limit = lower_limit;
self.is_limit_changed = true;
} }
pub fn get_lower_limit(&mut self) -> ThermodynamicTemperature { pub fn get_lower_limit(&mut self) -> ThermodynamicTemperature {
@ -129,11 +133,9 @@ impl TempMon {
} }
} }
State::PidStartUp | State::PidStable => { State::PidStartUp | State::PidStable => {
let is_over_temp: bool; let mut is_over_temp = temp > self.upper_limit || temp < self.lower_limit;
if self.state == State::PidStartUp { if self.state != State::PidStartUp {
is_over_temp = temp > self.upper_limit || temp < self.lower_limit; is_over_temp = is_over_temp || (temp.value - self.set_point.value).abs() > 0.5;
} else {
is_over_temp = (temp.value - self.set_point.value).abs() > 0.5;
} }
let is_within_spec: bool = (temp.value - self.set_point.value).abs() < 0.001; let is_within_spec: bool = (temp.value - self.set_point.value).abs() < 0.001;
@ -163,6 +165,12 @@ impl TempMon {
} else if self.is_set_point_changed { } else if self.is_set_point_changed {
self.is_set_point_changed = false; self.is_set_point_changed = false;
self.state = State::PidStartUp; self.state = State::PidStartUp;
} else if self.is_limit_changed {
self.is_limit_changed = false;
if is_over_temp {
self.state = State::PidStartUp;
self.count = 0;
}
} else if self.status.status == TempStatusEnum::Stable { } else if self.status.status == TempStatusEnum::Stable {
self.state = State::PidStable; self.state = State::PidStable;
} else if !pid_engaged { } else if !pid_engaged {