forked from M-Labs/ionpak-thermostat
use PID for FV, print all debug messages
This commit is contained in:
parent
df335865b7
commit
ad447cd5f9
|
@ -50,7 +50,7 @@ impl Electrometer {
|
||||||
impl ElectrometerStatus {
|
impl ElectrometerStatus {
|
||||||
pub fn debug_print(&self) {
|
pub fn debug_print(&self) {
|
||||||
if self.ic.is_some() {
|
if self.ic.is_some() {
|
||||||
println!("ion current: {}nA", 1e9*self.ic.unwrap());
|
println!("ion: {}nA", 1e9*self.ic.unwrap());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,12 +5,12 @@ use pid;
|
||||||
|
|
||||||
const PID_PARAMETERS: pid::Parameters = pid::Parameters {
|
const PID_PARAMETERS: pid::Parameters = pid::Parameters {
|
||||||
kp: 0.027,
|
kp: 0.027,
|
||||||
ki: 0.013,
|
ki: 0.014,
|
||||||
kd: 0.0,
|
kd: 0.0,
|
||||||
output_min: 0.0,
|
output_min: 0.0,
|
||||||
output_max: 30.0,
|
output_max: 30.0,
|
||||||
integral_min: -5000.0,
|
integral_min: -700.0,
|
||||||
integral_max: 5000.0
|
integral_max: 700.0
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@ pub struct Controller {
|
||||||
last_av: Option<f32>
|
last_av: Option<f32>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy)]
|
||||||
pub struct ControllerStatus {
|
pub struct ControllerStatus {
|
||||||
pub ready: bool,
|
pub ready: bool,
|
||||||
pub av: Option<f32>
|
pub av: Option<f32>
|
||||||
|
@ -38,8 +39,8 @@ impl Controller {
|
||||||
let av = av_sample as f32/board::AV_ADC_GAIN;
|
let av = av_sample as f32/board::AV_ADC_GAIN;
|
||||||
self.last_av = Some(av);
|
self.last_av = Some(av);
|
||||||
|
|
||||||
let pid_out = self.pid.update(av);
|
let hv_pwm_duty = self.pid.update(av);
|
||||||
board::set_hv_pwm(pid_out as u16)
|
board::set_hv_pwm(hv_pwm_duty as u16)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_target(&mut self, volts: f32) {
|
pub fn set_target(&mut self, volts: f32) {
|
||||||
|
@ -69,7 +70,7 @@ impl Controller {
|
||||||
|
|
||||||
impl ControllerStatus {
|
impl ControllerStatus {
|
||||||
pub fn debug_print(&self) {
|
pub fn debug_print(&self) {
|
||||||
println!("anode ready: {}", self.ready);
|
println!("anode rdy: {}", self.ready);
|
||||||
if self.av.is_some() {
|
if self.av.is_some() {
|
||||||
println!("voltage: {}V", self.av.unwrap());
|
println!("voltage: {}V", self.av.unwrap());
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,14 +3,24 @@ use core::num::Float;
|
||||||
use board;
|
use board;
|
||||||
use pid;
|
use pid;
|
||||||
|
|
||||||
const PID_PARAMETERS: pid::Parameters = pid::Parameters {
|
const FBI_PID_PARAMETERS: pid::Parameters = pid::Parameters {
|
||||||
kp: 0.004,
|
kp: 180.0,
|
||||||
ki: 0.002,
|
ki: 90.0,
|
||||||
|
kd: 0.0,
|
||||||
|
output_min: 0.5,
|
||||||
|
output_max: 3.0,
|
||||||
|
integral_min: -0.02,
|
||||||
|
integral_max: 0.02
|
||||||
|
};
|
||||||
|
|
||||||
|
const FV_PID_PARAMETERS: pid::Parameters = pid::Parameters {
|
||||||
|
kp: 1.80,
|
||||||
|
ki: 0.3,
|
||||||
kd: 0.0,
|
kd: 0.0,
|
||||||
output_min: 0.0,
|
output_min: 0.0,
|
||||||
output_max: 30.0,
|
output_max: 30.0,
|
||||||
integral_min: -5000.0,
|
integral_min: -50.0,
|
||||||
integral_max: 5000.0
|
integral_max: 50.0
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct Controller {
|
pub struct Controller {
|
||||||
|
@ -19,8 +29,9 @@ pub struct Controller {
|
||||||
fbi_buffer: [f32; 16],
|
fbi_buffer: [f32; 16],
|
||||||
fbi_buffer_count: usize,
|
fbi_buffer_count: usize,
|
||||||
last_fbi: Option<f32>,
|
last_fbi: Option<f32>,
|
||||||
pid: pid::Controller,
|
fbi_pid: pid::Controller,
|
||||||
|
|
||||||
|
fv_pid: pid::Controller,
|
||||||
last_fv: Option<f32>,
|
last_fv: Option<f32>,
|
||||||
|
|
||||||
fbv_target: f32,
|
fbv_target: f32,
|
||||||
|
@ -35,7 +46,6 @@ pub struct ControllerStatus {
|
||||||
pub fbv: Option<f32>
|
pub fbv: Option<f32>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl Controller {
|
impl Controller {
|
||||||
pub const fn new() -> Controller {
|
pub const fn new() -> Controller {
|
||||||
Controller {
|
Controller {
|
||||||
|
@ -44,8 +54,9 @@ impl Controller {
|
||||||
fbi_buffer: [0.0; 16],
|
fbi_buffer: [0.0; 16],
|
||||||
fbi_buffer_count: 0,
|
fbi_buffer_count: 0,
|
||||||
last_fbi: None,
|
last_fbi: None,
|
||||||
pid: pid::Controller::new(PID_PARAMETERS),
|
fbi_pid: pid::Controller::new(FBI_PID_PARAMETERS),
|
||||||
|
|
||||||
|
fv_pid: pid::Controller::new(FV_PID_PARAMETERS),
|
||||||
last_fv: None,
|
last_fv: None,
|
||||||
|
|
||||||
fbv_target: 0.0,
|
fbv_target: 0.0,
|
||||||
|
@ -78,7 +89,14 @@ impl Controller {
|
||||||
self.fbi_buffer_count = 0;
|
self.fbi_buffer_count = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.last_fv = Some(fv_sample as f32/board::FV_ADC_GAIN);
|
let fv_target = self.fbi_pid.update(fbi);
|
||||||
|
self.fv_pid.set_target(fv_target);
|
||||||
|
|
||||||
|
let fv = fv_sample as f32/board::FV_ADC_GAIN;
|
||||||
|
let fv_pwm_duty = self.fv_pid.update(fv);
|
||||||
|
board::set_fv_pwm(fv_pwm_duty as u16);
|
||||||
|
|
||||||
|
self.last_fv = Some(fv);
|
||||||
self.last_fbv = Some(fbv_sample as f32/board::FBV_ADC_GAIN);
|
self.last_fbv = Some(fbv_sample as f32/board::FBV_ADC_GAIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,7 +120,7 @@ impl Controller {
|
||||||
fn emission_ready(&self) -> bool {
|
fn emission_ready(&self) -> bool {
|
||||||
match self.last_fbi {
|
match self.last_fbi {
|
||||||
None => false,
|
None => false,
|
||||||
Some(last_fbi) => (self.fbi_target - last_fbi).abs()/self.fbi_target < 0.02
|
Some(last_fbi) => (self.fbi_target - last_fbi).abs()/self.fbi_target < 0.05
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,7 +132,8 @@ impl Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reset(&mut self) {
|
pub fn reset(&mut self) {
|
||||||
self.pid.reset();
|
self.fbi_pid.reset();
|
||||||
|
self.fv_pid.reset();
|
||||||
self.fbi_buffer_count = 0;
|
self.fbi_buffer_count = 0;
|
||||||
self.last_fbi = None;
|
self.last_fbi = None;
|
||||||
self.last_fv = None;
|
self.last_fv = None;
|
||||||
|
@ -134,15 +153,15 @@ impl Controller {
|
||||||
|
|
||||||
impl ControllerStatus {
|
impl ControllerStatus {
|
||||||
pub fn debug_print(&self) {
|
pub fn debug_print(&self) {
|
||||||
println!("cathode ready: {}", self.ready);
|
println!("cathode rdy: {}", self.ready);
|
||||||
if self.fbi.is_some() {
|
if self.fbi.is_some() {
|
||||||
println!("emission: {}mA", 1000.0*self.fbi.unwrap());
|
println!("emi: {}mA", 1000.0*self.fbi.unwrap());
|
||||||
}
|
}
|
||||||
if self.fv.is_some() {
|
if self.fv.is_some() {
|
||||||
println!("fil voltage: {}V", self.fv.unwrap());
|
println!("fil: {}V", self.fv.unwrap());
|
||||||
}
|
}
|
||||||
if self.fbv.is_some() {
|
if self.fbv.is_some() {
|
||||||
println!("bias voltage: {}V", self.fbv.unwrap());
|
println!("bias: {}V", self.fbv.unwrap());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,7 +84,6 @@ fn main() {
|
||||||
loop_anode.set_target(anode_cathode+cathode_bias);
|
loop_anode.set_target(anode_cathode+cathode_bias);
|
||||||
loop_cathode.set_emission_target(anode_cathode/10000.0);
|
loop_cathode.set_emission_target(anode_cathode/10000.0);
|
||||||
loop_cathode.set_bias_target(cathode_bias);
|
loop_cathode.set_bias_target(cathode_bias);
|
||||||
//board::set_fv_pwm(10);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
println!(r#"
|
println!(r#"
|
||||||
|
@ -171,8 +170,9 @@ extern fn adc0_ss0(_ctxt: ADC0SS0) {
|
||||||
time.set(time.get() + 1);
|
time.set(time.get() + 1);
|
||||||
|
|
||||||
if time.get() % 300 == 0 {
|
if time.get() % 300 == 0 {
|
||||||
//loop_anode.get_status().debug_print();
|
println!("");
|
||||||
//loop_cathode.get_status().debug_print();
|
loop_anode.get_status().debug_print();
|
||||||
|
loop_cathode.get_status().debug_print();
|
||||||
electrometer.get_status().debug_print();
|
electrometer.get_status().debug_print();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue