Changeset 12399 for trunk/FACT++
- Timestamp:
- 11/05/11 21:04:10 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/feedback.cc
r12351 r12399 56 56 kStateTempCtrlRunning, 57 57 kStateFeedbackCtrlRunning, 58 kStateCalibrating, 58 59 }; 59 60 … … 80 81 DimStampedInfo fFSC; 81 82 DimStampedInfo fBias; 83 DimStampedInfo fBiasA; 82 84 83 85 DimStampedInfo fBiasData; … … 86 88 DimDescribedService fDimReference; 87 89 DimDescribedService fDimDeviation; 90 DimDescribedService fDimCalibration; 91 92 vector<int64_t> fCurrentsAvg; 93 vector<int64_t> fCurrentsRms; 88 94 89 95 vector<vector<float>> fData; … … 175 181 if (curr==&fCameraTemp) 176 182 { 177 if (curr->getSize()==0)178 return;179 183 if (curr->getSize()!=60*sizeof(float)) 180 184 return; 181 185 182 const float *ptr = (float*)curr->getData();186 const float *ptr = static_cast<float*>(curr->getData()); 183 187 184 188 double avg = 0; … … 215 219 (void*)&diff, sizeof(float)); 216 220 } 217 return; 221 } 222 223 if (curr==&fBiasA && fControlType==kTemp && GetCurrentState()==kStateCalibrating) 224 { 225 if (curr->getSize()!=416*sizeof(int16_t)) 226 return; 227 228 if (fStatusBias.second==BIAS::kRamping) 229 return; 230 231 const int16_t *ptr = static_cast<int16_t*>(curr->getData()); 232 233 for (int i=0; i<416; i++) 234 if (ptr[i]>0) 235 { 236 fCurrentsAvg[i] += ptr[i]; 237 fCurrentsRms[i] += ptr[i]*ptr[i]; 238 } 239 240 if (++fCursor<100) 241 { 242 DimClient::sendCommandNB("BIAS_CONTROL/REQUEST_STATUS", NULL, 0); 243 return; 244 } 245 246 vector<float> val(2*416, 0); 247 for (int i=0; i<416; i++) 248 { 249 val[i] = double(fCurrentsAvg[i])/fCursor; 250 val[i+416] = sqrt(double(fCurrentsRms[i])/fCursor-val[i]*val[i]); 251 } 252 253 fDimCalibration.Update(val); 254 255 fOutputEnabled = false; 256 fControlType = kIdle; 218 257 } 219 258 220 259 if (curr==&fBiasData && fControlType==kFeedback) 221 260 { 222 if (curr->getSize()==0)223 return;224 261 if (curr->getSize()!=1440*sizeof(float)) 225 262 return; … … 443 480 444 481 } 445 446 /*447 vector<float> correction(416);448 vector<float> response(416);449 vector<float> dev(416);450 451 double gain = 0;452 453 for (int j=0; j<416; j++)454 {455 //avg[j] /= fData.size();456 //rms[j] /= sqrt((rms[j]*fData.size() - avg[j]*avg[j]))/fData.size();457 458 dev[j] = avg[j] - target[j];459 460 // Determine correction from response maxtrix and change voltages461 correction[j] = -dev[j]*response[j]*gain;462 463 if (correction[j]==0)464 continue;465 466 // Limit voltage steps // Limit changes to 100 mV467 // if (fabs(correction[j]) > 0.1)468 // correction[j] = 0.1*fabs(correction[j])/correction[j];469 470 // Add voltage change command if not too noisy471 // if (fabs(Average[i]) > 2*Sigma[i])472 // Cmd << fIDTable[i] << " " << std::showpos << Correction/Multiplicity[i] << " ";473 474 }475 */476 return;477 482 } 478 483 … … 624 629 } 625 630 631 int CalibrateCurrents() 632 { 633 // if (!CheckEventSize(evt.GetSize(), "StartTempCtrl", 4)) 634 // return kSM_FatalError; 635 636 ostringstream out; 637 out << "Starting temperature feedback with an offset of -2V"; 638 Message(out); 639 640 fBiasOffset = -2; 641 fControlType = kTemp; 642 fCursor = 0; 643 fCurrentsAvg.assign(416, 0); 644 fCurrentsRms.assign(416, 0); 645 fStartTime = Time(); 646 fOutputEnabled = true; 647 648 return kStateCalibrating; 649 } 626 650 627 651 int Execute() … … 649 673 return kStateConnecting; 650 674 675 if (GetCurrentState()==kStateCalibrating && fCursor<100) 676 return GetCurrentState(); 677 678 /* 651 679 // All subsystems are connected 652 680 if (GetCurrentStatus()==kStateConfiguringStep1) 681 { 682 if (fCursor<1) 683 return kStateConfiguringStep1; 684 685 if (fCursor==1) 686 { 687 fStartTime = Time(); 688 return kStateConfiguringStep2; 689 } 690 } 691 if (GetCurrentStatus()==kStateConfiguringStep2) 692 { 693 if (fCursor==1) 694 { 695 if ((Time()-fStartTime).total_microseconds()/1000000.<1.5) 696 return kStateConfiguringStep2; 697 698 Dim::SendCommand("BIAS_CONTROL/REQUEST_STATUS"); 699 } 700 if (fCursor==2) 701 { 702 703 int n=0; 704 double avg = 0; 705 for (size_t i=0; i<fCurrents.size(); i++) 706 if (fCurrents[i]>=0) 707 { 708 avg += fCurrents[i]; 709 n++; 710 } 711 712 cout << avg/n << endl; 713 } 714 return kStateConnected; 715 } 716 */ 653 717 if (fControlType==kFeedback) 654 718 return fOutputEnabled ? kStateFeedbackCtrlRunning : kStateFeedbackCtrlIdle; … … 669 733 fFSC("FSC_CONTROL/STATE", (void*)NULL, 0, this), 670 734 fBias("BIAS_CONTROL/STATE", (void*)NULL, 0, this), 735 fBiasA("BIAS_CONTROL/CURRENT", (void*)NULL, 0, this), 671 736 fBiasData("FAD_CONTROL/FEEDBACK_DATA", (void*)NULL, 0, this), 672 737 fCameraTemp("FSC_CONTROL/TEMPERATURE", (void*)NULL, 0, this), 673 738 fDimReference("FEEDBACK/REFERENCE", "F:416", ""), 674 739 fDimDeviation("FEEDBACK/DEVIATION", "F:416;F:416", ""), 740 fDimCalibration("FEEDBACK/CALIBRATION", "F:416;F:416", ""), 675 741 fKp(0), fKi(0), fKd(0), fT(-1), fOutputEnabled(false) 676 742 { … … 707 773 "Temperature control activated and voltage output enabled."); 708 774 775 AddStateName(kStateCalibrating, "Calibrating", 776 "Calibrating current offsets."); 777 709 778 AddEvent("START_FEEDBACK_CONTROL", kStateConnected) 710 779 (bind(&StateMachineFeedback::StartFeedback, this)) … … 713 782 AddEvent("START_TEMP_CONTROL", "F:1", kStateConnected) 714 783 (bind(&StateMachineFeedback::StartTempCtrl, this, placeholders::_1)) 715 ("Start the temperature control loop"); 784 ("Start the temperature control loop" 785 "|offset[V]:Offset from the nominal temperature corrected value in Volts"); 716 786 717 787 // kStateTempCtrlIdle, kStateFeedbackCtrlIdle, kStateTempCtrlRunning, kStateFeedbackCtrlRunning … … 747 817 (bind(&StateMachineFeedback::SetConstant, this, placeholders::_1, 3)) 748 818 ("Set time-constant. (-1 to use the cycle time, i.e. the time for the last average cycle, instead)"); 819 820 AddEvent("CALIBRATE_CURRENTS", kStateConnected)//, kStateIdle) 821 (bind(&StateMachineFeedback::CalibrateCurrents, this)) 822 (""); 749 823 750 824 // Verbosity commands
Note:
See TracChangeset
for help on using the changeset viewer.