ionpak-thermostat/firmware/src/loop_anode.rs

40 lines
785 B
Rust
Raw Normal View History

2017-05-09 15:57:54 +08:00
use board;
use pid;
const PID_PARAMETERS: pid::Parameters = pid::Parameters {
kp: 0.004,
ki: 0.002,
kd: 0.0,
output_min: 0.0,
output_max: 30.0,
integral_min: -5000.0,
integral_max: 5000.0
};
pub struct Controller {
pid: pid::Controller
}
impl Controller {
pub const fn new() -> Controller {
Controller {
pid: pid::Controller::new(PID_PARAMETERS)
}
}
pub fn adc_input(&mut self, av_sample: u16) {
let pid_out = self.pid.update(av_sample as f32);
board::set_hv_pwm(pid_out as u16)
}
pub fn set_target(&mut self, volts: f32) {
self.pid.set_target(volts*board::AV_ADC_GAIN)
}
pub fn ready(&mut self) -> bool {
self.pid.is_within(1.0*board::AV_ADC_GAIN)
}
}