Kenta Tanabe / TRP105F_Spline_for_child

Fork of TRP105F_Spline by Akifumi Takahashi

Revision:
3:b56e933bebc2
Parent:
1:2053662b1167
Child:
4:701f958d137a
--- a/TRP105F_Spline.cpp	Tue Feb 16 11:19:39 2016 +0000
+++ b/TRP105F_Spline.cpp	Wed Jun 01 05:38:46 2016 +0000
@@ -1,8 +1,11 @@
 #define DEBUG
 #include "TRP105F_Spline.h"
 
-//  To get voltage of TRP105F
-AnalogIn g_Sensor_Voltage(p16);
+//  To get ytage of TRP105F
+AnalogIn* g_Sensor_Voltage;
+//  To get ytage of TRP105F with spi
+//SPI spi(p5, p6, p7); // mosi(out), miso(in), sclk(clock)
+//DigitalOut cs(p8); // cs (the chip select signal)
 //  To get sample distance via seral com
 Serial g_Serial_Signal(USBTX, USBRX);
 
@@ -15,74 +18,97 @@
 DigitalOut led4(LED4);
 #endif
 
+//  Constructor
 TRP105FS::TRP105FS()
-    :_Data_Input_Type(SYSTEM)
+    :_useType(AsMODULE)
 {
     _Sample_Num = 5;
     _Sample_Set = (VDset *)malloc(_Sample_Num * sizeof(VDset));
     _u_spline   = (double*)malloc(_Sample_Num * sizeof(double));
-
-    //calibrateSensor();
+    g_Sensor_Voltage = new AnalogIn(p16);
 }
 
 TRP105FS::TRP105FS(
     unsigned int arg_num
 )
-    :_Data_Input_Type(SYSTEM)
+    :_useType(AsMODULE)
+{
+    if(arg_num > _ENUM) _Sample_Num = _ENUM;
+    else _Sample_Num = arg_num;
+
+    _Sample_Set = (VDset *)malloc(_Sample_Num * sizeof(VDset));
+    _u_spline   = (double*)malloc(_Sample_Num * sizeof(double));
+    g_Sensor_Voltage = new AnalogIn(p16);
+}
+
+TRP105FS::TRP105FS(
+    unsigned int arg_num,
+    UseType arg_type
+)
+    :_useType(arg_type)
 {
     if(arg_num > _ENUM) _Sample_Num = _ENUM;
     else _Sample_Num = arg_num;
 
     _Sample_Set = (VDset *)malloc(_Sample_Num * sizeof(VDset));
     _u_spline   = (double*)malloc(_Sample_Num * sizeof(double));
-
-    //calibrateSensor();
+    g_Sensor_Voltage = new AnalogIn(p16);
 }
 
 TRP105FS::TRP105FS(
     unsigned int arg_num,
-    DataInType arg_dit
+    UseType arg_type,
+    PinName pin
 )
-    :_Data_Input_Type(arg_dit)
+    :_useType(arg_type)
 {
     if(arg_num > _ENUM) _Sample_Num = _ENUM;
     else _Sample_Num = arg_num;
 
     _Sample_Set = (VDset *)malloc(_Sample_Num * sizeof(VDset));
     _u_spline   = (double*)malloc(_Sample_Num * sizeof(double));
-
-    //calibrateSensor();
+    g_Sensor_Voltage = new AnalogIn(pin);
 }
 
+//  Destructor
 TRP105FS::~TRP105FS()
 {
     free(_Sample_Set);
     free(_u_spline);
 }
 
-unsigned short TRP105FS::getDistance()
+
+unsigned short TRP105FS::getX(unsigned short arg_y)
 {
     int idx;
     unsigned short pv = 0;
 
-    //  low-pass filter
-    for(int i = 0; i < 10; i++)
-        pv += g_Sensor_Voltage.read_u16() / 10;
+    pv = arg_y;
 
     idx = _getNearest(_LIDX, _RIDX, pv);
 
     if (idx != 0xFFFF)    //  unless occuring error
-        return _Set[idx].dst;
+        return _Set[idx].x;
     else
         return 0xFFFF;
 }
 
