Changeset 1703 for trunk/MagicSoft/Cosy/main/MCosy.cc
- Timestamp:
- 01/14/03 12:08:46 (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Cosy/main/MCosy.cc
r1702 r1703 41 41 //const XY kGearRatio2(GEAR_RATIO_ALT*RES_RE/360.0, GEAR_RATIO_AZ*RES_RE/360.0); //[re/deg] 42 42 43 /* +===================================+ 44 FIXME: What if fMac3 (Sync) died? 45 +===================================+ 46 */ 47 43 48 double MCosy::Rad2SE(double rad) const 44 49 { … … 150 155 // Get the values 151 156 // 152 const int p0 = !fZd1->IsZombieNode() ? fZd1->GetPos() : 0; 153 const int p1 = !fZd2->IsZombieNode() ? fZd2->GetPos() : 0; 154 const int p2 = !fAz->IsZombieNode() ? fAz->GetPos() : 0; 155 156 const int a0 = p0; //p0>8192?p0-16384:p0; 157 const int a1 = p1; //p1>8192?p1-16384:p1; 158 const int a2 = p2; //p2>8192?p2-16384:p2; 157 const int p0 = fZd1->GetPos(); 158 const int p1 = fZd2->GetPos(); 159 const int p2 = fAz->GetPos(); 159 160 160 161 // 161 162 // interpolate shaft encoder positions 162 163 // 163 const float a = (float)(a0-a1)/2;164 const float p = (float)(p0-p1)/2; 164 165 165 166 // 166 167 // calculate 'regelabweichung' 167 168 // 168 return ZdAz( a, a2);169 return ZdAz(p, p2); 169 170 } 170 171 … … 177 178 Bool_t MCosy::RequestRePos() 178 179 { 179 if (fMac1->IsZombieNode() || fMac2->IsZombieNode())180 return kTRUE;181 182 180 // 183 181 // Send request … … 189 187 // Wait until the objects are received. 190 188 // 189 // FIXME, what when waiting times out (Zombie) 191 190 WaitForSdos(); 192 191 … … 194 193 // If waiting was not interrupted everything is ok. return. 195 194 // 196 if (!StopWaitingForSDO() )195 if (!StopWaitingForSDO() && !HasZombie()) 197 196 return kTRUE; 198 197 … … 216 215 ZdAz MCosy::GetRePos() 217 216 { 218 return !fMac1->IsZombieNode() && !fMac2->IsZombieNode() ? ZdAz(fMac2->GetPos(), fMac1->GetPos()) : ZdAz(0,0);217 return ZdAz(fMac2->GetPos(), fMac1->GetPos()); 219 218 } 220 219 … … 304 303 int MCosy::StopWaitingForSDO() const 305 304 { 306 return Break() || HasError() || HasZombie();305 return Break() || HasError(); 307 306 } 308 307 … … 316 315 void MCosy::WaitForEndMovement() 317 316 { 317 // FIXME, what when waiting times out (Zombie) 318 318 WaitForSdos(); 319 319 320 while ((fMac1->IsPositioning() || fMac2->IsPositioning()) && !StopWaitingForSDO() )320 while ((fMac1->IsPositioning() || fMac2->IsPositioning()) && !StopWaitingForSDO() && !HasZombie()) 321 321 usleep(1); 322 322 } … … 378 378 // FIXME: Correct by fOffset ? 379 379 380 /* 380 381 if (fMac1->IsZombieNode() || fMac2->IsZombieNode()) 381 382 { … … 383 384 return TRUE; 384 385 } 386 */ 387 388 // 389 // Make sure that the motors are in sync mode (necessary if the 390 // MACS has been rebooted from a Zombie state. 391 // 392 InitSync(); 393 if (fMac3->IsZombieNode()) 394 return false; 385 395 386 396 // 387 397 // Calculate new target position (shortest distance to go) 388 398 // 389 const ZdAz src = GetSePos(); //*TMath::Pi()*2/16384;;399 const ZdAz src = GetSePos(); 390 400 391 401 // … … 404 414 cout << "Shortest Dest Zd: " << dest.Zd() << "se Az:" << dest.Az() << "se" << endl; 405 415 406 for (int i=0; i<10 && !StopWaitingForSDO() ; i++)416 for (int i=0; i<10 && !StopWaitingForSDO() && !HasZombie(); i++) 407 417 { 408 418 // … … 450 460 451 461 rd.Round(); 462 463 // FIXME? Check for Error or Zombie? 452 464 453 465 /* … … 477 489 // in case of success, kFALSE in case of failure. 478 490 // 479 Bool_t MCosy::SetVelocity( ZdAzv)491 Bool_t MCosy::SetVelocity(const ZdAz &v) 480 492 { 481 493 // … … 488 500 // Wait for the objects to be OKed. 489 501 // 502 // FIXME, what when waiting times out (Zombie) 490 503 WaitForSdos(); 491 504 … … 493 506 // If the waiting for the objects wasn't interrupted return kTRUE 494 507 // 495 if (!StopWaitingForSDO() )508 if (!StopWaitingForSDO() && !HasZombie()) 496 509 return kTRUE; 497 510 … … 513 526 // revolution mode. 514 527 // 515 void MCosy::InitTracking() 516 { 528 bool MCosy::InitTracking() 529 { 530 // FIXME? Handling of Zombie OK? 517 531 if (fMac1->IsZombieNode() || fMac2->IsZombieNode()) 518 return ;532 return false; 519 533 520 534 // … … 523 537 fMac2->SetAcceleration(0.90*fMac2->GetVelRes()); 524 538 fMac2->SetDeceleration(0.90*fMac2->GetVelRes()); 539 if (fMac2->IsZombieNode()) 540 return false; 525 541 526 542 fMac1->SetAcceleration(0.90*fMac1->GetVelRes()); 527 543 fMac1->SetDeceleration(0.90*fMac1->GetVelRes()); 544 if (fMac1->IsZombieNode()) 545 return false; 528 546 529 547 SetStatus(MCosy::kMoving | MCosy::kTracking); 530 548 531 549 fMac2->SetRpmMode(TRUE); 550 if (fMac2->IsZombieNode()) 551 return false; 552 532 553 fMac1->SetRpmMode(TRUE); 554 if (fMac1->IsZombieNode()) 555 return false; 556 557 return true; 533 558 } 534 559 … … 640 665 // Init accelerations and Rpm Mode 641 666 // 642 InitTracking(); 667 if (!InitTracking()) 668 return; 643 669 644 670 XY xy(Rad2Deg(dst.Ra())*24/360, Rad2Deg(dst.Dec())); … … 655 681 // 656 682 fRaDec = dst; 657 658 if (fMac1->IsZombieNode() || fMac2->IsZombieNode())659 return;660 661 683 fTracking = kTRUE; 662 684 … … 671 693 // 672 694 const float dt = 1; // 1 second 673 while (!StopWaitingForSDO() )695 while (!StopWaitingForSDO() && !HasZombie()) 674 696 { 675 697 // … … 774 796 void MCosy::StopMovement() 775 797 { 776 if (fMac1->IsZombieNode() || fMac2->IsZombieNode())777 return;778 779 798 // 780 799 // Set status to Stopping … … 785 804 // set deceleration to 50% 786 805 // 787 cout << "Stopping positioning..." << endl;806 cout << "Stopping..." << endl; 788 807 fMac1->SetDeceleration(0.5*fMac1->GetVelRes()); 808 if (!fMac1->IsZombieNode()) 809 fMac1->SetRpmMode(FALSE); 810 789 811 fMac2->SetDeceleration(0.5*fMac2->GetVelRes()); 790 791 // 792 // Stop revolution mode (movement) 793 // 794 cout << "Stopping possibleRPM mode..." << endl; 795 fMac1->SetRpmMode(FALSE); 796 fMac2->SetRpmMode(FALSE); 812 if (!fMac2->IsZombieNode()) 813 fMac2->SetRpmMode(FALSE); 797 814 798 815 // … … 809 826 } 810 827 811 void *MCosy::Proc(int msg, void *mp)812 { 813 lout << "Checking for Zombies" << endl;828 bool MCosy::CheckNetwork() 829 { 830 CheckConnections(); 814 831 if (HasZombie()) 815 832 { 816 lout << " Found Zombies" << endl;833 lout << "- Found Zombies in Network..." << endl; 817 834 if (!RebootZombies()) 818 return (void*)0xebb0;835 return false; 819 836 } 820 837 return true; 838 } 839 840 void *MCosy::Proc(int msg, void *mp) 841 { 821 842 switch (msg) 822 843 { … … 827 848 case WM_STOP: 828 849 cout << "MCosy::Proc: Stop." << endl; 850 if (!CheckNetwork()) 851 return (void*)0xebb0; 829 852 StopMovement(); 830 853 return NULL; … … 832 855 case WM_PRESET: 833 856 cout << "WM_Preset: start." << endl; 834 if (!fZd1->IsZombieNode()) fZd1->SetPreset(); 835 if (!fZd2->IsZombieNode()) fZd2->SetPreset(); 836 if (!fAz->IsZombieNode()) fAz->SetPreset(); 857 if (!CheckNetwork()) 858 return (void*)0xebb0; 859 fZd1->SetPreset(); 860 fZd2->SetPreset(); 861 fAz->SetPreset(); 837 862 cout << "WM_Preset: done. (return 0xaffe)" << endl; 838 863 return (void*)0xaffe; … … 841 866 { 842 867 cout << "WM_Calib: start." << endl; 868 if (!CheckNetwork()) 869 return (void*)0xebb0; 870 843 871 SlaStars sla; 844 872 sla.SetMjd2Now(); … … 858 886 cout << "Got Zd: " << sepos.Zd() << " Az: " << sepos.Az() << endl; 859 887 860 if (!fZd1->IsZombieNode()) 861 fZd1->SetPreset(za.Zd()); 862 if (!fZd2->IsZombieNode()) 863 fZd2->SetPreset(-za.Zd()); 864 if (!fAz->IsZombieNode()) 865 fAz->SetPreset(za.Az()); 888 fZd1->SetPreset(za.Zd()); 889 fZd2->SetPreset(-za.Zd()); 890 fAz->SetPreset(za.Az()); 866 891 867 892 cout << "WM_Calib: done. (return 0xaffe)" << endl; … … 897 922 cout << "WM_Position: start." << endl; 898 923 { 924 if (!CheckNetwork()) 925 return (void*)0xebb0; 926 899 927 ZdAz dest = *((ZdAz*)mp); 900 901 928 SetPosition(dest*kDeg2Rad); 902 929 } … … 907 934 cout << "WM_Track: START" << endl; 908 935 { 936 if (!CheckNetwork()) 937 return (void*)0xebb0; 938 909 939 RaDec dest = *((RaDec*)mp); 910 940 TrackPosition(dest*kDeg2Rad); … … 933 963 case WM_HOME: 934 964 cout << "WM_Home: START" << endl; 935 if (!fMac1->IsZombieNode() && !fMac2->IsZombieNode()) 965 if (!CheckNetwork()) 966 return (void*)0xebb0; 967 else 936 968 { 937 969 cout << "Going Home..." << endl; … … 976 1008 case WM_QUIT: 977 1009 cout << "WM_Quit: now." << endl; 1010 if (!CheckNetwork()) 1011 { 1012 lout << "ERROR: Cannot shutdown CANbus network." << endl; 1013 return (void*)0xebb0; 1014 } 978 1015 TerminateApp(); 979 1016 cout << "WM_Quit: done." << endl; … … 1004 1041 resreaz = fMac1->GetRes(); 1005 1042 else 1006 if ( !fMac3->IsZombieNode())1043 if (fMac3 && !fMac3->IsZombieNode()) 1007 1044 resreaz = fMac3->GetRes(); 1008 1045 else … … 1040 1077 } 1041 1078 1079 void MCosy::InitSync() 1080 { 1081 if (!fMac3) 1082 return; 1083 1084 const int res = fMac3->GetVelRes(); 1085 1086 fMac3->SetVelocity(res); 1087 fMac3->SetAcceleration(res); 1088 fMac3->SetDeceleration(res); 1089 fMac3->StartPosSync(); 1090 } 1091 1042 1092 void MCosy::TalkThread() 1043 1093 { 1044 if (fMac1->IsZombieNode() || fMac2->IsZombieNode()) 1094 /* ========== FIXME? ============= 1095 if (fMac1->IsZombieNode() || fMac2->IsZombieNode()) 1045 1096 return; 1046 1097 */ 1047 1098 fMac1->ReqPos(); 1048 1099 fMac2->ReqPos(); 1049 1050 if (fMac3)1051 {1052 const int res = fMac3->GetVelRes();1053 1054 fMac3->SetVelocity(res);1055 fMac3->SetAcceleration(res);1056 fMac3->SetDeceleration(res);1057 fMac3->StartPosSync();1058 }1059 1100 1060 1101 if (fZd1->IsZombieNode() || fZd2->IsZombieNode() || fAz->IsZombieNode()) … … 1227 1268 // Update Gui, foremer MTGui. 1228 1269 // 1229 if (!fZd1->IsZombieNode())fZd1->DisplayVal();1230 if (!fZd2->IsZombieNode())fZd2->DisplayVal();1231 if (!fAz->IsZombieNode())fAz->DisplayVal();1270 fZd1->DisplayVal(); 1271 fZd2->DisplayVal(); 1272 fAz->DisplayVal(); 1232 1273 1233 1274 ZdAz seist = GetSePos()*2*TMath::Pi()/16384; // [se] … … 1238 1279 avail |= !fMac1->IsZombieNode() ? 0x01 : 0; 1239 1280 avail |= !fMac2->IsZombieNode() ? 0x02 : 0; 1240 avail |= !fMac3->IsZombieNode() ? 0x04 : 0;1281 avail |= (fMac3 && !fMac3->IsZombieNode()) ? 0x04 : 0; 1241 1282 avail |= !fZd1->IsZombieNode() ? 0x08 : 0; 1242 1283 avail |= !fZd2->IsZombieNode() ? 0x10 : 0; … … 1268 1309 // Don't call this function twice! 1269 1310 Network::Start(); 1270 /*1271 if (fMac1)1272 if (fMac1->IsZombieNode()) { delete fMac1; fMac1=NULL; }1273 if (fMac2)1274 if (fMac2->IsZombieNode()) { delete fMac2; fMac2=NULL; }1275 if (fMac3)1276 if (fMac3->IsZombieNode()) { delete fMac3; fMac3=NULL; }1277 */1278 /* if (fZd1)1279 if (fZd1->IsZombieNode()) { delete fZd1; fZd1=NULL; }1280 else */fZd1->SetDisplay(fWin->GetLabel2());1281 1282 /* if (fZd2)1283 if (fZd2->IsZombieNode()) { delete fZd2; fZd2=NULL; }1284 else */fZd2->SetDisplay(fWin->GetLabel3());1285 1286 /* if (fAz)1287 if (fAz->IsZombieNode()) { delete fAz; fAz=NULL; }1288 else */fAz->SetDisplay(fWin->GetLabel1());1289 1311 1290 1312 ReadConfig(); … … 1292 1314 lout << "- Starting TX Thread." << endl; 1293 1315 fTTalk = new MTTalk(this); 1294 // fTGui = new MTGui(this);1295 1316 1296 1317 lout << "- Starting GUI update." << endl; … … 1361 1382 lout << "- Starting GUI." << endl; 1362 1383 fWin=new MGCosy(this, gClient->GetRoot(), 1, 1); 1363 1364 fAz->SetDisplay(fWin->GetLabel1());1365 fZd1->SetDisplay(fWin->GetLabel2());1366 fZd2->SetDisplay(fWin->GetLabel3());1367 1368 lout.SetOutputGui(fWin->GetLog(), kTRUE);1369 1384 } 1370 1385 … … 1397 1412 lout << "- Starting GUI." << endl; 1398 1413 fWin=new MGCosy(this, gClient->GetRoot(), 1, 1); 1399 1400 fAz->SetDisplay(fWin->GetLabel1());1401 fZd1->SetDisplay(fWin->GetLabel2());1402 fZd2->SetDisplay(fWin->GetLabel3());1403 1404 lout.SetOutputGui(fWin->GetLog(), kTRUE);1405 1414 } 1406 1415 … … 1420 1429 lout << "- Starting GUI." << endl; 1421 1430 fWin=new MGCosy(this, gClient->GetRoot(), 1, 1); 1422 1423 lout.SetOutputGui(fWin->GetLog(), kTRUE);1424 1431 } 1425 1432 … … 1451 1458 } 1452 1459 1460 lout.SetOutputGui(fWin->GetLog(), kTRUE); 1461 1462 fZd1->SetDisplay(fWin->GetLabel2()); 1463 fZd2->SetDisplay(fWin->GetLabel3()); 1464 fAz->SetDisplay(fWin->GetLabel1()); 1465 1453 1466 int i=0; 1454 1467 char name[100]; … … 1503 1516 cout << "Deleting Nodes." << endl; 1504 1517 1505 if (fAz) delete fAz; 1506 if (fZd1) delete fZd1; 1507 if (fZd2) delete fZd2; 1508 if (fMac1) delete fMac1; 1509 if (fMac2) delete fMac2; 1510 if (fMac3) delete fMac3; 1518 delete fAz; 1519 delete fZd1; 1520 delete fZd2; 1521 delete fMac1; 1522 delete fMac2; 1523 if (fMac3) 1524 delete fMac3; 1511 1525 1512 1526 cout << "Deleting MGCosy." << endl;
Note:
See TracChangeset
for help on using the changeset viewer.