Ignore:
Timestamp:
08/15/01 12:39:04 (23 years ago)
Author:
tbretz
Message:
*** empty log message ***
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Cosy/MCosy.cc

    r808 r909  
    1414
    1515#include "macs.h"
    16 #include "timer.h"
     16#include "base/timer.h"
    1717#include "shaftencoder.h"
    1818
    19 #include <sys/resource.h>  // PRIO_PROCESS
     19#include "MGSkyPosition.h" // FIXME!!!!!!!!!!!!!!!!!
     20
     21//#include <sys/resource.h>  // PRIO_PROCESS
    2022
    2123typedef struct tm tm_t;
     
    121123        min = dist;
    122124    }
    123     cout << "Shortest Zd: " << ret.Zd() << "  Az:" << ret.Az() << endl;
    124125    return ret*(16384.0/360.0);
    125126}
     
    347348        {
    348349            lout << "Error 6004 happened" << endl;
    349             SkipPendingSdos();
    350350            break;
    351351        }
     
    393393        {
    394394            lout << "Error 3006 happened" << endl;
    395             SkipPendingSdos();
    396395            break;
    397396        }
     
    525524}
    526525
     526void *MTGui::Thread()
     527{
     528    fCosy->GuiThread(this);
     529    return NULL;
     530}
     531
     532void *MTTalk::Thread()
     533{
     534    fCosy->TalkThread();
     535    return NULL;
     536}
     537
    527538void MCosy::TalkThread()
    528539{
     
    530541    // Start the Network
    531542    //
    532     Network::Start();
     543    cout << "Reading configuration file..." << flush;
     544    TEnv env(".cosyrc");
     545    cout << "done." << endl;
    533546
    534547    const int res = fMac3->GetVelRes();
     
    538551    fMac3->SetDeceleration(res);
    539552
    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));
    544558    PostMsg(WM_PRESET, 0, 0);
    545559    PostMsg(WM_WAIT,   0, 0);
     
    551565    cout << "APOS: " << repos.Zd() << "re, " << repos.Az() << "re" << endl;
    552566
    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;
    564583
    565584/*
     
    567586    fMac2->SetPosEndswitch(Deg2ZdRE(env.GetValue("MaxZd[Deg]", +1.0)));
    568587*/
    569     fMac3->SetSyncMode();
     588//    fMac3->StartVelSync();
    570589/*
    571590    cout << "PostMsg(WM_PRESET)" << endl;
     
    588607    // dest = AltAz(-46.0, 210);
    589608    // SetPosition(dest);
    590     setpriority(PRIO_PROCESS, 0, 10);
    591609
    592610    Slalib sla;
     
    675693}
    676694
    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();
     695void 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
     714int MCosy::StopWaitingForSDO() const
     715{
     716    return Break() || HasError(); //fMac1->HasError() || fMac2->HasError();
    693717}
    694718
    695719void MCosy::Start()
    696720{
    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);
    707729}
    708730
    709731void MCosy::Stop()
    710732{
    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;
    722738
    723739    Network::Stop();
     
    725741
    726742MCosy::MCosy(const char *dev, const int baud, ostream &out)
    727 : Network(dev, baud, out), fTxThrd(NULL), fTracking(kFALSE)
     743: Network(dev, baud, out), fTracking(kFALSE)
    728744{
    729745    //
     
    747763    SetNode(fAz);
    748764
    749     MGCosy *fWin=new MGCosy(this, gClient->GetRoot(), 1, 1);
     765    fWin=new MGCosy(this, gClient->GetRoot(), 1, 1);
    750766
    751767    fAz->SetDisplay(fWin->GetLabel1());
     
    756772void MCosy::TerminateApp()
    757773{
    758    gSystem->ExitLoop();
     774    cout << "MCosy::TerminateApp()" << endl;
     775    gApplication->Terminate(0);
    759776}
    760777
    761778MCosy::~MCosy()
    762779{
     780    cout << "Deleting Nodes." << endl;
     781
    763782    delete fAz;
    764783    delete fAlt2;
     
    768787    delete fMac3;
    769788
     789    cout << "Deleting MGCosy." << endl;
     790
    770791    delete fWin;
    771 }
     792
     793    cout << "MGCosy deleted." << endl;
     794}
Note: See TracChangeset for help on using the changeset viewer.