+unsigned short TRP105FS::getDistance(unsigned short arg_y)
+{
+    return getX(arg_y);
+}
+
+unsigned short TRP105FS::getDistance()
+{
+    return getX(g_Sensor_Voltage->read_u16());
+}
+
 /*
-    Function to find a set whose vol member is nearest a voltage from the sensor, recursively.
+    Function to find a set whose y member is nearest a ytage from the sensor, recursively.
 
                    SHORT                                                          LONG
     +------------>  HIGH[lidx , ... , cidx , threshold[cidx], cidx+1 , ... , ridx]LOW <-----------+
-    |(if voltage form sensor < threshold[cidx])   |||   (if threshold[cidx] < voltage form sensor)|
+    |(if ytage form sensor < threshold[cidx])   |||   (if threshold[cidx] < ytage form sensor)|
     |               HIGH[lidx , ... , cidx]LOW    |||    HIGH[cidx+1 , ... , ridx]LOW             |
     |                |                                                            |               |
     +----------------+                                                            +---------------+
@@ -90,7 +116,7 @@
 int TRP105FS::_getNearest(
     int arg_lidx,
     int arg_ridx,
-    unsigned short arg_vol
+    unsigned short arg_y
 )
 {
     int cidx = (arg_lidx + arg_ridx) / 2;
@@ -98,43 +124,117 @@
     //  When the number of element to compare is only one, return it as result.
     if(arg_lidx == arg_ridx)
         return cidx;
-    //  If the voltage from the sensor is lower than the center threshold
+    //  If the ytage from the sensor is lower than the center threshold
     //  (_set[cidx] > _threshold[cidx] > _set[cidx+1])
-    else if(arg_vol > _Threshold[cidx])
-        return _getNearest(arg_lidx, cidx,     arg_vol);
-    //  If the voltage from the sensor is higher than the center threshold
-    else if(arg_vol < _Threshold[cidx])
-        return _getNearest(cidx + 1, arg_ridx, arg_vol);
-    //  If the voltage from the sensor eauals the center threshold
-    else //(arg_vol == _Treshold[cidx].vol)
+    else if(arg_y > _Threshold[cidx])
+        return _getNearest(arg_lidx, cidx,     arg_y);
+    //  If the ytage from the sensor is higher than the center threshold
+    else if(arg_y < _Threshold[cidx])
+        return _getNearest(cidx + 1, arg_ridx, arg_y);
+    //  If the ytage from the sensor eauals the center threshold
+    else //(arg_y == _Treshold[cidx].y)
         return cidx;
 }
 
+void TRP105FS::setSample(unsigned short arg_x, unsigned short arg_y){
+    _setSample(unsigned short arg_x, unsigned short arg_y);
+}
+
+void TRP105FS::_setSample(unsigned short arg_x, unsigned short arg_y)
+{
+    static unsigned int snum = 0;
+    unsigned int num;
+    int     tmp;
+    VDset tmp_set[_ENUM];   // for bucket sort
+
+    // Increment it if call this function.
+    snum++;
+
+    //  fit to smaller
+    if ( _Sample_Num < snum) {
+        num = _Sample_Num;
+    } else {
+        //  To reclloc memories if snum is bigger than _Sample_Num.
+        //  When realloc is failed, snum is back to porevius.
+        VDset*  tmp_Set = (VDset *)realloc(_Sample_Set, snum * sizeof(VDset));
+        double* tmp__u_ = (double*)realloc(_u_spline,   snum * sizeof(double));
+        if (tmp_set != NULL && tmp__u_ != NULL) {
+            _Sample_Set = tmp_Set;
+            _u_spline   = tmp__u_;
+            num = _Sample_Num = snum;
+        } else {
+            snum--;
+            num = snum = _Sample_Num ;
+        }
+    }
+
+    _Sample_Set[num - 1].x = arg_x;
+    _Sample_Set[num - 1].y = arg_y;
+    if((unsigned short)_RIDX < _Sample_Set[num - 1].x)_Sample_Set[num - 1].x = (unsigned short)_RIDX;
+
+    //
+    //  Sort set data array in distanceAscending order
+    //
+    //  Bucket sort
+    for(int i = 0; i < _ENUM; i++)
+        tmp_set[i].x = 0xaaaa;
+    tmp = 0;
+    for(int i = 0; i < _Sample_Num; i++) {
+        //  use x as index for x range [_LIDX,_RIDX]
+        if (tmp_set[_Sample_Set[i].x].x == 0xaaaa) {
+            tmp_set[_Sample_Set[i].x].x = _Sample_Set[i].x;
+            tmp_set[_Sample_Set[i].x].y = _Sample_Set[i].y;
+        } else { // if a same x has been input, calcurate mean.
+            tmp_set[_Sample_Set[i].x].y += _Sample_Set[i].y;
+            tmp_set[_Sample_Set[i].x].y /= 2;
+            tmp++;
+        }
+    }
+#ifdef DEBUG
+    g_Serial_Signal.printf("  _Sample_num: %d\n", _Sample_Num );
+    g_Serial_Signal.printf("-)        tmp: %d\n", tmp );
+#endif
+    //  substruct tmp from number of sample.
+    _Sample_Num -= tmp;
+#ifdef DEBUG
+    g_Serial_Signal.printf("-----------------\n");
+    g_Serial_Signal.printf("  _Sample_num: %d\n", _Sample_Num );
+#endif
+    //  apply sort on _Sample_Set
+    tmp = 0;
+    for(int i = 0; i < _ENUM; i++) {
+        if(tmp_set[i].x != 0xaaaa) {
+            _Sample_Set[i - tmp].x = tmp_set[i].x;
+            _Sample_Set[i - tmp].y = tmp_set[i].y;
+        } else //  if no data, skip it
+            tmp++;
+    }
+}
 void TRP105FS::_sampleData()
 {
     int     tmp;
     char    sig;
-    unsigned short tmp_vol;
+    unsigned short tmp_y;
     VDset tmp_set[_ENUM];   // for bucket sort
 
-    //  For evry set, 
-    //  1, get dst data via serai com,
-    //  2, get vol data,
+    //  For evry set,
+    //  1, get x data via serai com,
+    //  2, get y data,
     //  and then do same for next index set.
     for(int i = 0; i < _Sample_Num; i++) {
         //
         //  Recieve a Distance datus and store it into member
         //
-        if(_Data_Input_Type == KEYBORD) {
+        if(_useType == AsDEBUG) {
             g_Serial_Signal.putc('>');
-            _Sample_Set[i].dst = 0;
+            _Sample_Set[i].x = 0;
             do {
                 sig = g_Serial_Signal.getc();
                 if('0' <= sig && sig <= '9') {
-                    _Sample_Set[i].dst = 10 * _Sample_Set[i].dst + sig - 48;
+                    _Sample_Set[i].x = 10 * _Sample_Set[i].x + sig - 48;
                     g_Serial_Signal.putc(char(sig));
                 } else if(sig == 0x08) {
-                    _Sample_Set[i].dst = 0;
+                    _Sample_Set[i].x = 0;
                     g_Serial_Signal.printf("[canseled!]");
                     g_Serial_Signal.putc('\n');
                     g_Serial_Signal.putc('>');
@@ -142,14 +242,14 @@
             } while (!(sig == 0x0a || sig == 0x0d));
             g_Serial_Signal.putc('\n');
         } else { //_Data_Input_Type == SYSTEM
-            _Sample_Set[i].dst = g_Serial_Signal.getc();
+            _Sample_Set[i].x = g_Serial_Signal.getc();
         }
 
         //  if input data is over the bound calibrate it below
-        if (_Sample_Set[i].dst < 0)
-            _Sample_Set[i].dst = 0;
-        else if (_ENUM < _Sample_Set[i].dst)
-            _Sample_Set[i].dst = _ENUM;
+        if (_Sample_Set[i].x < (unsigned short)_LIDX)
+            _Sample_Set[i].x = (unsigned short)_LIDX;
+        else if ((unsigned short)_RIDX < _Sample_Set[i].x)
+            _Sample_Set[i].x = (unsigned short)_RIDX;
         //
         //  Recieve a Voltage datus and store it into member
         //
@@ -157,19 +257,20 @@
         //  Get 10 data and store mean as a sample.
         //  After get one original sample, system waits for 0.1 sec,
         //  thus it takes 1 sec evry sampling.
-        _Sample_Set[i].vol = 0;
+        _Sample_Set[i].y = 0;
         for(int j = 0; j < 10; j++) {
             //unsigned short 's range [0 , 65535]
-            //the Number of significant figures of read voltage is 3 or 4.
-            tmp_vol = g_Sensor_Voltage.read_u16();
+            //the Number of significant figures of read ytage is 3 or 4.
+            tmp_y = g_Sensor_Voltage->read_u16();
+
 #ifdef DEBUG
-            g_Serial_Signal.printf("%d,",tmp_vol);
+            g_Serial_Signal.printf("%d,",tmp_y);
 #endif
-            _Sample_Set[i].vol += (tmp_vol / 10);
+            _Sample_Set[i].y += (tmp_y / 10);
             wait(0.1);
         }
 #ifdef DEBUG
-        g_Serial_Signal.printf("(%d)\n",_Sample_Set[i].vol);
+        g_Serial_Signal.printf("(%d)\n",_Sample_Set[i].y);
 #endif
     }
     //
@@ -177,16 +278,16 @@
     //
     //  Bucket sort
     for(int i = 0; i < _ENUM; i++)
-        tmp_set[i].dst = 0xaaaa;
+        tmp_set[i].x = 0xaaaa;
     tmp = 0;
     for(int i = 0; i < _Sample_Num; i++) {
-        //  use dst as index for dst range [2,20]
-        if (tmp_set[_Sample_Set[i].dst].dst == 0xaaaa) {
-            tmp_set[_Sample_Set[i].dst].dst = _Sample_Set[i].dst;
-            tmp_set[_Sample_Set[i].dst].vol = _Sample_Set[i].vol;
-        } else { // if a same dst has been input, calcurate mean.
-            tmp_set[_Sample_Set[i].dst].vol += _Sample_Set[i].vol;
-            tmp_set[_Sample_Set[i].dst].vol /= 2;
+        //  use x as index for x range [LIDX,RIDX]
+        if (tmp_set[_Sample_Set[i].x].x == 0xaaaa) {
+            tmp_set[_Sample_Set[i].x].x = _Sample_Set[i].x;
+            tmp_set[_Sample_Set[i].x].y = _Sample_Set[i].y;
+        } else { // if a same x has been input, calcurate mean.
+            tmp_set[_Sample_Set[i].x].y += _Sample_Set[i].y;
+            tmp_set[_Sample_Set[i].x].y /= 2;
             tmp++;
         }
     }
@@ -202,9 +303,9 @@
     //  apply sort on _Sample_Set
     tmp = 0;
     for(int i = 0; i < _ENUM; i++) {
-        if(tmp_set[i].dst != 0xaaaa) {
-            _Sample_Set[i - tmp].dst = tmp_set[i].dst;
-            _Sample_Set[i - tmp].vol = tmp_set[i].vol;
+        if(tmp_set[i].x != 0xaaaa) {
+            _Sample_Set[i - tmp].x = tmp_set[i].x;
+            _Sample_Set[i - tmp].y = tmp_set[i].y;
         } else //  if no data, skip it
             tmp++;
     }
@@ -215,8 +316,8 @@
 //
 void TRP105FS::_makeSpline()
 {
-    //  x: dst, distance
-    //  y: vol, voltage
+    //  x: x, distance
+    //  y: y, ytage
     //
     //  N: max of index <=> (_Sample_Num - 1)
     //
@@ -258,16 +359,16 @@
     _printOutData(_Sample_Set, _Sample_Num, "\nSampleSet");
 #endif
     for(int i = 0; i < _Sample_Num - 1; i++)
-        h[i] =  (double)(_Sample_Set[i + 1].dst - _Sample_Set[i].dst);
-    //(unsigned short)(_Sample_Set[i + 1].dst - _Sample_Set[i].dst);
+        h[i] =  (double)(_Sample_Set[i + 1].x - _Sample_Set[i].x);
+    //(unsigned short)(_Sample_Set[i + 1].x - _Sample_Set[i].x);
 
     for(int i = 0; i < _Sample_Num - 2; i++)
         v[i] = 6 * (
-                   ((double)(_Sample_Set[i + 2].vol - _Sample_Set[i + 1].vol)) / h[i + 1]
-                   //(unsigned short)(_Sample_Set[i + 2].vol - _Sample_Set[i + 1].vol) / h[i + 1]
+                   ((double)(_Sample_Set[i + 2].y - _Sample_Set[i + 1].y)) / h[i + 1]
+                   //(unsigned short)(_Sample_Set[i + 2].y - _Sample_Set[i + 1].y) / h[i + 1]
                    -
-                   ((double)(_Sample_Set[i + 1].vol - _Sample_Set[i].vol))     / h[i]
-                   //(unsigned short)(_Sample_Set[i + 1].vol - _Sample_Set[i].vol) / h[i]
+                   ((double)(_Sample_Set[i + 1].y - _Sample_Set[i].y))     / h[i]
+                   //(unsigned short)(_Sample_Set[i + 1].y - _Sample_Set[i].y) / h[i]
                );
 
     //
@@ -322,13 +423,13 @@
     double arg_x       //  the argument is supposed as distance [mm]
 )
 {
-    double y;       //  voltage calculated by spline polynomial
+    double y;       //  ytage calculated by spline polynomial
     double a,b,c,d; //  which is specific constant of spline, and can be expressed with _u.
     int itv = 0;    //  interval(section) of interpolation
     //  the number of interval is less 1 than the number of sample sets,
     //  which means the max number of interval is _Sample_num - 2.
-    if((double)(_Sample_Set[0].dst) <= arg_x) {
-        while (!((double)(_Sample_Set[itv].dst) <= arg_x && arg_x < (double)(_Sample_Set[itv + 1].dst))) {
+    if((double)(_Sample_Set[0].x) <= arg_x) {
+        while (!((double)(_Sample_Set[itv].x) <= arg_x && arg_x < (double)(_Sample_Set[itv + 1].x))) {
             itv++;
             if(itv > _Sample_Num - 2) {
                 itv = _Sample_Num - 2;
@@ -336,18 +437,18 @@
             }
         }
     }
-    a = (double)(_u_spline[itv + 1] - _u_spline[itv]) / 6.0 / (double)(_Sample_Set[itv + 1].dst - _Sample_Set[itv].dst);
+    a = (double)(_u_spline[itv + 1] - _u_spline[itv]) / 6.0 / (double)(_Sample_Set[itv + 1].x - _Sample_Set[itv].x);
     b = (double)(_u_spline[itv]) / 2.0;
-    c = (double)(_Sample_Set[itv + 1].vol - _Sample_Set[itv].vol) / (double)(_Sample_Set[itv + 1].dst - _Sample_Set[itv].dst)
+    c = (double)(_Sample_Set[itv + 1].y - _Sample_Set[itv].y) / (double)(_Sample_Set[itv + 1].x - _Sample_Set[itv].x)
         -
-        (double)(_Sample_Set[itv + 1].dst - _Sample_Set[itv].dst) * (double)(_u_spline[itv + 1] + 2.0 * _u_spline[itv]) / 6.0;
-    d = (double)(_Sample_Set[itv].vol);
+        (double)(_Sample_Set[itv + 1].x - _Sample_Set[itv].x) * (double)(_u_spline[itv + 1] + 2.0 * _u_spline[itv]) / 6.0;
+    d = (double)(_Sample_Set[itv].y);
     //  cubic spline expression
-    y = a * (arg_x - (double)(_Sample_Set[itv].dst)) * (arg_x - (double)(_Sample_Set[itv].dst)) * (arg_x - (double)(_Sample_Set[itv].dst))
+    y = a * (arg_x - (double)(_Sample_Set[itv].x)) * (arg_x - (double)(_Sample_Set[itv].x)) * (arg_x - (double)(_Sample_Set[itv].x))
         +
-        b * (arg_x - (double)(_Sample_Set[itv].dst)) * (arg_x - (double)(_Sample_Set[itv].dst))
+        b * (arg_x - (double)(_Sample_Set[itv].x)) * (arg_x - (double)(_Sample_Set[itv].x))
         +
-        c * (arg_x - (double)(_Sample_Set[itv].dst))
+        c * (arg_x - (double)(_Sample_Set[itv].x))
         +
         d;
 
@@ -366,9 +467,23 @@
     _makeSpline();
 
     for(int i = 0; i < _ENUM; i++) {
-        _Set[i].dst     = i;
-        _Set[i].vol     = _getSplineYof((double)(_Set[i].dst));
-        _Threshold[i]   = _getSplineYof((double)(_Set[i].dst) + 0.5);
+        _Set[i].x     = i;
+        _Set[i].x     = _getSplineYof((double)(_Set[i].x));
+        _Threshold[i]   = _getSplineYof((double)(_Set[i].x) + 0.5);
+#ifdef DEBUG2
+        g_Serial_Signal.printf("(get...threashold:%d)\n", _Threshold[i]);
+#endif
+    }
+}
+
+void TRP105FS::calibrate()
+{
+    _makeSpline();
+
+    for(int i = 0; i < _ENUM; i++) {
+        _Set[i].x     = i;
+        _Set[i].x     = _getSplineYof((double)(_Set[i].x));
+        _Threshold[i]   = _getSplineYof((double)(_Set[i].x) + 0.5);
 #ifdef DEBUG2
         g_Serial_Signal.printf("(get...threashold:%d)\n", _Threshold[i]);
 #endif
@@ -382,9 +497,9 @@
     fp = fopen("/local/savedata.log", "wb");
 
     for(int i = 0; i < _ENUM; i++) {
-        fwrite(&_Set[i].dst,    sizeof(unsigned short), 1, fp);
+        fwrite(&_Set[i].x,    sizeof(unsigned short), 1, fp);
         fputc(0x2c, fp);
-        fwrite(&_Set[i].vol,    sizeof(unsigned short), 1, fp);
+        fwrite(&_Set[i].y,    sizeof(unsigned short), 1, fp);
         fputc(0x2c, fp);
         fwrite(&_Threshold[i],  sizeof(unsigned short), 1, fp);
         fputc(0x3b, fp);
@@ -392,9 +507,9 @@
     fwrite(&_Sample_Num, sizeof(int), 1, fp);
     fputc(0x3b, fp);
     for(int i = 0; i < _Sample_Num; i++) {
-        fwrite(&_Sample_Set[i].dst,    sizeof(unsigned short), 1, fp);
+        fwrite(&_Sample_Set[i].x,    sizeof(unsigned short), 1, fp);
         fputc(0x2c, fp);
-        fwrite(&_Sample_Set[i].vol,    sizeof(unsigned short), 1, fp);
+        fwrite(&_Sample_Set[i].y,    sizeof(unsigned short), 1, fp);
         fputc(0x3b, fp);
     }
     fclose(fp);
@@ -416,16 +531,16 @@
     fp = fopen("/local/savedata.log", "rb");
     for(int i = 0; i < _ENUM; i++) {
 
-        fread(&_Set[i].dst,     sizeof(unsigned short), 1, fp);
+        fread(&_Set[i].x,     sizeof(unsigned short), 1, fp);
         fread(&tmp,             sizeof(char),           1, fp);
 #ifdef DEBUG2
-        g_Serial_Signal.printf("%d%c",  _Set[i].dst, tmp);
+        g_Serial_Signal.printf("%d%c",  _Set[i].x, tmp);
 #endif
 
-        fread(&_Set[i].vol,     sizeof(unsigned short), 1, fp);
+        fread(&_Set[i].y,     sizeof(unsigned short), 1, fp);
         fread(&tmp,             sizeof(char), 1, fp);
 #ifdef DEBUG2
-        g_Serial_Signal.printf("%d%c",  _Set[i].vol, tmp);
+        g_Serial_Signal.printf("%d%c",  _Set[i].y, tmp);
 #endif
 
         fread(&_Threshold[i],   sizeof(unsigned short), 1, fp);
@@ -439,9 +554,9 @@
     fread(&tmp,         sizeof(char), 1, fp);
 
     for(int i = 0; i < _Sample_Num; i++) {
-        fread(&_Sample_Set[i].dst, sizeof(unsigned short), 1, fp);
+        fread(&_Sample_Set[i].x, sizeof(unsigned short), 1, fp);
         fread(&tmp, sizeof(char),1,fp);
-        fread(&_Sample_Set[i].vol, sizeof(unsigned short), 1, fp);
+        fread(&_Sample_Set[i].y, sizeof(unsigned short), 1, fp);
         fread(&tmp, sizeof(char),1,fp);
     }
     fclose(fp);
@@ -463,9 +578,9 @@
     fp = fopen(filepath, "wb");
 
     for(int i = 0; i < _ENUM; i++) {
-        fwrite(&_Set[i].dst,    sizeof(unsigned short), 1, fp);
+        fwrite(&_Set[i].x,    sizeof(unsigned short), 1, fp);
         fputc(0x2c, fp);
-        fwrite(&_Set[i].vol,    sizeof(unsigned short), 1, fp);
+        fwrite(&_Set[i].y,    sizeof(unsigned short), 1, fp);
         fputc(0x2c, fp);
         fwrite(&_Threshold[i],  sizeof(unsigned short), 1, fp);
         fputc(0x3b, fp);
@@ -473,9 +588,9 @@
     fwrite(&_Sample_Num, sizeof(int), 1, fp);
     fputc(0x3b, fp);
     for(int i = 0; i < _Sample_Num; i++) {
-        fwrite(&_Sample_Set[i].dst,    sizeof(unsigned short), 1, fp);
+        fwrite(&_Sample_Set[i].x,    sizeof(unsigned short), 1, fp);
         fputc(0x2c, fp);
-        fwrite(&_Sample_Set[i].vol,    sizeof(unsigned short), 1, fp);
+        fwrite(&_Sample_Set[i].y,    sizeof(unsigned short), 1, fp);
         fputc(0x3b, fp);
     }
     fclose(fp);
@@ -498,16 +613,16 @@
     fp = fopen(filepath, "rb");
     for(int i = 0; i < _ENUM; i++) {
 
-        fread(&_Set[i].dst,     sizeof(unsigned short), 1, fp);
+        fread(&_Set[i].x,     sizeof(unsigned short), 1, fp);
         fread(&tmp,             sizeof(char), 1, fp);
 #ifdef DEBUG3
-        g_Serial_Signal.printf("%d%c",  _Set[i].dst, tmp);
+        g_Serial_Signal.printf("%d%c",  _Set[i].x, tmp);
 #endif
 
-        fread(&_Set[i].vol,     sizeof(unsigned short), 1, fp);
+        fread(&_Set[i].y,     sizeof(unsigned short), 1, fp);
         fread(&tmp,             sizeof(char), 1, fp);
 #ifdef DEBUG3
-        g_Serial_Signal.printf("%d%c",  _Set[i].vol, tmp);
+        g_Serial_Signal.printf("%d%c",  _Set[i].y, tmp);
 #endif
 
         fread(&_Threshold[i],   sizeof(unsigned short), 1, fp);
@@ -524,16 +639,16 @@
 #endif
 
     for(int i = 0; i < _Sample_Num; i++) {
-        fread(&_Sample_Set[i].dst,  sizeof(unsigned short), 1, fp);
+        fread(&_Sample_Set[i].x,  sizeof(unsigned short), 1, fp);
         fread(&tmp,                 sizeof(char),1,fp);
 #ifdef DEBUG3
-        g_Serial_Signal.printf("%d%c",  _Sample_Set[i].dst, tmp);
+        g_Serial_Signal.printf("%d%c",  _Sample_Set[i].x, tmp);
 #endif
 
-        fread(&_Sample_Set[i].vol,  sizeof(unsigned short), 1, fp);
+        fread(&_Sample_Set[i].y,  sizeof(unsigned short), 1, fp);
         fread(&tmp,                 sizeof(char),1,fp);
 #ifdef DEBUG3
-        g_Serial_Signal.printf("%d%c",  _Sample_Set[i].vol, tmp);
+        g_Serial_Signal.printf("%d%c",  _Sample_Set[i].y, tmp);
 #endif
     }
     fclose(fp);
@@ -545,13 +660,13 @@
     FILE *fp;
 
     fp = fopen("/local/log.txt", "w");  // open file in writing mode
-    fprintf(fp, "dst, vol,(threshold)\n");
+    fprintf(fp, "x, y,(threshold)\n");
     for(int i = 0; i < _ENUM; i++) {
-        fprintf(fp, "%d,%d,(%d)\n", _Set[i].dst, _Set[i].vol, _Threshold[i]);
+        fprintf(fp, "%d,%d,(%d)\n", _Set[i].x, _Set[i].y, _Threshold[i]);
     }
-    fprintf(fp, "\nSample:dst, vol\n");
+    fprintf(fp, "\nSample:x, y\n");
     for(int i = 0; i < _Sample_Num; i++) {
-        fprintf(fp, "%d,%d\n", _Sample_Set[i].dst, _Sample_Set[i].vol);
+        fprintf(fp, "%d,%d\n", _Sample_Set[i].x, _Sample_Set[i].y);
     }
     fclose(fp);
 
@@ -586,7 +701,7 @@
     fp = fopen("/local/varlog.txt", "a");  // open file in add mode
     fprintf(fp, "%10s\n", name);
     for(int i = 0; i < num; i++) {
-        fprintf(fp, "%d, ", arg[i].vol);
+        fprintf(fp, "%d, ", arg[i].y);
     }
     fprintf(fp, "\n");
     fclose(fp);