Changeset 12067 for trunk/FACT++


Ignore:
Timestamp:
09/11/11 21:34:54 (13 years ago)
Author:
tbretz
Message:
Added or updated some text; set default control loop parameters in EvalOptions; added a gain (conversion constant)
File:
1 edited

Legend:

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

    r12050 r12067  
    6767    DimStampedInfo fFAD;
    6868    DimStampedInfo fBias;
     69
    6970    DimStampedInfo *fBiasData;
    7071
     
    8283    valarray<double> fSP;     // Set point        (target amplitudes)
    8384
    84     double fT;
    85     double fKp;               // Proportional constant
    86     double fKi;               // Integral     constant
    87     double fKd;               // Derivative   constant
     85    double fKp;    // Proportional constant
     86    double fKi;    // Integral     constant
     87    double fKd;    // Derivative   constant
     88    double fT;     // Time         constant (cycle time)
     89    double fGain;  // Gain (conversion from a DRS voltage deviation into a BIAS voltage change at G-APD reference voltage)
     90
     91    double fT21;
    8892
    8993    bool fOutputEnabled;
     
    253257                const Time tm0 = Time();
    254258
    255                 /*const*/ double T21 = (tm0-fStartTime).total_microseconds()/1000000.;
    256                 const double T10 = fT;
    257                 fT = T21;
     259                const double T21 = fT>0 ? fT : (tm0-fStartTime).total_microseconds()/1000000.;
     260                const double T10 = fT21;
     261                fT21 = T21;
    258262
    259263                fStartTime = tm0;
     
    310314                            // => Kd = 0.1  * gain/20s = 0.00003
    311315
    312                             fKp = 0;
    313                             fKd = 0;
    314                             fKi = 0.00003*20;
    315                             T21 = 1;
    316 
    317316                            //valarray<double> correction = - Kp*(PV[2] - PV[1]) + Ki * dT * (SP-PV[2]) - Kd/dT * (PV[2] - 2*PV[1] + PV[0]);
    318317                            //valarray<double> correction =
    319318                            //    - Kp*(PV[2] - PV[1]) + Ki * T21 * (SP-PV[2]) - Kd*(PV[2]-PV[1])/T21 - Kd*(PV[0]-PV[1])/T01;
    320                             const valarray<double> correction =
    321                                 - (fKp+fKd/T21)*(fPV[2] - fPV[1])
    322                                 +  fKi*T21*(fSP-fPV[2])
    323                                 +  fKd/T10*(fPV[1]-fPV[0]);
     319                            const valarray<double> correction = fGain/1000*
     320                                (
     321                                 - (fKp+fKd/T21)*(fPV[2] - fPV[1])
     322                                 +  fKi*T21*(fSP-fPV[2])
     323                                 +  fKd/T10*(fPV[1]-fPV[0])
     324                                );
    324325
    325326                            vector<float> vec(2*BIAS::kNumChannels);
     
    336337                                Info("Sending correction to feedback.");
    337338
    338                                 dic_cmnd_service("BIAS_CONTROL/ADD_REFERENCE_VOLTAGES",
     339                                dic_cmnd_service((char*)"BIAS_CONTROL/ADD_REFERENCE_VOLTAGES",
    339340                                                 (void*)(vec.data()+416), 416*sizeof(float));
    340341
     
    432433        switch (constant)
    433434        {
    434         case 0: fKi = evt.GetDouble(); break;
    435         case 1: fKp = evt.GetDouble(); break;
    436         case 2: fKd = evt.GetDouble(); break;
     435        case 0: fKi   = evt.GetDouble(); break;
     436        case 1: fKp   = evt.GetDouble(); break;
     437        case 2: fKd   = evt.GetDouble(); break;
     438        case 3: fT    = evt.GetDouble(); break;
     439        case 4: fGain = evt.GetDouble(); break;
    437440        default:
    438441            Fatal("SetConstant got an unexpected constant id -- this is a program bug!");
     
    526529        fFAD("FAD_CONTROL/STATE",       (void*)NULL, 0, this),
    527530        fBias("BIAS_CONTROL/STATE",     (void*)NULL, 0, this),
     531        fBiasData(0),
    528532        fDimReference("FEEDBACK/REFERENCE", "F:416",        ""),
    529533        fDimDeviation("FEEDBACK/DEVIATION", "F:416;F:416",  ""),
    530         fBiasData(NULL), fKp(0), fKi(0), fKd(0), fOutputEnabled(false)
     534        fKp(0), fKi(0), fKd(0), fT(-1), fOutputEnabled(false)
    531535    {
    532536        // ba::io_service::work is a kind of keep_alive for the loop.
     
    555559        AddEvent("START")//, kStateIdle)
    556560            (bind(&StateMachineFeedback::StartFeedback, this))
    557             ("");
     561            ("Start control loop");
    558562
    559563        AddEvent("STOP")//, kStateIdle)
    560564            (bind(&StateMachineFeedback::StopFeedback, this))
    561             ("");
     565            ("Stop control loop");
    562566
    563567        AddEvent("ENABLE_OUTPUT", "B:1")//, kStateIdle)
    564568            (bind(&StateMachineFeedback::EnableOutput, this, placeholders::_1))
    565             ("");
     569            ("Enable sending of correction values caluclated by the control loop to the biasctrl");
    566570
    567571        AddEvent("STORE_REFERENCE")//, kStateIdle)
    568572            (bind(&StateMachineFeedback::StoreReference, this))
    569             ("Stored the last (averaged) value as new reference (for debug purpose only)");
     573            ("Store the last (averaged) value as new reference (for debug purpose only)");
    570574
    571575        AddEvent("SET_Ki", "D:1")//, kStateIdle)
     
    580584            (bind(&StateMachineFeedback::SetConstant, this, placeholders::_1, 2))
    581585            ("Set derivative constant Kd");
     586
     587        AddEvent("SET_T", "D:1")//, kStateIdle)
     588            (bind(&StateMachineFeedback::SetConstant, this, placeholders::_1, 3))
     589            ("Set time-constant. (-1 to use the cycle time, i.e. the time for the last average cycle, instead)");
    582590
    583591        // Verbosity commands
     
    600608        }
    601609
     610        fGain = 5; // (BIAS)V / (DRS)V     ( 1V / 0.22V )
     611
     612        fKp = 0;
     613        fKd = 0;
     614        fKi = 0.12;
     615        fT  = 1;
     616
     617        ostringstream msg;
     618        msg << "Control loop parameters: ";
     619        msg << "Kp=" << fKp << ", Kd=" << fKd << ", Ki=" << fKi << ", ";
     620        if (fT>0)
     621            msg << fT;
     622        else
     623            msg << "<auto>";
     624        msg << ", Gain(BIAS/DRS)=" << fGain << "V/V";
     625
     626        Message(msg);
     627
    602628        return -1;
    603629    }
     
    616642void SetupConfiguration(Configuration &conf)
    617643{
    618     po::options_description control("BIAS control options");
     644    po::options_description control("Feedback options");
    619645    control.add_options()
    620646        ("pixel-map-file",  var<string>("FACTmapV5a.txt"), "Pixel mapping file. Used here to get the default reference voltage.")
     
    636662{
    637663    cout <<
    638         "The ftmctrl controls the FSC (FACT Slow Control) board.\n"
     664        "The feedback control the BIAS voltages based on the calibration signal.\n"
    639665        "\n"
    640666        "The default is that the program is started without user intercation. "
     
    643669        "help message about the usuage can be brought to the screen.\n"
    644670        "\n"
    645         "Usage: fscctrl [-c type] [OPTIONS]\n"
    646         "  or:  fscctrl [OPTIONS]\n";
     671        "Usage: feedback [-c type] [OPTIONS]\n"
     672        "  or:  feedback [OPTIONS]\n";
    647673    cout << endl;
    648674}
Note: See TracChangeset for help on using the changeset viewer.