Changeset 921 for trunk/MagicSoft/Cosy/MCosy.cc
- Timestamp:
- 08/30/01 16:02:20 (23 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Cosy/MCosy.cc
r920 r921 54 54 return rad*kGearRatio2.Y(); 55 55 } 56 57 //double Rad2Deg(double rad)58 //{59 // return 360.0/D2PI*rad;60 //}61 56 62 57 ZdAz MCosy::CorrectTarget(const ZdAz &src, const ZdAz &dst) … … 200 195 cout << "Waiting for positioning..." << flush; 201 196 202 WaitForSdos(); 203 204 cout << "SDO..." << flush; 205 206 while ((fMac1->IsPositioning() || fMac2->IsPositioning()) && !StopWaitingForSDO()) 207 usleep(1); 197 WaitForEndMovement(); 208 198 209 199 cout << "done." << endl; 210 211 SetStatus(kStopped);212 200 } 213 201 … … 215 203 { 216 204 if (!HasError()) 205 { 206 SetStatus(kStopped); 217 207 return; 208 } 218 209 219 210 SetStatus(kError); … … 228 219 int MCosy::SetPosition(const ZdAz &dst) // [rad] 229 220 { 230 // FIXME: C ORRECT BY fTrackingError !!!!!!!!!!221 // FIXME: Correct by fOffset ? 231 222 232 223 // … … 253 244 ZdAz rd = dest-p; // [se] 254 245 255 ZdAz cd = rd; // [se]246 ZdAz cd = rd; // [se] 256 247 cd.Round(); 257 248 … … 300 291 } 301 292 302 CheckForError(); 303 293 StopMovement(); 304 294 lout << "Warning: Requested position not reached." << endl; 305 295 return FALSE; … … 354 344 void MCosy::LimitSpeed(ZdAz *vt, const ZdAz &vcalc) const 355 345 { 356 return;357 358 346 // 359 347 // How to limit the speed. If the wind comes and blowes … … 367 355 #define sgn(x) (x<0?-1:1) 368 356 369 if (sgn(vt->Az()) != sgn(vcalc.Az())) 370 vt->Az(0.1*vcalc.Az()); 357 const Float_t limit = 0.25; 358 359 if (sgn(vt->Az()) != sgn(vcalc.Az()) && 360 fabs(vt->Az()) < limit*fabs(vcalc.Az())) 361 vt->Az(0); 371 362 else 372 363 if (fabs(vt->Az()) > 0.9*vraz) 373 364 vt->Az(0.9*vraz*sgn(vt->Az())); 374 365 375 if (sgn(vt->Zd()) != sgn(vcalc.Zd())) 376 vt->Zd(0.1*vcalc.Zd()); 366 if (sgn(vt->Zd()) != sgn(vcalc.Zd()) && 367 fabs(vt->Zd()) < limit*fabs(vcalc.Zd())) 368 vt->Zd(0); 377 369 else 378 370 if (fabs(vt->Zd()) > 0.9*vrzd) … … 392 384 if (!SetPosition(dest)) 393 385 { 394 lout << "E RROR: Cannot start tracking, unable to reach requested position." << endl;386 lout << "Error: Cannot start tracking, positioning failed." << endl; 395 387 return; 396 388 } … … 421 413 422 414 lout << "Start tracking:"; 423 lout << " Ra: " << Rad2Deg(dst.Ra()) << " deg";424 lout << "Dec: " << Rad2Deg(dst.Dec()) << " deg" << endl;415 lout << " Ra: " << Rad2Deg(dst.Ra()) << "\xb0 "; 416 lout << "Dec: " << Rad2Deg(dst.Dec()) << "\xb0" << endl; 425 417 426 418 // … … 431 423 432 424 ofstream fout("cosy.pos"); 433 fout << " Mjd/10ms V/re/min/4" << endl; 425 fout << "Tracking:"; 426 fout << " Ra: " << Rad2Deg(dst.Ra()) << "\x9c "; 427 fout << "Dec: " << Rad2Deg(dst.Dec()) << "\x9c" << endl << endl; 428 fout << " Mjd/10ms V/re/min/4" << endl; 434 429 435 430 // … … 450 445 dest = CorrectTarget(GetSePos(), sla.CalcZdAz(dst)); // [se] 451 446 452 //ZdAz vcalc = sla.GetApproxVel(dst) * kGearRatio2*4./60.; // [re/min]447 ZdAz vcalc = sla.GetApproxVel(dst) * kGearRatio2*4./60.; // [re/min] 453 448 454 449 // … … 478 473 // 479 474 ZdAz vt = v/4; 480 //LimitSpeed(&vt, vcalc);475 LimitSpeed(&vt, vcalc); 481 476 vt.Round(); 482 477 … … 484 479 // check if the drive is fast enough to follow the star 485 480 // 486 if (v .Zd()>.9*fMac1->GetVelRes() || v.Az()>.9*fMac2->GetVelRes())481 if (vt.Zd()>.9*fMac1->GetVelRes() || vt.Az()>.9*fMac2->GetVelRes()) 487 482 { 488 lout << "Error: Tracking speed faster than possible maximum velocity." << endl;483 lout << "Error: Tracking speed faster than 90% of possible maximum velocity." << endl; 489 484 break; 490 485 } … … 506 501 fout << setw(4) << vt.Zd() << " "; 507 502 fout << setw(4) << vt.Az() << endl; 503 // 504 // FIXME? Calculate an accuracy for the tracking system? 505 // How good do we reach the calculated position in 'real' 506 // re valus? 507 // 508 508 509 509 510 // … … 516 517 517 518 fTracking = kFALSE; 518 519 // 520 // Stop revolution mode 521 // 519 StopMovement(); 520 lout << "Tracking stopped." << endl; 521 } 522 523 int MCosy::IsPositioning() const 524 { 525 return (fMac1->IsPositioning() || fMac2->IsPositioning()) && !StopWaitingForSDO(); 526 } 527 528 void MCosy::WaitForEndMovement() 529 { 530 WaitForSdos(); 531 532 while (IsPositioning()) 533 usleep(1); 534 } 535 536 void MCosy::StopMovement() 537 { 522 538 SetStatus(kStopping); 523 539 540 cout << "Stopping positioning..." << endl; 541 fMac1->SetDeceleration(0.5*fMac1->GetVelRes()); 542 fMac2->SetDeceleration(0.5*fMac2->GetVelRes()); 543 544 cout << "Stoping possible RPM mode..." << endl; 545 fMac1->SetRpmMode(FALSE); 524 546 fMac2->SetRpmMode(FALSE); 525 fMac1->SetRpmMode(FALSE); 526 527 SetStatus(kStopped); 528 529 lout << "Tracking stopped." << endl; 547 548 cout << "Waiting for silence..." << endl; 549 WaitForEndMovement(); 530 550 531 551 CheckForError(); 552 553 cout << "Movement stopped." << endl; 532 554 } 533 555 … … 541 563 542 564 case WM_STOP: 543 cout << "Stopping positioning..." << endl; 544 SetStatus(kStopping); 545 fMac1->SetDeceleration(0.5*fMac1->GetVelRes()); 546 fMac2->SetDeceleration(0.5*fMac2->GetVelRes()); 547 cout << "Stoping possible RPM mode..." << endl; 548 fMac1->SetRpmMode(FALSE); 549 fMac2->SetRpmMode(FALSE); 550 cout << "Stopping commands sent." << endl; 551 while (fMac1->IsPositioning() || fMac2->IsPositioning()) 552 usleep(1); 553 SetStatus(kStopped); 554 cout << "Positioning stopped." << endl; 565 StopMovement(); 555 566 return NULL; 556 567 … … 698 709 // wait until a tracking session is started 699 710 // 700 while (!fTracking )711 while (!fTracking && !fTTalk->HasStopFlag()) 701 712 usleep(1); 702 713 714 if (fTTalk->HasStopFlag()) 715 break; 716 717 ofstream fout("cosy.err"); 718 fout << "Tracking:"; 719 fout << " Ra: " << Rad2Deg(fRaDec.Ra()) << "\x9c "; 720 fout << "Dec: " << Rad2Deg(fRaDec.Dec()) << "\x9c" << endl << endl; 721 fout << " MjdZd/10ms ErrZd/re"; 722 fout << " MjdAz/10ms ErrAd/re" << endl; 723 703 724 ZdAz old; 704 ZdAz ist = fTrackingError/kGearRatio; // [se] 705 ZdAz istre = fOffset; // [re] 706 707 // 708 // only update fTrackingError while tracking 709 // 725 ZdAz ist; 726 710 727 ZdAz sollzd; 711 728 ZdAz sollaz; 712 while (fTracking) 729 730 ZdAz istre = -fOffset; // [re] 731 ZdAz time; 732 733 // 734 // only update fTrackingError while tracking 735 // 736 while (fTracking && !fTTalk->HasStopFlag()) 713 737 { 738 // 739 // Make changes (eg wind) smoother - attenuation of control function 740 // 741 const float weight = 0.3; 742 743 ZdAz offset(fOffset.Zd()*(1.-weight)+(ist.Zd()*kGearRatio.X()-istre.Zd())*weight, 744 fOffset.Az()*(1.-weight)+(ist.Az()*kGearRatio.Y()-istre.Az())*weight); 745 746 fOffset = offset; 747 714 748 // 715 749 // This is the time constant which defines how fast … … 719 753 720 754 // 721 // Make changes (eg wind) smoother - attenuation of control function722 //723 fTrackingError.Set((ist.Zd()-sollzd.Zd())*kGearRatio.X(),724 (ist.Az()-sollaz.Az())*kGearRatio.Y());725 726 727 const float weight = 0.3;728 729 ZdAz offset(fOffset.Zd()*(1.-weight)+(ist.Zd()*kGearRatio.X()-istre.Zd())*weight,730 fOffset.Az()*(1.-weight)+(ist.Az()*kGearRatio.Y()-istre.Az())*weight);731 732 fOffset = offset;733 // fTrackingError.Zd(((offset.Zd()>1000)||(offset.Zd()<-1000))?0:offset.Zd());734 // fTrackingError.Az(((offset.Az()>1000)||(offset.Az()<-1000))?0:offset.Az());735 736 //737 755 // get position, where we are 738 756 // 757 old = ist; 739 758 ist = GetSePos(); // [se] 740 759 … … 750 769 // 751 770 // Get time from last shaftencoder position change (position: ist) 752 // 753 const double tzd = (fAlt1->GetMjd()+fAlt2->GetMjd())/2.0; 754 const double taz = fAz->GetMjd(); 771 // FIXME: I cannot take the avarage 772 // 773 time.Zd((fAlt1->GetMjd()+fAlt2->GetMjd())/2.0); 774 time.Az(fAz->GetMjd()); 755 775 756 776 // … … 760 780 if ((int)ist.Zd() != (int)old.Zd()) 761 781 { 762 sla.SetMjd(t zd);782 sla.SetMjd(time.Zd()); 763 783 sollzd = CorrectTarget(ist, sla.CalcZdAz(fRaDec)); // [se] 764 784 } … … 766 786 if ((int)ist.Az() != (int)old.Az()) 767 787 { 768 sla.SetMjd(t az);788 sla.SetMjd(time.Az()); 769 789 sollaz = CorrectTarget(ist, sla.CalcZdAz(fRaDec)); // [se] 770 790 } 771 791 772 old = ist; 792 fTrackingError.Set((ist.Zd()-sollzd.Zd())*kGearRatio.X(), 793 (ist.Az()-sollaz.Az())*kGearRatio.Y()); 794 795 fout << setprecision(15) << setw(15) << time.Zd()*60.*60.*24. << " "; 796 fout << setprecision(5) << setw(5) << fTrackingError.Zd() << " "; 797 fout << setprecision(15) << setw(15) << time.Az()*60.*60.*24. << " "; 798 fout << setprecision(5) << setw(5) << fTrackingError.Az() << endl; 773 799 } 800 801 fout << endl << endl; 774 802 } 775 803 } … … 814 842 void MCosy::Stop() 815 843 { 816 cout << "- Stopping GUI update." << endl; 844 845 lout << "- Stopping GUI update." << endl; 817 846 fUpdateGui->TurnOff(); 818 // delete fTGui; 819 lout << "- GUI Thread stopped." << endl; 847 lout << "- GUI Update stopped." << endl; 820 848 821 849 delete fTTalk;
Note:
See TracChangeset
for help on using the changeset viewer.