Changeset 9439 for trunk


Ignore:
Timestamp:
05/09/09 13:48:12 (15 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Cosy
Files:
1 added
35 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Cosy/Changelog

    r9438 r9439  
    104104   * videodev/FilterLed.[h,cc]:
    105105     - allow the search boxs to be asymmetric
     106
     107   * bending_magic2.txt, leds_magic2.txt, stargleds_magic2.txt,
     108     prepos_magic2.txt:
     109     - added
    106110
    107111
  • trunk/MagicSoft/Cosy/candrv/CandrvLinkDef.h

    r8841 r9439  
    55#pragma link off all functions;
    66
    7 #pragma link C++ class VmodIcan+;
    87#pragma link C++ class CanOpen+;
    98#pragma link C++ class Network+;
    10 #pragma link C++ class Ethernet+;
    11 //#pragma link C++ class Interface+;
    129
    1310#pragma link C++ class NodeDrv+;
  • trunk/MagicSoft/Cosy/candrv/Makefile

    r8809 r9439  
    1717
    1818SRCFILES = nodedrv.cc \
    19            vmodican.cc \
    2019           sdolist.cc \
    2120           canopen.cc \
  • trunk/MagicSoft/Cosy/candrv/canopen.h

    r9132 r9439  
    44#ifndef ROOT_TCondition
    55#include <TCondition.h>
     6#endif
     7
     8#ifdef __CINT__
     9typedef Byte_t   BYTE_t;
     10typedef UShort_t WORD_t;
     11typedef Short_t  WORDS_t;
     12typedef UInt_t   LWORD_t;
     13typedef Int_t    LWORDS_t;
     14struct Message;
     15struct FastMessage;
     16#else
     17#include "gendef.h"
     18#include "dpm.h"
    619#endif
    720
     
    1225#ifndef COSY_MTimeout
    1326#include "MTimeout.h"
    14 #endif
    15 
    16 #ifdef __CINT__
    17 typedef UInt_t LWORD_t;
    18 typedef Short_t WORDS_t;
    1927#endif
    2028
  • trunk/MagicSoft/Cosy/candrv/ethernet.cc

    r8865 r9439  
    3737#include <TSocket.h>
    3838
    39 ClassImp(Ethernet);
     39//ClassImp(Ethernet);
    4040
    4141#undef DEBUG
     
    5656//
    5757Ethernet::Ethernet(const char *addr, const int tx, const int rx, CanOpen *receiver)
    58     : MTcpIpI(rx),/* MTcpIpO(addr, tx),*/ Interface(receiver), fTxAddress(addr), fTxPort(tx)
     58    : MTcpIpI(rx), /*MTcpIpO(addr, tx),*/ Interface(receiver), fTxAddress(addr), fTxPort(tx)
    5959{
    6060    gLog << inf2 << "- Ethernet initialized." << endl;
     
    6868Ethernet::~Ethernet()
    6969{
    70     CancelThread();
     70    MTcpIpI::CancelThread();
    7171    gLog << inf2 << "- Ethernet stopped." << endl;
    7272}
     
    8585    const TString address = MTcpIpO::GetSocketAddress(rx);
    8686
    87     while (!IsThreadCanceled())
     87    while (!MTcpIpI::IsThreadCanceled())
    8888    {
    8989        unsigned char c;
     
    281281#endif
    282282    MTcpIpO::SendFrame(fTxAddress, fTxPort, (char*)(msg.data+1), msg.len-1);
     283//    Send((char*)(msg.data+1), msg.len-1);
    283284#ifdef DEBUG
    284285    st.Print();
  • trunk/MagicSoft/Cosy/candrv/ethernet.h

    r8864 r9439  
    2020
    2121    // Start/stop communication inherited from Interface
    22     void Start() { RunThread(); }
    23     void Stop()  { CancelThread(); }
     22    void Start() { MTcpIpI::RunThread(); }
     23    void Stop()  { MTcpIpI::CancelThread(); }
    2424
    25     Bool_t HasConnection() const { return IsConnectionEstablished(); }
     25    Bool_t HasConnection() const { return MTcpIpI::IsConnectionEstablished(); }
    2626
    2727public:
     
    3232    void SendCanFrame(WORD_t cobid, BYTE_t m[8], BYTE_t rtr=0);
    3333
    34     ClassDef(Ethernet, 0) // hardware interface to the vmodican can module (Janz)
     34//    ClassDef(Ethernet, 0) // hardware interface to the vmodican can module (Janz)
    3535};
    3636
  • trunk/MagicSoft/Cosy/catalog/SlaPlanets.cc

    r8376 r9439  
    4040    double ra, dec, diam;
    4141
    42     // One can use TT instead of TDB for all plenets
     42    // One can use TT instead of TDB for all planets
    4343    // (except the moon)
    4444    // TDB, planet, elong, phi, *ra, *dec, *diam
  • trunk/MagicSoft/Cosy/catalog/SlaStars.cc

    r8847 r9439  
    4949             0, 0,                         // polar motion x, y-coordinate (radians)
    5050             // 273.155, 1013.25, 0.5,     // temp, pressure, humidity
    51              273.155+20, 1013.25, 0.5,     // temp, pressure, humidity
     51             273.155+10, 780.0, 0.25,     // temp, pressure, humidity
    5252             // 0.2, 0.0065,               // wavelength, tropo lapse rate
    5353             0.55, 0.0065,                 // wavelength, tropo lapse rate
  • trunk/MagicSoft/Cosy/catalog/Slalib.cc

    r8847 r9439  
    1818Double_t Slalib::Trunc(Double_t val)
    1919{
    20     /* dint(A) - truncate to nearest whole number towards zero (double) */
     20    // dint(A) - truncate to nearest whole number towards zero (double)
    2121    return val<0 ? TMath::Ceil(val) : TMath::Floor(val);
    22 }
    23 
    24 Double_t Slalib::Round(Double_t val)
    25 {
    26     /* dnint(A) - round to nearest whole number (double) */
    27     return val<0 ? TMath::Ceil(val-0.5) : TMath::Floor(val+0.5);
    2822}
    2923
     
    4034    SetMjd(fTime.GetMjd()+offset/(24*60*60));
    4135}
    42 
    4336
    4437ZdAz Slalib::XYZ2ZdAz(double coord[3]) const
  • trunk/MagicSoft/Cosy/catalog/Slalib.h

    r8847 r9439  
    1919    double fAlpha;
    2020
    21     static Double_t Round(Double_t val);
    2221    static Double_t Trunc(Double_t val);
    2322
  • trunk/MagicSoft/Cosy/catalog/StarCatalog.cc

    r8848 r9439  
    1717using namespace std;
    1818
    19 StarCatalog::StarCatalog(MObservatory::LocationName_t key) : SlaStars(key), fW(768), fH(576), fAstro(0), /*fSao(NULL), fSrt(NULL), fEntries(0),*/ fSinAngle(0), fCosAngle(1), fBox(768)
     19StarCatalog::StarCatalog(MObservatory::LocationName_t key) : SlaStars(key), fW(768), fH(576), fAstro(0), /*fSao(NULL), fSrt(NULL), fEntries(0),*/ fSinAngle(0), fCosAngle(1), fBoxX(768), fBoxY(576)
    2020{
    2121    fAstro = new MAstroCatalog;
     
    3232{
    3333    // pixsize [arcsec/pixel]
    34     fPixSize = D2PI/360.0*pixsize/3600; // [rad / (deg*pixel)]
     34    fPixSize = TMath::DegToRad()*pixsize/3600; // [rad / (deg*pixel)]
    3535    fAstro->SetRadiusFOV(pixsize, 768, 576);
     36    // fov = hypot(768, 576)/2*pixsize/3600;
    3637}
    3738
    3839double StarCatalog::GetPixSize() const
    3940{
    40     return fPixSize*3600*360.0/D2PI;
     41    return fPixSize*3600*TMath::RadToDeg();
    4142}
    4243
     
    5556void StarCatalog::SetAltAz(const AltAz &altaz)
    5657{
    57     fAltAz = altaz * D2PI/360.0;
     58    fAltAz = altaz * TMath::DegToRad();
    5859    fRaDec = CalcRaDec(fAltAz);
    5960
     
    7273void StarCatalog::SetRaDec(const RaDec &radec)
    7374{
    74     const RaDec rd = fRaDec*360.0/D2PI;;
     75    const RaDec rd = fRaDec*TMath::RadToDeg();
    7576
    7677    const Bool_t same =
     
    7879        rd.Dec()>radec.Dec()-1e-5 && rd.Dec()<radec.Dec()+1e-5;
    7980
    80     fRaDec = radec * D2PI/360.0;
     81    fRaDec = radec * TMath::DegToRad();
    8182    fAltAz = CalcAltAz(fRaDec);
    8283
     
    153154
    154155void StarCatalog::CalcStars(MStarList &list, int xc, int yc,
    155                             int xo, int yo) const
    156 {
    157     // For an apropriate unit conversion to pixels [pix/rad]
    158     const Double_t scale = TMath::RadToDeg()*TMath::Sqrt(768*768 + 576*576)/(fAstro->GetRadiusFOV()*2);
    159 
    160     // Offsets to shift [-n/2;n/2] to [0;n] and to
    161     // move the stars in the counterdirection of the LEDs
    162     const Int_t offx = 768/2 + xo;
    163     const Int_t offy = 576/2 + yo;
     156                            float offx, float offy) const
     157{
     158//    const Int_t offx = 768/2 + xo;
     159//    const Int_t offy = 576/2 + yo;
    164160
    165161    // Allow catalog stars to be a bit outside [0.2deg] of the
    166162    // monitored window. To get the std behaviour set offset=0
    167     const Int_t offset = TMath::Nint(0.2*TMath::DegToRad()*scale);
    168     const Int_t box    = fBox+offset;
     163    const Int_t offset = TMath::Nint(0.2*TMath::DegToRad()/fPixSize);
     164    const Int_t boxx   = fBoxX+offset;
     165    const Int_t boxy   = fBoxY+offset;
    169166
    170167    // CalcStars flips the picture in X defaultwise now
    171168    // This defined the box in which stars are really returned
     169    const int x0 = TMath::Max((768-xc)-boxx,   -offset);
     170    const int y0 = TMath::Max(yc-boxy,         -offset);
     171    const int x1 = TMath::Min((768-xc)+boxx, fW+offset);
     172    const int y1 = TMath::Min(yc+boxy,       fH+offset);
     173/*
    172174    const int x0 = TMath::Max((768-xc)-box,   -offset);
    173     const int y0 = TMath::Max(yc-box,         -offset);
    174175    const int x1 = TMath::Min((768-xc)+box, fW+offset);
    175     const int y1 = TMath::Min(yc+box,       fH+offset);
    176 
     176
     177    const int y0 = TMath::Max(yc-box-100,         -offset);
     178    const int y1 = TMath::Min(yc+box+100,       fH+offset);
     179 */
     180
     181/*
    177182    // Align stars into telescope system
    178183    // (Move the telescope to pointing position)
     
    181186    align.RotateY(-(TMath::Pi()/2-fAltAz.Alt()));
    182187    align.RotateZ(TMath::Pi()/2);
     188 */
     189
     190    TRotation rot;
     191    rot.RotateY(-(TMath::Pi()/2-fAltAz.Alt()));
    183192
    184193    // Get List of stars from catalog
     
    200209        const ZdAz  za(CalcZdAz(rd));
    201210
     211        TVector3 v;
     212        //v.SetMagThetaPhi(1., TMath::Pi()/2-za.Alt(), za.Az()-fAltAz.Az());
     213        v.SetMagThetaPhi(1., za.Zd(), za.Az()-fAltAz.Az());
     214        v *= rot;
     215
     216        if (v(2)<0)
     217            continue;
     218
     219        // Stretch such, that the Z-component is alwas the same. Now
     220        // X and Y contains the intersection point between the star-light
     221        // and the plain of a virtual plain screen (ccd...)
     222        v *= 1./v(2);
     223
     224        // Do unit conversion to pixels
     225        v *= 1./fPixSize;
     226
     227        const Double_t x = -v.Y();
     228        const Double_t y =  v.X();
     229
     230/*
    202231        // Virtually move telescope to pointing position
    203232        TVector3 loc;
     
    215244
    216245        // Do an apropriate unit conversion to pixels
    217         loc *= scale;
    218 
     246        loc *= 1./fPixSize;
     247
     248        const Double_t x = loc.X();
     249        const Double_t y = loc.Y();
     250*/
    219251        // if (loc.Mod2()>fRadiusFOV*fRadiusFOV)
    220252        //     continue;
    221253
     254
    222255        // Rotate by the rotation angle of the video camera
    223256        // and add the offsets on both axis
    224         Float_t xx = loc.X()*fCosAngle - loc.Y()*fSinAngle  + offx;
    225         Float_t yy = loc.X()*fSinAngle + loc.Y()*fCosAngle  + offy;
     257        const Double_t xx = x*fCosAngle - y*fSinAngle + 768 - offx;
     258        const Double_t yy = x*fSinAngle + y*fCosAngle + offy;
    226259
    227260        // Check if the resulting star is in the
     
    235268}
    236269
     270/*
    237271AltAz StarCatalog::CalcAltAzFromPix(Double_t pixx, Double_t pixy) const
    238272{
     
    251285    return AltAz(-dec, ha+fAltAz.Az());
    252286}
     287*/
     288
     289ZdAz StarCatalog::CalcDeltaZdAzFromPix(Double_t dpixx, Double_t dpixy) const
     290{
     291    double dx =  dpixx*fCosAngle + dpixy*fSinAngle;
     292    double dy = -dpixx*fSinAngle + dpixy*fCosAngle;
     293
     294    TVector3 loc(dy, -dx, 1./fPixSize);
     295
     296    loc.RotateY(TMath::Pi()/2-fAltAz.Alt());
     297
     298    return ZdAz(loc.Theta()-TMath::Pi()/2+fAltAz.Alt(), -loc.Phi());
     299
     300    /*
     301    // Align stars into telescope system
     302    // (Move the telescope to pointing position)
     303    TRotation align;
     304    align.RotateZ(-fAltAz.Az());
     305    align.RotateY(-(TMath::Pi()/2-fAltAz.Alt()));
     306    align.RotateZ(TMath::Pi()/2);
     307
     308
     309    TVector3 loc(dx, dy, 1./fPixSize);
     310
     311    loc *= align.Inverse();
     312
     313    cout << (TMath::Pi()/2-loc.Theta()-alt)*TMath::RadToDeg() << " " << (loc.Phi()-az)*TMath::RadToDeg() << endl;
     314
     315
     316
     317    TVector3 loc(dx, -dy, 1./fPixSize);
     318
     319    loc *= align.Inverse();
     320
     321    return ZdAz(loc.Theta(), loc.Phi());*/
     322}
  • trunk/MagicSoft/Cosy/catalog/StarCatalog.h

    r9435 r9439  
    4141
    4242    void   SetRaDec(const RaDec &radec);
    43     void   SetAltAz(const AltAz &altaz);
    4443
    45     int    fBox;
     44    int    fBoxX;
     45    int    fBoxY;
    4646
    4747public:
    4848    StarCatalog(MObservatory::LocationName_t key);
    4949    virtual ~StarCatalog();
     50
     51    void   SetAltAz(const AltAz &altaz);
    5052
    5153    void GetImg(byte *img, byte *cimg, MStarList &list) const;
     
    6567    double GetPixSize() const;
    6668
    67     AltAz CalcAltAzFromPix(Double_t pixx, Double_t pixy) const;
     69    //AltAz CalcAltAzFromPix(Double_t pixx, Double_t pixy) const;
     70    ZdAz  CalcDeltaZdAzFromPix(Double_t pixx, Double_t pixy) const;
    6871
    6972    virtual void SetMjd(double mjd);
     
    7578
    7679    //void   CalcStars(MStarList &list);
    77     void   CalcStars(MStarList &list, int xc, int yc, int xo, int yo) const;
     80    void   CalcStars(MStarList &list, int xc, int yc, float xo, float yo) const;
    7881    static void DrawStars(MStarList &list, byte *img);
    7982
    80     void SetBox(int box)   { fBox = box; }
     83    void SetBox(int box)   { fBoxX = fBoxY = box; }
     84    void SetBox(int boxx, int boxy)   { fBoxX = boxx; fBoxY=boxy; }
    8185
    8286    ClassDef(StarCatalog, 0)
  • trunk/MagicSoft/Cosy/cosy.cc

    r9435 r9439  
    7474        return kTRUE;
    7575
     76    gLog << all << "- Trying to switch " << (on?"on":"off") << " " << (port==kPortTPoint?"TPoint":"Starguider") << " ccd via " << ip << endl;
     77
    7678    TSocket s(ip, 80);
    7779    if (!s.IsValid())
     
    160162    const TString ceco        = env.GetValue("IpAddressCentralControl", "161.72.130.60");
    161163    const TString powerswitch = env.GetValue("IpAddressPowerSwitch", "");
    162     const TString pointing    = env.GetValue("PointingModel", "bending.txt");
     164    const Int_t   telescope   = env.GetValue("Telescope", 1);
    163165
    164166    // And move the resource options from the command line to the MEnv
     
    238240
    239241    MDriveCom *com = new MDriveCom(ceco, ceco_tx, ceco_rx);
    240     com->SetTelescope(2);
    241 
    242     MCosy *cosy = new MCosy(env, com, pointing);
     242    com->SetTelescope(telescope);
     243
     244    MCosy *cosy = new MCosy(env, com);
    243245
    244246    com->SetMsgQueue(cosy);
     
    254256    if (kDebugEnv>0)
    255257        env.PrintUntouched();
    256 
    257258
    258259    MStarguider *client=0;
  • trunk/MagicSoft/Cosy/devdrv/dkc.cc

    r9435 r9439  
    2222    fStatus(0), fStatusDKC(0), fStatusPdo3(0xff), fArmed(false),
    2323    fReport(NULL),fLabel(NULL),fUpdPos(0)
    24 {
    25 }
    26 
    27 Dkc::~Dkc()
    2824{
    2925}
     
    165161    {
    166162    case 0x1000:
    167         if (subidx==1)
    168         {
    169             gLog << inf2 << "- " << GetNodeName() << ": Node is" << (val?" ":" not ") << "armed." << endl;
    170             fArmed = val==1;
    171         }
     163        gLog << inf2 << "- " << GetNodeName() << ": Node is" << (val?" ":" not ") << "armed." << endl;
     164        fArmed = val==1;
    172165        return;
    173166
    174167    case 0x1003:
    175168        // FIXME, see Init
    176         if (subidx!=2)
    177             return;
    178169        gLog << inf2 << "- " << GetNodeName() << ": Error[0]=" << hex << val << dec << endl;
    179170        CheckErrorDKC(val);
     
    196187
    197188    case 0x6004:
    198         if (subidx==0)
    199         {
    200             fPdoPos1 = (LWORDS_t)val;
    201             fPdoTime1.Set(tv);
    202             fHasChangedPos1 = true;
    203         }
    204         if (subidx==1)
    205         {
    206             fPdoPos2 = (LWORDS_t)val;
    207             fPdoTime2.Set(tv);
    208             fHasChangedPos2 = true;
    209         }
     189        fPdoPos1 = (LWORDS_t)val;
     190        fPdoTime1.Set(tv);
     191        fHasChangedPos1 = true;
     192        return;
     193
     194    case 0x6005:
     195        fPdoPos2 = (LWORDS_t)val;
     196        fPdoTime2.Set(tv);
     197        fHasChangedPos2 = true;
    210198        return;
    211199
     
    246234    {
    247235    case 0x1000:
    248         switch (subidx)
    249         {
    250         case 1:
    251             //lout << ddev(MLog::eGui);
    252             gLog << inf2 << "- " << GetNodeName() << ": State of node set." << endl;
    253             //lout << edev(MLog::eGui);
    254             return;
    255         }
    256         break;
     236        gLog << inf2 << "- " << GetNodeName() << ": State of node set." << endl;
     237        return;
     238
     239    case 0x1001:
     240        gLog << inf2 << "- " << GetNodeName() << ": PDOs requested." << endl;
     241        return;
    257242
    258243    case 0x2002:
    259         //lout << ddev(MLog::eGui);
    260244        gLog << inf2 << "- " << GetNodeName() << ": Velocity set." << endl;
    261         //lout << edev(MLog::eGui);
    262245        return;
    263246
    264247    case 0x2003:
    265         //lout << ddev(MLog::eGui);
    266248        gLog << inf2 << "- " << GetNodeName() << ": Acceleration set." << endl;
    267         //lout << edev(MLog::eGui);
    268249        return;
    269250
    270251    case 0x3006:
    271         switch (subidx)
    272         {
    273         case 0:
    274             //lout << ddev(MLog::eGui);
    275             gLog << inf2 << "- " << GetNodeName() << ": RPM mode switched." << endl;
    276             //lout << edev(MLog::eGui);
    277             return;
    278 
    279         case 1:
    280             /*
    281              lout << ddev(MLog::eGui);
    282              lout << "- Velocity set (" << GetNodeName() << ")" << endl;
    283              lout << edev(MLog::eGui);
    284              */
    285             return;
    286         }
    287         break;
     252        gLog << inf2 << "- " << GetNodeName() << ": RPM mode switched." << endl;
     253        return;
     254
     255    case 0x3007:
     256        //gLog << inf2 << "- Velocity set (" << GetNodeName() << ")" << endl;
     257        return;
    288258
    289259    case 0x4000:
     
    292262
    293263    case 0x6000:
    294         //lout << ddev(MLog::eGui);
    295264        gLog << inf2 << "- " << GetNodeName() << ": Rotation direction set." << endl;
    296         //lout << edev(MLog::eGui);
    297265        return;
    298266
    299267    case 0x6002:
    300         //lout << ddev(MLog::eGui);
    301         gLog << inf2 << "- " << GetNodeName() << ": Velocitz resolution set." << endl;
    302         //lout << edev(MLog::eGui);
     268        gLog << inf2 << "- " << GetNodeName() << ": Velocity resolution set." << endl;
    303269        return;
    304270
    305271    case 0x6004:
    306         switch (subidx)
    307         {
    308         case 0:
    309             //lout << ddev(MLog::eGui);
    310             gLog << inf2 << "- " << GetNodeName() << ": Absolute positioning started." << endl;
    311             fPosActive = kTRUE; // Make sure that the status is set correctly already before the first PDO
    312             //lout << edev(MLog::eGui);
    313             return;
    314 
    315         case 1:
    316             //lout << ddev(MLog::eGui);
    317             gLog << inf2 << "- " << GetNodeName() << ": Relative positioning started." << endl;
    318             fPosActive = kTRUE; // Make sure that the status is set correctly already before the first PDO
    319             //lout << edev(MLog::eGui);
    320             return;
    321         }
    322         break;
    323 
    324 
    325     }
     272        gLog << inf2 << "- " << GetNodeName() << ": Absolute positioning started." << endl;
     273        fPosActive = kTRUE; // Make sure that the status is set correctly already before the first PDO
     274        return;
     275
     276    case 0x6005:
     277        gLog << inf2 << "- " << GetNodeName() << ": Relative positioning started." << endl;
     278        fPosActive = kTRUE; // Make sure that the status is set correctly already before the first PDO
     279        return;
     280    }
     281
    326282    NodeDrv::HandleSDOOK(idx, subidx, data, tv);
    327283}
     
    348304}
    349305
    350 void Dkc::StartNode()
    351 {
    352     //
    353     // Switch node from pre-operational state to operational state
    354     // (This is not CANOpen compatible)
    355     // After this the MACS will react on real movement commands.
    356     //
    357     gLog << inf2 << "- " << GetNodeName() << ": Starting Node." << endl;
    358     SendSDO(0x1000, 1, (LWORD_t)1);
    359     WaitForSdo(0x1000, 1);
    360 }
    361 
    362306void Dkc::Arm()
    363307{
    364     StartNode();
     308    gLog << inf2 << "- " << GetNodeName() << ": Arming node." << endl;
     309    SendSDO(0x1000, (LWORD_t)1);
     310    WaitForSdo(0x1000);
    365311}
    366312
    367313void Dkc::Disarm()
    368314{
    369     gLog << inf2 << "- " << GetNodeName() << ": Stopping Node." << endl;
    370     SendSDO(0x1000, 1, (LWORD_t)0);
    371     WaitForSdo(0x1000, 1);
     315    gLog << inf2 << "- " << GetNodeName() << ": Disarming Node." << endl;
     316    SendSDO(0x1000, (LWORD_t)0);
     317    WaitForSdo(0x1000);
    372318}
    373319
     
    385331    //
    386332    gLog << inf2 << "- " << GetNodeName() << ": Requesting Error[0]." << endl;
    387     RequestSDO(0x1003, 2);
    388     WaitForSdo(0x1003, 2);
     333    RequestSDO(0x1003);
     334    WaitForSdo(0x1003);
    389335
    390336    /*
     
    404350    ReqVelMax(); // Init fVelMax
    405351
     352    // Request to send all PDOs at least once
     353    ReqPDOs();
     354
    406355#ifdef EXPERT
    407     StartNode();
     356    Arm();
    408357#endif
    409358
    410359    gLog << inf2 << "- " << GetNodeName() << ": Checking armed status." << endl;
    411     RequestSDO(0x1000, 1);
    412     WaitForSdo(0x1000, 1);
     360    RequestSDO(0x1000);
     361    WaitForSdo(0x1000);
    413362}
    414363
     
    422371}
    423372
     373void Dkc::ReqPDOs()
     374{
     375    gLog << inf2 << "- " << GetNodeName() << ": Requesting all PDOs." << endl;
     376
     377    SendSDO(0x1001, (LWORD_t)1);
     378    WaitForSdo(0x1001);
     379}
     380
    424381void Dkc::ReqPos1()
    425382{
    426383    gLog << inf2 << "- " << GetNodeName() << ": Requesting position feedback 1." << endl;
    427     RequestSDO(0x6004, 0);
    428     WaitForSdo(0x6004, 0);
     384    RequestSDO(0x6004);
     385    WaitForSdo(0x6004);
    429386}
    430387
     
    432389{
    433390    gLog << inf2 << "- " << GetNodeName() << ": Requesting position feedback 2." << endl;
    434     RequestSDO(0x6004, 1);
    435     WaitForSdo(0x6004, 1);
     391    RequestSDO(0x6005);
     392    WaitForSdo(0x6005);
    436393}
    437394
     
    460417{
    461418    gLog << dbg << "- Setting acceleration to: " << acc << endl;
    462     SendSDO(0x2003, 0, acc);  // acceleration
    463     WaitForSdo(0x2003, 0);
    464 }
    465 /*
    466 void Dkc::SetDeceleration(LWORD_t dec)
    467 {
    468     gLog << dbg << "- Setting deceleration to: " << dec << endl;
    469     SendSDO(0x2003, 1, dec);
    470     WaitForSdo(0x2003, 1);
    471 }
    472 */
     419    SendSDO(0x2003, acc);  // acceleration
     420    WaitForSdo(0x2003);
     421}
     422
    473423void Dkc::SetRpmMode(BYTE_t mode)
    474424{
     
    476426    // SetRpmMode(FALSE) stop the motor, but lets the position control unit on
    477427    //
    478     SendSDO(0x3006, 0, mode ? string('s','t','r','t') : string('s','t','o','p'));
    479     WaitForSdo(0x3006, 0);
     428    SendSDO(0x3006, mode ? string('s','t','r','t') : string('s','t','o','p'));
     429    WaitForSdo(0x3006);
    480430}
    481431
    482432void Dkc::SetRpmVelocity(LWORDS_t cvel)
    483433{
    484     SendSDO(0x3006, 1, (LWORD_t)cvel);
    485     WaitForSdo(0x3006, 1);
     434    SendSDO(0x3007, (LWORD_t)cvel);
     435    WaitForSdo(0x3007);
    486436}
    487437
     
    496446
    497447    gLog << dbg << GetNodeName() << ": Starting relative positioning by " << (LWORDS_t)pos << " ticks." << endl;
    498     SendSDO(0x6004, 1, (LWORD_t)pos);
     448    SendSDO(0x6005, (LWORD_t)pos);
    499449    fPosActive = kTRUE; // Make sure that the status is set correctly already before the first PDO
    500450}
     
    510460
    511461    gLog << dbg << GetNodeName() << ": Starting absolute positioning to " << (LWORDS_t)pos << " ticks." << endl;
    512     SendSDO(0x6004, 0, (LWORD_t)pos);
     462    SendSDO(0x6004, (LWORD_t)pos);
    513463    fPosActive = kTRUE; // Make sure that the status is set correctly already before the first PDO
    514464}
     
    526476
    527477    gLog << dbg << GetNodeName() << ": Starting absolute positioning to " << p << " ticks." << endl;
    528     SendSDO(0x6004, 0, p);
     478    SendSDO(0x6004, p);
    529479    fPosActive = kTRUE; // Make sure that the status is set correctly already before the first PDO
    530 }
    531 
    532 void Dkc::StartVelSync()
    533 {
    534     //
    535     // The syncronization mode is disabled by a 'MOTOR STOP'
    536     // or by a positioning command (POSA, ...)
    537     //
    538     gLog << inf2 << "- " << GetNodeName() << ": Starting RPM Sync Mode." << endl;
    539     SendSDO(0x3007, 0, string('s', 'y', 'n', 'c'));
    540     WaitForSdo(0x3007, 0);
    541 }
    542 
    543 void Dkc::StartPosSync()
    544 {
    545     //
    546     // The syncronization mode is disabled by a 'MOTOR STOP'
    547     // or by a positioning command (POSA, ...)
    548     //
    549     gLog << inf2 << "- " << GetNodeName() << ": Starting Position Sync Mode." << endl;
    550     SendSDO(0x3007, 1, string('s', 'y', 'n', 'c'));
    551     WaitForSdo(0x3007, 1);
    552480}
    553481
  • trunk/MagicSoft/Cosy/devdrv/dkc.h

    r9132 r9439  
    7373public:
    7474    Dkc(const BYTE_t nodeid, const char *name=NULL);
    75     virtual ~Dkc();
     75    virtual ~Dkc() { }
    7676
    7777    static LWORD_t string(BYTE_t b0=0, BYTE_t b1=0, BYTE_t b2=0, BYTE_t b3=0)
     
    8484                 BYTE_t d3=0, BYTE_t d4=0, BYTE_t d5=0);
    8585
     86    void ReqPDOs();
    8687    void ReqPos1();
    8788    void ReqPos2();
     
    9192    void ReqVelMax();
    9293    void SetAcceleration(LWORD_t acc);
    93     void SetDeceleration(LWORD_t dec);
     94//    void SetDeceleration(LWORD_t dec);
    9495    void SetVelocity(LWORD_t vel);
    9596    void SetVelocityRel(Double_t vel);
    9697    void SetRpmMode(BYTE_t mode=TRUE);
    9798    void SetRpmVelocity(LWORDS_t cvel);
    98     void SetPDO1On(BYTE_t flag=TRUE);
    99 
    100     void StartVelSync();
    101     void StartPosSync();
    10299
    103100    void StartRelPos(LWORDS_t pos);
    104101    void StartAbsPos(LWORDS_t pos);
    105102    void StartAbsPosRev(Double_t pos);
    106 
    107     void StartNode();
    108103
    109104    bool IsArmed() const { return fArmed; }
  • trunk/MagicSoft/Cosy/gui/MGCosy.cc

    r9132 r9439  
    318318}
    319319
    320 void MGCosy::CreatePredefinedPos(TGCompositeFrame *tf1)
     320void MGCosy::CreatePredefinedPos(TGCompositeFrame *tf1, const char *prepos)
    321321{
    322322    TGComboBox *box = new TGComboBox(tf1, kCB_PredefPos);
     
    331331    fList->Add(lay);
    332332
    333     ifstream fin("prepos.txt");
     333    ifstream fin(prepos);
    334334    if (!fin)
    335335    {
    336         gLog << err << "ERROR: Predifined positions in 'prepos.txt' not found." << endl;
     336        gLog << err << "ERROR: Predifined positions in '" << prepos << "' not found." << endl;
    337337        return;
    338338    }
     
    391391}
    392392
    393 void MGCosy::CreateTabs()
     393void MGCosy::CreateTabs(const char *prepos)
    394394{
    395395    TGCompositeFrame *tf1 = fTab->AddTab("Position");
     
    408408    fList->Add(fCZdAz);
    409409
    410     CreatePredefinedPos(tf1);
     410    CreatePredefinedPos(tf1, prepos);
    411411    CreateStarList(tf4);
    412412
     
    728728}
    729729
    730 MGCosy::MGCosy(MObservatory::LocationName_t key, MsgQueue *q)
     730MGCosy::MGCosy(MObservatory::LocationName_t key, const char *prepos, MsgQueue *q)
    731731    : TGMainFrame(gClient->GetRoot(), 1, 1), fObservatory(key), fQueue(q)
    732732{
     
    755755
    756756    fAccuracy = new MGAccuracy(f1, 300);
    757     fAccuracy->DrawText("0.5se", "1.0se", "2.0se", "Ctrl Deviation [min]");
     757    fAccuracy->SetColorScale(1);
     758    fAccuracy->DrawText("1.0'", "2.0'", "3.0'", "Ctrl Deviation [min]");
     759    //fAccuracy->DrawText("0.5se", "1.0se", "2.0se", "");
    758760    fAccuracy->DrawCircles();
    759761
     
    815817    AddFrame(f2, hints2);
    816818
    817     CreateTabs();
     819    CreateTabs(prepos);
    818820    CreateLabel(frame);
    819821
  • trunk/MagicSoft/Cosy/gui/MGCosy.h

    r9132 r9439  
    114114    void CreateMenu();
    115115    void CreateLabel(TGCompositeFrame *f);
    116     void CreateTabs();
    117     void CreatePredefinedPos(TGCompositeFrame *tf1);
     116    void CreateTabs(const char *prepos);
     117    void CreatePredefinedPos(TGCompositeFrame *tf1, const char *prepos);
    118118    void CreateStarList(TGCompositeFrame *tf1);
    119119
     
    133133
    134134public:
    135     MGCosy(MObservatory::LocationName_t key, MsgQueue *q);
     135    MGCosy(MObservatory::LocationName_t key, const char *prepos, MsgQueue *q);
    136136    ~MGCosy();
    137137
  • trunk/MagicSoft/Cosy/gui/MGStarg.cc

    r7790 r9439  
    2323: MGAccuracy(p, w)
    2424{
    25     SetColorScale(1.5);
     25    SetColorScale(1);
     26    DrawText("1.0'", "2.0'", "3.0'", "Mispointing [min]");
     27    DrawHexagon();
    2628}
  • trunk/MagicSoft/Cosy/leds_magic2.txt

    r9430 r9439  
    55370 518 0 0
    66170 405 0 0
    7 166 174 0 0
    8 251  87 0 0
     7#166 174 0 0
     8252  82 0 0
  • trunk/MagicSoft/Cosy/main/MCaos.cc

    r9435 r9439  
    354354
    355355    //          img  width height radius sigma
    356     FilterLed f(img, 768, 576, fSizeBox, fCut);
     356    FilterLed f(img, 768, 576, fSizeBox, fSizeBox, fCut);
    357357
    358358    Int_t first=0;
     
    506506
    507507    if (IsEnvDefined(env, prefix, "MinNumberLeds", print))
    508         fMaxRadius = GetEnvValue(env, prefix, "MinNumberLeds", fMinNumberLeds);
     508        fMinNumberLeds = GetEnvValue(env, prefix, "MinNumberLeds", fMinNumberLeds);
    509509
    510510    if (IsEnvDefined(env, prefix, "SizeBox", print))
  • trunk/MagicSoft/Cosy/main/MCosy.cc

    r9435 r9439  
    219219    if (d.Zd()<fMin.Zd())
    220220    {
    221         gLog << err << "ERROR: Requested Zenith Angle below negative endswitch." << endl;
     221        gLog << err << "ERROR: Requested Zenith Angle " << d.Zd()*TMath::RadToDeg() << " below negative endswitch " << fMin.Zd()*TMath::RadToDeg() << endl;
    222222        return kFALSE;
    223223    }
     
    225225    if (d.Zd()>fMax.Zd())
    226226    {
    227         gLog << err << "ERROR: Requested Zenith Angle behind positive endswitch." << endl;
     227        gLog << err << "ERROR: Requested Zenith Angle " << d.Zd()*TMath::RadToDeg() << " behind positive endswitch " << fMax.Zd()*TMath::RadToDeg() << endl;
    228228        return kFALSE;
    229229    }
     
    231231    if (d.Az()<fMin.Az())
    232232    {
    233         gLog << err << "ERROR: Requested Azimuth Angle below negative endswitch." << endl;
     233        gLog << err << "ERROR: Requested Azimuth Angle " << d.Az()*TMath::RadToDeg() << " below negative endswitch " << fMin.Az()*TMath::RadToDeg() << endl;
     234        if (TMath::Abs(d.Zd())<1)
     235            gLog << "       Remember that there is a small inaccessible region around zenith!" << endl;
     236
    234237        return kFALSE;
    235238    }
     
    237240    if (d.Az()>fMax.Az())
    238241    {
    239         gLog << err << "ERROR: Requested Azimuth Angle behind positive endswitch." << endl;
     242        gLog << err << "ERROR: Requested Azimuth Angle " << d.Az()*TMath::RadToDeg() << " behind positive endswitch " << fMax.Az()*TMath::RadToDeg() << endl;
     243        if (TMath::Abs(d.Zd())<1)
     244            gLog << "       Remember that there is a small inaccessible region around zenith!" << endl;
    240245        return kFALSE;
    241246    }
     
    336341
    337342    // Default: point.SetPointAcc(0.03, 0.01);
     343    // Default: point.SetPointVelocity(0.3);
    338344    point.SetPointAcc(0.03, 0.01);
    339345    point.SetPointVelocity(0.3);
     346
     347    //point.SetPointAcc(0.09, 0.03);
     348    //point.SetPointVelocity(1.0);
    340349
    341350    return point.SetPosition(dst, track);
     
    513522    case WM_STARGTPOINT:
    514523        if (fStarguider)
    515             fStarguider->StartTPoint();
     524            fStarguider->StartTPoint((char*)mp);
    516525        return 0xca1c;
    517526
    518527    case WM_STARGMODE:
    519528        if (fStarguider)
    520             fStarguider->StartStarguider();
     529            fStarguider->StartStarguider(*((bool*)mp));
    521530        return 0xca1c;
    522531
     
    594603            cout << "Preposition command to " << preps << " received." << endl;
    595604
    596             ifstream fin("prepos.txt");
     605            ifstream fin(fFilePrepos);
    597606            if (!fin)
    598607            {
    599                 cout << "ERROR: cannot open prepos.txt." << endl;
     608                cout << "ERROR: cannot open " << fFilePrepos << endl;
    600609                return 0xebb1;
    601610            }
     
    817826    {
    818827        tout.Start(999);
    819         fCom->SendReport(fStatus, fRaDec, fZdAzSoll, bendist, fTrackingError, armed);
     828        fCom->SendReport(fStatus, fRaDec, fZdAzSoll, bendist, fTrackingError, armed,
     829                         fStarguider ? fStarguider->GetStarguiderMode() : 0);
    820830    }
    821831
     
    876886}
    877887
    878 // --------------------------------------------------------------------------
    879 //
    880 // Disable the synchronization by using a negative CAN Id for id2.
    881 //
    882 void MCosy::Constructor(Int_t id1, Int_t id2)
    883 {
    884     //
    885     // Create Nodes
    886     //
    887     gLog << inf << "- Setting up network." << endl;
    888 
    889     fMac1=new Dkc(id1, "DKC/Az");
    890     fMac2=new Dkc(id2, "DKC/Zd");
    891 
    892     fMac1->SetReport(fOutRep);
    893     fMac2->SetReport(fOutRep);
    894 
    895     gLog << inf << "- Connecting devices to network." << endl;
    896 
    897     //
    898     // Connect the devices to the network
    899     //
    900     SetNode(fMac1);
    901     SetNode(fMac2);
    902 
    903     //
    904     // Create Gui Event timer and Gui
    905     //
    906     gLog << inf << "- Initializing GUI Timer." << endl;
    907     fUpdateGui = new TTimer(this, 100); // 100ms
    908 
    909     gLog << all << "- Starting GUI." << endl;
    910     fWin=new MGCosy(fObservatory, this);
    911 }
    912 
    913 /*
    914 void MCosy::ConstructorDemo()
    915 {
    916     //
    917     // Create Nodes
    918     //
    919     gLog << "- Setting up network." << endl;
    920 
    921     //
    922     // Create Gui Event timer and Gui
    923     //
    924     gLog << "- Initializing GUI Timer." << endl;
    925     fUpdateGui = new TTimer(this, 100); // 100ms
    926 
    927     gLog << "- Starting GUI." << endl;
    928     fWin=new MGCosy(fObservatory, this, gClient->GetRoot(), 1, 1);
    929 }
    930 */
    931 
    932888TString MCosy::GetFileName(const char *path, const char *name, const char *ext)
    933889{
     
    963919}
    964920
    965 MCosy::MCosy(MEnv &env, MDriveCom *com, const char *pointing)
     921MCosy::MCosy(MEnv &env, MDriveCom *com)
    966922: Network(), fObservatory(MObservatory::kMagic1), fStarguider(NULL),
    967923fMac1(0), fMac2(0), fStatus(MDriveCom::kStopped), fOutTp(0), fOutRep(0)
     
    969925    const Int_t id1 = env.GetValue("Az_Id", 1);
    970926    const Int_t id2 = env.GetValue("Zd_Id", 3);
     927
     928    fFilePrepos = env.GetValue("FilePredefinedPositions", "prepos.txt");
    971929
    972930    TString name = GetFileName("rep", "cosy", "rep");
     
    978936    *fOutRep << "[Reports]" << endl;
    979937
    980 /*
    981     gLog << "- Program in ";
    982     switch (mode)
    983     {
    984     case 0:
    985     gLog << "<<Standard mode>>" << endl;*/
    986         gLog << all << "Reading pointing model from " << pointing << "..." << endl;
    987         if (fBending.Load(pointing))
    988             gLog << all << "Reading pointing model from " << pointing << " successfull." << endl;
    989         else
    990             gLog << err << "ERROR - Reading pointing model from " << pointing << endl;
    991         Constructor(id1, id2);/*
    992         break;
    993     case 1:
    994         gLog << "<<SE mode>>" << endl;
    995         fBending.Load("bending.txt");
    996         ConstructorSE(id4, id5, id6);
    997         break;
    998     default:
    999         gLog << "<<Demo mode>>" << endl;
    1000         ConstructorDemo();
    1001     }
    1002 */
     938    const TString pointing = env.GetValue("PointingModel", "bending.txt");
     939
     940    gLog << all << "Reading pointing model from " << pointing << "..." << endl;
     941    if (fBending.Load(pointing))
     942        gLog << all << "Reading pointing model from " << pointing << " successfull." << endl;
     943    else
     944        gLog << err << "ERROR - Reading pointing model from " << pointing << endl;
     945
     946    //
     947    // Create Nodes
     948    //
     949    gLog << inf << "- Setting up network." << endl;
     950
     951    fMac1=new Dkc(id1, "DKC/Az");
     952    fMac2=new Dkc(id2, "DKC/Zd");
     953
     954    fMac1->SetReport(fOutRep);
     955    fMac2->SetReport(fOutRep);
     956
     957    gLog << inf << "- Connecting devices to network." << endl;
     958
     959    //
     960    // Connect the devices to the network
     961    //
     962    SetNode(fMac1);
     963    SetNode(fMac2);
     964
     965    //
     966    // Create Gui Event timer and Gui
     967    //
     968    gLog << inf << "- Initializing GUI Timer." << endl;
     969    fUpdateGui = new TTimer(this, 100); // 100ms
     970
     971    gLog << all << "- Starting GUI." << endl;
     972    fWin=new MGCosy(fObservatory, fFilePrepos, this);
    1003973
    1004974    gLog.SetOutputGui(fWin->GetLog(), kTRUE);
  • trunk/MagicSoft/Cosy/main/MCosy.h

    r9435 r9439  
    9191    MLog     *fOutRep;
    9292
     93    TString fFilePrepos;
     94
    9395    ZdAz AlignTrackingPos(ZdAz pointing) const;
    9496    Bool_t CheckRange(const ZdAz &d) const;
     
    122124
    123125public:
    124     MCosy(MEnv &env, MDriveCom *com, const char *pointing);
     126    MCosy(MEnv &env, MDriveCom *com);
    125127    ~MCosy();
    126128
  • trunk/MagicSoft/Cosy/main/MStarguider.cc

    r9435 r9439  
    1 #undef EXPERT
    21#undef EXPERT
    32
     
    307306
    308307    fGStarg = new MGStarg(this, 235);
    309     fGStarg->DrawText("0.75'", "1.50'", "3.00'", "Mispointing [min]");
    310     fGStarg->DrawHexagon();
    311308    fGStarg->Move(530,596+5);
    312309    fList->Add(fGStarg);
     
    342339
    343340    fTPoint = new TGTextButton(this, "TPoint");
    344     fTPoint->Move(4, fMenu->GetDefaultHeight()+785);
     341    //fTPoint->Move(4, fMenu->GetDefaultHeight()+785);
     342    fTPoint->Move(170, fMenu->GetDefaultHeight()+785);
    345343    fTPoint->AllowStayDown(kTRUE);
    346344    AddFrame(fTPoint);
    347 
    348     fStargTPoint = new TGTextButton(this, "StargTPoint");
    349     fStargTPoint->Move(170, fMenu->GetDefaultHeight()+785);
    350     fStargTPoint->AllowStayDown(kTRUE);
    351     AddFrame(fStargTPoint);
     345    /*
     346     fStargTPoint = new TGTextButton(this, "StargTPoint");
     347     fStargTPoint->Move(170, fMenu->GetDefaultHeight()+785);
     348     fStargTPoint->AllowStayDown(kTRUE);
     349     AddFrame(fStargTPoint);
     350    */
    352351
    353352    fFps = new TGLabel(this, "---fps");
     
    448447    MapSubwindows();
    449448    fTPoint->UnmapWindow();
    450     fStargTPoint->UnmapWindow();
     449    //fStargTPoint->UnmapWindow();
    451450    fGStarg->UnmapWindow();
    452451    fGNumStars->UnmapWindow();
     
    479478      fOutTp(0),
    480479      fOutStargTp(0),
    481       fOutRq(0),
     480//      fOutRq(0),
    482481      fDx((768-kZOOM)/2),
    483482      fDy((512-kZOOM)/2),
    484483      fStatus(MDriveCom::kStandby),
    485484      fRadius(200),
    486       fTPointFromCC(0)
     485      fTPointFromCC(-1),
     486      fFindStarCut(3.0), fFindStarBox(70)
    487487{
    488488    gLog << warn << " #### FIXME: Make MCaos Thread safe!" << endl;
     
    557557
    558558    fRadius = env.GetValue("Leds.Radius", fRadius);
     559
     560    fStarguiderW = env.GetValue("Starguider.Width",  fStarguiderW);
     561    fStarguiderH = env.GetValue("Starguider.Height", fStarguiderH);
     562    fStarguiderX = env.GetValue("Starguider.X",      fStarguiderX);
     563    fStarguiderY = env.GetValue("Starguider.Y",      fStarguiderY);
     564
     565    fSkyOffsetX = env.GetValue("Starguider.SkyOffsetX", fSkyOffsetX);
     566    fSkyOffsetY = env.GetValue("Starguider.SkyOffsetY", fSkyOffsetY);
     567
     568    fFindStarBox = env.GetValue("FindStar.SizeBox",       fFindStarBox);
     569    fFindStarCut = env.GetValue("FindStar.CleaningLevel", fFindStarCut);
    559570}
    560571
     
    583594        delete fOutStargTp;
    584595
    585     if (fOutRq)
    586         delete fOutRq;
     596//    if (fOutRq)
     597//        delete fOutRq;
    587598
    588599    gLog << inf2 << "Camera Display destroyed." << endl;
     
    649660}
    650661
     662/*
    651663void MStarguider::ToggleFindStar()
    652664{
    653665    if (fDisplay->IsEntryChecked(IDM_kFindStar) && fCosy)
    654         fTPoint->MapWindow();
     666    fTPoint->MapWindow();
    655667    else
    656668    {
     
    659671    }
    660672}
    661 
     673*/
    662674void MStarguider::ToggleStarguider()
    663675{
     
    671683        fOperations->EnableEntry(IDM_kStargAnalysis);
    672684
    673         fStargTPoint->MapWindow();
     685        //fStargTPoint->MapWindow();
    674686
    675687        fPZdAz->MapWindow();
     
    703715        SwitchOff(fChannel, IDM_kChannel2);
    704716        fChannel->CheckEntry(IDM_kChannel1);
    705 
    706717    }
    707718    else
     
    709720        fStatus = MDriveCom::kStandby;
    710721
    711         fStargTPoint->UnmapWindow();
    712         fStargTPoint->SetDown(kFALSE);
     722        //fStargTPoint->UnmapWindow();
     723        //fStargTPoint->SetDown(kFALSE);
    713724
    714725        fPZdAz->UnmapWindow();
     
    772783    MapSubwindows(); // maps everything, but we don't want that
    773784    fTPoint->UnmapWindow();
    774     fStargTPoint->UnmapWindow();
     785    //fStargTPoint->UnmapWindow();
    775786    fGStarg->UnmapWindow();
    776787    fGNumStars->UnmapWindow();
     
    863874                    //tpoint
    864875                    SwitchOff(fDisplay, IDM_kFindStar);
    865                     ToggleFindStar();
    866876                    SwitchOff(fDisplay, IDM_kCaosFilter);
    867877                    ToggleCaosFilter();
     
    874884
    875885                    //check needed items
    876                     fDisplay->CheckEntry(IDM_kStretch);
     886                    fDisplay->UnCheckEntry(IDM_kStretch);
    877887                    fDisplay->CheckEntry(IDM_kStargCaosFilter);
    878888                    fDisplay->CheckEntry(IDM_kStarguider);
    879889                    ToggleStarguider();
     890
     891                    fTPoint->MapWindow();
    880892                }
    881893                else
     
    885897                    fDisplay->UnCheckEntry(IDM_kStargCaosFilter);
    886898                    fDisplay->UnCheckEntry(IDM_kStarguider);
     899                    fTPoint->UnmapWindow();
    887900                    ToggleStarguider();
    888901
     
    922935
    923936                    //checking needed items
    924                     fDisplay->CheckEntry(IDM_kStretch);
     937                    fDisplay->UnCheckEntry(IDM_kStretch);
    925938                    fDisplay->CheckEntry(IDM_kCaosFilter);
    926939                    ToggleCaosFilter();
    927940                    fDisplay->CheckEntry(IDM_kFindStar);
    928                     ToggleFindStar();
     941                    fTPoint->MapWindow();
    929942                }
    930943                else
     
    946959                    ToggleCaosFilter();
    947960                    fDisplay->UnCheckEntry(IDM_kFindStar);
    948                     ToggleFindStar();
     961                    fTPoint->UnmapWindow();
    949962                }
    950963                return kTRUE;
     
    956969            case IDM_kFindStar:
    957970                Toggle(fDisplay, IDM_kFindStar);
    958                 ToggleFindStar();
     971                //ToggleFindStar();
    959972                return kTRUE;
    960973
     
    12931306#endif
    12941307
     1308    return fSao->CalcDeltaZdAzFromPix(mx, my)*TMath::RadToDeg();
     1309/*
    12951310    AltAz pos0 = fSao->CalcAltAzFromPix(768/2,    576/2)*kRad2Deg;
    12961311    AltAz pos1 = fSao->CalcAltAzFromPix(768/2+mx, 576/2+my)*kRad2Deg;
     
    12981313    pos1 -= pos0;
    12991314
    1300     return ZdAz(-pos1.Alt(), pos1.Az());
    1301 }
    1302 
    1303 Int_t MStarguider::CalcTrackingError(Leds &leds, MStarList &stars,
    1304                                      ZdAz &d, MTime &t, double &bright, Int_t &num)
    1305 {
     1315    ZdAz res2 = ZdAz(-pos1.Alt(), pos1.Az());
     1316
     1317    return res1;
     1318*/
     1319}
     1320
     1321Int_t MStarguider::CalcTrackingError(const Leds &leds, MStarList &stars,
     1322                                     ZdAz &d, const MTime &t, const double &bright,
     1323                                     Int_t &num, const Ring &center, Int_t numleds, Int_t numrings)
     1324{
     1325    // Get tracking coordinates
     1326    const XY xy = fCRaDec->GetCoordinates();
     1327
    13061328    num = leds.GetEntries();
    13071329    if (num < 3) //was 1
    13081330    {
    13091331        gLog << warn << "Sorry, less than 3 detected spot in FOV!" << endl;
    1310         fStargTPoint->SetDown(kFALSE);
     1332        if (fTPoint->IsDown() && fCosy && fCosy->GetDriveCom())
     1333            fCosy->GetDriveCom()->SendTPoint(false, 'S', fTPointStarMag, fTPointStarName, AltAz(), ZdAz(), xy, 0, 0, t, center, Led(), numleds, numrings, num);    // Report
     1334        fTPoint->SetDown(kFALSE);
    13111335        return 0;
    13121336    }
     
    13151339    {
    13161340        gLog << warn << "Sorry, less than 3 stars in FOV!" << endl;
    1317         fStargTPoint->SetDown(kFALSE);
     1341        if (fTPoint->IsDown() && fCosy && fCosy->GetDriveCom())
     1342            fCosy->GetDriveCom()->SendTPoint(false, 'S', fTPointStarMag, fTPointStarName, AltAz(), ZdAz(), xy, 0, 0, t, center, Led(), numleds, numrings, num);    // Report
     1343        fTPoint->SetDown(kFALSE);
    13181344        return 0;
    13191345    }
     
    13751401    if (numcor<1)
    13761402    {
    1377         fStargTPoint->SetDown(kFALSE);
     1403        fTPoint->SetDown(kFALSE);
     1404        if (fTPoint->IsDown() && fCosy && fCosy->GetDriveCom())
     1405            fCosy->GetDriveCom()->SendTPoint(false, 'S', fTPointStarMag, fTPointStarName, AltAz(), ZdAz(), xy, 0, 0, t, center, Led(), numleds, numrings, num, numcor);    // Report
    13781406        return 0;
    13791407    }
     
    13881416
    13891417    // Check StargTPoint data set request
    1390     if (!fStargTPoint->IsDown())
     1418    if (!fDisplay->IsEntryChecked(IDM_kStarguiderMode) || !fTPoint->IsDown())
    13911419        return numcor;
    1392     fStargTPoint->SetDown(kFALSE);
     1420    fTPoint->SetDown(kFALSE);
    13931421
    13941422    // If no file open: open new file
     
    14061434    }
    14071435
    1408     // Get tracking coordinates
    1409     const XY    xy = fCRaDec->GetCoordinates();
    14101436    const RaDec rd(xy.X()*MAstro::HorToRad(), xy.Y()*TMath::DegToRad());
    14111437
     
    14301456
    14311457    // Write real pointing position
    1432     //cout << "     Alt/Az: " << za0.Alt() << "° " << za0.Az() << "°" << endl;
    14331458    *fOutStargTp << setprecision(7) << za0.Az() << " " << za0.Alt() << " ";
    14341459
    14351460    // Write system pointing position
    1436     //cout << "     SE-Pos: " << 90-cpos.Zd() << "° " << cpos.Az() << "°" << endl;
    14371461    *fOutStargTp << fmod(cpos.Az()+360, 360) << " " << 90-cpos.Zd();
    14381462
     
    14401464    *fOutStargTp << " " << d.Zd() << " " << d.Az();
    14411465    *fOutStargTp << " " << setprecision(11) << t.GetMjd();
    1442     *fOutStargTp << " " << num;
    1443     *fOutStargTp << " " << bright;
     1466    *fOutStargTp << " " << setprecision(4) << center.GetMag();
     1467    *fOutStargTp << " " << star->GetMag();
     1468    *fOutStargTp << " " << center.GetX() << " " << center.GetY();
     1469    *fOutStargTp << " 0 0";
     1470    *fOutStargTp << " " << numleds << " " << numrings;
     1471    *fOutStargTp << " " << num << " " << numcor << " " << bright;
    14441472    *fOutStargTp << endl;
    14451473
     1474    gLog << all << "Starguider TPoint successfully taken." << endl;
     1475
    14461476    fTimeFromTp.Clear();
    14471477
     1478    if (!fCosy)
     1479        return numcor;
     1480
     1481    MDriveCom *com = fCosy->GetDriveCom();
     1482    if (!com)
     1483        return numcor;
     1484
     1485    com->SendTPoint(true, 'S', fTPointStarMag, fTPointStarName, za0, cpos, xy, d.Zd(), d.Az(), t, center, Led(), numleds, numrings, num, numcor);    // Report
     1486
    14481487    return numcor;
    14491488}
    14501489
    1451 void MStarguider::FindStar(FilterLed &f, FilterLed &f2, Ring &center, MTime &t)
    1452 {
     1490void MStarguider::FindStar(const FilterLed &f, const FilterLed &f2, const Ring &center, const MTime &t, Int_t numleds, Int_t numrings)
     1491{
     1492    // Get tracking coordinates
     1493    const XY xy = fCRaDec->GetCoordinates();  // [h, deg]
     1494
     1495    if (center.GetX()<=0 && center.GetY()<=0)
     1496    {
     1497        gLog << warn << "Couldn't determine center of the camera." << endl;
     1498        if (fTPoint->IsDown() && fCosy && fCosy->GetDriveCom())
     1499            fCosy->GetDriveCom()->SendTPoint(false, 'T', fTPointStarMag, fTPointStarName, AltAz(), ZdAz(), xy, 0, 0, t, center, Led(), numleds, numrings);    // Report
     1500        return;
     1501    }
     1502
    14531503    // Try to find the star
    14541504    Leds leds;
     
    14591509    if (!star)
    14601510    {
    1461         if (fTPoint->IsDown())
    1462         {
    1463             fTPoint->SetDown(kFALSE);
    1464             gLog << warn << "No star found. Couldn't take a tpoint." << endl;
    1465         }
     1511        gLog << warn << "No star found." << endl;
     1512        if (fTPoint->IsDown() && fCosy && fCosy->GetDriveCom())
     1513            fCosy->GetDriveCom()->SendTPoint(false, 'T', fTPointStarMag, fTPointStarName, AltAz(), ZdAz(), xy, 0, 0, t, center, Led(), numleds, numrings);    // Report
    14661514        return;
    14671515    }
     
    14701518    star->Print();
    14711519    f2.MarkPoint(star->GetX(), star->GetY(), 2<<2);
     1520
     1521    const RaDec rd(xy.X()*MAstro::HorToRad(), xy.Y()*TMath::DegToRad());
    14721522
    14731523    // Initialize Star Catalog on the camera plane
     
    14781528    ac.SetObservatory(*fSao);
    14791529    ac.SetTime(t);
    1480 
    1481     // Get tracking coordinates
    1482     const XY xy = fCRaDec->GetCoordinates();  // [h, deg]
    1483     const RaDec rd(xy.X()*MAstro::HorToRad(), xy.Y()*TMath::DegToRad());
    1484 
    14851530    ac.SetRaDec(rd.Ra(), rd.Dec());
    14861531
     
    15001545
    15011546    // Check TPoint data set request
    1502     if (!fTPoint->IsDown())
     1547    if (!fDisplay->IsEntryChecked(IDM_kTpointMode) || !fTPoint->IsDown())
    15031548        return;
    1504 
    1505     fTPoint->SetDown(kFALSE);
    15061549
    15071550    // If no file open: open new file
     
    15391582    const ZdAz za1 = fCosy->GetSePos()*360; // [deg]
    15401583
     1584
    15411585    // Write real pointing position
    15421586    //cout << "     Alt/Az: " << za0.Alt() << "° " << za0.Az() << "°" << endl;
     
    15521596    *fOutTp << " " << setprecision(4) << center.GetMag();
    15531597    *fOutTp << " " << star->GetMag();
     1598    *fOutTp << " " << center.GetX() << " " << center.GetY();
     1599    *fOutTp << " " << star->GetX() << " " << star->GetY();
     1600    *fOutTp << " " << numleds << " " << numrings;
     1601    *fOutTp << " 0 0 0";
    15541602    *fOutTp << endl;
     1603
     1604    gLog << all << "TPoint successfully taken." << endl;
    15551605/*
    15561606    MLog &outrep = *fCosy->GetOutRep();
     
    15701620   
    15711621//    return zdaz;
     1622
     1623    if (!fCosy)
     1624        return;
     1625
     1626    MDriveCom *com = fCosy->GetDriveCom();
     1627    if (!com)
     1628        return;
     1629
     1630    com->SendTPoint(true, 'T', fTPointStarMag, fTPointStarName, za0, za1, xy, -dzd, -daz, t, center, *star, numleds, numrings);    // Report
    15721631}
    15731632
     
    16241683}
    16251684
    1626 void MStarguider::StartStarguider()
     1685void MStarguider::StartTPoint(char *cmd)
     1686{
     1687    fTPointStarName = "Dummy";
     1688    fTPointStarMag  = 0;
     1689
     1690    TString str(cmd);
     1691
     1692    TObjArray *arr = str.Tokenize(' ');
     1693
     1694    if (arr->GetEntries()==2)
     1695    {
     1696        fTPointStarName = (*arr)[0]->GetName();
     1697        fTPointStarMag  = atof((*arr)[1]->GetName());
     1698    }
     1699
     1700    delete arr;
     1701
     1702    if (fTPointFromCC<0)
     1703        fTPointFromCC=0;
     1704}
     1705
     1706void MStarguider::StartStarguider(bool on)
    16271707{
    16281708    // Switch to starguider mode
    1629     cout << " * Switching to Starguider mode" << endl;
    1630     fMode->UnCheckEntry(IDM_kStarguiderMode);
    1631     ProcessMessage(MK_MSG(kC_COMMAND, kCM_MENU), IDM_kStarguiderMode, 0);
     1709    if (on)
     1710    {
     1711        cout << " * Switching Starguider mode on" << endl;
     1712        fMode->UnCheckEntry(IDM_kStarguiderMode);
     1713        ProcessMessage(MK_MSG(kC_COMMAND, kCM_MENU), IDM_kStarguiderMode, 0);
     1714    }
     1715    else
     1716    {
     1717        cout << " * Switching Starguider mode off" << endl;
     1718        fMode->CheckEntry(IDM_kStarguiderMode);
     1719        ProcessMessage(MK_MSG(kC_COMMAND, kCM_MENU), IDM_kStarguiderMode, 0);
     1720    }
     1721}
     1722
     1723Int_t MStarguider::GetStarguiderMode() const
     1724{
     1725    return fMode->IsEntryChecked(IDM_kStarguiderMode) ? 1 : 2;
     1726
    16321727}
    16331728
    16341729Bool_t MStarguider::DoTPoint()
    16351730{
     1731    if (fTPoint->IsDown() && fTPointFromCC<0)
     1732    {
     1733        fTPointFromCC = 0;
     1734        fTPoint->SetDown(kFALSE);
     1735    }
     1736
    16361737    if (fTPointFromCC<0)
    16371738        return kTRUE;
     
    16501751
    16511752    case 2:
     1753    case 3:
    16521754        cout << " * Waiting one frame" << endl;
    16531755        // Wait one frame
    16541756        return kFALSE;
    16551757
    1656     case 3:
     1758    case 4:
    16571759        cout << " * Taking TPoint" << endl;
    16581760        fTPoint->SetDown(); // kTRUE
    16591761        return kTRUE;
    16601762
    1661     case 4:
     1763    case 5:
    16621764        if (!fTimeFromTp) // TPoint failed
    16631765            break;
     
    16691771        return kFALSE;
    16701772
    1671     case 5:
     1773    case 6:
     1774    case 7:
    16721775        cout << " * Waiting one frame" << endl;
    16731776        // Wait one frame
    16741777        return kFALSE;
    16751778
    1676     case 6:
     1779    case 8:
    16771780        cout << " * Taking Starguider TPoint" << endl;
    1678         fStargTPoint->SetDown(); // kTRUE
     1781        fTPoint->SetDown(); // kTRUE
    16791782        return kTRUE;
    16801783
    1681     case 7:
    1682         cout << " * Send Report" << endl;
     1784//    case 9:
     1785//        cout << " * Send Report" << endl;
     1786//        return kTRUE;
     1787
     1788    case 9:
     1789        cout << " * Switching to TPoint mode" << endl;
     1790        // Switch to tpoint mode
     1791        fMode->UnCheckEntry(IDM_kTpointMode);
     1792        ProcessMessage(MK_MSG(kC_COMMAND, kCM_MENU), IDM_kTpointMode, 0);
    16831793        break;
    16841794    }
     
    16861796    // Send report
    16871797    fTPointFromCC = -1;
    1688 
     1798/*
    16891799    if (!fCosy)
    16901800        return kTRUE;
     
    17021812    //fNumStarsCorrelated = rc;
    17031813    com->SendTPoint(fNumStarsCorrelated>0);
    1704 
     1814*/
    17051815    return kTRUE;
    17061816}
     
    17361846    if (!fWritePictures->IsEntryEnabled(IDM_kStart) &&
    17371847        (!(n%fWrtRate) || fWriteType->IsEntryChecked(IDM_kOnce)))
    1738     {     
     1848    {
    17391849
    17401850        if (fFileType->IsEntryChecked(IDM_kPNG))
     
    17521862        f.Execute();
    17531863
    1754     DoTPoint();
     1864    if (!DoTPoint())
     1865        return;
    17551866
    17561867    Int_t numleds = 0;
     
    17581869
    17591870    // Find Center of Camera for Caos and Tpoints
    1760     Ring center(768/2, 576/2);
     1871//    Ring center;//(-1, -1);
     1872    Ring center(5, 5);//(-1, -1);
    17611873    if (fDisplay->IsEntryChecked(IDM_kCaosFilter))
    17621874    {
     
    17741886
    17751887    // Find Star at Center---for Tpoint Procedure
    1776     if (fDisplay->IsEntryChecked(IDM_kFindStar) &&
    1777         center.GetX()>0 && center.GetY()>0)
     1888    if (fDisplay->IsEntryChecked(IDM_kFindStar))
    17781889    {
    17791890        // Set search Paremeters (FIXME: Get them from user input!)
    1780         f.SetCut(3.0);
    1781         f.SetBox(70);
    1782 
    1783         FindStar(f, f2, center, t);
     1891        f.SetCut(fFindStarCut);
     1892        f.SetBox(fFindStarBox);
     1893
     1894        FindStar(f, f2, center, t, numleds, numrings);
    17841895    }
    17851896
     
    17881899
    17891900    // Position corresponding to the camera center (53.2, 293.6)
    1790     Ring sgcenter(53.2, 293.6); // Center of camera in SG picture [px]
     1901    Ring sgcenter;//(-1, -1); // Center of camera in SG picture [px]
    17911902
    17921903    // Find Center of Camera in Starfield Camera picture
     
    18171928        fCZdAz->SetCoordinates(fSao->GetZdAz());
    18181929
    1819         fSao->SetBox(230); // Region of interest around center
     1930        fSao->SetBox(fStarguiderW, fStarguiderH); // 280 Region of interest around center
    18201931
    18211932        // If center of camera cannot be determined sgcenter is (0,0)
    18221933        const Bool_t centerisvalid = sgcenter.GetX()>0 && sgcenter.GetY()>0;
    1823 //        if (centerisvalid)
    1824 //            skycenter.SetXY(sgcenter.GetX() -  53.2,
    1825 //                            sgcenter.GetY() - 293.6);
    18261934
    18271935        // We determine the ideal starfield using camera sagging info
     
    18301938        // 53.2 and 293.6 are the "preliminary" camera center
    18311939        // -9 and 28.5 are the offsets of the pointing position in the sky
    1832         const XY off(sgcenter.GetX()- 53.2-9,
    1833                      sgcenter.GetY()-293.6+28.5);
    1834 
    1835         // we obtain stars in the effective star FOV and draw them.
    1836         // coordinates are video frame coords.
    1837         MStarList stars;
    1838         fSao->CalcStars(stars, 530, 292, TMath::FloorNint(off.X()), TMath::FloorNint(off.Y()));
    1839         fSao->DrawStars(stars, cimg);
    1840 
    1841         // Position around which the circles are drawn.
    1842         const Ring skycenter(768/2-off.X(), 576/2+off.Y());
     1940        //const XY off(sgcenter.GetX()- 53.2-9,
     1941        //             sgcenter.GetY()-293.6+28.5);
     1942
     1943        // Skycenter
     1944        const XY off(sgcenter.GetX() + fSkyOffsetX,
     1945                     sgcenter.GetY() + fSkyOffsetY);
     1946
     1947        MStarList stars;
     1948        if (centerisvalid)
     1949        {
     1950            // we obtain stars in the effective star FOV and draw them.
     1951            // coordinates are video frame coords.
     1952            fSao->CalcStars(stars, fStarguiderX, fStarguiderY, off.X(), off.Y());
     1953            fSao->DrawStars(stars, cimg);
     1954        }
    18431955
    18441956        // There are two corrections to the mispointing
     
    18531965
    18541966            Leds spots;
    1855             f.SetBox(230);
     1967            f.SetBox(fStarguiderW, fStarguiderH); // 280
    18561968            f.SetCut(cut);
    18571969
    18581970            double bright;
    1859             f.ExecuteAndMark(spots, 530, 292, bright);
     1971            f.ExecuteAndMark(spots, fStarguiderX, fStarguiderY, bright);
    18601972
    18611973            ULong_t color;
     
    18781990
    18791991            Int_t numstars = 0;
    1880             const Int_t rc = CalcTrackingError(spots, stars, fD, t, bright, numstars);
     1992            const Int_t rc = CalcTrackingError(spots, stars, fD, t, bright, numstars, sgcenter, numleds, numrings);
    18811993
    18821994            const Bool_t monitoring = brightnessisvalid && centerisvalid && fNumStarsCorrelated>2;
     
    19072019        if (centerisvalid && fNumStarsCorrelated>2)
    19082020        {
     2021            // Position around which the circles are drawn.
     2022            const Ring skycenter(off.X(), off.Y());
     2023
    19092024            f2.DrawCircle(skycenter,   2.0,     0x0a);
    19102025
     
    19172032
    19182033    } //CalcStars
     2034
     2035    if (fTPoint->IsDown())
     2036        fTPoint->SetDown(kFALSE);
    19192037
    19202038    // Draw Circles around center of Camera
     
    19482066void MStarguider::UpdatePosZoom()
    19492067{
    1950     MString txt;
     2068    MString txt;/*
    19512069    if (fDisplay->IsEntryChecked(IDM_kCatalog))
    19522070    {
     
    19582076        txt.Form("(%d, %d) %.1fd/%.1fd", fDx, fDy, -aa.Alt(), aa.Az()-180);
    19592077    }
    1960     else
     2078    else*/
    19612079        txt.Form("(%d, %d)", fDx, fDy);
    19622080    fPosZoom->SetText(txt);
  • trunk/MagicSoft/Cosy/main/MStarguider.h

    r9435 r9439  
    9898
    9999    TGButton      *fTPoint;
    100     TGButton      *fStargTPoint;
     100//    TGButton      *fStargTPoint;
    101101
    102102    ZdAz          fPos;
     
    121121    ofstream *fOutTp;
    122122    ofstream *fOutStargTp;
    123     ofstream *fOutRq;
     123//    ofstream *fOutRq;
    124124
    125125    Int_t fDx;
     
    135135
    136136    Int_t fTPointFromCC;
     137
     138    Int_t fStarguiderW;
     139    Int_t fStarguiderH;
     140    Int_t fStarguiderX;
     141    Int_t fStarguiderY;
     142
     143    Float_t fSkyOffsetX;  // Offset between camera center and sky position
     144    Float_t fSkyOffsetY;  // Offset between camera center and sky position
     145
     146    Float_t fFindStarCut;
     147    Int_t   fFindStarBox;
     148
     149    TString fTPointStarName;
     150    Float_t fTPointStarMag;
    137151
    138152    void Toggle(TGPopupMenu *p, UInt_t id);
    139153    void SwitchOff(TGPopupMenu *p, UInt_t id);
    140154    void ToggleStargAnalysis();
    141     void ToggleFindStar();
     155//    void ToggleFindStar();
    142156    void ToggleStarguider();
    143157    void ToggleCaosFilter();
    144158    void SetChannel();
    145     Int_t CalcTrackingError(Leds &, MStarList &, ZdAz &, MTime &, double &bright, Int_t &num);
     159    Int_t CalcTrackingError(const Leds &, MStarList &, ZdAz &, const MTime &, const double &bright, Int_t &num, const Ring &center, Int_t numleds, Int_t numrings);
    146160    ZdAz TrackingError(TArrayF &alt, TArrayF &az, TArrayF &mag, Int_t &num) const;
    147161    bool Interpolate(const unsigned long n, byte *img) const;
    148     void FindStar(FilterLed &f, FilterLed &f2, Ring &center, MTime &t);
     162    void FindStar(const FilterLed &f, const FilterLed &f2, const Ring &center, const MTime &t, Int_t numleds, Int_t numrings);
    149163
    150164    void InitGui(Int_t channel);
     
    188202    void Print(Option_t *o) const { }
    189203
    190     void StartTPoint() { if (fTPointFromCC<0) fTPointFromCC=0; }
    191     void StartStarguider();
     204    void StartTPoint(char *cmd=0);// { if (fTPointFromCC<0) fTPointFromCC=0; }
     205    void StartStarguider(bool on);
     206
     207    Int_t GetStarguiderMode() const;
    192208
    193209    ClassDef(MStarguider, 0)
  • trunk/MagicSoft/Cosy/main/MTracking.cc

    r9435 r9439  
    3333    // Send the new velocities for both axes.
    3434    //
    35     fCosy->fMac2->SendSDO(0x3006, 1, (LWORD_t)(v.Zd()*vrzd));  // SetRpmVelocity [re/min]
    36     fCosy->fMac1->SendSDO(0x3006, 1, (LWORD_t)(v.Az()*vraz));  // SetRpmVelocity [re/min]
     35    fCosy->fMac2->SendSDO(0x3007, (LWORD_t)(v.Zd()*vrzd));  // SetRpmVelocity [re/min]
     36    fCosy->fMac1->SendSDO(0x3007, (LWORD_t)(v.Az()*vraz));  // SetRpmVelocity [re/min]
    3737
    3838    //
    3939    // Wait for the objects to be acknoledged.
    4040    //
    41     fCosy->fMac2->WaitForSdo(0x3006, 1, 100);
    42     fCosy->fMac1->WaitForSdo(0x3006, 1, 100);
     41    fCosy->fMac2->WaitForSdo(0x3007, 0, 100);
     42    fCosy->fMac1->WaitForSdo(0x3007, 0, 100);
    4343
    4444    //
     
    272272    {
    273273        /*
    274         sla.Now(1);
     274         // Code for position control mode
     275         // Set: S-0-0001
     276         // Set: S-0-0002
     277         // Set: P-0-0099
     278         // Set: P-0-0187 (Spline)
     279         // Replace S-0-0258 by S-0-0047 in communication
     280
     281        sla.Now();
    275282        const ZdAz pointing = sla.CalcZdAz(fCosy->fRaDec); // [rad]
    276283        ZdAz dest = fCosy->AlignTrackingPos(pointing);     // fix ambiguity
     
    279286            break;
    280287        dest *= 1./TMath::TwoPi(); //[rev]
    281         fCosy->fMac2->SendSDO(0x6004, 0, (LWORD_t)(dest.Zd()*fCosy->fMac2->GetPosRes()+.5), false);
    282         fCosy->fMac1->SendSDO(0x6004, 0, (LWORD_t)(dest.Az()*fCosy->fMac1->GetPosRes()+.5), false);
    283         usleep(100000); // 1s
     288        fCosy->fMac2->SendSDO(0x6004, (LWORD_t)(dest.Zd()*fCosy->fMac2->GetPosRes()+.5), false);
     289        fCosy->fMac1->SendSDO(0x6004, (LWORD_t)(dest.Az()*fCosy->fMac1->GetPosRes()+.5), false);
     290        usleep(10000); // 10ms
    284291        continue;
    285292        */
  • trunk/MagicSoft/Cosy/prepos_magic2.txt

    r9430 r9439  
    1 93.724 0.0  Park
     193.62 0.0  Park
  • trunk/MagicSoft/Cosy/stargleds_magic2.txt

    r9430 r9439  
    1 35     139    0 0
    2 90     195    0 0
    3 113    271    0 0
    4 34     402    0 0
     191  136 0 0
     2148 192 0 0
     3169 267 0 0
     491  400 0 0
     520  420 0 0
  • trunk/MagicSoft/Cosy/tcpip/MCeCoCom.cc

    r9435 r9439  
    104104    cout << "Zd/Az: " << zd << "/" << az << "  ";
    105105    cout << "Ra/Dec: " << ra/15 << "h/" << dec << "  ";
    106     cout << "SolRad: " << solar << "W/m²" << endl;
     106    //cout << "SolRad: " << solar << "W/m²";
     107    cout << endl;
    107108
    108109    fComStat = kCmdReceived;
     
    122123        return InterpreteReport(str);
    123124
    124     const bool rc = InterpreteCmd(cmd, str.Strip(TString::kBoth));
    125     fComStat = rc ? kCmdReceived : kComProblem;
    126     return rc;
     125    return InterpreteCmd(cmd, str.Strip(TString::kBoth));
    127126}
    128127
    129128bool MCeCoCom::SendRep(const char *cmd, const char *str, bool force)
    130129{
    131     MTime t;
    132     t.Now();
    133130
    134131    UShort_t y1, y2, ms1, ms2;
    135132    Byte_t mon1, mon2, d1, d2, h1, h2, m1, m2, s1, s2;
    136133
     134    fT.GetDate(y2, mon2, d2);
     135    fT.GetTime(h2, m2, s2, ms2);
     136
     137    MTime t(-1);
    137138    t.GetDate(y1, mon1, d1);
    138139    t.GetTime(h1, m1, s1, ms1);
    139140
    140     fT.GetDate(y2, mon2, d2);
    141     fT.GetTime(h2, m2, s2, ms2);
     141    if (t-fT>20)
     142        fComStat = kComProblem;
    142143
    143144    const TString msg =
     
    152153    // Send report to CC
    153154    const bool rc = Send(msg.Data(), msg.Length());
    154     fComStat = rc ? kNoCmdReceived : kComProblem;
    155155
    156156    // Write report to stream
  • trunk/MagicSoft/Cosy/tcpip/MCeCoCom.h

    r9432 r9439  
    1919    enum ComStatus_t
    2020    {
    21         kCmdReceived,
    22         kNoCmdReceived,
    23         kComProblem
     21        kCmdReceived = 1,
     22        kComProblem  = 2
    2423    };
    2524
     
    5251    MCeCoCom(const char *addr, const int tx=7304, const int rx=7404, MLog *out=NULL)
    5352        : MTcpIpIO(addr, tx, rx), fOut(out), fStatus(0),
    54         fTelescope(1), fComStat(kNoCmdReceived),
     53        fTelescope(1), fComStat(kComProblem),
    5554        fHumidity(0), fTemperature(0), fWindSpeed(0), fSolarRadiation(-1),
    5655        fAlarmCounter(0)
  • trunk/MagicSoft/Cosy/tcpip/MDriveCom.cc

    r9435 r9439  
    77#include "MString.h"
    88#include "Ring.h"
     9#include "Led.h"
     10
     11#include "MLog.h"
     12#include "MLogManip.h"
    913
    1014using namespace std;
     
    4549    if (!ReadPosition(str, ra, dec))
    4650    {
    47         cout << "ERROR - Reading position from RADEC" << endl;
     51        gLog << err << "ERROR - Reading position from RADEC" << endl;
    4852        return false;
    4953    }
    5054    if (!str.IsNull())
    5155    {
    52         cout << "ERROR - Too many bytes in command RADEC" << endl;
    53         return false;
    54     }
    55 
    56     cout << "CC-COMMAND " << MTime(-1) << " RADEC " << ra << "h " << dec << "d '" << str << "'" << endl;
     56        gLog << err << "ERROR - Too many bytes in command RADEC" << endl;
     57        return false;
     58    }
     59
     60    gLog << all << "CC-COMMAND " << MTime(-1) << " RADEC " << ra << "h " << dec << "d '" << str << "'" << endl;
    5761
    5862    ra *= 15; // h -> deg
     
    7276    if (!ReadPosition(str, ra, dec))
    7377    {
    74         cout << "ERROR - Reading position from GRB" << endl;
     78        gLog << err << "ERROR - Reading position from GRB" << endl;
    7579        return false;
    7680    }
    7781    if (!str.IsNull())
    7882    {
    79         cout << "ERROR - Too many bytes in command GRB" << endl;
    80         return false;
    81     }
    82 
    83     cout << "CC-COMMAND " << MTime(-1) << " GRB " << ra << "h " << dec << "d '" << str << "'" << endl;
     83        gLog << err << "ERROR - Too many bytes in command GRB" << endl;
     84        return false;
     85    }
     86
     87    gLog << all << "CC-COMMAND " << MTime(-1) << " GRB " << ra << "h " << dec << "d '" << str << "'" << endl;
    8488
    8589    ra *= 15; // h -> deg
     
    99103    if (!ReadPosition(str, zd, az))
    100104    {
    101         cout << "ERROR - Reading position from ZDAZ" << endl;
     105        gLog << err << "ERROR - Reading position from ZDAZ" << endl;
    102106        return false;
    103107    }
     
    105109    if (!str.IsNull())
    106110    {
    107         cout << "ERROR - Too many bytes in command ZDAZ" << endl;
    108         return false;
    109     }
    110 
    111     cout << "CC-COMMAND " << MTime(-1) << " ZDAZ " << zd << "deg " << az << "deg" << endl;
     111        gLog << err << "ERROR - Too many bytes in command ZDAZ" << endl;
     112        return false;
     113    }
     114
     115    gLog << all << "CC-COMMAND " << MTime(-1) << " ZDAZ " << zd << "deg " << az << "deg" << endl;
    112116
    113117    ZdAz za(zd, az);
     
    125129    if (str.IsNull())
    126130    {
    127         cout << "ERROR - No identifier for preposition (PREPS) given." << endl;
     131        gLog << err << "ERROR - No identifier for preposition (PREPS) given." << endl;
    128132        return false;
    129133    }
    130134    if (str.First(' ')>=0)
    131135    {
    132         cout << "ERROR - PREPS command syntax error (contains whitespaces)." << endl;
     136        gLog << err << "ERROR - PREPS command syntax error (contains whitespaces)." << endl;
    133137        return false;
    134138    }
     
    136140    str.ToLower();
    137141
    138     cout << "CC-COMMAND " << MTime(-1) << " PREPS '" << str << "'" << endl;
     142    gLog << all << "CC-COMMAND " << MTime(-1) << " PREPS '" << str << "'" << endl;
    139143
    140144    //cout << "MDriveCom - TRACK... start." << endl;
     
    147151bool MDriveCom::CommandTPOINT(TString &str)
    148152{
    149     cout << "CC-COMMAND " << MTime(-1) << " TPOIN " << str << endl;
    150 
    151     if (fQueue)
    152         fQueue->PostMsg(WM_TPOINT);//, (void*)str.Data(), str.Length()+1);
     153    gLog << all << "CC-COMMAND " << MTime(-1) << " TPOIN " << str << endl;
     154
     155    TObjArray *arr = str.Tokenize(' ');
     156
     157    if (arr->GetEntries()!=2)
     158    {
     159        delete arr;
     160        gLog << err << "ERROR - Wrong number of arguments in TPOIN command" << endl;
     161        return false;
     162    }
     163
     164    delete arr;
     165
     166    if (fQueue)
     167        fQueue->PostMsg(WM_STARGTPOINT, (void*)str.Data(), str.Length()+1);//, (void*)str.Data(), str.Length()+1);
    153168
    154169    return true;
     
    157172bool MDriveCom::CommandSTGMD(TString &str)
    158173{
    159     cout << "CC-COMMAND " << MTime(-1) << "STGMD" << endl;
    160 
    161     if (fQueue)
    162         fQueue->PostMsg(WM_STARGMODE);//, (void*)str.Data(), str.Length()+1);
     174    gLog << all << "CC-COMMAND " << MTime(-1) << " STGMD " << str << endl;
     175
     176    bool on = str=="ON";
     177
     178    if (fQueue)
     179        fQueue->PostMsg(WM_STARGMODE, &on, sizeof(bool));//, (void*)str.Data(), str.Length()+1);
    163180
    164181    return true;
     
    170187    if (str.IsNull())
    171188    {
    172         cout << "ERROR - No identifier for ARM command." << endl;
     189        gLog << err << "ERROR - No identifier for ARM command." << endl;
    173190        return false;
    174191    }
    175192    if (str.First(' ')>=0)
    176193    {
    177         cout << "ERROR - ARM command syntax error (contains whitespaces)." << endl;
     194        gLog << err << "ERROR - ARM command syntax error (contains whitespaces)." << endl;
    178195        return false;
    179196    }
     
    182199    if (str!="lock" && str!="unlock")
    183200    {
    184         cout << "ERROR - ARM command syntax error (neither LOCK nor UNLOCK)." << endl;
    185         return false;
    186     }
    187 
    188     cout << "CC-COMMAND " << MTime(-1) << " ARM '" << str << "'" << endl;
     201        gLog << err << "ERROR - ARM command syntax error (neither LOCK nor UNLOCK)." << endl;
     202        return false;
     203    }
     204
     205    gLog << all << "CC-COMMAND " << MTime(-1) << " ARM '" << str << "'" << endl;
    189206
    190207    bool lock = str=="lock";
     
    200217    {
    201218        //cout << "MDriveCom - WAIT... start." << endl;
    202         cout << "CC-COMMAND " << MTime(-1) << " WAIT" << endl;
     219        gLog << all << "CC-COMMAND " << MTime(-1) << " WAIT" << endl;
    203220        if (fQueue)
    204221            fQueue->PostMsg(WM_WAIT);
     
    210227    {
    211228        //cout << "MDriveCom - STOP!... start." << endl;
    212         cout << "CC-COMMAND " << MTime(-1) << " STOP!" << endl;
     229        gLog << all << "CC-COMMAND " << MTime(-1) << " STOP!" << endl;
    213230        if (fQueue)
    214231            fQueue->PostMsg(WM_STOP);
     
    240257    if (cmd.IsNull() && str.IsNull())
    241258    {
    242         cout << "CC-COMMAND " << MTime(-1) << " Empty command (single '\\n') received." << endl;
    243         return false;
    244     }
    245 
    246     cout << "CC-COMMAND " << MTime(-1) << " Syntax error: '" << cmd << "':'" << str << "'" << endl;
     259        gLog << all << "CC-COMMAND " << MTime(-1) << " Empty command (single '\\n') received." << endl;
     260        return false;
     261    }
     262
     263    gLog << err << "CC-COMMAND " << MTime(-1) << " Syntax error: '" << cmd << "':'" << str << "'" << endl;
    247264    return false;
    248265}
     
    258275}
    259276
    260 bool MDriveCom::SendReport(UInt_t stat, RaDec rd, ZdAz so, ZdAz is, ZdAz er, Bool_t armed)
     277bool MDriveCom::SendReport(UInt_t stat, RaDec rd, ZdAz so, ZdAz is, ZdAz er, Bool_t armed, Int_t stargmd)
    261278{
    262279    // rd [rad]
     
    294311    str += MString::Format("%08.3f ", er.Az());
    295312    str += armed ? "1 " : "0 ";
     313    str += MString::Format("%d ", stargmd);           // Starguider mode: 0=none, 1=starguider, 2=starguider off
    296314
    297315    return SendRep("DRIVE-REPORT", str.Data(), kFALSE);
     
    336354}
    337355
    338 bool MDriveCom::SendTPoint(UInt_t stat)
    339 {
    340     //const MTime t(-1);
    341 
     356bool MDriveCom::SendTPoint(bool stat, char type, Float_t mag, const char *name, const AltAz &za0, const ZdAz &za1,
     357                           const TVector2 &xy, Float_t dzd, Float_t daz, const MTime &t,
     358                           const Ring &center, const Led &star, Int_t numleds, Int_t numrings,
     359                           Int_t numstars, Int_t numcor, Float_t bright)
     360{
    342361    SetStatus(stat);
    343     /*
    344      TString str;
    345      str += name;  // star name
    346      str += " ";
    347      str += nominalaz;
    348      str += nominalel;
    349      str += realaz;
    350      str += realel;
    351      str += nomra;
    352      str += nomdec;
    353      str += diffaz;
    354      str += diffel;
    355      str += mjd;
    356      str += numleds;
    357      str += artmag;
    358      */
    359     return SendRep("TPOINT-REPORT", "", kTRUE);
    360 }
     362
     363    TString str = type;
     364    str += MString::Format(" %8.4f ", za0.Az());
     365    str += MString::Format("%8.4f ", za0.Alt());
     366    str += MString::Format("%8.4f ", fmod(za1.Az()+360, 360));
     367    str += MString::Format("%8.4f ", 90-za1.Zd());
     368    str += MString::Format("%8.4f ", xy.X());
     369    str += MString::Format("%8.4f ", xy.Y());
     370    str += MString::Format("%8.4f ", dzd);
     371    str += MString::Format("%8.4f ", daz);
     372    str += MString::Format("%12.6f ", t.GetMjd());
     373    str += MString::Format("%f ", center.GetMag());
     374    str += MString::Format("%f ", star.GetMag());
     375    str += MString::Format("%f ", center.GetX());
     376    str += MString::Format("%f ", center.GetY());
     377    str += MString::Format("%f ", star.GetX());
     378    str += MString::Format("%f ", star.GetY());
     379    str += numleds;
     380    str += " ";
     381    str += numrings;
     382    str += " ";
     383    str += numstars;
     384    str += " ";
     385    str += numcor;
     386    str += " ";
     387    str += bright;
     388    str += " ";
     389    str += mag;
     390    str += " ";
     391    str += name;
     392
     393    return SendRep("TPOINT-REPORT", str, kTRUE);
     394}
  • trunk/MagicSoft/Cosy/tcpip/MDriveCom.h

    r9435 r9439  
    77
    88class RaDec;
     9class AltAz;
    910class ZdAz;
    1011class MsgQueue;
    1112class Ring;
     13class Led;
    1214class MLog;
     15class MTime;
     16class TVector2;
    1317
    1418class MDriveCom : public MCeCoCom
     
    4953
    5054
    51     bool SendReport(UInt_t stat, RaDec rd, ZdAz so, ZdAz is, ZdAz er, Bool_t armed);
     55    bool SendReport(UInt_t stat, RaDec rd, ZdAz so, ZdAz is, ZdAz er, Bool_t armed, Int_t stargmd);
    5256    bool SendStargReport(UInt_t stat, ZdAz miss, ZdAz nompos, Ring center, Int_t num, Int_t n, Double_t bright, Double_t mjd, Int_t numleds, Int_t numrings);
    53     bool SendTPoint(UInt_t stat);
     57//    bool SendTPoint(char type);
     58    bool SendTPoint(bool stat, char type, Float_t mag, const char *name, const AltAz &za0, const ZdAz &za1,
     59                    const TVector2 &xy, Float_t dzd, Float_t daz, const MTime &t,
     60                    const Ring &center, const Led &star, Int_t numleds, Int_t numrings,
     61                    Int_t numstars=0, Int_t numcor=0, Float_t bright=0);
    5462    bool SendStatus(const char *stat);
    5563};
  • trunk/MagicSoft/Cosy/tcpip/MTcpIpIO.cc

    r9432 r9439  
    4343MTcpIpO::MTcpIpO(const char *addr, Int_t tx) : fPortTx(tx)
    4444{
    45     gLog << inf2 << "- Open send socket to " << addr << ":" << tx << endl;
     45    // was "inf2" but nobody knows what the prg is doing if it times out
     46    gLog << all << "- Open send socket to " << addr << ":" << tx << endl;
     47
    4648    fTxSocket = new TSocket(addr, tx);
     49    fTxSocket->SetOption(kNoBlock, 1);
     50
     51    MTcpIpO::RunThread();
    4752}
    4853
    4954MTcpIpO::~MTcpIpO()
    5055{
     56    CancelThread();
     57
    5158    // Now delete all TCP/IP objects
    5259    delete fTxSocket;
     
    5562MTcpIpIO::MTcpIpIO(const char *addr, Int_t tx, Int_t rx) : MTcpIpI(rx), MTcpIpO(addr, tx)
    5663{
    57     RunThread();
     64    MTcpIpI::RunThread();
    5865}
    5966
     
    7481}
    7582
     83/*
    7684TString MTcpIpO::GetSocketAddress() const
    7785{
     86    TLockGuard guard(const_cast<TMutex*>(&fMutex));
    7887    return GetSocketAddress(*fTxSocket);
    7988}
    80 
     89*/
    8190bool MTcpIpO::SendFrame(TSocket &tx, const char *msg, int len)
    8291{
    8392    if (!tx.IsValid())
    84     {
    85         //gLog << warn << "WARNING - No transmission to " << GetSocketAddress(tx) << " possible." << endl;
    8693        return false;
    87     }
    8894
    8995#ifdef DEBUG
     
    9197#endif
    9298
    93     const Int_t l = tx.SendRaw(msg, len);
     99    const Int_t l = tx.SendRaw(msg, len, kDontBlock);
     100
     101    // Frame not sent, EWOULDBLOCK
     102    if (l==-4)
     103    {
     104        gLog << err << "ERROR - Sending to " << GetSocketAddress(tx) << " would block." << endl;
     105/*--->*/        tx.Close(); // ?????
     106        return false;
     107    }
     108
    94109    if (l<0)
    95110    {
     
    100115    if (l!=len)
    101116    {
    102         gLog << err << "ERROR - Sent wrong number (" << l << ") of bytes to " << GetSocketAddress(tx) << endl;
     117        gLog << err << "ERROR - Could only sent " << l << " out of "  << len << " bytes to " << GetSocketAddress(tx) << endl;
    103118        return false;
    104119    }
     
    109124bool MTcpIpO::SendFrame(const char *addr, int port, const char *msg, int len)
    110125{
    111     //    R__LOCKGUARD2(myMutex);
    112126#ifdef DEBUG
    113127    cout << "Connecting to " << addr << ":" << port << endl;
     
    117131    TSocket tx(addr, port);
    118132    return SendFrame(tx, msg, len);
    119 /*
    120     if (!tx.IsValid())
    121     {
    122         gLog << warn << "WARNING - No transmission to " << addr << ":" << port << " possible." << endl;
     133}
     134
     135bool MTcpIpO::Send(const char *msg, Int_t len)
     136{
     137    const Int_t mtx = fMutex.TryLock();
     138    if (mtx==13)
     139        gLog << warn << "MTcpIpO::Send - mutex is already locked by this thread." << endl;
     140
     141    // If Mutex cannot be locked, i.e. we are currently reopening
     142    // the send socket we cannot wait, because we would block the
     143    // executing threrad.
     144    if (mtx)
    123145        return false;
    124     }
    125 
    126     gLog << dbg << "Sending to " << addr << ":" << port << endl;
    127 
    128     const Int_t l = tx.SendRaw(msg, len, kDontBlock);
    129     if (l<0)
    130     {
    131         gLog << err << "ERROR - Sending TCP/IP frame to " << addr << ":" << port << endl;
    132         return false;
    133     }
    134 
    135     if (l!=len)
    136     {
    137         gLog << err << "ERROR - Sent wrong number (" << l << ") of bytes to " << addr << ":" << port << endl;
    138         return false;
    139     }
    140 
    141 #ifdef DEBUG
    142     cout << "Tx: " << msg << flush;
    143 #endif
    144 
    145     return true;
    146     */
    147 }
    148 
    149 bool MTcpIpO::Send(const char *msg, Int_t len)
    150 {
    151     if (!fTxSocket->IsValid())
    152     {
    153         const TInetAddress &a = fTxSocket->GetInetAddress();
    154         if (!a.IsValid())
    155             return false;
     146
     147    const bool rc = SendFrame(*fTxSocket, msg, len);
     148
     149    fMutex.UnLock();
     150
     151    return rc;
     152}
     153
     154Int_t MTcpIpO::Thread()
     155{
     156    const TInetAddress &a = fTxSocket->GetInetAddress();
     157    if (!a.IsValid())
     158    {
     159        gLog << err << "ERROR: Send socket address invalid." << endl;
     160        return 0;
     161    }
     162
     163    Int_t wait = 1000; /// Wait a ms
     164
     165    while (!IsThreadCanceled())
     166    {
     167        if (fTxSocket->IsValid())
     168        {
     169            MThread::Sleep(1000); // Wait a ms
     170            wait = 1000;
     171            continue;
     172        }
     173
     174
    156175#ifdef DEBUG
    157176        cout << "- Reopen send socket to " << a.GetHostAddress() << ":" << fPortTx << endl;
    158177#endif
     178
     179        fMutex.Lock();
     180
    159181        delete fTxSocket;
     182
    160183        fTxSocket = new TSocket(a.GetHostAddress(), fPortTx);
    161     }
    162 
    163     return SendFrame(*fTxSocket, msg, len);
     184        fTxSocket->SetOption(kNoBlock, 1);
     185
     186        fMutex.UnLock();
     187
     188        if (fTxSocket->IsValid())
     189            continue;
     190
     191        MThread::Sleep(wait); // Wait a ms
     192        if (wait<30000000) // 30s
     193            wait *= 2;
     194    }
     195
     196    return 1;
    164197}
    165198
     
    174207    TString str;
    175208
    176     while (!IsThreadCanceled())
     209    while (!MTcpIpI::IsThreadCanceled())
    177210    {
    178211        char c;
  • trunk/MagicSoft/Cosy/tcpip/MTcpIpIO.h

    r9432 r9439  
    22#define COSY_MTcpIpIO
    33
    4 #ifndef MARS_MThread
    5 #include "MThread.h"
     4#ifndef COSY_MsgQueue
     5#include "msgqueue.h"
    66#endif
    77#ifndef MARS_MTime
    88#include "MTime.h"
     9#endif
     10#ifndef ROOT_TMutex
     11#include <TMutex.h>
    912#endif
    1013
     
    2225
    2326    Bool_t fConnectionEstablished;
     27
     28    MTime  fLast;
    2429
    2530    Bool_t WaitForData(TSocket &sock);
     
    3944
    4045// A generalized class for sending over tcp/ip
    41 class MTcpIpO
     46class MTcpIpO : public MThread
    4247{
    4348private:
    4449    TSocket *fTxSocket;
     50    TMutex   fMutex;
    4551
    4652    Int_t fPortTx;
     53
     54    Int_t Thread();
    4755
    4856public:
     
    5462    static bool    SendFrame(const char *addr, int port, const char *msg, int len);
    5563
    56     TString GetSocketAddress() const;
    57     bool    Send(const char *msg, int len);
     64    bool Send(const char *msg, int len);
    5865};
    5966
  • trunk/MagicSoft/Cosy/videodev/FilterLed.cc

    r8869 r9439  
    247247
    248248int FilterLed::GetMeanPosition(const int x, const int y,
    249                                const int box, float &mx, float &my, unsigned int &sum) const
     249                               const int boxx, const int boxy,
     250                               float &mx, float &my, unsigned int &sum) const
    250251{
    251252    unsigned int sumx=0;
     
    253254
    254255    sum=0;
    255     for (int dx=x-box; dx<x+box+1; dx++)
    256         for (int dy=y-box; dy<y+box+1; dy++)
     256    for (int dx=x-boxx; dx<x+boxx+1; dx++)
     257        for (int dy=y-boxy; dy<y+boxy+1; dy++)
    257258        {
    258259            const byte &m = fImg[dy*fW+dx];
     
    269270}
    270271
    271 int FilterLed::GetMeanPosition(const int x, const int y, const int box) const
     272int FilterLed::GetMeanPosition(const int x, const int y, const int boxx, const int boxy) const
    272273{
    273274    float mx, my;
    274275    unsigned int sum;
    275     return GetMeanPosition(x, y, box, mx, my, sum);
     276    return GetMeanPosition(x, y, boxx, boxy, mx, my, sum);
    276277}
    277278
    278279int FilterLed::GetMeanPositionBox(const int x, const int y,
    279                                   const int box, float &mx,
    280                                   float &my, unsigned int &sum) const
     280                                  const int boxx, const int boxy,
     281                                  float &mx, float &my, unsigned int &sum) const
    281282{
    282283    //-------------------------------
    283284    // Improved algorithm:
    284285    // 1. Look for the largest five-pixel-cross signal inside the box
    285     int x0 = TMath::Max(x-box+1,   0);
    286     int y0 = TMath::Max(y-box+1,   0);
    287 
    288     int x1 = TMath::Min(x+box+1-1, fW);
    289     int y1 = TMath::Min(y+box+1-1, fH);
     286    int x0 = TMath::Max(x-boxx+1,   0);
     287    int y0 = TMath::Max(y-boxy+1,   0);
     288
     289    int x1 = TMath::Min(x+boxx+1-1, fW);
     290    int y1 = TMath::Min(y+boxy+1-1, fH);
    290291
    291292    int maxx=0;
     
    330331
    331332int FilterLed::GetMeanPositionBox(const int x, const int y,
    332                                   const int box) const
     333                                  const int boxx, const int boxy) const
    333334{
    334335    float mx, my;
    335336    unsigned int sum;
    336     return GetMeanPositionBox(x, y, box, mx, my, sum);
     337    return GetMeanPositionBox(x, y, boxx, boxy, mx, my, sum);
    337338}
    338339
     
    374375void FilterLed::Execute(Leds &leds, int xc, int yc, double &bright) const
    375376{
    376     const int x0 = TMath::Max(xc-fBox, 0);
    377     const int y0 = TMath::Max(yc-fBox, 0);
    378     const int x1 = TMath::Min(xc+fBox, fW);
    379     const int y1 = TMath::Min(yc+fBox, fH);
     377    const int x0 = TMath::Max(xc-fBoxX, 0);
     378    const int y0 = TMath::Max(yc-fBoxY, 0);
     379    const int x1 = TMath::Min(xc+fBoxX, fW);
     380    const int y1 = TMath::Min(yc+fBoxY, fH);
    380381
    381382    const int wx = x1-x0;
     
    432433    // Define inner box in which to search the signal
    433434    //
    434     const int x0 = TMath::Max(xc-fBox, 0);
    435     const int y0 = TMath::Max(yc-fBox, 0);
    436     const int x1 = TMath::Min(xc+fBox, fW);
    437     const int y1 = TMath::Min(yc+fBox, fH);
     435    const int x0 = TMath::Max(xc-fBoxX, 0);
     436    const int y0 = TMath::Max(yc-fBoxY, 0);
     437    const int x1 = TMath::Min(xc+fBoxX, fW);
     438    const int y1 = TMath::Min(yc+fBoxY, fH);
    438439
    439440    //
     
    444445    const double sqrt2 = sqrt(2.);
    445446
    446     const int xa = TMath::Max(xc-(int)rint(fBox*sqrt2), 0);
    447     const int ya = TMath::Max(yc-(int)rint(fBox*sqrt2), 0);
    448     const int xb = TMath::Min(xc+(int)rint(fBox*sqrt2), fW);
    449     const int yb = TMath::Min(yc+(int)rint(fBox*sqrt2), fH);
     447    const int xa = TMath::Max(xc-TMath::Nint(fBoxX*sqrt2), 0);
     448    const int ya = TMath::Max(yc-TMath::Nint(fBoxY*sqrt2), 0);
     449    const int xb = TMath::Min(xc+TMath::Nint(fBoxX*sqrt2), fW);
     450    const int yb = TMath::Min(yc+TMath::Nint(fBoxY*sqrt2), fH);
    450451
    451452    //
     
    518519    float mx, my;
    519520    unsigned int mag;
    520     int pos = box ? GetMeanPositionBox(xc, yc, fBox-1, mx, my, mag) : GetMeanPosition(xc, yc, fBox-1, mx, my, mag);
     521    int pos = box ? GetMeanPositionBox(xc, yc, fBoxX-1, fBoxY-1, mx, my, mag)
     522        : GetMeanPosition(xc, yc, fBoxX-1, fBoxY-1, mx, my, mag);
    521523
    522524    if (pos<0 || pos>=fW*fH || fImg[pos]<sum+fCut*sdev)
  • trunk/MagicSoft/Cosy/videodev/FilterLed.h

    r8810 r9439  
    1717    int fW;
    1818    int fH;
    19     int fBox;
     19    int fBoxX;
     20    int fBoxY;
    2021    float fCut;
    2122
     
    2425
    2526    void GetMinMax(const int offset, byte *min, byte *max) const;
    26     int  GetMeanPosition(const int x, const int y, const int box) const;
    27     int  GetMeanPosition(const int x, const int y, const int box,
     27    int  GetMeanPosition(const int x, const int y, const int boxx, const int boxy) const;
     28    int  GetMeanPosition(const int x, const int y, const int boxx, const int boxy,
    2829                         float &mx, float &my, unsigned int &sum) const;
    2930
    3031    int  GetMeanPositionBox(const int x, const int y,
    31                             const int box) const;
     32                            const int boxx, const int boxy) const;
    3233    int  GetMeanPositionBox(const int x, const int y,
    33                             const int box, float &mx, float &my,
     34                            const int boxx, const int boxy, float &mx, float &my,
    3435                            unsigned int &sum) const;
    3536
     
    4041public:
    4142    FilterLed(byte *img, int w, int h, double cut=2.5)
    42       : fImg(img), fW(w), fH(h), fBox(w>h?w:h), fCut(cut)
     43      : fImg(img), fW(w), fH(h), fBoxX(w), fBoxY(h), fCut(cut)
    4344    {
    4445    }
    4546
    46     FilterLed(byte *img, int w, int h, int box, double cut=2.5)
    47       : fImg(img), fW(w), fH(h), fBox(box), fCut(cut)
     47    FilterLed(byte *img, int w, int h, int boxx, int boxy, double cut=2.5)
     48      : fImg(img), fW(w), fH(h), fBoxX(boxx), fBoxY(boxy), fCut(cut)
    4849    {
    4950    }
    5051    virtual ~FilterLed() { }
    5152
    52     void SetBox(int box)   { fBox = box; }
     53    void SetBox(int box)   { fBoxX = fBoxY = box; }
     54    void SetBox(int boxx, int boxy)   { fBoxX = boxx; fBoxY = boxy; }
    5355    void SetCut(float cut) { fCut = cut; }
    5456    void FindStar(Leds &leds, int xc, int yc, bool circle=false) const;
Note: See TracChangeset for help on using the changeset viewer.