Skip to content

Commit

Permalink
Fix mA to PSI conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
samderanova committed Apr 30, 2024
1 parent 51cb4a7 commit f2921c2
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions pod-operation/src/components/pressure_transducer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ const INA219_SCALING_VALUE: f32 = 160.0;
// The pressure transducer outputs a current between 4 mA and 20 mA with 0 PSI
// and 300 PSI respectively. Assuming a linear interpolation, a 1 mA increase
// results in a 18.75 PSI increase.
const MA_TO_PSI: f32 = 18.75;
const REF_CURRENT_LOW: f32 = 4.0;
const REF_CURRENT_HIGH: f32 = 20.0;
const REF_PRESSURE_LOW: f32 = 0.0;
const REF_PRESSURE_HIGH: f32 = 300.0;

const REF_CURRENT_SPAN: f32 = REF_CURRENT_HIGH - REF_CURRENT_LOW;
const REF_PRESSURE_SPAN: f32 = REF_PRESSURE_HIGH - REF_PRESSURE_LOW;

impl PressureTransducer {
pub fn new(ina219_addr: u8) -> Self {
Expand All @@ -38,7 +44,10 @@ impl PressureTransducer {
// Read current from the INA219 and apply a scaling factor to translate
// the current reading to PSI.
pub fn read(&mut self) -> f32 {
self.read_current() * MA_TO_PSI
let current = self.read_current();

return REF_PRESSURE_LOW
+ REF_PRESSURE_SPAN * (current - REF_CURRENT_LOW) / REF_CURRENT_SPAN;
}

// Read from the INA219 and divide the reading by a scalar factor to
Expand Down

0 comments on commit f2921c2

Please sign in to comment.