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

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