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.
Diff: TRP105F_Spline.h
- Revision:
- 3:b56e933bebc2
- Parent:
- 2:40ae18445079
- Child:
- 4:701f958d137a
--- a/TRP105F_Spline.h Tue Feb 16 11:19:39 2016 +0000 +++ b/TRP105F_Spline.h Wed Jun 01 05:38:46 2016 +0000 @@ -28,48 +28,44 @@ #include "mbed.h" +// For SPI +//int DAread(int channel); + // Set of voltage-distance typedef struct { - unsigned short vol; // voltage - unsigned short dst; // distance + unsigned short x; // distance + unsigned short y; // voltage } VDset; // Type of modality to input data for calibration -enum DataInType{ - KEYBORD, // set this if input data by 0-9 key - SYSTEM // set this if any other input method, for instance, like GUI. +enum UseType { + AsDEBUG, + AsMODULE } ; // // TRP105FS Class for get distance from voltage // -///////////////////////////////////////////////////////////////////////////////// -//// At calibration, at sampling data, first the class send '>' via serial com, -//// after which You can send distance data [0:255](in ver2.2). -//// Then the class measure the voltage data for 1 sec. -//// Above procedure is looped for the number you input as 1st arg of the constructor. -////------------------------------------------ -//// (when TRP105FS object is made) -//// > (< you can input distance data after this signal('>' <=> 0x3e) -//// >1 (< distance data is limited in [0:255](in ver2.2) on integer. -//// >14[CR or LF] (< you can continue to input unless input ERNTER([CR or LF]). -//// ( 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: // Constraction TRP105FS(); TRP105FS(unsigned int); - TRP105FS(unsigned int arg_num, DataInType arg_dit); + TRP105FS(unsigned int, UseType); + TRP105FS(unsigned int, UseType, PinName); + //TRP105FS(unsigned int arg_num, DataInType arg_dit, unsigned int channel); // Destraction ~TRP105FS(); // Functions - unsigned short getDistance(); // the fuction to get distance. + unsigned short getDistance(unsigned short); // alias of getX + unsigned short getDistance(); // get voltage from PinName and getX() + unsigned short getX(unsigned short); // the fuction to get distance. + unsigned short getY(unsigned short); void calibrateSensor(); + //void calibrateSensor(VDset* arg_set, unsigned int arg_num); + void calibrate(); + void setSample(unsigned short,unsigned short); void saveSetting(); void saveSetting(const char *filename); void loadSetting(); @@ -89,18 +85,24 @@ // // Variables // - 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; + UseType _useType; + unsigned 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. + double* _u_spline; + // + // Variable for spi + // + //unsigned int _channel; // // For calibration // void _sampleData(); + void _setSample(unsigned short,unsigned short); + void _setSamples(VDset* arg_set, unsigned int arg_num); + unsigned short _getSplineYof(double arg_x); void _makeSpline(); // Cubic spline - unsigned short _getSplineYof(double); // // For get distance //