diff --git a/src/channel_state.rs b/src/channel_state.rs index 4b1c459..c5fa4c6 100644 --- a/src/channel_state.rs +++ b/src/channel_state.rs @@ -67,10 +67,10 @@ impl ChannelState { } /// Update PID state on ADC input, calculate new DAC output - pub fn update_pid(&mut self, current: ElectricCurrent) -> Option { + pub fn update_pid(&mut self) -> Option { let temperature = self.get_temperature()? .get::(); - let pid_output = self.pid.update(temperature, self.get_adc_interval(), current); + let pid_output = self.pid.update(temperature); Some(pid_output) } diff --git a/src/channels.rs b/src/channels.rs index 5119ae7..7aa34e9 100644 --- a/src/channels.rs +++ b/src/channels.rs @@ -75,10 +75,9 @@ impl Channels { pub fn poll_adc(&mut self, instant: Instant) -> Option { self.adc.data_ready().unwrap().map(|channel| { let data = self.adc.read_data().unwrap(); - let current = self.get_tec_i(channel.into()); let state = self.channel_state(channel); state.update(instant, data); - match state.update_pid(current) { + match state.update_pid() { Some(pid_output) if state.pid_engaged => { // Forward PID output to i_set DAC self.set_i(channel.into(), ElectricCurrent::new::(pid_output)); diff --git a/src/pid.rs b/src/pid.rs index 1b0656e..9708135 100644 --- a/src/pid.rs +++ b/src/pid.rs @@ -1,10 +1,4 @@ use serde::{Serialize, Deserialize}; -use uom::si::{ - f64::{Time, ElectricCurrent}, - time::second, - electric_current::ampere, -}; - #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub struct Parameters { @@ -62,7 +56,7 @@ impl Controller { // + x2 * kd // + kp * (u0 - u1) // y0 = clip(y0', ymin, ymax) - pub fn update(&mut self, input: f64, time_delta: Time, current: ElectricCurrent) -> f64 { + pub fn update(&mut self, input: f64) -> f64 { let mut output: f64 = self.y1 - self.target * f64::from(self.parameters.ki) + input * f64::from(self.parameters.kp + self.parameters.ki + self.parameters.kd) @@ -140,7 +134,7 @@ mod test { while !values.iter().all(|value| target.contains(value)) && total_t < CYCLE_LIMIT { let next_t = (t + 1) % DELAY; // Feed the oldest temperature - output = pid.update(values[next_t], Time::new::(1.0), ElectricCurrent::new::(output)); + output = pid.update(values[next_t]); // Overwrite oldest with previous temperature - output values[next_t] = values[t] - output - (values[t] - DEFAULT) * LOSS; t = next_t;