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