Changeset 12435 for trunk/FACT++


Ignore:
Timestamp:
11/07/11 00:02:49 (13 years ago)
Author:
tbretz
Message:
First working version of a whole-camera-setup.
File:
1 edited

Legend:

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

    r12429 r12435  
    4040        kStateConnected,
    4141
    42         kStateWaitingForReference,
    4342        kStateSettingGlobalThreshold,
    4443        kStateGlobalThresholdSet,
     
    6463
    6564    uint16_t fThresholdMin;
     65    uint16_t fThresholdReference;
    6666
    6767    bool fTriggerOn;
     
    214214                if (maxi==j)
    215215                {
     216                    // This is the step which has to be performed to go from
     217                    // a NSB rate of sdata.fPatchRate[i*4+j]
     218
     219
    216220                    const float step = (log10(sdata.fPatchRate[i*4+j])-log10(mp+5*dp))/0.039;
    217221                    //  * (dif-5)/dif
     
    259263        for (int i=0; i<40; i++)
    260264        {
    261             if ( fabs(sdata.fBoardRate[i]-mb)<5*db)
     265            if ( fabs(sdata.fBoardRate[i]-mb)<3*db)
    262266            {
    263267                avg += sdata.fBoardRate[i];
     
    272276            Out() << "Board:  Median=" << mb << " Dev=" << db << endl;
    273277            Out() << "Camera: " << fTriggerRate << " (" << sdata.fTriggerRate << ", n=" << num << ")" << endl;
     278            Out() << "Target: " << fTargetRate << endl;
    274279        }
    275280
    276281        // ----------------------
    277282
    278 
    279         if (fTriggerRate<fTargetRate)
    280             return;
    281 
    282         // Is this a step to 70Hz?
    283         const float step = (log10(fTriggerRate)-log10(fTargetRate))/0.039;
     283        if (fTriggerRate>0 && fTriggerRate<fTargetRate)
     284        {
     285            // I am assuming here (and at other places) the the answer from the FTM when setting
     286            // the new threshold always arrives faster than the next rate update.
     287            fThresholdMin = fThresholds[0];
     288            return;
     289        }
     290
     291        // This is a step towards a threshold at which the NSB rate is equal the target rate
     292        // +1 to avoid getting a step of 0
     293        const float step = (log10(fTriggerRate)-log10(fTargetRate))/0.039 + 1;
    284294
    285295        const uint16_t diff = fThresholds[0]+int16_t(truncf(step));
     296
     297        cout << diff << endl;
    286298
    287299        if (diff==fThresholds[0])
     
    327339
    328340            const FTM::DimStaticData &sdata = *static_cast<FTM::DimStaticData*>(curr->getData());
    329 
     341            fTriggerOn = sdata.HasTrigger();
     342 
    330343            PrintThresholds(sdata);
    331344
    332             fTriggerOn = sdata.HasTrigger();
    333 
    334345            fThresholds.assign(sdata.fThreshold, sdata.fThreshold+160);
    335 
    336346            return;
    337347        }
     
    342352                return;
    343353
    344             if (!fTriggerOn)
     354            if (!fTriggerOn && !fEnabled)
    345355                return;
    346356
     
    358368    }
    359369
    360     int StartDataTaking()
    361     {
    362         if (!fEnabled)
     370    int Calibrate()
     371    {
     372        if (!fTriggerOn)
    363373            return kStateGlobalThresholdSet;
    364374
    365         fThresholds.resize(0);
    366 
    367         const int32_t val[2] = { -1, fThresholdMin };
     375        const int32_t val[2] = { -1, fThresholdReference };
    368376        Dim::SendCommand("FTM_CONTROL/SET_THRESHOLD", val);
    369377
    370         return kStateWaitingForReference;
     378        fThresholds.assign(160, fThresholdReference);
     379
     380        fThresholdMin = fThresholdReference;
     381        fTriggerRate  = -1;
     382        fEnabled      = true;
     383
     384        return kStateSettingGlobalThreshold;
     385    }
     386
     387    int StartRC()
     388    {
     389        fEnabled = true;
     390        return GetCurrentState();
     391    }
     392
     393    int StopRC()
     394    {
     395        fEnabled = false;
     396        return GetCurrentState();
    371397    }
    372398
     
    388414        // FIXME: Check missing
    389415
    390         fThresholdMin = evt.GetUShort();
     416        fThresholdReference = evt.GetUShort();
    391417
    392418        return GetCurrentState();
     
    453479            return kStateDisconnected;
    454480
    455         if (GetCurrentState()==kStateWaitingForReference)
    456         {
    457             if (fThresholds.size()==0)
    458                 return kStateWaitingForReference;
    459 
    460             return kStateSettingGlobalThreshold;
    461         }
    462 
    463481        if (GetCurrentState()==kStateSettingGlobalThreshold)
    464482        {
    465             if (fTriggerRate>fTargetRate)
     483            if (fTriggerRate<0 || fTriggerRate>fTargetRate)
    466484                return kStateSettingGlobalThreshold;
    467485
     
    471489        if (GetCurrentState()==kStateGlobalThresholdSet)
    472490        {
    473             // FIXME: What if it changes?
    474             return kStateGlobalThresholdSet;
     491            if (!fTriggerOn)
     492                return kStateGlobalThresholdSet;
     493            //return kStateInProgress;
    475494        }
    476495
    477496        // At least one subsystem is not connected
    478497        //        if (fStatusFTM.second>=FTM::kConnected)
    479         return fTriggerOn ? kStateInProgress : kStateConnected;
     498        return fTriggerOn && fEnabled ? kStateInProgress : kStateConnected;
    480499    }
    481500
     
    513532                     "All needed subsystems are connected to their hardware, no action is performed.");
    514533
     534        AddStateName(kStateSettingGlobalThreshold, "Calibrating", "");
     535        AddStateName(kStateGlobalThresholdSet, "GlobalThresholdSet", "");
     536
    515537        AddStateName(kStateInProgress, "InProgress",
    516538                     "Rate scan in progress.");
    517539
    518 //        AddEvent("STOP", kStateInProgress)
    519 //            (bind(&StateMachineRateControl::StopRateControl, this))
    520 //            ("Stop a ratescan in progress");
    521 
    522         AddEvent("START_DATA_TAKING")
    523             (bind(&StateMachineRateControl::StartDataTaking, this))
     540        AddEvent("CALIBRATE")
     541            (bind(&StateMachineRateControl::Calibrate, this))
    524542            ("");
    525543
    526         AddEvent("ENABLE_RATE_CONTROL", "B:1")
    527             (bind(&StateMachineRateControl::SetEnabled, this, placeholders::_1))
     544        AddEvent("START", "")
     545            (bind(&StateMachineRateControl::StartRC, this))
     546            ("");
     547
     548        AddEvent("STOP", "")
     549            (bind(&StateMachineRateControl::StopRC, this))
    528550            ("");
    529551
     
    550572    {
    551573        fVerbose = !conf.Get<bool>("quiet");
     574
     575        fThresholdReference = 300;
     576        fTargetRate         =  70;
     577
    552578        return -1;
    553579    }
Note: See TracChangeset for help on using the changeset viewer.