From 1c30ff08de3a3abde5d979b86c0dc8afd858c92c Mon Sep 17 00:00:00 2001 From: atse Date: Mon, 28 Aug 2023 14:52:09 +0800 Subject: [PATCH] steinhart_hart: Beta Parameter uom dimensions The Beta Parameter is not dimensionless, and has unit kelvin. Incorporate that into the type system. --- src/command_handler.rs | 8 ++++++-- src/steinhart_hart.rs | 15 ++++++++------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/command_handler.rs b/src/command_handler.rs index 74106be..c042b24 100644 --- a/src/command_handler.rs +++ b/src/command_handler.rs @@ -19,7 +19,11 @@ use uom::si::{ electric_current::ampere, electric_potential::volt, electrical_resistance::ohm, - f64::{ElectricCurrent, ElectricPotential, ElectricalResistance, ThermodynamicTemperature}, + f64::{ + ElectricCurrent, ElectricPotential, ElectricalResistance, TemperatureInterval, + ThermodynamicTemperature, + }, + temperature_interval::kelvin, thermodynamic_temperature::degree_celsius, }; @@ -248,7 +252,7 @@ impl Handler { use super::command_parser::ShParameter::*; match parameter { T0 => sh.t0 = ThermodynamicTemperature::new::(value), - B => sh.b = value, + B => sh.b = TemperatureInterval::new::(value), R0 => sh.r0 = ElectricalResistance::new::(value), } send_line(socket, b"{}"); diff --git a/src/steinhart_hart.rs b/src/steinhart_hart.rs index 667c587..c4f1d0a 100644 --- a/src/steinhart_hart.rs +++ b/src/steinhart_hart.rs @@ -2,8 +2,9 @@ use num_traits::float::Float; use serde::{Deserialize, Serialize}; use uom::si::{ electrical_resistance::ohm, - f64::{ElectricalResistance, ThermodynamicTemperature}, + f64::{ElectricalResistance, TemperatureInterval, ThermodynamicTemperature}, ratio::ratio, + temperature_interval::kelvin as kelvin_interval, thermodynamic_temperature::{degree_celsius, kelvin}, }; @@ -12,17 +13,17 @@ use uom::si::{ pub struct Parameters { /// Base temperature pub t0: ThermodynamicTemperature, - /// Base resistance + /// Resistance at base temperature pub r0: ElectricalResistance, /// Beta - pub b: f64, + pub b: TemperatureInterval, } impl Parameters { - /// Perform the voltage to temperature conversion. + /// Perform the resistance to temperature conversion. pub fn get_temperature(&self, r: ElectricalResistance) -> ThermodynamicTemperature { - let inv_temp = 1.0 / self.t0.get::() + (r / self.r0).get::().ln() / self.b; - ThermodynamicTemperature::new::(1.0 / inv_temp) + let temp = (self.t0.recip() + (r / self.r0).get::().ln() / self.b).recip(); + ThermodynamicTemperature::new::(temp.get::()) } } @@ -31,7 +32,7 @@ impl Default for Parameters { Parameters { t0: ThermodynamicTemperature::new::(25.0), r0: ElectricalResistance::new::(10_000.0), - b: 3800.0, + b: TemperatureInterval::new::(3800.0), } } }