This lib is supposed to be used as a sensor's calibration or control program. This makes Cubic Spline Model from some sample plots(sets of (value, voltage)), and then discretize the model (dividing the range of voltage into some steps) in order to use the calibrated model data without getting the INVERSE function.
TRP105F_Spline.h
- Committer:
- aktk
- Date:
- 2016-02-12
- Revision:
- 0:e85788b14028
- Child:
- 1:2053662b1167
File content as of revision 0:e85788b14028:
/** * TRP105F_Spline.h,.cpp * * - This library is for provide a distance from TRP105F, proximity sensor, * to whatever reflect the flash. * - Deistance is derived from a voltage signal of TRP105F. * - An object of TRPFS class has an array of sets of * distance(16 bit-value) and voltage(16bit-value) at the distance. * - The range of distances that an array has in sets is [0:1024] by 1. * - an array is derived from a spline curve model. * - In order to derive spline curve, some value sets should be got * at the first calibration. * * LOG: * ver.1 2015/10/19 - 2015/10/22 * ver.2 2015/10/22 - * Distance data type has become unsigned short from int. * Distance data range : [2:20] by 1 -> [0:1024] by 1. * ver.2.1 2016/02.12 - * Distance data range : [0:1024] -> [0:256]. */ #ifndef TRP105F_Spline_H #define TRP105F_Spline_H #include "mbed.h" // Set of voltage-distance typedef struct { unsigned short vol; // voltage unsigned short dst; // distance } VDset; // Type of modality to input data enum DataInType{ KEYBORD, // set this if input data by 0-9 key SYSTEM // set this if any other input method, for instance, like GUI. } ; // // TRP105FS Class for get distance from voltage ///////////////////////////////////////////////////////////////////////////////// //// At calibration, at sampling data, first the class send '>' via seral com, //// after which You can send distancedata [2,20][mm]. Then the class measure //// the voltage data for 1 sec. //// Above procedure is looped for the number you input in the constructor. ////------------------------------------------ //// (when TRP105FS object is made) //// > (< you can input distance data after this signal('>' <=> 0x3e) //// >1 (< in this version, distance data is limited[2,20] integer. //// >14[CR or LF] (< you can continue to input unless input ERNTER. But if you set [SYSTEM] on constructor you can input it only once. (use this in GUI) //// >14 (< then voltage mesuring begins. //// (< after mesuring voltage, CR or LF signal is sent, which means tt is started a new line if console. //// > (< when you shoud input more data, ':'signal is sent again. //////////////////////////////////////////////////////////////////////////////// class TRP105FS { public: TRP105FS(); TRP105FS(unsigned int); TRP105FS(unsigned int arg_num, DataInType arg_dit); ~TRP105FS(); unsigned short getDistance(); // the fuction to get distance. void calibrateSensor(); void saveSetting(); void saveSetting(const char *filename);//not usable yet void loadSetting(); void loadSetting(const char *filename);//not usable yet void printOutData(); void printThresholds(); private: enum _SetConstant { _LIDX = 0, _RIDX = 1024, _ENUM = _RIDX - _LIDX + 1 }; int _Sample_Num; // the number of samples for derive spline VDset* _Sample_Set; VDset _Set[_ENUM]; unsigned short _Threshold[_ENUM]; //_Threshold[18] is not used virtually. DataInType _Data_Input_Type; double* _u_spline; // // 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