Compare commits

..

No commits in common. "a76b8de994f9f3aeef64e252af6483a16770e4f1" and "b95b9dcefae9b61efedbe21d5b01e462deeb65a7" have entirely different histories.

View File

@ -213,14 +213,13 @@ impl Thermostat {
} }
pub fn power_up(&mut self) { pub fn power_up(&mut self) {
if !self.max1968.is_powered_on() {
self.max1968.power_up(); self.max1968.power_up();
self.pid_ctrl_ch0.reset_pid_state();
}
} }
pub fn power_down(&mut self) { pub fn power_down(&mut self) {
self.max1968.power_down(); self.max1968.power_down();
self.pid_ctrl_ch0.reset_pid_state();
self.set_i(ElectricCurrent::new::<ampere>(0.0));
} }
fn set_center_pt(&mut self, value: ElectricPotential) { fn set_center_pt(&mut self, value: ElectricPotential) {
@ -233,39 +232,36 @@ impl Thermostat {
pub fn set_i(&mut self, i_tec: ElectricCurrent) -> ElectricCurrent { pub fn set_i(&mut self, i_tec: ElectricCurrent) -> ElectricCurrent {
let voltage = i_tec * 10.0 * R_SENSE + self.tec_settings.center_pt; let voltage = i_tec * 10.0 * R_SENSE + self.tec_settings.center_pt;
let _voltage = self.max1968.set_dac(voltage, self.max1968.dac_out_range); let voltage = self.max1968.set_dac(voltage, self.max1968.dac_out_range);
self.tec_settings.i_set = i_tec; self.tec_settings.i_set = (voltage - self.tec_settings.center_pt) / (10.0 * R_SENSE);
self.tec_settings.i_set self.tec_settings.i_set
} }
pub fn set_max_v(&mut self, max_v: ElectricPotential) -> ElectricPotential { pub fn set_max_v(&mut self, max_v: ElectricPotential) -> ElectricPotential {
let duty = (max_v / TecSettings::MAX_V_DUTY_TO_VOLTAGE_RATE).get::<ratio>(); let duty = (max_v / TecSettings::MAX_V_DUTY_TO_VOLTAGE_RATE).get::<ratio>();
let _duty = self let duty = self
.max1968 .max1968
.set_pwm(PwmPinsEnum::MaxV, duty as f64, TecSettings::MAX_V_DUTY_MAX); .set_pwm(PwmPinsEnum::MaxV, duty as f64, TecSettings::MAX_V_DUTY_MAX);
self.tec_settings.max_v_set = duty as f32 * TecSettings::MAX_V_DUTY_TO_VOLTAGE_RATE;
self.tec_settings.max_v_set = max_v;
self.tec_settings.max_v_set self.tec_settings.max_v_set
} }
pub fn set_max_i_pos(&mut self, max_i_pos: ElectricCurrent) -> ElectricCurrent { pub fn set_max_i_pos(&mut self, max_i_pos: ElectricCurrent) -> ElectricCurrent {
let duty = (max_i_pos / TecSettings::MAX_I_POS_NEG_DUTY_TO_CURRENT_RATE).get::<ratio>(); let duty = (max_i_pos / TecSettings::MAX_I_POS_NEG_DUTY_TO_CURRENT_RATE).get::<ratio>();
let _duty = self let duty = self
.max1968 .max1968
.set_pwm(PwmPinsEnum::MaxPosI, duty as f64, TecSettings::MAX_I_POS_DUTY_MAX); .set_pwm(PwmPinsEnum::MaxPosI, duty as f64, TecSettings::MAX_I_POS_DUTY_MAX);
self.tec_settings.max_i_pos_set = duty as f32 * TecSettings::MAX_I_POS_NEG_DUTY_TO_CURRENT_RATE;
self.tec_settings.max_i_pos_set = max_i_pos;
self.tec_settings.max_i_pos_set self.tec_settings.max_i_pos_set
} }
pub fn set_max_i_neg(&mut self, max_i_neg: ElectricCurrent) -> ElectricCurrent { pub fn set_max_i_neg(&mut self, max_i_neg: ElectricCurrent) -> ElectricCurrent {
let duty = (max_i_neg / TecSettings::MAX_I_POS_NEG_DUTY_TO_CURRENT_RATE).get::<ratio>(); let duty = (max_i_neg / TecSettings::MAX_I_POS_NEG_DUTY_TO_CURRENT_RATE).get::<ratio>();
let _duty = self let duty = self
.max1968 .max1968
.set_pwm(PwmPinsEnum::MaxNegI, duty as f64, TecSettings::MAX_I_NEG_DUTY_MAX); .set_pwm(PwmPinsEnum::MaxNegI, duty as f64, TecSettings::MAX_I_NEG_DUTY_MAX);
self.tec_settings.max_i_neg_set = duty as f32 * TecSettings::MAX_I_POS_NEG_DUTY_TO_CURRENT_RATE;
self.tec_settings.max_i_neg_set = max_i_neg;
self.tec_settings.max_i_neg_set self.tec_settings.max_i_neg_set
} }