Changeset 1275 for trunk


Ignore:
Timestamp:
04/12/02 16:59:23 (23 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Cosy
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Cosy/Changelog

    r1266 r1275  
    11                                                                  -*-*- END -*-*-
     2
     3 2002/04/12 - Thomas Bretz:
     4
     5   * Makefile.conf.linux-gnu:
     6     - added -D_REENTRANT
     7
     8   * base/MThread.cc:
     9     - added debug output
     10
     11   * candrv/canopen.cc:
     12     - added debug output to destructor
     13
     14   * candrv/vmodican.cc:
     15     - added debug output to failing read
     16     - added some general debug output
     17
     18   * catalog/SlaStars.[h,cc]:
     19     - added CalcRaDecFast
     20     - added Calc*AzFast
     21     - added some comments
     22
     23   * devdrv/macs.cc:
     24     - added some HandleSDOOK output
     25     - changed timer frequency to Guard Time third instead of half
     26     - added some degub output
     27     - changed timer to single shot timer
     28     - switched off Mac timeout handling!!!
     29
     30   * gui/MGCosy.cc:
     31     - added demo mode for 'Tag-der-Physik'
     32
     33   * gui/MGSkyPosition.cc:
     34     - changed 'dots' to fast calculation functions
     35
     36   * gui/MGEmbeddedCanvas.cc:
     37     - added some output
     38     - fixed a bug with zero range
     39
     40   * main/MCosy.[h,cc]:
     41     - added and changed some output
     42     - changed LimitSpeed
     43     - changed TalkThread
     44       + only change offset when a new value for this axis is available
     45       + reset the HasChanged flag before testing it
     46
     47
     48
     49 2002/04/11 - Thomas Bretz:
     50 
     51   * base/MThread.[h,cc]:
     52     - added priority to constructor
     53
     54   * base/coord.h:
     55     - added setter functions to RaDec
     56
     57   * base/msgqueue.[h,cc]:
     58     - added some comments
     59
     60   * candrv/network.cc:
     61     - HasError now checks all nodes
     62
     63   * candrv/nodedrv.[h,cc]:
     64     - fixed some buggy output
     65
     66   * candrv/vmodican.cc:
     67     - removed nonsens SetPriority (doesn't have any effect)
     68
     69   * gui/MGCosy.cc:
     70     - replaced colors by the correct requested colors
     71
     72   * gui/MGSkyPosition.[h,cc]:
     73     - added dots for the position in the past and future
     74
     75
    276
    377 2002/04/04 - Thomas Bretz:
  • trunk/MagicSoft/Cosy/Makefile.conf.linux-gnu

    r909 r1275  
    2020#
    2121
    22 OPTIM    = -O2 -Wall -fno-rtti -fno-exceptions -fPIC -Wtraditional -Wpointer-arith -Wcast-align -Wwrite-strings -Wconversion -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Woverloaded-virtual
     22OPTIM    = -O2 -Wall -fno-rtti -fno-exceptions -fPIC -Wtraditional -Wpointer-arith -Wcast-align -Wwrite-strings -Wconversion -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Woverloaded-virtual -D_REENTRANT
    2323DEBUG    = -g
    2424
  • trunk/MagicSoft/Cosy/base/MThread.cc

    r1273 r1275  
    11#include <MThread.h>
     2
     3#include <iostream.h>
    24
    35#include <pthread.h>
     
    1214MThread::MThread(bool start, int prio) : fIsRunning(false), fIsDetached(false), fThread(NULL), fReturn(NULL)
    1315{
    14     if (start)
    15     {
    16         SetPriority(prio);
    17         Start();
    18     }
     16    if (!start)
     17        return;
     18
     19    SetPriority(prio);
     20    Start();
    1921}
    2022
     
    2729MThread::~MThread()
    2830{
    29     if (fIsRunning)
    30         Stop();
     31    cout << "~MThread::MThread" << endl;
     32    Stop();
    3133}
    3234
     
    120122void MThread::Stop()
    121123{
     124    cout << "MThread::Stop: fThread=" << fThread << ", fIsRunning=" << (int)fIsRunning << endl;
    122125    if (!fThread || !fIsRunning)
    123126        return;
     
    125128    if (fIsDetached)
    126129    {
     130        cout << "Stopping detached thread..." << flush;
    127131        pthread_cancel(*fThread);
    128132        fIsRunning = false;
     
    130134    else
    131135    {
     136        cout << "Stopping thread..." << flush;
    132137        fStop = true;
    133138        pthread_join(*fThread, &fReturn);
    134139    }
     140    cout << "done." << endl;
    135141
    136142    delete fThread;
    137143    fThread = NULL;
     144
     145    cout << "MThread::Stop() done." << endl;
    138146}
  • trunk/MagicSoft/Cosy/base/msgqueue.cc

    r1273 r1275  
    66#include <sys/resource.h>  // PRIO_PROCESS
    77
     8// --------------------------------------------------------------------------
     9//
     10// This creates the Message queue thread,
     11//
    812MsgQueue::MsgQueue() : fBreak(0)
    913{
     
    1216}
    1317
     18// --------------------------------------------------------------------------
     19//
     20// The destructor terminates the thread.
     21//
    1422MsgQueue::~MsgQueue()
    1523{
     24    cout << "~MsgQueue::MsgQueue" << endl;
    1625    pthread_cancel(fThread);
    1726    delete (unsigned char*)fMp;
    1827}
    1928
     29// --------------------------------------------------------------------------
     30//
     31// This is the function which must be overloaded.
     32// Here you process the messages. mp is a pointer which you can
     33// specify when posting the message.
     34//
     35// If a new messages is posted while the old one is not yet
     36// finished the fBreak flag is set. Please test this flag with
     37// Break() and try to finish (or stop) the current action as soon
     38// as possible. This makes sure, that before a new action is started
     39// the old action can be finished correctly by the user.
     40//
    2041void *MsgQueue::Proc(int msg, void *mp)
    2142{
     
    2344}
    2445
     46// --------------------------------------------------------------------------
     47//
     48// This is the thread mapper.
     49//
    2550void *MsgQueue::MapThread(void *arg)
    2651{
     
    3459}
    3560
     61// --------------------------------------------------------------------------
     62//
     63// This is the thread which handles the processing.
     64// As soon as a message is posted the fBreak flag is set (see PostMsg)
     65// And as soon as the current action is finished the new action is executed
     66// in this thread. This makes sure, that the calling program is not stalled.
     67//
    3668void MsgQueue::Thread()
    3769{
     
    5688        pthread_mutex_unlock(&fMuxMsg);
    5789
     90        cout << "Processing Msg 0x" << hex << fMsg << endl;
     91        // --- bool quit = fMsg==WM_QUIT;
    5892        fRc=Proc(fMsg, fMp);
     93        cout << "Msg 0x" << hex << fMsg << " processed." << endl;
    5994
    60         if (fMsg==WM_QUIT)
    61             break;
     95        // --- if (quit)
     96        // ---    break;
     97    }
    6298
    63     }
     99    // --- fStart = 0;
     100    // --- cout << "WM_QUIT posted... leaving msg queue." << endl;
    64101}
    65102
     103// --------------------------------------------------------------------------
     104//
     105// Use this function to post a message.
     106// mp can be a pointer to a data structure. size should be the size of it.
     107// size bytes of this structure are copied and a pointer to the copy
     108// is forwarded to the Proc function.
     109//
    66110void *MsgQueue::PostMsg(int msg, void *mp, int size)
    67111{
     
    74118    // stopped and the messages are processed serialized
    75119    //
     120    cout << "Locking MsgQueue mutex..." << flush;
    76121    pthread_mutex_lock(&fMuxMsg);
     122    cout << "done." << endl;
    77123
    78124    //
     
    101147    //
    102148    fStart = 1;
     149    cout << "Releasing MsgQueue mutex..." << flush;
    103150    pthread_mutex_unlock(&fMuxMsg);
    104     while (fStart) usleep(1);
     151    cout << "done." << endl;
     152    while (fStart)
     153        usleep(1);
    105154
     155    cout << "Returning rc = 0x" << hex << rc << endl;
    106156    return rc;
    107157}
  • trunk/MagicSoft/Cosy/candrv/canopen.cc

    r1266 r1275  
    6767            pthread_mutex_destroy(&fPdoMux[i][j]);
    6868        }
     69    lout << "- CanOpen destroyed." << endl;
    6970}
    7071
  • trunk/MagicSoft/Cosy/candrv/vmodican.cc

    r1273 r1275  
    3838#include <errno.h>         // errno
    3939#include <unistd.h>        // read
    40 #include <pthread.h>       // pthread_create
    4140#include <sys/time.h>      // gettimeofday
    4241#include <sys/ioctl.h>     // ioctl
    43 #include <sys/resource.h>  // PRIO_PROCESS
    4442
    4543ClassImp(VmodIcan);
     
    110108    while (1)
    111109    {
     110        //
     111        // Sleeps until a message arrives
     112        //
    112113        unsigned char c;
     114        const int n = read(fd, &c, 1);
     115
     116        if (n<0)
     117        {
     118            cerr << "Vmodican: read(" << dec << (int)fd << "," << (void*)&c;
     119            cerr << ",1) returned c=" << (int)c << " '" << strerror(errno);
     120            cerr << "' (errno = " << errno << ")" << endl;
     121            continue;
     122            //return (void *)1;
     123        }
     124
     125        //
     126        // read the time for the message as soon as possible
     127        //
    113128        timeval_t tv;
    114 
    115         //
    116         // Sleeps until a message arrives
    117         //
    118         const int n = read(fd, &c, 1);
    119 
    120         //
    121         // read the time for the message as soon as possible
    122         //
    123129        gettimeofday(&tv, NULL);
    124130
     
    128134        if (n == 0)
    129135        {
    130             cerr << "panic read (errno=" << errno << ") ..." << endl;
     136            cerr << "Vmodican: Panic read '" << strerror(errno) << "' ";
     137            cerr << "(errno=" << errno << ")" << endl;
    131138            return (void *)1;
    132139        }
     
    155162
    156163            cout << endl;
    157             break;
     164            continue;
    158165
    159166        //
     
    171178
    172179            HandleMessage(&msg, &tv);
    173 
    174             break;
     180            continue;
    175181        }
     182
     183        cout << "Vmodican: read, Message c=" << (int)c << " unknown." << endl;
    176184    }
    177185    return NULL;
     
    495503void VmodIcan::DisableCanBusConnection()
    496504{
    497     lout << "- Disconnect from Bus!" << endl;
     505    lout << "- Disconnect VmodIcan module from Bus!" << endl;
    498506
    499507    Message msg;                  /* buffer for module messages */
     
    503511
    504512    while (!Send(&msg));
     513
     514    lout << "- VmodIcan disconnected." << endl;
    505515}
    506516
     
    529539void VmodIcan::Close()
    530540{
    531     lout << "- Close Device!" << endl;
     541    lout << "- Closing device VmodIcan #" << (int)fd << endl;
    532542
    533543    Message msg; /* disconnect message */
     
    539549
    540550    close(fd);
     551
     552    lout << "- Device closed." << endl;
    541553}
    542554
     
    950962VmodIcan::~VmodIcan()
    951963{
     964    lout << "- Stopping VmodIcan module." << endl;
    952965    Stop();
    953966    DisableCanBusConnection();
    954967    Close();
     968    lout << "- VmodIcan stopped." << endl;
    955969}
    956970
  • trunk/MagicSoft/Cosy/catalog/SlaStars.cc

    r1109 r1275  
    4040    slaMappa(2000.0, mjd, fAmprms);
    4141    slaAoppa(mjd, 0,                    // mjd, UT1-UTC
    42              GetElong(), GetPhi(), 148, // g”ttingen long, lat, height
     42             GetElong(), GetPhi(), 148, // göttingen long, lat, height
    4343             0, 0,                      // polar motion x, y-coordinate (radians)
    4444             273.155, 1013.25, 0.5,     // temp, pressure, humidity
     
    6969
    7070    return RaDec(ra, dec);
     71}
     72
     73RaDec SlaStars::CalcRaDecFast(const AltAz &altaz) const
     74{
     75    //
     76    // This function does a coordinate system transformation only.
     77    // This is very fast compared to a correct tranformation with all
     78    // effects, but much less accurate.
     79    //
     80    // It transforms Altitude/Azimuth [rad] into
     81    // Right Ascension/Declination [rad]
     82    //
     83    double ha, dec;
     84    slaDh2e(altaz.Az(), altaz.Alt(), GetPhi(), &ha, &dec);
     85    return RaDec(GetAlpha()-ha, dec);
     86}
     87
     88RaDec SlaStars::CalcRaDecFast(const ZdAz &zdaz) const
     89{
     90    //
     91    // This function does a coordinate system transformation only.
     92    // This is very fast compared to a correct tranformation with all
     93    // effects, but much less accurate.
     94    //
     95    // It transforms Zenith Distance/Azimuth [rad] into
     96    // Right Ascension/Declination [rad]
     97    //
     98    return CalcRaDecFast(AltAz(kPiDiv2-zdaz.Zd(), zdaz.Az()));
     99}
     100
     101ZdAz SlaStars::CalcZdAzFast(const RaDec &radec) const
     102{
     103    //
     104    // This function does a coordinate system transformation only.
     105    // This is very fast compared to a correct tranformation with all
     106    // effects, but much less accurate.
     107    //
     108    // It transforms Right Ascension/Declination [rad] into
     109    // zenith Distance/Azimuth [rad]
     110    //
     111    AltAz altaz = CalcAltAzFast(radec);
     112    return ZdAz(kPiDiv2-altaz.Alt(), altaz.Az());
     113}
     114
     115AltAz SlaStars::CalcAltAzFast(const RaDec &radec) const
     116{
     117    //
     118    // This function does a coordinate system transformation only.
     119    // This is very fast compared to a correct tranformation with all
     120    // effects, but much less accurate.
     121    //
     122    // It transforms Right Ascension/Declination [rad] into
     123    // Altitude/Azimuth [rad]
     124    //
     125    double az, el;
     126    slaDe2h(GetAlpha()-radec.Ra(), radec.Dec(), GetPhi(), &az, &el);
     127    return AltAz(el, az);
    71128}
    72129
  • trunk/MagicSoft/Cosy/devdrv/macs.cc

    r1140 r1275  
    99
    1010ClassImp(Macs);
     11
     12/*
     13 ---------------------------
     14 For test purposes
     15 ---------------------------
     16
     17class MyTimer : public TTimer
     18{
     19public:
     20    MyTimer(TObject *obj, Long_t ms, Bool_t mode) : TTimer(obj, ms, mode) {}
     21    Bool_t Notify()
     22    {
     23        cout << "Notify" << endl;
     24        TTimer::Notify();
     25        return kTRUE;
     26    }
     27};
     28*/
    1129
    1230Macs::Macs(const BYTE_t nodeid, const char *name, MLog &out)
     
    1533    fPosActive(0), fRpmActive(0)
    1634{
    17     fTimeout = new TTimer(this, 100, kFALSE); // 100ms
     35    fTimeout = new TTimer(this, 100, kFALSE); // 100ms, asynchronous
    1836}
    1937
     
    102120void Macs::HandleSDOOK(WORD_t idx, BYTE_t subidx)
    103121{
    104     if (idx==0x4000 && subidx==0 && fTimerOn)
    105     {
    106         ResetTimeout();
    107         return;
     122    switch (idx)
     123    {
     124    case 0x2002:
     125        switch (subidx)
     126        {
     127        case 0:
     128            lout << ddev(MLog::eGui);
     129            lout << "- Velocity set (" << GetNodeName() << ")" << endl;
     130            lout << edev(MLog::eGui);
     131            return;
     132        }
     133        break;
     134    case 0x2003:
     135        switch (subidx)
     136        {
     137        case 0:
     138            lout << ddev(MLog::eGui);
     139            lout << "- Acceleration set (" << GetNodeName() << ")" << endl;
     140            lout << edev(MLog::eGui);
     141            return;
     142        case 1:
     143            lout << ddev(MLog::eGui);
     144            lout << "- Deceleration set (" << GetNodeName() << ")" << endl;
     145            lout << edev(MLog::eGui);
     146            return;
     147        }
     148        break;
     149    case 0x3006:
     150        switch (subidx)
     151        {
     152        case 0:
     153            lout << ddev(MLog::eGui);
     154            lout << "- RPM mode switched (" << GetNodeName() << ")" << endl;
     155            lout << edev(MLog::eGui);
     156            return;
     157
     158        case 1:
     159            /*
     160             lout << ddev(MLog::eGui);
     161             lout << "- Velocity set (" << GetNodeName() << ")" << endl;
     162             lout << edev(MLog::eGui);
     163             */
     164            return;
     165        }
     166        break;
     167    case 0x4000:
     168        if (subidx==0 && fTimerOn)
     169        {
     170            ResetTimeout();
     171            return;
     172        }
     173        break;
     174    case 0x6004:
     175        switch (subidx)
     176        {
     177        case 0:
     178            lout << ddev(MLog::eGui);
     179            lout << "- Relative positioning started (" << GetNodeName() << ")" << endl;
     180            lout << edev(MLog::eGui);
     181            return;
     182
     183        case 1:
     184            lout << ddev(MLog::eGui);
     185            lout << "- Absolute positioning started (" << GetNodeName() << ")" << endl;
     186            lout << edev(MLog::eGui);
     187            return;
     188        }
     189        break;
     190
     191
    108192    }
    109193    NodeDrv::HandleSDOOK(idx, subidx);
     
    348432    if (!errnum)
    349433    {
    350         cout << "Mac " << GetNodeName() << " reports Error occursion." << endl;
     434        lout << "Mac " << GetNodeName() << " reports Error occursion." << endl;
    351435        SetError(-1);
    352436        return;
     
    358442    //
    359443    if (GetError()>0)
    360         cout << "Mac " << GetNodeName() << " WARNING! Error #" << GetError() << " unhandled by software." << endl;
     444        lout << GetNodeName() << " WARNING! Error #" << GetError() << " unhandled by software." << endl;
    361445
    362446    SetError(errnum);
    363447
    364     cout << "Mac " << GetNodeName() << " reports: ";
     448    lout << GetNodeName() << " reports: ";
    365449    switch (errnum)
    366450    {
    367451    case 6:
    368         cout << "Home position not the first positioning command." << endl;
     452        lout << "Home position not the first positioning command." << endl;
    369453        return;
    370454
    371455    case 8:
    372         cout << "Control deviation overflow." << endl;
     456        lout << "Control deviation overflow." << endl;
    373457        return;
    374458
    375459    case 9:
    376         cout << "Zero index not found." << endl;
     460        lout << "Zero index not found." << endl;
    377461        return;
    378462
     
    382466        {
    383467        case -1:
    384             cout << "Negative";
     468            lout << "Negative";
    385469            break;
    386470        case 1:
    387             cout << "Positive";
     471            lout << "Positive";
    388472            break;
    389473        default:
    390             cout << "-unknown-";
     474            lout << "-unknown-";
    391475        }
    392476        switch (errnum)
    393477        {
    394478        case 11:
    395             cout << " software endswitch activated." << endl;
     479            lout << " software endswitch activated." << endl;
    396480            break;
    397481        case 25:
    398             cout << " hardware endswitch activated." << endl;
     482            lout << " hardware endswitch activated." << endl;
    399483            break;
    400484        }
     
    402486
    403487    case 84:
    404         cout << "Too many (>12) ON TIME calls." << endl;
     488        lout << "Too many (>12) ON TIME calls." << endl;
    405489        return;
    406490
    407491    case 100:
    408         cout << "Connection timed out." << endl;
     492        lout << "Connection timed out." << endl;
    409493        return;
    410494
    411495    default:
    412         cout << "Error Nr. " << errnum << ", " << errinf << endl;
     496        lout << "Error Nr. " << errnum << ", " << errinf << endl;
    413497    }
    414498}
     
    436520    // we can go on working 'as usual' Eg. Initialize a Display Update
    437521    //
    438     cout << "Mac " << GetNodeName() << " Handling Error #" << GetError() << endl;
     522    cout << GetNodeName() << " Handling Error #" << GetError() << endl;
    439523    switch (GetError())
    440524    {
     
    525609
    526610        fTimerOn = kTRUE;
    527         fTimeout->Start(fGuardTime, kFALSE); //kTRUE);
    528 
    529         SendSDO(0x4000, 1, string('o', 'n'));
    530         WaitForSdo(0x4000, 1);
     611        fTimeout->Start(fGuardTime/*/3*2*/, kTRUE); //kFALSE); //TRUE);
     612        //
     613        // Start with kFALSE would be a continous timer, but this
     614        // timer seems to stop it's activity at some stage without
     615        // any reason
     616        //
     617
     618//        SendSDO(0x4000, 1, string('o', 'n'));
     619//        WaitForSdo(0x4000, 1);
    531620    }
    532621    lout << "- Timeout timer of " << GetNodeName() << " turned "
     
    565654    //  FIXME! Use NMT!
    566655    //
     656    // --- lout << ddev(MLog::eGui);
     657    // --- lout << "Send 0x4000: " << GetNodeName() << endl;
     658
    567659    SendSDO(0x4000, 0, (LWORD_t)0, false);
    568660
     661    // --- lout << "Done 0x4000: " << GetNodeName() << endl;
     662
    569663    Timer time;
    570     if (time.Now() > fTimeoutTime)
     664
     665    // --- lout << "dT " << GetNodeName() << ": " <<  dec <<(int)((fTimeoutTime-time.Now())*1000) << endl;
     666    // --- lout << edev(MLog::eGui);
     667
     668    if (time.Now() > fTimeoutTime+0.5)
    571669    {
    572670        lout << ddev(MLog::eGui);
     
    576674    }
    577675
    578 
    579676    //WaitForSdo(0x4000, 0, kDontWait);
    580     //    if (fTimerOn)
    581     //        fTimeout->Start(fGuardTime, kTRUE);
     677    //
     678    // Would not be necessary if I would Start the timer with
     679    // kFALSE. This would be a continous timer, but this
     680    // timer seems to stop it's activity at some stage without
     681    // any reason
     682    //
     683    if (fTimerOn)
     684        fTimeout->Start(fGuardTime/*/3*2*/, kTRUE);
    582685
    583686    return kTRUE;
     
    587690{
    588691    Timer time;
    589     fTimeoutTime = time.Now() + 2.*fGuardTime/1000.; //[usec]
     692
     693    // --- lout << ddev(MLog::eGui);
     694    // --- lout << "Reset " << GetNodeName() << ": " << dec << (int)((fTimeoutTime-time.Now())*1000) << endl;
     695    // --- lout << edev(MLog::eGui);
     696
     697    fTimeoutTime = time.Now() + 3.*fGuardTime/1000.;
    590698}
    591699
    592700void Macs::SetTimeoutTime(LWORD_t ms)
    593701{
    594     fGuardTime = ms/2; // FIXME: Is '/2' the best choose?
    595 
    596     SendSDO(0x4000, 2, ms);
     702    // FIXME: Is '/2' the best choose?
     703    fGuardTime = ms/3;      // how often do we send/request the handshake
     704
     705    SendSDO(0x4000, 2, ms); // How often do we check for the handshake
    597706    WaitForSdo(0x4000, 2);
    598707}
  • trunk/MagicSoft/Cosy/gui/MGCosy.cc

    r1273 r1275  
    206206    TGCompositeFrame *tf1 = fTab->AddTab("Position Zd/Az");
    207207    TGCompositeFrame *tf2 = fTab->AddTab("Track Ra/Dec");
     208    TGCompositeFrame *tf3 = fTab->AddTab("Demo Mode");
    208209
    209210    fCZdAz = new MGCoordinates(tf1, kETypeZdAz);
     
    467468    cout << "Closing window - waiting until all nodes are stopped." << endl;
    468469    fQueue->PostMsg(WM_QUIT, 0, 0);
     470    cout << "Closing window - done." << endl;
    469471    // gApplication->Terminate(0);
    470472}
     
    497499    cout << "PostMsg (WM_Position) returned." << endl;
    498500}
     501
     502//
     503// ************************** For demo purpose **********************
     504//
     505#include <TRandom.h>
     506class MDemo : public MThread
     507{
     508private:
     509    MsgQueue *fQueue;
     510    TRandom  fRand;
     511
     512public:
     513    MDemo() : MThread(false) {}
     514
     515    void SetQueue(MsgQueue *q) { fQueue = q; }
     516
     517    virtual void *Thread()
     518    {
     519        while (1)
     520        {
     521            Timer tm;
     522            tm.Now();
     523
     524            Float_t h = 2.+tm.H()+(8.+tm.M())/60.;
     525            RaDec dest(h*15, 130);
     526
     527            cout << dest.Ra()/15 << "h " << dest.Dec() << "°" << endl;
     528
     529            fQueue->PostMsg(WM_TRACK, &dest, sizeof(dest));
     530
     531            int i = 0;
     532            while (!HasStopFlag() && i++<130)  // 2.5min
     533                usleep(1000000);
     534            if (HasStopFlag())
     535                break;
     536
     537            //fQueue->PostMsg(WM_STOP, 0, 0);
     538
     539            ZdAz dest1(fRand.Integer(56)+5, fRand.Integer(360));
     540
     541            cout << "Demo: Zd=" << dest1.Zd() << "° Az=" << dest1.Az() << "°" << endl;
     542
     543            fQueue->PostMsg(WM_POSITION, &dest1, sizeof(dest1));
     544
     545            i = 0;
     546            while (!HasStopFlag() && i++<30)  // 30s
     547                usleep(1000000);
     548            if (HasStopFlag())
     549                break;
     550
     551            //ZdAz dest2(5, 30);
     552            //fQueue->PostMsg(WM_POSITION, &dest2, sizeof(dest2));
     553            /*
     554            i = 0;
     555            while (!HasStopFlag() && i++<30)  // 30s
     556                usleep(1000000);
     557            */
     558            //if (HasStopFlag())
     559            //    break;
     560        }
     561        cout << "Demo Thread: done." << endl;
     562        return NULL;
     563    }
     564};
     565
     566MDemo demo;
     567
     568void MGCosy::StartDemo()
     569{
     570    cout << "Start Demo." << endl;
     571
     572    demo.SetQueue(fQueue);
     573    demo.Start();
     574
     575    cout << "PostMsg (WM_Demo) returned." << endl;
     576}
     577
     578void StopDemo()
     579{
     580    cout << "Stopping demo." << endl;
     581    demo.Stop();
     582}
     583//
     584// ******************************************************************
     585//
    499586
    500587Bool_t MGCosy::ProcessMessage(Long_t msg, Long_t mp1, Long_t mp2)
     
    526613             */
    527614            case kPB_START:
    528                 fTab->GetCurrent() ? StartTrack() : StartPos();
     615                switch (fTab->GetCurrent())
     616                {
     617                case 0:
     618                    StartPos();
     619                    return kTRUE;
     620                case 1:
     621                    StartTrack();
     622                    return kTRUE;
     623                case 2:
     624                    StartDemo();
     625                    return kTRUE;
     626                }
    529627                return kTRUE;
    530628
    531629            case kPB_STOP:
    532630                cout << "Sending stop movement msg." << endl;
     631                StopDemo();
    533632                fQueue->PostMsg(WM_STOP, 0, 0);
     633
    534634                cout << "PostMsg (WM_Stop) returned." << endl;
    535635                return kTRUE;
     
    563663            {
    564664            case IDM_EXIT:
     665                cout << "IDM_EXIT: Posting WM_QUIT." << endl;
    565666                fQueue->PostMsg(WM_QUIT, 0, 0);
     667                cout << "IDM_EXIT: WM_QUIT done." << endl;
    566668                //cout << "Idm_Exit." << endl;
    567669                //CloseWindow();
  • trunk/MagicSoft/Cosy/gui/MGCosy.h

    r1111 r1275  
    7373    void StartPos();
    7474    void StartTrack();
     75    void StartDemo();
    7576
    7677    void EnableLabel(TGLabel *label, Bool_t stat);
  • trunk/MagicSoft/Cosy/gui/MGEmbeddedCanvas.cc

    r1111 r1275  
    66
    77#include "MGEmbeddedCanvas.h"
     8
     9#include <iostream.h>
    810
    911#include <TList.h>
     
    1719      fModified(kFALSE), fWidth(width), fRange(range), fPix(2.*range/width)
    1820{
     21    cout << "MGEmbeddedCanvas: Initializing." << endl;
    1922    fCanvas = GetCanvas();
    2023
     24    cout << "MGEmbeddedCanvas: fCanvas = 0x" << fCanvas << endl;
     25
     26    cout << "MGEmbeddedCanvas: SetFillColor." << endl;
    2127    fCanvas->SetFillColor(39); // s. TAttFill
    22     fCanvas->Range(-fRange, -fRange, fRange, fRange);
     28    cout << "MGEmbeddedCanvas: fRange=" << fRange << endl;
     29    if (fRange>0)
     30        fCanvas->Range(-fRange, -fRange, fRange, fRange);
    2331
    2432    fList = new TList;
    2533    fList->SetOwner();
     34
     35    cout << "MGEmbeddedCanvas: Initializing done." << endl;
    2636}
    2737
  • trunk/MagicSoft/Cosy/gui/MGSkyPosition.cc

    r1273 r1275  
    208208{
    209209    RaDec rd(radec.Ra()+off*360/24*kDeg2Rad, radec.Dec());
    210     ZdAz zdaz = fSlaStar->CalcZdAz(rd);
     210    ZdAz zdaz = fSlaStar->CalcZdAzFast(rd);
    211211
    212212    const float s = sin(zdaz.Az());
     
    319319    UpdatePlanet(kEMars,    fMars);
    320320
    321     RaDec radec = fSlaStar->CalcRaDec(pos*kDeg2Rad);
     321    RaDec radec = fSlaStar->CalcRaDecFast(pos*kDeg2Rad);
    322322
    323323    UpdatePosition(radec, pos.Zd(), pos.Az());
  • trunk/MagicSoft/Cosy/main/MCosy.cc

    r1111 r1275  
    187187    //
    188188    if (HasError())
    189         lout << "Error #6004 (requesting re pos from Macs) happened." << endl;
     189        lout << "Error while requesting re pos from Macs (SDO #6004)" << endl;
    190190
    191191    return kFALSE;
     
    400400        if (!cdzd && !cdaz)
    401401        {
    402             lout << "Positioning done with " << i << "manuvers." << endl;
     402            lout << "Positioning done in " << i << (i==1?" step.":" steps.") << endl;
     403            SetStatus(MCosy::kStopped);
    403404            return TRUE;
    404405        }
     
    468469    //
    469470    if (HasError())
    470         lout << "Error #3006 (setting velocity of Macs) happened." << endl;
     471        lout << "Error while setting velocity (SDO #3006)" << endl;
    471472
    472473    return kFALSE;
     
    520521
    521522    const Float_t limit = 0.25;
    522 
    523     if (sgn(vt->Az()) != sgn(vcalc.Az()) &&
    524         fabs(vt->Az()) < limit*fabs(vcalc.Az()))
     523/*
     524    if (sgn(vt->Az()) != sgn(vcalc.Az()))
     525        vt->Az(0);
     526//    else
     527    {
     528        if (fabs(vt->Az()) < fabs(vcalc.Az()) *0.5)
     529            vt->Az(0.5*vcalc.Az());
     530
     531        if (fabs(vt->Az()) > fabs(vcalc.Az()) *1.5)
     532            vt->Az(1.5*vcalc.Az());
     533    }
     534
     535    if (sgn(vt->Zd()) != sgn(vcalc.Zd()))
     536        vt->Zd(0);
     537//    else
     538    {
     539        if (fabs(vt->Zd()) > fabs(vcalc.Az()) *1.5)
     540            vt->Zd(1.5*vcalc.Zd());
     541
     542        if (fabs(vt->Zd()) < fabs(vcalc.Az()) *0.5)
     543            vt->Zd(0.5*vcalc.Zd());
     544    }
     545    */
     546
     547    if (sgn(vt->Az()) != sgn(vcalc.Az())
     548        && fabs(vt->Az()) < limit*fabs(vcalc.Az())
     549       )
    525550        vt->Az(0);
    526551    else
     
    531556        }
    532557
    533     if (sgn(vt->Zd()) != sgn(vcalc.Zd()) &&
    534         fabs(vt->Zd()) < limit*fabs(vcalc.Zd()))
     558    if (sgn(vt->Zd()) != sgn(vcalc.Zd())
     559        && fabs(vt->Zd()) < limit*fabs(vcalc.Zd())
     560       )
    535561        vt->Zd(0);
    536562    else
     
    605631    {
    606632        //
     633        // The loop should not be executed faster than the ramp of
     634        // a change in the velocity can be followed.
     635        // (This is important on fast machines >500MHz)
     636        //
     637        //usleep(100000000);
     638
     639        //
    607640        // Request Target position for this moment
    608641        //
     
    715748    // Stop revolution mode (movement)
    716749    //
    717     cout << "Stoping possibleRPM mode..." << endl;
     750    cout << "Stopping possibleRPM mode..." << endl;
    718751    fMac1->SetRpmMode(FALSE);
    719752    fMac2->SetRpmMode(FALSE);
     
    734767void *MCosy::Proc(int msg, void *mp)
    735768{
     769    cout << "MCosy::Proc: 0x" << msg << endl;
    736770    switch (msg)
    737771    {
     
    846880     << Deg2ZdRE(env.GetValue("MaxZd[Deg]", +1.0)) << "RE" << endl;
    847881     */
     882
    848883
    849884    cout << "Setting up software endswitch..." << flush;
     
    890925        // wait until a tracking session is started
    891926        //
    892         while (!fTracking && !fTTalk->HasStopFlag())
     927        while (!fTracking)
    893928            usleep(1);
    894 
    895         if (fTTalk->HasStopFlag())
    896             break;
    897929
    898930        ofstream fout("log/cosy.err");
     
    915947        // only update fTrackingError while tracking
    916948        //
    917         while (fTracking && !fTTalk->HasStopFlag())
     949        bool phca1=false;
     950        bool phca2=false;
     951        bool phcaz=false;
     952
     953        while (fTracking)
    918954        {
    919955            //
     
    922958            const float weight = 1.; //0.3;
    923959
    924             ZdAz offset(fOffset.Zd()*(1.-weight)+(ist.Zd()*kGearRatio.X()-istre.Zd())*weight,
    925                         fOffset.Az()*(1.-weight)+(ist.Az()*kGearRatio.Y()-istre.Az())*weight);
    926 
    927             fOffset = offset;
    928 
    929960            //
    930961            // This is the time constant which defines how fast
    931962            // you correct for external influences (like wind)
    932963            //
    933             bool phca1;
    934             bool phca2;
    935             bool phcaz;
    936 
     964            fZd1->ResetPosHasChanged();
     965            fZd2->ResetPosHasChanged();
     966            fAz->ResetPosHasChanged();
    937967            do
    938968            {
     
    941971                phcaz = fAz->PosHasChanged();
    942972                usleep(1);
    943             } while (!phca1 && !phca2 && !phcaz);
     973            } while (!phca1 && !phca2 && !phcaz && fTracking);
     974
    944975            //---usleep(100000); // 0.1s
    945976
     
    9751006                sla.SetMjd(time.Zd());
    9761007                sollzd = CorrectTarget(ist, sla.CalcZdAz(fRaDec)); // [se]
     1008
     1009                fOffset.Zd(fOffset.Zd()*(1.-weight)+(ist.Zd()*kGearRatio.X()-istre.Zd())*weight);
    9771010            }
    9781011
     
    9811014                sla.SetMjd(time.Az());
    9821015                sollaz = CorrectTarget(ist, sla.CalcZdAz(fRaDec)); // [se]
     1016
     1017                fOffset.Az(fOffset.Az()*(1.-weight)+(ist.Az()*kGearRatio.Y()-istre.Az())*weight);
    9831018            }
    9841019
     
    10631098    // Create Nodes
    10641099    //
     1100    lout << "- Setting up network." << endl;
     1101
    10651102    fMac1=new Macs(1, "Mac.1/Az",      lout);
    10661103    fMac2=new Macs(2, "Mac.2/Zd",      lout);
     
    10841121    // Create Gui Event timer and Gui
    10851122    //
     1123    lout << "- Initializing GUI Timer." << endl;
    10861124    fUpdateGui = new TTimer(this, 100); // 100ms
    10871125
     1126    lout << "- Starting GUI." << endl;
    10881127    fWin=new MGCosy(this, gClient->GetRoot(), 1, 1);
    10891128
     
    11081147*/
    11091148
     1149    lout.DisableOutputDevice(MLog::eGui);
     1150    lout.SetOutputGui(NULL, kFALSE);
     1151
    11101152    gApplication->Terminate(0);
    11111153}
  • trunk/MagicSoft/Cosy/main/MCosy.h

    r1111 r1275  
    1515#define WM_STOP      0x1003
    1616#define WM_POLARIS   0x1004
    17 #define WM_QUIT      0x1005
    1817
    1918class ShaftEncoder;
     
    3332    {
    3433        SetPriority(10);
     34        Detach();
    3535        Start();
    3636    }
     37    ~MTTalk() { cout << "~MTTalk::MTTalk" << endl; }
    3738};
    3839
     
    4142class MCosy : public Network, public MsgQueue, public TObject
    4243{
    43     friend class MTGui;
    4444    friend class MTTalk;
    4545
     
    9494
    9595    void TalkThread();
    96     void GuiThread(MTGui *t);
    9796
    9897    int  SetPosition(const ZdAz &dst);
Note: See TracChangeset for help on using the changeset viewer.