Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed-dsp mbed capstone_display_2
Revision 11:8c3b4995b05d, committed 2014-04-25
- Comitter:
- ryanyuyu
- Date:
- Fri Apr 25 03:09:18 2014 +0000
- Parent:
- 10:ab4209a25811
- Commit message:
- Final (For sure)
Changed in this revision
| capstone_display.lib | Show annotated file Show diff for this revision Revisions of this file |
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/capstone_display.lib Fri Apr 25 02:03:04 2014 +0000 +++ b/capstone_display.lib Fri Apr 25 03:09:18 2014 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/ryanyuyu/code/capstone_display_2/#057f9952189b +http://mbed.org/users/ryanyuyu/code/capstone_display_2/#53ac4447ffd2
--- a/main.cpp Fri Apr 25 02:03:04 2014 +0000
+++ b/main.cpp Fri Apr 25 03:09:18 2014 +0000
@@ -13,6 +13,10 @@
Serial pc(USBTX, USBRX); //USB serial for PC, to be removed later
AnalogOut waveOut(p18); //for debugging
+
+
+
+
//-------------------- SPI communication
SPI spi(p5, p6, p7); //MOSI, MISO, SCLK
DigitalOut cs(p8);
@@ -36,8 +40,8 @@
//-------------------for distance calculation and calibration
bool adjusting = true; //whether the user is still adjusting the beacon's distance
-float minThreshold;
-float maxThresholds[numGainStages];
+float minThreshold = .042;
+float maxThresholds[numGainStages] = {.400, .400, .400, .400};
float average = 0;
float pastAverage1 = 0;
float pastAverage2 = 0;
@@ -45,7 +49,7 @@
int state;
int gainStage;
float gainMultiplier;
-float gainCutoffs[numGainStages] = {20.0, 100.0, 1200.0, 10000.0};
+float gainCutoffs[numGainStages] = {20.639122, 71.663605, 1486.016724, 8599.633789};
//gainCutoffs = {20.0, 100.0, 1200.0, 10000.0};
float gain1;
float gain0;
@@ -54,11 +58,13 @@
int callibrationPoints[numCallibrationSteps] = {6, 10, 14, 14, 20, 24, 26, 36, 50, 50, 62, 78};
//callibrationPoints = {6, 10, 14, 14, 20, 24, 26, 36, 50, 50, 62, 78};
-float mLower[numGainStages]; //m (slope) lower portion
-float bLower[numGainStages]; //b (y-offset) lower portion
-float mid[numGainStages]; //the middle x-value for the piecewise
-float mUpper[numGainStages]; //m (slope) upper portion
-float bUpper[numGainStages]; //b (y-offset) upper portion
+//the slopes and y-intercepts and mid voltages.
+float mLower[numGainStages] = {-15.322362, -108.246826, -43.797886, 90.550484};
+float mUpper[numGainStages] = {-100.010368, -485.365387, -186.721283, -223.606857};
+float bLower[numGainStages] = {11.394491, 25.797676, 42.176929, 77.429733};
+float bUpper[numGainStages] = {19.101967, 45.996063, 62.333790, 100.10244};
+float mid[numGainStages] = {0.091010, 0.053560, 0.141033, 0.170399};
+float fix = -0.75;
/*
float m10;
@@ -296,17 +302,17 @@
switch (gainStage)
{
case 0:
- if (value > mid[0]) return mLower[0]*value + bLower[0];
- else return mUpper[0]*value + bUpper[0];
+ if (value > mid[0]) return mLower[0]*value + bLower[0] + fix;
+ else return mUpper[0]*value + bUpper[0] + fix;
case 1:
- if (value > mid[1]) return mLower[1]*value + bLower[1];
- else return mUpper[1]*value + bUpper[1];
+ if (value > mid[1]) return mLower[1]*value + bLower[1] + fix;
+ else return mUpper[1]*value + bUpper[1] + fix;
case 2:
- if (value > mid[2]) return mLower[2]*value + bLower[2];
- else return mUpper[2]*value + bUpper[2];
+ if (value > mid[2]) return mLower[2]*value + bLower[2] + fix;
+ else return mUpper[2]*value + bUpper[2] + fix;
case 3:
- if (value > mid[3]) return mLower[3]*value + bLower[3];
- else return mUpper[3]*value + bUpper[3];
+ if (value > mid[3]) return mLower[3]*value + bLower[3] + fix;
+ else return mUpper[3]*value + bUpper[3] + fix;
//*/
default:
return 0;
@@ -329,7 +335,7 @@
else if (distance == 999) //the special case for being too far
{
//pc.printf(" Too far.\n\r");
- if (gainStage < numGainStages) gainStage++;
+ if (gainStage < numGainStages-1) gainStage++;
else lcd.print("No beacon found.");
}
else lcd.print("");
@@ -459,6 +465,11 @@
waitForButton();
adjusting = false;
state = 2;
+ if (button == 1) //skip callibration and use preset stuff;
+ {
+ callibrationStep = -1;
+ }
+ else fix = 0;
}
else
{
@@ -485,7 +496,7 @@
mUpper[i] = (callibrationPoints[i*3+2] - callibrationPoints[i*3+1]) / (linearSamples[i*3+2] - linearSamples[i*3+1]) ;
bLower[i] = callibrationPoints[i*3+0] - mLower[i]*linearSamples[i*3+0];
bUpper[i] = callibrationPoints[i*3+1] - mUpper[i]*linearSamples[i*3+1];
- //pc.printf("mL=%f mU=%f bL=%f, bU=%f, mid=%f, cutoff=%f\n\r", mLower[i], mUpper[i], bLower[i], bUpper[i], mid[i], gainCutoffs[i]);
+ pc.printf("mL=%f mU=%f bL=%f, bU=%f, mid=%f, cutoff=%f\n\r", mLower[i], mUpper[i], bLower[i], bUpper[i], mid[i], gainCutoffs[i]);
}
callibrationStep = -1;
state = 2;
@@ -493,7 +504,7 @@
for (int i = 0; i < numCallibrationSteps; i++)
{
- //pc.printf("linear(x)=%f callibration(y)=%d \n\r", linearSamples[i], callibrationPoints[i]);
+ pc.printf("linear(x)=%f callibration(y)=%d \n\r", linearSamples[i], callibrationPoints[i]);
}
//pc.printf("End of callibration.\n\r");
}
@@ -654,30 +665,32 @@
wait_ms(1000);
*/
- /*
- m00 = -15.221;
- b00 = 10.836;
- mid0 = .088;
- m01 = -142.2;
- b01 = 22.101;
-
- m10 = -48.639;
- b10 = 22.128;
- mid1 = .068;
- m11 = -363.74;
- b11 = 22.352;
-
- m20 = -45.513;
- b20 = 39.895;
- mid2 = .115;
- m21 = -314.87;
- b21 = 70.387;
-
- m30 = -81.809;
- b30 = 76.868;
- mid3 = .194;
- m31 = -201.48;
- b31 = 99.556;
+ /*
+ mLower = {-15.322362, -108.246826, -43.797886, 90.550484};
+ mUpper = {-100.010368, -485.365387, -186.721283, -223.606857};
+ bLower = {11.394491, 25.797676, 42.176929, 77.429733};
+ bUpper = {19.101967, 45.996063, 62.333790, 100.10244};
+ mid = {0.091010, 0.053560, 0.141033, 0.170399};
+ gainCutoffs = {20.639122, 71.663605, 1486.016724, 8599.633789};
+mL=-15.322362 mU=-100.010368 bL=11.394491, bU=19.101967, mid=0.091010, cutoff=20.639122
+mL=-108.246826 mU=-485.365387 bL=25.797676, bU=45.996063, mid=0.053560, cutoff=71.663605
+mL=-43.797886 mU=-186.721283 bL=42.176929, bU=62.333790, mid=0.141033, cutoff=1486.016724
+mL=-90.550484 mU=-223.606857 bL=77.429733, bU=100.102448, mid=0.170399, cutoff=8599.633789
+linear(x)=0.352067 callibration(y)=6
+linear(x)=0.091010 callibration(y)=10
+linear(x)=0.051014 callibration(y)=14
+linear(x)=0.108989 callibration(y)=14
+linear(x)=0.053560 callibration(y)=20
+linear(x)=0.045319 callibration(y)=24
+linear(x)=0.369354 callibration(y)=26
+linear(x)=0.141033 callibration(y)=36
+linear(x)=0.066055 callibration(y)=50
+linear(x)=0.302922 callibration(y)=50
+linear(x)=0.170399 callibration(y)=62
+linear(x)=0.098845 callibration(y)=78
+
+
+
/*
