Changeset 1758 for trunk/MagicSoft/Cosy/main
- Timestamp:
- 02/14/03 23:18:37 (22 years ago)
- Location:
- trunk/MagicSoft/Cosy/main
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Cosy/main/MCosy.cc
r1757 r1758 10 10 #include <TApplication.h> 11 11 #include <TTimer.h> 12 13 #include <TH2.h> 14 #include <TProfile.h> 15 #include <TCanvas.h> 12 16 13 17 #include "MGCosy.h" … … 147 151 // are avaraged. The values are returned as a ZdAz object. 148 152 // 153 // If one of the two shaftencoders on the elevation axis is missing 154 // the other one's position is returned. 155 // 149 156 // The positions are alway up-to-date because the shaftencoders are 150 157 // sending all changes immediatly. … … 152 159 ZdAz MCosy::GetSePos() 153 160 { 161 const int pa = fAz->GetPos(); 162 if (fZd1->IsZombieNode() && fZd2->IsZombieNode()) 163 return ZdAz(0, pa); 164 154 165 // 155 166 // Get the values 156 167 // 157 const int p0 = fZd1->GetPos(); 158 const int p1 = fZd2->GetPos(); 159 const int p2 = fAz->GetPos(); 168 const int p1 = fZd1->GetPos(); 169 const int p2 = -fZd2->GetPos(); 170 171 if (fZd1->IsZombieNode()) 172 return ZdAz(p2, pa); 173 if (fZd2->IsZombieNode()) 174 return ZdAz(p1, pa); 160 175 161 176 // 162 177 // interpolate shaft encoder positions 163 178 // 164 const float p = (float)(p0-p1)/2;179 float p = (float)(p1+p2)/2; 165 180 166 181 // 167 182 // calculate 'regelabweichung' 168 183 // 169 return ZdAz(p, p 2);184 return ZdAz(p, pa); 170 185 } 171 186 … … 655 670 void MCosy::TrackPosition(const RaDec &dst) // ra, dec [rad] 656 671 { 657 SlaStars sla ;672 SlaStars sla(fObservatory); 658 673 659 674 // 660 675 // Position to actual position 661 676 // 662 sla. SetMjd2Now();677 sla.Now(); 663 678 ZdAz dest = sla.CalcZdAz(dst); 664 679 … … 707 722 // 708 723 fRaDec = dst; 709 f Tracking = kTRUE;724 fBackground = kBgdTracking; 710 725 711 726 //--- ofstream fout("log/cosy.pos"); … … 729 744 // Request theoretical Position for a time in the future (To+dt) from CPU 730 745 // 731 sla.SetMjd(sla. CalcMjd()+dt/(60*60*24));746 sla.SetMjd(sla.GetMjd()+dt/(60*60*24)); 732 747 ZdAz dummy = fBending(sla.CalcZdAz(fRaDec)); 733 748 dest = CorrectTarget(GetSePos(), dummy); // [se] … … 817 832 } 818 833 819 f Tracking = kFALSE;834 fBackground = kBgdNone; 820 835 StopMovement(); 821 836 lout << "Tracking stopped." << endl; … … 915 930 return (void*)0xebb0; 916 931 917 SlaStars sla ;918 sla. SetMjd2Now();932 SlaStars sla(fObservatory); 933 sla.Now(); 919 934 920 935 RaDec rd = *((RaDec*)mp); … … 943 958 { 944 959 cout << "WM_TPoint: start." << endl; 945 SlaStars sla ;946 sla. SetMjd2Now();960 SlaStars sla(fObservatory); 961 sla.Now(); 947 962 948 963 RaDec rd = *((RaDec*)mp); … … 976 991 cout << "WM_Position: done. (return 0x7777)" << endl; 977 992 return (void*)0x7777; 993 994 case WM_TESTSE: 995 cout << "WM_TestSe: start." << endl; 996 fBackground = mp ? kBgdSeTest : kBgdNone; 997 cout << "WM_TestSe: done. (return 0x1e51)" << endl; 998 return (void*)0x1e51; 978 999 979 1000 case WM_TRACK: … … 1040 1061 cout << endl; 1041 1062 1042 SlaStars sla ;1043 sla. SetMjd2Now();1063 SlaStars sla(fObservatory); 1064 sla.Now(); 1044 1065 1045 1066 XY xy = *((XY*)mp); … … 1160 1181 } 1161 1182 1183 void MCosy::TalkThreadTracking() 1184 { 1185 if (fZd1->IsZombieNode() || fZd2->IsZombieNode() || fAz->IsZombieNode()) 1186 return; 1187 if (!fMac1 || !fMac2) 1188 return; 1189 1190 SlaStars sla(fObservatory); 1191 1192 ZdAz old; 1193 ZdAz ist; 1194 1195 ZdAz sollzd; 1196 ZdAz sollaz; 1197 1198 ZdAz istre = -fOffset; // [re] 1199 ZdAz time; 1200 1201 // 1202 // only update fTrackingError while tracking 1203 // 1204 bool phca1=false; 1205 bool phca2=false; 1206 bool phcaz=false; 1207 1208 while (fBackground==kBgdTracking) 1209 { 1210 // 1211 // Make changes (eg wind) smoother - attenuation of control function 1212 // 1213 const float weight = 1.; //0.3; 1214 1215 // 1216 // This is the time constant which defines how fast 1217 // you correct for external influences (like wind) 1218 // 1219 fZd1->ResetPosHasChanged(); 1220 fZd2->ResetPosHasChanged(); 1221 fAz->ResetPosHasChanged(); 1222 do 1223 { 1224 phca1 = fZd1->PosHasChanged(); 1225 phca2 = fZd2->PosHasChanged(); 1226 phcaz = fAz->PosHasChanged(); 1227 usleep(1); 1228 } while (!phca1 && !phca2 && !phcaz && fBackground==kBgdTracking); 1229 1230 //---usleep(100000); // 0.1s 1231 1232 // 1233 // get position, where we are 1234 // 1235 old = ist; 1236 ist = GetSePos(); // [se] 1237 1238 // 1239 // if the position didn't change continue 1240 // 1241 /*--- 1242 if ((int)ist.Zd() == (int)old.Zd() && 1243 (int)ist.Az() == (int)old.Az()) 1244 continue; 1245 */ 1246 istre = GetRePosPdo(); 1247 1248 // 1249 // Get time from last shaftencoder position change (position: ist) 1250 // FIXME: I cannot take the avarage 1251 // 1252 if (fZd1->GetMjd()>fZd2->GetMjd()) 1253 time.Zd(fZd1->GetMjd()); 1254 else 1255 time.Zd(fZd2->GetMjd()); 1256 //time.Zd((fZd1->GetMjd()+fZd2->GetMjd())/2.0); 1257 time.Az(fAz->GetMjd()); 1258 1259 // 1260 // if Shaftencoder changed position 1261 // calculate were we should be 1262 // 1263 if (phca1 || phca2 /*(int)ist.Zd() != (int)old.Zd()*/) 1264 { 1265 sla.SetMjd(time.Zd()); 1266 1267 ZdAz dummy = fBending(sla.CalcZdAz(fRaDec)); 1268 sollzd = CorrectTarget(ist, dummy); // [se] 1269 1270 fOffset.Zd(fOffset.Zd()*(1.-weight)+(ist.Zd()*kGearRatio.X()-istre.Zd())*weight); 1271 } 1272 1273 if (phcaz /*(int)ist.Az() != (int)old.Az()*/) 1274 { 1275 sla.SetMjd(time.Az()); 1276 1277 ZdAz dummy = fBending(sla.CalcZdAz(fRaDec)); 1278 sollaz = CorrectTarget(ist, dummy); // [se] 1279 1280 fOffset.Az(fOffset.Az()*(1.-weight)+(ist.Az()*kGearRatio.Y()-istre.Az())*weight); 1281 } 1282 1283 ZdAz soll(sollzd.Zd(), sollaz.Az()); 1284 fZdAzSoll = fBending.CorrectBack(soll*2*TMath::Pi()/16384); 1285 1286 fTrackingError.Set((ist.Zd()-sollzd.Zd())*kGearRatio.X(), 1287 (ist.Az()-sollaz.Az())*kGearRatio.Y()); 1288 1289 //--- fout << setprecision(15) << setw(17) << time.Zd()*60.*60.*24. << " "; 1290 //--- fout << setprecision(5) << setw(7) << fTrackingError.Zd() << " "; 1291 //--- fout << setprecision(15) << setw(17) << time.Az()*60.*60.*24. << " "; 1292 //--- fout << setprecision(5) << setw(7) << fTrackingError.Az() << endl; 1293 } 1294 //--- fout << endl << endl; 1295 } 1296 1297 void MCosy::TalkThreadSeTest() 1298 { 1299 // if (fZd1->IsZombieNode() || fZd2->IsZombieNode()) 1300 // return; 1301 1302 if (fHistTestSe) 1303 { 1304 lout << "You are much too fast... try again." << endl; 1305 return; 1306 } 1307 1308 fHistTestSe = new TH2F("Diff", "Difference of SE values", 1309 201, fMin.Zd(), fMax.Zd(), 101, -50, 50); 1310 fHistTestSe->SetXTitle("ZA [\\circ]"); 1311 fHistTestSe->SetYTitle("\\Delta SE"); 1312 1313 Double_t offset = 0; 1314 1315 int cnt = 0; 1316 1317 lout << "Starting Shaftencoder Test..." << endl; 1318 1319 while (fBackground==kBgdSeTest) 1320 { 1321 fZd1->ResetPosHasChanged(); 1322 fZd2->ResetPosHasChanged(); 1323 1324 while (!fZd1->PosHasChanged() && !fZd2->PosHasChanged() && 1325 fBackground==kBgdSeTest) 1326 usleep(1); 1327 1328 const Double_t pos[3] = { fZd1->GetPos(), fZd2->GetPos(), fAz->GetPos() }; 1329 1330 // 1331 // Estimate Offset from the first ten positions 1332 // 1333 if (cnt++<10) 1334 offset += pos[0]+pos[1]; 1335 if (cnt++==10) 1336 offset /= 10; 1337 if (cnt<11) 1338 continue; 1339 1340 Double_t apos = (pos[0]-pos[1])/2 * TMath::Pi()*2 / 16384; 1341 1342 ZdAz bend = fBending(ZdAz(apos, pos[2]))*kRad2Deg; 1343 1344 fHistTestSe->Fill(bend.Zd(), pos[0]+pos[1]-offset); 1345 } 1346 1347 lout << "Shaftencoder Test Stopped... displaying Histogram." << endl; 1348 } 1349 1162 1350 void MCosy::TalkThread() 1163 1351 { … … 1180 1368 /*** FOR DEMO MODE ***/ 1181 1369 1182 if (fZd1->IsZombieNode() || fZd2->IsZombieNode() || fAz->IsZombieNode())1183 return;1184 1185 if (!fMac1 || !fMac2)1186 return;1187 1188 1370 // 1189 1371 // Start the Network 1190 1372 // 1191 /*1192 TEnv env(".cosyrc");1193 1194 cout << "Setting up software endswitch..." << flush;1195 fMac1->SetNegEndswitch(Deg2AzRE(env.GetValue("Az_Min[Deg]", -1.0)));1196 fMac1->SetPosEndswitch(Deg2AzRE(env.GetValue("Az_Max[Deg]", +1.0)));1197 1198 fMac2->SetNegEndswitch(Deg2ZdRE(env.GetValue("Zd_Min[Deg]", -1.0)));1199 fMac2->SetPosEndswitch(Deg2ZdRE(env.GetValue("Zd_Max[Deg]", +1.0)));1200 cout << "done." << endl;1201 */1202 SlaStars sla;1203 1373 while (1) 1204 1374 { … … 1206 1376 // wait until a tracking session is started 1207 1377 // 1208 while ( !fTracking)1378 while (fBackground==kBgdNone) 1209 1379 usleep(1); 1210 1380 1211 //--- ofstream fout("log/cosy.err"); 1212 //--- fout << "Tracking:"; 1213 //--- fout << " Ra: " << Rad2Deg(fRaDec.Ra()) << "\x9c "; 1214 //--- fout << "Dec: " << Rad2Deg(fRaDec.Dec()) << "\x9c" << endl << endl; 1215 //--- fout << " MjdZd/10ms ErrZd/re"; 1216 //--- fout << " MjdAz/10ms ErrAd/re" << endl; 1217 1218 ZdAz old; 1219 ZdAz ist; 1220 1221 ZdAz sollzd; 1222 ZdAz sollaz; 1223 1224 ZdAz istre = -fOffset; // [re] 1225 ZdAz time; 1226 1227 // 1228 // only update fTrackingError while tracking 1229 // 1230 bool phca1=false; 1231 bool phca2=false; 1232 bool phcaz=false; 1233 1234 while (fTracking) 1381 switch (fBackground) 1235 1382 { 1236 // 1237 // Make changes (eg wind) smoother - attenuation of control function 1238 // 1239 const float weight = 1.; //0.3; 1240 1241 // 1242 // This is the time constant which defines how fast 1243 // you correct for external influences (like wind) 1244 // 1245 fZd1->ResetPosHasChanged(); 1246 fZd2->ResetPosHasChanged(); 1247 fAz->ResetPosHasChanged(); 1248 do 1249 { 1250 phca1 = fZd1->PosHasChanged(); 1251 phca2 = fZd2->PosHasChanged(); 1252 phcaz = fAz->PosHasChanged(); 1253 usleep(1); 1254 } while (!phca1 && !phca2 && !phcaz && fTracking); 1255 1256 //---usleep(100000); // 0.1s 1257 1258 // 1259 // get position, where we are 1260 // 1261 old = ist; 1262 ist = GetSePos(); // [se] 1263 1264 // 1265 // if the position didn't change continue 1266 // 1267 /*--- 1268 if ((int)ist.Zd() == (int)old.Zd() && 1269 (int)ist.Az() == (int)old.Az()) 1270 continue; 1271 */ 1272 istre = GetRePosPdo(); 1273 1274 // 1275 // Get time from last shaftencoder position change (position: ist) 1276 // FIXME: I cannot take the avarage 1277 // 1278 if (fZd1->GetMjd()>fZd2->GetMjd()) 1279 time.Zd(fZd1->GetMjd()); 1280 else 1281 time.Zd(fZd2->GetMjd()); 1282 //time.Zd((fZd1->GetMjd()+fZd2->GetMjd())/2.0); 1283 time.Az(fAz->GetMjd()); 1284 1285 // 1286 // if Shaftencoder changed position 1287 // calculate were we should be 1288 // 1289 if (phca1 || phca2 /*(int)ist.Zd() != (int)old.Zd()*/) 1290 { 1291 sla.SetMjd(time.Zd()); 1292 1293 ZdAz dummy = fBending(sla.CalcZdAz(fRaDec)); 1294 sollzd = CorrectTarget(ist, dummy); // [se] 1295 1296 fOffset.Zd(fOffset.Zd()*(1.-weight)+(ist.Zd()*kGearRatio.X()-istre.Zd())*weight); 1297 } 1298 1299 if (phcaz /*(int)ist.Az() != (int)old.Az()*/) 1300 { 1301 sla.SetMjd(time.Az()); 1302 1303 ZdAz dummy = fBending(sla.CalcZdAz(fRaDec)); 1304 sollaz = CorrectTarget(ist, dummy); // [se] 1305 1306 fOffset.Az(fOffset.Az()*(1.-weight)+(ist.Az()*kGearRatio.Y()-istre.Az())*weight); 1307 } 1308 1309 ZdAz soll(sollzd.Zd(), sollaz.Az()); 1310 fZdAzSoll = fBending.CorrectBack(soll*2*TMath::Pi()/16384); 1311 1312 fTrackingError.Set((ist.Zd()-sollzd.Zd())*kGearRatio.X(), 1313 (ist.Az()-sollaz.Az())*kGearRatio.Y()); 1314 1315 //--- fout << setprecision(15) << setw(17) << time.Zd()*60.*60.*24. << " "; 1316 //--- fout << setprecision(5) << setw(7) << fTrackingError.Zd() << " "; 1317 //--- fout << setprecision(15) << setw(17) << time.Az()*60.*60.*24. << " "; 1318 //--- fout << setprecision(5) << setw(7) << fTrackingError.Az() << endl; 1383 case kBgdNone: 1384 continue; 1385 1386 case kBgdTracking: 1387 TalkThreadTracking(); 1388 continue; 1389 1390 case kBgdSeTest: 1391 TalkThreadSeTest(); 1392 continue; 1319 1393 } 1320 1321 //--- fout << endl << endl;1322 1394 } 1323 1395 } … … 1355 1427 fVelocity, fOffset, fRaDec, fZdAzSoll, fStatus, avail); 1356 1428 1357 1358 1429 /* 1359 1430 cout << (int)(fMac1->GetStatus()&Macs::kOutOfControl) << " "; … … 1362 1433 */ 1363 1434 1435 if (fBackground==kBgdSeTest || fHistTestSe==NULL) 1436 return kTRUE; 1437 1438 DisplayHistTestSe(); 1439 1364 1440 return kTRUE; 1365 1441 } 1366 1442 1443 void MCosy::DisplayHistTestSe() 1444 { 1445 TH2F &hist = *fHistTestSe; 1446 fHistTestSe = NULL; 1447 1448 TCanvas *c=new TCanvas("c1", "", 1000, 1000); 1449 c->Divide(1,2); 1450 1451 c->cd(1); 1452 TH2 *h=(TH2*)hist.DrawCopy(); 1453 1454 TProfile *p = h->ProfileX("_pfx", -1, 9999, "s"); 1455 p->SetLineColor(kBlue); 1456 p->Draw("same"); 1457 p->SetBit(kCanDelete); 1458 1459 c->cd(2); 1460 1461 TH1F p2("spread", "Spread of the differences", hist.GetNbinsX(), hist.GetBinLowEdge(1), 1462 hist.GetBinLowEdge(hist.GetNbinsX()+1)); 1463 p2.SetXTitle("ZA [\\circ]"); 1464 for (int i=0; i<hist.GetNbinsX(); i++) 1465 p2.SetBinError(i, p->GetBinError(i)); 1466 p2.SetLineColor(kRed); 1467 p2.SetStats(0); 1468 p2.DrawCopy(); 1469 1470 delete &hist; 1471 } 1367 1472 1368 1473 // -------------------------------------------------------------------------- … … 1450 1555 1451 1556 lout << "- Starting GUI." << endl; 1452 fWin=new MGCosy( this, gClient->GetRoot(), 1, 1);1557 fWin=new MGCosy(fObservatory, this, gClient->GetRoot(), 1, 1); 1453 1558 } 1454 1559 … … 1480 1585 1481 1586 lout << "- Starting GUI." << endl; 1482 fWin=new MGCosy( this, gClient->GetRoot(), 1, 1);1587 fWin=new MGCosy(fObservatory, this, gClient->GetRoot(), 1, 1); 1483 1588 } 1484 1589 … … 1497 1602 1498 1603 lout << "- Starting GUI." << endl; 1499 fWin=new MGCosy( this, gClient->GetRoot(), 1, 1);1604 fWin=new MGCosy(fObservatory, this, gClient->GetRoot(), 1, 1); 1500 1605 } 1501 1606 1502 1607 MCosy::MCosy(int mode, const char *dev, const int baud, MLog &out) 1503 : Network(dev, baud, out), f Zd1(0), fZd2(0), fAz(0), fMac1(0), fMac2(0), fMac3(0), fTracking(kFALSE)1608 : Network(dev, baud, out), fObservatory(MObservatory::kMagic1), fZd1(0), fZd2(0), fAz(0), fMac1(0), fMac2(0), fMac3(0), fBackground(kBgdNone) 1504 1609 { 1505 1610 TEnv env(".cosyrc"); -
trunk/MagicSoft/Cosy/main/MCosy.h
r1757 r1758 7 7 #include "MThread.h" 8 8 #include "MBending.h" 9 10 #ifndef MARS_Mobservatory 11 #include "MObservatory.h" 12 #endif 9 13 10 14 #define kDEG ((char)0x9c) // Linux 'ø' … … 22 26 #define WM_CALCALTAZ 0x1009 23 27 #define WM_HOME 0x100a 28 #define WM_TESTSE 0x100b 24 29 25 30 … … 28 33 class MGCosy; 29 34 class MCosy; 35 class TH2F; 30 36 31 37 class MTTalk : public MThread … … 46 52 }; 47 53 48 49 54 class TTimer; 50 55 class MCosy : public Network, public MsgQueue, public TObject … … 62 67 }; 63 68 69 const MObservatory::LocationName_t fObservatory; 70 64 71 ShaftEncoder *fZd1; 65 72 ShaftEncoder *fZd2; … … 76 83 // with a generic interface to both... 77 84 85 enum BackgroundAction_t 86 { 87 kBgdNone, 88 kBgdTracking, 89 kBgdSeTest 90 }; 91 92 BackgroundAction_t fBackground; // Flag for present backgroundthread 93 78 94 ZdAz fTrackingError; // Tracking Offset between SE and calc-pos [re] 79 95 ZdAz fOffset; // Offset between se and re coordinate system [re] 80 96 ZdAz fZdAzSoll; // Soll position when moving 81 97 RaDec fRaDec; // Position to track 82 int fTracking; // Flag for present tracking action83 98 ZdAz fAccuracy; // Actual accuracy of Tracking 84 99 ZdAz fVelocity; // Actual velocity of Tracking 85 100 ZdAz fMin; 86 101 ZdAz fMax; 102 103 TH2F *fHistTestSe; 87 104 88 105 XY kGearRatio; // describing the gear of the system [re/se] … … 119 136 120 137 void TalkThread(); 138 void TalkThreadTracking(); 139 void TalkThreadSeTest(); 140 141 void DisplayHistTestSe(); 121 142 122 143 int SetPosition(const ZdAz &dst); -
trunk/MagicSoft/Cosy/main/Makefile
r1531 r1758 33 33 34 34 SRCFILES = MCosy.cc \ 35 MBending.cc \ 36 MStarguider.cc 35 MBending.cc 37 36 38 37 SRCS = $(SRCFILES)
Note:
See TracChangeset
for help on using the changeset viewer.