Changeset 15019 for trunk/FACT++/src/feedback.cc
- Timestamp:
- 03/10/13 16:06:30 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/feedback.cc
r14352 r15019 51 51 DimDescribedService fDimDeviation; 52 52 DimDescribedService fDimCalibration; 53 DimDescribedService fDimCurrents; 53 54 54 55 vector<int64_t> fCurrentsAvg; … … 57 58 vector<float> fCalibration; 58 59 vector<float> fVoltGapd; 60 vector<float> fBiasVolt; 59 61 60 62 vector<vector<float>> fData; … … 66 68 Time fBiasLast; 67 69 Time fStartTime; 70 Time fCalibTime; 68 71 69 72 valarray<double> fPV[3]; // Process variable (intgerated/averaged amplitudes) … … 367 370 } 368 371 369 fDimCalibration.Update(fCalibration); 372 fCalibTime = Time(); 373 374 fDimCalibration.setData(fCalibration); 375 fDimCalibration.Update(fCalibTime); 370 376 371 377 fOutputEnabled = false; … … 719 725 } 720 726 727 void HandleCalibrateCurrents(const EventImp &evt) 728 { 729 if (fBiasVolt.size()==0 || fCalibration.size()==0) 730 return; 731 732 struct dim_data { 733 float I[416]; 734 float Iavg; 735 float Irms; 736 float Imed; 737 float Idev; 738 uint16_t N; 739 float Tdiff; 740 741 dim_data() : Iavg(0), Irms(0), Imed(0), Idev(0), N(0), Tdiff(0) { memset(I, 0, sizeof(float)*416); } 742 } __attribute__((__packed__));; 743 744 const int16_t *I = evt.Ptr<int16_t>(); 745 const float *R = fCalibration.data()+BIAS::kNumChannels*2; 746 const float *U = fBiasVolt.data(); 747 748 vector<float> med(416); 749 uint16_t cnt = 0; 750 751 double avg = 0; 752 double rms = 0; 753 754 dim_data data; 755 for (int i=0; i<416; i++) 756 { 757 const PixelMapEntry &hv = fMap.hv(i); 758 if (!hv) 759 continue; 760 761 if (R[i]<=0) 762 continue; 763 764 data.I[i] = I[i]*5000./4096 - U[i]/R[i]*1e6; 765 data.I[i] /= hv.group() ? 5 : 4; 766 767 avg += data.I[i]; 768 rms += data.I[i]*data.I[i]; 769 770 if (i>=320) 771 continue; 772 773 med[cnt++] = data.I[i]; 774 } 775 776 if (cnt==0) 777 return; 778 779 avg /= cnt; 780 rms /= cnt; 781 782 data.N = cnt; 783 data.Iavg = avg; 784 data.Irms = sqrt(rms-avg*avg); 785 786 sort(med.data(), med.data()+cnt); 787 788 data.Imed = cnt%2 ? (med[cnt/2-1]+med[cnt/2])/2 : med[cnt/2]; 789 790 for (int i=0; i<cnt; i++) 791 med[i] = fabs(med[i]-data.Imed); 792 793 sort(med.data(), med.data()+cnt); 794 795 data.Idev = med[uint32_t(0.682689477208650697*cnt)]; 796 797 data.Tdiff = evt.GetTime().UnixTime()-fCalibTime.UnixTime(); 798 799 fDimCurrents.setData(&data, sizeof(dim_data)); 800 fDimCurrents.Update(evt.GetTime()); 801 } 802 721 803 int HandleBiasCurrent(const EventImp &evt) 722 804 { … … 736 818 }*/ 737 819 820 HandleCalibrateCurrents(evt); 821 738 822 return GetCurrentState(); 739 823 } … … 756 840 Info("Nominal bias voltages received."); 757 841 842 return GetCurrentState(); 843 } 844 845 int HandleBiasVoltage(const EventImp &evt) 846 { 847 fBiasVolt.assign(evt.Ptr<float>(), evt.Ptr<float>()+416); 758 848 return GetCurrentState(); 759 849 } … … 1199 1289 "|Rms[uA]:Rms of offset" 1200 1290 "|R[Ohm]:Measured calibration resistor"), 1291 fDimCurrents("FEEDBACK/CALIBRATED_CURRENTS", "F:416;F:1;F:1;F:1;F:1;I:1;F:1", 1292 "Calibrated currents" 1293 "|I[uA]:Calibrated currents" 1294 "|I_avg[uA]:Average calibrated current (320 channels)" 1295 "|I_rms[uA]:Rms of calibrated current (320 channels)" 1296 "|I_med[uA]:Median calibrated current (320 channels)" 1297 "|I_dev[uA]:Deviation of calibrated current (320 channels)" 1298 "|N:Number of valid values" 1299 "|T_diff[s]:Time difference to calibration"), 1201 1300 fSP(BIAS::kNumChannels), 1202 1301 fKp(0), fKi(0), fKd(0), fT(-1), … … 1221 1320 Subscribe("BIAS_CONTROL/CURRENT") 1222 1321 (bind(&StateMachineFeedback::HandleBiasCurrent, this, placeholders::_1)); 1322 Subscribe("BIAS_CONTROL/VOLTAGE") 1323 (bind(&StateMachineFeedback::HandleBiasVoltage, this, placeholders::_1)); 1223 1324 Subscribe("BIAS_CONTROL/FEEDBACK_DATA") 1224 1325 (bind(&StateMachineFeedback::HandleBiasData, this, placeholders::_1));
Note:
See TracChangeset
for help on using the changeset viewer.