Changeset 12183
- Timestamp:
- 10/17/11 12:33:31 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/feedback.cc
r12161 r12183 52 52 kStateConnecting, 53 53 kStateConnected, 54 kStateRunning, 55 kStateControlling, 54 kStateTempCtrlIdle, 55 kStateFeedbackCtrlIdle, 56 kStateTempCtrlRunning, 57 kStateFeedbackCtrlRunning, 56 58 }; 57 59 … … 62 64 pair<Time, int> fStatusDim; 63 65 pair<Time, int> fStatusFAD; 66 pair<Time, int> fStatusFSC; 64 67 pair<Time, int> fStatusBias; 65 68 66 69 DimStampedInfo fDim; 67 70 DimStampedInfo fFAD; 71 DimStampedInfo fFSC; 68 72 DimStampedInfo fBias; 69 73 70 74 DimStampedInfo *fBiasData; 75 DimStampedInfo *fCameraTemp; 71 76 72 77 DimDescribedService fDimReference; … … 144 149 } 145 150 151 if (curr==&fFSC) 152 { 153 fStatusFSC = GetNewState(fFSC); 154 return; 155 } 156 146 157 if (curr==&fDim) 147 158 { 148 159 fStatusDim = GetNewState(fDim); 149 160 fStatusDim.second = curr->getSize()==4 ? curr->getInt() : 0; 161 return; 162 } 163 164 if (curr==fCameraTemp) 165 { 166 if (curr->getSize()==0) 167 return; 168 if (curr->getSize()!=60*sizeof(float)) 169 return; 170 171 const float *ptr = (float*)curr->getData(); 172 173 double avg = 0; 174 int num = 0; 175 for (int i=1; i<32; i++) 176 if (ptr[i]!=0) 177 { 178 avg += ptr[i]; 179 num++; 180 } 181 182 if (num==0) 183 return; 184 185 const double diff = (25-avg)*0.057; 186 187 vector<float> vec(2*BIAS::kNumChannels); 188 for (int i=0; i<BIAS::kNumChannels; i++) 189 vec[i+416] = diff; 190 191 fDimDeviation.Update(vec); 192 193 if (fOutputEnabled) 194 { 195 Info("Sending correction to feedback."); 196 197 dic_cmnd_service((char*)"BIAS_CONTROL/SET_GAPD_REFERENCE_OFFSET", 198 (void*)&diff, sizeof(float)); 199 } 150 200 return; 151 201 } … … 465 515 } 466 516 517 int StartTempCtrl() 518 { 519 fCameraTemp = new DimStampedInfo("FSC_CONTROL/TEMPERATURE", (void*)NULL, 0, this); 520 521 return GetCurrentState(); 522 } 523 467 524 int StopFeedback() 468 525 { 469 delete fBiasData; 470 fBiasData = 0; 526 if (fBiasData) 527 { 528 delete fBiasData; 529 fBiasData = 0; 530 } 531 532 if (fCameraTemp) 533 { 534 delete fCameraTemp; 535 fCameraTemp = 0; 536 } 471 537 472 538 return GetCurrentState(); … … 494 560 for (int i=0; i<BIAS::kNumChannels; i++) 495 561 vec[i] = fSP[i]; 562 fDimReference.Update(vec); 563 564 return GetCurrentState(); 565 } 566 567 int SetReference(const EventImp &evt) 568 { 569 if (!CheckEventSize(evt.GetSize(), "SetReference", 4)) 570 return kSM_FatalError; 571 572 const float val = evt.GetFloat(); 573 if (!fPV[0].size() && !fPV[1].size() && !fPV[2].size()) 574 { 575 Warn("No values in memory. Take enough events first!"); 576 return GetCurrentState(); 577 } 578 579 vector<float> vec(BIAS::kNumChannels); 580 for (int i=0; i<BIAS::kNumChannels; i++) 581 vec[i] = fSP[i] = val; 496 582 fDimReference.Update(vec); 497 583 … … 512 598 return kStateDimNetworkNA; 513 599 514 if (fStatusFAD.second<FAD::kConnected && fStatusBias.second<BIAS::kConnecting) 600 // All subsystems are not connected 601 if (fStatusFAD.second<FAD::kConnected && 602 fStatusBias.second<BIAS::kConnecting && 603 fStatusFSC.second<2) 515 604 return kStateDisconnected; 516 605 517 if (fStatusFAD.second<FAD::kConnected && fStatusBias.second<BIAS::kConnected) 606 // At least one subsystem is not connected 607 if (fStatusFAD.second<FAD::kConnected || 608 fStatusBias.second<BIAS::kConnected || 609 fStatusFSC.second<2) 518 610 return kStateConnecting; 519 611 520 return fBiasData ? kStateRunning : kStateConnected; 612 // All subsystems are connected 613 614 if (fBiasData) 615 return fOutputEnabled ? kStateFeedbackCtrlRunning : kStateFeedbackCtrlIdle; 616 617 if (fCameraTemp) 618 return fOutputEnabled ? kStateTempCtrlRunning : kStateTempCtrlIdle; 619 620 return kStateConnected; 521 621 } 522 622 … … 528 628 fDim("DIS_DNS/VERSION_NUMBER", (void*)NULL, 0, this), 529 629 fFAD("FAD_CONTROL/STATE", (void*)NULL, 0, this), 630 fFSC("FSC_CONTROL/STATE", (void*)NULL, 0, this), 530 631 fBias("BIAS_CONTROL/STATE", (void*)NULL, 0, this), 531 fBiasData(0), 632 fBiasData(0), fCameraTemp(0), 532 633 fDimReference("FEEDBACK/REFERENCE", "F:416", ""), 533 634 fDimDeviation("FEEDBACK/DEVIATION", "F:416;F:416", ""), … … 543 644 // State names 544 645 AddStateName(kStateDimNetworkNA, "DimNetworkNotAvailable", 545 " .");646 "The Dim DNS is not reachable."); 546 647 547 648 AddStateName(kStateDisconnected, "Disconnected", 548 " .");649 "The Dim DNS is reachable, but the required subsystems are not available."); 549 650 550 651 AddStateName(kStateConnecting, "Connecting", 551 " .");652 "Not all subsystems (FAD, FSC, Bias) are connected to their hardware."); 552 653 553 654 AddStateName(kStateConnected, "Connected", 554 "."); 555 556 AddStateName(kStateRunning, "Running", 557 "."); 558 559 AddEvent("START")//, kStateIdle) 655 "All needed subsystems are connected to their hardware, no action is performed."); 656 657 AddStateName(kStateFeedbackCtrlIdle, "FeedbackIdle", 658 "Feedback control activated, but voltage output disabled."); 659 660 AddStateName(kStateTempCtrlIdle, "FeedbackIdle", 661 "Temperature control activated, but voltage output disabled."); 662 663 AddStateName(kStateFeedbackCtrlRunning, "FeedbackControl", 664 "Feedback control activated and voltage output enabled."); 665 666 AddStateName(kStateTempCtrlRunning, "TempControl", 667 "Temperature control activated and voltage output enabled."); 668 669 AddEvent("START_FEEDBACK_CONTROL", kStateConnected) 560 670 (bind(&StateMachineFeedback::StartFeedback, this)) 561 ("Start control loop"); 562 563 AddEvent("STOP")//, kStateIdle) 671 ("Start the feedback control loop"); 672 673 AddEvent("START_TEMP_CONTROL", kStateConnected) 674 (bind(&StateMachineFeedback::StartTempCtrl, this)) 675 ("Start the temperature control loop"); 676 677 AddEvent("STOP", kStateTempCtrlIdle, kStateFeedbackCtrlIdle, kStateTempCtrlRunning, kStateFeedbackCtrlRunning) 564 678 (bind(&StateMachineFeedback::StopFeedback, this)) 565 ("Stop control loop");679 ("Stop any control loop"); 566 680 567 681 AddEvent("ENABLE_OUTPUT", "B:1")//, kStateIdle) … … 572 686 (bind(&StateMachineFeedback::StoreReference, this)) 573 687 ("Store the last (averaged) value as new reference (for debug purpose only)"); 688 689 AddEvent("SET_REFERENCE", "F:1")//, kStateIdle) 690 (bind(&StateMachineFeedback::SetReference, this, placeholders::_1)) 691 ("Set a new global reference value (for debug purpose only)"); 574 692 575 693 AddEvent("SET_Ki", "D:1")//, kStateIdle)
Note:
See TracChangeset
for help on using the changeset viewer.