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

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