Changeset 4105 for trunk/MagicSoft/Cosy


Ignore:
Timestamp:
05/20/04 05:01:03 (20 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Cosy
Files:
2 deleted
31 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Cosy/Changelog

    r4076 r4105  
    11                                                                  -*-*- END -*-*-
     2 2004/05/15 - Thomas Bretz (La Palma)
     3
     4   * Makefile:
     5     - added MGMenu links
     6
     7   * bending_magic.txt:
     8     - last calculated pointing model (stil has the hysteresis
     9       problem)
     10
     11   * cosy.cc:
     12     - moved camera stuff to MStarguider
     13     - added channel selection
     14
     15   * base/BaseLinkDef.h:
     16     - updated
     17
     18   * base/MString.[h,cc]:
     19     - removed (now in Mars)
     20
     21   * base/MThread.h, candrv/network.h, candrv/nodedrv.h,
     22     candrv/vmodican.h, devdrv/macs.h, videodev/Camera.h:
     23     - changed ifndef
     24
     25   * base/Makefile:
     26     - updated
     27
     28   * candrv/nodedrv.cc:
     29     - added cast to MTime
     30
     31   * candrv/vmodican.cc:
     32     - changed priority from 10 to 1
     33
     34   * caos/Led.cc, caos/Ring.cc:
     35     - changed Form to MString
     36
     37   * caos/Makefile:
     38     - added include base
     39
     40   * caos/Ring.[h,cc]:
     41     - added arguments to constructor
     42
     43   * catalog/CatalogLinkDef.h, catalog/Makefile:
     44     - removed SaoFile
     45
     46   * catalog/Slalib.cc:
     47     - removed some obsolete code
     48
     49   * catalog/StarCatalog.cc:
     50     - added a size check for the bitmap
     51
     52   * devdrv/macs.cc:
     53     - no guarding for the moment
     54
     55   * devdrv/shaftencoder.[h,cc]:
     56     - added code to communicate with the Macs
     57
     58   * gui/GuiLinkDef.h, gui/Makefile:
     59     - removed MGVelocity
     60
     61   * gui/MGCosy.[h,cc]:
     62     - added weather data to display
     63     - added image of the camera to window
     64     - removed velocity from window
     65     - replaced Form by MString
     66
     67   * main/MBending.cc:
     68     - changed handling in GetAnAw - Hopefully correct???
     69       the old handling gave problems
     70
     71   * main/MCosy.[h,cc]:
     72     - added SetTrackingPosRE
     73     - display interpolated position when tracking
     74     - added SetMotor calls
     75
     76   * main/MStarguider.[h,cc]:
     77     - added code to find star in the display
     78     - added corresponding menus
     79     - added code to support more than one ccd channel
     80
     81   * main/MTracking.[h,cc]: 
     82     - complete change to the algorithm. The position which is
     83       send to CC need still some investigations. For more information
     84       look at the code. The main difference is that the motor
     85       encoders are taken better into account which fixes the SE
     86       handling on the elevation axis
     87
     88   * main/MainLinkDef.h, main/Makefile:
     89     - added MPointing
     90     - added MTracking
     91     
     92   * tcpip/MCeCoCom.[h,cc]: 
     93     - added alarm counter
     94
     95   * tcpip/MTcpIpIO.cc:
     96     - do not write to output file if stream is locked
     97
     98   * tpoint/gui.C:
     99     - fixed display so that it perfectly shows north, east, ...
     100     - added error for residual
     101     - simplified residual algorithm
     102     - read new files
     103     - changed displaying deviations a bit
     104     - display result in the display (preliminary)
     105     - set gIgnoreLevel to suppress strange color warnings
     106
     107   * videodev/FilterLed.cc:
     108     - use MGMap for drawing...
     109
     110
     111
    2112 2004/05/15 - Thomas Bretz (La Palma)
    3113
  • trunk/MagicSoft/Cosy/Makefile

    r4076 r4105  
    143143        @ln -sf ../../Mars/mbase/MGMap.h  base/MGMap.h
    144144        @ln -sf ../../Mars/mbase/MGMap.cc base/MGMap.cc
     145        @ln -sf ../../Mars/mbase/MGMenu.h  base/MGMenu.h
     146        @ln -sf ../../Mars/mbase/MGMenu.cc base/MGMenu.cc
    145147        @ln -sf ../../Mars/mgeom/MGeomMirror.h  base/MGeomMirror.h
    146148        @ln -sf ../../Mars/mgeom/MGeomMirror.cc  base/MGeomMirror.cc
  • trunk/MagicSoft/Cosy/base/BaseLinkDef.h

    r2615 r4105  
    88#pragma link C++ class MLog;
    99#pragma link C++ class MStar+;
     10#pragma link C++ class MGMap+;
    1011#pragma link C++ class MGList+;
    1112#pragma link C++ class MParContainer+;
     13
    1214#pragma link C++ class MObservatory+;
     15#pragma link C++ class MVector3+;
     16
     17#pragma link C++ class MString+;
    1318#pragma link C++ class MAstro+;
     19#pragma link C++ class MAstroSky2Local+;
     20#pragma link C++ class MAstroCatalog+;
     21#pragma link C++ class MAstroCamera+;
     22
     23#pragma link C++ class MGeomPix+;
     24#pragma link C++ class MGeomCam+;
     25#pragma link C++ class MGeomCamMagic+;
     26#pragma link C++ class MGeomMirror+;
     27
     28#pragma link C++ class MHCamera+;
     29#pragma link C++ class MH+;
     30#pragma link C++ class MBinning+;
     31#pragma link C++ class MCamEvent+;
     32#pragma link C++ class MHexagon+;
    1433
    1534#pragma link C++ class MTime+;
  • trunk/MagicSoft/Cosy/base/MThread.h

    r1273 r4105  
    1 #ifndef MTHREAD_H
    2 #define MTHREAD_H
     1#ifndef COSY_MThread
     2#define COSY_MThread
    33
    44#ifdef __CINT__
  • trunk/MagicSoft/Cosy/base/Makefile

    r2615 r4105  
    3131.SUFFIXES: .c .cc .cxx .h .hxx .o
    3232
    33 SRCFILES = File.cc \
    34            MStopwatch.cc \
     33SRCFILES = MStopwatch.cc \
    3534           MParContainer.cc \
    3635           MThread.cc \
    3736           MTimeout.cc \
    3837           MTime.cc \
    39            MAstro.cc \
     38           MString.cc \
    4039           MStar.cc \
    4140           MStarList.cc \
     41           MAstro.cc \
     42           MAstroCatalog.cc \
     43           MAstroCamera.cc \
     44           MAstroSky2Local.cc \
     45           MGeomMirror.cc \
     46           MGeomPix.cc \
     47           MGeomCam.cc \
     48           MGeomCamMagic.cc \
     49           MGMap.cc \
     50           MGMenu.cc \
     51           MH.cc \
     52           MBinning.cc \
     53           MHexagon.cc \
     54           MCamEvent.cc \
     55           MHCamera.cc \
    4256           msgqueue.cc \
    4357           MLog.cc \
     
    4963              MGList.h \
    5064              MTime.h \
     65              MString.h \
    5166              MAstro.h \
     67              MAstroSky2Local.h \
     68              MAstroCatalog.h \
     69              MAstroCamera.h \
     70              MGeomMirror.h \
     71              MGeomPix.h \
     72              MGeomCam.h \
     73              MGeomCamMagic.h \
     74              MHCamera.h \
     75              MBinning.h \
     76              MH.h \
     77              MGMap.h \
     78              MGMenu.h \
     79              MHexagon.h \
     80              MCamEvent.h \
    5281              MLog.h \
    5382              MLogManip.h \
  • trunk/MagicSoft/Cosy/bending_magic.txt

    r2751 r4105  
    1 MAGIC1 2003/12/29 19:15:38.433
     1MAGIC1 15.05.2004 23:25:21.338
    22S   00   000000   000000  0000000
    3      IA     502.52368   0.034356796
    4      IE    -9.0564239   0.019895878
     3     IA     502.51471   0.0072972921
     4     IE    -9.0539559   0.0050128431
    55   FLOP             0             0
    66     AN             0             0
    7      AW             0             0
    8    NPAE   0.077561439   0.038824444
     7     AW  -0.066794332   0.005947689
     8   NPAE             0             0
    99     CA             0             0
    1010     TF             0             0
    1111     TX             0             0
    1212   ECES             0             0
    13    ACES             0             0
     13   ACES  -0.021708338   0.0089723026
    1414   ECEC             0             0
    15    ACEC             0             0
     15   ACEC  -0.072368751   0.011236351
    1616    NRX             0             0
    1717    NRY             0             0
  • trunk/MagicSoft/Cosy/candrv/network.h

    r1727 r4105  
    1 #ifndef NETWORK_H
    2 #define NETWORK_H
     1#ifndef COSY_Network
     2#define COSY_Network
    33
     4#ifndef COSY_CanOpen
    45#include "canopen.h"
     6#endif
     7#ifndef COSY_NodeDrv
    58#include "nodedrv.h"
     9#endif
    610
    711class Network : public CanOpen
  • trunk/MagicSoft/Cosy/candrv/nodedrv.cc

    r2615 r4105  
    4848#include <iostream.h>
    4949
    50 #include <TTimer.h>
     50//#include <TTimer.h>
    5151
    5252#include "MTime.h"
     
    530530            const Double_t t0 = t+fGuardTime;
    531531
    532             while (!HasStopFlag() && t<t0 && t<fTimeoutTime)
     532            while (!HasStopFlag() && (double)t<t0 && (double)t<fTimeoutTime)
    533533            {
    534534                usleep(5);
     
    540540            //cout << "-g-> " << (Long_t)((t-t0)*1000)<< endl;
    541541
    542             if (t<fTimeoutTime)
     542            if ((double)t<fTimeoutTime)
    543543                continue;
    544544
  • trunk/MagicSoft/Cosy/candrv/nodedrv.h

    r2518 r4105  
    1 #ifndef NODEDRV_H
    2 #define NODEDRV_H
     1#ifndef COSY_NodeDrv
     2#define COSY_NodeDrv
    33
     4#ifndef ROOT_TString
    45#include <TString.h>
     6#endif
    57
     8#ifndef COSY_Log
    69#include "log.h"
     10#endif
    711
    812#ifdef __CINT__
  • trunk/MagicSoft/Cosy/candrv/vmodican.cc

    r4076 r4105  
    934934//  and switch the can bus communication on
    935935//
    936 VmodIcan::VmodIcan(const char *dev, const int baud, MLog &out) : Log(out), MThread(false, 10)//: CanDriver(dev, baud)
     936VmodIcan::VmodIcan(const char *dev, const int baud, MLog &out) : Log(out), MThread(false, 1)//: CanDriver(dev, baud)
    937937{
    938938    //
  • trunk/MagicSoft/Cosy/candrv/vmodican.h

    r1727 r4105  
    1 #ifndef VMODICAN_H
    2 #define VMODICAN_H
     1#ifndef COSY_VmodIcan
     2#define COSY_VmodIcan
    33
    44#include <pthread.h>
     
    1616#endif
    1717
     18#ifndef COSY_MThread
    1819#include "MThread.h"
     20#endif
    1921
    2022class Message;
  • trunk/MagicSoft/Cosy/cosy.cc

    r4076 r4105  
    1313
    1414#define EXPERT
    15 #define HAVE_CAMERA
    1615
    1716#define clog(txt) \
     
    4241        if (arg=="-0")
    4342            channel = 0;
     43        if (arg=="-c")
     44            channel = -1;
    4445    }
    4546
     
    9697    cosy->Start();
    9798
    98     clog("- Starting Camera.");
    99 #ifdef HAVE_CAMERA
    100     MStarguider *client=new MStarguider(MObservatory::kMagic1, channel);
     99    MStarguider *client=0;
     100    if (channel>=0)
     101    {
     102        clog("- Starting Camera.");
     103        client=new MStarguider(MObservatory::kMagic1, channel);
     104        cosy->SetStarguider(client);
     105        client->SetCosy(cosy);
     106    }
    101107
    102     cosy->SetStarguider(client);
    103     client->SetCosy(cosy);
    104 #endif
    105108    clog("- Starting mainloop.");
    106109#ifndef EXPERT
     
    108111#endif
    109112    app->Run(kTRUE);
    110 #ifdef HAVE_CAMERA
    111     client->SetCosy(NULL);
    112     cosy->SetStarguider(NULL);
    113113
    114     clog("- Stopping starg.");
    115     delete client;
    116 #endif
     114    if (channel>=0)
     115    {
     116        client->SetCosy(NULL);
     117        cosy->SetStarguider(NULL);
     118        clog("- Stopping starg.");
     119        delete client;
     120    }
     121
    117122    clog("- Stopping cosy.");
    118123    cosy->Stop();
  • trunk/MagicSoft/Cosy/main/MBending.cc

    r2615 r4105  
    317317
    318318    // Vector in cartesian coordinates
    319     TVector3 v(1., 1., 1.);
     319    TVector3 v1;
    320320
    321321    // Set Azimuth and Elevation
    322     v.SetPhi(p.Az());
    323     v.SetTheta(TMath::Pi()/2-p.Alt());
     322    v1.SetMagThetaPhi(1, TMath::Pi()/2-p.Alt(), p.Az());
     323
     324
     325    TVector3 v2(v1);
     326//    cout << sign << endl;
     327
     328//    cout << "v1: " << v1.Theta()*TMath::RadToDeg() << " " << v1.Phi()*TMath::RadToDeg() << endl;
    324329
    325330    // Rotate around the x- and y-axis
    326     v.RotateY(sign*fAn);
    327     v.RotateX(sign*fAw);
     331    v1.RotateY(sign*fAn);
     332    v1.RotateX(sign*fAw);
     333
     334//    cout << "v1: " << v1.Theta()*TMath::RadToDeg() << " " << v1.Phi()*TMath::RadToDeg() << endl;
     335//    cout << "v2: " << v2.Theta()*TMath::RadToDeg() << " " << v2.Theta()*TMath::RadToDeg() << endl;
     336
     337   // cout << "dv: " << (v2.Theta()-v1.Theta())*TMath::RadToDeg() << " " << (v2.Phi()-v1.Phi())*TMath::RadToDeg() << endl;
     338
     339    Double_t dalt = v1.Theta()-v2.Theta();
     340    Double_t daz  = v1.Phi()  -v2.Phi();
     341
     342    //cout << dalt*TMath::RadToDeg() << " " << daz*TMath::RadToDeg() << endl;
     343
     344    if (daz>TMath::Pi())
     345        daz -= TMath::TwoPi();
     346    if (daz<-TMath::Pi())
     347        daz += TMath::TwoPi();
     348
     349//    if (daz>TMath::Pi()/2)
     350//    {
     351//    }
     352
     353    AltAz d(dalt, daz);
     354    return d;
    328355
    329356    // Calculate Delta Azimuth and Delta Elevation
    330     AltAz d(TMath::Pi()/2-v.Theta(), v.Phi());
     357    /*
     358    AltAz d(TMath::Pi()/2-v1.Theta(), v1.Phi());
     359
     360    cout << "p :  " << p.Alt()*TMath::RadToDeg() << " " << p.Az()*TMath::RadToDeg() << endl;
     361    cout << "d :  " << d.Alt()*TMath::RadToDeg() << " " << d.Az()*TMath::RadToDeg() << endl;
    331362    d -= p;
     363    cout << "d-p: " << d.Alt()*TMath::RadToDeg() << " " << d.Az()*TMath::RadToDeg() << endl;
    332364    d *= sign;
    333 
     365    cout << "d* : " << d.Alt()*TMath::RadToDeg() << " " << d.Az()*TMath::RadToDeg() << endl;
     366
     367
     368    cout << "p2:  " << 90-p.Alt()*TMath::RadToDeg() << " " << p.Az()*TMath::RadToDeg() << endl;
     369    cout << "d2:  " << 90-d.Alt()*TMath::RadToDeg() << " " << d.Az()*TMath::RadToDeg() << endl;
     370
     371    Int_t s1 = 90-d.Alt()*TMath::RadToDeg() < 0 ? -1 : 1;
     372    Int_t s2 = 90-p.Alt()*TMath::RadToDeg() < 0 ? -1 : 1;
     373
     374
     375    if (s1 != s2)
     376    {
     377        //90-d.Alt() <-- -90+d.Alt()
     378
     379        d.Alt(d.Alt()-TMath::Pi());
     380        cout << "Alt-" << endl;
     381    }
     382    cout << "d': " << 90-d.Alt()*TMath::RadToDeg() << " " << d.Az()*TMath::RadToDeg() << endl;
     383 /*
    334384    // Fix 'direction' of output depending on input vector
    335     if (sign*p.Alt()>TMath::Pi()/2)
     385    if (TMath::Pi()/2-sign*p.Alt()<0)
     386    {
    336387        d.Alt(d.Alt()-TMath::Pi());
     388        cout << "Alt-" << endl;
     389    }
     390    //if (TMath::Pi()/2-sign*p.Alt()>TMath::Pi())
     391    //{
     392    //    d.Alt(TMath::Pi()-d.Alt());
     393    //    cout << "Alt+" << endl;
     394    //}
    337395
    338396    // Align correction into [-180,180]
    339397    while (d.Az()>TMath::Pi())
     398    {
    340399        d.Az(d.Az()-TMath::Pi()*2);
     400        cout << "Az-" << endl;
     401    }
    341402    while (d.Az()<-TMath::Pi())
     403    {
    342404        d.Az(d.Az()+TMath::Pi()*2);
    343 
     405        cout << "Az+" << endl;
     406    }
     407   */
    344408    return d;
    345409}
     
    426490    p += FLOP;
    427491
     492    //const AltAz MAGIC1(fMagic1*sin(p.Az()), 0);
     493    //p += MAGIC1;
     494
    428495    const AltAz I(fIe, fIa);
    429496    p += I;
     
    445512    const AltAz I(fIe, fIa);
    446513    p -= I;
     514
     515    //const AltAz MAGIC1(fMagic1*sin(p.Az()), 0);
     516    //p -= MAGIC1;
    447517
    448518    const AltAz FLOP(Sign(fFlop, p.Alt()), 0);
  • trunk/MagicSoft/Cosy/main/MCaos.cc

    r4076 r4105  
    167167    fHistallw->SetNameTitle("allw","Rotation angel");
    168168    fHistallw->SetBins(26, -25, 25);
    169     fHistallw->SetXTitle("\\Phi [arcmin]");
     169    fHistallw->SetXTitle("\\phi [arcmin]");
    170170    fHistallw->SetYTitle("counts");
    171171
    172172    fHistprxpry = new TH2F;
    173     fHistprxpry->SetNameTitle("prx und pry","x- and y-coordniate of the ring-center");
     173    fHistprxpry->SetNameTitle("prx und pry","x- and y-coordinate of the ring-center");
    174174    fHistprxpry->SetBins(xbin, xmin, xmax, ybin, ymin, ymax);
    175     fHistprxpry->SetXTitle("x [mm]");
    176     fHistprxpry->SetYTitle("y [mm]");
     175    fHistprxpry->SetXTitle("x [pix]");
     176    fHistprxpry->SetYTitle("y [pix]");
    177177    fHistprxpry->SetZTitle("counts");
    178178
     
    183183    fGraphpry->SetTitle("time-developement of the y-coordinate of the ring-center");
    184184
    185     fGraphw = new TGraph*[fPositions.GetEntriesFast()];
    186     for (int i=0; i<fPositions.GetEntriesFast(); i++)
    187     {
    188         TString title = "Time-developement of the angle ";
    189         title += i;
    190 
    191         fGraphw[i] = new TGraph;
    192         fGraphw[i]->SetTitle(title);
    193     }
     185    fGraphw = new TGraph;
     186    fGraphw->SetTitle("Time-developement of rotation angle");
    194187
    195188    fHistpr = new TH1F("pr","Radius of the ring", rbin, rmin, rmax);
     
    211204    delete fGraphprx;
    212205    delete fGraphpry;
     206    delete fGraphr;
    213207
    214208    for (int i=0; i<6; i++)
     
    216210        delete fHistled[i];
    217211        delete fHistw[i];
    218         delete fGraphw[i];
     212        delete fGraphw;
    219213    }
    220214    delete fHistled;
     
    265259    c2->Update();
    266260
    267     c = new TCanvas("ctime", "timedevelopement of center", 800, 800);
    268     c->Divide(1,2);
     261    c = new TCanvas("ctime", "Timedevelopement of Center", 800, 800);
     262    c->Divide(1,3);
    269263    c->cd(1);
    270264    h = fGraphprx->GetHistogram();
     
    272266    h->SetYTitle("x [pix]");
    273267    h->DrawCopy();
    274     //fGraphprx->DrawClone("LP*")->SetBit(kCanDelete);
     268    ((TPad*)gPad)->SetSelected(NULL);
     269    fGraphprx->DrawClone("ALP*")->SetBit(kCanDelete);
    275270    c->cd(2);
    276271    h = fGraphpry->GetHistogram();
     
    278273    h->SetYTitle("y [pix]");
    279274    h->DrawCopy();
    280     //fGraphpry->DrawClone("LP*")->SetBit(kCanDelete);
     275    ((TPad*)gPad)->SetSelected(NULL);
     276    fGraphpry->DrawClone("ALP*")->SetBit(kCanDelete);
     277    c->cd(3);
     278    h = fGraphr->GetHistogram();
     279    h->SetXTitle("time [s]");
     280    h->SetYTitle("r [pix]");
     281    h->DrawCopy();
     282    ((TPad*)gPad)->SetSelected(NULL);
     283    fGraphr->DrawClone("ALP*")->SetBit(kCanDelete);
    281284    c->Modified();
    282285    c->Update();
     286
     287    c = new TCanvas("crot", "rotation angle", 800, 600);
     288    c->Divide(2,1);
     289    c->cd(1);
     290    fHistallw->SetXTitle("\\phi [arcmin]");
     291    fHistallw->SetYTitle("counts");
     292    fHistallw->DrawCopy();
     293    c->cd(2);
     294    h = fGraphw->GetHistogram();
     295    h->SetXTitle("time [s]");
     296    h->SetYTitle("\\phi [arcmin]");
     297    h->DrawCopy();
     298    ((TPad*)gPad)->SetSelected(NULL);
     299    fGraphw->DrawClone("ALP*")->SetBit(kCanDelete);
     300
    283301
    284302    /* --------------------------------------------------------
     
    333351            f.MarkPoint(l1.GetX(), l1.GetY(), l1.GetMag());
    334352
     353            //old
     354            /*
    335355            // Fill values into Histogram
    336356            if (!fHistpr)
     
    339359            fHistled[i]->Fill(l1.GetX(), l1.GetY());
    340360            fHistw[i]->Fill(l1.GetPhi());
     361            */
    341362        }
    342363        first = leds.GetEntries();
     
    344365
    345366    Rings rings;
    346     rings.CalcRings(leds, 266, 268);
     367    rings.CalcRings(leds, 265, 268);
    347368
    348369    const Ring &center = rings.GetCenter();
     
    358379        fGraphprx->SetPoint(fGraphprx->GetN(), fEvtTime, center.GetX());
    359380        fGraphpry->SetPoint(fGraphpry->GetN(), fEvtTime, center.GetY());
     381
     382        //new
     383        //-----
     384        Double_t sum = 0;
     385        for (int j=0; j<leds.GetEntries(); j++)
     386        {
     387            Led &l1 = leds(j);
     388
     389            fHistled[j]->Fill(l1.GetX(), l1.GetY());
     390            //fHistw[j]->Fill(l1.GetPhi());
     391
     392            Double_t phi[6] =
     393            {
     394                0,
     395                0,
     396                0,
     397                0,
     398                0,
     399                0
     400            };
     401
     402            const Double_t w = (leds(j).GetPhi()-phi[j])*60;
     403            sum += w;
     404
     405            fHistw[j]->Fill(w);
     406            sum /= leds.GetEntries();
     407        }
     408        fGraphw->SetPoint(fGraphw->GetN(), fEvtTime, sum);
     409        fHistallw->Fill(sum/leds.GetEntries());
     410        //-----
    360411    }
    361412
  • trunk/MagicSoft/Cosy/main/MCaos.h

    r4076 r4105  
    4242    TGraph        *fGraphprx;
    4343    TGraph        *fGraphpry;
    44     TGraph       **fGraphw;
     44    TGraph        *fGraphw;
     45    TGraph        *fGraphr;
    4546
    4647public:
  • trunk/MagicSoft/Cosy/main/MCosy.cc

    r4076 r4105  
    402402
    403403    return point.SetPosition(dst, track);
     404}
     405
     406void MCosy::SetTrackingPosRE(ZdAz za)
     407{
     408    za /= kGearTot;                        // [U_tel]
     409    za *= TMath::TwoPi();                  // [rad]
     410    //cout << "RE1:  " << za.Zd()*180/3.1415 << " " << za.Az()*180/3.1415 << endl;
     411    fTrackingPos = fBending.CorrectBack(za)*TMath::RadToDeg();
     412    //cout << "RE2:  " << fTrackingPos.Zd() << " " << fTrackingPos.Az() << endl;
    404413}
    405414
     
    828837
    829838    cout << "Reading gear ratios..." << flush;
     839    kGear.X(env.GetValue("Zd_GearRatio[U_mot/U_tel]", 1000.0));
    830840    kGear.Y(env.GetValue("Az_GearRatio[U_mot/U_tel]", 1000.0));
    831     kGear.X(env.GetValue("Zd_GearRatio[U_mot/U_tel]", 1000.0));
    832841
    833842    kResRE.Y(0);
     
    11181127        SetStatus(MDriveCom::kError);
    11191128
    1120     ZdAz bendist = GetPointingPos();
     1129
     1130    ZdAz bendist = fStatus&MDriveCom::kTracking ? fTrackingPos : GetPointingPos();
     1131
     1132    //cout << (fStatus&MDriveCom::kTracking?"TRA: ":"POS: ") << bendist.Zd() << " " << bendist.Az() << endl;
     1133
    11211134    fCom->SendReport(fStatus, fRaDec, fZdAzSoll, bendist, fTrackingError);
    11221135
     
    13281341    fAz->SetReport(fOutRep);
    13291342
     1343    fAz->SetMotor(fMac1);
     1344    fZd1->SetMotor(fMac2);
     1345    fZd2->SetMotor(fMac2);
     1346 
    13301347    lout << "- Connecting devices to network." << endl;
    13311348
  • trunk/MagicSoft/Cosy/main/MCosy.h

    r4076 r4105  
    1 #ifndef MCOSY_H
    2 #define MCOSY_H
     1#ifndef COSY_MCosy
     2#define COSY_MCosy
    33
    44#include "coord.h"
    55#include "msgqueue.h"
    6 #include "network.h"
    76#include "MThread.h"
    87#include "MBending.h"
    98
     9#ifndef COSY_Network
     10#include "network.h"
     11#endif
    1012#ifndef MARS_MObservatory
    1113#include "MObservatory.h"
     
    8486    MDriveCom *fCom;
    8587
    86     TTimer *fUpdateGui;
    87     MTTalk *fTTalk;       // should be outsourced, like the starguider.
     88    TTimer    *fUpdateGui;
     89    MTTalk    *fTTalk;    // should be outsourced, like the starguider.
    8890                          // with a generic interface to both...
     91    ZdAz fTrackingPos;    // [deg] Current tracking position
    8992
    9093    TMutex fMutexGui;
     
    185188    MGCosy *GetWin() { return fWin; }
    186189
     190    ZdAz GetTrackingPosDeg() const { return fTrackingPos; };
     191    void SetTrackingPosRE(ZdAz za);
     192
    187193    AltAz GetAltAzDeg() const
    188194    {
  • trunk/MagicSoft/Cosy/main/MPointing.cc

    r4076 r4105  
    151151        const ZdAz p=fCosy->GetSePos();
    152152
    153         // calculate control deviation and rounded cd
     153        // calculate control deviation
    154154        ZdAz rd = dest-p; // [se]
    155155        ZdAz cd = rd;     // [se]
     156        // Correct for having two SE available
     157        cd.Zd(cd.Zd()*2);
     158        // Round to check whether we are as near as possible
     159        // to the value we expect
    156160        cd.Round();
    157161
  • trunk/MagicSoft/Cosy/main/MStarguider.cc

    r2615 r4105  
    88#include <TGraph.h>
    99#include <TTimer.h>
     10#include <TSystem.h>
    1011
    1112#include <TGMenu.h>
    1213#include <TGLabel.h>
    13 #include <TSystem.h>
     14#include <TGButton.h>
    1415#include <TGSplitter.h>    // TGHorizontal3DLine
    1516#include <TGTextEntry.h>
    1617
     18#include "MString.h"
     19
    1720#include "MCosy.h"
    1821#include "MCaos.h"
     
    2225
    2326#include "coord.h"
     27
     28#include "Camera.h"
     29#include "PngReader.h"
    2430
    2531#include "Led.h"
     
    2935#include "CaosFilter.h"
    3036#include "StarCatalog.h"
     37#include "MGeomCamMagic.h"
     38#include "MAstroCamera.h"
    3139
    3240#include "MGMenu.h"
     41#include "MGCosy.h"
    3342
    3443ClassImp(MStarguider);
     
    3645enum {
    3746    IDM_kFilter,
     47    IDM_kFindStar,
    3848    IDM_kCaosFilter,
    3949    IDM_kCatalog,
     
    4656    IDM_kOnce,
    4757    IDM_kStretch,
    48 //    IDM_kUseFileRaDec,
     58    IDM_kInput,
     59    IDM_kChannel1,
     60    IDM_kChannel2,
    4961    IDM_kContinous,
    5062    IDM_kRate25ps,
     
    6577    IDM_kPixSize,
    6678    IDM_kAngle,
     79    IDM_kInterpol250,
    6780    IDM_kInterpol125,
    6881    IDM_kInterpol50,
     
    8396Bool_t MStarguider::HandleTimer(TTimer *t)
    8497{
    85     fImage->DoRedraw();
    86     fZoomImage->DoRedraw();
     98    if (IsMapped())
     99    {
     100        fImage->DoRedraw();
     101        fZoomImage->DoRedraw();
     102    }
     103
     104    if (fCosy && fCosy->GetWin()->IsMapped())
     105        fCosy->GetWin()->GetImage()->DoRedraw();
     106
    87107    return kTRUE;
    88108}
     
    95115}
    96116
    97 void MStarguider::InitGui()
     117void MStarguider::InitGui(Int_t channel)
    98118{
    99119    fList = new MGList;
    100120
    101121    const TGWindow *p=gClient->GetRoot();
     122
     123    fChannel = new MGPopupMenu(p);
     124    fChannel->AddEntry("Channel #1", IDM_kChannel1);
     125    fChannel->AddEntry("Channel #2", IDM_kChannel2);
     126    fChannel->CheckEntry(channel==0?IDM_kChannel1:IDM_kChannel2);
     127    fChannel->Associate(this);
     128    fList->Add(fChannel);
    102129
    103130    //
     
    106133    fDisplay = new MGPopupMenu(p);
    107134    fDisplay->AddEntry("&Filter",      IDM_kFilter);
     135    fDisplay->AddEntry("Find &Star",   IDM_kFindStar);
    108136    fDisplay->AddEntry("C&aosFilter",  IDM_kCaosFilter);
    109137    fDisplay->AddEntry("Sao &Catalog", IDM_kCatalog);
    110138    fDisplay->AddEntry("Starguider",   IDM_kStarguider);
    111139    fDisplay->AddEntry("Stretch",      IDM_kStretch);
     140    if (channel>=0)
     141        fDisplay->AddPopup("&Input",   fChannel);
    112142    fDisplay->DisableEntry(IDM_kStarguider);
    113143    fDisplay->CheckEntry(IDM_kStretch);
     
    169199
    170200    fInterpol = new MGPopupMenu(p);
     201    fInterpol->AddEntry("250", IDM_kInterpol250);
    171202    fInterpol->AddEntry("125", IDM_kInterpol125);
    172203    fInterpol->AddEntry("50",  IDM_kInterpol50);
     
    242273
    243274    fCRaDec = new MGCoordinates(this, kETypeRaDec);
    244     fCRaDec->Move(1, fMenu->GetDefaultHeight()+584);
     275    fCRaDec->Move(4, fMenu->GetDefaultHeight()+584);
    245276    AddFrame(fCRaDec);
    246277    fList->Add(fCRaDec);
     
    255286    AddFrame(fPZdAz);
    256287    fList->Add(fPZdAz);
     288
     289    fTPoint = new TGTextButton(this, "TPoint");
     290    fTPoint->Move(4, fMenu->GetDefaultHeight()+665);
     291    fTPoint->AllowStayDown(kTRUE);
     292    AddFrame(fTPoint);
     293    fList->Add(fTPoint);
    257294
    258295    fFps = new TGLabel(this, "---fps");
     
    294331    const Double_t pixsize = 23.4;
    295332
    296     fSao->SetPixSize(pixsize/3600);
     333    fSao->SetPixSize(pixsize);
    297334    fSao->SetRotationAngle(0);
    298335
     
    336373
    337374    MapSubwindows();
     375    fTPoint->UnmapWindow();
    338376    MapWindow();
     377
     378    IconifyWindow();
    339379
    340380    //------------------------------------------------------------
     
    345385}
    346386
    347 MStarguider::MStarguider(MObservatory::LocationName_t obs)
    348 : TGMainFrame(gClient->GetRoot(), 768, 740), fCosy(NULL), fDx((768-kZOOM)/2), fDy((512-kZOOM)/2)
     387MStarguider::MStarguider(MObservatory::LocationName_t obs, Int_t channel)
     388: TGMainFrame(gClient->GetRoot(), 768, 740), fCosy(NULL), fOutTp(0), fDx((768-kZOOM)/2), fDy((512-kZOOM)/2)
    349389{
    350390    cout << " #### FIXME: Make MCaos Thread safe!" << endl;
     
    356396    fCaos->ReadResources();
    357397
    358     InitGui();
    359 
    360     gVirtualX->GrabButton(fId, kButton2, 0, 0, 0, 0, kTRUE);
     398    InitGui(channel);
    361399
    362400    fTimer=new TTimer(this, 1000/25); // 40ms
     
    364402
    365403    fTime.Now();
     404                                             
     405    gVirtualX->GrabButton(fId, kButton2, 0, 0, 0, 0, kTRUE);
     406
     407    if (channel<0)
     408        fGetter=new PngReader(*this);
     409    else
     410    {
     411        fGetter = new Camera(*this, channel);
     412        ((Camera*)fGetter)->Loop(0);
     413    }
    366414}
    367415
    368416MStarguider::~MStarguider()
    369417{
     418    fGetter->ExitLoop();
     419    delete fGetter;
     420
    370421    gVirtualX->GrabButton(fId, kButton2, 0, 0, 0, 0, kFALSE);
    371422
     
    378429    delete fSao;
    379430    delete fRaDec;
     431
     432    if (fOutTp)
     433        delete fOutTp;
    380434
    381435    cout << "Camera Display destroyed." << endl;
     
    416470                    const Float_t pixsize = atof(fPixSize->GetText());
    417471                    cout << "Pixel Size changed to " << pixsize << "\"/pix" << endl;
    418                     fSao->SetPixSize(pixsize/3600);
     472                    fSao->SetPixSize(pixsize);
    419473                    return kTRUE;
    420474                }
     
    459513                    fDisplay->UnCheckEntry(IDM_kStarguider);
    460514                    fDisplay->DisableEntry(IDM_kStarguider);
     515                }
     516                return kTRUE;
     517
     518            case IDM_kFindStar:
     519                Toggle(fDisplay, IDM_kFindStar);
     520                if (fDisplay->IsEntryChecked(IDM_kFindStar) && fCosy)
     521                    fTPoint->MapWindow();
     522                else
     523                {
     524                    fTPoint->UnmapWindow();
     525                    fTPoint->SetDown(kFALSE);
    461526                }
    462527                return kTRUE;
     
    595660                return kTRUE;
    596661
     662            case IDM_kChannel1:
     663            case IDM_kChannel2:
     664                {
     665                    const Int_t ch0 = fChannel->IsEntryChecked(IDM_kChannel1) ? 0 : 1;
     666                    const Int_t ch1 = mp1==IDM_kChannel1                      ? 0 : 1;
     667                    if (ch0==ch1)
     668                        return kTRUE;
     669
     670                    fChannel->CheckEntry  (ch1==0?IDM_kChannel1:IDM_kChannel2);
     671                    fChannel->UnCheckEntry(ch1==1?IDM_kChannel1:IDM_kChannel2);
     672                    delete fGetter;
     673                    usleep(150000); // FIX: Device or resource busy.
     674                    fGetter = new Camera(*this, ch1);
     675                    ((Camera*)fGetter)->Loop(0);
     676                }
     677                return kTRUE;
     678
     679            case IDM_kInterpol250:
    597680            case IDM_kInterpol125:
    598681            case IDM_kInterpol50:
     
    602685            case IDM_kInterpol2:
    603686            case IDM_kInterpol1:
    604                 for (int i=IDM_kInterpol125; i<=IDM_kInterpol1; i++)
     687                for (int i=IDM_kInterpol250; i<=IDM_kInterpol1; i++)
    605688                    if (mp1==i)
    606689                        fInterpol->CheckEntry(i);
     
    629712                case IDM_kInterpol125:
    630713                    fIntRate = 125;
     714                    return kTRUE;
     715                case IDM_kInterpol250:
     716                    fIntRate = 250;
    631717                    return kTRUE;
    632718                }
     
    806892}
    807893
     894void MStarguider::FindStar(FilterLed &f, FilterLed &f2, Ring &center, MTime &t)
     895{
     896    // Set search Paremeters (FIXME: Get them from user input!)
     897    f.SetCut(3.0);
     898    f.SetBox(70);
     899
     900    // Try to find Led in this area
     901    Leds leds;
     902    f.FindStar(leds, center.GetX(), center.GetY());
     903
     904    // Check wheter star found
     905    Led *star = (Led*)leds.At(0);
     906    if (!star)
     907        return;
     908
     909    cout << "Found star @ " << flush;
     910    star->Print();
     911    f2.MarkPoint(star->GetX(), star->GetY(), 2<<2);
     912
     913    // Initialize Star Catalog on th camera plane
     914    MGeomCamMagic geom;
     915    MAstroCamera ac;
     916    ac.SetMirrors("magic.def");
     917    ac.SetGeom(geom);
     918    ac.SetRadiusFOV(3);
     919    ac.SetObservatory(*fSao);
     920    ac.SetTime(t);
     921
     922    // Get tracking coordinates
     923    const XY    xy = fCRaDec->GetCoordinates();
     924    const RaDec rd(xy.X()*TMath::DegToRad()*360/24, xy.Y()*TMath::DegToRad());
     925
     926    ac.SetRaDec(rd.Ra(), rd.Dec());
     927
     928    // Adapt coordinate system (GUI and humans are counting Y in different directions)
     929    Double_t x = star->GetX()-center.GetX();
     930    Double_t y = center.GetY()-star->GetY();
     931
     932    // Convert from Pixel to millimeter (1pix=2.9mm)
     933    x *= 2.58427;
     934    y *= 2.58427;
     935
     936    // Correct for abberation.
     937    x /= 1.0713;
     938    y /= 1.0713;
     939
     940    // Calculate Offset
     941    Double_t dzd, daz;
     942    ac.GetDiffZdAz(x, y, dzd, daz);
     943
     944    cout << "STAR-Offset: " << MTime(-1) << " dZd=" << dzd << "d  dAz=" << daz << "d" << endl;
     945
     946    // Check TPoint data set request
     947    if (!fTPoint->IsDown())
     948        return;
     949    fTPoint->SetDown(kFALSE);
     950
     951    // If no file open: open new file
     952    if (!fOutTp)
     953    {
     954        //
     955        // open tpoint file
     956        //
     957        const TString name = MCosy::GetFileName("tpoint/starg_%s.txt");
     958        cout << "TPoint-Starg File ********* " << name << " ********** " << endl;
     959
     960        fOutTp = new ofstream(name);
     961        *fOutTp << "Magic Model  TPOINT data file" << endl;
     962        *fOutTp << ": ALTAZ" << endl;
     963        *fOutTp << "49 48 0 ";
     964        *fOutTp << t << endl;
     965        // temp(°C) pressure(mB) height(m) humidity(1) wavelength(microm) troplapserate(K/m)
     966    }
     967
     968    // Output Ra/Dec the drive system thinks that it is currently tracking
     969    cout << "TPoint Star: " << xy.X() << "h " << xy.Y() << "°" << endl;
     970
     971    // From the star position in the camera we calculate the Alt/Az
     972    // position we are currently tracking (real pointing position)
     973    fSao->SetMjd(t.GetMjd());
     974    AltAz za0 = fSao->CalcAltAz(rd)*kRad2Deg;
     975
     976    //ZdAz za0 = fSao->GetZdAz();
     977    za0 -= AltAz(-dzd, daz);
     978
     979    // From the Shaftencoders we get the current 'pointing' position
     980    // as it is seen by the drive system (system pointing position)
     981    const ZdAz za1 = fCosy->GetTrackingPosDeg();
     982
     983    // Write real pointing position
     984    cout << "     Alt/Az: " << za0.Alt() << "° " << za0.Az() << "°" << endl;
     985    *fOutTp << setprecision(7) << za0.Az() << " " << za0.Alt() << " ";
     986
     987    // Write system pointing position
     988    cout << "     SE-Pos: " << 90-za1.Zd() << "° " << za1.Az() << "°" << endl;
     989    *fOutTp << fmod(za1.Az()+360, 360) << " " << 90-za1.Zd();
     990
     991    *fOutTp << " " << xy.X() << " " << xy.Y();
     992    *fOutTp << " " << -dzd << " " << -daz;
     993    *fOutTp << " " << setprecision(11) << t.GetMjd();
     994    *fOutTp << endl;
     995}
     996
    808997bool MStarguider::Interpolate(const unsigned long n, byte *img) const
    809998{
     
    8441033    if (d>1)
    8451034    {
    846         fFps->SetText(Form("%dfps", (int)((n-n0)/d+.5)));
     1035        MString txt;
     1036        txt.Print("%dfps", (int)((n-n0)/d+.5));
     1037        fFps->SetText(txt);
    8471038        fTime = t;
    8481039        n0 = n;
     
    8521043        return;
    8531044
    854     FilterLed f(img, 768, 576, 2.5); // 2.5
     1045    byte cimg[768*576];
     1046    memset(cimg, 0, 768*576);
     1047
     1048    FilterLed f(img,   768, 576, 2.5); // 2.5
     1049    FilterLed f2(cimg, 768, 576); // former color 0xb0
    8551050
    8561051    if (fDisplay->IsEntryChecked(IDM_kStretch))
     
    8741069        f.Execute();
    8751070
     1071    Ring center(768/2, 576/2);
    8761072    if (fDisplay->IsEntryChecked(IDM_kCaosFilter))
    8771073    {
     
    8821078            pos = fCosy->GetPointingPos();
    8831079
    884         fCaos->Run(img, printl, printr, pos, t);
    885     }
     1080        center = fCaos->Run(img, printl, printr, pos, t);
     1081    }
     1082
     1083    if (fDisplay->IsEntryChecked(IDM_kFindStar))
     1084        FindStar(f, f2, center, t);
    8861085
    8871086    byte zimg[kZOOM*kZOOM];
     
    8921091    fZoomImage->DrawImg(zimg);
    8931092
     1093    if (fCosy)
     1094    {
     1095        byte simg[(768/2-1)*(576/2-1)];
     1096        for (int y=0; y<576/2-1; y++)
     1097            for (int x=0; x<768/2-1; x++)
     1098                simg[x+y*(768/2-1)] = ((unsigned int)img[2*x+2*y*768]+img[2*x+2*y*768+1]+img[2*x+2*(y+1)*768]+img[2*x+2*(y+1)*768+1])/4;
     1099
     1100        fCosy->GetWin()->GetImage()->DrawImg(simg);
     1101    }
     1102
    8941103    if (fDisplay->IsEntryChecked(IDM_kCatalog))
    8951104    {
     
    9011110        UpdatePosZoom();
    9021111
    903         MStarList stars;
    904         fSao->GetStars(stars, time.GetMjd(), *fRaDec);
    905 
     1112        /*
    9061113        if (fDisplay->IsEntryChecked(IDM_kStarguider))
    9071114        {
     
    9131120            CalcTrackingError(leds, stars);
    9141121        }
    915 
    916         byte cimg[768*576];
    917         fSao->GetImg(img, cimg, stars);
    918 
    919         const float r = 60*60/fSao->GetPixSize()+1;
    920         f.DrawCircle(0.5*r);
    921         f.DrawCircle(1.0*r);
    922         f.DrawCircle(1.5*r);
    923 
     1122        */
     1123
     1124        // Always call SetMjd first!
     1125        fSao->SetPointing(time.GetMjd(), *fRaDec);
    9241126        fCZdAz->SetCoordinates(fSao->GetZdAz());
    9251127
     1128        MStarList stars;
     1129        fSao->CalcStars(stars);
     1130        fSao->DrawStars(stars, cimg);
     1131    }
     1132
     1133    if (fDisplay->IsEntryChecked(IDM_kCaosFilter))
     1134    {
     1135        f2.DrawCircle(center, 0x0a);
     1136        f2.DrawCircle(center,   5.0, fDisplay->IsEntryChecked(IDM_kFindStar)?3:0xb0);
     1137        f2.DrawCircle(center, 115.0, 0x0a);
     1138        f2.DrawCircle(center, 230.0, 0x0a);
     1139        f2.DrawCircle(center, 245.0, 0x0a);
     1140    }
     1141
     1142    if (fDisplay->IsEntryChecked(IDM_kCatalog))
     1143    {
     1144        fSao->PaintImg(cimg, 768, 576);
     1145
     1146        const float r = 60*60/fSao->GetPixSize();
     1147
     1148        f2.DrawCircle(0.5*r, 0x0a);
     1149        f2.DrawCircle(1.0*r, 0x0a);
     1150        f2.DrawCircle(1.5*r, 0x0a);
     1151    }
     1152
     1153    if (fDisplay->IsEntryChecked(IDM_kCaosFilter) ||
     1154        fDisplay->IsEntryChecked(IDM_kCatalog)    ||
     1155        fDisplay->IsEntryChecked(IDM_kFindStar))
    9261156        fImage->DrawColImg(img, cimg);
    927     }
    9281157    else
    9291158        fImage->DrawImg(img);
     
    9321161void MStarguider::UpdatePosZoom()
    9331162{
     1163    MString txt;
    9341164    if (fDisplay->IsEntryChecked(IDM_kCatalog))
    9351165    {
     
    9401170        if (aa.Az()<0)
    9411171            aa.Az(aa.Az()+360);
    942         fPosZoom->SetText(Form("%.1fd/%.1fd (%d, %d)",
    943                                -aa.Alt(), aa.Az()-180, fDx, fDy));
     1172
     1173        txt.Print("%.1fd/%.1fd (%d, %d)", -aa.Alt(), aa.Az()-180, fDx, fDy);
    9441174    }
    9451175    else
    946         fPosZoom->SetText(Form("(%d, %d)", fDx, fDy));
     1176        txt.Print("(%d, %d)", fDx, fDy);
     1177
     1178    fPosZoom->SetText(txt);
    9471179}
    9481180
  • trunk/MagicSoft/Cosy/main/MStarguider.h

    r2615 r4105  
    77
    88#include "PixClient.h"
     9#include "MGImage.h"
     10#include "coord.h"
    911
    1012#ifndef MARS_MObservatory
    1113#include "MObservatory.h"
    1214#endif
    13 
    1415#ifndef MARS_MTime
    1516#include "MTime.h"
    1617#endif
    17 
     18#ifndef MARS_MGList
    1819#include "MGList.h"
    19 #include "MGImage.h"
    20 
    21 #include "coord.h"
     20#endif
    2221
    2322class TArrayF;
    2423class TGLabel;
     24class TGButton;
    2525
    2626class TTimer;
     
    2929class MGPopupMenu;
    3030class TGTextEntry;
     31
     32class PixGetter;
    3133
    3234class MGImage;
     
    3739class MCosy;
    3840class MCaos;
     41class FilterLed;
     42class Ring;
    3943
    4044class Leds;
     
    4347{
    4448private:
     49    PixGetter     *fGetter;
     50
    4551    MGList        *fList;
    4652
     
    5763    MGPopupMenu   *fSetup;
    5864    MGPopupMenu   *fLimMag;
     65    MGPopupMenu   *fChannel;
    5966
    6067    MGPopupMenu   *fCaosWrite;
     
    7481    TGLabel       *fPosZoom;
    7582
     83    TGButton      *fTPoint;
     84
    7685    StarCatalog   *fSao;
    7786    MCosy         *fCosy;
     
    8291    TTimer *fTimer;
    8392    MTime   fTime;
     93
     94    ofstream *fOutTp;
    8495
    8596    Int_t fDx;
     
    95106    ZdAz TrackingError(TArrayF &alt, TArrayF &az, TArrayF &mag) const;
    96107    bool Interpolate(const unsigned long n, byte *img) const;
     108    void FindStar(FilterLed &f, FilterLed &f2, Ring &center, MTime &t);
    97109
    98110    //void InitHists();
    99111    //void InitGraphs();
    100     void InitGui();
     112    void InitGui(Int_t channel);
    101113
    102114    //void OpenFile();
     
    110122
    111123public:
    112     MStarguider(MObservatory::LocationName_t obs);
     124    MStarguider(MObservatory::LocationName_t obs, Int_t channel);
    113125    virtual ~MStarguider();
    114126
     
    119131
    120132    Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2);
     133
    121134    Bool_t HandleDoubleClick(Event_t *event);
     135    //Bool_t HandleButton(Event_t *);
    122136
    123137    void SetPointingPosition(RaDec rd);
  • trunk/MagicSoft/Cosy/main/MTracking.cc

    r4076 r4105  
    7373        return false;
    7474
    75     fCosy->SetStatus(MDriveCom::kMoving | MDriveCom::kTracking);
    76 
    7775    fCosy->fMac2->SetRpmMode(TRUE);
    7876    if (fCosy->fMac2->IsZombieNode())
     
    8280    if (fCosy->fMac1->IsZombieNode())
    8381        return false;
     82
     83    fCosy->SetStatus(MDriveCom::kMoving | MDriveCom::kTracking);
    8484
    8585    return true;
     
    223223
    224224    return kFALSE;
     225}
     226
     227// --------------------------------------------------------------------
     228//
     229// Return pointing position of the telescope based on the
     230// Shaftencoders with interpolation with motor encoders.
     231//
     232// GetPointingPos [re]
     233//
     234ZdAz MTracking::GetPointingPosRE(Bool_t pdo) const
     235{
     236    // Conversion factor from se to re
     237    const XY re = fCosy->kGearTot/fCosy->kResSE; //[re/se]
     238
     239    // Get current shaftencoder position of the telescope
     240    Double_t seposzd1 = ((fCosy->fZd1->GetPos()+8192)%16384)*re.X();
     241    Double_t seposzd2 = ((fCosy->fZd2->GetPos()+8192)%16384)*re.X();
     242    Double_t seposaz  =   fCosy->fAz->GetPos() *re.Y();
     243
     244    // distance between (To+dt) and To [re]
     245    // position time difference < 5usec
     246    // fRePos does the synchronization between the
     247    // Shaft- and the rotary encoders
     248    const ZdAz repos = pdo ? fCosy->GetRePosPdo() : fCosy->GetRePos();
     249
     250    // Calculate the part of one SE which the motors moved
     251    // since the last SE has changed its value
     252    const Double_t offzd1 = repos.Zd() - fCosy->fZd1->GetOffset();
     253    const Double_t offzd2 = repos.Zd() - fCosy->fZd2->GetOffset();
     254    const Double_t offaz  = repos.Az() - fCosy->fAz->GetOffset();
     255
     256    // Correct for the direction in which the motor is moving
     257    // (in which the shaftencoders should change its values)
     258    if (offaz<0)
     259        seposaz += re.Y();
     260    if (offzd1<0)
     261        seposzd1 += re.X();
     262    if (offzd2<0)
     263        seposzd2 += re.X();
     264
     265    // and interpolate the shaftencoder steps using the motor
     266    // encoder positon (Be carefull the minus-sign is important)
     267    seposzd1 += offzd1;
     268    seposzd2 -= offzd2;
     269    seposaz  += offaz;
     270
     271    return ZdAz((seposzd1-seposzd2)/2, seposaz);
    225272}
    226273
     
    260307    // calculate offset from present se position
    261308    //
    262     const ZdAz sepos = fCosy->GetSePos()*fCosy->kGearTot/fCosy->kResSE; //[re]
     309    //const ZdAz sepos = fCosy->GetSePos()*fCosy->kGearTot/fCosy->kResSE; //[re]
    263310    if (!RequestRePos())
    264311        return;
    265312
    266     //
    267313    // Estimate Offset before starting to track
    268     //
    269     fOffset = sepos-fCosy->GetRePos();
    270 
    271     /*
    272      cout << "Sepos:  " << sepos.Zd() << "re, " << sepos.Az() << "re" << endl;
    273      cout << "Repos:  " << repos.Zd() << "re, " << repos.Az() << "re" << endl;
    274      cout << "Offset: " << fOffset.Zd() << "re, " << fOffset.Az() << "re" << endl;
    275      */
     314    ZdAz repos = fCosy->GetRePos();
     315    fCosy->fZd1->SetOffset(repos.Zd());
     316    fCosy->fZd2->SetOffset(repos.Zd());
     317    fCosy->fAz->SetOffset(repos.Az());
     318
     319    fCosy->SetTrackingPosRE(GetPointingPosRE());
     320
     321    // Initialize Tracker (slalib or starguider)
     322    fCosy->fRaDec = dst;
     323
     324    // StartThread
     325    Start();
    276326
    277327    //
     
    283333        return;
    284334    }
    285 
    286     // Initialize Tracker (slalib or starguider)
    287     fCosy->fRaDec = dst;
    288 
    289     // StartThread
    290     Start();
    291335
    292336    // Get current nominal local position
     
    296340    // Some output
    297341    XY xy(Rad2Deg(dst.Ra())*24/360, Rad2Deg(dst.Dec()));
    298     lout << sla.GetTime() << " - Start Tracking: Ra=" <<xy.X() << "h Dec=";
     342    lout << sla.GetTime() << " - Start Tracking: Ra=" << xy.X() << "h Dec=";
    299343    lout << xy.Y() << "\xb0 @ Zd=" << pos.Zd()*kRad2Deg <<"deg Az=" << pos.Az()*kRad2Deg <<"deg" << endl;
    300344
     
    331375                break;
    332376
     377            // Destination position at t+dt in re-units
    333378            dest *= fCosy->kGearTot/TMath::TwoPi();  // [re]
    334379
    335             //*fCosy->fOutRep << "> ReqRePos1 " << endl;
    336 
    337             //
    338380            // Request absolute position of rotary encoder from Macs
    339             //
     381            // Such that the RE position used in GetPointingPos is
     382            // as up-to-date as possible.
     383// DO I NEED THIS OR IS THE PDOPOS ENOUGH?
    340384            if (!RequestRePos())
    341385                break;
    342386
    343             //*fCosy->fOutRep << "> ReqRePos2 " << fOffset.Zd() << " " << fOffset.Az() << endl;
    344 
    345             //
     387            // *NEW* offset handling
     388            // Get current position of the telescope and
     389            // forward this position to MCosy
     390            ZdAz sepos = GetPointingPosRE(); //[re]
     391            fCosy->SetTrackingPosRE(sepos);
     392
    346393            // distance between (To+dt) and To [re]
    347394            // position time difference < 5usec
    348             // fOffset does the synchronization between the
     395            // fRePos does the synchronization between the
    349396            // Shaft- and the rotary encoders
    350397            repos = fCosy->GetRePos();
    351             dest -= repos + fOffset; //[re]
     398
     399            // Now calculate the distance to move from now
     400            // to a time in t+dt.
     401            dest -= sepos;
    352402
    353403            dtime = dt;
     
    412462        if (fOut)
    413463        {
    414             fOut->Lock();
     464            fOut->Lock("MTracking::TrackPosition");
    415465            *fOut << "RE-REPORT " << MTime(-1) << " " << repos.Zd() << " " << repos.Az() <<" " << vt.Zd() << " " << vt.Az() << endl;
    416             fOut->UnLock();
     466            fOut->UnLock("MTracking::TrackPosition");
    417467        }
    418468
     
    455505    lout << "- Tracking Thread started..." << endl;
    456506
    457     const XY re2se = fCosy->kGearTot/fCosy->kResSE; //[re/se]
     507    //const XY re2se = fCosy->kGearTot/fCosy->kResSE; //[re/se]
    458508
    459509    SlaStars sla(fCosy->fObservatory);
     
    471521    bool phcaz=false;
    472522
     523    ZdAz wasse = fCosy->GetSePos();
     524    ZdAz oldse = fCosy->GetSePos();
     525
    473526    while (!HasStopFlag())
    474527    {
     
    476529        // This is the time constant which defines how fast
    477530        // you correct for external influences (like wind)
    478         const float weight = 1.; //0.3;
     531        //const float weight = 1.; //0.3;
    479532
    480533        // Check for changes of the shaftencoder values
     
    492545        } while (!phca1 && !phca2 && !phcaz && !HasStopFlag());
    493546
    494         //*fCosy->fOutRep << "> Do Calculation" << endl;
    495 
    496         // Get current position of motors (use last automatically sent
    497         // position (PDO) - requesting the position results in problems
    498         // with thread safty)
    499         ZdAz istre = fCosy->GetRePosPdo();
    500 
    501         // get current position of shaftencoders
    502         ZdAz istse = fCosy->GetSePos(); // [se]
    503 
    504547        // Get time from last shaftencoder position change (position: ist)
    505548        // FIXME: Is this correct?
    506         if (fCosy->fZd1->GetMjd()>fCosy->fZd2->GetMjd())
    507             time.Zd(fCosy->fZd1->GetMjd());
    508         else
    509             time.Zd(fCosy->fZd2->GetMjd());
    510 
    511         time.Az(fCosy->fAz->GetMjd());
     549        //        time.Az(fCosy->fMac1->GetMjd());
     550        //        time.Zd(fCosy->fMac2->GetMjd());
     551
     552        Double_t mjd1 = fCosy->fZd1->GetMjd();
     553        Double_t mjd2 = fCosy->fZd2->GetMjd();
     554        Double_t mjd0 = fCosy->fAz->GetMjd();
     555
     556        // get current position of shaftencoders (interpolated
     557        // using motor encoders)
     558        const ZdAz istse = GetPointingPosRE(kTRUE)/fCosy->kGearTot*TMath::TwoPi();
     559        //const ZdAz istse = fCosy->GetSePosPdo();
    512560
    513561        // calculate offset for both axis (only one is needed)
    514         const ZdAz offset = (istse*re2se - istre)*weight + fOffset*(weight-1);
    515 
     562        // *NEW* offset handling
     563        //.const ZdAz offset = istre; //(istse*re2se - istre)*weight + fRePos*(weight-1);
    516564        // if Shaftencoder changed position, calculate nominal position
    517565        if (phca1 || phca2)
    518566        {
    519             const ZdAz dummy = sla.CalcZdAz(fCosy->fRaDec, time.Zd());
     567            ZdAz dummy = sla.CalcZdAz(fCosy->fRaDec, fCosy->fMac2->GetPdoMjd());//TMath::Max(mjd1, mjd2));
     568            dummy = fCosy->AlignTrackingPos(dummy);
     569            dummy = fCosy->fBending(dummy);
    520570            soll.Zd(dummy.Zd()); // [rad]
    521             fOffset.Zd(offset.Zd());
    522571        }
    523572        if (phcaz)
    524573        {
    525             const ZdAz dummy = sla.CalcZdAz(fCosy->fRaDec, time.Az());
     574            const Double_t mjd = fCosy->fMac1->GetMjd();
     575            ZdAz dummy = sla.CalcZdAz(fCosy->fRaDec, fCosy->fMac1->GetPdoMjd());//mjd0);
     576            dummy = fCosy->AlignTrackingPos(dummy);
     577            dummy = fCosy->fBending(dummy);
    526578            soll.Az(dummy.Az()); // [rad]
    527             fOffset.Az(offset.Az());
    528579        }
    529580
    530         // After calculation of fOffset is done we need 'ist' in rad
    531         istse /= fCosy->kResSE/TMath::TwoPi(); // [rad]
     581        fCosy->fZdAzSoll = soll;
    532582
    533583        // Calculate the aligned tracking posotion from 'soll'-position
    534         fCosy->fZdAzSoll = fCosy->AlignTrackingPos(soll);
    535 
    536         /* --- OLD --- */
    537         //fCosy->fTrackingError = istse-fCosy->fBending(fCosy->fZdAzSoll);
    538         /* --- NEW --- */
    539         fCosy->fTrackingError = fCosy->fBending.CorrectBack(istse)-fCosy->fZdAzSoll;
    540         /* --- END --- */
     584        if (phca1 || phca2)
     585            fCosy->fTrackingError.Zd(soll.Zd()-istse.Zd());
     586        if (phcaz)
     587            fCosy->fTrackingError.Az(soll.Az()-istse.Az());
    541588    }
    542589
  • trunk/MagicSoft/Cosy/main/MTracking.h

    r4076 r4105  
    2020    Float_t fTrackDec;
    2121
    22     ZdAz    fOffset; // Offset between se and re coordinate system [re]
     22    //Int_t fSePosZd1;
     23    //Int_t fSePosZd2;
     24    //Int_t fSePosAz;
    2325
    24     MLog *fOut;
     26    //Int_t fRePosZd1;
     27    //Int_t fRePosZd2;
     28    //Int_t fRePosAz;
     29
     30    //ZdAz    fRePos;  // Offset between se and re coordinate system [re]
     31    //ZdAz    fSePos;  // Shaftencoder Position
     32
     33    MLog   *fOut;
    2534
    2635    bool RequestRePos();
     
    2837    bool LimitSpeed(ZdAz *vt, const SlaStars &sla) const;
    2938    bool InitTracking();
    30     //void StopTracking();
     39    ZdAz GetPointingPosRE(Bool_t pdo=kFALSE) const;
    3140
    3241    void *Thread();
     
    3948
    4049    void SetOut(MLog *fout) { fOut = fout; }
    41     //void TalkThreadTracking();
    42  
     50
    4351    ClassDef(MTracking, 0)
    4452};
  • trunk/MagicSoft/Cosy/main/MainLinkDef.h

    r2278 r4105  
    1010#pragma link C++ class MBending;
    1111
     12#pragma link C++ class MPointing;
     13#pragma link C++ class MTracking;
     14
    1215#endif
  • trunk/MagicSoft/Cosy/main/Makefile

    r2384 r4105  
    3434SRCFILES = MBending.cc \
    3535           MStarguider.cc \
     36           MPointing.cc \
     37           MTracking.cc \
    3638           MCaos.cc \
    3739           MCosy.cc
  • trunk/MagicSoft/Cosy/tcpip/MCeCoCom.cc

    r4076 r4105  
    5959    fSolarRadiation = solar;
    6060    fWindSpeed = wind;
     61
     62    if (fWindSpeed>30)
     63        fAlarmCounter++;
     64    else
     65        fAlarmCounter=0;
    6166
    6267    cout << "Zd/Az: " << zd << "/" << az << "  ";
     
    131136    if (fHumidity>80)
    132137        rc++;
     138    if (fWindSpeed>10)
     139        rc++;
    133140    if (fWindSpeed>20)
    134141        rc++;
    135142    if (fWindSpeed>30)
    136143        rc++;
    137     if (fWindSpeed>50)
    138         rc++;
    139144
    140145    return rc;
  • trunk/MagicSoft/Cosy/tcpip/MCeCoCom.h

    r4076 r4105  
    3131    ComStatus_t fComStat; // communication status
    3232
    33     Float_t fHumidity;       // [%]
    34     Float_t fTemperature;    // [deg] celsius
    35     Float_t fWindSpeed;      // [km/h]
    36     Float_t fSolarRadiation; // [W/m^2] IR-Radiation
     33    Float_t fHumidity;         // [%]
     34    Float_t fTemperature;      // [deg] celsius
     35    Float_t fWindSpeed;        // [km/h]
     36    Float_t fSolarRadiation;   // [W/m^2] IR-Radiation
     37
     38    Int_t   fAlarmCounter;     // Counter for alarm cases
    3739
    3840    virtual bool InterpreteCmd(TString cmd, TString str);
     
    5658    TString GetWeather() const;
    5759    Int_t   GetWeatherStatus() const;
     60
     61    Bool_t  HasAlarm() const { return fAlarmCounter>3; }
    5862};
    5963
  • trunk/MagicSoft/Cosy/tcpip/MDriveCom.cc

    r4076 r4105  
    156156    er *= kRad2Deg;
    157157
    158     rd.Ra(rd.Ra()*24/360);
     158    rd.Ra(rd.Ra()/15);
    159159
    160160    // Set status flag
  • trunk/MagicSoft/Cosy/tcpip/MTcpIpIO.cc

    r4076 r4105  
    7474        return true;
    7575
    76     const Int_t rc = lout.IsOutputDeviceEnabled(MLog::eGui);
    77     lout.DisableOutputDevice(MLog::eGui);
    78     lout.Lock();
    79     lout << msg << flush;
    80     lout.UnLock();
    81     if (rc)
    82         lout.EnableOutputDevice(MLog::eGui);
     76    if (lout.Lock("MTcpIpIO::Send"))
     77    {
     78        const Int_t rc = lout.IsOutputDeviceEnabled(MLog::eGui);
     79        lout.DisableOutputDevice(MLog::eGui);
     80        lout << msg << flush;
     81        lout.UnLock("MTcpIpIO::Send");
     82        if (rc)
     83            lout.EnableOutputDevice(MLog::eGui);
     84    }
    8385
    8486    fTime = t;
  • trunk/MagicSoft/Cosy/videodev/Camera.h

    r4076 r4105  
    1 #ifndef CAMERA_H
    2 #define CAMERA_H
     1#ifndef COSY_Camera
     2#define COSY_Camera
    33
    44#ifndef ROOT_TMutex
  • trunk/MagicSoft/Cosy/videodev/FilterLed.cc

    r4076 r4105  
    88#include "Ring.h"
    99
     10#include "MGMap.h"
     11
    1012ClassImp(FilterLed);
    11 
    12 void FilterLed::DrawCircle(float cx, float cy, float rpix, byte col) const
    13 {
    14     if (cx-rpix<1 || cy-rpix<1 || cx+rpix>fW-2 || cy+rpix>fH-2)
    15         return;
    16 
    17     for (int dx=-(int)(rpix*0.7); dx<(int)(rpix*0.7); dx+=2)
    18     {
    19         const int dy = (int)sqrt(rpix*rpix-dx*dx);
    20         fImg[(int)(cx+dx) + (int)(cy-dy)*fW] = col;
    21         fImg[(int)(cx+dx) + (int)(cy+dy)*fW] = col;
    22         fImg[(int)(cx-dy) + (int)(cy+dx)*fW] = col;
    23         fImg[(int)(cx+dy) + (int)(cy+dx)*fW] = col;
    24     }
    25 }
    26 
    27 void FilterLed::DrawCircle(const Ring &l, byte col=0x40) const
    28 {
    29     DrawCircle(l.GetX(), l.GetY(), l.GetR(), col);
    30 }
    31 
    32 void FilterLed::DrawCircle(const Ring &l, double r, byte col=0x40) const
    33 {
    34     DrawCircle(l.GetX(), l.GetY(), r, col);
    35 }
    3613
    3714void FilterLed::DrawBox(const int x1, const int y1,
     
    3916                        const int col) const
    4017{
    41     for (int x=x1; x<x2+1; x++)
    42         for (int y=y1; y<y2+1; y++)
    43             if (x>=0 && x<fW-1 && y>=0 && y<fH-1)
    44                 fImg[y*fW+x] = col;
    45 }
    46 
    47 void FilterLed::MarkPoint(const Led &led) const
    48 {
    49     const int x = (int)(led.GetX()+.5);
    50     const int y = (int)(led.GetY()+.5);
    51     const int m = (int)(led.GetMag());
    52 
    53     MarkPoint(x, y, m);
     18    MGMap::DrawBox(fImg, 768, 576, x1, y1, x2, y2, col);
    5419}
    5520
     
    6429    DrawBox(x+5, y, x+8, y, m);
    6530    DrawBox(x, y-8, x, y-5, m);
     31}
     32
     33void FilterLed::MarkPoint(const Led &led) const
     34{
     35    const int x = (int)(led.GetX()+.5);
     36    const int y = (int)(led.GetY()+.5);
     37    const int m = (int)(led.GetMag());
     38
     39    MarkPoint(x, y, m);
     40}
     41
     42void FilterLed::DrawCircle(float cx, float cy, float r, byte col) const
     43{
     44    MGMap::DrawCircle(fImg, 768, 576, cx, cy, r, col);
     45}
     46
     47void FilterLed::DrawCircle(const Ring &l, byte col) const
     48{
     49    DrawCircle(l.GetX(), l.GetY(), l.GetR(), col);
     50}
     51
     52void FilterLed::DrawCircle(const Ring &l, double r, byte col) const
     53{
     54    DrawCircle(l.GetX(), l.GetY(), r, col);
    6655}
    6756
Note: See TracChangeset for help on using the changeset viewer.