diff --git a/README.md b/README.md index 221263d..22a1f99 100644 --- a/README.md +++ b/README.md @@ -114,8 +114,8 @@ formatted as line-delimited JSON. | `pid <0/1> kd ` | Set differential gain | | `pid <0/1> output_min ` | Set mininum output | | `pid <0/1> output_max ` | Set maximum output | -| `s-h` | Show Steinhart-Hart equation parameters | -| `s-h <0/1> ` | Set Steinhart-Hart parameter for a channel | +| `b-p` | Show B-Parameter equation parameters | +| `b-p <0/1> ` | Set B-Parameter for a channel | | `postfilter` | Show postfilter settings | | `postfilter <0/1> off` | Disable postfilter | | `postfilter <0/1> rate ` | Set postfilter output data rate | @@ -147,22 +147,22 @@ output will be truncated when USB buffers are full. Connect the thermistor with the SENS pins of the device. Temperature-depending resistance is measured by the AD7172 -ADC. To prepare conversion to a temperature, set the Beta parameters -for the Steinhart-Hart equation. +ADC. To prepare conversion to a temperature, set the parameters +for the B-Parameter equation. Set the base temperature in degrees celsius for the channel 0 thermistor: ``` -s-h 0 t0 20 +b-p 0 t0 20 ``` Set the resistance in Ohms measured at the base temperature t0: ``` -s-h 0 r0 10000 +b-p 0 r0 10000 ``` Set the Beta parameter: ``` -s-h 0 b 3800 +b-p 0 b 3800 ``` ### 50/60 Hz filtering @@ -261,7 +261,7 @@ with the following keys. | `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` | +| `temperature` | Degrees Celsius | B-Parameter conversion result derived from `sens` | | `pid_engaged` | Boolean | `true` if in closed-loop mode | | `i_set` | Amperes | TEC output current | | `vref` | Volts | MAX1968 VREF (1.5 V) | diff --git a/pytec/example.py b/pytec/example.py index 001ea49..1b6dcef 100644 --- a/pytec/example.py +++ b/pytec/example.py @@ -1,11 +1,11 @@ from pytec.client import Client tec = Client() #(host="localhost", port=6667) -tec.set_param("s-h", 1, "t0", 20) +tec.set_param("b-p", 1, "t0", 20) print(tec.get_pwm()) print(tec.get_pid()) print(tec.get_pwm()) print(tec.get_postfilter()) -print(tec.get_steinhart_hart()) +print(tec.get_b_parameter()) for data in tec.report_mode(): print(data) diff --git a/pytec/pytec/client.py b/pytec/pytec/client.py index 062d8dc..22b63c1 100644 --- a/pytec/pytec/client.py +++ b/pytec/pytec/client.py @@ -89,14 +89,14 @@ class Client: """ return self._get_conf("pid") - def get_steinhart_hart(self): - """Retrieve Steinhart-Hart parameters for resistance to temperature conversion + def get_b_parameter(self): + """Retrieve B-Parameter equation parameters for resistance to temperature conversion Example:: [{'params': {'b': 3800.0, 'r0': 10000.0, 't0': 298.15}, 'channel': 0}, {'params': {'b': 3800.0, 'r0': 10000.0, 't0': 298.15}, 'channel': 1}] """ - return self._get_conf("s-h") + return self._get_conf("b-p") def get_postfilter(self): """Retrieve DAC postfilter configuration @@ -143,7 +143,7 @@ class Client: Examples:: tec.set_param("pwm", 0, "max_v", 2.0) tec.set_param("pid", 1, "output_max", 2.5) - tec.set_param("s-h", 0, "t0", 20.0) + tec.set_param("b-p", 0, "t0", 20.0) tec.set_param("center", 0, "vref") tec.set_param("postfilter", 1, 21) diff --git a/src/steinhart_hart.rs b/src/b_parameter.rs similarity index 85% rename from src/steinhart_hart.rs rename to src/b_parameter.rs index 87149df..e76aa26 100644 --- a/src/steinhart_hart.rs +++ b/src/b_parameter.rs @@ -10,15 +10,15 @@ use uom::si::{ }; use serde::{Deserialize, Serialize}; -/// Steinhart-Hart equation parameters +/// B-Parameter equation parameters #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub struct Parameters { /// Base temperature pub t0: ThermodynamicTemperature, - /// Base resistance + /// Thermistor resistance at base temperature pub r0: ElectricalResistance, - /// Beta - pub b: f64, + /// B, the average slope of the function ln R vs. 1/T + pub b: ThermodynamicTemperature, } impl Parameters { diff --git a/src/channel_state.rs b/src/channel_state.rs index 0f00f0b..d996c65 100644 --- a/src/channel_state.rs +++ b/src/channel_state.rs @@ -14,7 +14,7 @@ use uom::si::{ use crate::{ ad7172, pid, - steinhart_hart as sh, + b_parameter as bp, command_parser::CenterPoint, }; @@ -31,7 +31,7 @@ pub struct ChannelState { pub dac_value: ElectricPotential, pub pid_engaged: bool, pub pid: pid::Controller, - pub sh: sh::Parameters, + pub bp: bp::Parameters, } impl ChannelState { @@ -46,7 +46,7 @@ impl ChannelState { dac_value: ElectricPotential::new::(0.0), pid_engaged: false, pid: pid::Controller::new(pid::Parameters::default()), - sh: sh::Parameters::default(), + bp: bp::Parameters::default(), } } @@ -92,7 +92,7 @@ impl ChannelState { pub fn get_temperature(&self) -> Option { let r = self.get_sens()?; - let temperature = self.sh.get_temperature(r); + let temperature = self.bp.get_temperature(r); Some(temperature) } } diff --git a/src/channels.rs b/src/channels.rs index a90d886..d19c88c 100644 --- a/src/channels.rs +++ b/src/channels.rs @@ -19,7 +19,7 @@ use crate::{ command_parser::{CenterPoint, PwmPin}, command_handler::JsonBuffer, pins, - steinhart_hart, + b_parameter, }; pub const CHANNELS: usize = 2; @@ -511,15 +511,15 @@ impl Channels { serde_json_core::to_vec(&summaries) } - fn steinhart_hart_summary(&mut self, channel: usize) -> SteinhartHartSummary { - let params = self.channel_state(channel).sh.clone(); - SteinhartHartSummary { channel, params } + fn b_parameter_summary(&mut self, channel: usize) -> BParameterSummary { + let params = self.channel_state(channel).bp.clone(); + BParameterSummary { channel, params } } - pub fn steinhart_hart_summaries_json(&mut self) -> Result { + pub fn b_parameter_summaries_json(&mut self) -> Result { let mut summaries = Vec::<_, U2>::new(); for channel in 0..CHANNELS { - let _ = summaries.push(self.steinhart_hart_summary(channel)); + let _ = summaries.push(self.b_parameter_summary(channel)); } serde_json_core::to_vec(&summaries) } @@ -595,7 +595,7 @@ pub struct PostFilterSummary { } #[derive(Serialize)] -pub struct SteinhartHartSummary { +pub struct BParameterSummary { channel: usize, - params: steinhart_hart::Parameters, + params: b_parameter::Parameters, } diff --git a/src/command_handler.rs b/src/command_handler.rs index 91b46d7..9d9329f 100644 --- a/src/command_handler.rs +++ b/src/command_handler.rs @@ -11,7 +11,7 @@ use super::{ CenterPoint, PidParameter, PwmPin, - ShParameter + BpParameter }, ad7172, CHANNEL_CONFIG_KEY, @@ -139,13 +139,13 @@ impl Handler { Ok(Handler::Handled) } - fn show_steinhart_hart(socket: &mut TcpSocket, channels: &mut Channels) -> Result { - match channels.steinhart_hart_summaries_json() { + fn show_b_parameter(socket: &mut TcpSocket, channels: &mut Channels) -> Result { + match channels.b_parameter_summaries_json() { Ok(buf) => { send_line(socket, &buf); } Err(e) => { - error!("unable to serialize steinhart-hart summaries: {:?}", e); + error!("unable to serialize b parameter summaries: {:?}", e); let _ = writeln!(socket, "{{\"error\":\"{:?}\"}}", e); return Err(Error::ReportError); } @@ -238,13 +238,13 @@ impl Handler { Ok(Handler::Handled) } - fn set_steinhart_hart (socket: &mut TcpSocket, channels: &mut Channels, channel: usize, parameter: ShParameter, value: f64) -> Result { - let sh = &mut channels.channel_state(channel).sh; - use super::command_parser::ShParameter::*; + fn set_b_parameter (socket: &mut TcpSocket, channels: &mut Channels, channel: usize, parameter: BpParameter, value: f64) -> Result { + let bp = &mut channels.channel_state(channel).bp; + use super::command_parser::BpParameter::*; match parameter { - T0 => sh.t0 = ThermodynamicTemperature::new::(value), - B => sh.b = value, - R0 => sh.r0 = ElectricalResistance::new::(value), + T0 => bp.t0 = ThermodynamicTemperature::new::(value), + B => bp.b = value, + R0 => bp.r0 = ElectricalResistance::new::(value), } send_line(socket, b"{}"); Ok(Handler::Handled) @@ -420,14 +420,14 @@ impl Handler { Command::Show(ShowCommand::Input) => Handler::show_report(socket, channels), Command::Show(ShowCommand::Pid) => Handler::show_pid(socket, channels), Command::Show(ShowCommand::Pwm) => Handler::show_pwm(socket, channels), - Command::Show(ShowCommand::SteinhartHart) => Handler::show_steinhart_hart(socket, channels), + Command::Show(ShowCommand::BParameter) => Handler::show_b_parameter(socket, channels), Command::Show(ShowCommand::PostFilter) => Handler::show_post_filter(socket, channels), Command::Show(ShowCommand::Ipv4) => Handler::show_ipv4(socket, ipv4_config), Command::PwmPid { channel } => Handler::engage_pid(socket, channels, channel), Command::Pwm { channel, pin, value } => Handler::set_pwm(socket, channels, channel, pin, value), Command::CenterPoint { channel, center } => Handler::set_center_point(socket, channels, channel, center), Command::Pid { channel, parameter, value } => Handler::set_pid(socket, channels, channel, parameter, value), - Command::SteinhartHart { channel, parameter, value } => Handler::set_steinhart_hart(socket, channels, channel, parameter, value), + Command::BParameter { channel, parameter, value } => Handler::set_b_parameter(socket, channels, channel, parameter, value), Command::PostFilter { channel, rate: None } => Handler::reset_post_filter(socket, channels, channel), Command::PostFilter { channel, rate: Some(rate) } => Handler::set_post_filter(socket, channels, channel, rate), Command::Load { channel } => Handler::load_channel(socket, channels, store, channel), diff --git a/src/command_parser.rs b/src/command_parser.rs index b9e70bb..1928510 100644 --- a/src/command_parser.rs +++ b/src/command_parser.rs @@ -99,7 +99,7 @@ pub enum ShowCommand { Reporting, Pwm, Pid, - SteinhartHart, + BParameter, PostFilter, Ipv4, } @@ -114,9 +114,9 @@ pub enum PidParameter { OutputMax, } -/// Steinhart-Hart equation parameter +/// B-Parameter equation parameter #[derive(Debug, Clone, PartialEq)] -pub enum ShParameter { +pub enum BpParameter { T0, B, R0, @@ -169,9 +169,9 @@ pub enum Command { parameter: PidParameter, value: f64, }, - SteinhartHart { + BParameter { channel: usize, - parameter: ShParameter, + parameter: BpParameter, value: f64, }, PostFilter { @@ -400,31 +400,31 @@ fn pid(input: &[u8]) -> IResult<&[u8], Result> { ))(input) } -/// `s-h <0-1> ` -fn steinhart_hart_parameter(input: &[u8]) -> IResult<&[u8], Result> { +/// `b-p <0-1> ` +fn b_parameter_parameter(input: &[u8]) -> IResult<&[u8], Result> { let (input, channel) = channel(input)?; let (input, _) = whitespace(input)?; let (input, parameter) = - alt((value(ShParameter::T0, tag("t0")), - value(ShParameter::B, tag("b")), - value(ShParameter::R0, tag("r0")) + alt((value(BpParameter::T0, tag("t0")), + value(BpParameter::B, tag("b")), + value(BpParameter::R0, tag("r0")) ))(input)?; let (input, _) = whitespace(input)?; let (input, value) = float(input)?; let result = value - .map(|value| Command::SteinhartHart { channel, parameter, value }); + .map(|value| Command::BParameter { channel, parameter, value }); Ok((input, result)) } -/// `s-h` | `s-h ` -fn steinhart_hart(input: &[u8]) -> IResult<&[u8], Result> { - let (input, _) = tag("s-h")(input)?; +/// `b-p` | `b-p ` +fn b_parameter(input: &[u8]) -> IResult<&[u8], Result> { + let (input, _) = tag("b-p")(input)?; alt(( preceded( whitespace, - steinhart_hart_parameter + b_parameter_parameter ), - value(Ok(Command::Show(ShowCommand::SteinhartHart)), end) + value(Ok(Command::Show(ShowCommand::BParameter)), end) ))(input) } @@ -594,7 +594,7 @@ fn command(input: &[u8]) -> IResult<&[u8], Result> { pwm, center_point, pid, - steinhart_hart, + b_parameter, postfilter, value(Ok(Command::Dfu), tag("dfu")), fan, @@ -765,17 +765,17 @@ mod test { } #[test] - fn parse_steinhart_hart() { - let command = Command::parse(b"s-h"); - assert_eq!(command, Ok(Command::Show(ShowCommand::SteinhartHart))); + fn parse_b_parameter() { + let command = Command::parse(b"b-p"); + assert_eq!(command, Ok(Command::Show(ShowCommand::BParameter))); } #[test] - fn parse_steinhart_hart_set() { - let command = Command::parse(b"s-h 1 t0 23.05"); - assert_eq!(command, Ok(Command::SteinhartHart { + fn parse_b_parameter_set() { + let command = Command::parse(b"b-p 1 t0 23.05"); + assert_eq!(command, Ok(Command::BParameter { channel: 1, - parameter: ShParameter::T0, + parameter: BpParameter::T0, value: 23.05, })); } diff --git a/src/config.rs b/src/config.rs index e7286fa..7fb50ce 100644 --- a/src/config.rs +++ b/src/config.rs @@ -9,7 +9,7 @@ use crate::{ channels::Channels, command_parser::CenterPoint, pid, - steinhart_hart, + b_parameter, }; #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] @@ -18,7 +18,7 @@ pub struct ChannelConfig { pid: pid::Parameters, pid_target: f32, pid_engaged: bool, - sh: steinhart_hart::Parameters, + bp: b_parameter::Parameters, pwm: PwmLimits, /// uses variant `PostFilter::Invalid` instead of `None` to save space adc_postfilter: PostFilter, @@ -38,7 +38,7 @@ impl ChannelConfig { pid: state.pid.parameters.clone(), pid_target: state.pid.target as f32, pid_engaged: state.pid_engaged, - sh: state.sh.clone(), + bp: state.bp.clone(), pwm, adc_postfilter, } @@ -50,7 +50,7 @@ impl ChannelConfig { state.pid.parameters = self.pid.clone(); state.pid.target = self.pid_target.into(); state.pid_engaged = self.pid_engaged; - state.sh = self.sh.clone(); + state.bp = self.bp.clone(); self.pwm.apply(channels, channel); diff --git a/src/main.rs b/src/main.rs index 3c01d74..6d888a3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -41,7 +41,7 @@ mod command_parser; use command_parser::Ipv4Config; mod timer; mod pid; -mod steinhart_hart; +mod b_parameter; mod channels; use channels::{CHANNELS, Channels}; mod channel;