Changeset 909 for trunk/MagicSoft/Cosy/MCosy.cc
- Timestamp:
- 08/15/01 12:39:04 (23 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Cosy/MCosy.cc
r808 r909 14 14 15 15 #include "macs.h" 16 #include " timer.h"16 #include "base/timer.h" 17 17 #include "shaftencoder.h" 18 18 19 #include <sys/resource.h> // PRIO_PROCESS 19 #include "MGSkyPosition.h" // FIXME!!!!!!!!!!!!!!!!! 20 21 //#include <sys/resource.h> // PRIO_PROCESS 20 22 21 23 typedef struct tm tm_t; … … 121 123 min = dist; 122 124 } 123 cout << "Shortest Zd: " << ret.Zd() << " Az:" << ret.Az() << endl;124 125 return ret*(16384.0/360.0); 125 126 } … … 347 348 { 348 349 lout << "Error 6004 happened" << endl; 349 SkipPendingSdos();350 350 break; 351 351 } … … 393 393 { 394 394 lout << "Error 3006 happened" << endl; 395 SkipPendingSdos();396 395 break; 397 396 } … … 525 524 } 526 525 526 void *MTGui::Thread() 527 { 528 fCosy->GuiThread(this); 529 return NULL; 530 } 531 532 void *MTTalk::Thread() 533 { 534 fCosy->TalkThread(); 535 return NULL; 536 } 537 527 538 void MCosy::TalkThread() 528 539 { … … 530 541 // Start the Network 531 542 // 532 Network::Start(); 543 cout << "Reading configuration file..." << flush; 544 TEnv env(".cosyrc"); 545 cout << "done." << endl; 533 546 534 547 const int res = fMac3->GetVelRes(); … … 538 551 fMac3->SetDeceleration(res); 539 552 540 fMac3->SetSyncMode(); 541 542 fMac1->SetHome(250000); 543 fMac2->SetHome(250000); 553 fMac3->StartPosSync(); 554 555 cout << "Going Home..." << endl; 556 fMac1->SetHome(250000, env.GetValue("Az_MaxTime2ReachHome[s]", 100)); 557 fMac2->SetHome(250000, env.GetValue("Zd_MaxTime2ReachHome[s]", 100)); 544 558 PostMsg(WM_PRESET, 0, 0); 545 559 PostMsg(WM_WAIT, 0, 0); … … 551 565 cout << "APOS: " << repos.Zd() << "re, " << repos.Az() << "re" << endl; 552 566 553 TEnv env(".cosyrc"); 554 555 cout << Deg2AzRE(env.GetValue("MinAz[Deg]", -1.0)) << " < Az < " 556 << Deg2AzRE(env.GetValue("MaxAz[Deg]", +1.0)) << "RE" << endl; 557 cout << env.GetValue("MinAz[Deg]", -1.0) << " < Az < " 558 << env.GetValue("MaxAz[Deg]", +1.0) << kDEG << endl; 559 cout << Deg2ZdRE(env.GetValue("MinZd[Deg]", -1.0)) << "RE < Zd < " 560 << Deg2ZdRE(env.GetValue("MaxZd[Deg]", +1.0)) << "RE" << endl; 561 562 fMac1->SetNegEndswitch(Deg2AzRE(env.GetValue("MinAz[Deg]", -1.0))); 563 fMac1->SetPosEndswitch(Deg2AzRE(env.GetValue("MaxAz[Deg]", +1.0))); 567 /* 568 cout << Deg2AzRE(env.GetValue("MinAz[Deg]", -1.0)) << " < Az < " 569 << Deg2AzRE(env.GetValue("MaxAz[Deg]", +1.0)) << "RE" << endl; 570 cout << env.GetValue("MinAz[Deg]", -1.0) << " < Az < " 571 << env.GetValue("MaxAz[Deg]", +1.0) << kDEG << endl; 572 cout << Deg2ZdRE(env.GetValue("MinZd[Deg]", -1.0)) << "RE < Zd < " 573 << Deg2ZdRE(env.GetValue("MaxZd[Deg]", +1.0)) << "RE" << endl; 574 */ 575 576 cout << "Setting up software endswitch..." << flush; 577 fMac1->SetNegEndswitch(Deg2AzRE(env.GetValue("Az_Min[Deg]", -1.0))); 578 fMac1->SetPosEndswitch(Deg2AzRE(env.GetValue("Az_Max[Deg]", +1.0))); 579 580 fMac2->SetNegEndswitch(Deg2ZdRE(env.GetValue("Zd_Min[Deg]", -1.0))); 581 fMac2->SetPosEndswitch(Deg2ZdRE(env.GetValue("Zd_Max[Deg]", +1.0))); 582 cout << "done." << endl; 564 583 565 584 /* … … 567 586 fMac2->SetPosEndswitch(Deg2ZdRE(env.GetValue("MaxZd[Deg]", +1.0))); 568 587 */ 569 fMac3->SetSyncMode();588 // fMac3->StartVelSync(); 570 589 /* 571 590 cout << "PostMsg(WM_PRESET)" << endl; … … 588 607 // dest = AltAz(-46.0, 210); 589 608 // SetPosition(dest); 590 setpriority(PRIO_PROCESS, 0, 10);591 609 592 610 Slalib sla; … … 675 693 } 676 694 677 void *MCosy::MapTalkThread(void *arg) 678 { 679 pthread_detach(pthread_self()); 680 681 MCosy *cosy = (MCosy*)arg; 682 683 cosy->TalkThread(); 684 685 cosy->lout << "- Sending Thread done." << endl; 686 687 return NULL; 688 } 689 690 int MCosy::StopWaitingForSDO() 691 { 692 return Break() || fMac1->HasError() || fMac2->HasError(); 695 void MCosy::GuiThread(MTGui *t) 696 { 697 MGSkyPosition *disp = fWin->GetSkyDisplay(); 698 while (!t->HasStopFlag()) 699 { 700 usleep(100000); // 0.1s 701 702 fAlt1->DisplayVal(); 703 fAlt2->DisplayVal(); 704 fAz->DisplayVal(); 705 706 // gSystem->ProcessEvents(); 707 708 ZdAz ist = GetSePos()*(360.0/16384.0); // [se] 709 disp->DrawPosition(ist); 710 } 711 cout << "Not running anymore." << endl; 712 } 713 714 int MCosy::StopWaitingForSDO() const 715 { 716 return Break() || HasError(); //fMac1->HasError() || fMac2->HasError(); 693 717 } 694 718 695 719 void MCosy::Start() 696 720 { 697 if (fTxThrd) 698 { 699 cout << "Error: tx thread already started." << endl; 700 return; 701 } 702 703 lout << "- Starting sending Thread." << endl; 704 705 fTxThrd = new pthread_t; 706 pthread_create(fTxThrd, NULL, MapTalkThread, this); 721 // Don't call this function twice! 722 Network::Start(); 723 724 lout << "- Starting TX Thread." << endl; 725 fTTalk = new MTTalk(this); 726 727 lout << "- Starting GUI Thread." << endl; 728 fTGui = new MTGui(this); 707 729 } 708 730 709 731 void MCosy::Stop() 710 732 { 711 if (!fTxThrd) 712 return; 713 714 pthread_cancel(*fTxThrd); 715 716 delete fTxThrd; 717 fTxThrd = NULL; 718 719 lout << "- Sending Thread stopped." << endl; 720 721 SkipPendingSdos(); 733 delete fTGui; 734 lout << "- GUI Thread stopped." << endl; 735 736 delete fTTalk; 737 lout << "- TX Thread stopped." << endl; 722 738 723 739 Network::Stop(); … … 725 741 726 742 MCosy::MCosy(const char *dev, const int baud, ostream &out) 727 : Network(dev, baud, out), fT xThrd(NULL), fTracking(kFALSE)743 : Network(dev, baud, out), fTracking(kFALSE) 728 744 { 729 745 // … … 747 763 SetNode(fAz); 748 764 749 MGCosy *fWin=new MGCosy(this, gClient->GetRoot(), 1, 1);765 fWin=new MGCosy(this, gClient->GetRoot(), 1, 1); 750 766 751 767 fAz->SetDisplay(fWin->GetLabel1()); … … 756 772 void MCosy::TerminateApp() 757 773 { 758 gSystem->ExitLoop(); 774 cout << "MCosy::TerminateApp()" << endl; 775 gApplication->Terminate(0); 759 776 } 760 777 761 778 MCosy::~MCosy() 762 779 { 780 cout << "Deleting Nodes." << endl; 781 763 782 delete fAz; 764 783 delete fAlt2; … … 768 787 delete fMac3; 769 788 789 cout << "Deleting MGCosy." << endl; 790 770 791 delete fWin; 771 } 792 793 cout << "MGCosy deleted." << endl; 794 }
Note:
See TracChangeset
for help on using the changeset viewer.