Akifumi Takahashi / TRP105F_Spline
Committer:
aktk
Date:
Tue Feb 16 07:52:38 2016 +0000
Revision:
1:2053662b1167
Parent:
0:e85788b14028
Child:
2:40ae18445079
data list range [0,255]. message has been little changed.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
aktk 0:e85788b14028 1 /**
aktk 0:e85788b14028 2 * TRP105F_Spline.h,.cpp
aktk 0:e85788b14028 3 *
aktk 0:e85788b14028 4 * - This library is for provide a distance from TRP105F, proximity sensor,
aktk 0:e85788b14028 5 * to whatever reflect the flash.
aktk 0:e85788b14028 6 * - Deistance is derived from a voltage signal of TRP105F.
aktk 0:e85788b14028 7 * - An object of TRPFS class has an array of sets of
aktk 0:e85788b14028 8 * distance(16 bit-value) and voltage(16bit-value) at the distance.
aktk 0:e85788b14028 9 * - The range of distances that an array has in sets is [0:1024] by 1.
aktk 0:e85788b14028 10 * - an array is derived from a spline curve model.
aktk 0:e85788b14028 11 * - In order to derive spline curve, some value sets should be got
aktk 0:e85788b14028 12 * at the first calibration.
aktk 0:e85788b14028 13 *
aktk 0:e85788b14028 14 * LOG:
aktk 0:e85788b14028 15 * ver.1 2015/10/19 - 2015/10/22
aktk 0:e85788b14028 16 * ver.2 2015/10/22 -
aktk 0:e85788b14028 17 * Distance data type has become unsigned short from int.
aktk 0:e85788b14028 18 * Distance data range : [2:20] by 1 -> [0:1024] by 1.
aktk 0:e85788b14028 19 * ver.2.1 2016/02.12 -
aktk 1:2053662b1167 20 * Distance data range : [0:1024] -> [0:255].
aktk 0:e85788b14028 21 */
aktk 0:e85788b14028 22 #ifndef TRP105F_Spline_H
aktk 0:e85788b14028 23 #define TRP105F_Spline_H
aktk 0:e85788b14028 24
aktk 0:e85788b14028 25 #include "mbed.h"
aktk 0:e85788b14028 26
aktk 0:e85788b14028 27
aktk 0:e85788b14028 28 // Set of voltage-distance
aktk 0:e85788b14028 29 typedef struct {
aktk 0:e85788b14028 30 unsigned short vol; // voltage
aktk 0:e85788b14028 31 unsigned short dst; // distance
aktk 0:e85788b14028 32 } VDset;
aktk 0:e85788b14028 33
aktk 1:2053662b1167 34 // Type of modality to input data for calibration
aktk 0:e85788b14028 35 enum DataInType{
aktk 0:e85788b14028 36 KEYBORD, // set this if input data by 0-9 key
aktk 0:e85788b14028 37 SYSTEM // set this if any other input method, for instance, like GUI.
aktk 0:e85788b14028 38 } ;
aktk 0:e85788b14028 39
aktk 0:e85788b14028 40 //
aktk 0:e85788b14028 41 // TRP105FS Class for get distance from voltage
aktk 0:e85788b14028 42 /////////////////////////////////////////////////////////////////////////////////
aktk 1:2053662b1167 43 //// At calibration, at sampling data, first the class send '>' via serial com,
aktk 1:2053662b1167 44 //// after which You can send distance data [0:255](in ver2.2).
aktk 1:2053662b1167 45 //// Then the class measure the voltage data for 1 sec.
aktk 1:2053662b1167 46 //// Above procedure is looped for the number you input as 1st arg of the constructor.
aktk 0:e85788b14028 47 ////------------------------------------------
aktk 0:e85788b14028 48 //// (when TRP105FS object is made)
aktk 0:e85788b14028 49 //// > (< you can input distance data after this signal('>' <=> 0x3e)
aktk 1:2053662b1167 50 //// >1 (< distance data is limited in [0:255](in ver2.2) on integer.
aktk 1:2053662b1167 51 //// >14[CR or LF] (< you can continue to input unless input ERNTER([CR or LF]).
aktk 1:2053662b1167 52 //// ( But if you set [SYSTEM] on constructor, you can input it only once. (use this in GUI)
aktk 0:e85788b14028 53 //// >14 (< then voltage mesuring begins.
aktk 0:e85788b14028 54 //// (< after mesuring voltage, CR or LF signal is sent, which means tt is started a new line if console.
aktk 0:e85788b14028 55 //// > (< when you shoud input more data, ':'signal is sent again.
aktk 0:e85788b14028 56 ////////////////////////////////////////////////////////////////////////////////
aktk 0:e85788b14028 57 class TRP105FS
aktk 0:e85788b14028 58 {
aktk 0:e85788b14028 59 public:
aktk 1:2053662b1167 60 // Constraction
aktk 0:e85788b14028 61 TRP105FS();
aktk 0:e85788b14028 62 TRP105FS(unsigned int);
aktk 0:e85788b14028 63 TRP105FS(unsigned int arg_num, DataInType arg_dit);
aktk 1:2053662b1167 64 // Destraction
aktk 0:e85788b14028 65 ~TRP105FS();
aktk 1:2053662b1167 66 // Functions
aktk 0:e85788b14028 67 unsigned short getDistance(); // the fuction to get distance.
aktk 0:e85788b14028 68 void calibrateSensor();
aktk 0:e85788b14028 69 void saveSetting();
aktk 1:2053662b1167 70 void saveSetting(const char *filename);
aktk 0:e85788b14028 71 void loadSetting();
aktk 1:2053662b1167 72 void loadSetting(const char *filename);
aktk 0:e85788b14028 73 void printOutData();
aktk 0:e85788b14028 74 void printThresholds();
aktk 0:e85788b14028 75
aktk 0:e85788b14028 76 private:
aktk 1:2053662b1167 77 //
aktk 1:2053662b1167 78 // Defining Constants
aktk 1:2053662b1167 79 //
aktk 0:e85788b14028 80 enum _SetConstant {
aktk 0:e85788b14028 81 _LIDX = 0,
aktk 1:2053662b1167 82 _RIDX = 255,
aktk 0:e85788b14028 83 _ENUM = _RIDX - _LIDX + 1
aktk 0:e85788b14028 84 };
aktk 1:2053662b1167 85 //
aktk 1:2053662b1167 86 // Variables
aktk 1:2053662b1167 87 //
aktk 0:e85788b14028 88 int _Sample_Num; // the number of samples for derive spline
aktk 0:e85788b14028 89 VDset* _Sample_Set;
aktk 0:e85788b14028 90 VDset _Set[_ENUM];
aktk 0:e85788b14028 91 unsigned short _Threshold[_ENUM]; //_Threshold[18] is not used virtually.
aktk 0:e85788b14028 92 DataInType _Data_Input_Type;
aktk 0:e85788b14028 93 double* _u_spline;
aktk 0:e85788b14028 94 //
aktk 0:e85788b14028 95 // For calibration
aktk 0:e85788b14028 96 //
aktk 0:e85788b14028 97 void _sampleData();
aktk 0:e85788b14028 98 void _makeSpline(); // Cubic spline
aktk 0:e85788b14028 99 unsigned short _getSplineYof(double);
aktk 0:e85788b14028 100 //
aktk 0:e85788b14028 101 // For get distance
aktk 0:e85788b14028 102 //
aktk 0:e85788b14028 103 int _getNearest(int, int, unsigned short);
aktk 0:e85788b14028 104 //
aktk 1:2053662b1167 105 // For debug
aktk 1:2053662b1167 106 //
aktk 0:e85788b14028 107 void _printOutData(unsigned short *arg, int num, char* name);
aktk 0:e85788b14028 108 void _printOutData(VDset *arg, int num, char* name);
aktk 0:e85788b14028 109 void _printOutData(double *arg, int num, char* name);
aktk 0:e85788b14028 110 };
aktk 0:e85788b14028 111 #endif