Changeset 12047 for trunk/FACT++/src/feedback.cc
- Timestamp:
- 09/08/11 21:57:11 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/feedback.cc
r12028 r12047 53 53 kStateConnected, 54 54 kStateRunning, 55 kStateControlling, 55 56 }; 56 57 … … 73 74 vector<vector<float>> fData; 74 75 75 int fCursor;76 uint64_t fCursor; 76 77 77 78 Time fBiasLast; … … 86 87 double fKd; // Derivative constant 87 88 89 bool fOutputEnabled; 90 88 91 pair<Time, int> GetNewState(DimStampedInfo &info) const 89 92 { … … 108 111 fSP = valarray<double>(0., 416); 109 112 113 vector<float> vec(2*BIAS::kNumChannels); 114 fDimDeviation.Update(vec); 115 110 116 fPV[0].resize(0); 111 117 fPV[1].resize(0); 112 118 fPV[2].resize(0); 119 120 if (fKp==0 && fKi==0 && fKd==0) 121 Warn("Control loop parameters are all set to zero."); 113 122 } 114 123 … … 165 174 reinterpret_cast<float*>(curr->getData())+1440); 166 175 167 168 ostringstream out;169 out << "New event received: " << fCursor;170 Info(out);171 176 172 177 fCursor++; … … 248 253 const Time tm0 = Time(); 249 254 250 constdouble T21 = (tm0-fStartTime).total_microseconds()/1000000.;255 /*const*/ double T21 = (tm0-fStartTime).total_microseconds()/1000000.; 251 256 const double T10 = fT; 252 257 fT = T21; … … 254 259 fStartTime = tm0; 255 260 256 cout << "Step..." << endl; 261 ostringstream out; 262 out << "New " << fData.size() << " event received: " << fCursor << " / " << setprecision(3) << T21 << "s"; 263 Info(out); 257 264 258 265 if (fPV[0].size()==0) … … 284 291 return; 285 292 286 cout << "Calculating (" << fCursor << " )... " << endl;293 cout << "Calculating (" << fCursor << ":" << T21 << ")... " << endl; 287 294 288 295 // fKi[j] = response[j]*gain; … … 290 297 // Kd = 0; 291 298 292 // (PV[2]-PV[1] + PV[0]-PV[1]) 299 // -110 / -110 (-23 DAC / -0.51V) 300 // Reference voltage: -238 / -203 301 // -360 / -343 ( 23 DAC / 0.51V) 302 303 // 0.005 A/V 304 // 220 Amplitude / 1V 305 306 // Gain = 1V / 200 = 0.005 307 308 // => Kp = 0.01 * gain = 0.00005 309 // => Ki = 0.8 * gain/20s = 0.00025 310 // => Kd = 0.1 * gain/20s = 0.00003 311 312 fKp = 0; 313 fKd = 0; 314 fKi = 0.00003*20; 315 T21 = 1; 316 293 317 //valarray<double> correction = - Kp*(PV[2] - PV[1]) + Ki * dT * (SP-PV[2]) - Kd/dT * (PV[2] - 2*PV[1] + PV[0]); 294 318 //valarray<double> correction = 295 319 // - Kp*(PV[2] - PV[1]) + Ki * T21 * (SP-PV[2]) - Kd*(PV[2]-PV[1])/T21 - Kd*(PV[0]-PV[1])/T01; 296 320 const valarray<double> correction = 297 - (fKp+fKd/T21)*(fPV[2] - fPV[1]) + fKi*T21*(fSP-fPV[2]) + fKd/T10*(fPV[1]-fPV[0]); 321 - (fKp+fKd/T21)*(fPV[2] - fPV[1]) 322 + fKi*T21*(fSP-fPV[2]) 323 + fKd/T10*(fPV[1]-fPV[0]); 298 324 299 325 vector<float> vec(2*BIAS::kNumChannels); 300 326 for (int i=0; i<BIAS::kNumChannels; i++) 301 vec[i] = f SP[i]-fPV[2][i];327 vec[i] = fPV[2][i]-fSP[i]; 302 328 303 329 for (int i=0; i<BIAS::kNumChannels; i++) … … 305 331 306 332 fDimDeviation.Update(vec); 333 334 if (fOutputEnabled) 335 { 336 Info("Sending correction to feedback."); 337 338 dic_cmnd_service("BIAS_CONTROL/ADD_REFERENCE_VOLTAGES", 339 (void*)(vec.data()+416), 416*sizeof(float)); 340 341 /* 342 if (!Dim::SendCommand("BIAS_CONTROL/ADD_REFERENCE_VOLTAGES", 343 (const void*)(vec.data()+416), 416*sizeof(float))) 344 { 345 Error("Sending correction to bias control failed... switching off."); 346 fOutputEnabled=false; 347 } 348 else 349 Info("Success!"); 350 */ 351 } 307 352 } 308 353 … … 383 428 { 384 429 if (!CheckEventSize(evt.GetSize(), "SetConstant", 8)) 385 return T::kSM_FatalError;430 return kSM_FatalError; 386 431 387 432 switch (constant) 388 433 { 389 case 0: fKi = evt.GetDouble(); break ,434 case 0: fKi = evt.GetDouble(); break; 390 435 case 1: fKp = evt.GetDouble(); break; 391 436 case 2: fKd = evt.GetDouble(); break; 392 437 default: 393 438 Fatal("SetConstant got an unexpected constant id -- this is a program bug!"); 394 } 439 return kSM_FatalError; 440 } 441 442 return GetCurrentState(); 443 } 444 445 int EnableOutput(const EventImp &evt) 446 { 447 if (!CheckEventSize(evt.GetSize(), "EnableOutput", 1)) 448 return kSM_FatalError; 449 450 fOutputEnabled = evt.GetBool(); 395 451 396 452 return GetCurrentState(); … … 472 528 fDimReference("FEEDBACK/REFERENCE", "F:416", ""), 473 529 fDimDeviation("FEEDBACK/DEVIATION", "F:416;F:416", ""), 474 fBiasData(NULL) 530 fBiasData(NULL), fKp(0), fKi(0), fKd(0), fOutputEnabled(false) 475 531 { 476 532 // ba::io_service::work is a kind of keep_alive for the loop. … … 505 561 (""); 506 562 563 AddEvent("ENABLE_OUTPUT", "B:1")//, kStateIdle) 564 (bind(&StateMachineFeedback::EnableOutput, this, placeholders::_1)) 565 (""); 566 507 567 AddEvent("STORE_REFERENCE")//, kStateIdle) 508 568 (bind(&StateMachineFeedback::StoreReference, this)) … … 510 570 511 571 AddEvent("SET_Ki", "D:1")//, kStateIdle) 512 (bind(&StateMachineFeedback::SetConstant, this, 0))572 (bind(&StateMachineFeedback::SetConstant, this, placeholders::_1, 0)) 513 573 ("Set integral constant Ki"); 514 574 515 575 AddEvent("SET_Kp", "D:1")//, kStateIdle) 516 (bind(&StateMachineFeedback::SetConstant, this, 1))576 (bind(&StateMachineFeedback::SetConstant, this, placeholders::_1, 1)) 517 577 ("Set proportional constant Kp"); 518 578 519 579 AddEvent("SET_Kd", "D:1")//, kStateIdle) 520 (bind(&StateMachineFeedback::SetConstant, this, 2))580 (bind(&StateMachineFeedback::SetConstant, this, placeholders::_1, 2)) 521 581 ("Set derivative constant Kd"); 522 582 … … 538 598 //fFSC.SetVerbose(!conf.Get<bool>("quiet")); 539 599 540 if (!fMap.Read("FACTmapV5 .txt"))541 { 542 Error("Reading mapping table from FACTmapV5 .txt failed.");600 if (!fMap.Read("FACTmapV5a.txt")) 601 { 602 Error("Reading mapping table from FACTmapV5a.txt failed."); 543 603 return 1; 544 604 } … … 652 712 return 0; 653 713 } 714 715 const PixelMapEntry PixelMap::empty = { 0, 0, 0, 0, 0, 0 };
Note:
See TracChangeset
for help on using the changeset viewer.