Basic class for reading SPTE 10 bar 0-5V analog pressure sensor made by Festo

Dependents:   heros_leg_readout_torque_addition heros_leg_readout_torque_addition_V3 DROPSAWTestRigCode_V4

Revision:
0:642482fd9da0
Child:
1:189d6f2b0612
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SPTEPressureSensor.h	Fri Jun 15 10:29:41 2018 +0000
@@ -0,0 +1,67 @@
+#ifndef _SPTEPSensor_H_
+#define _AS5048_H_
+
+#include "mbed.h"
+/**
+ * Reading and nulling the SPTE pressure sensor made by festo (analog input)
+ */
+
+class SPTEPressureSensor {
+public:
+
+    /**
+     * @param pin_a_in PinName of analog input
+     * @param offset of analog value (calibration data)
+     * @param factor multiplication factor for analog value (calibration data)
+     */
+    SPTEPressureSensor(PinName pin_a_in, float offset, float factor) :
+        analog_in_(pin_a_in),
+        kOffset_(offset),
+        kFactor_(factor)
+    {
+    }
+
+    /**
+     * @return unscaled analog input value
+     */
+    float getPressureRaw() 
+    {
+        return analog_in_.read();
+    }
+
+    /**
+     * @return force value kOffset_ + kFactor_ * getPressureRaw();
+     */
+    float getPressure() 
+    {
+        return kOffset_ + kFactor_ * getPressureRaw();
+    }
+    
+    /**
+     * sets pressure scaling offset so that current output is pressure zero
+     */
+    void nullPressure()
+    {
+        kOffset_ = kOffset_ - getPressure();
+        return;        
+    }
+    
+    /**
+     * @return ffset of analog value
+     */
+    float get_offset() { return kOffset_; }
+    
+    /**
+     * @return factor multiplication factor for analog value
+     */
+    float get_factor() { return kFactor_; }
+
+
+private:
+    AnalogIn analog_in_;
+    
+    float kOffset_;
+    const float kFactor_;
+};
+
+#endif
\ No newline at end of file