| 1 | #ifndef MCOSY_H
|
|---|
| 2 | #define MCOSY_H
|
|---|
| 3 |
|
|---|
| 4 | #include "coord.h"
|
|---|
| 5 | #include "msgqueue.h"
|
|---|
| 6 | #include "network.h"
|
|---|
| 7 | #include "MThread.h"
|
|---|
| 8 | #include "MBending.h"
|
|---|
| 9 |
|
|---|
| 10 | #ifndef MARS_Mobservatory
|
|---|
| 11 | #include "MObservatory.h"
|
|---|
| 12 | #endif
|
|---|
| 13 |
|
|---|
| 14 | #define kDEG ((char)0x9c) // Linux 'ø'
|
|---|
| 15 |
|
|---|
| 16 | #define WM_WAIT WM_NULL
|
|---|
| 17 | //#define WM_PRESET 0x1000
|
|---|
| 18 | #define WM_POSITION 0x1001
|
|---|
| 19 | #define WM_TRACK 0x1002
|
|---|
| 20 | #define WM_STOP 0x1003
|
|---|
| 21 | //#define WM_CALIB 0x1004
|
|---|
| 22 | #define WM_TPOINT 0x1005
|
|---|
| 23 | #define WM_NEWTRACK 0x1006
|
|---|
| 24 | #define WM_LOADBENDING 0x1007
|
|---|
| 25 | #define WM_RESETBENDING 0x1008
|
|---|
| 26 | #define WM_CALCALTAZ 0x1009
|
|---|
| 27 | #define WM_HOME 0x100a
|
|---|
| 28 | #define WM_TESTSE 0x100b
|
|---|
| 29 | #define WM_GEAR 0x100c
|
|---|
| 30 | #define WM_DISPLAY 0x100d
|
|---|
| 31 | #define WM_TRACKPOS 0x100e
|
|---|
| 32 |
|
|---|
| 33 | class ShaftEncoder;
|
|---|
| 34 | class Macs;
|
|---|
| 35 | class MGCosy;
|
|---|
| 36 | class MCosy;
|
|---|
| 37 | class TH1;
|
|---|
| 38 | class MStarguider;
|
|---|
| 39 |
|
|---|
| 40 | class MTTalk : public MThread
|
|---|
| 41 | {
|
|---|
| 42 | private:
|
|---|
| 43 | MCosy *fCosy;
|
|---|
| 44 |
|
|---|
| 45 | void *Thread();
|
|---|
| 46 |
|
|---|
| 47 | public:
|
|---|
| 48 | MTTalk(MCosy *cosy) : MThread(false), fCosy(cosy)
|
|---|
| 49 | {
|
|---|
| 50 | SetPriority(10);
|
|---|
| 51 | Detach();
|
|---|
| 52 | Start();
|
|---|
| 53 | }
|
|---|
| 54 | ~MTTalk() { cout << "~MTTalk::MTTalk" << endl; }
|
|---|
| 55 | };
|
|---|
| 56 |
|
|---|
| 57 | class TTimer;
|
|---|
| 58 | class MCosy : public Network, public MsgQueue, public TObject
|
|---|
| 59 | {
|
|---|
| 60 | friend class MTTalk;
|
|---|
| 61 |
|
|---|
| 62 | private:
|
|---|
| 63 | enum
|
|---|
| 64 | {
|
|---|
| 65 | kError = 0x01,
|
|---|
| 66 | kMoving = 0x02,
|
|---|
| 67 | kTracking = 0x04,
|
|---|
| 68 | kStopping = 0x08,
|
|---|
| 69 | kStopped = 0x10
|
|---|
| 70 | };
|
|---|
| 71 |
|
|---|
| 72 | const MObservatory::LocationName_t fObservatory;
|
|---|
| 73 |
|
|---|
| 74 | MStarguider *fStarguider;
|
|---|
| 75 |
|
|---|
| 76 | ShaftEncoder *fZd1;
|
|---|
| 77 | ShaftEncoder *fZd2;
|
|---|
| 78 | ShaftEncoder *fAz;
|
|---|
| 79 |
|
|---|
| 80 | Macs *fMac1;
|
|---|
| 81 | Macs *fMac2;
|
|---|
| 82 | Macs *fMac3;
|
|---|
| 83 |
|
|---|
| 84 | MGCosy *fWin;
|
|---|
| 85 |
|
|---|
| 86 | TTimer *fUpdateGui;
|
|---|
| 87 | MTTalk *fTTalk; // should be outsourced, like the starguider.
|
|---|
| 88 | // with a generic interface to both...
|
|---|
| 89 |
|
|---|
| 90 | enum BackgroundAction_t
|
|---|
| 91 | {
|
|---|
| 92 | kBgdNone,
|
|---|
| 93 | kBgdTracking,
|
|---|
| 94 | kBgdSeTest,
|
|---|
| 95 | kBgdSeTestDispl,
|
|---|
| 96 | kBgdGear,
|
|---|
| 97 | kBgdGearDispl
|
|---|
| 98 | };
|
|---|
| 99 |
|
|---|
| 100 | BackgroundAction_t fBackground; // Flag for present backgroundthread
|
|---|
| 101 |
|
|---|
| 102 | ZdAz fTrackingError; // [rad] Tracking Offset between SE and calc-pos
|
|---|
| 103 | ZdAz fOffset; // Offset between se and re coordinate system [re]
|
|---|
| 104 | ZdAz fZdAzSoll; // [rad] Soll position when moving
|
|---|
| 105 | RaDec fRaDec; // Position to track
|
|---|
| 106 | ZdAz fAccuracy; // Actual accuracy of Tracking
|
|---|
| 107 | ZdAz fVelocity; // Actual velocity of Tracking
|
|---|
| 108 | ZdAz fMin;
|
|---|
| 109 | ZdAz fMax;
|
|---|
| 110 |
|
|---|
| 111 | TH1 *fHist;
|
|---|
| 112 | Bool_t fTriggerDisplay;
|
|---|
| 113 |
|
|---|
| 114 | XY kGearRatio; // describing the gear of the system [re/se]
|
|---|
| 115 | XY kGearRatio2; // describing the gear of the system [re/deg]
|
|---|
| 116 |
|
|---|
| 117 | MBending fBending;
|
|---|
| 118 |
|
|---|
| 119 | UInt_t fStatus;
|
|---|
| 120 |
|
|---|
| 121 | ofstream *tpout;
|
|---|
| 122 |
|
|---|
| 123 | Bool_t AlignTrackingPos(ZdAz pointing, ZdAz &za) const;
|
|---|
| 124 | Bool_t CheckRange(const ZdAz &d) const;
|
|---|
| 125 | Double_t Starguider(Double_t mjd, ZdAz &dest) const;
|
|---|
| 126 |
|
|---|
| 127 | double Rad2SE(double rad) const;
|
|---|
| 128 | double Rad2ZdRE(double rad) const;
|
|---|
| 129 | double Rad2AzRE(double rad) const;
|
|---|
| 130 | double Deg2ZdRE(double rad) const;
|
|---|
| 131 | double Deg2AzRE(double rad) const;
|
|---|
| 132 |
|
|---|
| 133 | void SetStatus(UInt_t stat) { fStatus = stat; }
|
|---|
| 134 | UInt_t GetStatus() const { return fStatus; }
|
|---|
| 135 |
|
|---|
| 136 | ZdAz GetRePos();
|
|---|
| 137 | ZdAz GetRePosPdo();
|
|---|
| 138 | ZdAz GetSePos() const; // [se]
|
|---|
| 139 |
|
|---|
| 140 | Bool_t RequestRePos();
|
|---|
| 141 | Bool_t SetVelocity(const ZdAz &v);
|
|---|
| 142 |
|
|---|
| 143 | void SetPosVelocity(const Float_t ratio, Float_t vel);
|
|---|
| 144 |
|
|---|
| 145 | void DoRelPos(const ZdAz &rd, const Bool_t axe1, const Bool_t axe2);
|
|---|
| 146 |
|
|---|
| 147 | void InitSync();
|
|---|
| 148 | bool InitTracking();
|
|---|
| 149 | void LimitSpeed(ZdAz *vt, const ZdAz &vcalc) const;
|
|---|
| 150 |
|
|---|
| 151 | void TalkThread();
|
|---|
| 152 | void TalkThreadTracking();
|
|---|
| 153 | void TalkThreadSeTest();
|
|---|
| 154 | void TalkThreadGear();
|
|---|
| 155 |
|
|---|
| 156 | void DisplayHistTestSe(Bool_t del=kTRUE);
|
|---|
| 157 | void DisplayHistGear(Bool_t del=kTRUE);
|
|---|
| 158 |
|
|---|
| 159 | int SetPosition(const ZdAz &dst, Bool_t track=kFALSE);
|
|---|
| 160 |
|
|---|
| 161 | void TerminateApp();
|
|---|
| 162 |
|
|---|
| 163 | void TrackPosition(const RaDec &dst); // ra, dec [rad]
|
|---|
| 164 |
|
|---|
| 165 | int StopWaitingForSDO() const;
|
|---|
| 166 | void CheckForError();
|
|---|
| 167 |
|
|---|
| 168 | void StopMovement();
|
|---|
| 169 | void StopTracking();
|
|---|
| 170 |
|
|---|
| 171 | void WaitForEndMovement();
|
|---|
| 172 |
|
|---|
| 173 | void Constructor(Int_t id1, Int_t id2, Int_t id3, Int_t id4, Int_t id5, Int_t id6);
|
|---|
| 174 | void ConstructorSE(Int_t id1, Int_t id2, Int_t id3);
|
|---|
| 175 | void ConstructorDemo();
|
|---|
| 176 |
|
|---|
| 177 | void ReadConfig();
|
|---|
| 178 |
|
|---|
| 179 | bool CheckNetwork();
|
|---|
| 180 |
|
|---|
| 181 | public:
|
|---|
| 182 | MCosy(int mode, const char *dev, const int baud, MLog &out=gLog);
|
|---|
| 183 | ~MCosy();
|
|---|
| 184 |
|
|---|
| 185 | void Start();
|
|---|
| 186 | void Stop();
|
|---|
| 187 |
|
|---|
| 188 | void *Proc(int msg, void *mp);
|
|---|
| 189 |
|
|---|
| 190 | Bool_t HandleTimer(TTimer *t);
|
|---|
| 191 |
|
|---|
| 192 | ZdAz GetPointingPos(void) const;
|
|---|
| 193 | void SetStarguider(MStarguider *s) { fStarguider = s; }
|
|---|
| 194 |
|
|---|
| 195 | // static ZdAz CorrectTarget(const ZdAz &src, const ZdAz &dst);
|
|---|
| 196 | // static ZdAz RaDec2ZdAz(const double mjd, const RaDec &pos, const RaDec &pm=RaDec(0,0));
|
|---|
| 197 |
|
|---|
| 198 | ClassDef(MCosy, 0)
|
|---|
| 199 | };
|
|---|
| 200 |
|
|---|
| 201 | #endif
|
|---|