Changeset 12435 for trunk/FACT++
- Timestamp:
- 11/07/11 00:02:49 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/ratecontrol.cc
r12429 r12435 40 40 kStateConnected, 41 41 42 kStateWaitingForReference,43 42 kStateSettingGlobalThreshold, 44 43 kStateGlobalThresholdSet, … … 64 63 65 64 uint16_t fThresholdMin; 65 uint16_t fThresholdReference; 66 66 67 67 bool fTriggerOn; … … 214 214 if (maxi==j) 215 215 { 216 // This is the step which has to be performed to go from 217 // a NSB rate of sdata.fPatchRate[i*4+j] 218 219 216 220 const float step = (log10(sdata.fPatchRate[i*4+j])-log10(mp+5*dp))/0.039; 217 221 // * (dif-5)/dif … … 259 263 for (int i=0; i<40; i++) 260 264 { 261 if ( fabs(sdata.fBoardRate[i]-mb)< 5*db)265 if ( fabs(sdata.fBoardRate[i]-mb)<3*db) 262 266 { 263 267 avg += sdata.fBoardRate[i]; … … 272 276 Out() << "Board: Median=" << mb << " Dev=" << db << endl; 273 277 Out() << "Camera: " << fTriggerRate << " (" << sdata.fTriggerRate << ", n=" << num << ")" << endl; 278 Out() << "Target: " << fTargetRate << endl; 274 279 } 275 280 276 281 // ---------------------- 277 282 278 279 if (fTriggerRate<fTargetRate) 280 return; 281 282 // Is this a step to 70Hz? 283 const float step = (log10(fTriggerRate)-log10(fTargetRate))/0.039; 283 if (fTriggerRate>0 && fTriggerRate<fTargetRate) 284 { 285 // I am assuming here (and at other places) the the answer from the FTM when setting 286 // the new threshold always arrives faster than the next rate update. 287 fThresholdMin = fThresholds[0]; 288 return; 289 } 290 291 // This is a step towards a threshold at which the NSB rate is equal the target rate 292 // +1 to avoid getting a step of 0 293 const float step = (log10(fTriggerRate)-log10(fTargetRate))/0.039 + 1; 284 294 285 295 const uint16_t diff = fThresholds[0]+int16_t(truncf(step)); 296 297 cout << diff << endl; 286 298 287 299 if (diff==fThresholds[0]) … … 327 339 328 340 const FTM::DimStaticData &sdata = *static_cast<FTM::DimStaticData*>(curr->getData()); 329 341 fTriggerOn = sdata.HasTrigger(); 342 330 343 PrintThresholds(sdata); 331 344 332 fTriggerOn = sdata.HasTrigger();333 334 345 fThresholds.assign(sdata.fThreshold, sdata.fThreshold+160); 335 336 346 return; 337 347 } … … 342 352 return; 343 353 344 if (!fTriggerOn )354 if (!fTriggerOn && !fEnabled) 345 355 return; 346 356 … … 358 368 } 359 369 360 int StartDataTaking()361 { 362 if (!f Enabled)370 int Calibrate() 371 { 372 if (!fTriggerOn) 363 373 return kStateGlobalThresholdSet; 364 374 365 fThresholds.resize(0); 366 367 const int32_t val[2] = { -1, fThresholdMin }; 375 const int32_t val[2] = { -1, fThresholdReference }; 368 376 Dim::SendCommand("FTM_CONTROL/SET_THRESHOLD", val); 369 377 370 return kStateWaitingForReference; 378 fThresholds.assign(160, fThresholdReference); 379 380 fThresholdMin = fThresholdReference; 381 fTriggerRate = -1; 382 fEnabled = true; 383 384 return kStateSettingGlobalThreshold; 385 } 386 387 int StartRC() 388 { 389 fEnabled = true; 390 return GetCurrentState(); 391 } 392 393 int StopRC() 394 { 395 fEnabled = false; 396 return GetCurrentState(); 371 397 } 372 398 … … 388 414 // FIXME: Check missing 389 415 390 fThreshold Min= evt.GetUShort();416 fThresholdReference = evt.GetUShort(); 391 417 392 418 return GetCurrentState(); … … 453 479 return kStateDisconnected; 454 480 455 if (GetCurrentState()==kStateWaitingForReference)456 {457 if (fThresholds.size()==0)458 return kStateWaitingForReference;459 460 return kStateSettingGlobalThreshold;461 }462 463 481 if (GetCurrentState()==kStateSettingGlobalThreshold) 464 482 { 465 if (fTriggerRate >fTargetRate)483 if (fTriggerRate<0 || fTriggerRate>fTargetRate) 466 484 return kStateSettingGlobalThreshold; 467 485 … … 471 489 if (GetCurrentState()==kStateGlobalThresholdSet) 472 490 { 473 // FIXME: What if it changes? 474 return kStateGlobalThresholdSet; 491 if (!fTriggerOn) 492 return kStateGlobalThresholdSet; 493 //return kStateInProgress; 475 494 } 476 495 477 496 // At least one subsystem is not connected 478 497 // if (fStatusFTM.second>=FTM::kConnected) 479 return fTriggerOn ? kStateInProgress : kStateConnected;498 return fTriggerOn && fEnabled ? kStateInProgress : kStateConnected; 480 499 } 481 500 … … 513 532 "All needed subsystems are connected to their hardware, no action is performed."); 514 533 534 AddStateName(kStateSettingGlobalThreshold, "Calibrating", ""); 535 AddStateName(kStateGlobalThresholdSet, "GlobalThresholdSet", ""); 536 515 537 AddStateName(kStateInProgress, "InProgress", 516 538 "Rate scan in progress."); 517 539 518 // AddEvent("STOP", kStateInProgress) 519 // (bind(&StateMachineRateControl::StopRateControl, this)) 520 // ("Stop a ratescan in progress"); 521 522 AddEvent("START_DATA_TAKING") 523 (bind(&StateMachineRateControl::StartDataTaking, this)) 540 AddEvent("CALIBRATE") 541 (bind(&StateMachineRateControl::Calibrate, this)) 524 542 (""); 525 543 526 AddEvent("ENABLE_RATE_CONTROL", "B:1") 527 (bind(&StateMachineRateControl::SetEnabled, this, placeholders::_1)) 544 AddEvent("START", "") 545 (bind(&StateMachineRateControl::StartRC, this)) 546 (""); 547 548 AddEvent("STOP", "") 549 (bind(&StateMachineRateControl::StopRC, this)) 528 550 (""); 529 551 … … 550 572 { 551 573 fVerbose = !conf.Get<bool>("quiet"); 574 575 fThresholdReference = 300; 576 fTargetRate = 70; 577 552 578 return -1; 553 579 }
Note:
See TracChangeset
for help on using the changeset viewer.