forked from M-Labs/thermostat
steinhart_hart: fix equation
This commit is contained in:
parent
bec7019f3a
commit
2e72a03b93
@ -110,7 +110,7 @@ pub enum PidParameter {
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum ShParameter {
|
||||
T0,
|
||||
R,
|
||||
B,
|
||||
R0,
|
||||
}
|
||||
|
||||
@ -353,7 +353,7 @@ fn steinhart_hart_parameter(input: &[u8]) -> IResult<&[u8], Result<Command, Erro
|
||||
let (input, _) = whitespace(input)?;
|
||||
let (input, parameter) =
|
||||
alt((value(ShParameter::T0, tag("t0")),
|
||||
value(ShParameter::R, tag("r")),
|
||||
value(ShParameter::B, tag("b")),
|
||||
value(ShParameter::R0, tag("r0"))
|
||||
))(input)?;
|
||||
let (input, _) = whitespace(input)?;
|
||||
|
@ -243,7 +243,7 @@ fn main() -> ! {
|
||||
channel,
|
||||
);
|
||||
let _ = writeln!(socket, "- t0={}", state.sh.t0);
|
||||
let _ = writeln!(socket, "- r={}", state.sh.r);
|
||||
let _ = writeln!(socket, "- b={}", state.sh.b);
|
||||
let _ = writeln!(socket, "- r0={}", state.sh.r0);
|
||||
let _ = writeln!(socket, "");
|
||||
}
|
||||
@ -355,10 +355,9 @@ fn main() -> ! {
|
||||
use command_parser::ShParameter::*;
|
||||
match parameter {
|
||||
T0 => sh.t0 = value,
|
||||
R => sh.r = value,
|
||||
B => sh.b = value,
|
||||
R0 => sh.r0 = value,
|
||||
}
|
||||
sh.update();
|
||||
let _ = writeln!(socket, "Steinhart-Hart equation parameter updated");
|
||||
}
|
||||
Command::PostFilter { channel, rate } => {
|
||||
|
@ -4,38 +4,28 @@ use num_traits::float::Float;
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Parameters {
|
||||
pub t0: f64,
|
||||
pub r: f64,
|
||||
pub b: f64,
|
||||
pub r0: f64,
|
||||
|
||||
r_fact: f64,
|
||||
}
|
||||
|
||||
impl Parameters {
|
||||
/// Update the cached r_fact
|
||||
pub fn update(&mut self) {
|
||||
self.r_fact = (self.r / self.r0).ln();
|
||||
}
|
||||
|
||||
/// Perform the voltage to temperature conversion.
|
||||
///
|
||||
/// Result unit: Kelvin
|
||||
///
|
||||
/// TODO: verify
|
||||
pub fn get_temperature(&self, b: f64) -> f64 {
|
||||
let inv_temp = 1.0 / self.t0 + self.r_fact / b;
|
||||
pub fn get_temperature(&self, r: f64) -> f64 {
|
||||
let inv_temp = 1.0 / self.t0 + (r / self.r0).ln() / self.b;
|
||||
1.0 / inv_temp
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Parameters {
|
||||
fn default() -> Self {
|
||||
let mut p = Parameters {
|
||||
Parameters {
|
||||
t0: 0.001_4,
|
||||
r: 0.000_000_099,
|
||||
b: 0.000_000_099,
|
||||
r0: 5_110.0,
|
||||
r_fact: 0.0,
|
||||
};
|
||||
p.update();
|
||||
p
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user