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

Last change on this file since 8864 was 8862, checked in by tbretz, 17 years ago
*** empty log message ***
File size: 5.3 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;
54class MEnv;
55
56class MTTalk : public MThread
57{
58private:
59 MCosy *fCosy;
60
61 Int_t Thread();
62
63public:
64 MTTalk(MCosy *cosy) : MThread("MTTalk"), fCosy(cosy)
65 {
66 RunThread();
67 }
68 ~MTTalk();
69};
70
71class TTimer;
72class MCosy : public Network, public MsgQueue, public TObject
73{
74 friend class MTTalk;
75 friend class MSlewing;
76 friend class MTracking;
77
78private:
79 const MObservatory::LocationName_t fObservatory;
80
81 MStarguider *fStarguider;
82
83 ShaftEncoder *fZd1;
84 ShaftEncoder *fZd2;
85 ShaftEncoder *fAz;
86
87 Macs *fMac1;
88 Macs *fMac2;
89 Macs *fMac3;
90
91 MGCosy *fWin;
92 MDriveCom *fCom;
93
94 TTimer *fUpdateGui;
95 MTTalk *fTTalk; // should be outsourced, like the starguider.
96 // with a generic interface to both...
97 ZdAz fTrackingPos; // [deg] Current tracking position
98 ZdAz fTrackingPosRaw; // [deg] Raw tracking position
99
100 TMutex fMutexGui;
101
102 enum BackgroundAction_t
103 {
104 kBgdNone,
105 //kBgdTracking,
106 kBgdSeTest,
107 kBgdSeTestDispl,
108 kBgdGear,
109 kBgdGearDispl
110 };
111
112 BackgroundAction_t fBackground; // Flag for present backgroundthread
113
114 ZdAz fTrackingError; // [rad] Tracking Offset between SE and calc-pos
115 ZdAz fZdAzSoll; // [rad] Soll position when moving
116 RaDec fRaDec; // Position to track
117 ZdAz fAccuracy; // Actual accuracy of Tracking
118 ZdAz fVelocity; // Actual velocity of Tracking
119 ZdAz fMin;
120 ZdAz fMax;
121
122 TH1 *fHist;
123 Bool_t fTriggerDisplay;
124
125 XY kResSE; // describing the resolution of the system [se/U_tel]
126 XY kResRE; // describing the resolution of the system [re/U_mot]
127 XY kGear; // describing the resolution of the system [U_mot/U_tel]
128 XY kGearTot; // describing the resolution of the system [re/U_tel]
129
130 MPointing fBending;
131
132 UInt_t fStatus;
133
134 ofstream *fOutTp;
135 MLog *fOutRep;
136
137 ZdAz AlignTrackingPos(ZdAz pointing) const;
138 Bool_t CheckRange(const ZdAz &d) const;
139 Double_t Starguider(Double_t mjd, ZdAz &dest) const;
140
141 void SetStatus(UInt_t stat) { fStatus = stat; }
142 UInt_t GetStatus() const { return fStatus; }
143
144 ZdAz GetRePos();
145 ZdAz GetRePosPdo();
146 ZdAz GetSePos() const; // [se]
147 // FIXME: Must depend on the Shaftencoder mounted
148 ZdAz GetSePosRad() const { return GetSePos()*TMath::TwoPi()/16384; } // [rad]
149
150 void InitSync();
151
152 void TalkThread();
153 void TalkThreadSeTest();
154 void TalkThreadGear();
155
156 void DisplayHistTestSe(Bool_t del=kTRUE);
157 void DisplayHistGear(Bool_t del=kTRUE);
158
159 int SetPosition(const ZdAz &dst, Bool_t track=kFALSE);
160 void TrackPosition(const RaDec &dst); // ra, dec [rad]
161 void TrackPositionGRB(const RaDec &dst); // ra, dec [rad]
162
163 void TerminateApp();
164
165 int StopWaitingForSDO() const;
166 void CheckForError();
167
168 void StopMovement();
169
170 void WaitForEndMovement();
171
172 void Constructor(Int_t id1, Int_t id2, Int_t id3, Int_t id4, Int_t id5, Int_t id6);
173 //void ConstructorSE(Int_t id1, Int_t id2, Int_t id3);
174 //void ConstructorDemo();
175
176 void ReadConfig(MEnv &env);
177
178 bool CheckNetwork();
179
180 void Start() { }
181
182public:
183 MCosy(MEnv &env, const char *addr, const char *pointing);
184 ~MCosy();
185
186 void Start(MEnv &env);
187 void Stop();
188
189 Int_t Proc(int msg, void *mp);
190
191 Bool_t HandleTimer(TTimer *t);
192
193 ZdAz GetPointingPos(void) const;
194 void SetStarguider(MStarguider *s) { fStarguider = s; }
195
196 static TString GetFileName(const char *path, const char *name, const char *ext);
197
198 MGCosy *GetWin() { return fWin; }
199
200 ZdAz GetTrackingPosDeg() const { return fTrackingPos; };
201 ZdAz GetTrackingPosRaw() const { return fTrackingPosRaw; };
202 void SetTrackingPosRE(ZdAz za);
203
204 AltAz GetAltAzDeg() const
205 {
206 ZdAz sepos = GetSePos()*TMath::TwoPi()/kResSE;
207 AltAz za1(TMath::Pi()/2-sepos.Zd(), sepos.Az());
208 za1 *= kRad2Deg;
209 return za1;
210 }
211
212 MLog *GetOutRep() { return fOutRep; }
213
214 //rwagner
215 MDriveCom *GetDriveCom() { return fCom; }
216
217 // static ZdAz CorrectTarget(const ZdAz &src, const ZdAz &dst);
218 // static ZdAz RaDec2ZdAz(const double mjd, const RaDec &pos, const RaDec &pm=RaDec(0,0));
219
220 ClassDef(MCosy, 0)
221};
222
223#endif
Note: See TracBrowser for help on using the repository browser.