Changeset 7788 for trunk/MagicSoft/Cosy
- Timestamp:
- 07/12/06 03:00:16 (18 years ago)
- Location:
- trunk/MagicSoft/Cosy
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Cosy/Changelog
r7787 r7788 37 37 is neccessary in root 4.04/02g to make cosy work is 38 38 unknown. Anyhow it makes switching the cameras more robust 39 40 * cosy.cc: 41 - updated writing log-files 42 - implemented sanity check for batch mode 43 44 * gui/MGAccuracy.cc, gui/MGStarg.cc: 45 - use GetabsDev from MAstro 46 - scale azimuth deviation to real distance on the sky 47 48 * main/MCosy.[h,cc]: 49 - updated writing log-files 50 - do no perfect position in case of move'n'track 51 - implemented WM_PREPS for predefined positions 52 - unified WM_TRACK and WM_GRB 53 - updated GetFileName 54 55 * main/MStarguider.cc: 56 - undef EXPERT 57 - some layout changes 58 - set rotation angle of starguider camera to -0.4deg 59 - unified FindStar and FindStarCircle 60 - updated writing log-files 61 - to calc skycenter the X-offset must be subtracted 62 63 * tcpip/MDriveCom.[h,cc]: 64 - implemented CommandPREPS 65 - implemented CommandARM 66 67 * videodev/FilterLed.[h,cc]: 68 - unified FindStar and FindStarCircle 69 - fixed algorithm FindStarCircle (it was not working for 70 bright stars and didn't take care of the edge of the 71 image!) 72 - fixed a long outstanding bug which accessed some memory 73 outside the image due to a wrong logical condition 39 74 40 75 -
trunk/MagicSoft/Cosy/cosy.cc
r4105 r7788 48 48 // this must move to MGCosy !!!! 49 49 // 50 const TString name = MCosy::GetFileName("log /cosy_%s.log");50 const TString name = MCosy::GetFileName("log", "cosy", "log"); 51 51 cout << "Open Logfile: " << name << endl; 52 52 … … 65 65 // FIXME: Fails deleteing something in TGClient::fWlist 66 66 TApplication *app=new TApplication("App", &argc, argv); 67 68 if (gROOT->IsBatch()) 69 { 70 cout << "ERROR - Cannot run in Batch mode!" << endl; 71 return 0; 72 } 67 73 68 74 // -
trunk/MagicSoft/Cosy/gui/MGAccuracy.cc
r4076 r7788 20 20 #include "coord.h" 21 21 #include "MTime.h" 22 #include "MAstro.h" 22 23 23 24 ClassImp(MGAccuracy); … … 238 239 void MGAccuracy::Update(Float_t pzd, Float_t azd, Float_t aaz) 239 240 { 240 const Float_t d2r = TMath::Pi()/180.; 241 242 pzd *= d2r; 243 azd *= d2r; 244 aaz *= d2r; 245 246 const double el = TMath::Pi()/2-pzd; 247 248 const double dphi2 = aaz/2.; 249 const double cos2 = cos(dphi2)*cos(dphi2); 250 const double sin2 = sin(dphi2)*sin(dphi2); 251 const double d = cos(azd)*cos2 - cos(2*el)*sin2; 252 253 // 254 // Original: 255 // cos(Zd1)*cos(Zd2)+sin(Zd1)*sin(Zd2)*cos(dAz) 256 // 257 // Correct: 258 // const double d = cos(azd)*cos2 - cos(el1+el2)*sin2; 259 // 260 // Estimated: 261 // const double d = cos(azd)*cos2 - cos(2*el)*sin2; 262 // 263 264 double dist = acos(d)*TMath::RadToDeg(); 241 const double dist = MAstro::GetDevAbs(pzd, azd, aaz); 265 242 266 243 UpdateText(dist); … … 303 280 } 304 281 305 void MGAccuracy::Update(ZdAz &pos, ZdAz &acc) 306 { 307 UpdateCross(acc.Az()*3600., acc.Zd()*3600.); 308 Update(pos.Zd(), acc.Zd(), acc.Az()); 282 void MGAccuracy::Update(ZdAz &pos, ZdAz &dev) 283 { 284 // Estimate the distance in az direction on the camera plane 285 const double daz = MAstro::GetDevAbs(pos.Zd(), 0, dev.Az())*3600.; 286 287 //cout << "--> T: " << dev.Az()*60 << " " << dev.Zd()*60. << endl; 288 289 UpdateCross(TMath::Sign(daz, dev.Az()), dev.Zd()*3600.); 290 Update(pos.Zd(), dev.Zd(), dev.Az()); 309 291 310 292 UpdateCanvas(); -
trunk/MagicSoft/Cosy/gui/MGStarg.cc
r4865 r7788 16 16 #include "coord.h" 17 17 #include "MTime.h" 18 #include "MAstro.h" 18 19 19 20 ClassImp(MGStarg); … … 36 37 text.SetTextAlign(11); // left, bottom (s.TAttText) 37 38 text.SetTextColor(3); 38 text.DrawText( 160, -220, "0.0125 deg");39 text.DrawText(220, -220, "0.75'"); 39 40 40 41 text.SetTextColor(5); 41 text.DrawText( 160, -250, "0.025 deg");42 text.DrawText(220, -250, "1.50'"); 42 43 43 44 text.SetTextColor(2); 44 text.DrawText( 160, -280, "0.05 deg");45 text.DrawText(220, -280, "3.00'"); 45 46 46 47 … … 218 219 void MGStarg::Update(Float_t pzd, Float_t azd, Float_t aaz) 219 220 { 220 const Float_t d2r = TMath::Pi()/180.; 221 222 pzd *= d2r; 223 azd *= d2r; 224 aaz *= d2r; 225 226 const double el = TMath::Pi()/2-pzd; 227 228 const double dphi2 = aaz/2.; 229 const double cos2 = cos(dphi2)*cos(dphi2); 230 const double sin2 = sin(dphi2)*sin(dphi2); 231 const double d = cos(azd)*cos2 - cos(2*el)*sin2; 232 233 double dist = acos(d)*TMath::RadToDeg(); 221 const double dist = MAstro::GetDevAbs(pzd, azd, aaz); 234 222 235 223 UpdateText(dist); … … 269 257 } 270 258 271 void MGStarg::Update(ZdAz &pos, ZdAz &acc) 272 { 273 274 UpdateCross(acc.Az()*3600., acc.Zd()*3600.); 275 Update(pos.Zd(), acc.Zd(), acc.Az()); 259 void MGStarg::Update(ZdAz &pos, ZdAz &dev) 260 { 261 // Estimate the distance in az direction on the camera plane 262 const double daz = MAstro::GetDevAbs(pos.Zd(), 0, dev.Az())*3600.; 263 264 //cout << "--> S: " << dev.Az()*60 << " " << dev.Zd()*60. << endl; 265 266 UpdateCross(TMath::Sign(daz, dev.Az()), dev.Zd()*3600.); 267 Update(pos.Zd(), dev.Zd(), dev.Az()); 276 268 277 269 UpdateCanvas(); 278 270 } 279 280 281 282 283 284 285 286 287 288 -
trunk/MagicSoft/Cosy/main/MCosy.cc
r7614 r7788 401 401 // 402 402 point.SetPointAccDec(0.2, 0.1); 403 403 404 point.SetPointVelocity(0.1); 404 405 … … 634 635 // open tpoint file 635 636 // 636 const TString name = GetFileName("tpoint /old-tpoint_%s.txt");637 const TString name = GetFileName("tpoint", "old-tpoint", "txt"); 637 638 cout << "TPoint-Cosy File ********* " << name << " ********** " << endl; 638 639 … … 675 676 676 677 ZdAz dest = *((ZdAz*)mp) * kDeg2Rad; 677 if (!SetPosition(dest ))678 if (!SetPosition(dest, kTRUE)) 678 679 return (void*)0x1234; 679 680 … … 686 687 //cout << "WM_TrackPosition: done. (return 0xabcd)" << endl; 687 688 return (void*)0xabcd; 688 689 /* 690 case WM_ARM: 691 //cout << "WM_Position: start." << endl; 692 { 693 if (!CheckNetwork()) 694 return (void*)0xebb0; 695 696 const bool arm = *((bool*)mp); 697 if (arm) 698 { 699 fMac1->Arm(); 700 fMac2->Arm(); 701 cout << "ARMED" << endl; 702 } 703 else 704 { 705 fMac1->Disarm(); 706 fMac2->Disarm(); 707 cout << "DISARMED" << endl; 708 } 709 } 710 //cout << "WM_Position: done. (return 0x7777)" << endl; 711 return (void*)0x9999; 712 */ 689 713 case WM_POSITION: 690 714 //cout << "WM_Position: start." << endl; … … 711 735 return (void*)0x7777; 712 736 737 case WM_PREPS: 738 //cout << "WM_Track: START" << endl; 739 { 740 if (!CheckNetwork()) 741 return (void*)0xebb0; 742 743 const char *preps = (const char*)mp; 744 cout << "Preposition command to " << preps << " received." << endl; 745 746 ifstream fin("prepos.txt"); 747 if (!fin) 748 { 749 cout << "ERROR: cannot open prepos.txt." << endl; 750 return (void*)0xebb1; 751 } 752 753 while (1) 754 { 755 Double_t zd, az; 756 fin >> zd >> az; 757 758 TString str; 759 str.ReadLine(fin); 760 if (!fin) 761 break; 762 763 str.ToLower(); 764 765 if (str.Strip(TString::kBoth)==preps) 766 { 767 ZdAz dest(zd, az); 768 SetPosition(dest*kDeg2Rad); 769 return (void*)0x7979; 770 } 771 cout << "ERROR - Requested preposition not found in file..." << endl; 772 } 773 } 774 //cout << "WM_Track: done. (return 0x8888)" << endl; 775 return (void*)0x7878; 776 713 777 case WM_TESTSE: 714 778 //cout << "WM_TestSe: start." << endl; … … 730 794 731 795 case WM_TRACK: 732 //cout << "WM_Track: START" << endl; 796 case WM_GRB: 797 //cout << "WM_Track/GRB: START" << endl; 733 798 { 734 799 RaDec dest = ((RaDec*)mp)[0]; … … 737 802 if (!CheckNetwork()) 738 803 return (void*)0xebb0; 739 TrackPosition(dest*kDeg2Rad); 804 805 if (msg==WM_TRACK) 806 TrackPosition(dest*kDeg2Rad); 807 else 808 TrackPositionGRB(dest*kDeg2Rad); 740 809 } 741 //cout << "WM_Track: done. (return 0x8888)" << endl; 742 return (void*)0x8888; 743 744 case WM_GRB: 745 //cout << "WM_Track: START" << endl; 746 { 747 RaDec dest = ((RaDec*)mp)[0]; 748 if (fStarguider) 749 fStarguider->SetPointingPosition(((RaDec*)mp)[1]); 750 if (!CheckNetwork()) 751 return (void*)0xebb0; 752 TrackPositionGRB(dest*kDeg2Rad); 753 } 754 //cout << "WM_Track: done. (return 0x8888)" << endl; 810 //cout << "WM_Track/GRB: done. (return 0x8888)" << endl; 755 811 return (void*)0x8888; 756 812 … … 1178 1234 avail |= (fZd2 && !fZd2->IsZombieNode()) ? 0x10 : 0; 1179 1235 avail |= (fAz && !fAz->IsZombieNode()) ? 0x20 : 0; 1236 // avail |= (!(fStatus&MDriveCom::kError) && 1 ? 0x40 : 0; 1180 1237 1181 1238 if (HasError()) … … 1471 1528 */ 1472 1529 1473 TString MCosy::GetFileName(const char * fmt)1530 TString MCosy::GetFileName(const char *path, const char *name, const char *ext) 1474 1531 { 1475 1532 // FIXME: Timeout missing 1533 1476 1534 while (1) 1477 1535 { 1478 1536 MTime time(-1); 1479 const TString name = Form(fmt, (const char*)time.GetFileName()); 1480 if (gSystem->AccessPathName(name, kFileExists)) 1481 return name; 1482 break; 1537 1538 // This is the full qualified date which is part of the name 1539 const TString clock = time.GetStringFmt("%y%m%d_%H%M%S"); 1540 1541 // This gives the night in which the date belongs to 1542 time.SetMjd(TMath::Nint(time.GetMjd())); 1543 1544 const TString night = time.GetStringFmt("%Y_%m_%d"); 1545 1546 const TString dir = Form("%s/%s", path, night.Data()); 1547 const TString fname = Form("%s_%s.%s", name, clock.Data(), ext); 1548 1549 const TString full = Form("%s/%s", dir.Data(), fname.Data()); 1550 1551 gSystem->mkdir(dir, kTRUE); 1552 1553 if (gSystem->AccessPathName(full, kFileExists)) 1554 return full; 1555 1556 break;// !!!!!!!!!!!!!!!!!!!!!!! 1483 1557 1484 1558 usleep(1000); … … 1498 1572 const Int_t id6 = env.GetValue("Az_Id-SE", 6); //6 1499 1573 1500 TString name = GetFileName("rep /cosy_%s.rep");1574 TString name = GetFileName("rep", "cosy", "rep"); 1501 1575 cout << "Open Repfile: " << name << endl; 1502 1576 fOutRep = new MLog(name, kTRUE); -
trunk/MagicSoft/Cosy/main/MCosy.h
r6841 r7788 38 38 #define WM_ENDSWITCH 0x1010 39 39 #define WM_GRB 0x1011 40 #define WM_PREPS 0x1012 41 #define WM_ARM 0x1013 40 42 41 43 class ShaftEncoder; … … 187 189 void SetStarguider(MStarguider *s) { fStarguider = s; } 188 190 189 static TString GetFileName(const char * name);191 static TString GetFileName(const char *path, const char *name, const char *ext); 190 192 191 193 MGCosy *GetWin() { return fWin; } -
trunk/MagicSoft/Cosy/main/MStarguider.cc
r7785 r7788 1 #undef EXPERT 1 2 #undef EXPERT 2 3 … … 335 336 336 337 fCZdAz = new MGCoordinates(this, kETypeZdAz, kFALSE); 337 fCZdAz->Move(240+12+28, fMenu->GetDefaultHeight()+581+ 12);338 fCZdAz->Move(240+12+28, fMenu->GetDefaultHeight()+581+20-4); 338 339 AddFrame(fCZdAz); 339 340 fList->Add(fCZdAz); 340 341 341 342 fPZdAz = new MGCoordinates(this, kETypeZdAz, kFALSE); 342 fPZdAz->Move(240+12+28, fMenu->GetDefaultHeight()+627+2* 12);343 fPZdAz->Move(240+12+28, fMenu->GetDefaultHeight()+627+2*20-4); 343 344 AddFrame(fPZdAz); 344 345 fList->Add(fPZdAz); 345 346 346 347 fDZdAz = new MGCoordinates(this, kETypeZdAz, kFALSE); 347 fDZdAz->Move(240+12+28, fMenu->GetDefaultHeight()+673+3* 12);348 fDZdAz->Move(240+12+28, fMenu->GetDefaultHeight()+673+3*20-4); 348 349 AddFrame(fDZdAz); 349 350 fList->Add(fDZdAz); 350 351 351 352 fSZdAz = new MGCoordinates(this, kETypeZdAz, kFALSE); 352 fSZdAz->Move(240+12+28, fMenu->GetDefaultHeight()+719+4* 12);353 fSZdAz->Move(240+12+28, fMenu->GetDefaultHeight()+719+4*20-4); 353 354 AddFrame(fSZdAz); 354 355 fList->Add(fSZdAz); 355 356 356 357 fTPoint = new TGTextButton(this, "TPoint"); 357 fTPoint->Move(4, fMenu->GetDefaultHeight()+722+3*1 2+25);358 fTPoint->Move(4, fMenu->GetDefaultHeight()+722+3*15+15); 358 359 fTPoint->AllowStayDown(kTRUE); 359 360 AddFrame(fTPoint); … … 361 362 362 363 fStargTPoint = new TGTextButton(this, "StargTPoint"); 363 fStargTPoint->Move(240+12+2 0, fMenu->GetDefaultHeight()+785);364 fStargTPoint->Move(240+12+28, fMenu->GetDefaultHeight()+785); 364 365 fStargTPoint->AllowStayDown(kTRUE); 365 366 AddFrame(fStargTPoint); … … 368 369 fFps = new TGLabel(this, "---fps"); 369 370 fFps->SetTextJustify(kTextRight); 370 fFps->Move(650-4 40, fMenu->GetDefaultHeight()+619+13+60+20);371 fFps->Move(650-495, fMenu->GetDefaultHeight()+619+13+60+20+2); 371 372 AddFrame(fFps); 372 373 fList->Add(fFps); 373 374 374 fPosZoom = new TGLabel(this, " ----.--d/----.--d (----, ----)");375 fPosZoom->SetTextJustify(kText Right);375 fPosZoom = new TGLabel(this, "(----, ----) ----.--d/----.--d"); 376 fPosZoom->SetTextJustify(kTextLeft); 376 377 fPosZoom->Move(4, fMenu->GetDefaultHeight()+765); 377 378 AddFrame(fPosZoom); … … 386 387 TGLabel *l = new TGLabel(this, "arcsec/pix"); 387 388 l->SetTextJustify(kTextLeft); 388 l->Move(60 5-400, fMenu->GetDefaultHeight()+619+13+60);389 l->Move(606-412, fMenu->GetDefaultHeight()+619+13+60); 389 390 AddFrame(l); 390 391 fList->Add(l); … … 392 393 l = new TGLabel(this, "deg"); 393 394 l->SetTextJustify(kTextLeft); 394 l->Move(60 5-410, fMenu->GetDefaultHeight()+619-10+60);395 l->Move(606-412, fMenu->GetDefaultHeight()+619-10+60); 395 396 AddFrame(l); 396 397 fList->Add(l); … … 398 399 l = new TGLabel(this, "Telescope pointing at"); 399 400 l->SetTextJustify(kTextLeft); 400 l->Move(240+12+20 , fMenu->GetDefaultHeight()+584-5);401 l->Move(240+12+20+7, fMenu->GetDefaultHeight()+584-5); 401 402 AddFrame(l); 402 403 fList->Add(l); … … 404 405 l = new TGLabel(this, "Starguider position"); 405 406 l->SetTextJustify(kTextLeft); 406 l->Move(240+12+20 , fMenu->GetDefaultHeight()+630+12-5);407 l->Move(240+12+20+7, fMenu->GetDefaultHeight()+630+20-5); 407 408 AddFrame(l); 408 409 fList->Add(l); … … 410 411 l = new TGLabel(this, "Misspointing"); 411 412 l->SetTextJustify(kTextLeft); 412 l->Move(240+12+20 , fMenu->GetDefaultHeight()+676+2*12-5);413 l->Move(240+12+20+7, fMenu->GetDefaultHeight()+676+2*20-5); 413 414 AddFrame(l); 414 415 fList->Add(l); … … 417 418 l = new TGLabel(this, "Misspointing/FindStar (Experts Only!)"); 418 419 l->SetTextJustify(kTextLeft); 419 l->Move(240+12+20, fMenu->GetDefaultHeight()+722+3* 12-5);420 l->Move(240+12+20, fMenu->GetDefaultHeight()+722+3*20-5); 420 421 AddFrame(l); 421 422 fList->Add(l); … … 436 437 fList->Add(fPixSize); 437 438 438 fAngle = new TGTextEntry(this, " 0", IDM_kAngle); 439 const Double_t angle = -0.4; 440 fSao->SetRotationAngle(angle); 441 442 txt = ""; 443 txt += angle; 444 445 fAngle = new TGTextEntry(this, txt, IDM_kAngle); 439 446 fAngle->SetAlignment(kTextCenterX); 440 447 fAngle->Move(547-410, fMenu->GetDefaultHeight()+617-10+60); … … 1385 1392 { 1386 1393 // open tpoint file 1387 const TString name = MCosy::GetFileName("tpoint /starg_%s.txt");1394 const TString name = MCosy::GetFileName("tpoint", "starg", "txt"); 1388 1395 cout << "TPoint-Starg File ********* " << name << " ********** " << endl; 1389 1396 … … 1451 1458 // Try to find Led in this area 1452 1459 Leds leds; 1453 f.FindStar Circle(leds, (Int_t)SearchCenter.X(), (Int_t)SearchCenter.Y());1460 f.FindStar(leds, (Int_t)SearchCenter.X(), (Int_t)SearchCenter.Y(), true); 1454 1461 1455 1462 // Check whether star found … … 1470 1477 if (!fOutRq) 1471 1478 { 1472 const TString name = MCosy::GetFileName("tpoint /starg_roquelamp_%s.txt");1479 const TString name = MCosy::GetFileName("tpoint", "roquelamp", "txt"); 1473 1480 cout << "Starg_RoqueLamp File ********* " << name << " ********** " << endl; 1474 1481 fOutRq = new ofstream(name); … … 1476 1483 } 1477 1484 1478 1479 1485 return relroquepos; 1480 1486 } 1481 1482 1487 1483 1488 ZdAz MStarguider::FindStar(FilterLed &f, FilterLed &f2, Ring ¢er, MTime &t, Double_t cut, Double_t box, Double_t scalefactor = 1.0) … … 1489 1494 // Try to find Led in this area 1490 1495 Leds leds; 1491 f.FindStar Circle(leds, (Int_t)center.GetX(), (Int_t)center.GetY());1496 f.FindStar(leds, (Int_t)center.GetX(), (Int_t)center.GetY(), true); 1492 1497 1493 1498 if (leds.GetEntries()<0) … … 1505 1510 return ZdAz(.0,.0); 1506 1511 } 1507 1508 1512 cout << "Found star @ " << flush; 1509 1513 star->Print(); … … 1561 1565 // open tpoint file 1562 1566 // 1563 const TString name = MCosy::GetFileName("tpoint /tpoint_%s.txt");1567 const TString name = MCosy::GetFileName("tpoint", "tpoint", "txt"); 1564 1568 cout << "TPoint-Starg File ********* " << name << " ********** " << endl; 1565 1569 … … 1715 1719 // Find Star at Center---for Tpoint Procedure 1716 1720 if (fDisplay->IsEntryChecked(IDM_kFindStar)) 1717 /*ZdAz zdaz =*/FindStar(f, f2, center, t, 3.5, 70);1721 FindStar(f, f2, center, t, 3.5, 70); 1718 1722 1719 1723 byte zimg[kZOOM*kZOOM]; … … 1779 1783 { 1780 1784 1781 XY roquelamp(0,0);1782 1783 1785 Double_t imageclean = 1.5; 1784 1786 Double_t boxradius = 60; … … 1786 1788 XY searchcenter(768/2-1,576/2+25); 1787 1789 1788 roquelamp = FindRoqueLamp(f, f2, sgcenter, t, imageclean, boxradius, searchcenter);1790 XY roquelamp = FindRoqueLamp(f, f2, sgcenter, t, imageclean, boxradius, searchcenter); 1789 1791 1790 1792 if (fOutRq) … … 1804 1806 1805 1807 // Find Spot on Camera Center in Starguider camera 1806 1807 1808 if (fOperations->IsEntryChecked(IDM_kRoqueLampAna)) 1808 1809 { … … 1832 1833 f2.DrawCircle(sgcenter, 115.0, 0x0fa); 1833 1834 } 1834 1835 1835 // we calculate the offset given by the three ETH Leds visible to 1836 1836 // the guide camera … … 1884 1884 1885 1885 // Position around which the circles are drawn. 1886 const Ring skycenter(768/2 +off.X(), 576/2+off.Y());1886 const Ring skycenter(768/2-off.X(), 576/2+off.Y()); 1887 1887 1888 1888 // There are two corrections to the misspointing … … 1896 1896 Leds spots; 1897 1897 f.SetBox(230); 1898 // f.SetCut(1.5); 1899 double bright; 1898 f.SetCut(2.5); 1899 1900 double bright; 1900 1901 f.ExecuteAndMark(spots, 530, 292, bright); 1901 MString txt; 1902 1903 MString txt; 1902 1904 txt.Print("Sky Brightness: %.1f", bright); 1903 1905 fSkyBright->SetText(txt); … … 1961 1963 { 1962 1964 f2.DrawCircle(center, 0x0a); 1963 f2.DrawCircle(center, 5.0,1965 f2.DrawCircle(center, 7.0, 1964 1966 fDisplay->IsEntryChecked(IDM_kFindStar)?3:0xb0); 1965 1967 f2.DrawCircle(center, 115.0, 0x0a); … … 2003 2005 if (aa.Az()<0) 2004 2006 aa.Az(aa.Az()+360); 2005 txt.Print(" %.1fd/%.1fd (%d, %d)", -aa.Alt(), aa.Az()-180, fDx, fDy);2007 txt.Print("(%d, %d) %.1fd/%.1fd", fDx, fDy, -aa.Alt(), aa.Az()-180); 2006 2008 } 2007 2009 else -
trunk/MagicSoft/Cosy/tcpip/MDriveCom.cc
r7764 r7788 118 118 } 119 119 120 bool MDriveCom::CommandPREPS(TString &str) 121 { 122 str = str.Strip(TString::kBoth); 123 if (str.IsNull()) 124 { 125 cout << "ERROR - No identifier for preposition (PREPS) given." << endl; 126 return false; 127 } 128 if (str.First(' ')>=0) 129 { 130 cout << "ERROR - PREPS command syntax error (contains whitespaces)." << endl; 131 return false; 132 } 133 134 str.ToLower(); 135 136 cout << "CC-COMMAND " << MTime(-1) << " PREPS '" << str << "'" << endl; 137 138 //cout << "MDriveCom - TRACK... start." << endl; 139 fQueue->PostMsg(WM_PREPS, (void*)str.Data(), str.Length()+1); 140 //cout << "MDriveCom - TRACK... done." << endl; 141 return true; 142 } 143 144 bool MDriveCom::CommandARM(TString &str) 145 { 146 str = str.Strip(TString::kBoth); 147 if (str.IsNull()) 148 { 149 cout << "ERROR - No identifier for ARM command." << endl; 150 return false; 151 } 152 if (str.First(' ')>=0) 153 { 154 cout << "ERROR - ARM command syntax error (contains whitespaces)." << endl; 155 return false; 156 } 157 158 str.ToLower(); 159 if (str!="lock" && str!="unlock") 160 { 161 cout << "ERROR - ARM command syntax error (neither LOCK nor UNLOCK)." << endl; 162 return false; 163 } 164 165 cout << "CC-COMMAND " << MTime(-1) << " ARM '" << str << "'" << endl; 166 167 bool lock = str=="lock"; 168 169 fQueue->PostMsg(WM_ARM, &lock, sizeof(lock)); 170 return true; 171 } 172 120 173 bool MDriveCom::InterpreteCmd(TString cmd, TString str) 121 174 { … … 148 201 149 202 if (cmd==(TString)"PREPS") 150 { 151 cout << "Prepos: " << str << endl; 152 return true; 153 } 203 return CommandPREPS(str); 154 204 155 205 if (cmd.IsNull() && str.IsNull()) -
trunk/MagicSoft/Cosy/tcpip/MDriveCom.h
r7764 r7788 25 25 bool CommandGRB(TString &str); 26 26 bool CommandZDAZ(TString &str); 27 bool CommandPREPS(TString &str); 28 bool CommandARM(TString &str); 27 29 28 30 public: … … 46 48 47 49 #endif 48 49 50 51 52 53 54 55 56 57 58 -
trunk/MagicSoft/Cosy/videodev/FilterLed.cc
r7230 r7788 125 125 float &my, unsigned int &sum) const 126 126 { 127 //------------------------------- 128 // Improved algorithm: 129 // 1. Look for the largest five-pixel-cross signal inside the box 130 int x0 = TMath::Max(x-box+1, 0); 131 int y0 = TMath::Max(y-box+1, 0); 132 133 int x1 = TMath::Min(x+box+1-1, fW); 134 int y1 = TMath::Min(y+box+1-1, fH); 135 136 int maxx=0; 137 int maxy=0; 138 139 unsigned int max =0; 140 for (int dx=x0; dx<x1; dx++) 141 { 142 for (int dy=y0; dy<y1; dy++) 143 { 144 const unsigned int sumloc = 145 fImg[(dy+0)*fW + (dx-1)] + 146 fImg[(dy+0)*fW + (dx+1)] + 147 fImg[(dy+1)*fW + dx] + 148 fImg[(dy+0)*fW + dx] + 149 fImg[(dy-1)*fW + dx]; 150 151 if(sumloc<=max) 152 continue; 153 154 maxx=dx; 155 maxy=dy; 156 max =sum; 157 } 158 } 159 160 // 2. Calculate mean position inside a circle around 161 // the highst cross-signal with radius of 6 pixels. 127 162 unsigned int sumx=0; 128 163 unsigned int sumy=0; 129 164 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. 165 const int rad = 17; 166 167 x0 = TMath::Max(x-box, maxx-rad); 168 y0 = TMath::Max(y-box, maxy-rad); 169 170 x1 = TMath::Min(x+box+1, maxx+rad+1); 171 y1 = TMath::Min(y+box+1, maxy+rad+1); 151 172 152 173 sum=0; 153 for (int dx=x -box; dx<x+box+1; dx++)154 for (int dy=y -box; dy<y+box+1; dy++)174 for (int dx=x0; dx<x1; dx++) 175 for (int dy=y0; dy<y1; dy++) 155 176 { 156 177 const byte &m = fImg[dy*fW+dx]; 157 178 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 } 179 sumx += m*dx; 180 sumy += m*dy; 181 sum += m; 166 182 } 167 183 … … 171 187 return (int)my*fW + (int)mx; 172 188 } 173 174 175 189 176 190 int FilterLed::GetMeanPositionCircle(const int x, const int y, … … 323 337 void FilterLed::Execute(Leds &leds, int xc, int yc, double &bright) const 324 338 { 325 int x0 = xc-fBox; 326 int x1 = xc+fBox; 327 int y0 = yc-fBox; 328 int y1 = yc+fBox; 329 330 if (x0<0) x0=0; 331 if (y0<0) y0=0; 332 if (x1>fW) x1=fW; 333 if (y1>fH) y1=fH; 339 const int x0 = TMath::Max(xc-fBox, 0); 340 const int y0 = TMath::Max(yc-fBox, 0); 341 const int x1 = TMath::Min(xc+fBox, fW); 342 const int y1 = TMath::Min(yc+fBox, fH); 334 343 335 344 const int wx = x1-x0; … … 430 439 431 440 RemoveTwinsInterpol(leds, first, 5); 432 433 434 } 435 436 void FilterLed::FindStar(Leds &leds, int xc, int yc) const 441 } 442 443 void FilterLed::FindStar(Leds &leds, int xc, int yc, bool circle) const 437 444 { 438 445 // fBox: radius of the inner (signal) box … … 442 449 // Define inner box in which to search the signal 443 450 // 444 int x0 = xc-fBox; 445 int x1 = xc+fBox; 446 int y0 = yc-fBox; 447 int y1 = yc+fBox; 448 449 if (x0<0) x0=0; 450 if (y0<0) y0=0; 451 if (x1>fW) x1=fW; 452 if (y1>fH) y1=fH; 451 const int x0 = TMath::Max(xc-fBox, 0); 452 const int y0 = TMath::Max(yc-fBox, 0); 453 const int x1 = TMath::Min(xc+fBox, fW); 454 const int y1 = TMath::Min(yc+fBox, fH); 453 455 454 456 // … … 459 461 const double sqrt2 = sqrt(2.); 460 462 461 int xa = xc-(int)rint(fBox*sqrt2); 462 int xb = xc+(int)rint(fBox*sqrt2); 463 int ya = yc-(int)rint(fBox*sqrt2); 464 int yb = yc+(int)rint(fBox*sqrt2); 465 466 if (xa<0) xa=0; 467 if (ya<0) ya=0; 468 if (xb>fW) xb=fW; 469 if (yb>fH) yb=fH; 463 const int xa = TMath::Max(xc-(int)rint(fBox*sqrt2), 0); 464 const int ya = TMath::Max(yc-(int)rint(fBox*sqrt2), 0); 465 const int xb = TMath::Min(xc+(int)rint(fBox*sqrt2), fW); 466 const int yb = TMath::Min(yc+(int)rint(fBox*sqrt2), fH); 470 467 471 468 // … … 538 535 float mx, my; 539 536 unsigned int mag; 540 int pos = GetMeanPosition(xc, yc, fBox-1, mx, my, mag);541 542 if (pos<0 || pos>=fW*fH &&fImg[pos]<sum+fCut*sdev)537 int pos = circle ? GetMeanPositionCircle(xc, yc, fBox-1, mx, my, mag) : GetMeanPosition(xc, yc, fBox-1, mx, my, mag); 538 539 if (pos<0 || pos>=fW*fH || fImg[pos]<sum+fCut*sdev) 543 540 return; 544 541 … … 549 546 } 550 547 551 void FilterLed::FindStarCircle(Leds &leds, int xc, int yc) const552 {553 // fBox: radius of the inner (signal) box554 // Radius of the outer box is fBox*sqrt(2)555 556 //557 // Define inner box in which to search the signal558 //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 almost571 // the same number of pixels in which the background572 // is calculated573 //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 square588 // excluding the inner part were we expect589 // 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<max612 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 noise617 // (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 else627 n++;628 }629 630 //631 // Mark the background region632 //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 star652 //653 float mx, my;654 unsigned int mag;655 656 // int pos = GetMeanPosition(xc, yc, fBox-1, mx, my, mag);657 658 // try new method659 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 671 548 void FilterLed::Stretch() const 672 549 { … … 698 575 } 699 576 } 700 -
trunk/MagicSoft/Cosy/videodev/FilterLed.h
r7230 r7788 49 49 void SetBox(int box) { fBox = box; } 50 50 void SetCut(float cut) { fCut = cut; } 51 void FindStar(Leds &leds, int xc, int yc) const; 52 void FindStarCircle(Leds &leds, int xc, int yc) const; 51 void FindStar(Leds &leds, int xc, int yc, bool circle=false) const; 53 52 54 53 void Execute(Leds &leds, int xc, int yc, double &bright) const;
Note:
See TracChangeset
for help on using the changeset viewer.