This lib is considered to be used as a sensor's calibration program. Calibration with Spline Interpolation might be useful in the case that you want some model expressing relationship such like between a value of physical quantity and your sensor's voltage, but you cannot estimate a model such as liner, square, cubic polynomial, or sine curve. This makes (Parametric) Cubic Spline Polynomial Model (Coefficients of the polynomial) from some sample plots(e.g. sets of (value, voltage)). The inverse function (x,y)->(y,x) has been implemented so as to get analog data (not stepping or leveled data).

Fork of TRP105F_Spline by Akifumi Takahashi

Revision:
3:75f50dbedf1b
Child:
4:8db89b731133
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/CubicSpline.h	Thu May 12 14:41:15 2016 +0000
@@ -0,0 +1,74 @@
+/**
+ *  Spline_Cubic.h,.cpp
+ *
+ *  Author: aktk, aktk.j.uec@gmail.com
+ *  Tokyo, Japan.
+ *
+ *  LOG:
+ *  ver.0   2016/02.12 - 2016/02/16
+ *      TRP105F_Spline.h,.cpp(Ver.2.1)
+ *  ver.1   2016/05.12
+ */
+#ifndef Cubic_Spline_H
+#define Cubic_Spline_H
+
+#include "mbed.h"
+
+
+//  Vector Element Type
+typedef struct {
+    unsigned short x; //  
+    unsigned short y; //  distance
+} Vector2d;
+
+enum UseType{
+    AsDEBUG,
+    AsMODULE
+};
+
+class Spline_2dCubic
+{
+public:
+    //  Constraction
+    Spline_2dCubic();
+    Spline_2dCubic(unsigned int);
+    Spline_2dCubic(unsigned int arg_NumSample, UseType arg_dit);
+    //  Destraction
+    ~Spline_2dCubic();
+    //  Functions
+    unsigned short getX();
+    unsigned short getY();
+    void    calibrateSensor();
+    void    saveSetting();
+    void    saveSetting(const char *filename);
+    void    loadSetting();
+    void    loadSetting(const char *filename);
+    void    printOutData();
+    void    printThresholds();
+
+private:
+    //
+    //  Variables
+    //
+    unsigned int _Sample_Num;    // the number of samples for derive spline
+    Vector2d*    _Sample_Set;
+    UseType      _useType;
+    double*      _u_param;
+    //
+    //  For calibration
+    //
+    void    _sampleData();
+    void    _makeSpline();  //  Cubic spline
+    unsigned short _getSplineYof(double);
+    //
+    //  For get distance
+    //
+    int     _getNearest(int, int, unsigned short);
+    //
+    //  For debug
+    //
+    void    _printOutData(unsigned short    *arg, int num, char* name);
+    void    _printOutData(VDset             *arg, int num, char* name);
+    void    _printOutData(double            *arg, int num, char* name);
+};
+#endif
\ No newline at end of file