Ignore:
Timestamp:
10/08/13 15:35:24 (11 years ago)
Author:
tbretz
Message:
Added custom channel offsets to correct gain variations seen in the camera; some small imporvements to the output; instead of using Ubd as reference, now the voltage around which the gain is spposed to be 0 is used as reference - this also improves the behaviour during bright light.
File:
1 edited

Legend:

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

    r17173 r17203  
    4343    DimDescribedService fDimCalibrationR8;
    4444    DimDescribedService fDimCurrents;
     45    DimDescribedService fDimOffsets;
    4546
    4647    vector<float>    fCalibCurrentMes[6]; // Measured calibration current at six different levels
     
    7071    double fTempCoefficient;
    7172    double fTemp;
     73
     74    vector<double> fVoltOffset;
    7275
    7376    uint16_t fCurrentRequestInterval;
     
    399402        } __attribute__((__packed__));
    400403
     404        int Ndev[3] = { 0, 0, 0 };
     405
    401406        dim_data data;
    402407
     
    507512
    508513            // Current in R4/R5 branch
    509             const double Iout = I8>I9 ? I8 - I9 : 0;
     514            const double Iout = I8 - I9;//I8>I9 ? I8 - I9 : 0;
    510515
    511516            // Applied voltage at calibration resistors, according to biasctrl
     
    547552
    548553            // Nominal breakdown voltage with correction for temperature dependence
    549             const double Ubd = fVoltGapd[i] + fTempOffset[i];
     554            const double Ubd = fVoltGapd[i] + fVoltOffset[i] + fTempOffset[i];
    550555
    551556            // Current overvoltage (at a G-APD with the correct 3900 Ohm resistor)
    552             const double Uov = U9-Udrp-Ubd>0 ? U9-Udrp-Ubd : 0;
     557            //const double Uov = U9-Udrp-Ubd>0 ? U9-Udrp-Ubd : 0;
     558            const double Uov = U9-Udrp-Ubd>-0.34 ? U9-Udrp-Ubd : -0.34;
    553559
    554560            // Iout linear with U9 above Ubd
     
    591597            // Estimate set point for over-voltage (voltage drop at the target point)
    592598            //const double Uset = Ubd + overvoltage + R*Iov*N;
    593             const double Uset = Uov<0.3 ? Ubd + overvoltage + Udrp : Ubd + overvoltage + Udrp*pow(overvoltage/Uov, 1.66);
     599            //const double Uset = Uov<0.3 ? Ubd + overvoltage + Udrp : Ubd + overvoltage + Udrp*pow(overvoltage/Uov, 1.66);
     600            const double Uset = Uov<0 ?
     601                Ubd + overvoltage + Udrp*pow(overvoltage/0.34+1, 1.66) :
     602                Ubd + overvoltage + Udrp*pow((overvoltage+0.34)/(Uov+0.34), 1.66);
     603
     604            if (fabs(overvoltage-Uov)>0.033)
     605                Ndev[0]++;
     606            if (fabs(overvoltage-Uov)>0.022)
     607                Ndev[1]++;
     608            if (fabs(overvoltage-Uov)>0.011)
     609                Ndev[2]++;
    594610
    595611            // Voltage set point
     
    638654
    639655                ostringstream msg;
    640                 msg << setprecision(4) << "Sending new absolute offset: dU(" << fTemp << "degC)=" << fTempOffsetAvg << "V+-" << fTempOffsetRms << ", Unom=" << overvoltage << "V, Uov=" << (num[0]+num[1]>0?(avg[0]+avg[1])/(num[0]+num[1]):0);
     656                msg << setprecision(4) << "Sending new absolute offset: dU(" << fTemp << "degC)=" << fTempOffsetAvg << "V+-" << fTempOffsetRms << ", Unom=" << overvoltage << "V, Uov=" << (num[0]+num[1]>0?(avg[0]+avg[1])/(num[0]+num[1]):0) << " [N=" << Ndev[0] << "/" << Ndev[1] << "/" << Ndev[2] << "]";
    641657                Info(msg);
    642658            }
     
    647663            {
    648664                ostringstream msg;
    649                 msg << setprecision(4) << "Current status: dU(" << fTemp << "degC)=" << fTempOffsetAvg << "V+-" << fTempOffsetRms << ", Unom=" << overvoltage << "V, Uov=" << (num[0]+num[1]>0?(avg[0]+avg[1])/(num[0]+num[1]):0);
     665                msg << setprecision(4) << "Current status: dU(" << fTemp << "degC)=" << fTempOffsetAvg << "V+-" << fTempOffsetRms << ", Unom=" << overvoltage << "V, Uov=" << (num[0]+num[1]>0?(avg[0]+avg[1])/(num[0]+num[1]):0) << " [N=" << Ndev[0] << "/" << Ndev[1] << "/" << Ndev[2] << "]";
    650666                Info(msg);
    651667            }
     
    850866        return GetCurrentState();
    851867    }
     868
     869    bool LoadOffsets(const string &file)
     870    {
     871        vector<double> data(416);
     872
     873        ifstream fin(file);
     874
     875        int cnt = 0;
     876        while (fin && cnt<320)
     877            fin >> data[cnt++];
     878
     879        if (cnt!=320)
     880        {
     881            Error("Reading offsets from "+file+" failed [N="+to_string(cnt-1)+"]");
     882            return false;
     883        }
     884
     885        fVoltOffset = data;
     886
     887        fDimOffsets.Update(fVoltOffset);
     888
     889        Info("New voltage offsets loaded from "+file);
     890        return true;
     891
     892    }
     893
     894    int LoadOffset(const EventImp &evt)
     895    {
     896        LoadOffsets(evt.GetText());
     897        return GetCurrentState();
     898    }
     899
     900    int ResetOffset()
     901    {
     902        fVoltOffset.assign(416, 0);
     903
     904        fDimOffsets.Update(fVoltOffset);
     905
     906        Info("Voltage offsets resetted.");
     907        return GetCurrentState();
     908    }
     909
    852910
    853911    int Execute()
     
    926984                     "|dU_temp[V]:Correction calculated from temperature"
    927985                    ),
     986        fDimOffsets("FEEDBACK/OFFSETS", "F:416",
     987                    "Offsets operation voltages"
     988                    "|U[V]:Offset per bias channels"),
     989        fVoltOffset(416),
    928990        fCurrentRequestInterval(0),
    929991        fNumCalibIgnore(30),
     
    9881050            ("Stop any control loop");
    9891051
     1052        AddEvent("LOAD_OFFSETS", "C", Feedback::State::kConnected, Feedback::State::kCalibrated)
     1053            (bind(&StateMachineFeedback::LoadOffset, this, placeholders::_1))
     1054            ("");
     1055        AddEvent("RESET_OFFSETS", Feedback::State::kConnected, Feedback::State::kCalibrated)
     1056            (bind(&StateMachineFeedback::ResetOffset, this))
     1057            ("");
     1058
    9901059
    9911060        AddEvent("PRINT")
     
    10171086        fNumCalibRequests       = conf.Get<uint16_t>("num-calib-average");
    10181087        fTempCoefficient        = conf.Get<double>("temp-coefficient");
     1088
     1089        if (conf.Has("offset-file"))
     1090            LoadOffsets(conf.Get<string>("offset-file"));
    10191091
    10201092        return -1;
     
    10421114        ("num-calib-average",   var<uint16_t>(300), "Number of current requests to be averaged")
    10431115        ("temp-coefficient",    var<double>()->required(), "Temp. coefficient [V/K]")
     1116        ("offset-file",         var<string>(), "File with operation voltage offsets")
    10441117        ;
    10451118
Note: See TracChangeset for help on using the changeset viewer.