Changeset 13497 for trunk/FACT++/src


Ignore:
Timestamp:
05/01/12 14:27:04 (12 years ago)
Author:
tbretz
Message:
Added current calibration; some updates to the colors
File:
1 edited

Legend:

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

    r13483 r13497  
    6262    DimStampedInfo fDimMagicWeatherData;
    6363
     64    DimStampedInfo fDimFeedback;
    6465    DimStampedInfo fDimFeedbackCalibration;
    6566
     
    7576    enum weather_t { kTemp = 0, kDew, kHum, kPress, kWind, kGusts, kDir };
    7677    float fMagicWeatherData[7];
     78
     79    vector<float> fFeedbackCalibration;
     80    vector<float> fBiasControlVoltageVec;
    7781
    7882    float  fBiasControlVoltageMed;
     
    231235    void HandleFeedbackCalibration(const DimData &d)
    232236    {
     237        if (!CheckDataSize(d, "Feedback:Calibration", 3*4*416))
     238        {
     239            fFeedbackCalibration.clear();
     240            return;
     241        }
     242
     243        const float *ptr = d.ptr<float>();
     244        fFeedbackCalibration.assign(ptr+2*416, ptr+3*416);
     245    }
     246
     247    void HandleBiasControlVoltage(const DimData &d)
     248    {
    233249        if (!CheckDataSize(d, "BiasControl:Voltage", 1664))
    234             return;
    235 
    236         vector<float> v(d.ptr<float>(), d.ptr<float>()+320);
     250        {
     251            fBiasControlVoltageVec.clear();
     252            return;
     253        }
     254
     255        fBiasControlVoltageVec.assign(d.ptr<float>(), d.ptr<float>()+320);
     256
     257        vector<float> v(fBiasControlVoltageVec);
    237258        sort(v.begin(), v.end());
    238259
     
    245266    }
    246267
    247     void HandleBiasControlVoltage(const DimData &d)
    248     {
    249         if (!CheckDataSize(d, "BiasControl:Voltage", 1664))
    250             return;
    251 
    252         vector<float> v(d.ptr<float>(), d.ptr<float>()+320);
    253         sort(v.begin(), v.end());
    254 
    255         fBiasControlVoltageMed = (v[159]+v[160])/2;
    256 
    257         const char *ptr = d.ptr<char>();
    258 
    259         ofstream fout("www/biascontrol-voltage.bin");
    260         fout.write(ptr, 320*sizeof(float));
    261     }
    262 
    263268    void HandleBiasControlCurrent(const DimData &d)
    264269    {
     
    266271            return;
    267272
    268         vector<uint16_t> v(d.ptr<uint16_t>(), d.ptr<uint16_t>()+320);
     273        vector<float> v(320);
     274        for (int i=0; i<320; i++)
     275            v[i] = d.ptr<uint16_t>()[i];
     276
     277        if (fFeedbackCalibration.size()>0 && fBiasControlVoltageVec.size()>0)
     278            for (int i=0; i<320; i++)
     279                v[i] -= fBiasControlVoltageVec[i]/fFeedbackCalibration[i]*1e6;
     280
     281        vector<uint8_t> val(160, 0);
     282        for (int i=0; i<160; i++)
     283        {
     284            const float I = max(v[i*2], v[i*2+1]);
     285
     286            float range = nearbyint(128*I/1000); // [0, 1000uA]
     287            if (range>127)
     288                range=127;
     289            if (range<0)
     290                range=0;
     291            val[i] = (uint8_t)range;
     292        }
     293
    269294        sort(v.begin(), v.end());
    270295
     
    273298        fBiasControlCurrentMax = v[316]            * 5000./4096;
    274299
    275         const char *ptr = d.ptr<char>();
     300        const char *ptr = reinterpret_cast<char*>(val.data());
    276301
    277302        ofstream fout("www/biascontrol-current.bin");
    278         fout.write(ptr, 320*sizeof(uint16_t));
     303        fout.write(ptr, 160*sizeof(uint8_t));
    279304    }
    280305
     
    425450        out << "n/a\n";
    426451
     452        const static string kWhite  = "#ffffff";
     453        const static string kYellow = "#fffff0";
     454        const static string kRed    = "#fff8f0";
     455        const static string kGreen  = "#f0fff0";
     456        const static string kBlue   = "#f0f0ff";
     457
    427458        // ------------------ Drive -----------------
    428459        if (fStatusDriveControl.second>=5)   // Armed, Moving, Tracking
    429460        {
    430461            const State rc = fNetwork.GetState("DRIVE_CONTROL", fStatusDriveControl.second);
    431             out << "#ffffff\t";
     462            out << kWhite << "\t";
    432463            out << rc.name << '\t';
    433464            out << fDriveControlPointingZd  << '\t';
     
    437468        }
    438469        else
    439             out << "#ffffff\t\t\t\t\t\n";
     470            out << kWhite << "\t\t\t\t\t\n";
    440471
    441472        // --------------- MagicWeather -------------
     
    443474        {
    444475            const float diff = fMagicWeatherData[kTemp]-fMagicWeatherData[kDew];
    445             string col1 = "#fff8f0";
     476            string col1 = kRed;
    446477            if (diff>0.3)
    447                 col1="#fffff0";
     478                col1 = kYellow;
    448479            if (diff>0.7)
    449                 col1="#f0fff0";
     480                col1 = kGreen;
    450481
    451482            const float wind = fMagicWeatherData[kGusts];
    452             string col2 = "#f0fff0";
     483            string col2 = kGreen;
    453484            if (wind>35)
    454                 col2="#fffff0";
     485                col2 = kYellow;
    455486            if (wind>50)
    456                 col2="#fff8f0";
     487                col2 = kRed;
    457488
    458489            out << col1 << "\t";
     
    463494        }
    464495        else
    465             out << "#ffffff\t\t\n\n";
     496            out << kWhite << "\t\t\n\n";
    466497
    467498        // --------------- BiasControl -------------
     
    470501            fStatusBiasControl.second==9)   // Off
    471502        {
    472             string col = fBiasControlVoltageMed>3?"#fff8f0":"#ffffff";
     503            string col = fBiasControlVoltageMed>3?kGreen:kWhite;
    473504            if (fBiasControlCurrentMax>280)
    474                 col = "#fffff0";
     505                col = kYellow;
    475506            if (fBiasControlCurrentMax>350)
    476                 col = "#fff8f0";
     507                col = kRed;
     508
     509            if (fFeedbackCalibration.size()==0)
     510                col = kBlue;
    477511
    478512            out << col << "\t";
     
    482516        }
    483517        else
    484             out << "#ffffff\t\t\t\n";
     518            out << kWhite << "\t\t\t\n";
    485519
    486520
Note: See TracChangeset for help on using the changeset viewer.