Ignore:
Timestamp:
06/08/13 12:27:45 (11 years ago)
Author:
tbretz
Message:
When calibrated by currents after the calibration was started, wait until a static data block with the correct currents has been received before setting GlobalThresholdSet. This is to ensure that the thresholds are set _before_ the trigger is started; for better performance, the new command SET_ALL_THRESHOLDS is used.
File:
1 edited

Legend:

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

    r16565 r16772  
    130130    }
    131131
     132    // RETUNR VALUE
    132133    void Step(int idx, float step)
    133134    {
     
    239240                Step(i*4+j, step);
    240241            }
     242            // SET_SELECTED_THRESHOLDS
     243
    241244        }
    242245    }
     
    371374        PrintThresholds(sdata);
    372375
     376        if (GetCurrentState()==RateControl::State::kSettingGlobalThreshold && fCalibrateByCurrent)
     377        {
     378            if (fThresholds.empty())
     379                return RateControl::State::kSettingGlobalThreshold;
     380
     381            if (!std::equal(sdata.fThreshold, sdata.fThreshold+160, fThresholds.begin()))
     382                return RateControl::State::kSettingGlobalThreshold;
     383
     384            return RateControl::State::kGlobalThresholdSet;
     385        }
     386
    373387        fThresholds.assign(sdata.fThreshold, sdata.fThreshold+160);
    374388
     
    436450            return GetCurrentState();
    437451
     452        // We are not setting thresholds at all
    438453        if (GetCurrentState()!=RateControl::State::kSettingGlobalThreshold)
     454            return GetCurrentState();
     455
     456        // Target thresholds have been assigned already
     457        if (!fThresholds.empty())
    439458            return GetCurrentState();
    440459
     
    498517        int counter = 1;
    499518
    500         const int32_t val[2] = { -1, fThresholdMin };
    501         Dim::SendCommandNB("FTM_CONTROL/SET_THRESHOLD", val);
    502 
    503519        double avg2 = 0;
    504520        for (int i=0; i<160; i++)
     
    511527                fThresholds[i] = max(uint16_t(40.5*pow(vec[i], 0.642)+164), fThresholdReference);
    512528
    513                 const int32_t dat[2] = { i, fThresholds[i] };
    514                 Dim::SendCommandNB("FTM_CONTROL/SET_THRESHOLD", dat);
    515 
    516                 fBlock[i/4] = true;
    517 
    518529                counter++;
    519530            }
    520531        }
    521 
    522532        avg2 /= 160;
     533
     534
     535        vector<int32_t> val(160, fThresholdMin);
     536        std::copy(fThresholds.begin(), fThresholds.end(), val.begin());
     537        Dim::SendCommandNB("FTM_CONTROL/SET_ALL_THRESHOLDS", val.data(), val.size()*sizeof(int32_t));
     538
    523539
    524540        const RateControl::DimThreshold data = { fThresholdMin, fCalibrationTimeStart.Mjd(), Time().Mjd() };
     
    526542        fDimThreshold.Update(data);
    527543
    528         Info("Sent a total of "+to_string(counter)+" commands for threshold setting");
     544        //Info("Sent a total of "+to_string(counter)+" commands for threshold setting");
    529545
    530546        ostringstream out;
     
    532548        out << "Measured average current " << avg << "uA +- " << rms << "uA [N=" << fCurrentsMed.size() << "]... mininum threshold set to " << fThresholdMin;
    533549        Info(out);
     550        Info("Set "+to_string(counter)+" individual thresholds.");
    534551
    535552        fTriggerOn = false;
    536553        fPhysTriggerEnabled = false;
    537         return RateControl::State::kGlobalThresholdSet;
     554
     555        return RateControl::State::kSettingGlobalThreshold;
    538556    }
    539557
     
    587605        fCalibrationTimeStart = Time();
    588606        fBlock.assign(160, false);
     607
     608        fThresholds.clear();
    589609
    590610        ostringstream out;
Note: See TracChangeset for help on using the changeset viewer.