Mercurial > hg > fxanalyse
comparison FXAnalyse.c @ 66:aa125ad6e842
Clarify variables names in dedrifting code
author | Daniele Nicolodi <daniele.nicolodi@obspm.fr> |
---|---|
date | Mon, 29 Oct 2012 14:48:01 +0100 |
parents | da82b4815c2f |
children | 0159abc1a9d8 |
comparison
equal
deleted
inserted
replaced
65:da82b4815c2f | 66:aa125ad6e842 |
---|---|
102 | 102 |
103 // slope cancelling | 103 // slope cancelling |
104 | 104 |
105 int SlopeMeasuring = FALSE; | 105 int SlopeMeasuring = FALSE; |
106 int StopSlopeCancellingOnUnlocked = TRUE; | 106 int StopSlopeCancellingOnUnlocked = TRUE; |
107 double SlopeMath2 = 0.0; // currently applied frequency dedrifiting slope | |
108 double TimetoSlope = 60.0; | 107 double TimetoSlope = 60.0; |
109 double SlopeMeasuringTimeBegin = 0.0; | 108 double SlopeMeasuringTimeBegin = 0.0; |
110 | 109 |
111 double Slope_Math2slope=0.0,Moy_Math2slope=0.0; | 110 int Nsamples = 0; // number of samples in current measurement |
112 int N_Math2slope=0.0; | 111 double previousFreq = 0.0; // previous frequency value |
112 double meanFreq = 0.0; // mean value | |
113 double measuredSlope = 0.0; // measured slope | |
114 double appliedSlope = 0.0; // currently applied frequency dedrifiting slope | |
113 | 115 |
114 double LimitToDelock=5.0; | 116 double LimitToDelock=5.0; |
115 double limitotakoff=70.0; | 117 double limitotakoff=70.0; |
116 | 118 |
117 int ratio=10; //Recentre la frequence tous les ratios | 119 int ratio=10; //Recentre la frequence tous les ratios |
124 enum { | 126 enum { |
125 SLOPE_REFERENCE_MICROWAVE = 0, | 127 SLOPE_REFERENCE_MICROWAVE = 0, |
126 SLOPE_REFERENCE_HG_CAVITY = 1, | 128 SLOPE_REFERENCE_HG_CAVITY = 1, |
127 }; | 129 }; |
128 | 130 |
129 double previousFreq = 0.0; | |
130 int invertSlopeSign = 0; | 131 int invertSlopeSign = 0; |
131 int slopeReference = SLOPE_REFERENCE_MICROWAVE; | 132 int slopeReference = SLOPE_REFERENCE_MICROWAVE; |
132 | 133 |
133 int KeepCentering = FALSE; | 134 int KeepCentering = FALSE; |
134 double Timetorecenter275K = 3600.0 * 10; | 135 double Timetorecenter275K = 3600.0 * 10; |
1241 double frequency = DEDRIFT_DDS_FREQUENCY; | 1242 double frequency = DEDRIFT_DDS_FREQUENCY; |
1242 if (KeepFrequ) | 1243 if (KeepFrequ) |
1243 frequency = DDSFox_ReadFreq(&DDS1xAD9956); | 1244 frequency = DDSFox_ReadFreq(&DDS1xAD9956); |
1244 | 1245 |
1245 if (! KeepSlope) | 1246 if (! KeepSlope) |
1246 SlopeMath2 = 0.0; | 1247 appliedSlope = 0.0; |
1247 | 1248 |
1248 SetCtrlVal(MainPanel, PANEL_SLOPE_APPLIED, SlopeMath2); | 1249 SetCtrlVal(MainPanel, PANEL_SLOPE_APPLIED, appliedSlope); |
1249 DDSFox_Set(&DDS1xAD9956, frequency, SlopeMath2); | 1250 DDSFox_Set(&DDS1xAD9956, frequency, appliedSlope); |
1250 | 1251 |
1251 Slope_Math2slope = 0.0; | 1252 measuredSlope = 0.0; |
1252 SlopeMeasuring = FALSE; | 1253 SlopeMeasuring = FALSE; |
1253 SetCtrlVal(MainPanel, PANEL_MEASURE_SLOPE, 0); | 1254 SetCtrlVal(MainPanel, PANEL_MEASURE_SLOPE, 0); |
1254 } | 1255 } |
1255 | 1256 |
1256 // update slope measurement | 1257 // update slope measurement |
1257 N_Math2slope = N_Math2slope + 1; | 1258 Nsamples = Nsamples + 1; |
1259 meanFreq = ((Nsamples - 1) * meanFreq + currentFreq) / Nsamples; | |
1260 measuredSlope = (measuredSlope * (Nsamples - 2) + 6 * (currentFreq - meanFreq) / Nsamples) / (Nsamples + 1); | |
1258 previousFreq = currentFreq; | 1261 previousFreq = currentFreq; |
1259 Moy_Math2slope = ((N_Math2slope-1)*Moy_Math2slope + currentFreq)/N_Math2slope; | |
1260 Slope_Math2slope = (Slope_Math2slope*(N_Math2slope-2) + 6*(currentFreq-Moy_Math2slope)/N_Math2slope)/(N_Math2slope+1); | |
1261 // update indicator | 1262 // update indicator |
1262 SetCtrlVal(MainPanel, PANEL_SLOPE_MEASURED, Slope_Math2slope); | 1263 SetCtrlVal(MainPanel, PANEL_SLOPE_MEASURED, measuredSlope); |
1263 | 1264 |
1264 // update applied slope | 1265 // update applied slope |
1265 if ((utc - SlopeMeasuringTimeBegin) > TimetoSlope) { | 1266 if ((utc - SlopeMeasuringTimeBegin) > TimetoSlope) { |
1266 | 1267 |
1267 if (invertSlopeSign) | 1268 if (invertSlopeSign) |
1268 SlopeMath2 = SlopeMath2 - Slope_Math2slope; | 1269 appliedSlope = appliedSlope - measuredSlope; |
1269 else | 1270 else |
1270 SlopeMath2 = SlopeMath2 + Slope_Math2slope; | 1271 appliedSlope = appliedSlope + measuredSlope; |
1271 | 1272 |
1272 if (FrequCorrec) { | 1273 if (FrequCorrec) { |
1273 // proportional correction | 1274 // proportional correction |
1274 | 1275 |
1275 Nratio += 1; | 1276 Nratio += 1; |
1276 if (Nratio >= 1) { | 1277 if (Nratio >= 1) { |
1277 MoyMath2 = MoyMath2 + Moy_Math2slope; | 1278 MoyMath2 = MoyMath2 + meanFreq; |
1278 } | 1279 } |
1279 if (Nratio == 1 && CenterFrequencyCh2ToDetermine == TRUE) { | 1280 if (Nratio == 1 && CenterFrequencyCh2ToDetermine == TRUE) { |
1280 CenterFrequencyCh2 = MoyMath2; | 1281 CenterFrequencyCh2 = MoyMath2; |
1281 CenterFrequencyCh2ToDetermine = FALSE; | 1282 CenterFrequencyCh2ToDetermine = FALSE; |
1282 } | 1283 } |
1283 if (Nratio == ratio) { | 1284 if (Nratio == ratio) { |
1284 double correction = (MoyMath2/ratio-CenterFrequencyCh2)/TimetoSlope; | 1285 double correction = (MoyMath2/ratio-CenterFrequencyCh2)/TimetoSlope; |
1285 SlopeMath2 = SlopeMath2 + correction; | 1286 appliedSlope = appliedSlope + correction; |
1286 Nratio = 0; | 1287 Nratio = 0; |
1287 MoyMath2 = 0.0; | 1288 MoyMath2 = 0.0; |
1288 } | 1289 } |
1289 } | 1290 } |
1290 | 1291 |
1291 SetCtrlVal(MainPanel, PANEL_SLOPE_APPLIED, SlopeMath2); | 1292 SetCtrlVal(MainPanel, PANEL_SLOPE_APPLIED, appliedSlope); |
1292 DDSFox_SetSweepRate(&DDS1xAD9956, SlopeMath2); | 1293 DDSFox_SetSweepRate(&DDS1xAD9956, appliedSlope); |
1293 | 1294 |
1294 N_Math2slope = 0.0; | 1295 Nsamples = 0.0; |
1295 Moy_Math2slope = 0.0; | 1296 meanFreq = 0.0; |
1296 Slope_Math2slope = 0.0; | 1297 measuredSlope = 0.0; |
1297 SlopeMeasuringTimeBegin = utc; | 1298 SlopeMeasuringTimeBegin = utc; |
1298 } | 1299 } |
1299 } | 1300 } |
1300 | 1301 |
1301 // re-centering | 1302 // re-centering |
2237 frequency = DEDRIFT_DDS_FREQUENCY; | 2238 frequency = DEDRIFT_DDS_FREQUENCY; |
2238 if (KeepFrequ) | 2239 if (KeepFrequ) |
2239 frequency = DDSFox_ReadFreq(&DDS1xAD9956); | 2240 frequency = DDSFox_ReadFreq(&DDS1xAD9956); |
2240 | 2241 |
2241 if (! KeepSlope) | 2242 if (! KeepSlope) |
2242 SlopeMath2 = 0.0; | 2243 appliedSlope = 0.0; |
2243 | 2244 |
2244 SetCtrlVal(panel, PANEL_SLOPE_APPLIED, SlopeMath2); | 2245 SetCtrlVal(panel, PANEL_SLOPE_APPLIED, appliedSlope); |
2245 DDSFox_Set(&DDS1xAD9956, frequency, SlopeMath2); | 2246 DDSFox_Set(&DDS1xAD9956, frequency, appliedSlope); |
2246 | 2247 |
2247 SlopeMeasuring = FALSE; | 2248 SlopeMeasuring = FALSE; |
2248 N_Math2slope = 0.0; | 2249 Nsamples = 0.0; |
2249 Moy_Math2slope = 0.0; | 2250 meanFreq = 0.0; |
2250 Slope_Math2slope = 0.0; | 2251 measuredSlope = 0.0; |
2251 MoyMath2 = 0.0; | 2252 MoyMath2 = 0.0; |
2252 Slope_Math2slope = 0.0; | |
2253 CenterFrequencyCh2 = 0.0; | 2253 CenterFrequencyCh2 = 0.0; |
2254 Nratio = -1; | 2254 Nratio = -1; |
2255 } | 2255 } |
2256 break; | 2256 break; |
2257 } | 2257 } |
2267 case EVENT_COMMIT: | 2267 case EVENT_COMMIT: |
2268 CenterFrequencyCh2 = 0.0; | 2268 CenterFrequencyCh2 = 0.0; |
2269 MoyMath2 = 0.0; | 2269 MoyMath2 = 0.0; |
2270 Nratio = -1; | 2270 Nratio = -1; |
2271 CenterFrequencyCh2ToDetermine = TRUE ; | 2271 CenterFrequencyCh2ToDetermine = TRUE ; |
2272 SlopeMath2 = 0.0; | 2272 appliedSlope = 0.0; |
2273 SetCtrlVal(panel, PANEL_SLOPE_APPLIED, SlopeMath2); | 2273 SetCtrlVal(panel, PANEL_SLOPE_APPLIED, appliedSlope); |
2274 DDSFox_Set(&DDS1xAD9956, DEDRIFT_DDS_FREQUENCY, SlopeMath2); | 2274 DDSFox_Set(&DDS1xAD9956, DEDRIFT_DDS_FREQUENCY, appliedSlope); |
2275 break; | 2275 break; |
2276 } | 2276 } |
2277 return 0; | 2277 return 0; |
2278 } | 2278 } |
2279 | 2279 |
2458 void *callbackData, int eventData1, int eventData2) | 2458 void *callbackData, int eventData1, int eventData2) |
2459 { | 2459 { |
2460 switch (event) | 2460 switch (event) |
2461 { | 2461 { |
2462 case EVENT_COMMIT: | 2462 case EVENT_COMMIT: |
2463 GetCtrlVal(panel, control, &SlopeMath2); | 2463 GetCtrlVal(panel, control, &appliedSlope); |
2464 DDSFox_SetSweepRate(&DDS1xAD9956, SlopeMath2); | 2464 DDSFox_SetSweepRate(&DDS1xAD9956, appliedSlope); |
2465 break; | 2465 break; |
2466 } | 2466 } |
2467 return 0; | 2467 return 0; |
2468 } | 2468 } |
2469 | 2469 |