Changeset 13922 for trunk/FACT++
- Timestamp:
- 05/26/12 15:31:42 (12 years ago)
- Location:
- trunk/FACT++/src
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/feedback.cc
r13873 r13922 16 16 17 17 #include "HeadersFAD.h" 18 #include "HeadersFSC.h" 18 19 #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" 23 24 24 25 using namespace std; 25 26 // ------------------------------------------------------------------------27 28 #include "DimDescriptionService.h"29 #include "DimState.h"30 26 31 27 // ------------------------------------------------------------------------ … … 34 30 { 35 31 private: 36 enum states_t37 {38 kStateDimNetworkNA = 1,39 kStateDisconnected,40 kStateConnecting,41 kStateConnectedFSC,42 kStateConnectedFAD,43 kStateConnected,44 kStateTempCtrlIdle, // 745 kStateFeedbackCtrlIdle, // 846 kStateCurrentCtrlIdle, // 947 kStateTempCtrlRunning, // 9->1048 kStateFeedbackCtrlRunning, // 10->1149 kStateCurrentCtrlRunning, // 1250 kStateCalibrating, // 11->1351 };52 53 32 enum control_t 54 33 { … … 138 117 const double dUt = (avgt-25)*4./70; // [V] 139 118 140 if (GetCurrentState()== kStateCalibrating && fBiasOffset>dUt-1.2)119 if (GetCurrentState()==Feedback::State::kCalibrating && fBiasOffset>dUt-1.2) 141 120 { 142 121 ostringstream msg; … … 149 128 // FIXME: If calibrating do not wait for the temperature! 150 129 fAppliedOffset = fBiasOffset; 151 if (GetCurrentState()!= kStateCalibrating)130 if (GetCurrentState()!=Feedback::State::kCalibrating) 152 131 fAppliedOffset += dUt; 153 132 … … 275 254 fDimDeviation.Update(vec); 276 255 277 if (!fOutputEnabled || fDimBias.state()!=BIAS:: kVoltageOn)256 if (!fOutputEnabled || fDimBias.state()!=BIAS::State::kVoltageOn) 278 257 return GetCurrentState(); 279 258 280 259 // Trigger calibration 281 if (GetCurrentState()== kStateCalibrating && fCursorTemp==1)260 if (GetCurrentState()==Feedback::State::kCalibrating && fCursorTemp==1) 282 261 { 283 262 DimClient::sendCommandNB("BIAS_CONTROL/REQUEST_STATUS", NULL, 0); … … 321 300 return -1; 322 301 323 if (fDimBias.state()!=BIAS:: kVoltageOn)302 if (fDimBias.state()!=BIAS::State::kVoltageOn) 324 303 return false; 325 304 … … 347 326 if (fCursorCur<fNumCalibRequests) 348 327 { 349 if (fDimBias.state()==BIAS:: kVoltageOn)328 if (fDimBias.state()==BIAS::State::kVoltageOn) 350 329 DimClient::sendCommandNB("BIAS_CONTROL/REQUEST_STATUS", NULL, 0); 351 330 return; … … 379 358 Info("Calibration successfully done."); 380 359 381 if (fDimBias.state()==BIAS:: kVoltageOn)360 if (fDimBias.state()==BIAS::State::kVoltageOn) 382 361 DimClient::sendCommandNB("BIAS_CONTROL/REQUEST_STATUS", NULL, 0); 383 362 } … … 582 561 fDimDeviation.Update(vec); 583 562 584 if (!fOutputEnabled || fDimBias.state()!=BIAS:: kVoltageOn)563 if (!fOutputEnabled || fDimBias.state()!=BIAS::State::kVoltageOn) 585 564 return; 586 565 … … 715 694 fDimDeviation.Update(vec); 716 695 717 if (!fOutputEnabled || fDimBias.state()!=BIAS:: kVoltageOn)696 if (!fOutputEnabled || fDimBias.state()!=BIAS::State::kVoltageOn) 718 697 return; 719 698 … … 726 705 int HandleBiasCurrent(const EventImp &evt) 727 706 { 728 if (fControlType==kTemp && GetCurrentState()== kStateCalibrating)707 if (fControlType==kTemp && GetCurrentState()==Feedback::State::kCalibrating) 729 708 HandleCalibration(evt); 730 709 … … 817 796 void WarnState(bool needfsc, bool needfad) 818 797 { 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; 822 801 823 802 if (!bias) … … 931 910 Message(out); 932 911 933 if (fDimBias.state()==BIAS:: kVoltageOn)912 if (fDimBias.state()==BIAS::State::kVoltageOn) 934 913 DimClient::sendCommandNB("BIAS_CONTROL/REQUEST_STATUS", NULL, 0); 935 914 … … 1022 1001 // return kSM_FatalError; 1023 1002 1024 if (fDimBias.state()==BIAS:: kRamping)1003 if (fDimBias.state()==BIAS::State::kRamping) 1025 1004 { 1026 1005 Warn("Calibration cannot be started when biasctrl is in state Ramping."); … … 1050 1029 fOutputEnabled = true; 1051 1030 1052 return kStateCalibrating;1031 return Feedback::State::kCalibrating; 1053 1032 } 1054 1033 … … 1075 1054 1076 1055 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; 1082 1061 1083 1062 // All subsystems are not connected 1084 1063 if (!bias && !fad && !fsc) 1085 return kStateDisconnected;1064 return Feedback::State::kDisconnected; 1086 1065 1087 1066 // At least one subsystem apart from bias is connected 1088 1067 if (bias && !fad && !fsc) 1089 return kStateConnecting;1068 return Feedback::State::kConnecting; 1090 1069 1091 1070 /* 1092 1071 // All subsystems are connected 1093 if (GetCurrentStatus()== kStateConfiguringStep1)1072 if (GetCurrentStatus()==Feedback::State::kConfiguringStep1) 1094 1073 { 1095 1074 if (fCursor<1) 1096 return kStateConfiguringStep1;1075 return Feedback::State::kConfiguringStep1; 1097 1076 1098 1077 if (fCursor==1) 1099 1078 { 1100 1079 fStartTime = Time(); 1101 return kStateConfiguringStep2;1080 return Feedback::State::kConfiguringStep2; 1102 1081 } 1103 1082 } 1104 if (GetCurrentStatus()== kStateConfiguringStep2)1083 if (GetCurrentStatus()==Feedback::State::kConfiguringStep2) 1105 1084 { 1106 1085 if (fCursor==1) 1107 1086 { 1108 1087 if ((Time()-fStartTime).total_microseconds()/1000000.<1.5) 1109 return kStateConfiguringStep2;1088 return Feedback::State::kConfiguringStep2; 1110 1089 1111 1090 Dim::SendCommand("BIAS_CONTROL/REQUEST_STATUS"); … … 1125 1104 cout << avg/n << endl; 1126 1105 } 1127 return kStateConnected;1106 return Feedback::State::kConnected; 1128 1107 } 1129 1108 */ … … 1133 1112 { 1134 1113 if (fControlType==kFeedback || fControlType==kFeedbackGlobal) 1135 return fOutputEnabled ? kStateFeedbackCtrlRunning : kStateFeedbackCtrlIdle;1114 return fOutputEnabled ? Feedback::State::kFeedbackCtrlRunning : Feedback::State::kFeedbackCtrlIdle; 1136 1115 } 1137 1116 … … 1141 1120 if (fControlType==kTemp) 1142 1121 { 1143 if (GetCurrentState()== kStateCalibrating && fCursorCur<fNumCalibRequests)1122 if (GetCurrentState()==Feedback::State::kCalibrating && fCursorCur<fNumCalibRequests) 1144 1123 return GetCurrentState(); 1145 1124 1146 return fOutputEnabled ? kStateTempCtrlRunning : kStateTempCtrlIdle;1125 return fOutputEnabled ? Feedback::State::kTempCtrlRunning : Feedback::State::kTempCtrlIdle; 1147 1126 } 1148 1127 if (fControlType==kCurrents) … … 1151 1130 if (fCurrentRequestInterval>0 && Time()-past>boost::posix_time::milliseconds(fCurrentRequestInterval)) 1152 1131 { 1153 if (fDimBias.state()==BIAS:: kVoltageOn)1132 if (fDimBias.state()==BIAS::State::kVoltageOn) 1154 1133 DimClient::sendCommandNB("BIAS_CONTROL/REQUEST_STATUS", NULL, 0); 1155 1134 past = Time(); 1156 1135 } 1157 1136 1158 return fOutputEnabled ? kStateCurrentCtrlRunning : kStateCurrentCtrlIdle;1137 return fOutputEnabled ? Feedback::State::kCurrentCtrlRunning : Feedback::State::kCurrentCtrlIdle; 1159 1138 } 1160 1139 } 1161 1140 1162 1141 if (bias && fad && !fsc) 1163 return kStateConnectedFAD;1142 return Feedback::State::kConnectedFAD; 1164 1143 1165 1144 if (bias && fsc && !fad) 1166 return kStateConnectedFSC;1167 1168 return kStateConnected;1145 return Feedback::State::kConnectedFSC; 1146 1147 return Feedback::State::kConnected; 1169 1148 } 1170 1149 … … 1218 1197 1219 1198 // State names 1220 AddStateName( kStateDimNetworkNA, "DimNetworkNotAvailable",1199 AddStateName(Feedback::State::kDimNetworkNA, "DimNetworkNotAvailable", 1221 1200 "The Dim DNS is not reachable."); 1222 1201 1223 AddStateName( kStateDisconnected, "Disconnected",1202 AddStateName(Feedback::State::kDisconnected, "Disconnected", 1224 1203 "The Dim DNS is reachable, but the required subsystems are not available."); 1225 1204 1226 AddStateName( kStateConnecting, "Connecting",1205 AddStateName(Feedback::State::kConnecting, "Connecting", 1227 1206 "Only biasctrl is available and connected with its hardware."); 1228 1207 1229 AddStateName( kStateConnectedFSC, "ConnectedFSC",1208 AddStateName(Feedback::State::kConnectedFSC, "ConnectedFSC", 1230 1209 "biasctrl and fscctrl are available and connected with their hardware."); 1231 AddStateName( kStateConnectedFAD, "ConnectedFAD",1210 AddStateName(Feedback::State::kConnectedFAD, "ConnectedFAD", 1232 1211 "biasctrl and fadctrl are available and connected with their hardware."); 1233 AddStateName( kStateConnected, "Connected",1212 AddStateName(Feedback::State::kConnected, "Connected", 1234 1213 "biasctrl, fadctrl and fscctrl are available and connected with their hardware."); 1235 1214 1236 AddStateName( kStateFeedbackCtrlIdle, "FeedbackIdle",1215 AddStateName(Feedback::State::kFeedbackCtrlIdle, "FeedbackIdle", 1237 1216 "Feedback control activated, but voltage output disabled."); 1238 AddStateName( kStateTempCtrlIdle, "TempCtrlIdle",1217 AddStateName(Feedback::State::kTempCtrlIdle, "TempCtrlIdle", 1239 1218 "Temperature control activated, but voltage output disabled."); 1240 AddStateName( kStateCurrentCtrlIdle, "CurrentCtrlIdle",1219 AddStateName(Feedback::State::kCurrentCtrlIdle, "CurrentCtrlIdle", 1241 1220 "Current control activated, but voltage output disabled."); 1242 1221 1243 AddStateName( kStateFeedbackCtrlRunning, "FeedbackControl",1222 AddStateName(Feedback::State::kFeedbackCtrlRunning, "FeedbackControl", 1244 1223 "Feedback control activated and voltage output enabled."); 1245 AddStateName( kStateTempCtrlRunning, "TempControl",1224 AddStateName(Feedback::State::kTempCtrlRunning, "TempControl", 1246 1225 "Temperature control activated and voltage output enabled."); 1247 AddStateName( kStateCurrentCtrlRunning, "CurrentControl",1226 AddStateName(Feedback::State::kCurrentCtrlRunning, "CurrentControl", 1248 1227 "Current/Temp control activated and voltage output enabled."); 1249 AddStateName( kStateCalibrating, "Calibrating",1228 AddStateName(Feedback::State::kCalibrating, "Calibrating", 1250 1229 "Calibrating current offsets."); 1251 1230 1252 AddEvent("START_FEEDBACK_CONTROL", "S:1", kStateConnectedFAD, kStateConnected)1231 AddEvent("START_FEEDBACK_CONTROL", "S:1", Feedback::State::kConnectedFAD, Feedback::State::kConnected) 1253 1232 (bind(&StateMachineFeedback::StartFeedback, this, placeholders::_1)) 1254 1233 ("Start the feedback control loop" 1255 1234 "|Num[short]:Number of events 'medianed' to calculate the correction value"); 1256 1235 1257 AddEvent("START_GLOBAL_FEEDBACK", "S:1", kStateConnectedFAD, kStateConnected)1236 AddEvent("START_GLOBAL_FEEDBACK", "S:1", Feedback::State::kConnectedFAD, Feedback::State::kConnected) 1258 1237 (bind(&StateMachineFeedback::StartFeedbackGlobal, this, placeholders::_1)) 1259 1238 ("Start the global feedback control loop" 1260 1239 "Num[short]:Number of events averaged to calculate the correction value"); 1261 1240 1262 AddEvent("START_TEMP_CONTROL", "F:1", kStateConnectedFSC, kStateConnected)1241 AddEvent("START_TEMP_CONTROL", "F:1", Feedback::State::kConnectedFSC, Feedback::State::kConnected) 1263 1242 (bind(&StateMachineFeedback::StartTempCtrl, this, placeholders::_1)) 1264 1243 ("Start the temperature control loop" 1265 1244 "|offset[V]:Offset from the nominal temperature corrected value in Volts"); 1266 1245 1267 AddEvent("START_CURRENT_CONTROL", "F:1", kStateConnectedFSC, kStateConnected)1246 AddEvent("START_CURRENT_CONTROL", "F:1", Feedback::State::kConnectedFSC, Feedback::State::kConnected) 1268 1247 (bind(&StateMachineFeedback::StartCurrentCtrl, this, placeholders::_1)) 1269 1248 ("Start the current/temperature control loop" 1270 1249 "|offset[V]:Offset from the nominal current/temperature corrected value in Volts"); 1271 1250 1272 // kStateTempCtrlIdle, kStateFeedbackCtrlIdle, kStateTempCtrlRunning, kStateFeedbackCtrlRunning1251 // Feedback::State::kTempCtrlIdle, Feedback::State::kFeedbackCtrlIdle, Feedback::State::kTempCtrlRunning, Feedback::State::kFeedbackCtrlRunning 1273 1252 AddEvent("STOP") 1274 1253 (bind(&StateMachineFeedback::StopFeedback, this)) 1275 1254 ("Stop any control loop"); 1276 1255 1277 AddEvent("ENABLE_OUTPUT", "B:1")//, kStateIdle)1256 AddEvent("ENABLE_OUTPUT", "B:1")//, Feedback::State::kIdle) 1278 1257 (bind(&StateMachineFeedback::EnableOutput, this, placeholders::_1)) 1279 1258 ("Enable sending of correction values caluclated by the control loop to the biasctrl"); 1280 1259 1281 AddEvent("STORE_REFERENCE")//, kStateIdle)1260 AddEvent("STORE_REFERENCE")//, Feedback::State::kIdle) 1282 1261 (bind(&StateMachineFeedback::StoreReference, this)) 1283 1262 ("Store the last (averaged) value as new reference (for debug purpose only)"); 1284 1263 1285 AddEvent("SET_REFERENCE", "F:1")//, kStateIdle)1264 AddEvent("SET_REFERENCE", "F:1")//, Feedback::State::kIdle) 1286 1265 (bind(&StateMachineFeedback::SetReference, this, placeholders::_1)) 1287 1266 ("Set a new global reference value (for debug purpose only)"); 1288 1267 1289 AddEvent("SET_Ki", "D:1")//, kStateIdle)1268 AddEvent("SET_Ki", "D:1")//, Feedback::State::kIdle) 1290 1269 (bind(&StateMachineFeedback::SetConstant, this, placeholders::_1, 0)) 1291 1270 ("Set integral constant Ki"); 1292 1271 1293 AddEvent("SET_Kp", "D:1")//, kStateIdle)1272 AddEvent("SET_Kp", "D:1")//, Feedback::State::kIdle) 1294 1273 (bind(&StateMachineFeedback::SetConstant, this, placeholders::_1, 1)) 1295 1274 ("Set proportional constant Kp"); 1296 1275 1297 AddEvent("SET_Kd", "D:1")//, kStateIdle)1276 AddEvent("SET_Kd", "D:1")//, Feedback::State::kIdle) 1298 1277 (bind(&StateMachineFeedback::SetConstant, this, placeholders::_1, 2)) 1299 1278 ("Set derivative constant Kd"); 1300 1279 1301 AddEvent("SET_T", "D:1")//, kStateIdle)1280 AddEvent("SET_T", "D:1")//, Feedback::State::kIdle) 1302 1281 (bind(&StateMachineFeedback::SetConstant, this, placeholders::_1, 3)) 1303 1282 ("Set time-constant. (-1 to use the cycle time, i.e. the time for the last average cycle, instead)"); 1304 1283 1305 AddEvent("CALIBRATE_CURRENTS", kStateConnectedFSC, kStateConnected)//, kStateIdle)1284 AddEvent("CALIBRATE_CURRENTS", Feedback::State::kConnectedFSC, Feedback::State::kConnected)//, Feedback::State::kIdle) 1306 1285 (bind(&StateMachineFeedback::CalibrateCurrents, this)) 1307 1286 (""); 1308 1287 1309 AddEvent("SET_CURRENT_REQUEST_INTERVAL", kStateConnectedFSC, kStateConnected)//, kStateIdle)1288 AddEvent("SET_CURRENT_REQUEST_INTERVAL", Feedback::State::kConnectedFSC, Feedback::State::kConnected)//, Feedback::State::kIdle) 1310 1289 (bind(&StateMachineFeedback::SetCurrentRequestInterval, this, placeholders::_1)) 1311 1290 ("|interval[ms]:Interval between two current requests in modes which need that.");
Note:
See TracChangeset
for help on using the changeset viewer.