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
ef362643a7
commit
cee633845e
17
README.md
17
README.md
@ -258,18 +258,15 @@ 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` |
|
||||
| `time` | Seconds | Report timestamp (since thermostat reset) |
|
||||
| `interval` | Seconds | ADC Sampling Interval |
|
||||
| `sens` | Ohms | Thermistor resistance |
|
||||
| `temperature` | Degrees Celsius | Temperature derived from thermistor resistance |
|
||||
| `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 |
|
||||
| `i_set` | Amperes | Set TEC output current |
|
||||
| `i_measured` | Amperes | Measured current passing through TEC |
|
||||
| `v_measured` | Volts | Measured voltage across TEC |
|
||||
|
||||
Note: With Thermostat v2 and below, the voltage and current readouts `i_tec` and `tec_i` are noisy without the hardware fix shown in [this PR][https://git.m-labs.hk/M-Labs/thermostat/pulls/105].
|
||||
|
||||
|
@ -408,15 +408,15 @@ impl Channels {
|
||||
(duty * max, MAX_TEC_I)
|
||||
}
|
||||
|
||||
// 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.adc_read(channel, PinsAdcReadTarget::ITec, 16)
|
||||
- self.adc_read(channel, PinsAdcReadTarget::VREF, 16))
|
||||
/ 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.adc_read(channel, PinsAdcReadTarget::VTec, 16) - ElectricPotential::new::<volt>(1.5))
|
||||
* 4.0
|
||||
}
|
||||
@ -475,28 +475,23 @@ impl Channels {
|
||||
|
||||
fn report(&mut self, channel: usize) -> Report {
|
||||
let i_set = self.get_i_set(channel);
|
||||
let i_tec = self.adc_read(channel, PinsAdcReadTarget::ITec, 16);
|
||||
let tec_i = self.get_tec_i(channel);
|
||||
let dac_value = self.get_dac(channel);
|
||||
let i_measured = self.get_i_measured(channel);
|
||||
let v_measured = self.get_v_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.adc_read(channel, PinsAdcReadTarget::DacVfb, 1),
|
||||
i_tec,
|
||||
tec_i,
|
||||
tec_u_meas: self.get_tec_v(channel),
|
||||
pid_output,
|
||||
i_set,
|
||||
i_measured,
|
||||
v_measured,
|
||||
}
|
||||
}
|
||||
|
||||
@ -576,8 +571,8 @@ impl Channels {
|
||||
serde_json_core::to_vec(&summaries)
|
||||
}
|
||||
|
||||
max_by(self.get_tec_i(0).abs(), self.get_tec_i(1).abs(), |a, b| {
|
||||
pub fn max_abs_i_measured(&mut self) -> ElectricCurrent {
|
||||
max_by(self.get_i_measured(0).abs(), self.get_i_measured(1).abs(), |a, b| {
|
||||
a.partial_cmp(b).unwrap_or(core::cmp::Ordering::Equal)
|
||||
})
|
||||
}
|
||||
@ -588,17 +583,13 @@ 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,
|
||||
pid_output: ElectricCurrent,
|
||||
i_set: ElectricCurrent,
|
||||
i_measured: ElectricCurrent,
|
||||
v_measured: ElectricPotential,
|
||||
}
|
||||
|
||||
pub struct CenterPointJson(CenterPoint);
|
||||
|
Loading…
Reference in New Issue
Block a user