Thermocouple type K conversion
This commit is contained in:
@ -41,7 +41,7 @@ version = "0.3.*"
|
|||||||
version = "0.4.*"
|
version = "0.4.*"
|
||||||
# Serialization
|
# Serialization
|
||||||
[workspace.dependencies.parity-scale-codec]
|
[workspace.dependencies.parity-scale-codec]
|
||||||
version = "3.5.*"
|
version = "3.6.*"
|
||||||
default-features = false
|
default-features = false
|
||||||
# Embedded-HAL
|
# Embedded-HAL
|
||||||
[workspace.dependencies.embedded-hal]
|
[workspace.dependencies.embedded-hal]
|
||||||
@ -132,6 +132,7 @@ thermocouple_k = []
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
uom = { workspace = true }
|
uom = { workspace = true }
|
||||||
parity-scale-codec = { workspace = true }
|
parity-scale-codec = { workspace = true }
|
||||||
|
libm = { workspace = true }
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------------------------------------------
|
||||||
#----- Profiles ------------------------
|
#----- Profiles ------------------------
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
use crate::transducer::InvalidValue;
|
use crate::transducer::InvalidValue;
|
||||||
|
use libm::powf;
|
||||||
use uom::si::electric_potential::{millivolt, volt};
|
use uom::si::electric_potential::{millivolt, volt};
|
||||||
use uom::si::f32;
|
use uom::si::f32;
|
||||||
use uom::si::thermodynamic_temperature::degree_celsius;
|
use uom::si::thermodynamic_temperature::degree_celsius;
|
||||||
@ -26,8 +27,7 @@ pub fn convert(
|
|||||||
let mv_pow7 = mv_pow6 * mv;
|
let mv_pow7 = mv_pow6 * mv;
|
||||||
let mv_pow8 = mv_pow7 * mv;
|
let mv_pow8 = mv_pow7 * mv;
|
||||||
|
|
||||||
let celsius = 1.0
|
let celsius = 2.5173462E+1 * mv
|
||||||
+ 2.5173462E+1 * mv
|
|
||||||
+ -1.1662878 * mv_pow2
|
+ -1.1662878 * mv_pow2
|
||||||
+ -1.0833638 * mv_pow3
|
+ -1.0833638 * mv_pow3
|
||||||
+ -8.9773540E-1 * mv_pow4
|
+ -8.9773540E-1 * mv_pow4
|
||||||
@ -42,8 +42,7 @@ pub fn convert(
|
|||||||
let mv_pow8 = mv_pow7 * mv;
|
let mv_pow8 = mv_pow7 * mv;
|
||||||
let mv_pow9 = mv_pow8 * mv;
|
let mv_pow9 = mv_pow8 * mv;
|
||||||
|
|
||||||
let celsius = 1.0
|
let celsius = 2.508355E+1 * mv
|
||||||
+ 2.508355E+1 * mv
|
|
||||||
+ 7.860106E-2 * mv_pow2
|
+ 7.860106E-2 * mv_pow2
|
||||||
+ -2.503131E-1 * mv_pow3
|
+ -2.503131E-1 * mv_pow3
|
||||||
+ 8.315270E-2 * mv_pow4
|
+ 8.315270E-2 * mv_pow4
|
||||||
@ -72,21 +71,47 @@ pub fn convert(
|
|||||||
pub fn r_junction_offset_poly(
|
pub fn r_junction_offset_poly(
|
||||||
temperature: f32::ThermodynamicTemperature,
|
temperature: f32::ThermodynamicTemperature,
|
||||||
) -> Result<f32::ElectricPotential, InvalidValue> {
|
) -> Result<f32::ElectricPotential, InvalidValue> {
|
||||||
const T0: f32 = 2.5000000E+01;
|
|
||||||
const V0: f32 = 1.0003453E+00;
|
|
||||||
const P1: f32 = 4.0514854E-02;
|
|
||||||
const P2: f32 = -3.8789638E-05;
|
|
||||||
const P3: f32 = -2.8608478E-06;
|
|
||||||
const P4: f32 = -9.5367041E-10;
|
|
||||||
const Q1: f32 = -1.3948675E-03;
|
|
||||||
const Q2: f32 = -6.7976627E-05;
|
|
||||||
|
|
||||||
let celsius = temperature.get::<degree_celsius>();
|
let celsius = temperature.get::<degree_celsius>();
|
||||||
if celsius >= -20.0 && celsius <= 70.0 {
|
let cel_pow2 = celsius * celsius;
|
||||||
let offset_tcj = celsius - T0;
|
let cel_pow3 = cel_pow2 * celsius;
|
||||||
let numerator = offset_tcj + (P1 + offset_tcj * (P2 + offset_tcj * (P3 + P4 * offset_tcj)));
|
let cel_pow4 = cel_pow3 * celsius;
|
||||||
let denominator = 1.0 + offset_tcj * (Q1 + Q2 * offset_tcj);
|
let cel_pow5 = cel_pow4 * celsius;
|
||||||
let mv = V0 + numerator / denominator;
|
let cel_pow6 = cel_pow5 * celsius;
|
||||||
|
let cel_pow7 = cel_pow6 * celsius;
|
||||||
|
let cel_pow8 = cel_pow7 * celsius;
|
||||||
|
let cel_pow9 = cel_pow8 * celsius;
|
||||||
|
|
||||||
|
if celsius >= -270.0 && celsius < 0.0 {
|
||||||
|
let cel_pow10 = cel_pow9 * celsius;
|
||||||
|
|
||||||
|
let mv = 0.394501280250E-01 * celsius
|
||||||
|
+ 0.236223735980E-04 * cel_pow2
|
||||||
|
+ -0.328589067840E-06 * cel_pow3
|
||||||
|
+ -0.499048287770E-08 * cel_pow4
|
||||||
|
+ -0.675090591730E-10 * cel_pow5
|
||||||
|
+ -0.574103274280E-12 * cel_pow6
|
||||||
|
+ -0.310888728940E-14 * cel_pow7
|
||||||
|
+ -0.104516093650E-16 * cel_pow8
|
||||||
|
+ -0.198892668780E-19 * cel_pow9
|
||||||
|
+ -0.163226974860E-22 * cel_pow10;
|
||||||
|
|
||||||
|
Ok(f32::ElectricPotential::new::<millivolt>(mv))
|
||||||
|
} else if celsius >= 0.0 && celsius <= 1372.0 {
|
||||||
|
let base = celsius - 0.126968600000E+03;
|
||||||
|
let exp = -0.118343200000E-03 * (base * base);
|
||||||
|
let addition = powf(0.1185976, exp);
|
||||||
|
|
||||||
|
let mv = -0.176004136860E-01
|
||||||
|
+ 0.389212049750E-01 * celsius
|
||||||
|
+ 0.185587700320E-04 * cel_pow2
|
||||||
|
+ -0.994575928740E-07 * cel_pow3
|
||||||
|
+ 0.318409457190E-09 * cel_pow4
|
||||||
|
+ -0.560728448890E-12 * cel_pow5
|
||||||
|
+ 0.560750590590E-15 * cel_pow6
|
||||||
|
+ -0.320207200030E-18 * cel_pow7
|
||||||
|
+ 0.971511471520E-22 * cel_pow8
|
||||||
|
+ -0.121047212750E-25 * cel_pow9
|
||||||
|
+ addition;
|
||||||
|
|
||||||
Ok(f32::ElectricPotential::new::<millivolt>(mv))
|
Ok(f32::ElectricPotential::new::<millivolt>(mv))
|
||||||
} else {
|
} else {
|
||||||
@ -94,11 +119,12 @@ pub fn r_junction_offset_poly(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
pub fn r_junction_offset_lin(
|
pub fn r_junction_offset_lin(
|
||||||
temperature: f32::ThermodynamicTemperature,
|
temperature: f32::ThermodynamicTemperature,
|
||||||
) -> Result<f32::ElectricPotential, InvalidValue> {
|
) -> Result<f32::ElectricPotential, InvalidValue> {
|
||||||
let celsius = temperature.get::<degree_celsius>();
|
let celsius = temperature.get::<degree_celsius>();
|
||||||
if celsius >= -2.0 && celsius <= 1000.0 {
|
if celsius >= -2.0 && celsius <= 800.0 {
|
||||||
let mv = 0.041 * celsius;
|
let mv = 0.041 * celsius;
|
||||||
Ok(f32::ElectricPotential::new::<millivolt>(mv))
|
Ok(f32::ElectricPotential::new::<millivolt>(mv))
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user