forked from M-Labs/thermostat
channels: Start to make reports make sense
Names in the report make no sense, and expose implementation details. Start simplifying the interface.
This commit is contained in:
parent
e998172cb2
commit
78a304d7e9
26
README.md
26
README.md
|
@ -255,21 +255,17 @@ Use the bare `report` command to obtain a single report. Enable
|
|||
continuous reporting with `report mode on`. Reports are JSON objects
|
||||
with the following keys.
|
||||
|
||||
| Key | Unit | Description |
|
||||
| --- | :---: | --- |
|
||||
| `channel` | Integer | Channel `0`, or `1` |
|
||||
| `time` | Seconds | Temperature measurement time |
|
||||
| `adc` | Volts | AD7172 input |
|
||||
| `sens` | Ohms | Thermistor resistance derived from `adc` |
|
||||
| `temperature` | Degrees Celsius | Steinhart-Hart conversion result derived from `sens` |
|
||||
| `pid_engaged` | Boolean | `true` if in closed-loop mode |
|
||||
| `i_set` | Amperes | TEC output current |
|
||||
| `dac_value` | Volts | AD5680 output derived from `i_set` |
|
||||
| `dac_feedback` | Volts | ADC measurement of the AD5680 output |
|
||||
| `i_tec` | Volts | MAX1968 TEC current monitor |
|
||||
| `tec_i` | Amperes | TEC output current feedback derived from `i_tec` |
|
||||
| `tec_u_meas` | Volts | Measurement of the voltage across the TEC |
|
||||
| `pid_output` | Amperes | PID control output |
|
||||
| Key | Unit | Description |
|
||||
| --- | :---: | --- |
|
||||
| `channel` | Integer | Channel `0`, or `1` |
|
||||
| `time` | Seconds | Temperature measurement time |
|
||||
| `interval` | Seconds | ADC Interval |
|
||||
| `temperature` | Degrees Celsius | Measured Temperature by the thermistor |
|
||||
| `pid_engaged` | Boolean | `true` if in closed-loop mode |
|
||||
| `i_set` | Amperes | Set TEC output current |
|
||||
| `i_measured` | Amperes | Measured current passing through TEC |
|
||||
| `v_measured` | Volts | Measured voltage across TEC |
|
||||
| `pid_output` | Amperes | PID control output |
|
||||
|
||||
## PID Tuning
|
||||
|
||||
|
|
|
@ -114,7 +114,7 @@ impl Channels {
|
|||
voltage
|
||||
}
|
||||
|
||||
pub fn get_i(&mut self, channel: usize) -> ElectricCurrent {
|
||||
pub fn get_i_set(&mut self, channel: usize) -> ElectricCurrent {
|
||||
let center_point = self.get_center(channel);
|
||||
let r_sense = ElectricalResistance::new::<ohm>(R_SENSE);
|
||||
let voltage = self.get_dac(channel);
|
||||
|
@ -134,7 +134,7 @@ impl Channels {
|
|||
voltage
|
||||
}
|
||||
|
||||
pub fn set_i(&mut self, channel: usize, i_tec: ElectricCurrent) -> ElectricCurrent {
|
||||
pub fn set_i(&mut self, channel: usize, i_set: ElectricCurrent) -> ElectricCurrent {
|
||||
let vref_meas = match channel {
|
||||
0 => self.channel0.vref_meas,
|
||||
1 => self.channel1.vref_meas,
|
||||
|
@ -142,7 +142,7 @@ impl Channels {
|
|||
};
|
||||
let center_point = vref_meas;
|
||||
let r_sense = ElectricalResistance::new::<ohm>(R_SENSE);
|
||||
let voltage = i_tec * 10.0 * r_sense + center_point;
|
||||
let voltage = i_set * 10.0 * r_sense + center_point;
|
||||
let voltage = self.set_dac(channel, voltage);
|
||||
(voltage - center_point) / (10.0 * r_sense)
|
||||
}
|
||||
|
@ -370,13 +370,13 @@ impl Channels {
|
|||
(duty * max, max)
|
||||
}
|
||||
|
||||
// Get current passing through TEC
|
||||
pub fn get_tec_i(&mut self, channel: usize) -> ElectricCurrent {
|
||||
// Measure current passing through TEC
|
||||
pub fn get_i_measured(&mut self, channel: usize) -> ElectricCurrent {
|
||||
(self.read_itec(channel) - self.read_vref(channel)) / ElectricalResistance::new::<ohm>(0.4)
|
||||
}
|
||||
|
||||
// Get voltage across TEC
|
||||
pub fn get_tec_v(&mut self, channel: usize) -> ElectricPotential {
|
||||
// Measure voltage across TEC
|
||||
pub fn get_v_measured(&mut self, channel: usize) -> ElectricPotential {
|
||||
(self.read_tec_u_meas(channel) - ElectricPotential::new::<volt>(1.5)) * 4.0
|
||||
}
|
||||
|
||||
|
@ -433,28 +433,21 @@ impl Channels {
|
|||
}
|
||||
|
||||
fn report(&mut self, channel: usize) -> Report {
|
||||
let i_set = self.get_i(channel);
|
||||
let i_tec = self.read_itec(channel);
|
||||
let tec_i = self.get_tec_i(channel);
|
||||
let dac_value = self.get_dac(channel);
|
||||
let i_set = self.get_i_set(channel);
|
||||
let i_measured = self.get_i_measured(channel);
|
||||
let state = self.channel_state(channel);
|
||||
let pid_output = ElectricCurrent::new::<ampere>(state.pid.y1);
|
||||
Report {
|
||||
channel,
|
||||
time: state.get_adc_time(),
|
||||
interval: state.get_adc_interval(),
|
||||
adc: state.get_adc(),
|
||||
sens: state.get_sens(),
|
||||
temperature: state
|
||||
.get_temperature()
|
||||
.map(|temperature| temperature.get::<degree_celsius>()),
|
||||
pid_engaged: state.pid_engaged,
|
||||
i_set,
|
||||
dac_value,
|
||||
dac_feedback: self.read_dac_feedback(channel),
|
||||
i_tec,
|
||||
tec_i,
|
||||
tec_u_meas: self.get_tec_v(channel),
|
||||
i_measured,
|
||||
v_measured: self.get_v_measured(channel),
|
||||
pid_output,
|
||||
}
|
||||
}
|
||||
|
@ -488,7 +481,7 @@ impl Channels {
|
|||
PwmSummary {
|
||||
channel,
|
||||
center: CenterPointJson(self.channel_state(channel).center.clone()),
|
||||
i_set: (self.get_i(channel), ElectricCurrent::new::<ampere>(3.0)).into(),
|
||||
i_set: (self.get_i_set(channel), ElectricCurrent::new::<ampere>(3.0)).into(),
|
||||
max_v: (self.get_max_v(channel), ElectricPotential::new::<volt>(5.0)).into(),
|
||||
max_i_pos: self.get_max_i_pos(channel).into(),
|
||||
max_i_neg: self.get_max_i_neg(channel).into(),
|
||||
|
@ -535,10 +528,10 @@ impl Channels {
|
|||
serde_json_core::to_vec(&summaries)
|
||||
}
|
||||
|
||||
pub fn current_abs_max_tec_i(&mut self) -> f64 {
|
||||
pub fn max_abs_i_measured(&mut self) -> f64 {
|
||||
max_by(
|
||||
self.get_tec_i(0).abs().get::<ampere>(),
|
||||
self.get_tec_i(1).abs().get::<ampere>(),
|
||||
self.get_i_measured(0).abs().get::<ampere>(),
|
||||
self.get_i_measured(1).abs().get::<ampere>(),
|
||||
|a, b| a.partial_cmp(b).unwrap_or(core::cmp::Ordering::Equal),
|
||||
)
|
||||
}
|
||||
|
@ -549,16 +542,11 @@ pub struct Report {
|
|||
channel: usize,
|
||||
time: Time,
|
||||
interval: Time,
|
||||
adc: Option<ElectricPotential>,
|
||||
sens: Option<ElectricalResistance>,
|
||||
temperature: Option<f64>,
|
||||
pid_engaged: bool,
|
||||
i_set: ElectricCurrent,
|
||||
dac_value: ElectricPotential,
|
||||
dac_feedback: ElectricPotential,
|
||||
i_tec: ElectricPotential,
|
||||
tec_i: ElectricCurrent,
|
||||
tec_u_meas: ElectricPotential,
|
||||
i_measured: ElectricCurrent,
|
||||
v_measured: ElectricPotential,
|
||||
pid_output: ElectricCurrent,
|
||||
}
|
||||
|
||||
|
|
|
@ -207,7 +207,7 @@ impl Handler {
|
|||
channel: usize,
|
||||
center: CenterPoint,
|
||||
) -> Result<Handler, Error> {
|
||||
let i_tec = channels.get_i(channel);
|
||||
let i_tec = channels.get_i_set(channel);
|
||||
let state = channels.channel_state(channel);
|
||||
state.center = center;
|
||||
if !state.pid_engaged {
|
||||
|
|
|
@ -196,7 +196,7 @@ fn main() -> ! {
|
|||
server.for_each(|_, session| session.set_report_pending(channel.into()));
|
||||
}
|
||||
|
||||
fan_ctrl.cycle(channels.current_abs_max_tec_i() as f32);
|
||||
fan_ctrl.cycle(channels.max_abs_i_measured() as f32);
|
||||
|
||||
if channels.pid_engaged() {
|
||||
leds.g3.on();
|
||||
|
|
Loading…
Reference in New Issue