Changeset 12067 for trunk/FACT++/src/feedback.cc
- Timestamp:
- 09/11/11 21:34:54 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/feedback.cc
r12050 r12067 67 67 DimStampedInfo fFAD; 68 68 DimStampedInfo fBias; 69 69 70 DimStampedInfo *fBiasData; 70 71 … … 82 83 valarray<double> fSP; // Set point (target amplitudes) 83 84 84 double fT; 85 double fKp; // Proportional constant 86 double fKi; // Integral constant 87 double fKd; // Derivative constant 85 double fKp; // Proportional constant 86 double fKi; // Integral constant 87 double fKd; // Derivative constant 88 double fT; // Time constant (cycle time) 89 double fGain; // Gain (conversion from a DRS voltage deviation into a BIAS voltage change at G-APD reference voltage) 90 91 double fT21; 88 92 89 93 bool fOutputEnabled; … … 253 257 const Time tm0 = Time(); 254 258 255 /*const*/ double T21 =(tm0-fStartTime).total_microseconds()/1000000.;256 const double T10 = fT ;257 fT = T21;259 const double T21 = fT>0 ? fT : (tm0-fStartTime).total_microseconds()/1000000.; 260 const double T10 = fT21; 261 fT21 = T21; 258 262 259 263 fStartTime = tm0; … … 310 314 // => Kd = 0.1 * gain/20s = 0.00003 311 315 312 fKp = 0;313 fKd = 0;314 fKi = 0.00003*20;315 T21 = 1;316 317 316 //valarray<double> correction = - Kp*(PV[2] - PV[1]) + Ki * dT * (SP-PV[2]) - Kd/dT * (PV[2] - 2*PV[1] + PV[0]); 318 317 //valarray<double> correction = 319 318 // - Kp*(PV[2] - PV[1]) + Ki * T21 * (SP-PV[2]) - Kd*(PV[2]-PV[1])/T21 - Kd*(PV[0]-PV[1])/T01; 320 const valarray<double> correction = 321 - (fKp+fKd/T21)*(fPV[2] - fPV[1]) 322 + fKi*T21*(fSP-fPV[2]) 323 + fKd/T10*(fPV[1]-fPV[0]); 319 const valarray<double> correction = fGain/1000* 320 ( 321 - (fKp+fKd/T21)*(fPV[2] - fPV[1]) 322 + fKi*T21*(fSP-fPV[2]) 323 + fKd/T10*(fPV[1]-fPV[0]) 324 ); 324 325 325 326 vector<float> vec(2*BIAS::kNumChannels); … … 336 337 Info("Sending correction to feedback."); 337 338 338 dic_cmnd_service( "BIAS_CONTROL/ADD_REFERENCE_VOLTAGES",339 dic_cmnd_service((char*)"BIAS_CONTROL/ADD_REFERENCE_VOLTAGES", 339 340 (void*)(vec.data()+416), 416*sizeof(float)); 340 341 … … 432 433 switch (constant) 433 434 { 434 case 0: fKi = evt.GetDouble(); break; 435 case 1: fKp = evt.GetDouble(); break; 436 case 2: fKd = evt.GetDouble(); break; 435 case 0: fKi = evt.GetDouble(); break; 436 case 1: fKp = evt.GetDouble(); break; 437 case 2: fKd = evt.GetDouble(); break; 438 case 3: fT = evt.GetDouble(); break; 439 case 4: fGain = evt.GetDouble(); break; 437 440 default: 438 441 Fatal("SetConstant got an unexpected constant id -- this is a program bug!"); … … 526 529 fFAD("FAD_CONTROL/STATE", (void*)NULL, 0, this), 527 530 fBias("BIAS_CONTROL/STATE", (void*)NULL, 0, this), 531 fBiasData(0), 528 532 fDimReference("FEEDBACK/REFERENCE", "F:416", ""), 529 533 fDimDeviation("FEEDBACK/DEVIATION", "F:416;F:416", ""), 530 f BiasData(NULL), fKp(0), fKi(0), fKd(0), fOutputEnabled(false)534 fKp(0), fKi(0), fKd(0), fT(-1), fOutputEnabled(false) 531 535 { 532 536 // ba::io_service::work is a kind of keep_alive for the loop. … … 555 559 AddEvent("START")//, kStateIdle) 556 560 (bind(&StateMachineFeedback::StartFeedback, this)) 557 (" ");561 ("Start control loop"); 558 562 559 563 AddEvent("STOP")//, kStateIdle) 560 564 (bind(&StateMachineFeedback::StopFeedback, this)) 561 (" ");565 ("Stop control loop"); 562 566 563 567 AddEvent("ENABLE_OUTPUT", "B:1")//, kStateIdle) 564 568 (bind(&StateMachineFeedback::EnableOutput, this, placeholders::_1)) 565 (" ");569 ("Enable sending of correction values caluclated by the control loop to the biasctrl"); 566 570 567 571 AddEvent("STORE_REFERENCE")//, kStateIdle) 568 572 (bind(&StateMachineFeedback::StoreReference, this)) 569 ("Store dthe last (averaged) value as new reference (for debug purpose only)");573 ("Store the last (averaged) value as new reference (for debug purpose only)"); 570 574 571 575 AddEvent("SET_Ki", "D:1")//, kStateIdle) … … 580 584 (bind(&StateMachineFeedback::SetConstant, this, placeholders::_1, 2)) 581 585 ("Set derivative constant Kd"); 586 587 AddEvent("SET_T", "D:1")//, kStateIdle) 588 (bind(&StateMachineFeedback::SetConstant, this, placeholders::_1, 3)) 589 ("Set time-constant. (-1 to use the cycle time, i.e. the time for the last average cycle, instead)"); 582 590 583 591 // Verbosity commands … … 600 608 } 601 609 610 fGain = 5; // (BIAS)V / (DRS)V ( 1V / 0.22V ) 611 612 fKp = 0; 613 fKd = 0; 614 fKi = 0.12; 615 fT = 1; 616 617 ostringstream msg; 618 msg << "Control loop parameters: "; 619 msg << "Kp=" << fKp << ", Kd=" << fKd << ", Ki=" << fKi << ", "; 620 if (fT>0) 621 msg << fT; 622 else 623 msg << "<auto>"; 624 msg << ", Gain(BIAS/DRS)=" << fGain << "V/V"; 625 626 Message(msg); 627 602 628 return -1; 603 629 } … … 616 642 void SetupConfiguration(Configuration &conf) 617 643 { 618 po::options_description control(" BIAS controloptions");644 po::options_description control("Feedback options"); 619 645 control.add_options() 620 646 ("pixel-map-file", var<string>("FACTmapV5a.txt"), "Pixel mapping file. Used here to get the default reference voltage.") … … 636 662 { 637 663 cout << 638 "The f tmctrl controls the FSC (FACT Slow Control) board.\n"664 "The feedback control the BIAS voltages based on the calibration signal.\n" 639 665 "\n" 640 666 "The default is that the program is started without user intercation. " … … 643 669 "help message about the usuage can be brought to the screen.\n" 644 670 "\n" 645 "Usage: f scctrl[-c type] [OPTIONS]\n"646 " or: f scctrl[OPTIONS]\n";671 "Usage: feedback [-c type] [OPTIONS]\n" 672 " or: feedback [OPTIONS]\n"; 647 673 cout << endl; 648 674 }
Note:
See TracChangeset
for help on using the changeset viewer.