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

Last change on this file since 5999 was 4865, checked in by rwagner, 20 years ago
*** empty log message ***
File size: 5.1 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() { std::cout << "~MTTalk::MTTalk" << std::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 ZdAz fTrackingPosRaw; // [deg] Raw tracking position
93
94 TMutex fMutexGui;
95
96 enum BackgroundAction_t
97 {
98 kBgdNone,
99 //kBgdTracking,
100 kBgdSeTest,
101 kBgdSeTestDispl,
102 kBgdGear,
103 kBgdGearDispl
104 };
105
106 BackgroundAction_t fBackground; // Flag for present backgroundthread
107
108 ZdAz fTrackingError; // [rad] Tracking Offset between SE and calc-pos
109 ZdAz fZdAzSoll; // [rad] Soll position when moving
110 RaDec fRaDec; // Position to track
111 ZdAz fAccuracy; // Actual accuracy of Tracking
112 ZdAz fVelocity; // Actual velocity of Tracking
113 ZdAz fMin;
114 ZdAz fMax;
115
116 TH1 *fHist;
117 Bool_t fTriggerDisplay;
118
119 XY kResSE; // describing the resolution of the system [se/U_tel]
120 XY kResRE; // describing the resolution of the system [re/U_mot]
121 XY kGear; // describing the resolution of the system [U_mot/U_tel]
122 XY kGearTot; // describing the resolution of the system [re/U_tel]
123
124 MBending fBending;
125
126 UInt_t fStatus;
127
128 ofstream *fOutTp;
129 MLog *fOutRep;
130
131 ZdAz AlignTrackingPos(ZdAz pointing) const;
132 Bool_t CheckRange(const ZdAz &d) const;
133 Double_t Starguider(Double_t mjd, ZdAz &dest) const;
134
135 void SetStatus(UInt_t stat) { fStatus = stat; }
136 UInt_t GetStatus() const { return fStatus; }
137
138 ZdAz GetRePos();
139 ZdAz GetRePosPdo();
140 ZdAz GetSePos() const; // [se]
141 // FIXME: Must depend on the Shaftencoder mounted
142 ZdAz GetSePosRad() const { return GetSePos()*TMath::TwoPi()/16384; } // [rad]
143
144 void InitSync();
145
146 void TalkThread();
147 void TalkThreadSeTest();
148 void TalkThreadGear();
149
150 void DisplayHistTestSe(Bool_t del=kTRUE);
151 void DisplayHistGear(Bool_t del=kTRUE);
152
153 int SetPosition(const ZdAz &dst, Bool_t track=kFALSE);
154 void TrackPosition(const RaDec &dst); // ra, dec [rad]
155
156 void TerminateApp();
157
158 int StopWaitingForSDO() const;
159 void CheckForError();
160
161 void StopMovement();
162
163 void WaitForEndMovement();
164
165 void Constructor(Int_t id1, Int_t id2, Int_t id3, Int_t id4, Int_t id5, Int_t id6);
166 //void ConstructorSE(Int_t id1, Int_t id2, Int_t id3);
167 //void ConstructorDemo();
168
169 void ReadConfig();
170
171 bool CheckNetwork();
172
173public:
174 MCosy(/*int mode,*/ const char *dev, const int baud, MLog &out=gLog);
175 ~MCosy();
176
177 void Start();
178 void Stop();
179
180 void *Proc(int msg, void *mp);
181
182 Bool_t HandleTimer(TTimer *t);
183
184 ZdAz GetPointingPos(void) const;
185 void SetStarguider(MStarguider *s) { fStarguider = s; }
186
187 static TString GetFileName(const char *name);
188
189 MGCosy *GetWin() { return fWin; }
190
191 ZdAz GetTrackingPosDeg() const { return fTrackingPos; };
192 ZdAz GetTrackingPosRaw() const { return fTrackingPosRaw; };
193 void SetTrackingPosRE(ZdAz za);
194
195 AltAz GetAltAzDeg() const
196 {
197 ZdAz sepos = GetSePos()*TMath::TwoPi()/kResSE;
198 AltAz za1(TMath::Pi()/2-sepos.Zd(), sepos.Az());
199 za1 *= kRad2Deg;
200 return za1;
201 }
202
203 MLog *GetOutRep() { return fOutRep; }
204
205 //rwagner
206 MDriveCom *GetDriveCom() { return fCom; }
207
208 // static ZdAz CorrectTarget(const ZdAz &src, const ZdAz &dst);
209 // static ZdAz RaDec2ZdAz(const double mjd, const RaDec &pos, const RaDec &pm=RaDec(0,0));
210
211 ClassDef(MCosy, 0)
212};
213
214#endif
Note: See TracBrowser for help on using the repository browser.