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

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