Changeset 7230 for trunk/MagicSoft/Cosy
- Timestamp:
- 07/28/05 22:24:32 (19 years ago)
- Location:
- trunk/MagicSoft/Cosy
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Cosy/Changelog
r6923 r7230 1 1 -*-*- END -*-*- 2 3 2005/07/28 - Florian Goebel 4 5 * videodev/FilterLed.[cc,h] 6 - add GetMeanPositionCircle and FindStarCircle 7 8 * devdrv/shaftencoder.[cc,h] 9 - add: fDirHasChanged, fDirChangedPos, fDirChangedOffset, 10 fDirection, fHysteresisPos, fHysteresisNeg 11 12 * main/MCosy.cc 13 - set faster acceleration and Velocity parameters in TrackPositionGRB 14 15 * main/MPointing.cc 16 - correct bug which always set speed to LO-SPEED 17 18 * main/MStarguider.[cc,h] 19 - add new Popup "Operation" (functionality is not ready yet) 20 - add new procedure: FindRoqueLamp 21 - in MStarguider::FindStar now use Leds::FindStarCircle 22 (instead of Leds::FindStar) 23 24 * main/MTracking.cc 25 - calculate DirHasChanged etc. 26 2 27 3 28 2005/04/11 - Thomas Bretz -
trunk/MagicSoft/Cosy/devdrv/shaftencoder.cc
r4104 r7230 16 16 ShaftEncoder::ShaftEncoder(const BYTE_t nodeid, const char *name, MLog &out) 17 17 : NodeDrv(nodeid, name, out), fPos(0), fVel(0), fAcc(0), 18 fTurn(0), fLabel(NULL), fPosHasChanged(false), fReport(NULL),/*fTwin(0), 19 fIsUpdated(kFALSE),*/ fMotor(0), fOffset(0) 18 fTurn(0), fLabel(NULL), fPosHasChanged(false), fDirHasChanged(false), 19 fReport(NULL), 20 /*fTwin(0), fIsUpdated(kFALSE),*/ 21 fMotor(0), fOffset(0), fDirChangedPos(0), 22 fDirection(kUndefined), fHysteresisPos(0), fHysteresisNeg(0) 20 23 { 21 24 } … … 93 96 fPos = val; 94 97 fTurn = 0; 98 fDirChangedPos = val; 95 99 fOffset = fMotor ? fMotor->GetPdoPos() : 0; 100 fPosHasChanged = true; 101 fDirHasChanged = true; 102 fDirection = kUndefined; 96 103 //fIsUpdated=kTRUE; 97 104 //fOffset = 0; … … 198 205 // return; 199 206 207 // Warning: A multiturn shaftencoder is assumed! 208 if ((pos>fDirChangedPos && pos<fPos) || 209 (pos<fDirChangedPos && pos>fPos)) 210 { 211 fDirChangedPos = pos; 212 fDirHasChanged = true; 213 } 214 else 215 fOffset = fMotor ? fMotor->GetPdoPos() : 0; 216 200 217 fPos = pos; 201 fOffset = fMotor ? fMotor->GetPdoPos() : 0;202 218 fTime.Set(*tv); 203 219 fPosHasChanged = true; … … 225 241 // return; 226 242 243 // Warning: A multiturn shaftencoder is assumed! 244 if ((pos>fDirChangedPos && pos<fPos) || 245 (pos<fDirChangedPos && pos>fPos)) 246 { 247 fDirChangedPos = pos; 248 fDirHasChanged = true; 249 } 250 else 251 fOffset = fMotor ? fMotor->GetPdoPos() : 0; 252 227 253 //CheckTwin(fPos-pos); 228 254 fPos=pos; 229 fOffset = fMotor ? fMotor->GetPdoPos() : 0;230 255 fTime.Set(*tv); 231 256 fPosHasChanged=true; … … 267 292 turn--; 268 293 294 LWORDS_t multipos = pos+turn*fTicks; // SE position of multiturn shaftencoder 295 269 296 //if (fPos==pos && fTurn==fTurn) 270 297 // return; … … 272 299 //CheckTwin(fPos-pos); 273 300 301 fOffset = fMotor ? fMotor->GetPdoPos() : 0; 302 303 // Warning: A multiturn shaftencoder is assumed! 304 if ((multipos>fDirChangedPos && multipos<fPos) || 305 (multipos<fDirChangedPos && multipos>fPos)) 306 { 307 fDirChangedPos = GetPos(); 308 fDirHasChanged = true; 309 fDirChangedOffset = fOffset; 310 } 311 else 312 { 313 fDirHasChanged = false; 314 } 315 316 if (multipos>GetPos()) fDirection = kForward; 317 else if (multipos<GetPos()) fDirection = kBackward; 318 else fDirection = kUndefined; 319 320 274 321 fPos = pos; 275 322 fTurn = turn; 276 323 277 fOffset = fMotor ? fMotor->GetPdoPos() : 0;278 324 fTime.Set(*tv); 279 325 fPosHasChanged=true; … … 281 327 //fOffset = 0; 282 328 283 284 329 if (fReport) 285 330 { 286 331 fReport->Lock("ShaftEncoder::HandlePDOType2"); 287 332 *fReport << "SE-REPORT " << (int)GetId() << " " << fTime << " PDO2 " << pos << " " << fVel << " " << fAcc << " " << GetNodeName() << endl; 333 *fReport << "DIR-REPORT " << (int)GetId() << " " << (Int_t)fDirHasChanged << " " << (Int_t)fDirChangedPos << endl; 288 334 fReport->UnLock("ShaftEncoder::HandlePDOType2"); 289 335 } … … 415 461 fPos = pre%16384; 416 462 fTurn = pre/16384; 417 463 fDirChangedPos = fPos; 418 464 fOffset = fMotor ? fMotor->GetPdoPos() : 0; 465 466 fPosHasChanged = true; 467 fDirHasChanged = true; 468 469 fDirection = kUndefined; 419 470 } 420 471 -
trunk/MagicSoft/Cosy/devdrv/shaftencoder.h
r4104 r7230 13 13 class TGLabel; 14 14 15 enum Direction_t { kUndefined, kForward, kBackward }; 16 15 17 class ShaftEncoder : public NodeDrv 16 18 { … … 23 25 WORD_t fTurns; // Number of possible turns 24 26 27 Direction_t fDirection; 28 29 Float_t fHysteresisPos; 30 Float_t fHysteresisNeg; 31 25 32 TGLabel *fLabel; // 26 33 LWORDS_t fUpdPos; // ticks 27 34 28 35 bool fPosHasChanged; //! 36 bool fDirHasChanged; //! 29 37 30 38 MTime fTime; 31 39 MLog *fReport; 32 40 33 Macs *fMotor; 34 Int_t fOffset; 41 Macs *fMotor; // Corresponding Motor/MACS 42 Int_t fOffset; // offset between SE and Motor 43 Int_t fDirChangedPos; // Last position at which the SE changed its moving direction 44 Int_t fDirChangedOffset; // Offset between SE and Motor when SE changed its moving direction last 45 35 46 36 47 void HandlePDOType0(BYTE_t *data, timeval_t *tv); … … 62 73 void HandlePDO2(BYTE_t *data, timeval_t *tv) { HandlePDOType2(data, tv); } 63 74 64 LWORDS_t GetPos() const { return IsZombieNode() ? 0 : fPos+fTurn*fTicks; } // FIXME? 0? 75 LWORDS_t GetPos() const { return IsZombieNode() ? 0 : fPos+fTurn*fTicks; } // FIXME? 0? 76 Int_t GetDirection() const { return IsZombieNode() ? 0 : fPos-fDirChangedPos; } // FIXME? 0? 77 Int_t GetDirChangedPos() const { return IsZombieNode() ? 0 : fDirChangedPos; } // FIXME? 0? 65 78 LWORD_t GetPhysRes() const { return fTicks; } 66 79 Int_t GetOffset() const { return fOffset; } 80 Int_t GetDirChangedOffset() const { return fDirChangedOffset; } 81 67 82 void SetOffset(Int_t off) { fOffset = off; } 68 83 … … 74 89 75 90 bool PosHasChanged() const { return fPosHasChanged; } 91 bool DirHasChanged() const { return fDirHasChanged; } 76 92 void ResetPosHasChanged() { fPosHasChanged = false; } 93 void ResetDirHasChanged() { fDirHasChanged = false; } 77 94 78 95 void SetReport(MLog *log) { fReport = log; } 96 97 void SetHysteresisNeg(Float_t f) { fHysteresisNeg = f; } 98 void SetHysteresisPos(Float_t f) { fHysteresisPos = f; } 99 100 Float_t GetPosCorrected() const { 101 switch (fDirection) { 102 case kUndefined: 103 return GetPos(); 104 case kForward: 105 return GetPos()-fHysteresisPos; 106 case kBackward: 107 return GetPos()+fHysteresisNeg; 108 } 109 } 79 110 80 111 ClassDef(ShaftEncoder, 0) -
trunk/MagicSoft/Cosy/main/MCosy.cc
r6841 r7230 397 397 // point.SetVelocity(0.2); // fast: 0.6, slow: 0.2 398 398 //#else 399 400 // original settings 401 // 399 402 point.SetPointAccDec(0.2, 0.1); 400 403 point.SetPointVelocity(0.1); 404 405 401 406 //#endif 402 407 408 // point.SetPointAccDec(0.4, 0.4); 409 // point.SetPointVelocity(0.4); 410 411 412 // original 403 413 return point.SetPosition(dst, track); 414 415 // test 416 // return point.SetPosition(dst, kTRUE); 417 418 419 404 420 } 405 421 … … 422 438 // track.SetPointVelocity(0.2); // fast: 0.6, slow: 0.2 423 439 //#else 440 441 442 424 443 track.SetPointAccDec(0.2, 0.1); 425 444 track.SetPointVelocity(0.1); 445 446 // track.SetPointAccDec(0.4, 0.4); 447 // track.SetPointVelocity(0.4); 448 449 450 426 451 //#endif 427 452 track.SetTrackAccDec(0.1, 0.1); … … 438 463 // track.SetPointVelocity(0.2); // fast: 0.6, slow: 0.2 439 464 //#else 440 track.SetPointAccDec(0. 2, 0.1);441 track.SetPointVelocity(0. 1);465 track.SetPointAccDec(0.4, 0.4); 466 track.SetPointVelocity(0.3); 442 467 //#endif 443 468 track.SetTrackAccDec(0.1, 0.1); -
trunk/MagicSoft/Cosy/main/MPointing.cc
r4106 r7230 202 202 else 203 203 { 204 const Double_t y = 15*fCosy->kGearTot.Y()*fCosy->kResSE.Y(); 205 if (rd.Az()>-y && rd.Az()<y) 206 { 207 //lout << "--- LO-SPEED Mac1 ---" << endl; 208 SetAccDec(fCosy->fMac1, 0.05, 0.05); 209 } 210 else 211 SetAccDec(fCosy->fMac1, fAcc, fDec); 204 const Double_t y = 15*fCosy->kGearTot.Y()/fCosy->kResSE.Y(); 205 206 // lout << "MPointing::SetPosition y: " << y << " rd.Az(): " << rd.Az() << endl; 207 // lout << "MPointing::SetPosition fCosy->kGearTot.Y(): " << fCosy->kGearTot.Y() << " fCosy->kResSE.Y(): " << fCosy->kResSE.Y() << endl; 208 209 if (rd.Az()>-y && rd.Az()<y) 210 { 211 //lout << "--- LO-SPEED Mac1 ---" << endl; 212 SetAccDec(fCosy->fMac1, 0.05, 0.05); 213 } 214 else 215 { 216 217 //lout << "MPointing::SetPosition SetAccDec Mac1: " << fAcc << fDec << endl; 218 219 SetAccDec(fCosy->fMac1, fAcc, fDec); 220 221 } 222 223 224 // new 16.05.05 F.G. 225 // SetAccDec(fCosy->fMac1, fAcc, fDec); 212 226 213 227 SetAccDec(fCosy->fMac2, fAcc, fDec); -
trunk/MagicSoft/Cosy/main/MStarguider.cc
r6842 r7230 70 70 IDM_kChannel1, 71 71 IDM_kChannel2, 72 IDM_kChannel3, 72 73 IDM_kContinous, 73 74 IDM_kRate25ps, … … 107 108 IDM_kStargCaosFilter, 108 109 IDM_kStargLEDFilter, 109 IDM_kStargFindStar 110 IDM_kStargFindStar, 111 IDM_kTPointAna, 112 IDM_kRoqueLampAna 110 113 111 114 }; … … 143 146 fChannel->AddEntry("Starfield Camera", IDM_kChannel1); 144 147 fChannel->AddEntry("TPoint Camera", IDM_kChannel2); 145 fChannel->CheckEntry(channel==0?IDM_kChannel1:IDM_kChannel2); 148 fChannel->AddEntry("Read from File", IDM_kChannel3); 149 if (channel<0) { 150 fChannel->CheckEntry(IDM_kChannel3); 151 } else { 152 fChannel->CheckEntry(channel==0?IDM_kChannel1:IDM_kChannel2); 153 } 146 154 fChannel->Associate(this); 147 155 fList->Add(fChannel); … … 170 178 fList->Add(fDisplay); 171 179 180 181 fOperations = new MGPopupMenu(p); 182 fOperations->AddEntry("TPoint Analysis", IDM_kTPointAna); 183 fOperations->AddEntry("Roque Lamp Analysis", IDM_kRoqueLampAna); 184 fOperations->Associate(this); 185 fList->Add(fOperations); 186 187 172 188 fFileType = new MGPopupMenu(p); 173 189 fFileType->AddEntry("PP&M", IDM_kPPM); … … 281 297 282 298 fMenu = new MGMenuBar(this, 0, 0, kHorizontalFrame); 283 fMenu->AddPopup("&Display", fDisplay, NULL); 284 fMenu->AddPopup("&WritePics", fWritePictures, NULL); 285 fMenu->AddPopup("&Setup", fSetup, NULL); 299 fMenu->AddPopup("&Display", fDisplay, NULL); 300 fMenu->AddPopup("&WritePics", fWritePictures, NULL); 301 fMenu->AddPopup("&Setup", fSetup, NULL); 302 303 fMenu->AddPopup("&Operations", fOperations, NULL); 304 286 305 fMenu->Resize(fMenu->GetDefaultSize()); 287 306 fMenu->BindKeys(this); … … 457 476 458 477 MStarguider::MStarguider(MObservatory::LocationName_t obs, Int_t channel) 459 : TGMainFrame(gClient->GetRoot(), 768, 840), fCosy(NULL), fOutTp(0), fDx((768-kZOOM)/2), fDy((512-kZOOM)/2), fStatus(MDriveCom::kStandby) 478 : TGMainFrame(gClient->GetRoot(), 768, 840), 479 fCosy(NULL), 480 fOutTp(0), 481 fOutRq(0), 482 fDx((768-kZOOM)/2), 483 fDy((512-kZOOM)/2), 484 fStatus(MDriveCom::kStandby) 460 485 { 461 486 … … 517 542 if (fOutTp) 518 543 delete fOutTp; 544 545 if (fOutRq) 546 delete fOutRq; 519 547 520 548 cout << "Camera Display destroyed." << endl; … … 585 613 return kTRUE; 586 614 615 case IDM_kRoqueLampAna: 616 Toggle(fOperations, IDM_kRoqueLampAna); 617 // if (!fDisplay->IsEntryChecked(IDM_kCatalog)) 618 if (fOperations->IsEntryChecked(IDM_kRoqueLampAna)) { 619 fDisplay->CheckEntry(IDM_kStargCaosFilter); 620 } 621 else { 622 fDisplay->UnCheckEntry(IDM_kStargCaosFilter); 623 } 624 625 return kTRUE; 626 627 587 628 case IDM_kStargFindStar: 588 589 629 Toggle(fDisplay, IDM_kStargFindStar); 630 if (fDisplay->IsEntryChecked(IDM_kStargFindStar)) { 590 631 fSZdAz->MapWindow(); 591 632 } else { … … 615 656 616 657 const Int_t ch0 = 617 fChannel->IsEntryChecked(IDM_kChannel1) ? 0 : 1; 618 const Int_t ch1 = 0; 619 620 if (ch0!=ch1) 621 { 622 658 fChannel->IsEntryChecked(IDM_kChannel1) ? 0 : 1; 659 const Int_t ch1 = 0; 660 661 if (ch0!=ch1) 662 { 623 663 delete fGetter; 624 664 usleep(150000); // FIX: Device or resource busy. 625 fGetter = new Camera(*this, ch1); 626 ((Camera*)fGetter)->Loop(0); 627 } 665 if (fChannel->IsEntryChecked(IDM_kChannel3)) { 666 fGetter=new PngReader(*this); 667 } else { 668 fGetter = new Camera(*this, ch1); 669 ((Camera*)fGetter)->Loop(0); 670 } 671 } 628 672 629 673 fChannel->CheckEntry(IDM_kChannel1); … … 854 898 delete fGetter; 855 899 usleep(150000); // FIX: Device or resource busy. 856 fGetter = new Camera(*this, ch1); 857 ((Camera*)fGetter)->Loop(0); 900 if (fChannel->IsEntryChecked(IDM_kChannel3)) 901 fGetter=new PngReader(*this); 902 else 903 { 904 fGetter = new Camera(*this, ch1); 905 ((Camera*)fGetter)->Loop(0); 906 } 858 907 } 859 908 return kTRUE; … … 1109 1158 } 1110 1159 1111 ZdAz MStarguider::FindStar(FilterLed &f, FilterLed &f2, Ring ¢er, MTime &t, Double_t cut, Double_t box, Double_t scalefactor = 1.0)1160 XY MStarguider::FindRoqueLamp(FilterLed &f, FilterLed &f2, Ring &CameraCenter, MTime &t, Double_t cut, Double_t box, XY SearchCenter) 1112 1161 { 1113 1162 // Set search Paremeters (FIXME: Get them from user input!) … … 1117 1166 // Try to find Led in this area 1118 1167 Leds leds; 1119 f.FindStar(leds, (Int_t)center.GetX(), (Int_t)center.GetY()); 1168 f.FindStarCircle(leds, (Int_t)SearchCenter.X(), (Int_t)SearchCenter.Y()); 1169 1170 // Check whether star found 1171 Led *star = (Led*)leds.At(0); 1172 if (!star || leds.GetEntries()<1) 1173 return XY(.0,.0); 1174 1175 // cout << "Found Roque Lamp @ " << flush; 1176 star->Print(); 1177 f.MarkPoint(star->GetX(), star->GetY(), 500); 1178 1179 // cout << "RoquePos: " << star->GetX() << "," << star->GetY() << endl; 1180 1181 XY roquepos(star->GetX(), star->GetY()); 1182 XY relroquepos(roquepos.X()-CameraCenter.GetX(), roquepos.Y()-CameraCenter.GetY()); 1183 1184 // If no file open: open new Roque Lamp file 1185 if (!fOutRq) 1186 { 1187 const TString name = MCosy::GetFileName("tpoint/starg_roquelamp_%s.txt"); 1188 cout << "Starg_RoqueLamp File ********* " << name << " ********** " << endl; 1189 fOutRq = new ofstream(name); 1190 *fOutRq << "# Magic Roque Lamp file " << t << endl; 1191 } 1192 1193 1194 return relroquepos; 1195 } 1196 1197 1198 ZdAz MStarguider::FindStar(FilterLed &f, FilterLed &f2, Ring ¢er, MTime &t, Double_t cut, Double_t box, Double_t scalefactor = 1.0) 1199 { 1200 // Set search Paremeters (FIXME: Get them from user input!) 1201 f.SetCut(cut); // 3.5 1202 f.SetBox(box); // 70 1203 1204 // Try to find Led in this area 1205 Leds leds; 1206 f.FindStarCircle(leds, (Int_t)center.GetX(), (Int_t)center.GetY()); 1120 1207 1121 1208 // Check whether star found … … 1329 1416 pos = fCosy->GetPointingPos(); 1330 1417 center = fCaos->Run(img, printl, printr, pos, t, 50, 3.0); 1418 1419 cout << "Caos Filter Camera center position: " << center.GetX() << " " << center.GetY() << endl; 1420 1331 1421 } 1332 1422 … … 1390 1480 } 1391 1481 1482 // Find Roque Lamp 1483 1484 if (fOperations->IsEntryChecked(IDM_kRoqueLampAna)) { 1485 1486 XY roquelamp(0,0); 1487 1488 Double_t imageclean = 1.5; 1489 Double_t boxradius = 60; 1490 Double_t scalefactor = 1; 1491 XY searchcenter(768/2-1,576/2+25); 1492 1493 roquelamp = FindRoqueLamp(f, f2, sgcenter, t, imageclean, boxradius, searchcenter); 1494 1495 if (fOutRq) { 1496 ZdAz pos = fCosy->GetPointingPos(); 1497 1498 *fOutRq << "RoqueLampDirect: " << MTime(-1) << " " 1499 << pos.Zd() << " " << pos.Az() << " " 1500 << roquelamp.X() << " " << roquelamp.Y() << endl; 1501 } 1502 1503 cout << "Starguider Camera Center: " << sgcenter.GetX() << "," << sgcenter.GetY() << endl; 1504 cout << ">=>=>=> Roque Lamp found at: >=>=>=> (" << roquelamp.X() << "," 1505 << roquelamp.Y() << ") <=<=<=<" << endl; 1506 1507 } 1508 1509 // Find Spot on Camera Center in Starguider camera 1510 1511 if (fOperations->IsEntryChecked(IDM_kRoqueLampAna)) { 1512 1513 XY cameraspot(0,0); 1514 1515 Double_t imageclean = 5; 1516 Double_t boxradius = 60; 1517 Double_t scalefactor = 1; 1518 // XY searchcenter(sgcenter.GetX(),sgcenter.GetY()); 1519 XY searchcenter(60.,290.); 1520 1521 cameraspot = FindRoqueLamp(f, f2, sgcenter, t, imageclean, boxradius, searchcenter); 1522 1523 if (fOutRq) { 1524 ZdAz pos = fCosy->GetPointingPos(); 1525 1526 *fOutRq << "RoqueLampReflected: " << MTime(-1) << " " 1527 << pos.Zd() << " " << pos.Az() << " " 1528 << cameraspot.X() << " " << cameraspot.Y() << endl; 1529 } 1530 1531 cout << ">>>>> Spot on Magic camera found at: >>>>> (" << cameraspot.X() << "," 1532 << cameraspot.Y() << ") <<<<<" << endl; 1533 1534 f2.DrawCircle(sgcenter, 5.0, 0x0fa); 1535 f2.DrawCircle(sgcenter, 115.0, 0x0fa); 1536 1537 } 1538 1539 1540 1392 1541 // we calculate the offset given by the three ETH Leds visible to 1393 1542 // the guide camera … … 1451 1600 Leds spots; 1452 1601 f.SetBox(230); 1602 // f.SetCut(1.5); 1453 1603 double bright; 1454 1604 f.ExecuteAndMark(spots, 530, 292, bright); … … 1528 1678 if (fDisplay->IsEntryChecked(IDM_kCaosFilter) || 1529 1679 fDisplay->IsEntryChecked(IDM_kCatalog) || 1530 fDisplay->IsEntryChecked(IDM_kFindStar)) 1680 fDisplay->IsEntryChecked(IDM_kFindStar) || 1681 fOperations->IsEntryChecked(IDM_kRoqueLampAna)) 1531 1682 fImage->DrawColImg(img, cimg); 1532 1683 else -
trunk/MagicSoft/Cosy/main/MStarguider.h
r4865 r7230 67 67 MGPopupMenu *fChannel; 68 68 69 MGPopupMenu *fOperations; 70 69 71 MGPopupMenu *fCaosWrite; 70 72 MGPopupMenu *fCaosPrint; … … 104 106 105 107 ofstream *fOutTp; 108 ofstream *fOutRq; 106 109 107 110 Int_t fDx; … … 121 124 ZdAz TrackingError(TArrayF &alt, TArrayF &az, TArrayF &mag) const; 122 125 bool Interpolate(const unsigned long n, byte *img) const; 126 127 XY FindRoqueLamp(FilterLed &f, FilterLed &f2, Ring &CameraCenter, MTime &t, 128 Double_t cut, Double_t box, XY SearchCenter); 129 123 130 ZdAz FindStar(FilterLed &f, FilterLed &f2, Ring ¢er, MTime &t, 124 131 Double_t cut, Double_t box, Double_t scalefactor); -
trunk/MagicSoft/Cosy/main/MTracking.cc
r6930 r7230 244 244 ZdAz MTracking::GetPointingPosRE(Bool_t pdo) const 245 245 { 246 // Conversion factor from se to re 247 const XY re = fCosy->kGearTot/fCosy->kResSE; //[re/se] 248 249 Int_t pzd1 = fCosy->fZd1->GetPos(); 250 Int_t pzd2 = fCosy->fZd2->GetPos(); 251 Int_t paz = fCosy->fAz->GetPos(); 246 // Conversion factor from se to re 247 const XY re = fCosy->kGearTot/fCosy->kResSE; //[re/se] 248 249 const bool bool1 = fCosy->fZd1->DirHasChanged(); 250 const bool bool2 = fCosy->fZd2->DirHasChanged(); 251 252 if (bool1 && bool2) { 253 fCosy->fZd1->ResetDirHasChanged(); 254 fCosy->fZd2->ResetDirHasChanged(); 255 } 256 257 Int_t pzd1 = !bool1 ? fCosy->fZd1->GetPos() : fCosy->fZd1->GetDirChangedPos(); 258 Int_t pzd2 = !bool2 ? fCosy->fZd2->GetPos() : fCosy->fZd2->GetDirChangedPos(); 259 Int_t paz = fCosy->fAz->GetPos(); 260 261 // Get current shaftencoder position of the telescope 262 Double_t seposzd1 = ((pzd1+8192)%16384)*re.X(); 263 Double_t seposzd2 = ((pzd2+8192)%16384)*re.X(); 264 Double_t seposaz = paz *re.Y(); 265 266 // distance between (To+dt) and To [re] 267 // position time difference < 5usec 268 // fRePos does the synchronization between the 269 // Shaft- and the rotary encoders 270 const ZdAz repos = pdo ? fCosy->GetRePosPdo() : fCosy->GetRePos(); 271 272 const Int_t offset1 = !bool1 ? fCosy->fZd1->GetOffset() : fCosy->fZd1->GetDirChangedOffset(); 273 const Int_t offset2 = !bool2 ? fCosy->fZd2->GetOffset() : fCosy->fZd2->GetDirChangedOffset(); 274 275 // Calculate the part of one SE which the motors moved 276 // since the last SE has changed its value 277 const Double_t offzd1 = repos.Zd() - offset1; 278 const Double_t offzd2 = repos.Zd() - offset2; 279 const Double_t offaz = repos.Az() - fCosy->fAz->GetOffset(); 280 281 // Correct for the direction in which the motor is moving 282 // (in which the shaftencoders should change its values) 283 if (offaz<0) 284 seposaz += re.Y(); 285 if (offzd1<0) 286 seposzd1 += re.X(); 287 if (offzd2<0) 288 seposzd2 += re.X(); 289 290 // and interpolate the shaftencoder steps using the motor 291 // encoder positon (Be carefull the minus-sign is important) 292 seposzd1 += offzd1; 293 seposzd2 -= offzd2; 294 seposaz += offaz; 295 296 297 298 return ZdAz((seposzd1-seposzd2)/2, seposaz); 299 } 252 300 /* 253 301 if (fCosy->fZd1->DirHasChanged() != fCosy->fZd2->DirHasChanged()) … … 262 310 } 263 311 */ 264 // Get current shaftencoder position of the telescope265 Double_t seposzd1 = ((pzd1+8192)%16384)*re.X();266 Double_t seposzd2 = ((pzd2+8192)%16384)*re.X();267 Double_t seposaz = paz *re.Y();268 269 // distance between (To+dt) and To [re]270 // position time difference < 5usec271 // fRePos does the synchronization between the272 // Shaft- and the rotary encoders273 const ZdAz repos = pdo ? fCosy->GetRePosPdo() : fCosy->GetRePos();274 275 // Calculate the part of one SE which the motors moved276 // since the last SE has changed its value277 const Double_t offzd1 = repos.Zd() - fCosy->fZd1->GetOffset();278 const Double_t offzd2 = repos.Zd() - fCosy->fZd2->GetOffset();279 const Double_t offaz = repos.Az() - fCosy->fAz->GetOffset();280 281 // Correct for the direction in which the motor is moving282 // (in which the shaftencoders should change its values)283 if (offaz<0)284 seposaz += re.Y();285 if (offzd1<0)286 seposzd1 += re.X();287 if (offzd2<0)288 seposzd2 += re.X();289 290 // and interpolate the shaftencoder steps using the motor291 // encoder positon (Be carefull the minus-sign is important)292 seposzd1 += offzd1;293 seposzd2 -= offzd2;294 seposaz += offaz;295 296 return ZdAz((seposzd1-seposzd2)/2, seposaz);297 }298 312 299 313 void MTracking::TrackPosition(const RaDec &dst) // ra, dec [rad] -
trunk/MagicSoft/Cosy/videodev/FilterLed.cc
r4865 r7230 120 120 return GetMeanPosition(x, y, box, mx, my, sum); 121 121 } 122 123 int FilterLed::GetMeanPositionCircle(const int x, const int y, 124 const int box, float &mx, 125 float &my, unsigned int &sum) const 126 { 127 unsigned int sumx=0; 128 unsigned int sumy=0; 129 130 //------------------------------- 131 // Improved algorithm: 132 // 1. Look for the largest four-pixel signal inside box 133 134 int thissum=0, maxsum=0; 135 int maxx=0, maxy=0; 136 for (int dx=x-box; dx<x+box+1; dx++) 137 for (int dy=y-box; dy<y+box+1; dy++) 138 { 139 thissum = fImg[dy*fW+dx]+fImg[(dy+1)*fW+dx]+ 140 fImg[dy*fW+(dx+1)]+fImg[(dy+1)*fW+(dx+1)]; 141 if(thissum>maxsum) 142 { 143 maxx=dx; 144 maxy=dy; 145 maxsum=thissum; 146 } 147 } 148 149 // 2. Calculate mean position inside a circle around 150 // the highst four-pixel signal with radius of 5 pixels. 151 152 sum=0; 153 for (int dx=x-box; dx<x+box+1; dx++) 154 for (int dy=y-box; dy<y+box+1; dy++) 155 { 156 const byte &m = fImg[dy*fW+dx]; 157 158 // Circle 159 if(sqrt((dx-maxx)*(dx-maxx)+ 160 (dy-maxy)*(dy-maxy)) <= 6) 161 { 162 sumx += m*dx; 163 sumy += m*dy; 164 sum += m; 165 } 166 } 167 168 mx = (float)sumx/sum; 169 my = (float)sumy/sum; 170 171 return (int)my*fW + (int)mx; 172 } 173 174 175 176 int FilterLed::GetMeanPositionCircle(const int x, const int y, 177 const int box) const 178 { 179 float mx, my; 180 unsigned int sum; 181 return GetMeanPositionCircle(x, y, box, mx, my, sum); 182 } 183 184 122 185 /* 123 186 void FilterLed::RemoveTwins(Leds &leds, Double_t radius) … … 486 549 } 487 550 551 void FilterLed::FindStarCircle(Leds &leds, int xc, int yc) const 552 { 553 // fBox: radius of the inner (signal) box 554 // Radius of the outer box is fBox*sqrt(2) 555 556 // 557 // Define inner box in which to search the signal 558 // 559 int x0 = xc-fBox; 560 int x1 = xc+fBox; 561 int y0 = yc-fBox; 562 int y1 = yc+fBox; 563 564 if (x0<0) x0=0; 565 if (y0<0) y0=0; 566 if (x1>fW) x1=fW; 567 if (y1>fH) y1=fH; 568 569 // 570 // Define outer box (excluding inner box) having almost 571 // the same number of pixels in which the background 572 // is calculated 573 // 574 const double sqrt2 = sqrt(2.); 575 576 int xa = xc-(int)rint(fBox*sqrt2); 577 int xb = xc+(int)rint(fBox*sqrt2); 578 int ya = yc-(int)rint(fBox*sqrt2); 579 int yb = yc+(int)rint(fBox*sqrt2); 580 581 if (xa<0) xa=0; 582 if (ya<0) ya=0; 583 if (xb>fW) xb=fW; 584 if (yb>fH) yb=fH; 585 586 // 587 // Calculate average and sdev for a square 588 // excluding the inner part were we expect 589 // the signal to be. 590 // 591 double sum = 0; 592 double sq = 0; 593 594 int n=0; 595 for (int x=xa; x<xb; x++) 596 for (int y=ya; y<yb; y++) 597 { 598 if (x>=x0 && x<x1 && y>=y0 && y<y1) 599 continue; 600 601 byte &b = fImg[y*fW+x]; 602 603 sum += b; 604 sq += b*b; 605 n++; 606 } 607 608 sum /= n; 609 sq /= n; 610 611 // 254 because b<=max and not b<max 612 const double sdev = sqrt(sq-sum*sum); 613 const byte max = sum+fCut*sdev>254 ? 254 : (byte)(sum+fCut*sdev); 614 615 // 616 // clean image from noise 617 // (FIXME: A lookup table could accelerate things... 618 // 619 n=0; 620 for (int x=x0; x<x1; x++) 621 for (int y=y0; y<y1; y++) 622 { 623 byte &b = fImg[y*fW+x]; 624 if (b<=max) 625 b = 0; 626 else 627 n++; 628 } 629 630 // 631 // Mark the background region 632 // 633 for (int x=xa; x<xb; x+=2) 634 { 635 fImg[ya*fW+x]=0xf0; 636 fImg[yb*fW+x]=0xf0; 637 } 638 for (int y=ya; y<yb; y+=2) 639 { 640 fImg[y*fW+xa]=0xf0; 641 fImg[y*fW+xb]=0xf0; 642 } 643 644 // 645 // Check if any pixel found... 646 // 647 if (n<5) 648 return; 649 650 // 651 // Get the mean position of the star 652 // 653 float mx, my; 654 unsigned int mag; 655 656 // int pos = GetMeanPosition(xc, yc, fBox-1, mx, my, mag); 657 658 // try new method 659 int pos = GetMeanPositionCircle(xc, yc, fBox-1, mx, my, mag); 660 661 if (pos<0 || pos>=fW*fH && fImg[pos]<sum+fCut*sdev) 662 return; 663 664 cout << "Mean=" << sum << " SDev=" << sdev << " : "; 665 cout << "Sum/n = " << sum << "/" << n << " = " << (n==0?0:mag/n) << endl; 666 667 leds.Add(mx, my, 0, 0, -2.5*log10((float)mag)+13.7); 668 } 669 670 488 671 void FilterLed::Stretch() const 489 672 { -
trunk/MagicSoft/Cosy/videodev/FilterLed.h
r4865 r7230 24 24 int GetMeanPosition(const int x, const int y, const int box, 25 25 float &mx, float &my, unsigned int &sum) const; 26 27 int GetMeanPositionCircle(const int x, const int y, 28 const int box) const; 29 int GetMeanPositionCircle(const int x, const int y, 30 const int box, float &mx, float &my, 31 unsigned int &sum) const; 32 26 33 void RemoveTwinsInterpol(Leds &leds, Int_t first, Double_t radius) const; 27 34 void DrawBox(const int x1, const int y1, … … 43 50 void SetCut(float cut) { fCut = cut; } 44 51 void FindStar(Leds &leds, int xc, int yc) const; 52 void FindStarCircle(Leds &leds, int xc, int yc) const; 53 45 54 void Execute(Leds &leds, int xc, int yc, double &bright) const; 46 55 void Execute(Leds &leds, int xc, int yc) const;
Note:
See TracChangeset
for help on using the changeset viewer.