Changeset 15019 for trunk/FACT++


Ignore:
Timestamp:
03/10/13 16:06:30 (12 years ago)
Author:
tbretz
Message:
Added Dim service with calibrated currents.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/src/feedback.cc

    r14352 r15019  
    5151    DimDescribedService fDimDeviation;
    5252    DimDescribedService fDimCalibration;
     53    DimDescribedService fDimCurrents;
    5354
    5455    vector<int64_t>  fCurrentsAvg;
     
    5758    vector<float>    fCalibration;
    5859    vector<float>    fVoltGapd;
     60    vector<float>    fBiasVolt;
    5961
    6062    vector<vector<float>> fData;
     
    6668    Time fBiasLast;
    6769    Time fStartTime;
     70    Time fCalibTime;
    6871
    6972    valarray<double> fPV[3];  // Process variable (intgerated/averaged amplitudes)
     
    367370        }
    368371
    369         fDimCalibration.Update(fCalibration);
     372        fCalibTime = Time();
     373
     374        fDimCalibration.setData(fCalibration);
     375        fDimCalibration.Update(fCalibTime);
    370376
    371377        fOutputEnabled = false;
     
    719725    }
    720726
     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
    721803    int HandleBiasCurrent(const EventImp &evt)
    722804    {
     
    736818        }*/
    737819
     820        HandleCalibrateCurrents(evt);
     821
    738822        return GetCurrentState();
    739823    }
     
    756840        Info("Nominal bias voltages received.");
    757841
     842        return GetCurrentState();
     843    }
     844
     845    int HandleBiasVoltage(const EventImp &evt)
     846    {
     847        fBiasVolt.assign(evt.Ptr<float>(), evt.Ptr<float>()+416);
    758848        return GetCurrentState();
    759849    }
     
    11991289                        "|Rms[uA]:Rms of offset"
    12001290                        "|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"),
    12011300        fSP(BIAS::kNumChannels),
    12021301        fKp(0), fKi(0), fKd(0), fT(-1),
     
    12211320        Subscribe("BIAS_CONTROL/CURRENT")
    12221321            (bind(&StateMachineFeedback::HandleBiasCurrent, this, placeholders::_1));
     1322        Subscribe("BIAS_CONTROL/VOLTAGE")
     1323            (bind(&StateMachineFeedback::HandleBiasVoltage, this, placeholders::_1));
    12231324        Subscribe("BIAS_CONTROL/FEEDBACK_DATA")
    12241325            (bind(&StateMachineFeedback::HandleBiasData,    this, placeholders::_1));
Note: See TracChangeset for help on using the changeset viewer.