source: trunk/MagicSoft/Cosy/main/MCosy.h@ 4096

Last change on this file since 4096 was 4076, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 4.7 KB
Line 
1#ifndef MCOSY_H
2#define MCOSY_H
3
4#include "coord.h"
5#include "msgqueue.h"
6#include "network.h"
7#include "MThread.h"
8#include "MBending.h"
9
10#ifndef MARS_MObservatory
11#include "MObservatory.h"
12#endif
13#ifndef ROOT_TMutex
14#include <TMutex.h>
15#endif
16
17#define kDEG ((char)0x9c) // Linux 'ø'
18
19#define WM_WAIT WM_NULL
20//#define WM_PRESET 0x1000
21#define WM_POSITION 0x1001
22#define WM_TRACK 0x1002
23#define WM_STOP 0x1003
24//#define WM_CALIB 0x1004
25#define WM_TPOINT 0x1005
26#define WM_NEWTRACK 0x1006
27#define WM_LOADBENDING 0x1007
28#define WM_RESETBENDING 0x1008
29#define WM_CALCALTAZ 0x1009
30#define WM_HOME 0x100a
31#define WM_TESTSE 0x100b
32#define WM_GEAR 0x100c
33#define WM_DISPLAY 0x100d
34#define WM_TRACKPOS 0x100e
35#define WM_POSITION1 0x100f
36#define WM_ENDSWITCH 0x1010
37
38class ShaftEncoder;
39class Macs;
40class MGCosy;
41class MCosy;
42class TH1;
43class MStarguider;
44class MDriveCom;
45
46class MTTalk : public MThread
47{
48private:
49 MCosy *fCosy;
50
51 void *Thread();
52
53public:
54 MTTalk(MCosy *cosy) : MThread(false), fCosy(cosy)
55 {
56 SetPriority(10);
57 Detach();
58 Start();
59 }
60 ~MTTalk() { cout << "~MTTalk::MTTalk" << endl; }
61};
62
63class TTimer;
64class MCosy : public Network, public MsgQueue, public TObject
65{
66 friend class MTTalk;
67 friend class MPointing;
68 friend class MTracking;
69
70private:
71 const MObservatory::LocationName_t fObservatory;
72
73 MStarguider *fStarguider;
74
75 ShaftEncoder *fZd1;
76 ShaftEncoder *fZd2;
77 ShaftEncoder *fAz;
78
79 Macs *fMac1;
80 Macs *fMac2;
81 Macs *fMac3;
82
83 MGCosy *fWin;
84 MDriveCom *fCom;
85
86 TTimer *fUpdateGui;
87 MTTalk *fTTalk; // should be outsourced, like the starguider.
88 // with a generic interface to both...
89
90 TMutex fMutexGui;
91
92 enum BackgroundAction_t
93 {
94 kBgdNone,
95 //kBgdTracking,
96 kBgdSeTest,
97 kBgdSeTestDispl,
98 kBgdGear,
99 kBgdGearDispl
100 };
101
102 BackgroundAction_t fBackground; // Flag for present backgroundthread
103
104 ZdAz fTrackingError; // [rad] Tracking Offset between SE and calc-pos
105 ZdAz fZdAzSoll; // [rad] Soll position when moving
106 RaDec fRaDec; // Position to track
107 ZdAz fAccuracy; // Actual accuracy of Tracking
108 ZdAz fVelocity; // Actual velocity of Tracking
109 ZdAz fMin;
110 ZdAz fMax;
111
112 TH1 *fHist;
113 Bool_t fTriggerDisplay;
114
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]
119
120 MBending fBending;
121
122 UInt_t fStatus;
123
124 ofstream *fOutTp;
125 MLog *fOutRep;
126
127 ZdAz AlignTrackingPos(ZdAz pointing) const;
128 Bool_t CheckRange(const ZdAz &d) const;
129 Double_t Starguider(Double_t mjd, ZdAz &dest) const;
130
131 void SetStatus(UInt_t stat) { fStatus = stat; }
132 UInt_t GetStatus() const { return fStatus; }
133
134 ZdAz GetRePos();
135 ZdAz GetRePosPdo();
136 ZdAz GetSePos() const; // [se]
137 // FIXME: Must depend on the Shaftencoder mounted
138 ZdAz GetSePosRad() const { return GetSePos()*TMath::TwoPi()/16384; } // [rad]
139
140 void InitSync();
141
142 void TalkThread();
143 void TalkThreadSeTest();
144 void TalkThreadGear();
145
146 void DisplayHistTestSe(Bool_t del=kTRUE);
147 void DisplayHistGear(Bool_t del=kTRUE);
148
149 int SetPosition(const ZdAz &dst, Bool_t track=kFALSE);
150 void TrackPosition(const RaDec &dst); // ra, dec [rad]
151
152 void TerminateApp();
153
154 int StopWaitingForSDO() const;
155 void CheckForError();
156
157 void StopMovement();
158
159 void WaitForEndMovement();
160
161 void Constructor(Int_t id1, Int_t id2, Int_t id3, Int_t id4, Int_t id5, Int_t id6);
162 //void ConstructorSE(Int_t id1, Int_t id2, Int_t id3);
163 //void ConstructorDemo();
164
165 void ReadConfig();
166
167 bool CheckNetwork();
168
169public:
170 MCosy(/*int mode,*/ const char *dev, const int baud, MLog &out=gLog);
171 ~MCosy();
172
173 void Start();
174 void Stop();
175
176 void *Proc(int msg, void *mp);
177
178 Bool_t HandleTimer(TTimer *t);
179
180 ZdAz GetPointingPos(void) const;
181 void SetStarguider(MStarguider *s) { fStarguider = s; }
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
195 // static ZdAz CorrectTarget(const ZdAz &src, const ZdAz &dst);
196 // static ZdAz RaDec2ZdAz(const double mjd, const RaDec &pos, const RaDec &pm=RaDec(0,0));
197
198 ClassDef(MCosy, 0)
199};
200
201#endif
Note: See TracBrowser for help on using the repository browser.