source: trunk/Cosy/main/MSlewing.cc@ 18162

Last change on this file since 18162 was 12596, checked in by tbretz, 13 years ago
Removed the zenith angle position correction for FACT
File size: 6.6 KB
Line 
1#include "MSlewing.h"
2
3#include "MLogManip.h"
4
5#include "MCosy.h"
6#include "dkc.h"
7#include "MDriveCom.h"
8
9#include "MString.h"
10#include "MPointing.h"
11
12ClassImp(MSlewing);
13
14using namespace std;
15
16//#define EXPERT
17#undef EXPERT
18
19bool MSlewing::SetAcc(Dkc *mac, Float_t acc)
20{
21 // FIXME: Get acceleration scale from DKC!
22 mac->SetAcceleration(TMath::Nint(acc*1000000000));
23 return !mac->IsZombieNode();
24}
25
26// --------------------------------------------------------------------------
27//
28// set the velocity and accelerations for position maneuvers.
29//
30// The acceleratin is set as given (in percent of maximum).
31// The velocity is given in percent, depending on the ratio (<1 or >1)
32// one of the axis becomes a slower velocity. This is used for maneuvers
33// in which both axis are moved synchromously and should reach their
34// target position at the same time.
35//
36void MSlewing::SetPosVelocity(const ZdAz &res, Float_t vel)
37{
38 const Double_t taz = TMath::Abs(res.Az())/fCosy->fMac1->GetVelMax();
39 const Double_t tzd = TMath::Abs(res.Zd())/fCosy->fMac2->GetVelMax();
40
41 if (tzd > taz)
42 {
43 fCosy->fMac1->SetVelocityRel(vel*TMath::Abs(res.Az()/res.Zd()));
44 fCosy->fMac2->SetVelocityRel(vel);
45 }
46 else
47 {
48 fCosy->fMac1->SetVelocityRel(vel);
49 fCosy->fMac2->SetVelocityRel(vel*TMath::Abs(res.Zd()/res.Az()));
50 }
51}
52
53// --------------------------------------------------------------------------
54//
55// Does an absolute positioning.
56//
57// The steps to move are given in a ZdAz object relative to the current
58// position. The coordinates are given in Roteryencoder steps.
59// Axis 1 is moved only if axe1==kTRUE, Axis 2 is moved only
60// if Axis 2==kTRUE. The function waits for the movement to be finished.
61//
62void MSlewing::DoAbsPos(const ZdAz &rd, const Bool_t axe1, const Bool_t axe2)
63{
64 if (fCosy->HasZombie())
65 return;
66
67 fCosy->SetStatus(MDriveCom::kMoving);
68
69 if (axe1) fCosy->fMac2->StartAbsPosRev(rd.Zd());
70 if (axe2) fCosy->fMac1->StartAbsPosRev(rd.Az());
71
72 if (axe1) fCosy->fMac2->WaitForSdo(0x6004, 0);
73 if (axe2) fCosy->fMac1->WaitForSdo(0x6004, 0);
74
75 // FIXME: We need a delay here to account for the delay of the
76 // toggle bit in the SPS. We need a more precise return value from
77 // the SPS:
78 usleep(150000);
79
80#ifdef EXPERT
81 cout << "Waiting for positioning..." << flush;
82#endif
83 fCosy->WaitForEndMovement();
84#ifdef EXPERT
85 cout << "done." << endl;
86#endif
87}
88
89bool MSlewing::Break()
90{
91 return fCosy->Break() || fCosy->HasError() || fCosy->HasZombie();
92}
93
94
95// --------------------------------------------------------------------------
96//
97// Caluclate the difference between feedback 1 and feedback 2 at
98// the given zenith angle (feedback 2)
99//
100Double_t MSlewing::GetDiff(const ZdAz &za) const
101{
102 const Double_t zd = za.Zd(); //[revolutions]
103
104 const Double_t sh = -1.21 *(TMath::SinH(0.916*zd*TMath::TwoPi())-1);
105 const Double_t cs = 0.667 *TMath::Cos(1.735*(zd-0.236)*TMath::TwoPi());
106 const Double_t of = 0.6497;
107
108 return (sh+cs+of)/360; //[revolutions]
109}
110
111// --------------------------------------------------------------------------
112//
113// Move the telescope to the given position. The position must be given in
114// a ZdAz object in rad.
115//
116// The first positioning is done absolutely. If we didn't reach the
117// correct psotion we try to correct for this by 10 relative position
118// maneuvers. If this doesn't help positioning failed.
119//
120// As a reference the shaftencoder values are used.
121//
122int MSlewing::SetPosition(const ZdAz &dst, Bool_t track) // [rad]
123{
124 gLog << all << MTime(-1) << " - Target Position: " << dst.Zd()*TMath::RadToDeg() << "deg, " << dst.Az()*TMath::RadToDeg() << "deg (Zd/Az)" << endl;
125
126 //
127 // Because we agreed on I don't search for the shortest move
128 // anymore
129 //
130 // const ZdAz dest = CorrectTarget(src, dst);
131 //
132 const ZdAz bend = fCosy->fBending(dst); // [rad]
133 const ZdAz dest = bend/TMath::TwoPi(); // [revolutions]
134
135 // Check whether bending is valid!
136
137 if (!fCosy->CheckRange(bend))
138 return kFALSE;
139
140 fCosy->fZdAzSoll = dst;
141
142 int i;
143 for (i=0; i<(track?1:10) && !Break(); i++)
144 {
145 gLog << inf2 << "- Step #" << i << endl;
146
147 // Get feedback 2
148 const ZdAz sepos = fCosy->GetSePos();
149
150 // Calculate residual to move deviation
151 const ZdAz res = dest-sepos; // [revolutions]
152
153 gLog << inf2 << "- Shaftencoders show a residual deviation of dZd=";
154 gLog << MString::Format("%.2f", res.Zd()*360*60) << "' and dAz=";
155 gLog << MString::Format("%.2f", res.Az()*360*60) << "'" << endl;
156
157 // Check which axis should still be moved
158 ZdAz cd = res; // [revolutions]
159 cd *= 1./fMaxResidual; // Scale to units of the maximum residual
160 cd.Abs();
161
162 // Check if there is a control deviation on the axis
163 const Bool_t cdzd = cd.Zd()>0.5 ? kTRUE : kFALSE;
164 const Bool_t cdaz = cd.Az()>0.5 ? kTRUE : kFALSE;
165
166 // check if we reached the correct position already
167 if (!cdzd && !cdaz)
168 {
169 gLog << all << MTime(-1) << " - Positioning done in " << i << (i==1?" step.":" steps.") << endl;
170 fCosy->SetStatus(MDriveCom::kStopped);
171 fCosy->fCom->SendStatus("Target position reached.");
172 return TRUE;
173 }
174
175 // ==============================================
176 // Estimate the noncircularity of the zd axis
177#ifdef FACT
178 const Double_t add = 0;
179#else
180 const Double_t add = GetDiff(sepos)-GetDiff(dest);
181#endif
182
183 const ZdAz dest2(dest.Zd()+add, dest.Az());
184 const ZdAz res2 = dest-sepos;
185 // =================================================
186
187 //gLog << warn << "WARNING - The center of the elevation axis is taken as center of the drive bow" << endl;
188
189 SetAcc(fCosy->fMac1, fAcc.Az());
190 SetAcc(fCosy->fMac2, fAcc.Zd());
191
192 SetPosVelocity(res2, fVel);
193
194 gLog << inf2 << "- Do absolute positioning..." << endl;
195 DoAbsPos(dest2, cdzd, cdaz);
196 gLog << inf2 << "- Absolute Positioning Done" << endl;
197 }
198 if (i==1 && track && !Break())
199 {
200 gLog << all << MTime(-1) << " - Positioning done." << endl;
201 fCosy->SetStatus(MDriveCom::kStopped);
202 fCosy->fCom->SendStatus("Tracking preposition reached.");
203 return TRUE;
204 }
205
206 if (i<10)
207 fCosy->StopMovement();
208 else
209 fCosy->SetStatus(MDriveCom::kStopped);
210
211 gLog << warn << MTime(-1) << " - Warning: Requested position not reached (i=" << i << ")" << endl;
212
213 fCosy->fCom->SendStatus("Target position missed!");
214
215 return FALSE;
216}
Note: See TracBrowser for help on using the repository browser.