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

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