Changeset 13922 for trunk/FACT++


Ignore:
Timestamp:
05/26/12 15:31:42 (12 years ago)
Author:
tbretz
Message:
Moved State definintions to header file and namespace.
Location:
trunk/FACT++/src
Files:
1 added
1 edited

Legend:

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

    r13873 r13922  
    1616
    1717#include "HeadersFAD.h"
     18#include "HeadersFSC.h"
    1819#include "HeadersBIAS.h"
    19 
    20 namespace ba    = boost::asio;
    21 namespace bs    = boost::system;
    22 namespace dummy = ba::placeholders;
     20#include "HeadersFeedback.h"
     21
     22#include "DimState.h"
     23#include "DimDescriptionService.h"
    2324
    2425using namespace std;
    25 
    26 // ------------------------------------------------------------------------
    27 
    28 #include "DimDescriptionService.h"
    29 #include "DimState.h"
    3026
    3127// ------------------------------------------------------------------------
     
    3430{
    3531private:
    36     enum states_t
    37     {
    38         kStateDimNetworkNA = 1,
    39         kStateDisconnected,
    40         kStateConnecting,
    41         kStateConnectedFSC,
    42         kStateConnectedFAD,
    43         kStateConnected,
    44         kStateTempCtrlIdle,      // 7
    45         kStateFeedbackCtrlIdle,  // 8
    46         kStateCurrentCtrlIdle,  // 9
    47         kStateTempCtrlRunning,  // 9->10
    48         kStateFeedbackCtrlRunning, // 10->11
    49         kStateCurrentCtrlRunning,  // 12
    50         kStateCalibrating,         // 11->13
    51     };
    52 
    5332    enum control_t
    5433    {
     
    138117        const double dUt = (avgt-25)*4./70; // [V]
    139118
    140         if (GetCurrentState()==kStateCalibrating && fBiasOffset>dUt-1.2)
     119        if (GetCurrentState()==Feedback::State::kCalibrating && fBiasOffset>dUt-1.2)
    141120        {
    142121            ostringstream msg;
     
    149128        // FIXME: If calibrating do not wait for the temperature!
    150129        fAppliedOffset = fBiasOffset;
    151         if (GetCurrentState()!=kStateCalibrating)
     130        if (GetCurrentState()!=Feedback::State::kCalibrating)
    152131            fAppliedOffset += dUt;
    153132
     
    275254        fDimDeviation.Update(vec);
    276255
    277         if (!fOutputEnabled || fDimBias.state()!=BIAS::kVoltageOn)
     256        if (!fOutputEnabled || fDimBias.state()!=BIAS::State::kVoltageOn)
    278257            return GetCurrentState();
    279258
    280259        // Trigger calibration
    281         if (GetCurrentState()==kStateCalibrating && fCursorTemp==1)
     260        if (GetCurrentState()==Feedback::State::kCalibrating && fCursorTemp==1)
    282261        {
    283262            DimClient::sendCommandNB("BIAS_CONTROL/REQUEST_STATUS", NULL, 0);
     
    321300            return -1;
    322301
    323         if (fDimBias.state()!=BIAS::kVoltageOn)
     302        if (fDimBias.state()!=BIAS::State::kVoltageOn)
    324303            return false;
    325304
     
    347326        if (fCursorCur<fNumCalibRequests)
    348327        {
    349             if (fDimBias.state()==BIAS::kVoltageOn)
     328            if (fDimBias.state()==BIAS::State::kVoltageOn)
    350329                DimClient::sendCommandNB("BIAS_CONTROL/REQUEST_STATUS", NULL, 0);
    351330            return;
     
    379358        Info("Calibration successfully done.");
    380359
    381         if (fDimBias.state()==BIAS::kVoltageOn)
     360        if (fDimBias.state()==BIAS::State::kVoltageOn)
    382361            DimClient::sendCommandNB("BIAS_CONTROL/REQUEST_STATUS", NULL, 0);
    383362    }
     
    582561        fDimDeviation.Update(vec);
    583562
    584         if (!fOutputEnabled || fDimBias.state()!=BIAS::kVoltageOn)
     563        if (!fOutputEnabled || fDimBias.state()!=BIAS::State::kVoltageOn)
    585564            return;
    586565
     
    715694        fDimDeviation.Update(vec);
    716695
    717         if (!fOutputEnabled || fDimBias.state()!=BIAS::kVoltageOn)
     696        if (!fOutputEnabled || fDimBias.state()!=BIAS::State::kVoltageOn)
    718697            return;
    719698
     
    726705    int HandleBiasCurrent(const EventImp &evt)
    727706    {
    728         if (fControlType==kTemp && GetCurrentState()==kStateCalibrating)
     707        if (fControlType==kTemp && GetCurrentState()==Feedback::State::kCalibrating)
    729708            HandleCalibration(evt);
    730709
     
    817796    void WarnState(bool needfsc, bool needfad)
    818797    {
    819         const bool bias = fDimBias.state() >= BIAS::kConnecting;
    820         const bool fsc  = fDimFSC.state()  >= 2;
    821         const bool fad  = fDimFAD.state()  >= FAD::kConnected;
     798        const bool bias = fDimBias.state() >= BIAS::State::kConnecting;
     799        const bool fsc  = fDimFSC.state()  >= FSC::State::kConnected;
     800        const bool fad  = fDimFAD.state()  >= FAD::State::kConnected;
    822801
    823802        if (!bias)
     
    931910        Message(out);
    932911
    933         if (fDimBias.state()==BIAS::kVoltageOn)
     912        if (fDimBias.state()==BIAS::State::kVoltageOn)
    934913            DimClient::sendCommandNB("BIAS_CONTROL/REQUEST_STATUS", NULL, 0);
    935914
     
    10221001//            return kSM_FatalError;
    10231002
    1024         if (fDimBias.state()==BIAS::kRamping)
     1003        if (fDimBias.state()==BIAS::State::kRamping)
    10251004        {
    10261005            Warn("Calibration cannot be started when biasctrl is in state Ramping.");
     
    10501029        fOutputEnabled = true;
    10511030
    1052         return kStateCalibrating;
     1031        return Feedback::State::kCalibrating;
    10531032    }
    10541033
     
    10751054
    10761055        if (!fDim.online())
    1077             return kStateDimNetworkNA;
    1078 
    1079         const bool bias = fDimBias.state() >= BIAS::kConnecting;
    1080         const bool fad  = fDimFAD.state()  >= FAD::kConnected;
    1081         const bool fsc  = fDimFSC.state()  >= 2;
     1056            return Feedback::State::kDimNetworkNA;
     1057
     1058        const bool bias = fDimBias.state() >= BIAS::State::kConnecting;
     1059        const bool fad  = fDimFAD.state()  >= FAD::State::kConnected;
     1060        const bool fsc  = fDimFSC.state()  >= FSC::State::kConnected;
    10821061
    10831062        // All subsystems are not connected
    10841063        if (!bias && !fad && !fsc)
    1085             return kStateDisconnected;
     1064            return Feedback::State::kDisconnected;
    10861065
    10871066        // At least one subsystem apart from bias is connected
    10881067        if (bias && !fad && !fsc)
    1089             return kStateConnecting;
     1068            return Feedback::State::kConnecting;
    10901069
    10911070/*
    10921071        // All subsystems are connected
    1093         if (GetCurrentStatus()==kStateConfiguringStep1)
     1072        if (GetCurrentStatus()==Feedback::State::kConfiguringStep1)
    10941073        {
    10951074            if (fCursor<1)
    1096                 return kStateConfiguringStep1;
     1075                return Feedback::State::kConfiguringStep1;
    10971076
    10981077            if (fCursor==1)
    10991078            {
    11001079                fStartTime = Time();
    1101                 return kStateConfiguringStep2;
     1080                return Feedback::State::kConfiguringStep2;
    11021081            }
    11031082        }
    1104         if (GetCurrentStatus()==kStateConfiguringStep2)
     1083        if (GetCurrentStatus()==Feedback::State::kConfiguringStep2)
    11051084        {
    11061085            if (fCursor==1)
    11071086            {
    11081087                if ((Time()-fStartTime).total_microseconds()/1000000.<1.5)
    1109                     return kStateConfiguringStep2;
     1088                    return Feedback::State::kConfiguringStep2;
    11101089
    11111090                Dim::SendCommand("BIAS_CONTROL/REQUEST_STATUS");
     
    11251104                cout << avg/n << endl;
    11261105            }
    1127             return kStateConnected;
     1106            return Feedback::State::kConnected;
    11281107        }
    11291108        */
     
    11331112        {
    11341113            if (fControlType==kFeedback || fControlType==kFeedbackGlobal)
    1135                 return fOutputEnabled ? kStateFeedbackCtrlRunning : kStateFeedbackCtrlIdle;
     1114                return fOutputEnabled ? Feedback::State::kFeedbackCtrlRunning : Feedback::State::kFeedbackCtrlIdle;
    11361115        }
    11371116
     
    11411120            if (fControlType==kTemp)
    11421121            {
    1143                 if (GetCurrentState()==kStateCalibrating && fCursorCur<fNumCalibRequests)
     1122                if (GetCurrentState()==Feedback::State::kCalibrating && fCursorCur<fNumCalibRequests)
    11441123                    return GetCurrentState();
    11451124
    1146                 return fOutputEnabled ? kStateTempCtrlRunning : kStateTempCtrlIdle;
     1125                return fOutputEnabled ? Feedback::State::kTempCtrlRunning : Feedback::State::kTempCtrlIdle;
    11471126            }
    11481127            if (fControlType==kCurrents)
     
    11511130                if (fCurrentRequestInterval>0 && Time()-past>boost::posix_time::milliseconds(fCurrentRequestInterval))
    11521131                {
    1153                     if (fDimBias.state()==BIAS::kVoltageOn)
     1132                    if (fDimBias.state()==BIAS::State::kVoltageOn)
    11541133                        DimClient::sendCommandNB("BIAS_CONTROL/REQUEST_STATUS", NULL, 0);
    11551134                    past = Time();
    11561135                }
    11571136
    1158                 return fOutputEnabled ? kStateCurrentCtrlRunning : kStateCurrentCtrlIdle;
     1137                return fOutputEnabled ? Feedback::State::kCurrentCtrlRunning : Feedback::State::kCurrentCtrlIdle;
    11591138            }
    11601139        }
    11611140
    11621141        if (bias && fad && !fsc)
    1163             return kStateConnectedFAD;
     1142            return Feedback::State::kConnectedFAD;
    11641143
    11651144        if (bias && fsc && !fad)
    1166             return kStateConnectedFSC;
    1167 
    1168         return kStateConnected;
     1145            return Feedback::State::kConnectedFSC;
     1146
     1147        return Feedback::State::kConnected;
    11691148    }
    11701149
     
    12181197
    12191198        // State names
    1220         AddStateName(kStateDimNetworkNA, "DimNetworkNotAvailable",
     1199        AddStateName(Feedback::State::kDimNetworkNA, "DimNetworkNotAvailable",
    12211200                     "The Dim DNS is not reachable.");
    12221201
    1223         AddStateName(kStateDisconnected, "Disconnected",
     1202        AddStateName(Feedback::State::kDisconnected, "Disconnected",
    12241203                     "The Dim DNS is reachable, but the required subsystems are not available.");
    12251204
    1226         AddStateName(kStateConnecting, "Connecting",
     1205        AddStateName(Feedback::State::kConnecting, "Connecting",
    12271206                     "Only biasctrl is available and connected with its hardware.");
    12281207
    1229         AddStateName(kStateConnectedFSC, "ConnectedFSC",
     1208        AddStateName(Feedback::State::kConnectedFSC, "ConnectedFSC",
    12301209                     "biasctrl and fscctrl are available and connected with their hardware.");
    1231         AddStateName(kStateConnectedFAD, "ConnectedFAD",
     1210        AddStateName(Feedback::State::kConnectedFAD, "ConnectedFAD",
    12321211                     "biasctrl and fadctrl are available and connected with their hardware.");
    1233         AddStateName(kStateConnected, "Connected",
     1212        AddStateName(Feedback::State::kConnected, "Connected",
    12341213                     "biasctrl, fadctrl and fscctrl are available and connected with their hardware.");
    12351214
    1236         AddStateName(kStateFeedbackCtrlIdle, "FeedbackIdle",
     1215        AddStateName(Feedback::State::kFeedbackCtrlIdle, "FeedbackIdle",
    12371216                     "Feedback control activated, but voltage output disabled.");
    1238         AddStateName(kStateTempCtrlIdle, "TempCtrlIdle",
     1217        AddStateName(Feedback::State::kTempCtrlIdle, "TempCtrlIdle",
    12391218                     "Temperature control activated, but voltage output disabled.");
    1240         AddStateName(kStateCurrentCtrlIdle, "CurrentCtrlIdle",
     1219        AddStateName(Feedback::State::kCurrentCtrlIdle, "CurrentCtrlIdle",
    12411220                     "Current control activated, but voltage output disabled.");
    12421221
    1243         AddStateName(kStateFeedbackCtrlRunning, "FeedbackControl",
     1222        AddStateName(Feedback::State::kFeedbackCtrlRunning, "FeedbackControl",
    12441223                     "Feedback control activated and voltage output enabled.");
    1245         AddStateName(kStateTempCtrlRunning, "TempControl",
     1224        AddStateName(Feedback::State::kTempCtrlRunning, "TempControl",
    12461225                     "Temperature control activated and voltage output enabled.");
    1247         AddStateName(kStateCurrentCtrlRunning, "CurrentControl",
     1226        AddStateName(Feedback::State::kCurrentCtrlRunning, "CurrentControl",
    12481227                     "Current/Temp control activated and voltage output enabled.");
    1249         AddStateName(kStateCalibrating, "Calibrating",
     1228        AddStateName(Feedback::State::kCalibrating, "Calibrating",
    12501229                     "Calibrating current offsets.");
    12511230
    1252         AddEvent("START_FEEDBACK_CONTROL", "S:1", kStateConnectedFAD, kStateConnected)
     1231        AddEvent("START_FEEDBACK_CONTROL", "S:1", Feedback::State::kConnectedFAD, Feedback::State::kConnected)
    12531232            (bind(&StateMachineFeedback::StartFeedback, this, placeholders::_1))
    12541233            ("Start the feedback control loop"
    12551234             "|Num[short]:Number of events 'medianed' to calculate the correction value");
    12561235
    1257         AddEvent("START_GLOBAL_FEEDBACK", "S:1", kStateConnectedFAD, kStateConnected)
     1236        AddEvent("START_GLOBAL_FEEDBACK", "S:1", Feedback::State::kConnectedFAD, Feedback::State::kConnected)
    12581237            (bind(&StateMachineFeedback::StartFeedbackGlobal, this, placeholders::_1))
    12591238            ("Start the global feedback control loop"
    12601239             "Num[short]:Number of events averaged to calculate the correction value");
    12611240
    1262         AddEvent("START_TEMP_CONTROL", "F:1", kStateConnectedFSC, kStateConnected)
     1241        AddEvent("START_TEMP_CONTROL", "F:1", Feedback::State::kConnectedFSC, Feedback::State::kConnected)
    12631242            (bind(&StateMachineFeedback::StartTempCtrl, this, placeholders::_1))
    12641243            ("Start the temperature control loop"
    12651244             "|offset[V]:Offset from the nominal temperature corrected value in Volts");
    12661245
    1267         AddEvent("START_CURRENT_CONTROL", "F:1", kStateConnectedFSC, kStateConnected)
     1246        AddEvent("START_CURRENT_CONTROL", "F:1", Feedback::State::kConnectedFSC, Feedback::State::kConnected)
    12681247            (bind(&StateMachineFeedback::StartCurrentCtrl, this, placeholders::_1))
    12691248            ("Start the current/temperature control loop"
    12701249             "|offset[V]:Offset from the nominal current/temperature corrected value in Volts");
    12711250
    1272         // kStateTempCtrlIdle, kStateFeedbackCtrlIdle, kStateTempCtrlRunning, kStateFeedbackCtrlRunning
     1251        // Feedback::State::kTempCtrlIdle, Feedback::State::kFeedbackCtrlIdle, Feedback::State::kTempCtrlRunning, Feedback::State::kFeedbackCtrlRunning
    12731252        AddEvent("STOP")
    12741253            (bind(&StateMachineFeedback::StopFeedback, this))
    12751254            ("Stop any control loop");
    12761255
    1277         AddEvent("ENABLE_OUTPUT", "B:1")//, kStateIdle)
     1256        AddEvent("ENABLE_OUTPUT", "B:1")//, Feedback::State::kIdle)
    12781257            (bind(&StateMachineFeedback::EnableOutput, this, placeholders::_1))
    12791258            ("Enable sending of correction values caluclated by the control loop to the biasctrl");
    12801259
    1281         AddEvent("STORE_REFERENCE")//, kStateIdle)
     1260        AddEvent("STORE_REFERENCE")//, Feedback::State::kIdle)
    12821261            (bind(&StateMachineFeedback::StoreReference, this))
    12831262            ("Store the last (averaged) value as new reference (for debug purpose only)");
    12841263
    1285         AddEvent("SET_REFERENCE", "F:1")//, kStateIdle)
     1264        AddEvent("SET_REFERENCE", "F:1")//, Feedback::State::kIdle)
    12861265            (bind(&StateMachineFeedback::SetReference, this, placeholders::_1))
    12871266            ("Set a new global reference value (for debug purpose only)");
    12881267
    1289         AddEvent("SET_Ki", "D:1")//, kStateIdle)
     1268        AddEvent("SET_Ki", "D:1")//, Feedback::State::kIdle)
    12901269            (bind(&StateMachineFeedback::SetConstant, this, placeholders::_1, 0))
    12911270            ("Set integral constant Ki");
    12921271
    1293         AddEvent("SET_Kp", "D:1")//, kStateIdle)
     1272        AddEvent("SET_Kp", "D:1")//, Feedback::State::kIdle)
    12941273            (bind(&StateMachineFeedback::SetConstant, this, placeholders::_1, 1))
    12951274            ("Set proportional constant Kp");
    12961275
    1297         AddEvent("SET_Kd", "D:1")//, kStateIdle)
     1276        AddEvent("SET_Kd", "D:1")//, Feedback::State::kIdle)
    12981277            (bind(&StateMachineFeedback::SetConstant, this, placeholders::_1, 2))
    12991278            ("Set derivative constant Kd");
    13001279
    1301         AddEvent("SET_T", "D:1")//, kStateIdle)
     1280        AddEvent("SET_T", "D:1")//, Feedback::State::kIdle)
    13021281            (bind(&StateMachineFeedback::SetConstant, this, placeholders::_1, 3))
    13031282            ("Set time-constant. (-1 to use the cycle time, i.e. the time for the last average cycle, instead)");
    13041283
    1305         AddEvent("CALIBRATE_CURRENTS", kStateConnectedFSC, kStateConnected)//, kStateIdle)
     1284        AddEvent("CALIBRATE_CURRENTS", Feedback::State::kConnectedFSC, Feedback::State::kConnected)//, Feedback::State::kIdle)
    13061285            (bind(&StateMachineFeedback::CalibrateCurrents, this))
    13071286            ("");
    13081287
    1309         AddEvent("SET_CURRENT_REQUEST_INTERVAL", kStateConnectedFSC, kStateConnected)//, kStateIdle)
     1288        AddEvent("SET_CURRENT_REQUEST_INTERVAL", Feedback::State::kConnectedFSC, Feedback::State::kConnected)//, Feedback::State::kIdle)
    13101289            (bind(&StateMachineFeedback::SetCurrentRequestInterval, this, placeholders::_1))
    13111290            ("|interval[ms]:Interval between two current requests in modes which need that.");
Note: See TracChangeset for help on using the changeset viewer.