- Timestamp:
- 05/15/04 16:46:27 (21 years ago)
- Location:
- trunk/MagicSoft/Cosy
- Files:
-
- 2 added
- 46 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Cosy/.cosyrc_magic
r2019 r4076 1 # 2 # .cosyrc 3 # 4 # Default values are commented out 5 # 1 6 7 # Number of motor revolution necessary to turn the 8 # telescope 360deg. (Remark: Here we do not talk about 9 # revolutions of the 'real' motor, but about revolutions 10 # 'seen' by the Macs) 2 11 Az_GearRatio[U_mot/U_tel]: 1338.8 3 # 1338.34 12 Zd_GearRatio[U_mot/U_tel]: 1165.2 5 # old value: 1165.2, try: 1211.86 #1149.57 #1208.298 13 14 # CANbus Id of the three MACS. -1 means not connected. 15 # MAC1 is Azimuth-1 16 # MAC2 is Azimuth-2 17 # MAC is Zenith Angle 9 18 Az_Id-MAC1: 1 10 19 Az_Id-MAC2: -1 11 20 Zd_Id-MAC: 3 12 21 22 # CANbus Id of the three Shaftencoders. 23 # SE1 is Zenith Angle-1 24 # SE2 is Zenith Angle-2 25 # SE is Azimuth 13 26 Az_Id-SE: 16 14 27 Zd_Id-SE1: 17 15 28 Zd_Id-SE2: 18 16 29 17 18 30 # Software endswitch 31 #Az_Min[deg]: -95.0 32 #Zd_Min[deg]: -75.0 33 #Az_Max[deg]: 305.0 34 #Zd_Max[deg]: 98.25 -
trunk/MagicSoft/Cosy/Changelog
r2751 r4076 1 1 -*-*- END -*-*- 2 2004/05/15 - Thomas Bretz (La Palma) 3 4 * .cosyrc_magic: 5 - updated with some comments 6 7 * Makefile: 8 - added many more links necessary for current make 9 (should be replaced by libmars.so in the future) 10 11 * Makefile.conf.general: 12 - added GX11 and HistPainter 13 14 * cosy.cc, starg.cc: 15 - Moved initialization of Camera to MStarguider 16 - added command line option to choose ccd channel 17 18 * leds.txt: 19 - replaced with new LED positions (OFFSETS MISSING) 20 21 * stars.txt: 22 - added many more stars 23 24 * base/coord.h: 25 - added operator/=(XY&) 26 27 * base/msgqueue.cc, candrv/sdolist.cc: 28 - added more output in case mutex is already locked by the same thread 29 30 * candrv/vmodican.cc: 31 - some changes to output 32 33 * catalog/SlaStars.cc: 34 - changed some comments 35 36 * catalog/StarCatalog.[h,cc]: 37 - replaced old algorithms by MAstroCatalog and new simplifications 38 to calculate star-positions accuratly by combining slalib with 39 MAstroCatalog 40 41 * devdrv/macs.h: 42 - added GetPosTime 43 44 * devdrv/shaftencoder.[h,cc]: 45 - added output to report file 46 47 * gui/MGAccuracy.[h,cc]: 48 - added time development curve (blue) 49 50 * gui/MGEmbeddedCanvas.h, gui/MGSkyPosition.h, 51 gui/MGVelocity.h: 52 - changed ifndef define 53 54 * gui/MGImage.[h,cc]: 55 - enhancements in speed 56 - enhancements in mutex locking mechanism 57 58 * gui/MGPngReader.cc, gui/MGTPoint.cc: 59 - changed meaning of PixSize 60 61 * gui/MGVelocity.cc: 62 - fixed units 63 64 * main/MCaos.[h,cc]: 65 - changed ring radius from 266/272 to 266,268 66 - moved drawing circles to MStarguider 67 68 * main/MCosy.[h,cc]: 69 - moved big parts of the code to MPointing and MTracking 70 - removed old conversion constants (Se to RE, etc) and 71 replaced by more meaningful ones 72 - prepare displaying starguider image 73 - added GetFileName to globally prepare correct file names 74 75 * main/MPointing.cc: 76 - fixed missing SetDecelaration 77 - changed to new unit conversion constants 78 - Use SendStatus instead of Send 79 80 * main/MStarguider.cc: 81 - added update and support of cosy-image display 82 - added channel swicthing for the frame grabber 83 - added algorithm to find star position FindStar 84 - commented out starguider algorithms 85 - draw support lines and grid stuff 86 87 * main/MTracking.[h,cc]: 88 - changed to new unit conversion constants 89 - added output of RE stuff to report file 90 - some simplification to tracking thread 91 92 * base/MString.[h,cc]: 93 - added as a thread safe replacement for Form() 94 95 * tcpip/MCeCoCom.[h,cc]: 96 - changed support for Weather information 97 98 * tcpip/MDriveCom.[h,cc]: 99 - changed output 100 - added SendStatus 101 102 * tcpip/MTcpIpIO.cc: 103 - changed output 104 - output reports to report file 105 106 * tpoint/gui.C: 107 - read new starg_* files 108 109 * videodev/Camera.[h,cc]: 110 - some enhancements to ioctl call 111 - some changes to output 112 - changes a bit the bahaviour of mutices 113 - replaced fRunning by mutex 114 - changes to ExitLoop and IsRunning 115 - added support for several frame grabber channels 116 117 * videodev/FilterLed.[h,cc] 118 - added new algorithms to find star 119 - small updates to star finding support 120 121 * videodev/PixGetter.h: 122 - added a virtual empty destructor (IMPORTANT) 123 124 125 2 126 2003/12/29 - Thomas Bretz 3 127 -
trunk/MagicSoft/Cosy/Makefile
r3897 r4076 127 127 links: 128 128 @ln -sf ../../Mars/mbase/MAGIC.h base/MAGIC.h 129 @ln -sf ../../Mars/mbase/MLog.h base/MLog.h129 @ln -sf ../../Mars/mbase/MLog.h base/MLog.h 130 130 @ln -sf ../../Mars/mbase/MLog.cc base/MLog.cc 131 @ln -sf ../../Mars/mbase/MLogManip.h base/MLogManip.h 131 @ln -sf ../../Mars/mbase/MLogPlugin.h base/MLogPlugin.h 132 @ln -sf ../../Mars/mbase/MLogPlugin.cc base/MLogPlugin.cc 133 @ln -sf ../../Mars/mbase/MLogManip.h base/MLogManip.h 132 134 @ln -sf ../../Mars/mbase/MLogManip.cc base/MLogManip.cc 133 @ln -sf ../../Mars/mbase/MAstro.h base/MAstro.h 134 @ln -sf ../../Mars/mbase/MAstro.cc base/MAstro.cc 135 @ln -sf ../../Mars/mbase/MGList.h base/MGList.h 135 @ln -sf ../../Mars/mbase/MGList.h base/MGList.h 136 136 @ln -sf ../../Mars/mbase/MGList.cc base/MGList.cc 137 @ln -sf ../../Mars/mbase/MTime.h base/MTime.h137 @ln -sf ../../Mars/mbase/MTime.h base/MTime.h 138 138 @ln -sf ../../Mars/mbase/MTime.cc base/MTime.cc 139 @ln -sf ../../Mars/mbase/MParContainer.h base/MParContainer.h139 @ln -sf ../../Mars/mbase/MParContainer.h base/MParContainer.h 140 140 @ln -sf ../../Mars/mbase/MParContainer.cc base/MParContainer.cc 141 @ln -sf ../../Mars/mtemp/MObservatory.h base/MObservatory.h 142 @ln -sf ../../Mars/mtemp/MObservatory.cc base/MObservatory.cc 141 @ln -sf ../../Mars/mbase/MString.h base/MString.h 142 @ln -sf ../../Mars/mbase/MString.cc base/MString.cc 143 @ln -sf ../../Mars/mbase/MGMap.h base/MGMap.h 144 @ln -sf ../../Mars/mbase/MGMap.cc base/MGMap.cc 145 @ln -sf ../../Mars/mgeom/MGeomMirror.h base/MGeomMirror.h 146 @ln -sf ../../Mars/mgeom/MGeomMirror.cc base/MGeomMirror.cc 147 @ln -sf ../../Mars/mgeom/MGeomCam.h base/MGeomCam.h 148 @ln -sf ../../Mars/mgeom/MGeomCam.cc base/MGeomCam.cc 149 @ln -sf ../../Mars/mgeom/MGeomPix.h base/MGeomPix.h 150 @ln -sf ../../Mars/mgeom/MGeomPix.cc base/MGeomPix.cc 151 @ln -sf ../../Mars/mgeom/MGeomCamMagic.h base/MGeomCamMagic.h 152 @ln -sf ../../Mars/mgeom/MGeomCamMagic.cc base/MGeomCamMagic.cc 153 @ln -sf ../../Mars/mastro/MAstro.h base/MAstro.h 154 @ln -sf ../../Mars/mastro/MAstro.cc base/MAstro.cc 155 @ln -sf ../../Mars/mastro/MAstroCatalog.h base/MAstroCatalog.h 156 @ln -sf ../../Mars/mastro/MAstroCatalog.cc base/MAstroCatalog.cc 157 @ln -sf ../../Mars/mastro/MAstroCamera.h base/MAstroCamera.h 158 @ln -sf ../../Mars/mastro/MAstroCamera.cc base/MAstroCamera.cc 159 @ln -sf ../../Mars/mastro/MAstroSky2Local.h base/MAstroSky2Local.h 160 @ln -sf ../../Mars/mastro/MAstroSky2Local.cc base/MAstroSky2Local.cc 161 @ln -sf ../../Mars/mastro/MObservatory.h base/MObservatory.h 162 @ln -sf ../../Mars/mastro/MObservatory.cc base/MObservatory.cc 163 @ln -sf ../../Mars/mhist/MHCamera.h base/MHCamera.h 164 @ln -sf ../../Mars/mhist/MHCamera.cc base/MHCamera.cc 165 @ln -sf ../../Mars/mhbase/MH.h base/MH.h 166 @ln -sf ../../Mars/mhbase/MH.cc base/MH.cc 167 @ln -sf ../../Mars/mhbase/MBinning.h base/MBinning.h 168 @ln -sf ../../Mars/mhbase/MBinning.cc base/MBinning.cc 169 @ln -sf ../../Mars/mbase/MParList.h base/MParList.h 170 @ln -sf ../../Mars/mbase/MParList.cc base/MParList.cc 171 @ln -sf ../../Mars/mgui/MHexagon.h base/MHexagon.h 172 @ln -sf ../../Mars/mgui/MHexagon.cc base/MHexagon.cc 173 @ln -sf ../../Mars/mgui/MCamEvent.h base/MCamEvent.h 174 @ln -sf ../../Mars/mgui/MCamEvent.cc base/MCamEvent.cc 143 175 144 176 magic: -
trunk/MagicSoft/Cosy/Makefile.conf.general
r2616 r4076 4 4 5 5 ROOTVER = `root-config --version` 6 ROOTLIBS = `root-config --libs` -lThread 7 ROOTGLIBS = `root-config --glibs` -lThread 6 ROOTLIBS = `root-config --libs` -lThread -lGX11 -lHistPainter 7 ROOTGLIBS = `root-config --glibs` -lThread -lGX11 -lHistPainter 8 8 ROOTCFLAGS = `root-config --cflags` 9 9 -
trunk/MagicSoft/Cosy/base/coord.h
r2278 r4076 90 90 void Az(double d) { fY=d; } 91 91 void operator*=(const XY &c) { fX*=c.X(); fY*=c.Y(); } 92 void operator/=(const XY &c) { fX/=c.X(); fY/=c.Y(); } 92 93 void operator-=(const AltAz &c) { fX-=c.fX; fY-=c.fY; } 93 94 void operator+=(const AltAz &c) { fX+=c.fX; fY+=c.fY; } … … 117 118 void Az(double d) { fY=d; } 118 119 void operator*=(const XY &c) { fX*=c.X(); fY*=c.Y(); } 120 void operator/=(const XY &c) { fX/=c.X(); fY/=c.Y(); } 119 121 void operator-=(const ZdAz &c) { fX-=c.fX; fY-=c.fY; } 120 122 void operator+=(const ZdAz &c) { fX+=c.fX; fY+=c.fY; } -
trunk/MagicSoft/Cosy/base/msgqueue.cc
r2518 r4076 89 89 // a PostMsg is processed correctly 90 90 // 91 fMuxMsg.Lock(); 91 if (fMuxMsg.Lock()==13) 92 cout << "MsgQueue::Thread - mutex is already locked by this thread." << endl; 92 93 fBreak = 0; 93 fMuxMsg.UnLock(); 94 if (fMuxMsg.UnLock()==13) 95 cout << "MsgQueue::Thread - tried to unlock mutex locked by other thread." << endl; 94 96 95 97 #ifdef DEBUG … … 130 132 cout << "MsgQueue::PostMsg: Locking MsgQueue mutex..." << flush; 131 133 #endif 132 fMuxMsg.Lock(); 134 if (fMuxMsg.Lock()==13) 135 cout << "MsgQueue::PostMsg - mutex is already locked by this thread." << endl; 133 136 #ifdef DEBUG 134 137 cout << "done." << endl; … … 145 148 if (fBreak) 146 149 { 147 fMuxMsg.UnLock(); 150 if (fMuxMsg.UnLock()==13) 151 cout << "MsgQueue::PostMsg - tried to unlock mutex locked by other thread." << endl; 148 152 #ifdef DEBUG 149 153 cout << "------------> MsgQueue::PostMsg: Proc still pending... Message IGNORED." << endl; … … 176 180 #endif 177 181 fStart = 1; 178 fMuxMsg.UnLock(); 182 if (fMuxMsg.UnLock()==13) 183 cout << "MsgQueue::PostMsg - tried to unlock mutex locked by other thread." << endl; 179 184 #ifdef DEBUG 180 185 cout << "done." << endl; -
trunk/MagicSoft/Cosy/candrv/sdolist.cc
r2518 r4076 20 20 void PendingSDOList::DelAll() 21 21 { 22 fMux.Lock(); 22 if (fMux.Lock()==13) 23 cout << "PendingSDOList::DelAll - mutex is already locked by this thread" << endl; 23 24 24 25 PendingSDO *prev = fFirst; … … 35 36 fLast = fFirst; 36 37 37 fMux.UnLock(); 38 if (fMux.UnLock()==13) 39 cout << "PendingSDOList::DelAll - tried to unlock mutex locked by other thread." << endl; 38 40 } 39 41 … … 42 44 PendingSDO *sdo = fFirst; 43 45 44 fMux.Lock(); 46 if (fMux.Lock()==13) 47 cout << "PendingSDOList::Add - mutex is already locked by this thread" << endl; 45 48 while ((sdo=sdo->Next)) 46 49 if (sdo->Node==node && sdo->Idx==idx && sdo->Subidx==subidx) … … 54 57 fLast->Next = new PendingSDO(node, idx, subidx); 55 58 fLast = fLast->Next; 56 fMux.UnLock(); 59 if (fMux.UnLock()==13) 60 cout << "PendingSDOList::Add - tried to unlock mutex locked by other thread." << endl; 57 61 } 58 62 … … 62 66 PendingSDO *sdo; 63 67 64 fMux.Lock(); 68 if (fMux.Lock()==13) 69 cout << "PendingSDOList::Del - mutex is already locked by this thread" << endl; 65 70 while ((sdo=prev->Next)) 66 71 { … … 80 85 break; 81 86 } 82 fMux.UnLock(); 87 if (fMux.UnLock()==13) 88 cout << "PendingSDOList::Del - tried to unlock mutex locked by other thread." << endl; 83 89 } 84 90 … … 93 99 PendingSDO *sdo = fFirst; 94 100 95 fMux.Lock(); 101 if (fMux.Lock()==13) 102 cout << "PendingSDOList::IsPending(byte) - mutex is already locked by this thread" << endl; 96 103 while ((sdo=sdo->Next)) 97 104 if (sdo->Node==node) … … 100 107 break; 101 108 } 102 fMux.UnLock(); 109 if (fMux.UnLock()==13) 110 cout << "PendingSDOList::IsPending(byte) - tried to unlock mutex locked by other thread." << endl; 103 111 104 112 return rc; … … 110 118 PendingSDO *sdo = fFirst; 111 119 112 fMux.Lock(); 120 if (fMux.Lock()==13) 121 cout << "PendingSDOList::IsPending - mutex is already locked by this thread" << endl; 113 122 while ((sdo=sdo->Next)) 114 123 if (sdo->Node==node && sdo->Idx==idx && sdo->Subidx==subidx) … … 117 126 break; 118 127 } 119 fMux.UnLock(); 128 if (fMux.UnLock()==13) 129 cout << "PendingSDOList::IsPending - tried to unlock mutex locked by other thread." << endl; 120 130 121 131 return rc; -
trunk/MagicSoft/Cosy/candrv/vmodican.cc
r2518 r4076 116 116 unsigned char c; 117 117 const int n = read(fd, &c, 1); 118 119 118 if (n<0) 120 119 { 121 120 cerr << "Vmodican: read(" << dec << (int)fd << "," << (void*)&c; 122 cerr << ",1) returned c=" << (int)c << " '" << strerror(errno);123 cerr << "' (errno = " << errno << ")" << endl;121 cerr << ",1) returned rc=" << n << " c=" << (int)c << " '"; 122 cerr << strerror(errno) << "' (errno = " << errno << ")" << endl; 124 123 continue; 125 //return (void *)1;126 124 } 127 125 … … 936 934 // and switch the can bus communication on 937 935 // 938 VmodIcan::VmodIcan(const char *dev, const int baud, MLog &out) : Log(out), MThread(false, -10)//: CanDriver(dev, baud)936 VmodIcan::VmodIcan(const char *dev, const int baud, MLog &out) : Log(out), MThread(false, 10)//: CanDriver(dev, baud) 939 937 { 940 938 // -
trunk/MagicSoft/Cosy/catalog/SlaStars.cc
r3897 r4076 159 159 double az; 160 160 slaAopqk (r, d, (double*)fAoprms, 161 &az, // observed azimuth (radians: N=0,E=90) 162 &zd, // observed zenith distance (radians) [-pi/2, pi/2]161 &az, // observed azimuth (radians: N=0,E=90) [-pi, pi] 162 &zd, // observed zenith distance (radians) [-pi/2, pi/2] 163 163 &h0, // observed hour angle (radians) 164 164 &d1, // observed declination (radians) … … 175 175 ZdAz SlaStars::GetApproxVel(const RaDec &radec) const // [rad/rad] 176 176 { 177 // radec [rad] 178 // GetApproxVel [rad/rad] 177 179 double az, vaz, aaz; 178 180 double el, vel, ael; -
trunk/MagicSoft/Cosy/catalog/StarCatalog.cc
r2407 r4076 5 5 6 6 #include <TSystem.h> 7 #include <TRotation.h> 7 8 8 9 #include "slalib.h" … … 11 12 12 13 #include "MStarList.h" 14 #include "MAstroCatalog.h" 13 15 14 16 ClassImp(StarCatalog); 15 17 16 StarCatalog::StarCatalog(MObservatory::LocationName_t key) : SlaStars(key), fSao(NULL), fSrt(NULL), fEntries(0), fSinAngle(0), fCosAngle(1) 17 { 18 // p = pointer to MainFrame (not owner) 19 20 // 21 // read index file 22 // 23 File idx("sao/sao-sort.idx", "r"); 24 if (!idx) 25 return; 26 27 while (!idx.Eof()) 28 { 29 idx.Newline(); 30 fEntries++; 31 } 32 33 idx.Reset(); 34 35 fSrt = new sort_t[fEntries]; 36 37 for (int i=0; i<fEntries; i++) 38 { 39 fSrt[i].ra = idx.Geti(4); 40 fSrt[i].dec = idx.Geti(4); 41 fSrt[i].nr = idx.Geti(10); 42 idx.Newline(); 43 } 44 45 // 46 // open catalog 47 // 48 fSao = new SaoFile("sao/sao-sort.cmp"); 18 StarCatalog::StarCatalog(MObservatory::LocationName_t key) : SlaStars(key), fAstro(0), /*fSao(NULL), fSrt(NULL), fEntries(0),*/ fSinAngle(0), fCosAngle(1) 19 { 20 fAstro = new MAstroCatalog; 21 fAstro->SetObservatory(*this); 22 fAstro->SetPlainScreen(); 49 23 } 50 24 51 25 StarCatalog::~StarCatalog() 52 26 { 53 if (fSrt) 54 delete fSrt; 55 if (fSao) 56 delete fSao; 27 delete fAstro; 57 28 } 58 29 59 30 void StarCatalog::SetPixSize(const double pixsize) 60 31 { 61 fPixSize = D2PI/360.0 * pixsize; 62 63 fWidth = fPixSize * 768/2; 64 fHeight = fPixSize * 576/2; 32 // pixsize [arcsec/pixel] 33 fPixSize = D2PI/360.0*pixsize/3600; // [rad / (deg*pixel)] 34 fAstro->SetRadiusFOV(pixsize, 768, 576); 65 35 } 66 36 … … 70 40 } 71 41 42 void StarCatalog::SetLimitMag(const float mag) 43 { 44 fLimitMag = mag; 45 fAstro->SetLimMag(mag); 46 } 47 48 void StarCatalog::SetMjd(double mjd) 49 { 50 SlaStars::SetMjd(mjd); 51 fAstro->SetTime(MTime(mjd)); 52 } 72 53 73 54 void StarCatalog::SetAltAz(const AltAz &altaz) 74 55 { 75 56 fAltAz = altaz * D2PI/360.0; 76 77 cout << "Set --> Alt: " << 360.0/D2PI*fAltAz.Alt();78 cout << " Az: " << fAltAz.Az() << endl;79 80 57 fRaDec = CalcRaDec(fAltAz); 81 58 82 cout << "Ra: " << 360.0/D2PI*fRaDec.Ra(); 83 cout << " Dec: " << 360.0/D2PI*fRaDec.Dec() << endl; 84 85 CalcAltAzRange(); 86 CalcRaDecRange(); 59 fAstro->SetRaDec(fRaDec.Ra(), fRaDec.Dec()); 60 } 61 62 void StarCatalog::Reload() 63 { 64 fAstro->SetLimMag(99); 65 //fAstro->ReadBSC("bsc5.dat"); 66 //fAstro->ReadHeasarcPPM("heasarc_ppm.tdat"); 67 fAstro->ReadCompressed("ppm9.bin"); 68 fAstro->SetLimMag(fLimitMag); 87 69 } 88 70 89 71 void StarCatalog::SetRaDec(const RaDec &radec) 90 72 { 91 fRaDec = radec; 92 fRaDec *= D2PI/360.0; 93 73 const RaDec rd = fRaDec*360.0/D2PI;; 74 75 const Bool_t same = 76 rd.Ra() >radec.Ra() -1e-5 && rd.Ra() <radec.Ra() +1e-5 && 77 rd.Dec()>radec.Dec()-1e-5 && rd.Dec()<radec.Dec()+1e-5; 78 79 fRaDec = radec * D2PI/360.0; 94 80 fAltAz = CalcAltAz(fRaDec); 95 81 96 //cout << "Alt: " << 360.0/D2PI*fAltAz.Alt() << " "; 97 //cout << "Az: " << 360.0/D2PI*fAltAz.Az() << endl; 98 99 CalcRaDecRange(); 100 CalcAltAzRange(); 101 } 102 103 void StarCatalog::CalcAltAzRange() 104 { 105 byte fAlt0[180]; 106 107 for (int h=0; h<180; h++) 108 fAlt0[h] = kFALSE; 109 110 for (int h=0; h<360; h++) 111 fAz0[h] = kFALSE; 112 113 double az0, alt0; 114 double az1, alt1; 115 // 116 // scan horizontal border 117 // 118 for (int x=-768/2; x<768/2+1; x++) 119 { 120 slaDh2e(DPI+x*fPixSize, -fHeight, DPI/2-fAltAz.Alt(), &az0, &alt0); 121 slaDh2e(DPI+x*fPixSize, +fHeight, DPI/2-fAltAz.Alt(), &az1, &alt1); 122 123 const int z0 = ((int)(360.0/D2PI*(az0+fAltAz.Az()))+360)%360; 124 const int t0 = (int)(360.0/D2PI*alt0); 125 126 fAz0[z0] = kTRUE; 127 128 if (-89<=t0 && t0<=90) 129 fAlt0[90-t0] = kTRUE; 130 131 const int z1 = ((int)(360.0/D2PI*(az1+fAltAz.Az()))+360)%360; 132 const int t1 = (int)(360.0/D2PI*alt1); 133 134 fAz0[z1] = kTRUE; 135 136 if (-89<=t1 && t1<=90) 137 fAlt0[90-t1] = kTRUE; 138 } 139 140 // 141 // scan vertical border 142 // 143 for (int y=-576/2; y<576/2+1; y++) 144 { 145 slaDh2e(DPI-fWidth, y*fPixSize, DPI/2-fAltAz.Alt(), &az0, &alt0); 146 slaDh2e(DPI+fWidth, y*fPixSize, DPI/2-fAltAz.Alt(), &az1, &alt1); 147 148 const int z0 = ((int)(360.0/D2PI*(az0+fAltAz.Az()))+360)%360; 149 const int t0 = (int)(360.0/D2PI*alt0); 150 151 fAz0[z0] = kTRUE; 152 153 if (-89<=t0 && t0<=90) 154 fAlt0[90-t0] = kTRUE; 155 156 const int z1 = ((int)(360.0/D2PI*(az1+fAltAz.Az()))+360)%360; 157 const int t1 = (int)(360.0/D2PI*alt1); 158 159 fAz0[z1] = kTRUE; 160 161 if (-89<=t1 && t1<=90) 162 fAlt0[90-t1] = kTRUE; 163 } 164 165 // 166 // count degrees of azimut 167 // 168 fAzCnt=0; 169 for (int x=0; x<360; x++) 170 if (fAz0[x]) 171 fAzCnt++; 172 173 //cout << "fAzCnt: " << setw(3) << fAzCnt << " " << flush; 174 175 // 176 // calculate min and max of altitude 177 // 178 fAltMin=0; 179 fAltMax=0; 180 for (int y=0; y<180; y++) 181 { 182 if (fAlt0[y]) 183 fAltMax = y; 184 185 if (fAlt0[179-y]) 186 fAltMin = 179-y; 187 } 188 189 fAltMin -= 90; 190 fAltMax -= 90; 191 192 // 193 // check whether altaz north- or south-pole is in the visible region 194 // 195 byte img[768*576]; 196 if (DrawAltAz(0, img, 90, 0)) 197 { 198 fAltMax=89; 199 cout << "Alt Az Pole1 Inside!" << endl; 200 } 201 if (DrawAltAz(0, img, -90, 0)) 202 { 203 fAltMin=-90; 204 cout << "Alt Az Pole2 Inside!" << endl; 205 } 206 207 //cout << "fAltMin: " << setw(3) << fAltMin << " "; 208 //cout << "fAltMax: " << setw(3) << fAltMax << endl; 209 } 210 211 void StarCatalog::CalcRaDecRange() 212 { 213 // 214 // calculate range to search in 215 // 216 byte fDec[180]; 217 218 for (int h=0; h<180; h++) 219 fDec[h] = kFALSE; 220 221 for (int h=0; h<360; h++) 222 fRa0[h] = kFALSE; 223 224 double ha0, ha1; 225 double de0, de1; 226 227 const double phi = GetPhi(); 228 const double alpha = GetAlpha(); 229 // 230 // scan horizontal border 231 // 232 for (int x=-768/2; x<768/2+1; x++) 233 { 234 double dx, dy; 235 slaDh2e(DPI-x*fPixSize, -fHeight, DPI/2-fAltAz.Alt(), &dx, &dy); 236 slaDh2e(fAltAz.Az()+dx, -dy, phi, &ha0, &de0); 237 238 slaDh2e(DPI-x*fPixSize, +fHeight, DPI/2-fAltAz.Alt(), &dx, &dy); 239 slaDh2e(fAltAz.Az()+dx, -dy, phi, &ha1, &de1); 240 241 const int h0 = ((int)(360.0/D2PI*(alpha-ha0))+360)%360; 242 const int d0 = (int)(360.0/D2PI*de0); 243 244 fRa0[h0] = kTRUE; 245 246 if (-90<=d0 && d0<=89) 247 fDec[d0+90] = kTRUE; 248 249 const int h1 = ((int)(360.0/D2PI*(alpha-ha1))+360)%360; 250 const int d1 = (int)(360.0/D2PI*de1); 251 252 fRa0[h1] = kTRUE; 253 254 if (-90<=d1 && d1<=89) 255 fDec[d1+90] = kTRUE; 256 } 257 258 // 259 // scan vertical border 260 // 261 for (int y=-576/2; y<576/2+1; y++) 262 { 263 double dx, dy; 264 slaDh2e(DPI-fWidth, -y*fPixSize, DPI/2-fAltAz.Alt(), &dx, &dy); 265 slaDh2e(fAltAz.Az()+dx, -dy, phi, &ha0, &de0); 266 267 slaDh2e(DPI+fWidth, -y*fPixSize, DPI/2-fAltAz.Alt(), &dx, &dy); 268 slaDh2e(fAltAz.Az()+dx, -dy, phi, &ha1, &de1); 269 270 const int h0 = ((int)(360.0/D2PI*(alpha-ha0))+360)%360; 271 const int d0 = (int)(360.0/D2PI*de0); 272 273 fRa0[h0] = kTRUE; 274 275 if (-90<=d0 && d0<=89) 276 fDec[d0+90] = kTRUE; 277 278 const int h1 = ((int)(360.0/D2PI*(alpha-ha1))+360)%360; 279 const int d1 = (int)(360.0/D2PI*de1); 280 281 fRa0[h1] = kTRUE; 282 283 if (-90<=d1 && d1<=89) 284 fDec[d1+90] = kTRUE; 285 } 286 287 // 288 // count degrees of right ascension 289 // 290 fRaCnt=0; 291 for (int x=0; x<360; x++) 292 if (fRa0[x]) 293 fRaCnt++; 294 //cout << "fRaCnt: " << setw(3) << fRaCnt << " " << flush; 295 296 // 297 // calculate min and max of declination 298 // 299 for (int y=0; y<180; y++) 300 { 301 if (fDec[y]) 302 fDecMax = y; 303 304 if (fDec[179-y]) 305 fDecMin = 179-y; 306 } 307 308 fDecMin -= 90; 309 fDecMax -= 90; 310 311 // 312 // check whether radec north- or south-pole is in the visible region 313 // 314 byte img[768*576]; 315 if (DrawRaDec(0, img, 0, 90)) 316 { 317 fDecMax=89; 318 cout << "Ra Dec Pole1 Inside!" << endl; 319 } 320 if (DrawRaDec(0, img, 0, -90)) 321 { 322 fDecMin=-90; 323 cout << "Ra Dec Pole1 Inside!" << endl; 324 } 325 326 //cout << "fDecMin: " << setw(3) << fDecMin << " "; 327 //cout << "fDecMax: " << setw(3) << fDecMax << endl; 328 } 329 330 void StarCatalog::DrawSCAltAz(byte *img, const int color) const 331 { 332 // 333 // ------------ draw az lines --------------- 334 // 335 for (int az=0; az<360; az++) 336 { 337 if (!fAz0[az]) 338 continue; 339 340 for (double alt=fAltMin-1; alt<fAltMax+1; alt+=0.006*(fAltMax-fAltMin)) 341 { 342 if ((alt>88 && az%5) || alt>89.5) 343 continue; 344 345 DrawAltAz(color, img, alt, az); 346 } 347 } 348 349 // 350 // ------------ draw alt lines --------------- 351 // 352 for (int alt=fAltMin; alt<fAltMax+1; alt++) 353 { 354 for (double az=0; az<360; az+=0.004*fAzCnt) 355 { 356 if (!fAz0[(int)az] && !fAz0[(int)(az+359)%360] && !fAz0[(int)(az+1)%360]) 357 continue; 358 359 DrawAltAz(color, img, alt, az); 360 } 361 } 362 } 363 364 void StarCatalog::DrawSCRaDec(byte *img, const int color) const 365 { 366 // 367 // ------------ draw ra lines --------------- 368 // 369 for (int ra=0; ra<360; ra++) 370 { 371 if (!fRa0[ra]) 372 continue; 373 374 for (double dec=fDecMin-1; dec<fDecMax+1; dec+=0.005*(fDecMax-fDecMin)) 375 { 376 if ((dec>88 && ra%5) || dec>89.5) 377 continue; 378 379 DrawRaDec(color, img, ra, dec, ra==0||ra==90); 380 } 381 } 382 383 // 384 // ------------ draw dec lines --------------- 385 // 386 for (int dec=fDecMin; dec<fDecMax+1; dec++) 387 { 388 for (double ra=0; ra<360; ra+=0.003*fRaCnt) 389 { 390 if (!fRa0[(int)ra]) 391 continue; 392 393 DrawRaDec(color, img, ra, dec, dec==89); 394 } 395 } 82 fAstro->SetRaDec(fRaDec.Ra(), fRaDec.Dec()); 83 if (!same) 84 Reload(); 396 85 } 397 86 … … 409 98 memset(cimg, 0, 768*576); 410 99 411 DrawSCAltAz(cimg, 2<<4);412 DrawSCRaDec(cimg, 2);413 414 100 DrawStars(list, cimg); 415 101 DrawCross(img, 768/2, 576/2); 416 }417 418 void StarCatalog::GetImg(byte *img, byte *cimg, const double utc,419 const RaDec &radec)420 {421 MStarList list;422 GetStars(list, utc, radec);423 GetImg(img, cimg, list);424 /*425 // memset(img, 0, 768*576);426 SetMjd(utc);427 //fAlpha = sla.GetAlpha();428 SetRaDec(radec);429 //CalcImg(cimg);430 */431 }432 433 void StarCatalog::GetImg(byte *img, byte *cimg, const double utc,434 const AltAz &altaz)435 {436 MStarList list;437 GetStars(list, utc, altaz);438 GetImg(img, cimg, list);439 /*440 // memset(img, 0, 768*576);441 442 SetMjd(utc);443 //fAlpha = sla.GetAlpha();444 SetAltAz(altaz);445 446 CalcRaDecRange();447 448 //CalcImg(img);449 */450 451 }452 453 void StarCatalog::GetStars(MStarList &list, const double utc, const RaDec &radec)454 {455 SetMjd(utc);456 SetRaDec(radec);457 458 CalcStars(list);459 }460 461 void StarCatalog::GetStars(MStarList &list, const double utc, const AltAz &altaz)462 {463 SetMjd(utc);464 SetAltAz(altaz);465 466 CalcRaDecRange();467 CalcStars(list);468 102 } 469 103 … … 489 123 } 490 124 491 Bool_t StarCatalog::DrawAltAz(const int color, byte *img, double alt, double az, int size) const 492 { 493 // 494 // alt/az[deg] -> alt/az[rad] 495 // 496 alt *= D2PI/360.0; 497 az *= D2PI/360.0; 498 499 // 500 // alt/az[rad] -> alt/az[pix] 501 // 502 double dx, dy; 503 slaDe2h(az-fAltAz.Az(), -alt, DPI/2-fAltAz.Alt(), &dx, &dy); 504 505 // 506 // Align alt/az[pix] 507 // 508 const int xx = (int)(((dx-DPI)*fCosAngle - dy*fSinAngle + fWidth)/fPixSize); 509 const int yy = (int)(((dx-DPI)*fSinAngle + dy*fCosAngle + fHeight)/fPixSize); 510 //const int xx = 767-(int)((fWidth-dx+DPI)/fPixSize); 511 //const int yy = (int)((fHeight+dy)/fPixSize); 512 513 // 514 // Range Check 515 // 516 if (!(0<=xx && xx<768 && 0<=yy && yy<576)) 517 return kFALSE; 518 519 // 520 // Draw 521 // 522 DrawCircle(color, img, xx, yy, size); 523 524 return kTRUE; 525 } 526 527 Bool_t StarCatalog::Draw(const int color, byte *img, const AltAz &altaz) 528 { 529 return DrawAltAz(color, img, altaz.Alt(), altaz.Az()); 530 } 531 532 /* 533 Bool_t StarCatalog::Draw(const int color, byte *img, const SaoFile *sao) 534 { 535 if (sao->MagV() > fLimitMag) 536 return kFALSE; 537 538 // 539 // ---- mean to observed --- 540 // 541 AltAz altaz=CalcAltAz(sao->GetRaDec()) * 360.0/D2PI; 542 543 const int mag = (10 - (sao->MagV()>1 ? (int)sao->MagV() : 1))/2; 544 545 // 546 // ---- imaging ----- 547 // 548 return DrawAltAz(color, img, altaz.Alt(), altaz.Az(), mag); 549 } 550 */ 551 552 Bool_t StarCatalog::DrawRaDec(const int color, byte *img, double ra, double dec, int size) const 553 { 554 // 555 // radec[deg] -> radec[rad] 556 // 557 ra *= D2PI/360.0; 558 dec *= D2PI/360.0; 559 560 // 561 // radec[rad] -> hadec[rad] 562 // 563 const double ha = GetAlpha()-ra; 564 565 // 566 // hadec[rad] -> altaz[rad] 567 // 568 double alt, az; 569 slaDe2h(ha, dec, GetPhi(), &az, &alt); 570 571 // 572 // altaz[rad] -> altaz[deg] 573 // 574 alt *= 360.0/D2PI; 575 az *= 360.0/D2PI; 576 577 return DrawAltAz(color, img, alt, az, size); 578 } 579 580 Bool_t StarCatalog::Draw(const int color, byte *img, const RaDec &radec) 581 { 582 return DrawRaDec(color, img, radec.Ra(), radec.Dec()); 583 } 584 /* 585 void StarCatalog::CalcImg(byte *img) 586 { 587 588 // 589 // --------- search for stars in catalog ---------- 590 // 591 int count = 0; 592 int deleted = 0; 593 594 int idx = 0; 595 596 while (fSrt[idx].dec<fDecMin) 597 idx++; 598 599 idx--; 600 while (++idx<fEntries && fSrt[idx].dec<fDecMax+1) 601 { 602 const int ra = fSrt[idx].ra; 603 604 if (!fRa0[ra]) 605 continue; 606 607 int nr = fSrt[idx].nr; 608 do 609 { 610 // 611 // Get entry from catalog 612 // 613 fSao->GetEntry(nr++); 614 615 // 616 // Try to draw star into the image 617 // white = 0xff 618 // 619 if (!Draw(0x0f, img, fSao)) 620 deleted++; 621 622 count++; 623 } 624 while ((int)(360.0/D2PI*fSao->Ra())==ra); 625 } 626 627 cout << " " << count << "-" << deleted << "=" << count-deleted << " " << flush; 628 } 629 */ 125 void StarCatalog::PaintImg(unsigned char *buf, int w, int h) 126 { 127 fAstro->PaintImg(buf, w, h); 128 } 129 630 130 void StarCatalog::DrawStars(MStarList &list, byte *img) 631 131 { … … 637 137 const int mag = (10 - (star->GetMag()>1 ? (int)star->GetMag() : 1))/2; 638 138 639 Double_t color = 0x0f; 640 139 Double_t color = 0xf0; //0x0f; 641 140 DrawCircle(color, img, (int)star->GetX(), (int)star->GetY(), mag); 642 141 } … … 645 144 void StarCatalog::CalcStars(MStarList &list) const 646 145 { 647 // 648 // --------- search for stars in catalog ---------- 649 // 650 if (fEntries==0) 651 return; 652 653 int count = 0; 654 int deleted = 0; 655 656 int idx = 0; 657 658 while (fSrt[idx].dec<fDecMin) 659 idx++; 660 661 idx--; 662 while (++idx<fEntries && fSrt[idx].dec<fDecMax+1) 146 // Align stars into telescope system 147 // (Move the telescope to pointing position) 148 TRotation align; 149 align.RotateZ(-fAltAz.Az()); 150 align.RotateY(-(TMath::Pi()/2-fAltAz.Alt())); 151 align.RotateZ(TMath::Pi()/2); 152 153 // For an apropriate unit conversion to pixels 154 const Double_t scale = TMath::RadToDeg()*sqrt(768*768 + 576*576)/(fAstro->GetRadiusFOV()*2); 155 156 // Get List of stars from catalog 157 TIter Next(fAstro->GetList()); 158 TVector3 *star=0; 159 160 const Double_t limmag = pow(10, -fLimitMag/2.5); 161 162 while ((star=(TVector3*)Next())) 663 163 { 664 const int ra = fSrt[idx].ra;665 666 if ( !fRa0[ra])164 // Check for limiting magnitude 165 const Double_t mag = star->Mag(); 166 if (mag < limmag) 667 167 continue; 668 168 669 int nr = fSrt[idx].nr; 670 do 671 { 672 // 673 // Get entry from catalog 674 // 675 fSao->GetEntry(nr++); 676 677 if (fSao->MagV() > fLimitMag) 678 continue; 679 680 // 681 // ---- mean to observed --- 682 // 683 AltAz altaz=CalcAltAz(fSao->GetRaDec()); 684 685 // 686 // alt/az[rad] -> alt/az[pix] 687 // 688 double dx, dy; 689 slaDe2h(altaz.Az()-fAltAz.Az(), -altaz.Alt(), 690 DPI/2-fAltAz.Alt(), &dx, &dy); 691 692 // 693 // Align and rotate alt/az[pix] 694 // 695 float xx = ((dx-DPI)*fCosAngle - dy*fSinAngle + fWidth)/fPixSize; 696 float yy = ((dx-DPI)*fSinAngle + dy*fCosAngle + fHeight)/fPixSize; 697 698 // 699 // Range Check, add stars to the list 700 // 701 if (!(0<=xx && xx<768 && 0<=yy && yy<576)) 702 { 703 deleted++; 704 continue; 705 } 706 707 list.Add(xx, yy, fSao->MagV()); 708 count++; 709 } 710 while ((int)(360.0/D2PI*fSao->Ra())==ra); 169 // Get star position and do an apropiate 170 // conversion to local coordinates 171 const RaDec rd(star->Phi(), TMath::Pi()/2-star->Theta()); 172 const ZdAz za(CalcZdAz(rd)); 173 174 // Virtually move telescope to pointing position 175 TVector3 loc; 176 loc.SetMagThetaPhi(1, za.Zd(), za.Az()); 177 loc *= align; 178 179 // Sanity check 180 if (loc(2)<0) 181 continue; 182 183 // Stretch such, that the Z-component is alwas the same. Now 184 // X and Y contains the intersection point between the star-light 185 // and the plain of a virtual plain screen (ccd...) 186 loc *= 1./loc(2); 187 188 // Do an apropriate unit conversion to pixels 189 loc *= scale; 190 191 // if (loc.Mod2()>fRadiusFOV*fRadiusFOV) 192 // continue; 193 194 // Rotate by the rotation angle of the video camera 195 Float_t xx = loc.X()*fCosAngle - loc.Y()*fSinAngle; 196 Float_t yy = loc.X()*fSinAngle + loc.Y()*fCosAngle; 197 198 // Store pixel coordinates of star in list 199 list.Add(xx+768/2, yy+576/2, -2.5*log10(mag)); 711 200 } 712 713 cout << "Showing " << count+deleted << "-" << deleted << "=" << count << " stars." << endl;714 201 } 715 202 716 203 AltAz StarCatalog::CalcAltAzFromPix(Double_t pixx, Double_t pixy) const 717 204 { 718 pixx *= fPixSize;719 pixy *= fPixSize;720 721 const double dx = (pixx-fWidth)*fCosAngle + (pixy-fHeight)*fSinAngle;722 const double dy = -(pixx-fWidth)*fSinAngle + (pixy-fHeight)*fCosAngle;205 double dx = (pixx-576/2)*fCosAngle + (pixy-768/2)*fSinAngle; 206 double dy = -(pixx-576/2)*fSinAngle + (pixy-768/2)*fCosAngle; 207 208 dx *= fPixSize; 209 dy *= fPixSize; 723 210 724 211 //const double dx = (pixx-768.0)*fPixSize + fWidth+DPI; -
trunk/MagicSoft/Cosy/catalog/StarCatalog.h
r1953 r4076 4 4 #ifndef ROOT_TROOT 5 5 #include <TROOT.h> 6 #endif 7 #ifndef ROOT_GuiTypes 8 #include <GuiTypes.h> 6 9 #endif 7 10 #ifndef SAOFILE_H … … 17 20 18 21 class MStarList; 22 class MAstroCatalog; 19 23 20 24 class StarCatalog : public SlaStars 21 25 { 22 26 private: 23 SaoFile *fSao; 24 sort_t *fSrt; 25 int fEntries; 27 MAstroCatalog *fAstro; 26 28 27 29 double fPixSize; // [rad/pix] size of one pixel 28 double fWidth; // size of display29 double fHeight; //30 30 double fSinAngle; 31 31 double fCosAngle; … … 34 34 35 35 AltAz fAltAz; // [rad] 36 byte fAz0[360];37 int fAltMin;38 int fAltMax;39 int fAzCnt;40 41 36 RaDec fRaDec; // [rad] 42 byte fRa0[360];43 int fRaCnt;44 int fDecMin;45 int fDecMax;46 37 47 38 static void DrawCross(byte *img, const int x, const int y); 48 39 static void DrawCircle(int color, byte *img, int xx, int yy, int size); 49 40 50 Bool_t DrawAltAz(const int color, byte *img, double alt, double az, int size=0) const;51 Bool_t DrawRaDec(const int color, byte *img, double ra, double dec, int size=0) const;52 53 Bool_t Draw(const int color, byte *img, const AltAz &altaz);54 Bool_t Draw(const int color, byte *img, const RaDec &radec);55 56 //Bool_t Draw(const int color, byte *img, const SaoFile *sao);57 //void CalcImg(byte *);58 59 void CalcStars(MStarList &list) const;60 61 static void DrawStars(MStarList &list, byte *img);62 63 41 void SetRaDec(const RaDec &radec); 64 42 void SetAltAz(const AltAz &altaz); 65 void DrawSCAltAz(byte *img, const int color) const;66 void DrawSCRaDec(byte *img, const int color) const;67 68 void CalcRaDecRange();69 void CalcAltAzRange();70 71 // RaDec AltAz2RaDec(const AltAz &altaz) const;72 // AltAz RaDec2AltAz(const RaDec &radec, const RaDec &rdpm) const;73 43 74 44 public: … … 77 47 78 48 void GetImg(byte *img, byte *cimg, MStarList &list) const; 79 void GetImg(byte *img, byte *cimg, const double utc, const RaDec &radec); 80 void GetImg(byte *img, byte *cimg, const double utc, const AltAz &altaz); 81 82 void GetStars(MStarList &list, const double utc, const RaDec &radec); 83 void GetStars(MStarList &list, const double utc, const AltAz &altaz); 49 void PaintImg(unsigned char *buf, int w, int h); 84 50 85 51 const AltAz GetAltAz() const { return fAltAz*kRad2Deg; } … … 88 54 89 55 void SetPixSize(const double pixsize); 90 void SetLimitMag(const float mag) { fLimitMag = mag; }56 void SetLimitMag(const float mag); 91 57 void SetRotationAngle(const float angle) { fSinAngle = sin(angle/kRad2Deg); fCosAngle = cos(angle/kRad2Deg); } 58 void Reload(); 92 59 93 60 double GetPixSize() const; … … 95 62 AltAz CalcAltAzFromPix(Double_t pixx, Double_t pixy) const; 96 63 64 virtual void SetMjd(double mjd); 65 66 void SetPointing(double mjd, const RaDec &radec) 67 { 68 SetMjd(mjd); SetRaDec(radec); 69 } 70 71 void CalcStars(MStarList &list) const; 72 static void DrawStars(MStarList &list, byte *img); 73 97 74 ClassDef(StarCatalog, 0) 98 75 }; -
trunk/MagicSoft/Cosy/cosy.cc
r2615 r4076 10 10 #include "MLogManip.h" 11 11 12 #include "Camera.h"13 #include "PngReader.h"14 12 #include "MStarguider.h" 15 13 16 //#define EXPERT17 //#define HAVE_CAMERA14 #define EXPERT 15 #define HAVE_CAMERA 18 16 19 17 #define clog(txt) \ … … 36 34 gLog << endl; 37 35 36 Int_t channel = 0; 37 for (int i=0; i<argc; i++) 38 { 39 TString arg(argv[i]); 40 if (arg=="-1") 41 channel = 1; 42 if (arg=="-0") 43 channel = 0; 44 } 45 38 46 // 39 47 // this must move to MGCosy !!!! 40 48 // 41 MTime time; 42 TString name; 43 while (1) 44 { 45 time.Now(); 46 name = Form("log/cosy_%s.log", (const char*)time.GetFileName()); 47 cout << "Test: " << time.GetFileName() << " " << name << endl; 48 if (gSystem->AccessPathName(name, kFileExists)) 49 break; 50 } 51 49 const TString name = MCosy::GetFileName("log/cosy_%s.log"); 52 50 cout << "Open Logfile: " << name << endl; 53 51 54 52 MLog *l = new MLog(name, kTRUE); 55 53 MLog &lout = *l; 54 lout.SetNoColors(); 56 55 57 clog("Starting Cosy at " << time << " ..."); 56 MTime now(-1); 57 clog("Starting Cosy at " << now << " ..."); 58 58 59 59 // … … 98 98 clog("- Starting Camera."); 99 99 #ifdef HAVE_CAMERA 100 MStarguider *client=new MStarguider(MObservatory::kMagic1); 101 Camera *cam = new Camera(*client); 102 cam->Loop(0); 100 MStarguider *client=new MStarguider(MObservatory::kMagic1, channel); 103 101 104 102 cosy->SetStarguider(client); … … 115 113 116 114 clog("- Stopping starg."); 117 cam->ExitLoop();118 delete cam;119 115 delete client; 120 116 #endif … … 122 118 cosy->Stop(); 123 119 124 time.Now();125 clog( time<< ": MCosy stopped.");120 now.Now(); 121 clog(now << ": MCosy stopped."); 126 122 127 123 delete cosy; 128 124 129 time.Now();130 clog("Terminating cosy at " << time);125 now.Now(); 126 clog("Terminating cosy at " << now); 131 127 132 128 delete l; -
trunk/MagicSoft/Cosy/devdrv/macs.h
r2615 r4076 118 118 void HandleError(); 119 119 120 Double_t GetPosTime() const { return fPosTime; } 121 120 122 ClassDef(Macs, 0) 121 123 }; -
trunk/MagicSoft/Cosy/devdrv/shaftencoder.cc
r2615 r4076 14 14 ShaftEncoder::ShaftEncoder(const BYTE_t nodeid, const char *name, MLog &out) 15 15 : NodeDrv(nodeid, name, out), fPos(0), fVel(0), fAcc(0), 16 fTurn(0), fLabel(NULL), fPosHasChanged(false) 16 fTurn(0), fLabel(NULL), fPosHasChanged(false), fReport(NULL) 17 17 { 18 18 } … … 183 183 fTime.Set(*tv); 184 184 fPosHasChanged = true; 185 186 if (fReport) 187 { 188 fReport->Lock(); 189 *fReport << "SE-REPORT " << (int)GetId() << " " << fTime << " PDO0 " << pos << " " << GetNodeName() << endl; 190 fReport->UnLock(); 191 } 185 192 } 186 193 … … 201 208 202 209 flag=flag; 210 211 if (fReport) 212 { 213 fReport->Lock(); 214 *fReport << "SE-REPORT " << (int)GetId() << " " << fTime << " PDO1 " << pos << " " << (int)flag << " " << GetNodeName() << endl; 215 fReport->UnLock(); 216 } 203 217 } 204 218 … … 235 249 fTime.Set(*tv); 236 250 fPosHasChanged=true; 251 252 if (fReport) 253 { 254 fReport->Lock(); 255 *fReport << "SE-REPORT " << (int)GetId() << " " << fTime << " PDO2 " << pos << " " << fVel << " " << fAcc << " " << GetNodeName() << endl; 256 fReport->UnLock(); 257 } 237 258 } 238 259 -
trunk/MagicSoft/Cosy/devdrv/shaftencoder.h
r2615 r4076 25 25 26 26 MTime fTime; 27 MLog *fReport; 27 28 28 29 void HandlePDOType0(BYTE_t *data, timeval_t *tv); … … 63 64 void ResetPosHasChanged() { fPosHasChanged = false; } 64 65 66 void SetReport(MLog *log) { fReport = log; } 67 65 68 ClassDef(ShaftEncoder, 0) 66 69 }; -
trunk/MagicSoft/Cosy/gui/MGAccuracy.cc
r2518 r4076 15 15 #include <TList.h> 16 16 #include <TGaxis.h> 17 #include <TGraph.h> 17 18 #include <TCanvas.h> 18 19 19 20 #include "coord.h" 21 #include "MTime.h" 20 22 21 23 ClassImp(MGAccuracy); … … 28 30 TText text; 29 31 text.SetTextAlign(22); // centered, centered (s.TAttText) 30 text.DrawText(-80*2, 132.5*2, " Tracking Error [']");32 text.DrawText(-80*2, 132.5*2, "Ctrl Deviation [min]"); 31 33 32 34 … … 75 77 axe->SetBit(kCanDelete); 76 78 axe->Draw(); 77 78 //79 // FIXME? Use TAxis?80 //81 /*82 TLine line;83 line.SetLineColor(13);84 line.SetLineStyle(3); // dotted (s. TAttLine)85 line.DrawLine(-30, -65, -30, 65);86 line.DrawLine(-65, -30, 65, -30);87 line.DrawLine( 30, -65, 30, 65);88 line.DrawLine(-65, 30, 65, 30);89 90 line.DrawLine(-15, -65, -15, 65);91 line.DrawLine(-65, -15, 65, -15);92 line.DrawLine( 15, -65, 15, 65);93 line.DrawLine(-65, 15, 65, 15);94 95 line.DrawLine(-45, -65, -45, 65);96 line.DrawLine(-65, -45, 65, -45);97 line.DrawLine( 45, -65, 45, 65);98 line.DrawLine(-65, 45, 65, 45);99 100 line.SetLineColor(12);101 line.SetLineStyle(2); // dashed (s. TAttLine)102 line.DrawLine(-60, -65, -60, 65);103 line.DrawLine(-65, -60, 65, -60);104 line.DrawLine( 60, -65, 60, 65);105 line.DrawLine(-65, 60, 65, 60);106 107 line.SetLineColor(1); // black108 line.SetLineStyle(1); // solid (s. TAttLine)109 line.DrawLine(-65, 0, 65, 0);110 line.DrawLine( 0, -65, 0, 65);111 112 line.DrawLine(-1, 60, 1, 60);113 line.DrawLine(-1, -60, 1, -60);114 line.DrawLine(-1, 30, 1, 30);115 line.DrawLine(-1, -30, 1, -30);116 117 line.DrawLine( 60, -1, 60, 1);118 line.DrawLine(-60, -1, -60, 1);119 line.DrawLine( 30, -1, 30, 1);120 line.DrawLine(-30, -1, -30, 1);121 122 TText text;123 text.SetTextAlign(22); // centered, centered (s.TAttText)124 text.DrawText(60, 5, "dAz[\xb0]");125 text.DrawText(0, 70, "dZd[\xb0]");126 127 text.SetTextAlign(23); // centered, centered (s.TAttText)128 text.DrawText(-60, -2, "-1'");129 text.DrawText( 60, -2, "1'");130 text.DrawText(-30, -2, "-30\"");131 text.DrawText( 30, -2, "30\"");132 133 text.SetTextAlign(32); // centered, centered (s.TAttText)134 text.DrawText(-2, -60, "-1'");135 text.DrawText(-2, 60, "1'");136 text.DrawText(-2, -30, "-30\"");137 text.DrawText(-2, 30, "30\"");138 */139 79 } 140 80 … … 183 123 : MGEmbeddedCanvas("Accuracy", p, w, 300) 184 124 { 125 // FIXME: Overload MapWindow in newer Root versions to remove 126 // the contents of the graph! 127 fGraph = new TGraph; 128 fGraph->SetPoint(0, 0, 0); 129 fGraph->SetLineColor(kBlue); 130 fGraph->SetMarkerColor(kBlue); 131 fGraph->SetMarkerStyle(kFullDotMedium); 132 fGraph->Draw("LP"); 133 fList->Add(fGraph); 134 //fGraph->SetNameTitle("AccVsT", "Accuracy vs Min of Time"); 135 //fGraph->Draw("APL"); 136 //fGraph->SetMarkerSize(2); 137 185 138 DrawCoordinateSystem(); 186 139 … … 192 145 193 146 SetNoContextMenu(); 147 148 MTime t(-1); 149 fTime = t.GetAxisTime(); 194 150 } 195 151 … … 199 155 } 200 156 201 void MGAccuracy::UpdateText(Float_t pzd, Float_t azd, Float_t aaz) 202 { 203 const Float_t d2r = TMath::Pi()/180.; 204 205 pzd *= d2r; 206 azd *= d2r; 207 aaz *= d2r; 208 209 const double el = TMath::Pi()/2-pzd; 210 211 const double dphi2 = aaz/2.; 212 const double cos2 = cos(dphi2)*cos(dphi2); 213 const double sin2 = sin(dphi2)*sin(dphi2); 214 const double d = cos(azd)*cos2 - cos(2*el)*sin2; 215 216 // 217 // Original: 218 // cos(Zd1)*cos(Zd2)+sin(Zd1)*sin(Zd2)*cos(dAz) 219 // 220 // Correct: 221 // const double d = cos(azd)*cos2 - cos(el1+el2)*sin2; 222 // 223 // Estimated: 224 // const double d = cos(azd)*cos2 - cos(2*el)*sin2; 225 // 226 227 double dist = acos(d); 228 229 dist *= 3600./d2r; // [min] 157 // dist [deg] 158 void MGAccuracy::UpdateText(Float_t dist) 159 { 160 dist *= 3600.; // [sec] 230 161 231 162 int rs = (int)floor(fmod(dist, 60.)); 232 163 233 dist /= 60.; 234 int rm = (int)dist; //floor(fmod(dist, 60.));164 dist /= 60.; // [min] 165 int rm = (int)dist; 235 166 236 167 char txt[100]; … … 239 170 fTxt->SetText(fTxt->GetX(), fTxt->GetY(), txt); 240 171 241 fBar->Set X2(dist*60);172 fBar->SetY2(dist*60); // [sec] 242 173 if (dist*16384<1*360*60) 243 174 fBar->SetLineColor(kGreen); … … 247 178 else 248 179 fBar->SetLineColor(kRed); 180 181 SetModified(); 182 } 183 184 // dist [deg] 185 void MGAccuracy::UpdateGraph(Float_t dist) 186 { 187 MTime t(-1); 188 const Double_t dtime = t.GetAxisTime()-fTime; // range [-0.5h, 0h] 189 190 dist *= 60; // min 191 192 static int odist = -1; 193 if (odist==(int)(dist*10*60) && dtime<10) 194 return; 195 196 odist = (int)(dist*10*60); 197 198 fGraph->SetPoint(fGraph->GetN(), dtime, dist*60); 199 200 const Double_t ntime = dtime; 201 for (int i=0; i<fGraph->GetN(); i++) 202 { 203 Double_t x, y; 204 fGraph->GetPoint(i, x, y); 205 fGraph->SetPoint(i, x-ntime, y); 206 //cout << i << ": " << x-ntime << " / " << y << endl; 207 } 208 while (fGraph->GetN()>0) 209 { 210 Double_t x, y; 211 fGraph->GetPoint(0, x, y); 212 213 if (x==-ntime && y==0) 214 { 215 fGraph->RemovePoint(0); 216 continue; 217 } 218 219 if (x>-4.75*60) 220 break; 221 222 fGraph->RemovePoint(0); 223 } 224 225 fTime = t.GetAxisTime(); 226 227 SetModified(); 228 229 //cout << "N1 == " << fGraph->GetN() << endl; 230 231 //fGraph->GetHistogram()->SetXTitle("Time"); 232 //fGraph->GetHistogram()->SetYTitle("\\Delta [arcmin]"); 233 //fGraph->GetHistogram()->GetXaxis()->SetTimeFormat("%M %F1995-01-01 00:00:00"); 234 //fGraph->GetHistogram()->GetXaxis()->SetTimeDisplay(1); 235 //fGraph->GetHistogram()->GetXaxis()->SetLabelSize(0.033); 236 } 237 238 void MGAccuracy::Update(Float_t pzd, Float_t azd, Float_t aaz) 239 { 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(); 265 266 UpdateText(dist); 267 UpdateGraph(dist); 249 268 } 250 269 251 270 void MGAccuracy::UpdateCross(Float_t x, Float_t y) 252 271 { 272 // 273 // calculate actual time for planet positions 274 // acc [deg] 275 // 276 // x["], y["] 277 // 278 static int X = ~0; 279 static int Y = ~0; 280 281 int pixx = (int)(x/fPix); // [pix] 282 int pixy = (int)(y/fPix); // [pix] 283 284 if (X==pixx && Y==pixy) 285 return; 286 287 X = pixx; 288 Y = pixy; 289 253 290 fLin1->SetX1(x-5.); 254 291 fLin1->SetX2(x+5.); … … 262 299 fLin2->SetY1(y+5.); 263 300 fLin2->SetY2(y-5.); 301 302 SetModified(); 264 303 } 265 304 266 305 void MGAccuracy::Update(ZdAz &pos, ZdAz &acc) 267 306 { 268 // 269 // calculate actual time for planet positions 270 // acc [deg] 271 // 272 static int X = ~0; 273 static int Y = ~0; 274 275 float x = acc.Az()*3600.; // ["] 276 float y = acc.Zd()*3600.; // ["] 277 278 int pixx = (int)(x/fPix); // [pix] 279 int pixy = (int)(y/fPix); // [pix] 280 281 if (X==pixx && Y==pixy) 282 return; 283 284 X = pixx; 285 Y = pixy; 286 287 UpdateCross(x, y); 288 UpdateText(pos.Zd(), acc.Zd(), acc.Az()); 289 290 SetModified(); 307 UpdateCross(acc.Az()*3600., acc.Zd()*3600.); 308 Update(pos.Zd(), acc.Zd(), acc.Az()); 309 291 310 UpdateCanvas(); 292 311 } -
trunk/MagicSoft/Cosy/gui/MGAccuracy.h
r2518 r4076 8 8 // Version: V1.0 (1-8-2000) 9 9 10 #ifndef MGEMBEDDEDCANVAS_H10 #ifndef COSY_MGEmbeddedCanvas 11 11 #include "MGEmbeddedCanvas.h" 12 12 #endif 13 13 14 class TGraph; 14 15 class TLine; 15 16 class TText; … … 26 27 TLine *fBar; 27 28 29 TGraph *fGraph; 30 31 Double_t fTime; 32 28 33 void DrawCoordinateSystem(); 29 34 … … 32 37 void InitBar(); 33 38 34 void UpdateText(Float_t zd, Float_t x, Float_t y);35 39 void UpdateCross(Float_t x, Float_t y); 40 void UpdateText(Float_t acc); 41 void UpdateGraph(Float_t acc); 42 void Update(Float_t zd, Float_t x, Float_t y); 36 43 37 44 public: -
trunk/MagicSoft/Cosy/gui/MGEmbeddedCanvas.h
r2278 r4076 1 #ifndef MGEMBEDDEDCANVAS_H2 #define MGEMBEDDEDCANVAS_H1 #ifndef COSY_MGEmbeddedCanvas 2 #define COSY_MGEmbeddedCanvas 3 3 4 4 // -
trunk/MagicSoft/Cosy/gui/MGImage.cc
r2613 r4076 7 7 // x11/src/GX11Gui.cxx 8 8 // 9 10 ////////////////////////////////////////////////////////////////////////////// 11 // 12 // MGImage 13 // 14 // If sync-mode is enabled the Redraw function is secured by a mutex (ignore 15 // error messages about it comming from root) This has the advantage that 16 // if you use a timer for screen update reading and writing the image is 17 // synchronized. In this way you don't get flickering half images. 18 // 19 ////////////////////////////////////////////////////////////////////////////// 9 20 #include "MGImage.h" 10 21 … … 17 28 18 29 using namespace std; 19 /*20 class MyX11 : public TGX1121 {22 public:23 Display *GetDisplay() { return fDisplay; }24 Drawable GetRootWin() { return fRootWin; }25 Drawable GetVisRootWin() { return fVisRootWin; }26 Int_t GetDepth() { return fDepth; }27 };28 */29 30 30 31 MGImage::MGImage(const TGWindow* p, UInt_t w, UInt_t h, UInt_t options, ULong_t back) … … 40 41 fMuxPixmap = new TMutex; 41 42 42 Resize( w, h);43 Resize(GetWidth(), GetHeight()); 43 44 44 45 // 45 46 // create empty pixmap 46 47 // 47 fPixmap = gVirtualX->CreatePixmap(fId, fWidth, fHeight);48 48 fDefGC = gVirtualX->CreateGC(fId, 0); 49 49 fImage = (XImage*)gVirtualX->CreateImage(fWidth, fHeight); … … 54 54 MGImage::~MGImage() 55 55 { 56 fMuxPixmap->Lock(); 56 if (fMuxPixmap->Lock()==13) 57 cout << "MGImage::~MGImage - mutex is already locked by this thread" << endl; 57 58 58 59 cout << "Deleting MGImage..." << endl; 59 60 60 gVirtualX->DeletePixmap(fPixmap);61 61 gVirtualX->DeleteGC(fDefGC); 62 62 gVirtualX->DeleteImage((Drawable_t)fImage); … … 69 69 void MGImage::DoRedraw() 70 70 { 71 fMuxPixmap->Lock(); 72 73 if (TestBit(kNeedRedraw)) 74 { 75 gVirtualX->PutImage(fId, fDefGC, (Drawable_t)fImage, 0, 0, 0, 0, fWidth, fHeight); 71 if (TestBit(kSyncMode)) 72 while (fMuxPixmap->Lock()==13) 73 usleep(1); 74 75 // gVirtualX->DrawLine(fId, fDefGC, 0, 0, fWidth+2, 0); 76 // gVirtualX->DrawLine(fId, fDefGC, 0, 0, 0, fHeight+2); 77 // gVirtualX->DrawLine(fId, fDefGC, fWidth+2, 0, fWidth+2, fHeight+2); 78 // gVirtualX->DrawLine(fId, fDefGC, 0, fHeight+2, fWidth+2, fHeight+2); 79 80 // if (TestBit(kNeedRedraw)) 81 { 82 gVirtualX->PutImage(fId, fDefGC, (Drawable_t)fImage, 0, 0, 0, 0, 83 fWidth, fHeight); 76 84 ResetBit(kNeedRedraw); 77 85 } 78 86 79 fMuxPixmap->UnLock(); 87 if (TestBit(kSyncMode)) 88 if (fMuxPixmap->UnLock()==13) 89 cout << "MGImage::DoRedraw - tried to unlock mutex locked by other thread." << endl; 80 90 } 81 91 … … 109 119 void MGImage::DrawImg(const byte *buffer) 110 120 { 111 if (fMuxPixmap->TryLock()) 112 return; 121 if (TestBit(kSyncMode)) 122 while (fMuxPixmap->Lock()==13) 123 usleep(1); 124 else 125 { 126 const Int_t rc = fMuxPixmap->Lock(); 127 if (rc==13) 128 cout << "MGImage::DrawImg - mutex is already locked by this thread" << endl; 129 if (rc) 130 return; 131 } 113 132 114 133 switch (gVirtualX->GetDepth()) … … 129 148 SetBit(kNeedRedraw); 130 149 131 fMuxPixmap->UnLock(); 150 if (fMuxPixmap->UnLock()==13) 151 cout << "MGImage::DrawImage - tried to unlock mutex locked by other thread." << endl; 132 152 } 133 153 … … 143 163 { 144 164 // 00000011 00001100 00110000 145 *d++ = (*s2&0x3) | (*s2&0xb)<<3 | (*s2&0x30)<<7;146 s1++;165 //*d++ = (*s2&0x3) | (*s2&0xb)<<3 | (*s2&0x30)<<7; 166 *d++ = (*s2&0x3)<<3 | (*s2&0xb)<<6 | (*s2&0x30)<<10; 147 167 } 148 168 else … … 150 170 // 11111100 11111000 11111100 151 171 *d++ = (*s1&0xfc) | (*s1&0xf8)<<5 | (*s1&0xfc)<<11; 152 s2++; 153 } 172 } 173 s1++; 174 s2++; 154 175 } 155 176 } … … 181 202 void MGImage::DrawColImg(const byte *gbuf, const byte *cbuf) 182 203 { 183 if (fMuxPixmap->TryLock()) 184 return; 204 if (TestBit(kSyncMode)) 205 while (fMuxPixmap->Lock()==13) 206 usleep(1); 207 else 208 { 209 const Int_t rc = fMuxPixmap->Lock(); 210 if (rc==13) 211 cout << "MGImage::DrawColImg - mutex is already locked by this thread" << endl; 212 if (rc) 213 return; 214 } 185 215 186 216 // FROM libAfterImage: … … 190 220 //#define ALPHA_SOLID 0xFF 191 221 // * Lowermost 8 bits - Blue channel 192 // * bits 8 to 15- Green channel222 // * bits 8 to 15 - Green channel 193 223 // * bits 16 to 23 - Red channel 194 224 // * bits 24 to 31 - Alpha channel … … 211 241 SetBit(kNeedRedraw); 212 242 213 fMuxPixmap->UnLock(); 214 } 243 if (fMuxPixmap->UnLock()==13) 244 cout << "MGImage::DrawColImage - tried to unlock mutex locked by other thread." << endl; 245 } -
trunk/MagicSoft/Cosy/gui/MGImage.h
r2518 r4076 24 24 25 25 GContext_t fDefGC; 26 Pixmap_t fPixmap;26 //Pixmap_t fPixmap; 27 27 28 28 UInt_t fWidth; … … 31 31 TMutex *fMuxPixmap; //! test 32 32 33 enum { kNeedRedraw = BIT(17) }; 33 enum 34 { 35 kNeedRedraw = BIT(17), 36 kSyncMode = BIT(18) 37 }; 34 38 35 39 void DrawImg16(unsigned short *d, char *s, char *e); … … 47 51 void DrawColImg(const byte *gbuf, const byte *cbuf); 48 52 53 void EnableSyncMode() { SetBit(kSyncMode); } 54 void DisableSyncMode() { ResetBit(kSyncMode); } 55 49 56 ClassDef(MGImage, 0) 50 57 }; -
trunk/MagicSoft/Cosy/gui/MGPngReader.cc
r2615 r4076 347 347 const Double_t pixsize = 23.4; 348 348 349 fSao->SetPixSize(pixsize /3600);349 fSao->SetPixSize(pixsize); 350 350 351 351 TString txt; … … 586 586 const Float_t pixsize = atof(fPixSize->GetText()); 587 587 cout << "Pixel Size changed to " << pixsize << "\"/pix" << endl; 588 fSao->SetPixSize(pixsize /3600);588 fSao->SetPixSize(pixsize); 589 589 } 590 590 return kTRUE; -
trunk/MagicSoft/Cosy/gui/MGSkyPosition.h
r2278 r4076 9 9 10 10 11 #ifndef MGEMBEDDEDCANVAS_H11 #ifndef COSY_MGEmbeddedCanvas 12 12 #include "MGEmbeddedCanvas.h" 13 13 #endif -
trunk/MagicSoft/Cosy/gui/MGTPoint.cc
r2615 r4076 151 151 const Double_t pixsize = 23.4; 152 152 153 fSao->SetPixSize(pixsize /3600);153 fSao->SetPixSize(pixsize); 154 154 155 155 TString txt; … … 225 225 const Float_t pixsize = atof(fPixSize->GetText()); 226 226 cout << "Pixel Size changed to " << pixsize << "\"/pix" << endl; 227 fSao->SetPixSize(pixsize /3600);227 fSao->SetPixSize(pixsize); 228 228 } 229 229 return kTRUE; -
trunk/MagicSoft/Cosy/gui/MGVelocity.cc
r2278 r4076 181 181 // calculate actual time for planet positions 182 182 // 183 float vx = zdaz.Az() *3600.; // ["/min]184 float vy = zdaz.Zd() *3600.; // ["/min]183 float vx = zdaz.Az(); // [U_mot/min] 184 float vy = zdaz.Zd(); // [U_mot/min] 185 185 186 186 int pixx = (int)(vx*fScale/fPix); -
trunk/MagicSoft/Cosy/gui/MGVelocity.h
r2278 r4076 8 8 // Version: V1.0 (1-8-2000) 9 9 10 #ifndef MGEMBEDDEDCANVAS_H10 #ifndef COSY_MGEmbeddedCanvas 11 11 #include "MGEmbeddedCanvas.h" 12 12 #endif -
trunk/MagicSoft/Cosy/leds.txt
r2278 r4076 1 321 535 -1.2 -1.02 573 460 -2.0 0.9 3 633 204 0.0 -1.6 4 446 25 0.0 0.05 193 95 2.0 1.06 118 347 0.0 9.1 1 260 83 0 0 2 147 321 0 0 3 296 540 0 0 4 525 61 0 0 5 676 280 0 0 6 561 519 0 0 -
trunk/MagicSoft/Cosy/main/MCaos.cc
r2615 r4076 307 307 } 308 308 309 voidMCaos::Run(byte *img, bool printl, bool printr, const ZdAz &pos, const MTime &t)309 Ring MCaos::Run(byte *img, bool printl, bool printr, const ZdAz &pos, const MTime &t) 310 310 { 311 311 Leds &leds = *fLeds; … … 344 344 345 345 Rings rings; 346 rings.CalcRings(leds, 266, 2 72);346 rings.CalcRings(leds, 266, 268); 347 347 348 348 const Ring ¢er = rings.GetCenter(); 349 350 f.DrawCircle(center, 0x80);351 f.DrawCircle(center, 5.0, 0x80);352 f.DrawCircle(center, 115.0, 0x80);353 f.DrawCircle(center, 190.0, 0x80);354 // f.MarkPoint(center.GetX(), center.GetY(), 0xa0);355 349 356 350 // FIXME! … … 380 374 } 381 375 376 return center; 382 377 /* 383 378 if (fCaosAnalyse->IsEntryEnabled(IDM_kStopAnalyse)) -
trunk/MagicSoft/Cosy/main/MCaos.h
r2615 r4076 4 4 #ifndef CAOS_Leds 5 5 #include "Leds.h" 6 #endif 7 #ifndef CAOS_Ring 8 #include "Ring.h" 6 9 #endif 7 10 … … 68 71 void ResetHistograms(); 69 72 70 voidRun(byte *img, bool printl, bool printr, const ZdAz &pos, const MTime &t);73 Ring Run(byte *img, bool printl, bool printr, const ZdAz &pos, const MTime &t); 71 74 }; 72 75 -
trunk/MagicSoft/Cosy/main/MCosy.cc
r3897 r4076 1 #include "MCosy.h"2 1 #include "MCosy.h" 3 2 … … 22 21 #include "MStarguider.h" 23 22 #include "SlaStars.h" 23 #include "MPointing.h" 24 #include "MTracking.h" 24 25 25 26 #include "slalib/slalib.h" // FIXME: REMOVE … … 31 32 32 33 typedef struct tm tm_t; 33 34 /*35 #define GEAR_RATIO_ALT 2475.6 // [U_mot/U_tel(360deg)]36 #define GEAR_RATIO_AZ 5891.7 // [U_mot/U_tel(360deg)]37 38 #define RES_RE 500 // [re/U_mot]39 #define RES_SE 16384 // [se/U_tel(360deg)]40 */41 /*42 #define GEAR_RATIO_ALT (75.55*16384/1500) // 75.25 VERY IMPORTANT! unit=U_mot/U_tel43 #define GEAR_RATIO_AZ (179.8*16384/1500) // VERY IMPORTANT! unit=U_mot/U_tel44 */45 46 //const XY kGearRatio (GEAR_RATIO_ALT*RES_RE/RES_SE, GEAR_RATIO_AZ*RES_RE/RES_SE); //[re/se]47 //const XY kGearRatio2(GEAR_RATIO_ALT*RES_RE/360.0, GEAR_RATIO_AZ*RES_RE/360.0); //[re/deg]48 34 49 35 /* +===================================+ … … 54 40 //#define EXPERT 55 41 #undef EXPERT 56 57 double MCosy::Rad2SE(double rad) const58 {59 return 16384.0/k2Pi*rad;60 }61 62 double MCosy::Rad2ZdRE(double rad) const63 {64 return 16384.0/k2Pi*rad*kGearRatio.X();65 }66 67 double MCosy::Rad2AzRE(double rad) const68 {69 return 16384.0/k2Pi*rad*kGearRatio.Y();70 }71 72 double MCosy::Deg2ZdRE(double rad) const73 {74 return rad*kGearRatio2.X();75 }76 77 double MCosy::Deg2AzRE(double rad) const78 {79 return rad*kGearRatio2.Y();80 }81 42 82 43 /* … … 191 152 // -------------------------------------------------------------------------- 192 153 // 193 // request the current positions from the rotary encoders.194 // use GetRePos to get the psotions. If the request fails the function195 // returns kFALSE, otherwise kTRUE196 //197 Bool_t MCosy::RequestRePos()198 {199 //200 // Send request201 //202 fMac2->RequestSDO(0x6004);203 fMac1->RequestSDO(0x6004);204 205 //206 // Wait until the objects are received.207 //208 fMac2->WaitForSdo(0x6004);209 fMac1->WaitForSdo(0x6004);210 211 //212 // If waiting was not interrupted everything is ok. return.213 //214 if (!(Break() || HasError() || HasZombie()))215 return kTRUE;216 217 //218 // If the waiting was interrupted due to a network error,219 // print some logging message.220 //221 if (HasError())222 lout << "Error while requesting re pos from Macs (SDO #6004)" << endl;223 224 return kFALSE;225 }226 227 // --------------------------------------------------------------------------228 //229 154 // reads the Rotary encoder positions from the last request of the Macs. 230 155 // … … 253 178 // -------------------------------------------------------------------------- 254 179 // 255 // set the velocity and accelerations for position maneuvers.256 //257 // The acceleratin is set as given (in percent of maximum).258 // The velocity is given in percent, depending on the ratio (<1 or >1)259 // one of the axis becomes a slower velocity. This is used for maneuvers260 // in which both axis are moved synchromously and should reach their261 // target position at the same time.262 //263 void MCosy::SetPosVelocity(const Float_t ratio, Float_t vel)264 {265 //266 // Set velocities267 //268 const int vr = fMac1->GetVelRes();269 270 vel *= vr;271 272 if (ratio <1)273 {274 fMac1->SetVelocity(vel);275 fMac2->SetVelocity(vel*ratio);276 }277 else278 {279 fMac1->SetVelocity(vel/ratio);280 fMac2->SetVelocity(vel);281 }282 }283 284 // --------------------------------------------------------------------------285 //286 // Does a relative positioning.287 //288 // The steps to move are given in a ZdAz object relative to the current289 // position. The coordinates are given in Roteryencoder steps.290 // Axis 1 is moved only if axe1==kTRUE, Axis 2 is moved only291 // if Axis 2==kTRUE. The function waits for the movement to be finished.292 //293 void MCosy::DoRelPos(const ZdAz &rd, const Bool_t axe1, const Bool_t axe2)294 {295 if (HasZombie())296 return;297 298 SetStatus(MDriveCom::kMoving);299 300 if (axe1) fMac2->StartRelPos(rd.Zd());301 if (axe2) fMac1->StartRelPos(rd.Az());302 #ifdef EXPERT303 cout << "Waiting for positioning..." << flush;304 #endif305 if (axe1) fMac2->WaitForSdo(0x6004, 1);306 if (axe2) fMac1->WaitForSdo(0x6004, 1);307 308 WaitForEndMovement();309 #ifdef EXPERT310 cout << "done." << endl;311 #endif312 }313 314 // --------------------------------------------------------------------------315 //316 180 // check for a break-signal (from the msgqueue) and errors. 317 181 // … … 341 205 return; 342 206 343 MTime t; 344 t.Now(); 207 MTime t(-1); 345 208 lout << t << " - MCosy::WaitForEndMovement aborted..."; 346 209 if (Break()) … … 434 297 } 435 298 436 // --------------------------------------------------------------------------437 //438 // Move the telescope to the given position. The position must be given in439 // a ZdAz object in rad.440 //441 // The first positioning is done absolutely. If we didn't reach the442 // correct psotion we try to correct for this by 10 relative position443 // maneuvers. If this doesn't help positioning failed.444 //445 // As a reference the shaftencoder values are used.446 //447 int MCosy::SetPosition(const ZdAz &dst, Bool_t track) // [rad]448 {449 const ZdAz d = dst*kRad2Deg;450 451 MTime t;452 t.Now();453 lout << t << " - Target Position: " << d.Zd() << "deg, " << d.Az() << "deg (Zd/Az)" << endl;454 455 //456 // Calculate new target position (shortest distance to go)457 //458 const ZdAz src = GetSePos(); // [se]459 460 //461 // Make sure that the motors are in sync mode (necessary if the462 // MACS has been rebooted from a Zombie state.463 //464 //InitSync();465 //if (fMac3->IsZombieNode())466 // return false;467 468 //469 // Because we agreed on I don't search for the shortest move470 // anymore471 //472 // const ZdAz dest = CorrectTarget(src, dst);473 //474 ZdAz bend = fBending(dst); // [rad]475 476 const ZdAz dest = bend*16384/2/TMath::Pi(); // [se]477 478 if (!CheckRange(bend))479 return kFALSE;480 481 bend *= kRad2Deg;482 fZdAzSoll = dst;483 484 cout << "Source Zd: " << src.Zd() << "se Az:" << src.Az() << "se" << endl;485 cout << "Destination Zd: " << Rad2SE(dst.Zd()) << "se Az:" << Rad2SE(dst.Az()) << "se" << endl;486 cout << "Bend'd Dest Zd: " << dest.Zd() << "se Az:" << dest.Az() << "se" << endl;487 cout << "Bend'd Dest Zd: " << bend.Zd() << "deg Az:" << bend.Az() << "deg" << endl;488 489 //490 // Set velocities491 //492 const int vr = fMac1->GetVelRes();493 494 int i;495 for (i=0; i<(track?1:10) && !(Break() || HasError() || HasZombie()); i++)496 {497 498 lout << "- Step #" << i << endl;499 //500 // Get Shaft Encoder Positions501 //502 const ZdAz p=GetSePos();503 504 //505 // calculate control deviation and rounded cd506 //507 ZdAz rd = dest-p; // [se]508 509 // ===========================================510 const ZdAz ist = dst-rd*TMath::Pi()/8192;511 512 const double p1 = ist.Zd()-19.0605/kRad2Deg;513 const double p2 = dst.Zd()-19.0605/kRad2Deg;514 515 const double f1 = (-26.0101*sin(p1)+443.761*ist.Zd())*8192/TMath::Pi();516 const double f2 = (-26.0101*sin(p2)+443.761*dst.Zd())*8192/TMath::Pi();517 // ===========================================518 519 ZdAz cd = rd; // [se]520 cd.Round();521 522 //523 // Check if there is a control deviation on the axis524 //525 const Bool_t cdzd = (int)cd.Zd() ? kTRUE : kFALSE;526 const Bool_t cdaz = (int)cd.Az() ? kTRUE : kFALSE;527 528 //529 // check if we reached the correct position already530 //531 if (!cdzd && !cdaz)532 {533 t.Now();534 lout << t << " - Positioning done in " << i << (i==1?" step.":" steps.") << endl;535 SetStatus(MDriveCom::kStopped);536 return TRUE;537 }538 539 //540 // change units from se to re541 //542 rd *= kGearRatio; // [re]543 rd.Zd(f2-f1);544 545 //546 // Initialize Velocities so that we reach both positions547 // at the same time548 //549 if (i)550 {551 fMac1->SetAcceleration(0.1*vr);552 fMac2->SetAcceleration(0.1*vr);553 554 fMac1->SetDeceleration(0.1*vr);555 fMac2->SetDeceleration(0.1*vr);556 557 SetPosVelocity(1.0, 0.05);558 }559 else560 {561 if (rd.Az()>-15*kGearRatio.Y() && rd.Az()<15*kGearRatio.Y())562 {563 #ifdef EXPERT564 cout << " -------------- LO ---------------- " << endl;565 #endif566 fMac1->SetAcceleration(0.05*vr);567 fMac1->SetDeceleration(0.05*vr);568 }569 else570 {571 #ifdef EXPERT572 cout << " -------------- HI ---------------- " << endl;573 fMac1->SetAcceleration(0.4*vr);// 0.4574 fMac1->SetDeceleration(0.4*vr);// 0.4575 #else576 fMac1->SetAcceleration(0.2*vr);577 fMac1->SetDeceleration(0.1*vr);578 #endif579 }580 581 #ifdef EXPERT582 fMac2->SetAcceleration(0.4*vr);// 0.4583 fMac2->SetDeceleration(0.4*vr);// 0.4584 SetPosVelocity(fabs(rd.Ratio()), 0.2); // fast: 0.6, slow: 0.2585 #else586 fMac2->SetAcceleration(0.2*vr);587 fMac2->SetDeceleration(0.1*vr);588 SetPosVelocity(fabs(rd.Ratio()), 0.1);589 #endif590 }591 592 rd.Round();593 594 // FIXME? Check for Error or Zombie?595 596 /*597 cout << " + " << (int)cdzd << " " << (int)cdaz << endl;598 cout << " + APOS: Zd=" << setw(6) << p.Zd() << "se Az=" << setw(6) << p.Az() << "se" << endl;599 cout << " + dZd=" << setw(6) << cd.Zd() << "se dAz=" << setw(6) << cd.Az() << "se" << endl;600 cout << " + dZd=" << setw(6) << rd.Zd() << "re dAz=" << setw(6) << rd.Az() << "re" << endl;601 cout << " + Ratio: Zd=" << setw(6) << kGearRatio.X() << "se Az=" << setw(6) << kGearRatio.Y() << "se" << endl;602 */603 604 //605 // repositioning (relative)606 //607 608 lout << "- Do Relative Positioning..." << endl;609 DoRelPos(rd, cdzd, cdaz);610 lout << "- Relative Positioning Done" << endl;611 }612 if (i==1 && track && !(Break() || HasError() || HasZombie()))613 {614 t.Now();615 lout << t << " - Positioning done." << endl;616 SetStatus(MDriveCom::kStopped);617 return TRUE;618 }619 620 if (i<10)621 StopMovement();622 else623 SetStatus(MDriveCom::kStopped);624 625 t.Now();626 lout << t << " - Warning: Requested position not reached (i=" << dec << i << ")" << endl;627 return FALSE;628 }629 630 // --------------------------------------------------------------------------631 //632 // Sets the tracking velocity633 //634 // The velocities are given in a ZdAz object in re/min. Return kTRUE635 // in case of success, kFALSE in case of failure.636 //637 Bool_t MCosy::SetVelocity(const ZdAz &v)638 {639 //640 // Send the new velocities for both axes.641 //642 fMac2->SendSDO(0x3006, 1, (LWORD_t)v.Zd()); // SetRpmVelocity [re/min]643 fMac1->SendSDO(0x3006, 1, (LWORD_t)v.Az()); // SetRpmVelocity [re/min]644 645 //646 // Wait for the objects to be acknoledged.647 //648 fMac2->WaitForSdo(0x3006, 1);649 fMac1->WaitForSdo(0x3006, 1);650 651 //652 // If the waiting for the objects wasn't interrupted return kTRUE653 //654 if (!(Break() || HasError() || HasZombie()))655 return kTRUE;656 657 //658 // print a message if the interruption was due to a Can-node Error659 //660 if (HasError())661 lout << "Error while setting velocity (SDO #3006)" << endl;662 663 return kFALSE;664 }665 666 // --------------------------------------------------------------------------667 //668 // Initializes Tracking mode669 //670 // Initializes the accelerations of both axes with 90% of the maximum671 // acceleration. Set the status for moving and tracking and starts thr672 // revolution mode.673 //674 bool MCosy::InitTracking()675 {676 // FIXME? Handling of Zombie OK?677 if (fMac1->IsZombieNode() || fMac2->IsZombieNode())678 return false;679 680 //681 // Start revolution mode682 //683 fMac2->SetAcceleration(0.1*fMac2->GetVelRes());684 fMac2->SetDeceleration(0.1*fMac2->GetVelRes());685 if (fMac2->IsZombieNode())686 return false;687 688 fMac1->SetAcceleration(0.1*fMac1->GetVelRes());689 fMac1->SetDeceleration(0.1*fMac1->GetVelRes());690 if (fMac1->IsZombieNode())691 return false;692 693 SetStatus(MDriveCom::kMoving | MDriveCom::kTracking);694 695 fMac2->SetRpmMode(TRUE);696 if (fMac2->IsZombieNode())697 return false;698 699 fMac1->SetRpmMode(TRUE);700 if (fMac1->IsZombieNode())701 return false;702 703 return true;704 }705 706 // --------------------------------------------------------------------------707 //708 // Limits the speed.709 //710 // This function should work as a limiter. If a tracking error is too large711 // to be corrected fast enough we would get enormous velocities. These712 // velocities are limited to the maximum velocity.713 //714 Bool_t MCosy::LimitSpeed(ZdAz *vt, const ZdAz &vcalc) const715 {716 Bool_t rc = kFALSE;717 718 //719 // How to limit the speed. If the wind comes and blowes720 // we cannot forbid changing of the sign. But on the other hand721 // we don't want fast changes!722 //723 ULong_t vrzd = fMac1->GetVelRes();724 ULong_t vraz = fMac2->GetVelRes();725 726 #define sgn(x) (x<0?-1:1)727 728 //729 // When speed changes sign, the maximum allowed speed730 // is 25% of the |v|731 //732 //const Float_t limit = 0.25;733 734 //735 // The maximum allowed speed while tracking is 10%736 //737 const Float_t maxtrack = 0.1;738 /*739 if (sgn(vt->Az()) != sgn(vcalc.Az()))740 vt->Az(0);741 // else742 {743 if (fabs(vt->Az()) < fabs(vcalc.Az()) *0.5)744 vt->Az(0.5*vcalc.Az());745 746 if (fabs(vt->Az()) > fabs(vcalc.Az()) *1.5)747 vt->Az(1.5*vcalc.Az());748 }749 750 if (sgn(vt->Zd()) != sgn(vcalc.Zd()))751 vt->Zd(0);752 // else753 {754 if (fabs(vt->Zd()) > fabs(vcalc.Az()) *1.5)755 vt->Zd(1.5*vcalc.Zd());756 757 if (fabs(vt->Zd()) < fabs(vcalc.Az()) *0.5)758 vt->Zd(0.5*vcalc.Zd());759 }760 */761 /*762 if (sgn(vt->Az()) != sgn(vcalc.Az())763 && fabs(vt->Az()) < limit*fabs(vcalc.Az())764 )765 {766 lout << "Warning: Negative Azimuth speed limit (" << limit*100 << "%) exceeded... set to 0." << endl;767 vt->Az(0);768 }769 else*/770 if (fabs(vt->Az()) > maxtrack*vraz)771 {772 lout << "Warning: Azimuth speed limit (" << maxtrack*100 << "%) exceeded (" << fabs(vt->Az()) << " > " << maxtrack*vraz << ")... limited." << endl;773 vt->Az(maxtrack*vraz*sgn(vcalc.Az()));774 rc=kTRUE;775 }776 /*777 if (sgn(vt->Zd()) != sgn(vcalc.Zd())778 && fabs(vt->Zd()) < limit*fabs(vcalc.Zd())779 )780 {781 lout << "Warning: Negative Altitude speed limit (" << limit*100 << "%) exceeded... set to 0." << endl;782 vt->Zd(0);783 }784 else785 */ if (fabs(vt->Zd()) > maxtrack*vrzd)786 {787 lout << "Warning: Altitude speed limit (" << maxtrack*100 << "%) exceeded (" << fabs(vt->Zd()) <<" > " << maxtrack*vrzd << ")... limited." << endl;788 vt->Zd(maxtrack*vrzd*sgn(vcalc.Zd()));789 rc=kTRUE;790 }791 return rc;792 }793 /*794 Bool_t MCosy::AlignTrackingPos(ZdAz pointing, ZdAz &za) const795 {796 // pointing [deg]797 if (pointing.Zd()<0)798 {799 pointing.Zd(-pointing.Zd());800 pointing.Az(pointing.Az()+180);801 }802 803 const ZdAz se = GetSePos()*2*TMath::Pi()/16384; // [rad]804 const ZdAz unbendedse = fBending.CorrectBack(se)*kRad2Deg; // ist pointing805 806 do807 {808 const Double_t d = unbendedse.Az() - pointing.Az();809 if (d>-180 && d<=180)810 break;811 812 pointing.Az(pointing.Az()+TMath::Sign(360., d));813 } while (1);814 815 const Bool_t rc = CheckRange(pointing);816 za = pointing/kRad2Deg; // [rad]817 818 if (!rc)819 lout << "Error: Aligned position out of Range." << endl;820 821 return rc;822 }823 */824 825 299 ZdAz MCosy::AlignTrackingPos(ZdAz pointing) const 826 300 { … … 837 311 } 838 312 839 const ZdAz se = GetSePos()* 2*TMath::Pi()/16384; // [rad]313 const ZdAz se = GetSePos()*TMath::TwoPi()/kResSE; // [rad] 840 314 const ZdAz unbendedse = fBending.CorrectBack(se)*kRad2Deg; // ist pointing 841 315 … … 897 371 898 372 dest -= point; 899 dest *= 16384/TMath::Pi()/2; // [se] 900 dest *= -kGearRatio; // [re] 373 dest *= -kGearTot/TMath::TwoPi(); // [re] 901 374 902 375 cout << "Using Starguider... dZd=" << dest.Zd() << " dAz=" << dest.Az() << endl; … … 905 378 } 906 379 380 // -------------------------------------------------------------------------- 381 // 382 // Move the telescope to the given position. The position must be given in 383 // a ZdAz object in rad. 384 // 385 // The first positioning is done absolutely. If we didn't reach the 386 // correct psotion we try to correct for this by 10 relative position 387 // maneuvers. If this doesn't help positioning failed. 388 // 389 // As a reference the shaftencoder values are used. 390 // 391 int MCosy::SetPosition(const ZdAz &dst, Bool_t track) // [rad] 392 { 393 MPointing point(this, lout); 394 395 //#ifdef EXPERT 396 // point.SetAccDec(0.4, 0.4); 397 // point.SetVelocity(0.2); // fast: 0.6, slow: 0.2 398 //#else 399 point.SetPointAccDec(0.2, 0.1); 400 point.SetPointVelocity(0.1); 401 //#endif 402 403 return point.SetPosition(dst, track); 404 } 405 907 406 void MCosy::TrackPosition(const RaDec &dst) // ra, dec [rad] 908 407 { 909 SlaStars sla(fObservatory); 910 911 // 912 // Position to actual position 913 // 914 sla.Now(); 915 ZdAz dest = sla.CalcZdAz(dst); 916 917 lout << sla.GetTime() << ": Track Position " << dst.Ra()*kRad2Deg/15 << "h, " << dst.Dec()*kRad2Deg <<"deg" << endl; 918 919 // FIXME: Determin tracking start point by star culmination 920 if (dest.Az()<-TMath::Pi()/2) 921 { 922 lout << "Adding 360deg to Azimuth " << dest.Az()*kRad2Deg << endl; 923 dest.Az(dest.Az() + TMath::Pi()*2); 924 } 925 926 if (dest.Az()>3*TMath::Pi()/2) 927 { 928 lout << "Substracting 360deg to Azimuth " << dest.Az()*kRad2Deg << endl; 929 dest.Az(dest.Az() -TMath::Pi()*2); 930 } 931 932 if (!SetPosition(dest, kTRUE)) 933 //if (!SetPosition(dest, kFALSE)) 934 { 935 lout << "Error: Cannot start tracking, positioning failed." << endl; 936 return; 937 } 938 939 // 940 // calculate offset from present se position 941 // 942 const ZdAz sepos = GetSePos()*kGearRatio; 943 944 if (!RequestRePos()) 945 return; 946 947 // 948 // Estimate Offset before starting to track 949 // 950 fOffset = sepos-GetRePos(); 951 952 /* 953 cout << "Sepos: " << sepos.Zd() << "re, " << sepos.Az() << "re" << endl; 954 cout << "Repos: " << repos.Zd() << "re, " << repos.Az() << "re" << endl; 955 cout << "Offset: " << fOffset.Zd() << "re, " << fOffset.Az() << "re" << endl; 956 */ 957 958 // 959 // Init accelerations and Rpm Mode 960 // 961 if (!InitTracking()) 962 { 963 StopMovement(); 964 return; 965 } 966 967 XY xy(Rad2Deg(dst.Ra())*24/360, Rad2Deg(dst.Dec())); 968 969 sla.Now(); 970 // lout << sla.GetTime() << " - Start tracking:"; 971 // lout << " Ra: " << xy.X() << "h " << "Dec: " << xy.Y() << "\xb0" << endl; 972 973 /*#ifdef EXPERT 974 ofstream fout("coordinates.txt"); 975 fout << xy; 976 fout.close(); 977 #endif 978 */ // 979 // Initialize Tracker (slalib or starguider) 980 // 981 fRaDec = dst; 982 fBackground = kBgdTracking; 983 984 ZdAz pos = sla.CalcZdAz(fRaDec); 985 986 lout << sla.GetTime() << " - Start Tracking: Ra=" <<xy.X() << "h Dec="; 987 lout << xy.Y() << "\xb0 @ Zd=" << pos.Zd()*kRad2Deg <<"deg Az=" << pos.Az()*kRad2Deg <<"deg" << endl; 988 989 //--- ofstream fout("log/cosy.pos"); 990 //--- fout << "Tracking:"; 991 //--- fout << " Ra: " << Rad2Deg(dst.Ra()) << "\x9c "; 992 //--- fout << "Dec: " << Rad2Deg(dst.Dec()) << "\x9c" << endl << endl; 993 //--- fout << " Mjd/10ms V/re/min/4" << endl; 994 995 // 996 // We want to reach the theoretical position exactly in about 0.5s 997 // 998 // *OLD*const float dt = 1; // 1 second 999 const float dt = 5;//3; // 2 second 1000 while (!(Break() || HasError() || HasZombie())) 1001 { 1002 // 1003 // Request Target position for this moment 1004 // 1005 sla.Now(dt); 1006 1007 // 1008 // Request theoretical Position for a time in the future (To+dt) from CPU 1009 // 1010 const ZdAz pointing = sla.CalcZdAz(fRaDec); // soll pointing [rad] 1011 1012 //lout << sla.GetTime() << pointing.Zd()*kRad2Deg << " " << pointing.Az()*kRad2Deg << endl; 1013 /* 1014 ZdAz dest; 1015 if (!AlignTrackingPos(pointing, dest)) 1016 break; 1017 */ 1018 ZdAz dest = AlignTrackingPos(pointing); 1019 1020 // lout << "DEST: " << dest.Zd()*kRad2Deg << " " <<dest.Az()*kRad2Deg << endl; 1021 1022 ZdAz vcalc = sla.GetApproxVel(fRaDec) * kGearRatio2*4./60.; 1023 //lout << "Vcalc: " << dest.Zd() << " " << dest.Az() << endl; 1024 vcalc *= kGearRatio2*4./60.; // [re/min] 1025 1026 float dtime = -1; 1027 if (kFALSE /*fUseStarguider*/) 1028 dtime = Starguider(sla.GetMjd(), dest); 1029 1030 if (dtime<0) 1031 { 1032 dest = fBending(dest); // [rad] 1033 1034 //lout << "DEST-BEND: " << dest.Zd()*kRad2Deg << " " <<dest.Az()*kRad2Deg << endl; 1035 1036 if (!CheckRange(dest)) 1037 break; 1038 1039 dest *= 16384/TMath::Pi()/2; // [se] 1040 dest *= kGearRatio; // [re] 1041 1042 // 1043 // Request absolute position of rotary encoder from Macs 1044 // 1045 if (!RequestRePos()) 1046 break; 1047 1048 // 1049 // distance between (To+dt) and To [re] 1050 // position time difference < 5usec 1051 // fOffset does the synchronization between the 1052 // Shaft- and the rotary encoders 1053 dest -= GetRePos() + fOffset; 1054 1055 dtime = dt; 1056 1057 ZdAz repos = GetRePos(); 1058 // lout << "Repos: " << repos.Zd()/kGearRatio.X() << " " << repos.Az()*kGearRatio.Y() << endl; 1059 // repos /= kGearRatio; 1060 repos /= 16384/TMath::Pi()/2; 1061 repos *= kRad2Deg; 1062 } 1063 1064 // 1065 // Velocity to go [re/min] to reach the right position at time t+dt 1066 // correct for the duration of RaDec2AltAz 1067 // 1068 const ZdAz v = dest*60.0/(dtime/*-(fMac2->GetTime()-sla)*/); 1069 1070 // 1071 // calculate real velocity of future [re/min] 1072 // believing the Macs manual '/4' shouldn't be necessary, but it is. 1073 // 1074 ZdAz vt = v/4; 1075 if (LimitSpeed(&vt, vcalc)) 1076 { 1077 lout << "Vcalc: " << vcalc.Zd() << " " << vcalc.Az() << "re/min" <<endl; 1078 lout << "vt: " << vt.Zd() << " " << vt.Az() << "re/min" << endl; 1079 lout << "Dest: " << dest.Zd() << " " << dest.Az() << endl; 1080 } 1081 vt.Round(); 1082 1083 // 1084 // check if the drive is fast enough to follow the star 1085 // 1086 if (vt.Zd()>.9*fMac1->GetVelRes() || vt.Az()>.9*fMac2->GetVelRes()) 1087 { 1088 lout << "Error: Tracking speed faster than 90% of possible maximum velocity." << endl; 1089 break; 1090 } 1091 1092 // 1093 // Set theoretical velocity (as early after calculation as possible) 1094 // Maybe we should attenuate the changes 1095 // 1096 if (!SetVelocity(vt)) 1097 break; 1098 1099 // 1100 // Now do 'unnecessary' things 1101 // 1102 fVelocity = vt/kGearRatio2*4; 1103 1104 //--- const double mjd = fMac2->GetMjd(); 1105 //--- fout << setprecision(15) << setw(17) << mjd*60.*60.*24. << " "; 1106 //--- fout << setw(4) << vt.Zd() << " "; 1107 //--- fout << setw(4) << vt.Az() << endl; 1108 // 1109 // FIXME? Calculate an accuracy for the tracking system? 1110 // How good do we reach the calculated position in 'real' 1111 // re valus? 1112 // 1113 1114 1115 // 1116 // Update speed as often as possible. 1117 // make sure, that dt is around 10 times larger than the 1118 // update time 1119 // 1120 // 1121 // The loop should not be executed faster than the ramp of 1122 // a change in the velocity can be followed. 1123 // (This is important on fast machines >500MHz) 1124 // 1125 /* 1126 MTimeout t(1000); 1127 while (!t.HasTimedOut()) 1128 usleep(1); 1129 */ 1130 usleep(1000000); // 1s 1131 cout << "." << flush; 1132 //usleep(50000); // 0.05s 1133 } 1134 1135 sla.Now(); 1136 1137 fBackground = kBgdNone; 1138 StopMovement(); 1139 1140 lout << sla.GetTime() << " - Tracking stopped." << endl; 408 MTracking track(this, lout); 409 track.SetOut(fOutRep); 410 //#ifdef EXPERT 411 // track.SetPointAccDec(0.4, 0.4); 412 // track.SetPointVelocity(0.2); // fast: 0.6, slow: 0.2 413 //#else 414 track.SetPointAccDec(0.2, 0.1); 415 track.SetPointVelocity(0.1); 416 //#endif 417 track.SetTrackAccDec(0.1, 0.1); 418 419 track.TrackPosition(dst); 1141 420 } 1142 421 … … 1201 480 } 1202 481 1203 void MCosy::StopTracking()1204 {1205 //1206 // Set status to Stopping1207 //1208 SetStatus(MDriveCom::kStopping);1209 1210 //1211 // set deceleration to 50%1212 //1213 cout << "Stopping tracking (dec=20%)..." << endl;1214 fMac1->SetDeceleration(0.2*fMac1->GetVelRes());1215 fMac2->SetDeceleration(0.2*fMac2->GetVelRes());1216 1217 fMac2->SendSDO(0x3006, 1, (LWORD_t)0); // SetRpmVelocity [re/min]1218 fMac1->SendSDO(0x3006, 1, (LWORD_t)0); // SetRpmVelocity [re/min]1219 fMac2->WaitForSdo(0x3006, 1);1220 fMac1->WaitForSdo(0x3006, 1);1221 1222 cout << "Waiting for end of movement..." << endl;1223 WaitForEndMovement();1224 1225 //1226 // Wait for the objects to be OKed.1227 //1228 fMac1->SetRpmMode(FALSE);1229 fMac2->SetRpmMode(FALSE);1230 1231 //1232 // Wait for the movement to really be finished.1233 //1234 //cout << "Waiting for end of movement..." << endl;1235 //WaitForEndMovement();1236 1237 //1238 // Check whether everything works fine.1239 //1240 CheckForError();1241 cout << "Movement stopped." << endl;1242 }1243 1244 482 bool MCosy::CheckNetwork() 1245 483 { … … 1281 519 1282 520 case WM_STOP: 1283 cout << "MCosy::Proc: Stop." << endl;521 //cout << "MCosy::Proc: Stop." << endl; 1284 522 if (!CheckNetwork()) 1285 523 return (void*)0xebb0; … … 1331 569 case WM_TPOINT: 1332 570 { 1333 cout << "WM_TPoint: start." << endl;571 //cout << "WM_TPoint: start." << endl; 1334 572 SlaStars sla(fObservatory); 1335 573 sla.Now(); … … 1340 578 AltAz za=sla.CalcAltAz(rd*kDeg2Rad)*kRad2Deg; 1341 579 580 if (!fOutTp) 581 { 582 // 583 // open tpoint file 584 // 585 const TString name = GetFileName("tpoint/tpoint_%s.txt"); 586 cout << "TPoint-Cosy File ********* " << name << " ********** " << endl; 587 588 fOutTp = new ofstream(name); 589 *fOutTp << "Magic Model TPOINT data file" << endl; 590 *fOutTp << ": ALTAZ" << endl; 591 *fOutTp << "49 48 0 "; 592 *fOutTp << sla.GetTime().Year() << " " << sla.GetTime().Month() << " " << sla.GetTime().Day() << " "; 593 *fOutTp << /*"20 1013.25 300 0.5 0.55 0.0065" <<*/ endl; 594 // temp(°C) pressure(mB) height(m) humidity(1) wavelength(microm) troplapserate(K/m) 595 } 596 1342 597 cout << " Alt/Az: " << za.Alt() << "° " << za.Az() << "°" << endl; 1343 * tpout<< setprecision(7) << za.Az() << " " << za.Alt() << " ";1344 1345 ZdAz sepos = GetSePos()*TMath:: Pi()*2/16384;;598 *fOutTp << setprecision(7) << za.Az() << " " << za.Alt() << " "; 599 600 ZdAz sepos = GetSePos()*TMath::TwoPi()/kResSE; 1346 601 za.Set(TMath::Pi()/2-sepos.Zd(), sepos.Az()); 1347 602 za *= kRad2Deg; 1348 603 1349 604 cout << " SE-Pos: " << za.Alt() << "° " << za.Az() << "°" << endl; 1350 * tpout<< fmod(za.Az()+360, 360) << " " << za.Alt() << " ";605 *fOutTp << fmod(za.Az()+360, 360) << " " << za.Alt() << " "; 1351 606 1352 607 if (fStarguider) 1353 608 { 1354 609 XY tp = fStarguider->GetCoordinates(); 1355 * tpout<< 90-tp.X() << " " << tp.Y() << " ";610 *fOutTp << 90-tp.X() << " " << tp.Y() << " "; 1356 611 } 1357 612 1358 * tpout<< rd.Ra()/15 << " " << rd.Dec() << " " << setprecision(11) << sla.GetMjd() << endl;1359 1360 cout << "WM_TPoint: done. (return 0xaffe)" << endl;613 *fOutTp << rd.Ra()/15 << " " << rd.Dec() << " " << setprecision(11) << sla.GetMjd() << endl; 614 615 //cout << "WM_TPoint: done. (return 0xaffe)" << endl; 1361 616 } 1362 617 return (void*)0xca1b; 1363 618 1364 619 case WM_TRACKPOS: 1365 cout << "WM_TrackPosition: start." << endl;620 //cout << "WM_TrackPosition: start." << endl; 1366 621 { 1367 622 if (!CheckNetwork()) … … 1376 631 1377 632 RaDec rd = sla.CalcRaDec(dest); 1378 cout << dest.Zd()*180/3.1415 << " " << dest.Az()*180/3.1415 << endl;1379 cout << rd.Ra()*12/3.1415 << " " << rd.Dec()*180/3.1415 << endl;1380 633 TrackPosition(rd); 1381 634 } 1382 cout << "WM_TrackPosition: done. (return 0xabcd)" << endl;635 //cout << "WM_TrackPosition: done. (return 0xabcd)" << endl; 1383 636 return (void*)0xabcd; 1384 637 1385 638 case WM_POSITION: 1386 cout << "WM_Position: start." << endl;639 //cout << "WM_Position: start." << endl; 1387 640 { 1388 641 if (!CheckNetwork()) … … 1392 645 SetPosition(dest*kDeg2Rad); 1393 646 } 1394 cout << "WM_Position: done. (return 0x7777)" << endl;647 //cout << "WM_Position: done. (return 0x7777)" << endl; 1395 648 return (void*)0x7777; 1396 649 1397 650 case WM_POSITION1: 1398 cout << "WM_Position1: start." << endl;651 //cout << "WM_Position1: start." << endl; 1399 652 { 1400 653 if (!CheckNetwork()) … … 1404 657 SetPosition(dest*kDeg2Rad, kTRUE); 1405 658 } 1406 cout << "WM_Position: done. (return 0x7777)" << endl;659 //cout << "WM_Position: done. (return 0x7777)" << endl; 1407 660 return (void*)0x7777; 1408 661 1409 662 case WM_TESTSE: 1410 cout << "WM_TestSe: start." << endl;663 //cout << "WM_TestSe: start." << endl; 1411 664 fBackground = mp ? kBgdSeTest : kBgdNone; 1412 cout << "WM_TestSe: done. (return 0x1e51)" << endl;665 //cout << "WM_TestSe: done. (return 0x1e51)" << endl; 1413 666 return (void*)0x1e51; 1414 667 1415 668 case WM_GEAR: 1416 cout << "WM_Gear: start." << endl;669 //cout << "WM_Gear: start." << endl; 1417 670 fBackground = mp ? kBgdGear : kBgdNone; 1418 cout << "WM_Gear: done. (return 0xfeaf)" << endl;671 //cout << "WM_Gear: done. (return 0xfeaf)" << endl; 1419 672 return (void*)0xfeaf; 1420 673 1421 674 case WM_DISPLAY: 1422 cout << "WM_Display: start." << endl;675 //cout << "WM_Display: start." << endl; 1423 676 fTriggerDisplay = kTRUE; 1424 cout << "WM_Disply: done. (return 0xd1e1)" << endl;677 //cout << "WM_Disply: done. (return 0xd1e1)" << endl; 1425 678 return (void*)0xd1e1; 1426 679 1427 680 case WM_TRACK: 1428 cout << "WM_Track: START" << endl;681 //cout << "WM_Track: START" << endl; 1429 682 { 1430 683 RaDec dest = ((RaDec*)mp)[0]; … … 1435 688 TrackPosition(dest*kDeg2Rad); 1436 689 } 1437 cout << "WM_Track: done. (return 0x8888)" << endl;690 //cout << "WM_Track: done. (return 0x8888)" << endl; 1438 691 return (void*)0x8888; 1439 692 1440 693 case WM_NEWTRACK: 1441 cout << "WM_NewTrack: START" << endl;694 //cout << "WM_NewTrack: START" << endl; 1442 695 fRaDec = *((RaDec*)mp); 1443 cout << "WM_NewTrack: done. (return 0x9999)" << endl;696 //cout << "WM_NewTrack: done. (return 0x9999)" << endl; 1444 697 return (void*)0x9999; 1445 698 1446 699 case WM_LOADBENDING: 1447 cout << "WM_LoadBending: START" << endl;700 //cout << "WM_LoadBending: START" << endl; 1448 701 fBending.Load("bending.txt"); 1449 cout << "WM_LoadBending: done. (return 0xbe0d)" << endl;702 //cout << "WM_LoadBending: done. (return 0xbe0d)" << endl; 1450 703 return (void*)0xbe0d; 1451 704 1452 705 case WM_RESETBENDING: 1453 cout << "WM_ResetBending: START" << endl;706 //cout << "WM_ResetBending: START" << endl; 1454 707 fBending.Reset(); 1455 cout << "WM_ResetBending: done. (return 0xbe0e)" << endl;708 //cout << "WM_ResetBending: done. (return 0xbe0e)" << endl; 1456 709 return (void*)0xbe0e; 1457 710 1458 711 case WM_HOME: 1459 cout << "WM_Home: START" << endl;712 //cout << "WM_Home: START" << endl; 1460 713 if (!CheckNetwork()) 1461 714 return (void*)0xebb0; … … 1485 738 */ 1486 739 } 1487 cout << "WM_Home: done. (return 0x403e)" << endl;740 //cout << "WM_Home: done. (return 0x403e)" << endl; 1488 741 return (void*)0x403e; 1489 742 … … 1510 763 a1 *= kRad2Deg; 1511 764 1512 const ZdAz a2 = a1* 16384/360;765 const ZdAz a2 = a1*kResSE/360; 1513 766 1514 767 cout << "Zd/Az bended: " << a1.Zd() << "° " << a1.Az() << "°" << endl; … … 1519 772 case WM_ENDSWITCH: 1520 773 { 1521 ZdAz pos = GetSePos()*TMath:: Pi()*2/16384;774 ZdAz pos = GetSePos()*TMath::TwoPi()/kResSE; 1522 775 pos = fBending.SubtractOffsets(pos)*kRad2Deg; 1523 776 … … 1575 828 1576 829 cout << "Reading gear ratios..." << flush; 1577 const Double_t gaz = env.GetValue("Az_GearRatio[U_mot/U_tel]", 1000.0);1578 const Double_t gzd = env.GetValue("Zd_GearRatio[U_mot/U_tel]", 1000.0);1579 1580 Double_t resreaz = 0;830 kGear.Y(env.GetValue("Az_GearRatio[U_mot/U_tel]", 1000.0)); 831 kGear.X(env.GetValue("Zd_GearRatio[U_mot/U_tel]", 1000.0)); 832 833 kResRE.Y(0); 1581 834 if (fMac1 && !fMac1->IsZombieNode()) 1582 resreaz = fMac1->GetRes();835 kResRE.Y(fMac1->GetRes()); 1583 836 else 1584 837 if (fMac3 && !fMac3->IsZombieNode()) 1585 resreaz = fMac3->GetRes();838 kResRE.Y(fMac3->GetRes()); 1586 839 else 1587 resreaz = env.GetValue("Az_ResRE[re/U_mot]", 1500);1588 1589 Double_t resrezd = 0;840 kResRE.Y(env.GetValue("Az_ResRE[re/U_mot]", 1500)); 841 842 kResRE.X(0); 1590 843 if (fMac2 && !fMac2->IsZombieNode()) 1591 resrezd = fMac2->GetRes();844 kResRE.X(fMac2->GetRes()); 1592 845 else 1593 resrezd = env.GetValue("Zd_ResRE[re/U_mot]", 1500);1594 1595 Double_t ressezd = 0;846 kResRE.X(env.GetValue("Zd_ResRE[re/U_mot]", 1500)); 847 848 kResSE.X(0); 1596 849 if (fZd1 && !fZd1->IsZombieNode()) 1597 ressezd = fZd1->GetPhysRes();850 kResSE.X(fZd1->GetPhysRes()); 1598 851 else 1599 852 if (fZd2 && !fZd2->IsZombieNode()) 1600 ressezd = fZd2->GetPhysRes();853 kResSE.X(fZd2->GetPhysRes()); 1601 854 else 1602 ressezd = env.GetValue("Zd_ResSE[se/U_mot]", 16384);1603 1604 Double_t resseaz = 0;855 kResSE.X(env.GetValue("Zd_ResSE[se/U_mot]", 16384)); 856 857 kResSE.Y(0); 1605 858 if (fAz && !fAz->IsZombieNode()) 1606 resseaz = fAz->GetPhysRes();859 kResSE.Y(fAz->GetPhysRes()); 1607 860 else 1608 resseaz = env.GetValue("Az_ResSE[se/U_mot]", 16384); 1609 1610 kGearRatio.Set (gzd*resrezd*4/ressezd, gaz*resreaz*4/resseaz); //[re/se] 1611 kGearRatio2.Set(gzd*resrezd*4/360.0, gaz*resreaz*4/360.0); //[re/deg] 861 kResSE.Y(env.GetValue("Az_ResSE[se/U_mot]", 16384)); 862 863 // believing the Macs manual '*4' shouldn't be necessary, but it is. 864 // Because the a RE is 4 quad counts. 865 // Calculating speeds we have to convert back to qc 866 kResRE *= 4; 867 kGearTot = kResRE*kGear; 868 1612 869 cout << "done." << endl; 1613 870 1614 871 cout << " * Setting Gear Ratios:" << endl; 1615 872 cout << " --------------------" << endl; 1616 cout << " * X: " << gzd << "*" << resrezd << "/" << ressezd << "=4*" << kGearRatio.X() << endl;1617 cout << " * Y: " << gaz << "*" << resreaz << "/" << resseaz << "=4*" << kGearRatio.Y() << endl;873 cout << " * X: " << kGear.X() << "*" << kResRE.X()/4 << "/" << kResSE.X() << "=4*" << kGearTot.X() << "/" << kResSE.X() << endl; 874 cout << " * Y: " << kGear.Y() << "*" << kResRE.Y()/4 << "/" << kResSE.Y() << "=4*" << kGearTot.Y() << "/" << kResSE.Y() << endl; 1618 875 } 1619 876 … … 1632 889 fMac3->SetDeceleration(0.2*res); 1633 890 fMac3->StartPosSync(); 1634 }1635 1636 void MCosy::TalkThreadTracking()1637 {1638 if (fZd1->IsZombieNode() && fZd2->IsZombieNode())1639 return;1640 1641 if (fAz->IsZombieNode())1642 return;1643 1644 if (!fMac1 || !fMac2)1645 return;1646 1647 lout << "- Tracking Thread started..." << endl;1648 1649 SlaStars sla(fObservatory);1650 sla.Now();1651 1652 ZdAz old;1653 ZdAz ist = GetSePos(); // [se]1654 1655 ZdAz time;1656 1657 ZdAz sollzd = sla.CalcZdAz(fRaDec); // [rad]1658 ZdAz sollaz = sollzd; // [rad]1659 1660 //1661 // only update fTrackingError while tracking1662 //1663 bool phca1=false;1664 bool phca2=false;1665 bool phcaz=false;1666 1667 while (fBackground==kBgdTracking)1668 {1669 //1670 // Make changes (eg wind) smoother - attenuation of control function1671 //1672 const float weight = 1.; //0.3;1673 1674 //1675 // This is the time constant which defines how fast1676 // you correct for external influences (like wind)1677 //1678 fZd1->ResetPosHasChanged();1679 fZd2->ResetPosHasChanged();1680 fAz->ResetPosHasChanged();1681 do1682 {1683 phca1 = fZd1->PosHasChanged();1684 phca2 = fZd2->PosHasChanged();1685 phcaz = fAz->PosHasChanged();1686 usleep(1);1687 } while (!phca1 && !phca2 && !phcaz && fBackground==kBgdTracking);1688 1689 //---usleep(100000); // 0.1s1690 1691 //1692 // get position, where we are1693 //1694 old = ist;1695 ist = GetSePos(); // [se]1696 1697 //1698 // if the position didn't change continue1699 //1700 /*---1701 if ((int)ist.Zd() == (int)old.Zd() &&1702 (int)ist.Az() == (int)old.Az())1703 continue;1704 */1705 ZdAz istre = GetRePosPdo();1706 1707 //1708 // Get time from last shaftencoder position change (position: ist)1709 // FIXME: I cannot take the avarage1710 //1711 // FIXME1712 //time.Zd(fZd1->GetMjd());1713 /* OLD* */1714 if (fZd1->GetMjd()>fZd2->GetMjd())1715 time.Zd(fZd1->GetMjd());1716 else1717 time.Zd(fZd2->GetMjd());1718 1719 //time.Zd((fZd1->GetMjd()+fZd2->GetMjd())/2.0);1720 time.Az(fAz->GetMjd());1721 1722 //1723 // if Shaftencoder changed position1724 // calculate were we should be1725 //1726 if (phca1 || phca2 /*(int)ist.Zd() != (int)old.Zd()*/)1727 {1728 sollzd = sla.CalcZdAz(fRaDec, time.Zd()); // [rad]1729 /*1730 ZdAz dummy = fBending(sla.CalcZdAz(fRaDec));1731 sollzd = CorrectTarget(ist, dummy); // [se]1732 */1733 fOffset.Zd(fOffset.Zd()*(1.-weight)+(ist.Zd()*kGearRatio.X()-istre.Zd())*weight);1734 }1735 1736 if (phcaz /*(int)ist.Az() != (int)old.Az()*/)1737 {1738 sollaz = sla.CalcZdAz(fRaDec, time.Az()); // [rad]1739 /*1740 ZdAz dummy = fBending(sla.CalcZdAz(fRaDec));1741 sollaz = CorrectTarget(ist, dummy); // [se]1742 */1743 fOffset.Az(fOffset.Az()*(1.-weight)+(ist.Az()*kGearRatio.Y()-istre.Az())*weight);1744 }1745 1746 ZdAz soll(sollzd.Zd(), sollaz.Az()); // [rad]1747 1748 fZdAzSoll = AlignTrackingPos(soll);1749 1750 ist *= TMath::Pi()*2/16384;1751 soll = fBending(fZdAzSoll);1752 fTrackingError.Set(ist.Zd()-soll.Zd(), ist.Az()-soll.Az());1753 1754 //--- fout << setprecision(15) << setw(17) << time.Zd()*60.*60.*24. << " ";1755 //--- fout << setprecision(5) << setw(7) << fTrackingError.Zd() << " ";1756 //--- fout << setprecision(15) << setw(17) << time.Az()*60.*60.*24. << " ";1757 //--- fout << setprecision(5) << setw(7) << fTrackingError.Az() << endl;1758 }1759 1760 lout << "- Tracking Thread done." << endl;1761 1762 //--- fout << endl << endl;1763 891 } 1764 892 … … 1813 941 } 1814 942 1815 Double_t apos = (pos[0]-pos[1])/2 * TMath:: Pi()*2 / 16384;943 Double_t apos = (pos[0]-pos[1])/2 * TMath::TwoPi() / kResSE.X(); 1816 944 1817 945 ZdAz bend = fBending.CorrectBack(ZdAz(apos, pos[2]))*kRad2Deg; … … 1865 993 ZdAz dre = re-re0; 1866 994 1867 if (fabs(dse.Zd())*144> 16384) // Each 2.5deg (144)995 if (fabs(dse.Zd())*144>kResSE.X()) // Each 2.5deg (144) 1868 996 { 1869 997 se0.Zd(se.Zd()); … … 1872 1000 se -= dse/2; 1873 1001 1874 ZdAz bend = fBending.CorrectBack(se* 2*TMath::Pi()/16384)*kRad2Deg;1002 ZdAz bend = fBending.CorrectBack(se*TMath::TwoPi()/kResSE)*kRad2Deg; 1875 1003 ((TH3*)fHist)->Fill(bend.Zd(), bend.Az(), dre.Zd()/dse.Zd()); 1876 1004 } 1877 1005 1878 if (fabs(dse.Az())*144> 16384) // Each 2.5deg (144)1006 if (fabs(dse.Az())*144>kResSE.Y()) // Each 2.5deg (144) 1879 1007 { 1880 1008 se0.Az(se.Az()); … … 1883 1011 se -= dse/2; 1884 1012 1885 ZdAz bend = fBending.CorrectBack(se* 2*TMath::Pi()/16384)*kRad2Deg;1013 ZdAz bend = fBending.CorrectBack(se*TMath::TwoPi()/kResSE)*kRad2Deg; 1886 1014 ((TH3*)fHist)->Fill(bend.Az(), bend.Az(), dre.Az()/dse.Az()); 1887 1015 } … … 1927 1055 case kBgdNone: 1928 1056 continue; 1929 1057 /*#ifndef NEWALGO 1930 1058 case kBgdTracking: 1931 1059 TalkThreadTracking(); 1932 1060 continue; 1933 1061 #endif*/ 1934 1062 case kBgdSeTest: 1935 1063 TalkThreadSeTest(); … … 1952 1080 1953 1081 // GetPointingPos [deg] 1954 const ZdAz seist = GetSePos()*2*TMath::Pi()/16384; // [se] 1955 1956 //cout << seist.Zd()*kRad2Deg << " " << seist.Az()*kRad2Deg << endl; 1957 1958 ZdAz back = fBending.CorrectBack(seist)*180/TMath::Pi(); 1959 1960 //cout << back.Zd() << " " << back.Az() << endl; 1961 1962 return back; 1082 const ZdAz seist = GetSePos()*TMath::TwoPi()/kResSE; // [rad] 1083 return fBending.CorrectBack(seist)*TMath::RadToDeg(); 1963 1084 } 1964 1085 1965 1086 Bool_t MCosy::HandleTimer(TTimer *t) 1966 1087 { 1088 const Int_t rc = fMutexGui.TryLock(); 1089 if (rc==13) 1090 cout << "MCosy::HandleTimer - mutex is already locked by this thread" << endl; 1091 1092 if (rc) 1093 { 1094 lout << "* GUI update skipped due to locked mutex." << endl; 1095 return kTRUE; 1096 } 1097 1967 1098 // 1968 1099 // Update Gui, foremer MTGui. … … 1975 1106 fAz->DisplayVal(); 1976 1107 1977 ZdAz bendist = GetPointingPos();1978 1979 1108 Byte_t avail = 0; 1980 1109 … … 1989 1118 SetStatus(MDriveCom::kError); 1990 1119 1991 lout.UpdateGui(); 1992 1120 ZdAz bendist = GetPointingPos(); 1121 fCom->SendReport(fStatus, fRaDec, fZdAzSoll, bendist, fTrackingError); 1122 1123 fWin->UpdateWeather(*fCom); 1993 1124 fWin->Update(bendist, fTrackingError, fVelocity, /*fOffset,*/ 1994 1125 fRaDec, fZdAzSoll, fStatus, avail); 1995 1126 1127 lout.UpdateGui(); 1128 1996 1129 const Bool_t trigger = fTriggerDisplay; 1997 1130 fTriggerDisplay = kFALSE; … … 2003 1136 DisplayHistGear(!trigger); 2004 1137 2005 // FIXME: Not thread safe! 2006 static int i=0; 2007 if (i++==7) 2008 { 2009 fCom->SendReport(fStatus, fRaDec, fZdAzSoll, bendist, fTrackingError); 2010 i=0; 2011 } 1138 if (fMutexGui.UnLock()==13) 1139 cout << "MCosy::HandleTimer - tried to unlock mutex locked by other thread." << endl; 1140 2012 1141 return kTRUE; 2013 1142 } … … 2195 1324 fAz =new ShaftEncoder(id6, "SE/Az", lout); 2196 1325 1326 fZd1->SetReport(fOutRep); 1327 fZd2->SetReport(fOutRep); 1328 fAz->SetReport(fOutRep); 1329 2197 1330 lout << "- Connecting devices to network." << endl; 2198 1331 … … 2265 1398 } 2266 1399 */ 1400 1401 TString MCosy::GetFileName(const char *fmt) 1402 { 1403 // FIXME: Timeout missing 1404 while (1) 1405 { 1406 MTime time(-1); 1407 const TString name = Form(fmt, (const char*)time.GetFileName()); 1408 if (gSystem->AccessPathName(name, kFileExists)) 1409 return name; 1410 break; 1411 1412 usleep(1000); 1413 } 1414 return ""; 1415 } 1416 2267 1417 MCosy::MCosy(/*int mode,*/ const char *dev, const int baud, MLog &out) 2268 : Network(dev, baud, out), fObservatory(MObservatory::kMagic1), fStarguider(NULL), fZd1(0), fZd2(0), fAz(0), fMac1(0), fMac2(0), fMac3(0), fBackground(kBgdNone), fStatus(MDriveCom::kStopped) 1418 : Network(dev, baud, out), fObservatory(MObservatory::kMagic1), fStarguider(NULL), fZd1(0), fZd2(0), fAz(0), fMac1(0), fMac2(0), fMac3(0), fBackground(kBgdNone), fStatus(MDriveCom::kStopped), fOutTp(0), fOutRep(0) 2269 1419 { 2270 1420 TEnv env(".cosyrc"); … … 2275 1425 const Int_t id5 = env.GetValue("Zd_Id-SE2", 5); //5 2276 1426 const Int_t id6 = env.GetValue("Az_Id-SE", 6); //6 1427 1428 TString name = GetFileName("rep/cosy_%s.rep"); 1429 cout << "Open Repfile: " << name << endl; 1430 fOutRep = new MLog(name, kTRUE); 1431 2277 1432 /* 2278 1433 lout << "- Program in "; … … 2300 1455 fAz->SetDisplay(fWin->GetLabel1()); 2301 1456 2302 // 2303 // open tpoint file 2304 // 2305 MTime time; 2306 TString name; 2307 while (1) 2308 { 2309 time.Now(); 2310 name = Form("tpoint/tpoint_%s.txt", (const char*)time.GetFileName()); 2311 if (gSystem->AccessPathName(name, kFileExists)) 2312 break; 2313 } 2314 2315 cout << "TPoint File ********* " << name << " ********** " << endl; 2316 2317 tpout = new ofstream(name); 2318 *tpout << "Magic Model TPOINT data file" << endl; 2319 *tpout << ": ALTAZ" << endl; 2320 *tpout << "49 48 0 "; 2321 *tpout << time.Year() << " " << time.Month() << " " << time.Day() << " "; 2322 *tpout << /*"20 1013.25 300 0.5 0.55 0.0065" <<*/ endl; 2323 // temp(°C) pressure(mB) height(m) humidity(1) wavelength(microm) troplapserate(K/m) 2324 2325 fCom = new MDriveCom(this, out); 1457 fCom = new MDriveCom(this, *fOutRep); 2326 1458 fCom->Start(); 2327 1459 } … … 2349 1481 MCosy::~MCosy() 2350 1482 { 2351 *tpout << "END" << endl; 2352 //streampos size = tpout.tellp(); 2353 delete tpout; 1483 if (fOutTp) 1484 { 1485 *fOutTp << "END" << endl; 1486 delete fOutTp; 1487 } 1488 delete fOutRep; 2354 1489 2355 1490 cout << "Deleting GUI timer." << endl; … … 2359 1494 2360 1495 cout << "Deleting Nodes." << endl; 1496 1497 fZd1->SetReport(0); 1498 fZd2->SetReport(0); 1499 fAz->SetReport(0); 2361 1500 2362 1501 delete fAz; -
trunk/MagicSoft/Cosy/main/MCosy.h
r3897 r4076 8 8 #include "MBending.h" 9 9 10 #ifndef MARS_M observatory10 #ifndef MARS_MObservatory 11 11 #include "MObservatory.h" 12 #endif 13 #ifndef ROOT_TMutex 14 #include <TMutex.h> 12 15 #endif 13 16 … … 62 65 { 63 66 friend class MTTalk; 67 friend class MPointing; 68 friend class MTracking; 64 69 65 70 private: … … 83 88 // with a generic interface to both... 84 89 90 TMutex fMutexGui; 91 85 92 enum BackgroundAction_t 86 93 { 87 94 kBgdNone, 88 kBgdTracking,95 //kBgdTracking, 89 96 kBgdSeTest, 90 97 kBgdSeTestDispl, … … 96 103 97 104 ZdAz fTrackingError; // [rad] Tracking Offset between SE and calc-pos 98 ZdAz fOffset; // Offset between se and re coordinate system [re]99 105 ZdAz fZdAzSoll; // [rad] Soll position when moving 100 106 RaDec fRaDec; // Position to track … … 107 113 Bool_t fTriggerDisplay; 108 114 109 XY kGearRatio; // describing the gear of the system [re/se] 110 XY kGearRatio2; // describing the gear of the system [re/deg] 115 XY kResSE; // describing the resolution of the system [se/U_tel] 116 XY kResRE; // describing the resolution of the system [re/U_mot] 117 XY kGear; // describing the resolution of the system [U_mot/U_tel] 118 XY kGearTot; // describing the resolution of the system [re/U_tel] 111 119 112 120 MBending fBending; … … 114 122 UInt_t fStatus; 115 123 116 ofstream * tpout;117 118 //Bool_t AlignTrackingPos(ZdAz pointing, ZdAz &za) const; 124 ofstream *fOutTp; 125 MLog *fOutRep; 126 119 127 ZdAz AlignTrackingPos(ZdAz pointing) const; 120 128 Bool_t CheckRange(const ZdAz &d) const; 121 129 Double_t Starguider(Double_t mjd, ZdAz &dest) const; 122 130 123 double Rad2SE(double rad) const;124 double Rad2ZdRE(double rad) const;125 double Rad2AzRE(double rad) const;126 double Deg2ZdRE(double rad) const;127 double Deg2AzRE(double rad) const;128 129 131 void SetStatus(UInt_t stat) { fStatus = stat; } 130 132 UInt_t GetStatus() const { return fStatus; } … … 133 135 ZdAz GetRePosPdo(); 134 136 ZdAz GetSePos() const; // [se] 135 136 Bool_t RequestRePos(); 137 Bool_t SetVelocity(const ZdAz &v); 138 139 void SetPosVelocity(const Float_t ratio, Float_t vel); 140 141 void DoRelPos(const ZdAz &rd, const Bool_t axe1, const Bool_t axe2); 137 // FIXME: Must depend on the Shaftencoder mounted 138 ZdAz GetSePosRad() const { return GetSePos()*TMath::TwoPi()/16384; } // [rad] 142 139 143 140 void InitSync(); 144 bool InitTracking();145 Bool_t LimitSpeed(ZdAz *vt, const ZdAz &vcalc) const;146 141 147 142 void TalkThread(); 148 void TalkThreadTracking();149 143 void TalkThreadSeTest(); 150 144 void TalkThreadGear(); … … 154 148 155 149 int SetPosition(const ZdAz &dst, Bool_t track=kFALSE); 150 void TrackPosition(const RaDec &dst); // ra, dec [rad] 156 151 157 152 void TerminateApp(); 158 159 void TrackPosition(const RaDec &dst); // ra, dec [rad]160 153 161 154 int StopWaitingForSDO() const; … … 163 156 164 157 void StopMovement(); 165 void StopTracking();166 158 167 159 void WaitForEndMovement(); … … 188 180 ZdAz GetPointingPos(void) const; 189 181 void SetStarguider(MStarguider *s) { fStarguider = s; } 190 182 183 static TString GetFileName(const char *name); 184 185 MGCosy *GetWin() { return fWin; } 186 187 AltAz GetAltAzDeg() const 188 { 189 ZdAz sepos = GetSePos()*TMath::TwoPi()/kResSE; 190 AltAz za1(TMath::Pi()/2-sepos.Zd(), sepos.Az()); 191 za1 *= kRad2Deg; 192 return za1; 193 } 194 191 195 // static ZdAz CorrectTarget(const ZdAz &src, const ZdAz &dst); 192 196 // static ZdAz RaDec2ZdAz(const double mjd, const RaDec &pos, const RaDec &pm=RaDec(0,0)); -
trunk/MagicSoft/Cosy/main/MPointing.cc
r3935 r4076 74 74 const int vr = mac->GetVelRes(); 75 75 mac->SetAcceleration(acc*vr); 76 mac->Set Acceleration(dec*vr);76 mac->SetDeceleration(dec*vr); 77 77 return !mac->IsZombieNode(); 78 78 } … … 96 96 int MPointing::SetPosition(const ZdAz &dst, Bool_t track) // [rad] 97 97 { 98 /*99 98 const ZdAz d = dst*kRad2Deg; 100 99 … … 105 104 // Calculate new target position (shortest distance to go) 106 105 // 107 const ZdAz src = fCosy->GetSePos(); // [se]106 //const ZdAz src = fCosy->GetSePos(); // [se] 108 107 109 108 // … … 123 122 ZdAz bend = fCosy->fBending(dst); // [rad] 124 123 125 const ZdAz dest = bend* 16384/2/TMath::Pi(); // [se]124 const ZdAz dest = bend*fCosy->kResSE/TMath::TwoPi(); // [se] 126 125 127 126 if (!fCosy->CheckRange(bend)) … … 131 130 fCosy->fZdAzSoll = dst; 132 131 133 cout << "Source Zd: " << src.Zd() << "se Az:" << src.Az() << "se" << endl; 134 cout << "Destination Zd: " << dst.Zd()*8192/TMath::Pi() << "se Az:" << dst.Az()*8192/TMath::Pi() << "se" << endl; 135 cout << "Bend'd Dest Zd: " << dest.Zd() << "se Az:" << dest.Az() << "se" << endl; 136 cout << "Bend'd Dest Zd: " << bend.Zd() << "deg Az:" << bend.Az() << "deg" << endl; 132 //cout << "Source Zd: " << src.Zd() << "se Az:" << src.Az() << "se" << endl; 133 //cout << "Destination Zd: " << Rad2SE(dst.Zd()) << "se Az:" << Rad2SE(dst.Az()) << "se" << endl; 134 //cout << "Bend'd Dest Zd: " << dest.Zd() << "se Az:" << dest.Az() << "se" << endl; 135 //cout << "Bend'd Dest Zd: " << bend.Zd() << "deg Az:" << bend.Az() << "deg" << endl; 136 137 // 138 // Set velocities 139 // 140 //const int vr = fCosy->fMac1->GetVelRes(); 141 142 const Float_t rad2se = fCosy->kResSE.X()/TMath::TwoPi(); 137 143 138 144 int i; 139 for (i=0; i<(track?1:10) && !Break() ; i++)145 for (i=0; i<(track?1:10) && !Break()/*(fCosy->Break() || fCosy->HasError() || fCosy->HasZombie())*/; i++) 140 146 { 141 147 142 148 lout << "- Step #" << i << endl; 143 // 149 144 150 // Get Shaft Encoder Positions 145 //146 151 const ZdAz p=fCosy->GetSePos(); 147 152 148 //149 153 // calculate control deviation and rounded cd 150 //151 154 ZdAz rd = dest-p; // [se] 152 153 // ===========================================154 const ZdAz ist = dst-rd*TMath::Pi()/8192;155 156 const double p1 = ist.Zd()-19.0605/kRad2Deg;157 const double p2 = dst.Zd()-19.0605/kRad2Deg;158 159 const double f1 = (-26.0101*sin(p1)+443.761*ist.Zd())*8192/TMath::Pi();160 const double f2 = (-26.0101*sin(p2)+443.761*dst.Zd())*8192/TMath::Pi();161 // ===========================================162 163 155 ZdAz cd = rd; // [se] 164 156 cd.Round(); 165 157 166 //167 158 // Check if there is a control deviation on the axis 168 //169 159 const Bool_t cdzd = (int)cd.Zd() ? kTRUE : kFALSE; 170 160 const Bool_t cdaz = (int)cd.Az() ? kTRUE : kFALSE; 171 161 172 //173 162 // check if we reached the correct position already 174 //175 163 if (!cdzd && !cdaz) 176 164 { … … 178 166 lout << t << " - Positioning done in " << i << (i==1?" step.":" steps.") << endl; 179 167 fCosy->SetStatus(MDriveCom::kStopped); 180 fCosy->fCom->Send ("POSITION DONE");168 fCosy->fCom->SendStatus("Target position reached."); 181 169 return TRUE; 182 170 } 183 171 184 // 172 // ============================================== 173 // Estimate the noncircularity of the zd axis 174 const ZdAz ist = dst-rd*TMath::TwoPi()/fCosy->kResSE; 175 176 const double p1 = ist.Zd()-19.0605/kRad2Deg; 177 const double p2 = dst.Zd()-19.0605/kRad2Deg; 178 179 const double f1 = (-26.0101*sin(p1)+443.761*ist.Zd())*rad2se; 180 const double f2 = (-26.0101*sin(p2)+443.761*dst.Zd())*rad2se; 181 // ==++========================================= 182 185 183 // change units from se to re 186 // 187 rd *= fCosy->kGearRatio; // [re] 184 rd *= fCosy->kGearTot/fCosy->kResSE; // [re] 188 185 rd.Zd(f2-f1); 189 186 190 //191 187 // Initialize Velocities so that we reach both positions 192 188 // at the same time 193 //194 if (i)195 {196 lout << "--- LO-SPEED ---" << endl;197 SetAccDec(fCosy->fMac1, 0.1, 0.1);198 SetAccDec(fCosy->fMac2, 0.1, 0.1);199 200 SetPosVelocity(1.0, 0.05);201 }202 else203 {204 const Double_t y = 15*fCosy->kGearRatio.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 else211 SetAccDec(fCosy->fMac1, fAcc, fDec);212 213 SetAccDec(fCosy->fMac2, fAcc, fDec);214 215 SetPosVelocity(fabs(rd.Ratio()), fVel);216 }217 218 rd.Round();219 220 // FIXME? Check for Error or Zombie?221 222 // cout << " + " << (int)cdzd << " " << (int)cdaz << endl;223 // cout << " + APOS: Zd=" << setw(6) << p.Zd() << "se Az=" << setw(6) << p.Az() << "se" << endl;224 // cout << " + dZd=" << setw(6) << cd.Zd() << "se dAz=" << setw(6) << cd.Az() << "se" << endl;225 // cout << " + dZd=" << setw(6) << rd.Zd() << "re dAz=" << setw(6) << rd.Az() << "re" << endl;226 // cout << " + Ratio: Zd=" << setw(6) << kGearRatio.X() << "se Az=" << setw(6) << kGearRatio.Y() << "se" << endl;227 228 //229 // repositioning (relative)230 //231 232 lout << "- Do Relative Positioning..." << endl;233 DoRelPos(rd, cdzd, cdaz);234 lout << "- Relative Positioning Done" << endl;235 }236 237 238 return FALSE;*/239 240 const ZdAz d = dst*kRad2Deg;241 242 MTime t(-1);243 lout << t << " - Target Position: " << d.Zd() << "deg, " << d.Az() << "deg (Zd/Az)" << endl;244 245 //246 // Calculate new target position (shortest distance to go)247 //248 //const ZdAz src = fCosy->GetSePos(); // [se]249 250 //251 // Make sure that the motors are in sync mode (necessary if the252 // MACS has been rebooted from a Zombie state.253 //254 //InitSync();255 //if (fMac3->IsZombieNode())256 // return false;257 258 //259 // Because we agreed on I don't search for the shortest move260 // anymore261 //262 // const ZdAz dest = CorrectTarget(src, dst);263 //264 ZdAz bend = fCosy->fBending(dst); // [rad]265 266 const ZdAz dest = bend*16384/2/TMath::Pi(); // [se]267 268 if (!fCosy->CheckRange(bend))269 return kFALSE;270 271 bend *= kRad2Deg;272 fCosy->fZdAzSoll = dst;273 274 //cout << "Source Zd: " << src.Zd() << "se Az:" << src.Az() << "se" << endl;275 //cout << "Destination Zd: " << Rad2SE(dst.Zd()) << "se Az:" << Rad2SE(dst.Az()) << "se" << endl;276 //cout << "Bend'd Dest Zd: " << dest.Zd() << "se Az:" << dest.Az() << "se" << endl;277 //cout << "Bend'd Dest Zd: " << bend.Zd() << "deg Az:" << bend.Az() << "deg" << endl;278 279 //280 // Set velocities281 //282 //const int vr = fCosy->fMac1->GetVelRes();283 284 int i;285 for (i=0; i<(track?1:10) && !Break()/*(fCosy->Break() || fCosy->HasError() || fCosy->HasZombie())*/; i++)286 {287 288 lout << "- Step #" << i << endl;289 //290 // Get Shaft Encoder Positions291 //292 const ZdAz p=fCosy->GetSePos();293 294 //295 // calculate control deviation and rounded cd296 //297 ZdAz rd = dest-p; // [se]298 299 // ===========================================300 const ZdAz ist = dst-rd*TMath::Pi()/8192;301 302 const double p1 = ist.Zd()-19.0605/kRad2Deg;303 const double p2 = dst.Zd()-19.0605/kRad2Deg;304 305 const double f1 = (-26.0101*sin(p1)+443.761*ist.Zd())*8192/TMath::Pi();306 const double f2 = (-26.0101*sin(p2)+443.761*dst.Zd())*8192/TMath::Pi();307 // ===========================================308 309 ZdAz cd = rd; // [se]310 cd.Round();311 312 //313 // Check if there is a control deviation on the axis314 //315 const Bool_t cdzd = (int)cd.Zd() ? kTRUE : kFALSE;316 const Bool_t cdaz = (int)cd.Az() ? kTRUE : kFALSE;317 318 //319 // check if we reached the correct position already320 //321 if (!cdzd && !cdaz)322 {323 t.Now();324 lout << t << " - Positioning done in " << i << (i==1?" step.":" steps.") << endl;325 fCosy->SetStatus(MDriveCom::kStopped);326 fCosy->fCom->Send("POSITION DONE");327 return TRUE;328 }329 330 //331 // change units from se to re332 //333 rd *= fCosy->kGearRatio; // [re]334 rd.Zd(f2-f1);335 336 //337 // Initialize Velocities so that we reach both positions338 // at the same time339 //340 /* if (i)341 {342 fCosy->fMac1->SetAcceleration(0.1*vr);343 fCosy->fMac2->SetAcceleration(0.1*vr);344 345 fCosy->fMac1->SetDeceleration(0.1*vr);346 fCosy->fMac2->SetDeceleration(0.1*vr);347 348 fCosy->SetPosVelocity(1.0, 0.05);349 }350 else351 {352 if (rd.Az()>-15*fCosy->kGearRatio.Y() && rd.Az()<15*fCosy->kGearRatio.Y())353 {354 #ifdef EXPERT355 cout << " -------------- LO ---------------- " << endl;356 #endif357 fCosy->fMac1->SetAcceleration(0.05*vr);358 fCosy->fMac1->SetDeceleration(0.05*vr);359 }360 else361 {362 #ifdef EXPERT363 cout << " -------------- HI ---------------- " << endl;364 fCosy->fMac1->SetAcceleration(0.4*vr);// 0.4365 fCosy->fMac1->SetDeceleration(0.4*vr);// 0.4366 #else367 fCosy->fMac1->SetAcceleration(0.2*vr);368 fCosy->fMac1->SetDeceleration(0.1*vr);369 #endif370 }371 372 #ifdef EXPERT373 fCosy->fMac2->SetAcceleration(0.4*vr);// 0.4374 fCosy->fMac2->SetDeceleration(0.4*vr);// 0.4375 fCosy->SetPosVelocity(fabs(rd.Ratio()), 0.2); // fast: 0.6, slow: 0.2376 #else377 fCosy->fMac2->SetAcceleration(0.2*vr);378 fCosy->fMac2->SetDeceleration(0.1*vr);379 fCosy->SetPosVelocity(fabs(rd.Ratio()), 0.1);380 #endif381 }382 */383 189 if (i) 384 190 { … … 391 197 else 392 198 { 393 const Double_t y = 15*fCosy->kGear Ratio.Y();199 const Double_t y = 15*fCosy->kGearTot.Y()*fCosy->kResSE.Y(); 394 200 if (rd.Az()>-y && rd.Az()<y) 395 201 { … … 409 215 // FIXME? Check for Error or Zombie? 410 216 411 412 217 // cout << " + " << (int)cdzd << " " << (int)cdaz << endl; 413 218 // cout << " + APOS: Zd=" << setw(6) << p.Zd() << "se Az=" << setw(6) << p.Az() << "se" << endl; … … 416 221 // cout << " + Ratio: Zd=" << setw(6) << kGearRatio.X() << "se Az=" << setw(6) << kGearRatio.Y() << "se" << endl; 417 222 418 419 //420 223 // repositioning (relative) 421 //422 224 lout << "- Do Relative Positioning..." << endl; 423 225 DoRelPos(rd, cdzd, cdaz); … … 429 231 lout << t << " - Positioning done." << endl; 430 232 fCosy->SetStatus(MDriveCom::kStopped); 431 fCosy->fCom->Send ("POSITION DONE");233 fCosy->fCom->SendStatus("Tracking preposition reached."); 432 234 return TRUE; 433 235 } … … 441 243 lout << t << " - Warning: Requested position not reached (i=" << dec << i << ")" << endl; 442 244 443 fCosy->fCom->Send ("POSITION FAILED");245 fCosy->fCom->SendStatus("Target position missed!"); 444 246 445 247 return FALSE; -
trunk/MagicSoft/Cosy/main/MTracking.cc
r3935 r4076 13 13 //#define EXPERT 14 14 #undef EXPERT 15 16 // -------------------------------------------------------------------------- 17 // 18 // request the current positions from the rotary encoders. 19 // use GetRePos to get the psotions. If the request fails the function 20 // returns kFALSE, otherwise kTRUE 21 // 22 bool MTracking::RequestRePos() 23 { 24 // 25 // Send request 26 // 27 fCosy->fMac2->RequestSDO(0x6004); 28 fCosy->fMac1->RequestSDO(0x6004); 29 30 // 31 // Wait until the objects are received. 32 // 33 fCosy->fMac2->WaitForSdo(0x6004); 34 fCosy->fMac1->WaitForSdo(0x6004); 35 36 // 37 // If waiting was not interrupted everything is ok. return. 38 // 39 if (!Break()) 40 return true; 41 42 // 43 // If the waiting was interrupted due to a network error, 44 // print some logging message. 45 // 46 if (fCosy->HasError()) 47 lout << "Error while requesting re pos from Macs (SDO #6004)" << endl; 48 49 return false; 50 } 15 51 16 52 // -------------------------------------------------------------------------- … … 49 85 return true; 50 86 } 51 87 /* 88 void MTracking::StopTracking() 89 { 90 // 91 // Set status to Stopping 92 // 93 fCosy->SetStatus(MDriveCom::kStopping); 94 95 // 96 // set deceleration to 50% 97 // 98 cout << "Stopping tracking (dec=20%)..." << endl; 99 fCosy->fMac1->SetDeceleration(0.2*fMac1->GetVelRes()); 100 fCosy->fMac2->SetDeceleration(0.2*fMac2->GetVelRes()); 101 102 fCosy->fMac2->SendSDO(0x3006, 1, (LWORD_t)0); // SetRpmVelocity [re/min] 103 fCosy->fMac1->SendSDO(0x3006, 1, (LWORD_t)0); // SetRpmVelocity [re/min] 104 fCosy->fMac2->WaitForSdo(0x3006, 1); 105 fCosy->fMac1->WaitForSdo(0x3006, 1); 106 107 cout << "Waiting for end of movement..." << endl; 108 fCosy->WaitForEndMovement(); 109 110 // 111 // Wait for the objects to be OKed. 112 // 113 fCosy->fMac1->SetRpmMode(FALSE); 114 fCosy->fMac2->SetRpmMode(FALSE); 115 116 // 117 // Wait for the movement to really be finished. 118 // 119 //cout << "Waiting for end of movement..." << endl; 120 //WaitForEndMovement(); 121 122 // 123 // Check whether everything works fine. 124 // 125 fCosy->CheckForError(); 126 cout << "Movement stopped." << endl; 127 } 128 */ 52 129 // -------------------------------------------------------------------------- 53 130 // … … 58 135 // velocities are limited to the maximum velocity. 59 136 // 60 Bool_t MTracking::LimitSpeed(ZdAz *vt, const ZdAz &vcalc) const 61 { 137 Bool_t MTracking::LimitSpeed(ZdAz *vt, const SlaStars &sla) const 138 { 139 // vt[re/min] 140 141 // Calculate approximate velocity of both axis 142 ZdAz vcalc = sla.GetApproxVel(fCosy->fRaDec); // [rad/rad] 143 144 //vcalc *= 1./(24*60); // [U_tel/min] 145 //vcalc *= fCosy->kGearTot; // [U_mot/min] 146 //vcalc *= fCosy->kResRE; // [re/min] 147 148 vcalc *= fCosy->kGearTot*fCosy->kResRE/(24*60); // [re/min] 149 150 // Set return code 62 151 Bool_t rc = kFALSE; 63 152 … … 83 172 const Float_t maxtrack = 0.1; 84 173 85 if (fabs(vt->Az()) > maxtrack*vraz) 86 { 174 if (fabs(vt->Az()) > maxtrack*vraz*4) 175 { 176 vt->Az(maxtrack*vraz*4*sgn(vcalc.Az())); 87 177 lout << "Warning: Azimuth speed limit (" << maxtrack*100 << "%) exceeded (" << fabs(vt->Az()) << " > " << maxtrack*vraz << ")... limited." << endl; 88 vt->Az(maxtrack*vraz*sgn(vcalc.Az()));178 lout << "Vcalc: " << vcalc.Zd() << " " << vcalc.Az() << "re/min" <<endl; 89 179 rc=kTRUE; 90 180 } 91 if (fabs(vt->Zd()) > maxtrack*vrzd) 92 { 181 if (fabs(vt->Zd()) > maxtrack*vrzd*4) 182 { 183 vt->Zd(maxtrack*vrzd*4*sgn(vcalc.Zd())); 93 184 lout << "Warning: Altitude speed limit (" << maxtrack*100 << "%) exceeded (" << fabs(vt->Zd()) <<" > " << maxtrack*vrzd << ")... limited." << endl; 94 vt->Zd(maxtrack*vrzd*sgn(vcalc.Zd()));185 lout << "Vcalc: " << vcalc.Zd() << " " << vcalc.Az() << "re/min" <<endl; 95 186 rc=kTRUE; 96 187 } … … 146 237 lout << sla.GetTime() << ": Track Position " << dst.Ra()*kRad2Deg/15 << "h, " << dst.Dec()*kRad2Deg <<"deg" << endl; 147 238 148 // az between -180 and 180 149 if (dst.Dec()>sla.GetPhi() && dest.Az()<0) 150 { 151 // align az between (roughly) 60 and 320 152 lout << "Adding 360deg to Azimuth " << dest.Az()*kRad2Deg << endl; 153 dest.Az(dest.Az() + TMath::Pi()*2); 154 } 155 /* 156 // FIXME: Determin tracking start point by star culmination 157 if (dest.Az()<-TMath::Pi()/2) 158 { 159 lout << "Adding 360deg to Azimuth " << dest.Az()*kRad2Deg << endl; 160 dest.Az(dest.Az() + TMath::Pi()*2); 161 } 162 163 if (dest.Az()>3*TMath::Pi()/2) 164 { 165 lout << "Substracting 360deg to Azimuth " << dest.Az()*kRad2Deg << endl; 166 dest.Az(dest.Az() -TMath::Pi()*2); 167 } 168 */ 239 // If the star is culminating behind the zenith (South) we want to 240 // align the azimuth angle between -180 and 180deg. If the star is 241 // culminating before the zenith (north) we want the star to be 242 // aligned between -180 and 180deg (which is the default of CalcZdAz) 243 if (sla.GetPhi()>dst.Dec() && dest.Az()<0) 244 { 245 // align az from -180/180 to 0/360 246 lout << "Star culminating behind zenith: Adding 360deg to Azimuth " << dest.Az()*kRad2Deg << endl; 247 dest.Az(dest.Az() + TMath::TwoPi()); 248 } 249 250 // Position the telescope to the current local position of the 251 // star. Do not reposition but start the tracking after the 252 // first positioning step 169 253 if (!SetPosition(dest, kTRUE)) 170 //if (!SetPosition(dest, kFALSE))171 254 { 172 255 lout << "Error: Cannot start tracking, positioning failed." << endl; … … 177 260 // calculate offset from present se position 178 261 // 179 const ZdAz sepos = fCosy->GetSePos()*fCosy->kGearRatio; 180 181 if (!fCosy->RequestRePos()) 262 const ZdAz sepos = fCosy->GetSePos()*fCosy->kGearTot/fCosy->kResSE; //[re] 263 if (!RequestRePos()) 182 264 return; 183 265 … … 185 267 // Estimate Offset before starting to track 186 268 // 187 f Cosy->fOffset = sepos-fCosy->GetRePos();269 fOffset = sepos-fCosy->GetRePos(); 188 270 189 271 /* … … 202 284 } 203 285 204 XY xy(Rad2Deg(dst.Ra())*24/360, Rad2Deg(dst.Dec()));205 206 sla.Now();207 // lout << sla.GetTime() << " - Start tracking:";208 // lout << " Ra: " << xy.X() << "h " << "Dec: " << xy.Y() << "\xb0" << endl;209 210 /*#ifdef EXPERT211 ofstream fout("coordinates.txt");212 fout << xy;213 fout.close();214 #endif215 */ //216 286 // Initialize Tracker (slalib or starguider) 217 //218 287 fCosy->fRaDec = dst; 219 288 … … 221 290 Start(); 222 291 292 // Get current nominal local position 293 sla.Now(); 223 294 ZdAz pos = sla.CalcZdAz(fCosy->fRaDec); 224 295 296 // Some output 297 XY xy(Rad2Deg(dst.Ra())*24/360, Rad2Deg(dst.Dec())); 225 298 lout << sla.GetTime() << " - Start Tracking: Ra=" <<xy.X() << "h Dec="; 226 299 lout << xy.Y() << "\xb0 @ Zd=" << pos.Zd()*kRad2Deg <<"deg Az=" << pos.Az()*kRad2Deg <<"deg" << endl; 227 228 //--- ofstream fout("log/cosy.pos");229 //--- fout << "Tracking:";230 //--- fout << " Ra: " << Rad2Deg(dst.Ra()) << "\x9c ";231 //--- fout << "Dec: " << Rad2Deg(dst.Dec()) << "\x9c" << endl << endl;232 //--- fout << " Mjd/10ms V/re/min/4" << endl;233 300 234 301 // … … 240 307 { 241 308 // 242 // Request Target position for this moment309 // Request Target position for Now+dt 243 310 // 244 311 sla.Now(dt); 245 312 246 313 // 247 // Request theoretical Position for a time in the future (To+dt) from CPU 248 // 249 const ZdAz pointing = sla.CalcZdAz(fCosy->fRaDec); // soll pointing [rad] 250 251 //lout << sla.GetTime() << pointing.Zd()*kRad2Deg << " " << pointing.Az()*kRad2Deg << endl; 252 /* 253 ZdAz dest; 254 if (!AlignTrackingPos(pointing, dest)) 255 break; 256 */ 257 ZdAz dest = fCosy->AlignTrackingPos(pointing); 258 259 // lout << "DEST: " << dest.Zd()*kRad2Deg << " " <<dest.Az()*kRad2Deg << endl; 260 261 ZdAz vcalc = sla.GetApproxVel(fCosy->fRaDec) * fCosy->kGearRatio2*4./60.; 262 //lout << "Vcalc: " << dest.Zd() << " " << dest.Az() << endl; 263 vcalc *= fCosy->kGearRatio2*4./60.; // [re/min] 314 // Request nominal position for this time in the future (To+dt) 315 // 316 const ZdAz pointing = sla.CalcZdAz(fCosy->fRaDec); // [rad] 317 ZdAz dest = fCosy->AlignTrackingPos(pointing); // fix ambiguity 318 319 //ZdAz vcalc = sla.GetApproxVel(fCosy->fRaDec); 320 //vcalc *= fCosy->kGearRatio2*4./60.; // [re/min] 264 321 265 322 float dtime = -1; … … 267 324 // dtime = Starguider(sla.GetMjd(), dest); 268 325 326 ZdAz repos; 269 327 if (dtime<0) 270 328 { 271 dest = fCosy->fBending(dest); // [rad] 272 273 //lout << "DEST-BEND: " << dest.Zd()*kRad2Deg << " " <<dest.Az()*kRad2Deg << endl; 274 329 dest = fCosy->fBending(dest); // [rad] 275 330 if (!fCosy->CheckRange(dest)) 276 331 break; 277 332 278 dest *= 16384/TMath::Pi()/2; // [se] 279 dest *= fCosy->kGearRatio; // [re] 280 281 *fCosy->fOutRep << "> ReqRePos1 " << endl; 333 dest *= fCosy->kGearTot/TMath::TwoPi(); // [re] 334 335 //*fCosy->fOutRep << "> ReqRePos1 " << endl; 282 336 283 337 // 284 338 // Request absolute position of rotary encoder from Macs 285 339 // 286 if (! fCosy->RequestRePos())340 if (!RequestRePos()) 287 341 break; 288 342 289 *fCosy->fOutRep << "> ReqRePos2 "<< endl;343 //*fCosy->fOutRep << "> ReqRePos2 " << fOffset.Zd() << " " << fOffset.Az() << endl; 290 344 291 345 // … … 294 348 // fOffset does the synchronization between the 295 349 // Shaft- and the rotary encoders 296 dest -= fCosy->GetRePos() + fCosy->fOffset; 350 repos = fCosy->GetRePos(); 351 dest -= repos + fOffset; //[re] 297 352 298 353 dtime = dt; 299 300 ZdAz repos = fCosy->GetRePos();301 // lout << "Repos: " << repos.Zd()/kGearRatio.X() << " " << repos.Az()*kGearRatio.Y() << endl;302 // repos /= kGearRatio;303 repos /= 16384/TMath::Pi()/2;304 repos *= kRad2Deg;305 354 } 306 355 … … 309 358 // correct for the duration of RaDec2AltAz 310 359 // 311 const ZdAz v = dest*60.0/(dtime/*-(fMac2->GetTime()-sla)*/); 360 /* --- OLD --- */ 361 ZdAz v = dest*60.0/dtime; //[re/min] 362 /* --- NEW --- seems to work worse! */ 363 //const Double_t dtaz = sla.GetTime() - fCosy->fMac1->GetPosTime(); 364 //const Double_t dtzd = sla.GetTime() - fCosy->fMac2->GetPosTime(); 365 // 366 //ZdAz v = dest*60.0; 367 //v.Zd(v.Zd()/dtzd); 368 //v.Az(v.Az()/dtaz); 369 /* --- END --- */ 370 371 //*fCosy->fOutRep << "> Dt: " << dtaz << " " << dtzd << endl; 372 373 if (LimitSpeed(&v, sla)) 374 { 375 lout << "vt: " << v.Zd() << " " << v.Az() << "re/min" << endl; 376 lout << "Dest: " << dest.Zd() << " " << dest.Az() << endl; 377 } 312 378 313 379 // … … 315 381 // believing the Macs manual '/4' shouldn't be necessary, but it is. 316 382 // 317 ZdAz vt = v/4; 318 if (LimitSpeed(&vt, vcalc)) 319 { 320 lout << "Vcalc: " << vcalc.Zd() << " " << vcalc.Az() << "re/min" <<endl; 321 lout << "vt: " << vt.Zd() << " " << vt.Az() << "re/min" << endl; 322 lout << "Dest: " << dest.Zd() << " " << dest.Az() << endl; 323 } 383 ZdAz vt = v/4; //[re'/min] 384 //lout << " " << vt.Zd() << " " << vt.Az() << " "; 324 385 vt.Round(); 386 //lout << " " << vt.Zd() << " " << vt.Az() << endl; 325 387 326 388 // … … 337 399 // Maybe we should attenuate the changes 338 400 // 339 *fCosy->fOutRep << "> SetVelocity1 "<< endl;401 //*fCosy->fOutRep << "> SetVelocity1: " << vt.Zd() << " " << vt.Az() << endl; 340 402 if (!SetVelocity(vt)) 341 403 break; 342 *fCosy->fOutRep << "> SetVelocity2 " << endl; 343 344 // 345 // Now do 'unnecessary' things 346 // 347 fCosy->fVelocity = vt/fCosy->kGearRatio2*4; 348 349 //--- const double mjd = fMac2->GetMjd(); 350 //--- fout << setprecision(15) << setw(17) << mjd*60.*60.*24. << " "; 351 //--- fout << setw(4) << vt.Zd() << " "; 352 //--- fout << setw(4) << vt.Az() << endl; 353 // 354 // FIXME? Calculate an accuracy for the tracking system? 355 // How good do we reach the calculated position in 'real' 356 // re valus? 357 // 358 404 //*fCosy->fOutRep << "> SetVelocity2 " << endl; 405 406 // 407 // Now do 'unnecessary' things (timing) 408 // 409 fCosy->fVelocity = vt*4/fCosy->kGear; // [U_mot/min] 410 // *OLD* fVelocity = vt/kGearRatio2*4; 411 412 if (fOut) 413 { 414 fOut->Lock(); 415 *fOut << "RE-REPORT " << MTime(-1) << " " << repos.Zd() << " " << repos.Az() <<" " << vt.Zd() << " " << vt.Az() << endl; 416 fOut->UnLock(); 417 } 359 418 360 419 // … … 363 422 // update time 364 423 // 365 //366 424 // The loop should not be executed faster than the ramp of 367 425 // a change in the velocity can be followed. 368 426 // (This is important on fast machines >500MHz) 369 427 // 370 /*371 MTimeout t(1000);372 while (!t.HasTimedOut())373 usleep(1);374 */375 428 usleep(1000000); // 1s 376 cout << "." << flush; 377 //usleep(50000); // 0.05s 429 // *****FIXME**** cout << "." << flush; 378 430 } 379 431 … … 385 437 fCosy->StopMovement(); 386 438 387 lout << sla.GetTime() << " - Tracking stopped." << endl; 439 lout << sla.GetTime() << " - Tracking stopped @ Zd="; 440 lout << fCosy->fZdAzSoll.Zd()*TMath::RadToDeg() <<"deg Az="; 441 lout << fCosy->fZdAzSoll.Az()*TMath::RadToDeg() <<"deg" << endl; 388 442 } 389 443 … … 401 455 lout << "- Tracking Thread started..." << endl; 402 456 457 const XY re2se = fCosy->kGearTot/fCosy->kResSE; //[re/se] 458 403 459 SlaStars sla(fCosy->fObservatory); 404 460 sla.Now(); 405 461 406 ZdAz old;407 ZdAz ist = fCosy->GetSePos(); // [se]408 409 462 ZdAz time; 410 463 411 ZdAz sollzd = sla.CalcZdAz(fCosy->fRaDec); // [rad] 412 ZdAz sollaz = sollzd; // [rad] 464 ZdAz soll = sla.CalcZdAz(fCosy->fRaDec); // [rad] 413 465 414 466 // … … 421 473 while (!HasStopFlag()) 422 474 { 423 //424 475 // Make changes (eg wind) smoother - attenuation of control function 425 //426 const float weight = 1.; //0.3;427 428 //429 476 // This is the time constant which defines how fast 430 477 // you correct for external influences (like wind) 431 // 432 *fCosy->fOutRep << "> ResetPosHasChanged" << endl; 478 const float weight = 1.; //0.3; 479 480 // Check for changes of the shaftencoder values 481 //*fCosy->fOutRep << "> ResetPosHasChanged" << endl; 433 482 fCosy->fZd1->ResetPosHasChanged(); 434 483 fCosy->fZd2->ResetPosHasChanged(); 435 484 fCosy->fAz->ResetPosHasChanged(); 436 *fCosy->fOutRep << "> Check for PosHasChanged" << endl;485 //*fCosy->fOutRep << "> Check for PosHasChanged" << endl; 437 486 do 438 487 { … … 443 492 } while (!phca1 && !phca2 && !phcaz && !HasStopFlag()); 444 493 445 //---usleep(100000); // 0.1s 446 447 *fCosy->fOutRep << "> Do Calculation" << endl; 448 449 // 450 // get position, where we are 451 // 452 old = ist; 453 ist = fCosy->GetSePos(); // [se] 454 455 // 456 // if the position didn't change continue 457 // 458 /*--- 459 if ((int)ist.Zd() == (int)old.Zd() && 460 (int)ist.Az() == (int)old.Az()) 461 continue; 462 */ 494 //*fCosy->fOutRep << "> Do Calculation" << endl; 495 496 // Get current position of motors (use last automatically sent 497 // position (PDO) - requesting the position results in problems 498 // with thread safty) 463 499 ZdAz istre = fCosy->GetRePosPdo(); 464 500 465 // 501 // get current position of shaftencoders 502 ZdAz istse = fCosy->GetSePos(); // [se] 503 466 504 // Get time from last shaftencoder position change (position: ist) 467 // FIXME: I cannot take the avarage 468 // 469 // FIXME 470 //time.Zd(fZd1->GetMjd()); 471 /* OLD* */ 505 // FIXME: Is this correct? 472 506 if (fCosy->fZd1->GetMjd()>fCosy->fZd2->GetMjd()) 473 507 time.Zd(fCosy->fZd1->GetMjd()); … … 475 509 time.Zd(fCosy->fZd2->GetMjd()); 476 510 477 //time.Zd((fZd1->GetMjd()+fZd2->GetMjd())/2.0);478 511 time.Az(fCosy->fAz->GetMjd()); 479 512 480 // 481 // if Shaftencoder changed position 482 // calculate were we should be 483 // 484 if (phca1 || phca2 /*(int)ist.Zd() != (int)old.Zd()*/) 485 { 486 sollzd = sla.CalcZdAz(fCosy->fRaDec, time.Zd()); // [rad] 487 /* 488 ZdAz dummy = fBending(sla.CalcZdAz(fRaDec)); 489 sollzd = CorrectTarget(ist, dummy); // [se] 490 */ 491 fCosy->fOffset.Zd(fCosy->fOffset.Zd()*(1.-weight)+(ist.Zd()*fCosy->kGearRatio.X()-istre.Zd())*weight); 513 // calculate offset for both axis (only one is needed) 514 const ZdAz offset = (istse*re2se - istre)*weight + fOffset*(weight-1); 515 516 // if Shaftencoder changed position, calculate nominal position 517 if (phca1 || phca2) 518 { 519 const ZdAz dummy = sla.CalcZdAz(fCosy->fRaDec, time.Zd()); 520 soll.Zd(dummy.Zd()); // [rad] 521 fOffset.Zd(offset.Zd()); 492 522 } 493 494 if (phcaz /*(int)ist.Az() != (int)old.Az()*/) 495 { 496 sollaz = sla.CalcZdAz(fCosy->fRaDec, time.Az()); // [rad] 497 /* 498 ZdAz dummy = fBending(sla.CalcZdAz(fRaDec)); 499 sollaz = CorrectTarget(ist, dummy); // [se] 500 */ 501 fCosy->fOffset.Az(fCosy->fOffset.Az()*(1.-weight)+(ist.Az()*fCosy->kGearRatio.Y()-istre.Az())*weight); 523 if (phcaz) 524 { 525 const ZdAz dummy = sla.CalcZdAz(fCosy->fRaDec, time.Az()); 526 soll.Az(dummy.Az()); // [rad] 527 fOffset.Az(offset.Az()); 502 528 } 503 529 504 ZdAz soll(sollzd.Zd(), sollaz.Az()); // [rad] 505 530 // After calculation of fOffset is done we need 'ist' in rad 531 istse /= fCosy->kResSE/TMath::TwoPi(); // [rad] 532 533 // Calculate the aligned tracking posotion from 'soll'-position 506 534 fCosy->fZdAzSoll = fCosy->AlignTrackingPos(soll); 507 535 508 ist *= TMath::Pi()*2/16384; 509 soll = fCosy->fBending(fCosy->fZdAzSoll); 510 fCosy->fTrackingError.Set(ist.Zd()-soll.Zd(), ist.Az()-soll.Az()); 511 512 //--- fout << setprecision(15) << setw(17) << time.Zd()*60.*60.*24. << " "; 513 //--- fout << setprecision(5) << setw(7) << fTrackingError.Zd() << " "; 514 //--- fout << setprecision(15) << setw(17) << time.Az()*60.*60.*24. << " "; 515 //--- fout << setprecision(5) << setw(7) << fTrackingError.Az() << endl; 536 /* --- OLD --- */ 537 //fCosy->fTrackingError = istse-fCosy->fBending(fCosy->fZdAzSoll); 538 /* --- NEW --- */ 539 fCosy->fTrackingError = fCosy->fBending.CorrectBack(istse)-fCosy->fZdAzSoll; 540 /* --- END --- */ 516 541 } 517 542 -
trunk/MagicSoft/Cosy/main/MTracking.h
r3935 r4076 1 1 #ifndef COSY_MTracking 2 2 #define COSY_MTracking 3 4 #include "coord.h" 3 5 4 6 #ifndef COSY_MPointing … … 10 12 #endif 11 13 14 class SlaStars; 15 12 16 class MTracking : public MPointing, public MThread 13 17 { … … 16 20 Float_t fTrackDec; 17 21 22 ZdAz fOffset; // Offset between se and re coordinate system [re] 23 24 MLog *fOut; 25 26 bool RequestRePos(); 18 27 bool SetVelocity(const ZdAz &v); 28 bool LimitSpeed(ZdAz *vt, const SlaStars &sla) const; 19 29 bool InitTracking(); 20 bool LimitSpeed(ZdAz *vt, const ZdAz &vcalc) const;30 //void StopTracking(); 21 31 22 32 void *Thread(); 23 33 24 34 public: 25 MTracking(MCosy *cosy, const Log &log) : MPointing(cosy, log), MThread(kFALSE), fTrackAcc(0.1), fTrackDec(0.1) { }35 MTracking(MCosy *cosy, const Log &log) : MPointing(cosy, log), MThread(kFALSE), fTrackAcc(0.1), fTrackDec(0.1), fOut(0) { } 26 36 27 37 void TrackPosition(const RaDec &dst); // ra, dec [rad] 28 38 void SetTrackAccDec(Float_t acc, Float_t dec) { fTrackAcc=0.1; fTrackDec=0.1; } 29 39 40 void SetOut(MLog *fout) { fOut = fout; } 30 41 //void TalkThreadTracking(); 31 42 -
trunk/MagicSoft/Cosy/starg.cc
r2278 r4076 1 #include <iostream.h> 2 1 3 #include <TROOT.h> 2 4 #include <TApplication.h> 3 5 4 #include <iostream.h>5 6 #include "Camera.h"7 #include "PngReader.h"8 6 #include "MStarguider.h" 9 7 … … 18 16 TApplication *app=new TApplication("Starguider", &argc, argv); 19 17 20 Bool_t dummy = kFALSE; 21 18 Int_t channel = 0; 22 19 for (int i=0; i<argc; i++) 23 20 { 24 21 TString arg(argv[i]); 25 22 if (arg=="-d") 26 dummy = kTRUE; 23 channel = -1; 24 if (arg=="-1") 25 channel = 1; 26 if (arg=="-0") 27 channel = 0; 27 28 } 28 29 29 PixClient *client=new MStarguider(MObservatory::kMagic1); 30 PixGetter *get; 31 32 if (dummy) 33 { 34 cout << " --> Starting in dummy-mode. <--" << endl; 35 get=new PngReader(*client); 36 } 37 else 38 { 39 cout << " --> Starting in real-mode. <--" << endl; 40 get = new Camera(*client); 41 ((Camera*)get)->Loop(0); 42 } 43 30 PixClient *client=new MStarguider(MObservatory::kMagic1, channel); 44 31 app->Run(kTRUE); 45 get->ExitLoop();46 47 delete get;48 32 delete client; 49 33 50 cout << "Application end...." << endl; 51 52 cout << "Exit." << endl; 53 34 cout << "Application end... Exit." << endl; 54 35 return 0; 55 36 } -
trunk/MagicSoft/Cosy/stars.txt
r2614 r4076 4 4 12 56 11 -05 47 22 3C279 (17.75) 5 5 12 54 02 55 57 35 Alioth (1.77) 6 00 08 23 29 05 26 Alpha Andromedae (2.1) 7 02 07 10 23 27 45 Alpha Aries (2.00) 8 00 40 31 56 32 14 Alpha Cassiopeiae (2.2) 9 21 18 35 62 35 08 Alpha Cephei (2.44) 10 15 34 56 26 42 53 Alpha CoronaBorealis (2.23) 11 09 27 35 -08 39 31 Alpha Hydrae (2.0) 12 17 34 56 12 33 36 Alpha Ophiuchi (2.08) 13 03 24 19 49 51 40 Alpha Persei (1.79) 14 11 03 44 61 45 03 Alpha UrsaMajoris (1.79) 6 15 00 08 24 29 05 26 Alpheratz (2.06) 7 16 19 50 47 08 52 06 Altair (0.77) … … 9 18 14 15 40 19 10 57 Arcturus (-0.04) 10 19 13 47 33 49 18 48 Benetnasch (1.86) 20 01 09 44 35 37 14 Beta Andromedae (2.1) 21 01 54 38 20 48 29 Beta Aries (2.6) 22 19 55 19 06 24 24 Beta Aquilae (3.7) 23 05 59 32 44 56 51 Beta Aurigae (1.9) 24 15 01 57 40 23 26 Beta Bootis (3.5) 25 00 09 11 59 08 59 Beta Cassiopeiae (2.3) 26 19 30 43 27 57 35 Beta1 Cygni (3.1) 27 16 30 13 21 29 23 Beta Herculi (2.77) 28 11 49 04 14 34 19 Beta Leonis (2.14) 29 15 17 00 -09 22 59 Beta Librae (2.61) 30 17 43 28 04 34 02 Beta Ophiuchi (2.77) 31 05 26 18 28 36 27 Beta Tauri (1.6) 32 14 50 42 74 09 20 Beta UrsaMinoris (2.1) 33 05 55 10 07 24 25 Betelgeuse (0.5) 11 34 22 02 43 42 16 40 BL-Lac (14.5) 12 35 05 15 41 45 59 53 Capella (0.08) … … 19 42 01 48 19 31 03 18 Dark Patch 4 20 43 20 41 26 45 16 49 Deneb (1.25) 44 19 25 30 03 06 53 Delta Aquilae (3.4) 45 01 25 49 60 14 07 Delta Cassiopeiae (2.7) 46 19 44 59 45 07 51 Delta Cygni (2.87) 21 47 11 03 44 61 45 03 Dubhe (1.79) 48 19 05 25 13 51 48 Epsilon Aquilae (2.99) 49 14 44 59 27 04 27 Epsilon Bootis (2.7) 50 20 46 13 33 58 13 Epsilon Cygni (2.46) 51 12 54 02 55 57 35 Epsilon UrsaMajoris (1.77) 52 13 02 11 10 57 33 Epsilon Virginis (2.8) 53 19 52 28 01 00 20 Eta Aquilae (3.9) 54 13 54 41 18 23 52 Eta Bootis (2.7) 55 19 56 19 35 05 00 Eta Cygni (3.89) 56 13 47 32 49 18 48 Eta UrsaMajoris (1.86) 57 22 57 39 -29 37 20 Formalhaut (1.16) 58 02 03 54 42 19 47 Gamma1 Andromedae (2.3) 59 19 46 15 10 36 48 Gamma Aquilae (2.7) 60 14 32 05 38 18 30 Gamma Bootis (3.0) 61 00 56 43 60 43 00 Gamma Cassiopeiae (2.5) 62 20 22 14 40 15 24 Gamma Cygni (2.20) 63 17 56 36 51 29 20 Gamma Draconis (2.2) 64 06 37 43 16 23 57 Gamma Gemini (1.9) 65 00 13 14 15 11 01 Gamma Pegasi (2.8) 66 03 04 48 53 30 23 Gamma Persei (2.9) 67 11 53 50 53 41 41 Gamma UrsaMajoris (2.4) 68 15 20 44 71 50 02 Gamma UrsaMinoris (3.0) 22 69 06 33 54 17 46 48 Geminga 70 19 30 42 51 43 47 Iota2 Cygni (3.8) 71 19 17 06 53 22 07 Kappa Cygni (3.9) 23 72 18 24 10 -34 23 05 Kaus Australis (1.85) 73 19 06 15 -04 52 57 Lambda Aquilae (3.4) 24 74 05 34 32 22 00 52 M1 (8.4) 25 75 13 23 56 54 55 31 Mizar A (2.23) … … 27 77 16 53 52 39 45 37 Markarian-501 28 78 02 31 49 89 15 51 Polaris (2.02) 79 07 45 19 28 01 34 Pollux (1.1) 80 07 39 18 05 13 30 Procyon (0.4) 29 81 17 34 56 12 33 36 Ras Alhague (2.08) 30 82 17 56 37 51 29 20 Rastaban (2.23) 83 10 08 22 11 58 02 Regulus (1.35) 31 84 17 45 12 -28 48 18 Sagittarius-A 32 85 18 55 16 -26 17 48 Sagittarius Sigma-34 (2.02) 33 86 00 40 31 56 32 14 Schedar (2.23) 87 06 45 09 -16 42 58 Sirius (-1.5) 34 88 15 02 22 -41 53 48 SN-1006 35 89 13 25 13 -11 09 41 Spica (0.98) 90 20 11 18 -00 49 17 Theta Aquilae (3.2) 36 91 17 37 19 -42 59 52 Theta Scorpionis (1.87) 37 92 18 36 56 38 47 01 Vega (0.03) 93 19 05 25 13 51 48 Zeta Aquilae (3.0) 94 16 41 17 31 36 11 Zeta Herculi (2.81) 38 95 05 37 39 21 08 33 Zeta Tauri (3.0) -
trunk/MagicSoft/Cosy/tcpip/MCeCoCom.cc
r2615 r4076 2 2 3 3 #include <iostream> 4 5 #include "MString.h" 4 6 5 7 using namespace std; … … 53 55 } 54 56 55 cout << "Zd/Az: " << zd << "/" << az << " ";56 cout << "Ra/Dec: " << ra << "/" << dec << " ";57 cout << "Temp: " << temp << "'C ";58 cout << "Hum: " << hum << "% ";59 cout << "SolRad: " << solar << "W/m² ";60 cout << "Wind: " << wind << "km/h" << endl;61 62 57 fHumidity = hum; 63 58 fTemperature = temp; 64 59 fSolarRadiation = solar; 65 60 fWindSpeed = wind; 61 62 cout << "Zd/Az: " << zd << "/" << az << " "; 63 cout << "Ra/Dec: " << ra/15 << "h/" << dec << " "; 64 cout << "SolRad: " << solar << "W/m²" << endl; 66 65 67 66 fComStat = kCmdReceived; … … 86 85 } 87 86 88 bool MCeCoCom::Send(const char * str)87 bool MCeCoCom::Send(const char *cmd, const char *str) 89 88 { 90 89 MTime t; … … 100 99 fT.GetTime(h2, m2, s2, ms2); 101 100 102 const char *msg =103 Form("%s "101 MString msg; 102 msg.Print("%s " 104 103 "%02d %04d %02d %02d %02d %02d %02d %03d " 105 104 "%02d %04d %02d %02d %02d %02d %02d %03d " 106 "%s\n", (const char*)fCommand,105 "%s\n", cmd, 107 106 fStatus, y1, mon1, d1, h1, m1, s1, ms1, 108 107 fComStat, y2, mon2, d2, h2, m2, s2, ms2, … … 113 112 return rc; 114 113 } 114 115 TString MCeCoCom::GetWeather() const 116 { 117 if (fSolarRadiation<0 || (double)MTime(-1)-(double)fT>11) 118 return ""; 119 120 MString str; 121 return str.Print("Temp: %.1f'C Hum: %.1f%% Wind: %.1fkm/h", 122 fTemperature, fHumidity, fWindSpeed); 123 } 124 125 Int_t MCeCoCom::GetWeatherStatus() const 126 { 127 if (fSolarRadiation<0 || (double)MTime(-1)-(double)fT>11) 128 return 0; 129 130 Int_t rc = 0; 131 if (fHumidity>80) 132 rc++; 133 if (fWindSpeed>20) 134 rc++; 135 if (fWindSpeed>30) 136 rc++; 137 if (fWindSpeed>50) 138 rc++; 139 140 return rc; 141 } -
trunk/MagicSoft/Cosy/tcpip/MCeCoCom.h
r2615 r4076 24 24 }; 25 25 26 TString fCommand; // report string of the current system26 //TString fCommand; // report string of the current system 27 27 MTime fT; // time of last report received 28 28 char fStatus; // current status of this system … … 43 43 public: 44 44 MCeCoCom::MCeCoCom(const char *cmd, MLog &out=gLog) 45 : MTcpIpIO(out), fCommand(cmd), fStatus(0), fComStat(kNoCmdReceived)45 : MTcpIpIO(out), /*fCommand(cmd),*/ fStatus(0), fComStat(kNoCmdReceived), fSolarRadiation(-1) 46 46 { 47 47 } 48 48 49 bool Send(const char * str);49 bool Send(const char *cmd, const char *str); 50 50 void SetStatus(Byte_t s) { fStatus=s; } 51 51 52 52 Float_t GetHumidity() const { return fHumidity; } 53 53 Float_t GetTemperature() const { return fTemperature; } 54 Float_t GetWindSpeed() const { return fWindSpeed; } 55 56 TString GetWeather() const; 57 Int_t GetWeatherStatus() const; 54 58 }; 55 59 -
trunk/MagicSoft/Cosy/tcpip/MDriveCom.cc
r2618 r4076 6 6 #include "MAstro.h" 7 7 #include "MCosy.h" 8 #include "MString.h" 8 9 9 10 using namespace std; … … 53 54 } 54 55 55 lout << "CC-COMMAND: Track " << ra << "h " << dec << "deg '" << str 56 << "'" << endl; 56 cout << "CC-COMMAND " << MTime(-1) << " RADEC " << ra << "h " << dec << "d '" << str << "'" << endl; 57 57 58 58 ra *= 15; // h -> deg … … 60 60 RaDec rd[2] = { RaDec(ra, dec), RaDec(ra, dec) }; 61 61 62 cout << "MDriveCom - TRACK... start." << endl;62 //cout << "MDriveCom - TRACK... start." << endl; 63 63 fQueue->PostMsg(WM_TRACK, &rd, sizeof(rd)); 64 cout << "MDriveCom - TRACK... done." << endl;64 //cout << "MDriveCom - TRACK... done." << endl; 65 65 return true; 66 66 } … … 81 81 } 82 82 83 lout << "CC-COMMAND: Move" << zd << "deg " << az << "deg" << endl;83 cout << "CC-COMMAND " << MTime(-1) << " ZDAZ " << zd << "deg " << az << "deg" << endl; 84 84 85 85 ZdAz za(zd, az); 86 86 87 cout << "MDriveCom - POSITION... start." << endl;87 //cout << "MDriveCom - POSITION... start." << endl; 88 88 fQueue->PostMsg(WM_POSITION, &za, sizeof(za)); 89 cout << "MDriveCom - POSITION... done." << endl;89 //cout << "MDriveCom - POSITION... done." << endl; 90 90 return true; 91 91 } … … 95 95 if (cmd==(TString)"WAIT" && str.IsNull()) 96 96 { 97 cout << "MDriveCom - WAIT... start." << endl; 97 //cout << "MDriveCom - WAIT... start." << endl; 98 cout << "CC-COMMAND " << MTime(-1) << " WAIT" << endl; 98 99 fQueue->PostMsg(WM_WAIT); 99 cout << "MDriveCom - WAIT... done." << endl;100 //cout << "MDriveCom - WAIT... done." << endl; 100 101 return true; 101 102 } … … 103 104 if (cmd==(TString)"STOP!" && str.IsNull()) 104 105 { 105 cout << "MDriveCom - STOP!... start." << endl;106 lout << "CC-COMMAND: STOP!" << endl;106 //cout << "MDriveCom - STOP!... start." << endl; 107 cout << "CC-COMMAND " << MTime(-1) << " STOP!" << endl; 107 108 fQueue->PostMsg(WM_STOP); 108 cout << "MDriveCom - STOP!... done." << endl;109 //cout << "MDriveCom - STOP!... done." << endl; 109 110 return true; 110 111 } … … 124 125 if (cmd.IsNull() && str.IsNull()) 125 126 { 126 cout << " Empty command (single '\\n') received." << endl;127 cout << "CC-COMMAND " << MTime(-1) << " Empty command (single '\\n') received." << endl; 127 128 return false; 128 129 } 129 130 130 cout << " Unknown Command: '" << cmd << "':'" << str << "'" << endl;131 cout << "CC-COMMAND " << MTime(-1) << " Syntax error: '" << cmd << "':'" << str << "'" << endl; 131 132 return false; 132 133 } … … 139 140 MAstro::Deg2Dms(deg, sgn, d, m, s); 140 141 141 str += Form("%c %03d %02d %03d ", sgn, d, m, s); 142 MString txt; 143 str += txt.Print("%c %03d %02d %03d ", sgn, d, m, s); 142 144 } 143 145 … … 148 150 // is [deg] 149 151 // er [rad] 152 const MTime t(-1); 150 153 151 154 rd *= kRad2Deg; … … 165 168 SetStatus(4); 166 169 167 MTime t; 168 t.Now(); 170 MString txt; 169 171 170 172 TString str; … … 172 174 Print(str, rd.Dec()); // Dec 173 175 Print(str, 0); // HA 174 str += Form("%12.6f ", t.GetMjd()); // mjd176 str += txt.Print("%12.6f ", t.GetMjd()); // mjd 175 177 Print(str, so.Zd()); 176 178 Print(str, so.Az()); 177 179 Print(str, is.Zd()); 178 180 Print(str, is.Az()); 179 str += Form("%08.3f ", er.Zd());180 str += Form("%08.3f", er.Az());181 str += txt.Print("%08.3f ", er.Zd()); 182 str += txt.Print("%08.3f", er.Az()); 181 183 182 return Send( str);184 return Send("DRIVE-REPORT", str); 183 185 } 186 187 bool MDriveCom::SendStatus(const char *stat) 188 { 189 return Send("DRIVE-STATUS", stat); 190 } -
trunk/MagicSoft/Cosy/tcpip/MDriveCom.h
r2517 r4076 37 37 38 38 bool SendReport(UInt_t stat, RaDec rd, ZdAz so, ZdAz is, ZdAz er); 39 bool SendStatus(const char *stat); 39 40 }; 40 41 -
trunk/MagicSoft/Cosy/tcpip/MTcpIpIO.cc
r2517 r4076 33 33 */ 34 34 35 MTcpIpIO::MTcpIpIO(MLog &out) : MThread(false), Log(out), fRxSocket(NULL), fServSock(NULL) 35 MTcpIpIO::MTcpIpIO(MLog &out) 36 : MThread(false), Log(out), fRxSocket(NULL), fServSock(NULL), fSendInterval(1000) 36 37 { 37 38 fTxSocket = new TSocket("ceco", 7304); … … 49 50 // Now delete all TCP/IP objects 50 51 // 51 cout << "Delete TxSocket " << fTxSocket << "..." << flush;52 //cout << "Delete TxSocket " << fTxSocket << "..." << flush; 52 53 delete fTxSocket; 53 cout << "Done." << endl;54 //cout << "Done." << endl; 54 55 if (fServSock) 55 56 { 56 cout << "Delete ServSock " << fServSock << "..." << flush;57 //cout << "Delete ServSock " << fServSock << "..." << flush; 57 58 delete fServSock; 58 cout << "Done." << endl;59 //cout << "Done." << endl; 59 60 } 60 61 if (fRxSocket) 61 62 { 62 cout << "Delete RxSocket " << fRxSocket << "..." << flush;63 //cout << "Delete RxSocket " << fRxSocket << "..." << flush; 63 64 delete fRxSocket; 64 cout << "Done." << endl;65 //cout << "Done." << endl; 65 66 } 66 67 } … … 68 69 bool MTcpIpIO::Send(const char *msg) 69 70 { 71 const MTime t(-1); 72 73 if ((double)t-(double)fTime<0.001*fSendInterval) 74 return true; 75 76 const Int_t rc = lout.IsOutputDeviceEnabled(MLog::eGui); 77 lout.DisableOutputDevice(MLog::eGui); 78 lout.Lock(); 79 lout << msg << flush; 80 lout.UnLock(); 81 if (rc) 82 lout.EnableOutputDevice(MLog::eGui); 83 84 fTime = t; 85 70 86 if (!fTxSocket->IsValid()) 71 87 return false; … … 112 128 switch (fServSock->GetErrorCode()) 113 129 { 114 case 0: cout << "No error." << endl; break;130 case 0: cout << "No error." << endl; break; 115 131 case -1: cout << "low level socket() call failed." << endl; break; 116 132 case -2: cout << "low level bind() call failed." << endl; break; -
trunk/MagicSoft/Cosy/tcpip/MTcpIpIO.h
r2384 r4076 7 7 #ifndef COSY_Log 8 8 #include "log.h" 9 #endif 10 #ifndef MARS_MTime 11 #include "MTime.h" 9 12 #endif 10 13 … … 19 22 TSocket *fRxSocket; 20 23 TServerSocket *fServSock; 24 25 MTime fTime; 26 Int_t fSendInterval; // [ms] 21 27 22 28 void Clear(); -
trunk/MagicSoft/Cosy/videodev/Camera.cc
r2518 r4076 17 17 inline int Camera::Ioctl(int req, void *opt, const char *str) 18 18 { 19 int rc = ioctl(fd, req, opt); 20 21 if (rc==-1) 22 { 23 cout << "Error! Ioctl " << req << ": "; 19 while (1) 20 { 21 const int rc = ioctl(fd, req, opt); 22 if (rc>=0) 23 return rc; 24 25 // errno== 4: Interrupted system call 26 // errno==16: Device or resource busy 27 if (errno==4 || errno==16) 28 { 29 cout << "Camera: ioctl returned rc=" << rc << " '"; 30 cout << (str?str:strerror(errno)) << "' (errno = " << errno << ")" << endl; 31 usleep(10); 32 continue; 33 } 34 35 cout << "Error! Ioctl " << hex << req << ": errno=" << dec << errno << " - "; 24 36 cout << (str?str:strerror(errno)) << " (rc=" << rc << ")" << endl; 25 }26 27 return rc;37 return rc; 38 } 39 return -1; 28 40 } 29 41 30 42 void Camera::Error(const char *str, int fatal) 31 43 { 32 cout << endl 33 << (fatal?"Fatal ":"") << "Error! " << str << ": " << strerror(errno)34 44 cout << endl; 45 cout << (fatal?"Fatal ":"") << "Error! " << str << ": " << strerror(errno); 46 cout << endl; 35 47 36 48 if (fatal) … … 39 51 void Camera::SigInit() 40 52 { 41 return; 42 struct sigaction act, old; 43 44 memset(&act, 0, sizeof(act)); 45 46 act.sa_handler = SigAlarm; 47 48 sigemptyset(&act. sa_mask); 49 sigaction(SIGALRM, &act, &old); 50 51 // signal(SIGINT, ctrlc); 53 /* 54 struct sigaction act, old; 55 56 memset(&act, 0, sizeof(act)); 57 58 act.sa_handler = SigAlarm; 59 60 sigemptyset(&act. sa_mask); 61 sigaction(SIGALRM, &act, &old); 62 63 // signal(SIGINT, ctrlc); 64 */ 52 65 } 53 66 … … 74 87 int Camera::StartGrab(unsigned int frame) 75 88 { 89 // We could also get RGB555, RGB565 and RGB32. But we want 90 // RGB24 because we have a 8bit DAC which gives us 8bit per 91 // color ==> RGB24 which is in the following the most simple 92 // to process. 76 93 static struct video_mmap gb = 77 94 { 78 0, 79 rows, cols, 80 VIDEO_PALETTE_RGB24 95 0, // frame 96 rows, cols, // height, width 97 VIDEO_PALETTE_RGB24 // palette 81 98 }; 82 99 … … 95 112 } 96 113 97 Camera::Camera(PixClient &client) : fd(-1), iBufferSize(0), fClient(client), fMutex(), fCond(&fMutex) 98 { 99 cout << "Starting thread..." << flush; 100 //pthread_cond_init(&fCond, NULL); 101 //pthread_mutex_init(&fMux, NULL); 102 //pthread_mutex_lock(&fMux); 103 fMutex.Lock(); 104 pthread_create(&fThread, NULL, MapThread, this); 105 cout << "done." << endl; 106 107 cout << "/dev/video: opening..." << flush; 114 Camera::Camera(PixClient &client, Int_t nch) : fd(-1), iBufferSize(0), fClient(client), fCond(), fMutex(fCond.GetMutex()) 115 { 116 cout << "Camera: " << this << " /dev/video: opening..." << flush; 108 117 109 118 // … … 126 135 // get input channel 0 information 127 136 // 137 128 138 struct video_channel ch; 129 ch.channel = 0;139 ch.channel = nch; 130 140 Ioctl(VIDIOCGCHAN, &ch); 131 141 … … 160 170 cout << "Buffer Size: " << (void*)iBufferSize << endl; 161 171 cout << "grab: use: 768x576 24 bit TrueColor (LE: bgr) = " << (void*)(768*576*3) << "b" << endl; 172 173 // if (fMutex->UnLock()==13) 174 // cout << "Camera::Camera - tried to unlock mutex locked by other thread." << endl; 175 176 cout << "Starting thread..." << flush; 177 //pthread_cond_init(&fCond, NULL); 178 //pthread_mutex_init(&fMux, NULL); 179 //pthread_mutex_lock(&fMux); 180 // if (fMutex->Lock()==13) 181 // cout << "Camera::Camera - mutex is already locked by this thread" << endl; 182 pthread_create(&fThread, NULL, MapThread, this); 183 cout << "done." << endl; 184 162 185 } 163 186 164 187 Camera::~Camera() 165 188 { 166 cout << "Stopping thread..." << flush;167 189 pthread_cancel(fThread); 168 //pthread_mutex_destroy(&fMux); 169 //pthread_cond_destroy(&fCond); 190 191 cout << "/dev/video: closing... " << flush; 192 if (fd != -1) 193 { 194 close(fd); 195 fd = -1; 196 } 170 197 cout << "done." << endl; 171 172 cout << "/dev/video: closing... " << flush;173 198 174 199 // unmap device memory 175 200 if ((int)pMapBuffer != -1) 176 201 munmap(pMapBuffer, iBufferSize); 177 178 if (fd != -1) 179 { 180 close(fd); 181 fd = -1; 182 } 183 184 cout << " Done." << endl; 185 } 186 202 } 187 203 188 204 void *Camera::MapThread(void *arg) … … 198 214 } 199 215 216 void Camera::ExitLoop() 217 { 218 // cout << "ExitLoop..." << endl; 219 fStop = 1; 220 while (IsRunning()) 221 usleep(1); 222 // cout << "Loop exited." << endl; 223 } 224 225 // 226 // flag if the execution is running or not 227 // 228 int Camera::IsRunning() const 229 { 230 const Int_t rc = fMutex->TryLock(); 231 if (rc==0) 232 return false; 233 234 if (rc==13) 235 return false; 236 237 fMutex->UnLock(); 238 return true; 239 } 240 200 241 void Camera::LoopStep(const unsigned long n) 201 242 { … … 217 258 { 218 259 #define IsOdd(i) (2*(i/2)!=i) 260 cout << "Camera::Thread started..." << endl; 219 261 while (1) 220 262 { 221 // pthread_cond_wait(&fCond, &fMux);263 //cout << "Wait..." << flush; 222 264 fCond.Wait(); 265 //cout << "done." << endl; 266 if (fd==-1) 267 break; 223 268 224 269 MStopwatch t; … … 259 304 t.Stop(); 260 305 t.Print(i); 261 262 fRunning = 0; 263 } 306 } 307 308 fMutex->UnLock(); 309 310 cout << "Camera::Thread.. stopped." << endl; 264 311 } 265 312 … … 272 319 } 273 320 274 // 275 // Stop running loop 276 // 277 fStop = 1; 278 279 // 280 // Wait until loop is stopped (pthread_cond_wait is executing) 281 // set new number of frames to process 282 // 283 fMutex.Lock(); 284 //pthread_mutex_lock(&fMux); 285 fNum = nof; 286 fStop = 0; 287 fRunning = 1; 288 fMutex.UnLock(); 289 //pthread_mutex_unlock(&fMux); 321 cout << "Loop..." << endl; 322 ExitLoop(); 323 324 fNum = nof; 325 fStop = 0; 290 326 291 327 // … … 293 329 // 294 330 fCond.Broadcast(); 295 //pthread_cond_signal(&fCond);296 331 } 297 332 -
trunk/MagicSoft/Cosy/videodev/Camera.h
r2518 r4076 45 45 46 46 int fStop; 47 int fRunning;47 // int fRunning; 48 48 49 49 char fImg[cols*rows]; … … 53 53 54 54 pthread_t fThread; 55 TMutex fMutex;56 55 TCondition fCond; 56 TMutex *fMutex; 57 57 //pthread_mutex_t fMux; 58 58 //pthread_cond_t fCond; … … 81 81 82 82 public: 83 Camera(PixClient &client );83 Camera(PixClient &client, Int_t ch=0); 84 84 virtual ~Camera(); 85 85 … … 88 88 // 89 89 void Loop(const unsigned long nof=0); 90 void ExitLoop() 91 { 92 fStop = 1; 93 while (IsRunning()) 94 usleep(1); 95 } 96 97 // 98 // flag if the execution is running or not 99 // 100 int IsRunning() const { return fRunning; } 90 void ExitLoop(); 91 int IsRunning() const; 101 92 102 93 // -
trunk/MagicSoft/Cosy/videodev/FilterLed.cc
r2278 r4076 15 15 return; 16 16 17 for (int dx=-(int)(rpix*0.7); dx<(int)(rpix*0.7); dx+ +)17 for (int dx=-(int)(rpix*0.7); dx<(int)(rpix*0.7); dx+=2) 18 18 { 19 19 const int dy = (int)sqrt(rpix*rpix-dx*dx); … … 64 64 DrawBox(x+5, y, x+8, y, m); 65 65 DrawBox(x, y-8, x, y-5, m); 66 return;67 66 } 68 67 … … 76 75 77 76 // 78 // calculate mean value 77 // calculate mean value (speed optimized) 79 78 // 80 79 while (s<e0) … … 104 103 105 104 int FilterLed::GetMeanPosition(const int x, const int y, 106 const int box, float &mx, float &my ) const105 const int box, float &mx, float &my, unsigned int &sum) const 107 106 { 108 107 unsigned int sumx=0; 109 108 unsigned int sumy=0; 110 unsigned int sum =0; 111 109 110 sum=0; 112 111 for (int dx=x-box; dx<x+box+1; dx++) 113 112 for (int dy=y-box; dy<y+box+1; dy++) … … 129 128 { 130 129 float mx, my; 131 return GetMeanPosition(x, y, box, mx, my); 130 unsigned int sum; 131 return GetMeanPosition(x, y, box, mx, my, sum); 132 132 } 133 133 /* … … 252 252 void FilterLed::Execute(Leds &leds, int xc, int yc) const 253 253 { 254 int x0 = xc-fBox W;255 int x1 = xc+fBox W;256 int y0 = yc-fBox H;257 int y1 = yc+fBox H;254 int x0 = xc-fBox; 255 int x1 = xc+fBox; 256 int y0 = yc-fBox; 257 int y1 = yc+fBox; 258 258 259 259 if (x0<0) x0=0; … … 280 280 sq /= wx*hy; 281 281 282 // 254 because b<=max and not b<max 282 283 const double sdev = sqrt(sq-sum*sum); 283 284 const byte max = sum+fCut*sdev>254 ? 254 : (byte)(sum+fCut*sdev); … … 348 349 349 350 Float_t mx, my; 350 GetMeanPosition(pos[i]%fW, pos[i]/fW, 5, mx, my); 351 unsigned int sum; 352 GetMeanPosition(pos[i]%fW, pos[i]/fW, 5, mx, my, sum); 351 353 352 354 leds.Add(mx, my, 0, 0, mag[i]); … … 354 356 355 357 RemoveTwinsInterpol(leds, first, 5); 358 } 359 360 void FilterLed::FindStar(Leds &leds, int xc, int yc) const 361 { 362 // fBox: radius of the inner (signal) box 363 // Radius of the outer box is fBox*sqrt(2) 364 365 // 366 // Define inner box in which to search the signal 367 // 368 int x0 = xc-fBox; 369 int x1 = xc+fBox; 370 int y0 = yc-fBox; 371 int y1 = yc+fBox; 372 373 if (x0<0) x0=0; 374 if (y0<0) y0=0; 375 if (x1>fW) x1=fW; 376 if (y1>fH) y1=fH; 377 378 // 379 // Define outer box (excluding inner box) having almost 380 // the same nuymber of pixels in which the background 381 // is calculated 382 // 383 const double sqrt2 = sqrt(2.); 384 385 int xa = xc-(int)rint(fBox*sqrt2); 386 int xb = xc+(int)rint(fBox*sqrt2); 387 int ya = yc-(int)rint(fBox*sqrt2); 388 int yb = yc+(int)rint(fBox*sqrt2); 389 390 if (xa<0) xa=0; 391 if (ya<0) ya=0; 392 if (xb>fW) xb=fW; 393 if (yb>fH) yb=fH; 394 395 // 396 // Calculate average and sdev for a square 397 // excluding the inner part were we expect 398 // the signal to be. 399 // 400 double sum = 0; 401 double sq = 0; 402 403 int n=0; 404 for (int x=xa; x<xb+1; x++) 405 for (int y=ya; y<yb+1; y++) 406 { 407 if (x>x0 && x<x1 && y>y0 && y<y1) 408 continue; 409 410 byte &b = fImg[y*fW+x]; 411 412 sum += b; 413 sq += b*b; 414 n++; 415 } 416 417 sum /= n; 418 sq /= n; 419 420 // 254 because b<=max and not b<max 421 const double sdev = sqrt(sq-sum*sum); 422 const byte max = sum+fCut*sdev>254 ? 254 : (byte)(sum+fCut*sdev); 423 424 // 425 // clean image from noise 426 // (FIXME: A lookup table could accelerate things... 427 // 428 n=0; 429 for (int x=x0; x<x1; x++) 430 for (int y=y0; y<y1; y++) 431 { 432 byte &b = fImg[y*fW+x]; 433 if (b<=max) 434 b = 0; 435 else 436 n++; 437 } 438 439 // 440 // Mark the background region 441 // 442 for (int x=xa; x<xb+1; x+=2) 443 { 444 fImg[ya*fW+x]=0xf0; 445 fImg[yb*fW+x]=0xf0; 446 } 447 for (int y=ya; y<yb+1; y+=2) 448 { 449 fImg[y*fW+xa]=0xf0; 450 fImg[y*fW+xb]=0xf0; 451 } 452 453 // 454 // Check if any pixel found... 455 // 456 if (n<5) 457 return; 458 459 // 460 // Get the mean position of the star 461 // 462 float mx, my; 463 unsigned int mag; 464 int pos = GetMeanPosition(xc, yc, fBox-1, mx, my, mag); 465 466 if (pos<0 || pos>=fW*fH && fImg[pos]<sum+fCut*sdev) 467 return; 468 469 cout << "Mean=" << sum << " SDev=" << sdev << " : "; 470 cout << "Sum/n = " << sum << "/" << n << " = " << (n==0?0:mag/n) << endl; 471 472 leds.Add(mx, my, 0, 0, -2.5*log10((float)mag)+13.7); 356 473 } 357 474 -
trunk/MagicSoft/Cosy/videodev/FilterLed.h
r2278 r4076 17 17 int fW; 18 18 int fH; 19 int fBoxW; 20 int fBoxH; 19 int fBox; 21 20 float fCut; 22 21 23 22 void GetMinMax(const int offset, byte *min, byte *max) const; 24 23 int GetMeanPosition(const int x, const int y, const int box) const; 25 int GetMeanPosition(const int x, const int y, const int box, float &mx, float &my ) const;24 int GetMeanPosition(const int x, const int y, const int box, float &mx, float &my, unsigned int &sum) const; 26 25 void RemoveTwinsInterpol(Leds &leds, Int_t first, Double_t radius) const; 27 26 void DrawBox(const int x1, const int y1, … … 31 30 public: 32 31 FilterLed(byte *img, int w, int h, double cut=2.5) 33 : fImg(img), fW(w), fH(h), fBox W(w/2), fBoxH(h/2), fCut(cut)32 : fImg(img), fW(w), fH(h), fBox(w>h?w:h), fCut(cut) 34 33 { 35 34 } 36 35 37 36 FilterLed(byte *img, int w, int h, int box, double cut=2.5) 38 : fImg(img), fW(w), fH(h), fBox W(box), fBoxH(box), fCut(cut)37 : fImg(img), fW(w), fH(h), fBox(box), fCut(cut) 39 38 { 40 39 } 41 40 42 FilterLed(byte *img, int w, int h, int boxw, int boxh, double cut=2.5)43 : fImg(img), fW(w), fH(h), fBoxW(boxw), fBoxH(boxh), fCut(cut)44 { 45 }41 void SetBox(int box) { fBox = box; } 42 void SetCut(float cut) { fCut = cut; } 43 44 void FindStar(Leds &leds, int xc, int yc) const; 46 45 47 46 void Execute(Leds &leds, int xc, int yc) const; … … 55 54 void Stretch() const; 56 55 void DrawCircle(float cx, float cy, float r, byte col=0x40) const; 57 void DrawCircle(float r, byte col=0x40) const { DrawCircle( r, fW/2.+.5, fH/2.+.5, col); }56 void DrawCircle(float r, byte col=0x40) const { DrawCircle(fW/2, fH/2, r, col); } 58 57 void DrawCircle(const Ring &c, byte col=0x40) const; 59 58 void DrawCircle(const Ring &c, double r, byte col) const; -
trunk/MagicSoft/Cosy/videodev/PixGetter.h
r2278 r4076 5 5 { 6 6 public: 7 virtual ~PixGetter() { } 7 8 virtual void ExitLoop() {} 8 9 };
Note:
See TracChangeset
for help on using the changeset viewer.