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

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