Changeset 808 for trunk


Ignore:
Timestamp:
05/25/01 16:51:24 (23 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Cosy
Files:
1 added
29 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Cosy/Changelog

    r807 r808  
    33 2001/05/25 - Thomas Bretz:
    44 
     5    * .cosyrc:
     6      - added
     7     
    58    * MCosy.[h,cc]:
    69      - changed the error handling os SetPosition
  • trunk/MagicSoft/Cosy/MCosy.cc

    r738 r808  
    66
    77#include <TROOT.h>
     8#include <TEnv.h>
    89#include <TSystem.h>
    910#include <TApplication.h>
    1011
    1112#include "MGCosy.h"
     13#include "Slalib.h"
    1214
    1315#include "macs.h"
    1416#include "timer.h"
    15 #include "slalib.h"
    16 #include "slamac.h"
    1717#include "shaftencoder.h"
    1818
     
    5959ZdAz MCosy::CorrectTarget(const ZdAz &src, const ZdAz &dst)
    6060{
     61    // CorrectTarget [se]
     62
    6163    // src [se]
    6264    // dst [rad]
     
    7173
    7274    if (dest.Zd()>-1e-6 && dest.Zd()<1e-6)
    73         return dst;
     75        return dst*(16384.0/D2PI);
    7476
    7577    const float fZdMin = -67;
     
    119121        min = dist;
    120122    }
     123    cout << "Shortest Zd: " << ret.Zd() << "  Az:" << ret.Az() << endl;
    121124    return ret*(16384.0/360.0);
    122125}
     
    160163
    161164    cout << "Positioning to Target:" << endl;
    162 //    cout << "Source        Alt: " << src.Alt()  << "se  Az:" << src.Az()  << "se  ->  Alt: " << srcd.Alt() << kDEG << " Az:" << srcd.Az() << kDEG << endl;
    163 //    cout << "Shortest Dest Alt: " << dest.Alt() << "se  Az:" << dest.Az()   << "se  ->  Alt: " << sed.Alt()  << kDEG << " Az:" << sed.Az()  << kDEG << endl;
    164 
    165     for (int i=0; i<10; i++)
     165    //cout << "Source        Zd: " << src.Zd()  << "se  Az:" << src.Az()  << "se" << endl;
     166    //cout << "Destination   Zd: " << Rad2SE(dst.Zd()) << "se  Az:" << Rad2SE(dst.Az())  << "se" << endl;
     167    cout << "Shortest Dest Zd: " << dest.Zd() << "se  Az:" << dest.Az() << "se" << endl;
     168
     169    for (int i=0; i<10 && !StopWaitingForSDO(); i++)
    166170    {
    167171        //
     
    242246        cout << "SDO..." << flush;
    243247
    244         while (fMac1->IsPositioning() || fMac2->IsPositioning())
    245         {
    246             if (StopWaitingForSDO())
    247                 return FALSE;
    248 
     248        while (fMac1->IsPositioning() || fMac2->IsPositioning() && !StopWaitingForSDO())
    249249            usleep(1);
    250         }
    251250
    252251        cout << "done." << endl;
     252    }
     253
     254    if (StopWaitingForSDO())
     255    {
     256        fMac1->HandleError();
     257        fMac2->HandleError();
    253258    }
    254259
     
    259264void MCosy::TrackPosition(const RaDec &dst) // ra, dec [rad]
    260265{
     266    Slalib sla;
     267
    261268    //
    262269    // Position to actual position
     
    265272    t.GetTime();
    266273
    267     RaDec pm;
    268     ZdAz dest = RaDec2ZdAz(t.GetMjd(), dst, pm);
     274    sla.Set(t.GetMjd());
     275    ZdAz dest = sla.CalcZdAz(dst);
    269276
    270277    if (!SetPosition(dest))
     
    273280        return;
    274281    }
    275 
    276     if (StopWaitingForSDO())
    277         return;
    278282
    279283    //
     
    299303    fMac2->SetAcceleration(0.90*fMac2->GetVelRes());
    300304    fMac2->SetDeceleration(0.90*fMac2->GetVelRes());
     305
    301306    fMac1->SetAcceleration(0.90*fMac1->GetVelRes());
    302307    fMac1->SetDeceleration(0.90*fMac1->GetVelRes());
     
    315320    fTracking = kTRUE;
    316321
     322    ofstream fout("cosy.pos");
     323    fout << "   Mjd/10ms    Offset/RE Deviation/RE V/RE/MIN/4" << endl;
     324
    317325    //
    318326    // We want to reach the theoretical position exactly in about 0.5s
     
    330338        // Request theoretical Position for a time in the future (To+dt) from CPU
    331339        //
    332         dest = CorrectTarget(GetSePos(), RaDec2ZdAz(t.GetMjd()+dt/(60*60*24), dst, pm));
     340        sla.Set(t.GetMjd()+dt/(60*60*24));
     341        dest = CorrectTarget(GetSePos(), sla.CalcZdAz(dst));
    333342
    334343        fMac2->RequestSDO(0x6004);
     
    392401        // calculate control deviation - for the moment for convinience
    393402        //
    394         if (fMac1->GetTime()-s > 1)
    395         {
    396             ZdAz dest0=CorrectTarget(GetSePos(),
    397                                      RaDec2ZdAz(fMac2->GetMjd(), dst, pm));
     403
     404        //if (fMac1->GetTime()-s > 1)
     405        {
     406            const double mjd = fMac2->GetMjd();
     407            sla.Set(mjd);
     408            ZdAz dest0=CorrectTarget(GetSePos(), sla.CalcZdAz(dst));
    398409            dest0 *= kGearRatio;
    399410            dest0 -= GetRePos()+offset;
    400411            dest0.Round();
    401             cout << "Control deviation: ";
    402             cout << setw(4) << (int)fOffset.Zd() << " ";
    403             cout << setw(4) << (int)fOffset.Az() << " re ";
    404 
    405             cout << setw(4) << dest0.Zd() << " ";
    406             cout << setw(4) << dest0.Az() << " re    V: ";
    407             cout << setw(4) << vt.Zd()    << " ";
    408             cout << setw(4) << vt.Az()    << " re/min/4" << endl;
     412            //cout << "Control deviation: ";
     413            fout << setprecision(15) << setw(15) << mjd*60.*60.*24. << " ";
     414            fout << setw(4) << (int)fOffset.Zd() << " ";
     415            fout << setw(4) << (int)fOffset.Az() << " ";
     416
     417            fout << setw(4) << dest0.Zd() << " ";
     418            fout << setw(4) << dest0.Az() << " ";
     419            fout << setw(4) << vt.Zd()    << " ";
     420            fout << setw(4) << vt.Az() << endl;
    409421            s = (int)fMac1->GetTime();
    410422        }
     
    427439
    428440    cout << "Tracking stopped." << endl;
    429 }
    430 
    431 ZdAz MCosy::RaDec2ZdAz(const double mjd, const RaDec &dst, const RaDec &pm)
    432 {
    433     int status;
    434 
    435     //
    436     // calculate observers location (goe)
    437     //
    438     double fPhi, fElong;
    439     slaDaf2r(51, 38, 48.0, &fPhi,   &status);
    440     slaDaf2r( 9, 56, 36.0, &fElong, &status);
    441 
    442     // cout << "fPhi:   51ø38'48.0\" = " <<  360.0/D2PI*fPhi << endl;
    443     // cout << "fElong:  9ø56'36.0\" = " <<  360.0/D2PI*fElong << endl;
    444 
    445     //
    446     // ----- calculate star independent parameters ----------
    447     //
    448     double fAmprms[21];
    449     double fAoprms[14];
    450     slaMappa(2000.0, mjd, fAmprms);
    451     slaAoppa(mjd, 0,                 // mjd, UT1-UTC
    452              fElong, fPhi, 148,      // g”ttingen long, lat, height
    453              0, 0,                   // polar motion x, y-coordinate (radians)
    454              273.155, 1013.25, 0.5,  // temp, pressure, humidity
    455              0.2, 0.0065,            // wavelength, tropo lapse rate
    456              fAoprms);
    457 
    458     //
    459     // ---- Mean to apparent ----
    460     //
    461     double r=0, d=0;
    462     slaMapqkz(dst.Ra(), dst.Dec(), (double*)fAmprms, &r, &d);
    463     //
    464     // Doesn't work - don't know why
    465     //
    466     //    slaMapqk(dst.Ra(), dst.Dec(), pm.Ra(), pm.Dec(),        // ra, dec (rad), r, d (rad)
    467     //             0, 0, fAmprms, &r, &d);
    468     //
    469 
    470     //
    471     // -- apparent to observed --
    472     //
    473     double r1=0;  // ra
    474     double d1=0;  // dec
    475     double h0=0;  // ha
    476 
    477     double az, zd;
    478     slaAopqk (r, d, fAoprms,
    479               &az,    // observed azimuth (radians: N=0,E=90)
    480               &zd,    // observed zenith distance (radians)
    481               &h0,    // observed hour angle (radians)
    482               &d1,    // observed declination (radians)
    483               &r1);   // observed right ascension (radians)
    484 
    485     return ZdAz(zd, az);
     441
     442    if (StopWaitingForSDO())
     443    {
     444        fMac1->HandleError();
     445        fMac2->HandleError();
     446    }
    486447}
    487448
     
    490451    switch (msg)
    491452    {
     453    case WM_WAIT:
     454        cout << "Wait for execution of Proc: done." << endl;
     455        return NULL;
     456
    492457    case WM_STOP:
    493458        cout << "Stopping  positioning." << endl;
     
    514479        {
    515480            cout << "WM_POLARIS: START" << endl;
     481            Slalib sla;
     482
    516483            Timer t;
    517484            t.GetTime();
    518485
     486            sla.Set(t.GetMjd());
     487
    519488            RaDec rd(37.94, 89.2644);
    520             ZdAz za=MCosy::RaDec2ZdAz(t.GetMjd(), rd*D2PI/360.0)*16384.0/D2PI;
     489            ZdAz za=sla.CalcZdAz(rd*D2PI/360.0)*16384.0/D2PI;
    521490
    522491            cout << "Calc Zd: " << za.Zd() << " Az: " << za.Az() << endl;
     
    537506        {
    538507            ZdAz dest = *((ZdAz*)mp);
     508
    539509            SetPosition(dest*D2PI/360.0);
    540510        }
     
    561531    //
    562532    Network::Start();
     533
     534    const int res = fMac3->GetVelRes();
     535
     536    fMac3->SetVelocity(res);
     537    fMac3->SetAcceleration(res);
     538    fMac3->SetDeceleration(res);
     539
     540    fMac3->SetSyncMode();
     541
     542    fMac1->SetHome(250000);
     543    fMac2->SetHome(250000);
    563544    PostMsg(WM_PRESET, 0, 0);
     545    PostMsg(WM_WAIT,   0, 0);
     546
     547    fMac1->ReqPos();
     548    fMac2->ReqPos();
     549
     550    const ZdAz repos=GetRePos();
     551    cout << "APOS: " << repos.Zd() << "re, " << repos.Az() << "re" << endl;
     552
     553    TEnv env(".cosyrc");
     554
     555    cout << Deg2AzRE(env.GetValue("MinAz[Deg]", -1.0)) << " < Az < "
     556        << Deg2AzRE(env.GetValue("MaxAz[Deg]", +1.0)) << "RE" << endl;
     557    cout << env.GetValue("MinAz[Deg]", -1.0) << " < Az < "
     558        << env.GetValue("MaxAz[Deg]", +1.0) << kDEG << endl;
     559    cout << Deg2ZdRE(env.GetValue("MinZd[Deg]", -1.0)) << "RE < Zd < "
     560        << Deg2ZdRE(env.GetValue("MaxZd[Deg]", +1.0)) << "RE" << endl;
     561
     562    fMac1->SetNegEndswitch(Deg2AzRE(env.GetValue("MinAz[Deg]", -1.0)));
     563    fMac1->SetPosEndswitch(Deg2AzRE(env.GetValue("MaxAz[Deg]", +1.0)));
     564
     565/*
     566    fMac2->SetNegEndswitch(Deg2ZdRE(env.GetValue("MinZd[Deg]", -1.0)));
     567    fMac2->SetPosEndswitch(Deg2ZdRE(env.GetValue("MaxZd[Deg]", +1.0)));
     568*/
     569    fMac3->SetSyncMode();
    564570/*
    565571    cout << "PostMsg(WM_PRESET)" << endl;
     
    584590    setpriority(PRIO_PROCESS, 0, 10);
    585591
     592    Slalib sla;
    586593    while (1)
    587594    {
     
    592599            usleep(1);
    593600
    594         RaDec pm;
    595601        ZdAz sollalt; // [se]
    596602        ZdAz sollaz;  // [se]
     
    641647                // calculate were we should be
    642648                //
    643                 sollalt = CorrectTarget(ist, RaDec2ZdAz(t, fRaDec, pm));
     649                sla.Set(t);
     650                sollalt = CorrectTarget(ist, sla.CalcZdAz(fRaDec));
    644651
    645652                old.Zd(ist.Zd());
     
    659666                // calculate were we should be
    660667                //
    661                 sollaz = CorrectTarget(ist, RaDec2ZdAz(t, fRaDec, pm));
     668                sla.Set(t);
     669                sollaz = CorrectTarget(ist, sla.CalcZdAz(fRaDec));
    662670
    663671                old.Az(ist.Az());
     
    724732    fMac1=new Macs(1, lout);
    725733    fMac2=new Macs(2, lout);
     734    fMac3=new Macs(3, lout);
    726735    fAlt1=new ShaftEncoder(4, lout);
    727736    fAlt2=new ShaftEncoder(5, lout);
     
    733742    SetNode(fMac1);
    734743    SetNode(fMac2);
     744    SetNode(fMac3);
    735745    SetNode(fAlt1);
    736746    SetNode(fAlt2);
     
    756766    delete fMac1;
    757767    delete fMac2;
     768    delete fMac3;
    758769
    759770    delete fWin;
  • trunk/MagicSoft/Cosy/MCosy.h

    r738 r808  
    1313#define WM_STOP      0x1003
    1414#define WM_POLARIS   0x1004
     15#define WM_WAIT      0x1005
    1516
    1617class ShaftEncoder;
     
    2728    Macs *fMac1;
    2829    Macs *fMac2;
     30    Macs *fMac3;
    2931
    3032    MGCosy *fWin;
     
    6062
    6163    static ZdAz CorrectTarget(const ZdAz &src, const ZdAz &dst);
    62     static ZdAz RaDec2ZdAz(const double mjd, const RaDec &pos, const RaDec &pm=RaDec(0,0));
     64//    static ZdAz RaDec2ZdAz(const double mjd, const RaDec &pos, const RaDec &pm=RaDec(0,0));
    6365};
    6466
  • trunk/MagicSoft/Cosy/Makefile

    r748 r808  
    9292           catalog/SaoFile.cc \
    9393           catalog/StarCatalog.cc \
     94           catalog/Slalib.cc \
    9495           videodev/Camera.cc \
    9596           videodev/Filter.cc \
  • trunk/MagicSoft/Cosy/Starguider.cc

    r748 r808  
    293293}
    294294
    295 void Starguider::Execute(const unsigned long n, char *img, struct timeval *tm)
     295void Starguider::Execute(const unsigned long n, byte *img, struct timeval *tm)
    296296{
    297297
     
    329329        if (fDisplay->IsEntryChecked(IDM_kCatalog))
    330330        {
    331             char cimg[768*576];
     331            byte cimg[768*576];
    332332
    333333            XY xy = fCRaDec->GetCoordinates();
  • trunk/MagicSoft/Cosy/Starguider.h

    r748 r808  
    6060    // Execution of one frame - this function may be overloaded!
    6161    //
    62     void Execute(const unsigned long n, char *img, struct timeval *tm);
     62    void Execute(const unsigned long n, byte *img, struct timeval *tm);
    6363};
    6464
  • trunk/MagicSoft/Cosy/aposs/Magic.m

    r738 r808  
    33/*-------------------------------------------------------------------------*/
    44
    5 DIM errlist[9]          
     5DIM errlist[9] /* idx 1=number of valid entries */          
    66
    77/* ----------------------------------------------------------------------- */
     
    1010/*                                                                         */
    1111kVERSION    = 0   /*                                                       */
    12 kSUBVERSION = 50  /*                                                       */
     12kSUBVERSION = 62  /*                                                       */
    1313/*                                                                         */
    1414/*  HISTORY:                                                               */
     15/*                                                                         */
     16/*   * V0.62:                                                              */
     17/*       - changed handling of 0x2000/1/2 added /3                         */
     18/*                                                                         */
     19/*   * V0.61:                                                              */
     20/*       - corrected problems with the error handling                      */
     21/*                                                                         */
     22/*   * V0.60:                                                              */
     23/*       - introduced syncronisation                                       */
     24/*                                                                         */
     25/*   * V0.52:                                                              */
     26/*       - changed the handling of the endswitch error (unknown switch)    */
     27/*                                                                         */
     28/*   * V0.51:                                                              */
     29/*       - made errlist working                                            */
    1530/*                                                                         */
    1631/*   * V0.50:                                                              */
     
    6580/*   0x1800 x rw Enable PDO1 (Axe Status, Position)                        */
    6681/*   0x2000 0 rw Maximum positioning error                                 */
    67 /*          1 rw Negative Software Endswitch                               */
    68 /*          2 rw Positive Software Endswitch                               */
     82/*          1 rw Negative Software Endswitch Value (Set=Enable)            */
     83/*          2 rw Positive Software Endswitch Value (Set=Enable)            */
     84/*          3 rw Enable/Disable Software Endswitch                         */
    6985/*   0x2002 x rw Velocity                                                  */
    7086/*   0x2003 0 wo Acceleration                                              */
     
    7692/*   0x3006 0 wo Velocity Mode 'strt', 'stop'                              */
    7793/*          1 wo VelMode Velocity                                          */
     94/*   0x3007 x wo Syncronisation 'sync'                                     */
    7895/*   0x3008 x wo Nowait 'on', 'off'                                        */
    7996/*   0x6000 x rw Rotation Direction                                        */
    8097/*   0x6002 x rw Velocity Resolution                                       */
    81 /*   0x6003 0 wo Define present position as origin                         */
     98/*   0x6003 0 wo Define present position as origin ('set')                 */
    8299/*          1 wo Define new origin (0=delete)                              */
    83100/*          2 rw Home Offset                                               */
     
    99116SET ENCODERTYPE   0          /* Incremental Encoder                        */
    100117SET ENCODER     500          /* Encoder has 500 Ticks                      */
     118SET MENCODERTYPE  0          /* Incremental Encoder (Master)               */
     119SET MENCODER    500          /* Encoder has 500 Ticks (Master)             */
    101120SET VELMAX     3600          /* Motor: Maximum rounds per minute           */
    102121SET POSERR     1500          /* Maximum tolarable Position error (qc) 0.1° */
     
    112131
    113132/*----------------*/
     133/* syncronisation */
     134/*----------------*/                                                       
     135SET MENCODERTYPE   0         /* Incremental Encoder (Master)               */
     136SET MENCODER     500         /* Encoder has 500 Ticks (Master)             */
     137SET SYNCFACTM      1         /* Master Sync Velocity factor                */
     138SET SYNCFACTS      1         /* Slave Sync Velocity factor                 */
     139SET SYNCPOSOFFS    0         /* Sync Position offset between M/S           */
     140SET SYNCACCURACY  50         /* When to set Accuracy Flag                  */
     141SET REVERS         0         /* How to handle reversation of vel           */
     142
     143/*----------------*/
    114144/*    Inputs      */
    115145/*----------------*/
     
    181211/*-------------------------------------------------------------------------*/
    182212/* ON CANMSG GOSUB PROC_CANMSG */
    183 i = 8
     213i = 9
    184214while (i) do
    185215   errlist[i] = 0
     
    197227
    198228   PRINT "Starting Mainloop..."
     229   
    199230   MAINLOOP:
    200231      rc = CANIN sdorx 0 0 canhi canlo
     
    225256*/
    226257      if (idx == 0x1003 and subidx == 0 and sdoval == 0) then
    227          i = 0
    228          while (i<9) do
     258         i = 9
     259         while (i) do
    229260            errlist[i] = 0
    230             i = i + 1
     261            i = i - 1
    231262         endwhile
    232263      elseif (idx == 0x1010 and sdoval == 's'<<24|'a'<<16|'v'<<8|'e') then
     
    244275              SET POSERR sdoval
    245276           elseif (subidx == 1) then 
    246               if ((sdoval>>30)&1) then
    247                  SET NEGLIMIT    sdoval & 0x3fffffff
    248                  SET SWNEGLIMACT 1
    249               else
    250                  SET SWNEGLIMACT 0
    251               endif
     277              SET NEGLIMIT    sdoval
     278              SET SWNEGLIMACT      1
    252279           elseif (subidx == 2) then
    253               if ((sdoval>>31)&1) then
    254                  SET POSLIMIT    sdoval & 0x3fffffff
    255                  SET SWPOSLIMACT 1
    256               else
    257                  SET SWPOSLIMACT 0
    258               endif
     280              SET POSLIMIT    sdoval
     281              SET SWPOSLIMACT      1
     282           elseif (subidx == 3) then
     283              SET SWNEGLIMACT sdoval&1
     284              SET SWPOSLIMACT (sdoval>>1)&1
    259285           endif 
    260286      elseif (idx == 0x2002) then
     
    306332            CVEL sdoval
    307333         endif
     334      elseif (idx == 0x3007 and sdoval == 's'<<24|'y'<<16|'n'<<8|'c') then
     335         SYNCP
    308336      elseif (idx == 0x3008) then
    309337         if (sdoval == 'o'<<24|'n'<<16) then
     
    325353            SET POSDRCT 1
    326354         endif
    327 /*    elseif (idx == 0x6001) then
    328          SET ENCODER sdoval*/
    329355      elseif (idx == 0x6002) then
    330356         SET VELRES sdoval
    331357      elseif (idx == 0x6003) then
    332          if (subidx == 0) then
     358         if (subidx == 0 and sdoval == 's'<<24|'e'<<16|'t'<<8) then
    333359            DEF ORIGIN   
    334360         elseif (subidx == 1) then
     
    383409      if (idx == 0x1003) then
    384410         if (subidx >=0 and subidx<=9) then
    385             sdoval = errlist[subidx]
     411            sdoval = errlist[subidx-1]
    386412         endif
    387413      elseif (idx == 0x1004) then
     
    422448           elseif (subidx == 2) then
    423449              sdoval = GET POSLIMIT | (GET SWPOSLIMACT) << 31
     450           elseif (subidx == 3) then
     451              sdoval = (GET SWNEGLIMACT) | ((GET SWPOSLIMACT)<<1)
    424452           endif
    425453      elseif (idx == 0x2001) then
     
    514542   SUBPROG PROC_ERROR
    515543      MOTOR STOP
    516       errinf = 0
    517544
    518545      /* Tell the bus that an error occured */
    519546      CANOUT pdo2 0 0
    520547     
    521       i = errlist[0] + 1       
    522       while (i>1) do
     548      i = errlist[1] + 1              /* Fill status of array       */
     549      while (i>2) do                  /* shift errors by one        */
    523550         errlist[i] = errlist[i-1]
    524551         i = i - 1
    525       endwhile 
    526       errlist[1] = ERRNO
    527       if (errlist[0]<8) then
    528          errlist[0] = errlist[0] + 1
    529       endif
    530 
     552      endwhile                        /* set new errornumber        */
     553      errlist[2] = ERRNO
     554      if (errlist[1]<8) then          /* write new size if enhanced */
     555         errlist[1] = errlist[1] + 1
     556      endif     
     557
     558      errinf = 0
     559     
    531560      /* check if the error is repairable and repair */
    532       if (errlist[1]==6) then
     561      if (errlist[2]==6) then
    533562        PRINT "No home forced!"
    534563        ERRCLR
    535       elseif (errlist[1]==8) then
    536         PRINT "Schleppabstand überschritten"
     564      elseif (errlist[2]==8) then
     565        PRINT "Control deviation overflow."
    537566        ERRCLR
    538567        errinf = 0xaffe
    539       elseif (errlist[1]==9) then
     568      elseif (errlist[2]==9) then
    540569        PRINT "Did'n find zero index."
    541570        ERRCLR
    542       elseif (errlist[1]==25) then
    543          lsw = -(GET I_POSLIMITSW)
    544          if (IN lsw == 0) then
     571      elseif (errlist[2]==11) then   
     572         poslsw = GET POSLIMIT
     573         neglsw = GET NEGLIMIT
     574         if ((GET SWNEGLIMACT) and APOS<=neglsw) then
     575            PRINT "Negative software endswitch (", neglsw, ") activated at position ", APOS
     576            SET SWNEGLIMACT 0
     577            ERRCLR
     578            CVEL  (vres%100)   
     579            ACC   (10*vres%100)
     580            DEC   (10*vres%100)
     581            POSA neglsw + 100
     582            SET SWNEGLIMACT 1   
     583            errinf = -1
     584         elseif ((GET SWPOSLIMACT) and APOS>=poslsw) then
     585            PRINT "Positive software endswitch (", poslsw, ") activated at position ", APOS
     586            SET SWPOSLIMACT 0
     587            ERRCLR
     588            CVEL  (vres%100)    /*   1% */
     589            ACC   (10*vres%100) /*  10% */
     590            DEC   (10*vres%100) /*  10% */
     591            POSA poslsw - 100
     592            SET SWPOSLIMACT 1
     593            errinf = 1
     594         else     
     595            PRINT "Software endswitch activated - command skipped. Pos: ", APOS
     596            ERRCLR
     597         endif
     598      elseif (errlist[2]==25) then   
     599         /* FIXME: To handle this correct you must make sure,
     600                   that the endswitch numbers are negative    */
     601         poslsw = -(GET I_POSLIMITSW)
     602         neglsw = -(GET I_NEGLIMITSW)
     603         if (IN poslsw == 0) then
    545604            PRINT "Positive endswitch activated at position ", APOS
    546605            SET I_POSLIMITSW 0
    547606            ERRCLR
    548             CVEL  (vres%100) /* 1% */
    549             ACC   (10*vres%100)
    550             DEC   (10*vres%100)
     607            CVEL  (vres%100)    /*  1% */
     608            ACC   (10*vres%100) /*  10% */
     609            DEC   (10*vres%100) /*  10% */
    551610            CSTART
    552             WHILE (IN lsw == 0) DO ENDWHILE
     611            WHILE (IN poslsw == 0) DO ENDWHILE
    553612            CSTOP
    554             SET I_POSLIMITSW -lsw
     613            SET I_POSLIMITSW -poslsw
    555614            errinf = 1
    556          endif
    557          lsw = -(GET I_NEGLIMITSW)
    558          if (IN lsw == 0) then
     615         elseif (IN neglsw == 0) then
    559616            PRINT "Negative endswitch activated at position ", APOS
    560617            SET I_NEGLIMITSW 0
     
    564621            ACC   (10*vres%100)  /* 10% */
    565622            DEC   (10*vres%100)  /* 10% */
    566             OUT 1 1
    567             MOTOR ON
    568623            CSTART
    569             WHILE (IN lsw == 0) DO ENDWHILE
     624            WHILE (IN poslsw == 0) DO ENDWHILE
    570625            CSTOP
    571             SET I_NEGLIMITSW -lsw
     626            SET I_NEGLIMITSW -poslsw
    572627            errinf = -1
    573628         endif
    574       elseif (errlist[1]==84) then
     629      elseif (errlist[2]==84) then
    575630         PRINT "Too many (>12) ON TIME interrupts."
    576631         ERRCLR
    577632      ELSE
    578         PRINT "Error Function Called: ERRNO=", errlist[1]
     633        PRINT "Error Function Called: ERRNO=", errlist[2]
    579634      endif
    580635
    581636            /* tell the bus what exactly happened */
    582       CANOUT pdo2 errlist[1] errinf
     637      CANOUT pdo2 errlist[2] errinf
    583638   RETURN
    584639
  • trunk/MagicSoft/Cosy/base/timer.h

    r738 r808  
    3434    double GetMjd();
    3535
     36    int H() const { return fHor; }
     37    int M() const { return fMin; }
     38    int S() const { return fSec; }
     39
    3640    const char *GetTimeStr();
    3741
  • trunk/MagicSoft/Cosy/candrv/network.cc

    r732 r808  
    166166}
    167167
     168bool Network::HasError()
     169{
     170    for (int i=0; i<32; i++)
     171        if (fNodes[i] && fNodes[i]->HasError())
     172            return true;
     173
     174    return false;
     175}
  • trunk/MagicSoft/Cosy/candrv/network.h

    r732 r808  
    3030    virtual void Start();
    3131    virtual void Stop();
     32
     33    bool HasError();
    3234};
    3335
  • trunk/MagicSoft/Cosy/candrv/nodedrv.cc

    r732 r808  
    66#include "network.h"
    77
    8 NodeDrv::NodeDrv(BYTE_t nodeid, ostream &out) : Log(out), fNetwork(NULL), fId(32)
     8NodeDrv::NodeDrv(BYTE_t nodeid, ostream &out) : Log(out), fNetwork(NULL), fId(32), fError(0)
    99{
    1010    if (nodeid>31)
  • trunk/MagicSoft/Cosy/candrv/nodedrv.h

    r732 r808  
    1313    BYTE_t   fId;
    1414
     15    int fError;
     16
     17protected:
     18    void SetError(int err) { fError = err; }
     19    void DelError()        { fError = 0; }
     20    int  GetError()        { return fError; }
     21
    1522public:
    1623    NodeDrv(BYTE_t nodeid, ostream &out=cout);
     
    2128    virtual void InitDevice(Network *net);
    2229    virtual void StopDevice() = 0;
     30
     31    bool HasError()        { return fError; }
    2332
    2433    virtual void HandleSDO(WORD_t idx, BYTE_t subidx, LWORD_t val, struct timeval *tv);
  • trunk/MagicSoft/Cosy/catalog/StarCatalog.cc

    r748 r808  
    1616
    1717    //
    18     // calculate observers location (goe)
    19     //
    20     int status;
    21     slaDaf2r(51, 38, 48.0, &fPhi,   &status);
    22     slaDaf2r( 9, 56, 36.0, &fElong, &status);
    23 
    24     cout << "fPhi:   51ø38'48.0\" = " <<  360.0/D2PI*fPhi << endl;
    25     cout << "fElong:  9ø56'36.0\" = " <<  360.0/D2PI*fElong << endl;
    26 
    27     //
    2818    // read index file
    2919    //
     
    7868    cout << "  Az: " << fAltAz.Az() << endl;
    7969
    80     fRaDec = AltAz2RaDec(fAltAz);
     70    fRaDec = sla.CalcRaDec(fAltAz);
    8171
    8272    cout << "Ra: " << 360.0/D2PI*fRaDec.Ra();
     
    8777}
    8878
    89 RaDec StarCatalog::AltAz2RaDec(const AltAz &altaz) const
    90 {
    91     //
    92     // -- observed to apparent --
    93     //  Workaraound for slalib: discard const
    94     //
    95     double r=0, d=0;
    96     slaOapqk ("A", altaz.Az(), DPI/2-altaz.Alt(), (double*)fAoprms, &r, &d);
    97 
    98     //
    99     // -- apparent to mean --
    100     //  Workaraound for slalib: discard const
    101     //
    102     double ra, dec;
    103     slaAmpqk(r, d, (double*)fAmprms, &ra, &dec);
    104 
    105     return RaDec(ra, dec);
    106 }
    107 
    108 AltAz StarCatalog::RaDec2AltAz(const RaDec &radec, const RaDec &rdpm) const
    109 {
    110     //
    111     // ---- Mean to apparent ----
    112     //
    113 
    114     double r=0, d=0;
    115     slaMapqkz(radec.Ra(), radec.Dec(), (double*)fAmprms, &r, &d);
    116     //
    117     // Doesn't work - don't know why
    118     //
    119     //    slaMapqk (radec.Ra(), radec.Dec(), rdpm.Ra(), rdpm.Dec(),
    120     //              0, 0, (double*)fAmprms, &r, &d);
    121     //
    122 
    123     //
    124     // -- apparent to observed --
    125     //
    126     double r1=0;  // ra
    127     double d1=0;  // dec
    128     double h0=0;  // ha
    129 
    130     double zd;
    131     double az;
    132     slaAopqk (r, d, (double*)fAoprms,
    133               &az,    // observed azimuth (radians: N=0,E=90)
    134               &zd,    // observed zenith distance (radians) [-pi/2, pi/2]
    135               &h0,    // observed hour angle (radians)
    136               &d1,    // observed declination (radians)
    137               &r1);   // observed right ascension (radians)
    138 
    139     return AltAz(DPI/2-zd, az);
    140 }
    141 
    142 void StarCatalog::SetRaDec(const RaDec &radec, const RaDec &rdpm)
     79void StarCatalog::SetRaDec(const RaDec &radec)
    14380{
    14481    fRaDec = radec;
    14582    fRaDec *= D2PI/360.0;
    14683
    147     RaDec pm = rdpm * D2PI/360.0;
    148 
    149     fAltAz = RaDec2AltAz(fRaDec, pm);
     84    fAltAz = sla.CalcAltAz(fRaDec);
    15085
    15186    cout << "Alt: " << 360.0/D2PI*fAltAz.Alt() << "  ";
     
    15893void StarCatalog::CalcAltAzRange()
    15994{
    160     char fAlt0[180];
     95    byte fAlt0[180];
    16196
    16297    for (int h=0; h<180; h++)
     
    248183    // check whether altaz north- or south-pole is in the visible region
    249184    //
    250     char img[768*576];
     185    byte img[768*576];
    251186    if (DrawAltAz(0, img, 90, 0))
    252187    {
     
    263198    cout << "fAltMax: " << setw(3) << fAltMax << endl;
    264199}
     200
    265201void StarCatalog::CalcRaDecRange()
    266202{
     
    268204    // calculate range to search in
    269205    //
    270     char fDec[180];
     206    byte fDec[180];
    271207
    272208    for (int h=0; h<180; h++)
     
    279215    double de0, de1;
    280216
     217    const double phi   = sla.GetPhi();
     218    const double alpha = sla.GetAlpha();
    281219    //
    282220    // scan horizontal border
     
    286224        double dx, dy;
    287225        slaDh2e(DPI-x*fPixSize, -fHeight, DPI/2-fAltAz.Alt(), &dx, &dy);
    288         slaDh2e(fAltAz.Az()+dx, -dy, fPhi, &ha0, &de0);
     226        slaDh2e(fAltAz.Az()+dx, -dy, phi, &ha0, &de0);
    289227
    290228        slaDh2e(DPI-x*fPixSize, +fHeight, DPI/2-fAltAz.Alt(), &dx, &dy);
    291         slaDh2e(fAltAz.Az()+dx, -dy, fPhi, &ha1, &de1);
    292 
    293         const int h0 = ((int)(360.0/D2PI*(fAlpha-ha0))+360)%360;
     229        slaDh2e(fAltAz.Az()+dx, -dy, phi, &ha1, &de1);
     230
     231        const int h0 = ((int)(360.0/D2PI*(alpha-ha0))+360)%360;
    294232        const int d0 = (int)(360.0/D2PI*de0);
    295233
     
    299237            fDec[d0+90] = kTRUE;
    300238
    301         const int h1 = ((int)(360.0/D2PI*(fAlpha-ha1))+360)%360;
     239        const int h1 = ((int)(360.0/D2PI*(alpha-ha1))+360)%360;
    302240        const int d1 = (int)(360.0/D2PI*de1);
    303241
     
    315253        double dx, dy;
    316254        slaDh2e(DPI-fWidth, -y*fPixSize, DPI/2-fAltAz.Alt(), &dx, &dy);
    317         slaDh2e(fAltAz.Az()+dx, -dy, fPhi, &ha0, &de0);
     255        slaDh2e(fAltAz.Az()+dx, -dy, phi, &ha0, &de0);
    318256
    319257        slaDh2e(DPI+fWidth, -y*fPixSize, DPI/2-fAltAz.Alt(), &dx, &dy);
    320         slaDh2e(fAltAz.Az()+dx, -dy, fPhi, &ha1, &de1);
    321 
    322         const int h0 = ((int)(360.0/D2PI*(fAlpha-ha0))+360)%360;
     258        slaDh2e(fAltAz.Az()+dx, -dy, phi, &ha1, &de1);
     259
     260        const int h0 = ((int)(360.0/D2PI*(alpha-ha0))+360)%360;
    323261        const int d0 = (int)(360.0/D2PI*de0);
    324262
     
    328266            fDec[d0+90] = kTRUE;
    329267
    330         const int h1 = ((int)(360.0/D2PI*(fAlpha-ha1))+360)%360;
     268        const int h1 = ((int)(360.0/D2PI*(alpha-ha1))+360)%360;
    331269        const int d1 = (int)(360.0/D2PI*de1);
    332270
     
    364302    // check whether radec north- or south-pole is in the visible region
    365303    //
    366     char img[768*576];
     304    byte img[768*576];
    367305    if (DrawRaDec(0, img, 0, 90))
    368306    {
     
    380318}
    381319
    382 void StarCatalog::DrawSCAltAz(char *img, const int color)
     320void StarCatalog::DrawSCAltAz(byte *img, const int color)
    383321{
    384322    //
     
    414352}
    415353
    416 void StarCatalog::DrawSCRaDec(char *img, const int color)
     354void StarCatalog::DrawSCRaDec(byte *img, const int color)
    417355{
    418356    //
     
    446384        }
    447385    }
    448 
    449 //    DrawRaDec(color, img, 37.953, 89.2641, 10);
    450 }
    451 
    452 
    453 void StarCatalog::SetMjd(const double mjd)
    454 {
    455     fMjd   = mjd;
    456     fAlpha = slaGmst(mjd) + fElong;
    457 
    458     cout << "UTC: " << mjd << endl;
    459 
    460     //
    461     // ----- calculate star independent parameters ----------
    462     //
    463     slaMappa(2000.0, fMjd, fAmprms);
    464     slaAoppa(fMjd, 0,                // mjd, UT1-UTC
    465              fElong, fPhi, 148,      // g”ttingen long, lat, height
    466              0, 0,                   // polar motion x, y-coordinate (radians)
    467              273.155, 1013.25, 0.5,  // temp, pressure, humidity
    468              0.2, 0.0065,            // wavelength, tropo lapse rate
    469              fAoprms);
    470 
    471 }
    472 
    473 void StarCatalog::DrawCross(char *img, const int x, const int y)
     386}
     387
     388void StarCatalog::DrawCross(byte *img, const int x, const int y)
    474389{
    475390    for (int dx=-4; dx<5; dx++)
     
    480395}
    481396
    482 void StarCatalog::GetImg(char *img, char *cimg, const double utc,
     397void StarCatalog::GetImg(byte *img, byte *cimg, const double utc,
    483398                         const RaDec &radec)
    484399{
     
    486401    memset(cimg, 0, 768*576);
    487402
    488     SetMjd(utc);
    489 
    490     SetRaDec(radec, RaDec());
     403    sla.Set(utc);
     404    //fAlpha = sla.GetAlpha();
     405    SetRaDec(radec);
    491406
    492407    DrawSCAltAz(cimg, 2<<4);
     
    498413}
    499414
    500 void StarCatalog::GetImg(char *img, char *cimg, const double utc,
     415void StarCatalog::GetImg(byte *img, byte *cimg, const double utc,
    501416                         const AltAz &altaz)
    502417{
     
    504419    memset(cimg, 0, 768*576);
    505420
    506     SetMjd(utc);
    507 
     421    sla.Set(utc);
     422    //fAlpha = sla.GetAlpha();
    508423    SetAltAz(altaz);
    509424
     
    516431}
    517432
    518 void StarCatalog::DrawCircle(int color, char *img, int xx, int yy, int size)
     433void StarCatalog::DrawCircle(int color, byte *img, int xx, int yy, int size)
    519434{
    520435    for (int x=xx-size; x<xx+size+1; x++)
     
    537452}
    538453
    539 Bool_t StarCatalog::DrawAltAz(const int color, char *img, double alt, double az, int size)
     454Bool_t StarCatalog::DrawAltAz(const int color, byte *img, double alt, double az, int size)
    540455{
    541456    //
     
    571486}
    572487
    573 Bool_t StarCatalog::Draw(const int color, char *img, const AltAz &altaz)
     488Bool_t StarCatalog::Draw(const int color, byte *img, const AltAz &altaz)
    574489{
    575490    return DrawAltAz(color, img, altaz.Alt(), altaz.Az());
    576491}
    577492
    578 Bool_t StarCatalog::Draw(const int color, char *img, const SaoFile *sao)
     493Bool_t StarCatalog::Draw(const int color, byte *img, const SaoFile *sao)
    579494{
    580495    //
    581496    // ---- mean to observed ---
    582497    //
    583     AltAz altaz=RaDec2AltAz(sao->GetRaDec(), sao->GetRaDecPm()) * 360.0/D2PI;
     498    AltAz altaz=sla.CalcAltAz(sao->GetRaDec()) * 360.0/D2PI;
    584499
    585500    if (sao->MagV() > fLimitMag)
     
    594509}
    595510
    596 Bool_t StarCatalog::DrawRaDec(const int color, char *img, double ra, double dec, int size)
     511Bool_t StarCatalog::DrawRaDec(const int color, byte *img, double ra, double dec, int size)
    597512{
    598513    //
     
    605520    // radec[rad] -> hadec[rad]
    606521    //
    607     const double ha = fAlpha-ra;
     522    const double ha = sla.GetAlpha()-ra;
    608523
    609524    //
     
    611526    //
    612527    double alt, az;
    613     slaDe2h(ha, dec, fPhi, &az, &alt);
     528    slaDe2h(ha, dec, sla.GetPhi(), &az, &alt);
    614529
    615530    //
     
    622537}
    623538
    624 Bool_t StarCatalog::Draw(const int color, char *img, const RaDec &radec)
     539Bool_t StarCatalog::Draw(const int color, byte *img, const RaDec &radec)
    625540{
    626541    return DrawRaDec(color, img, radec.Ra(), radec.Dec());
    627542}
    628543
    629 void StarCatalog::CalcImg(char *img)
     544void StarCatalog::CalcImg(byte *img)
    630545{
    631546
  • trunk/MagicSoft/Cosy/catalog/StarCatalog.h

    r740 r808  
    88#include "SaoFile.h"
    99#endif
     10#ifndef SLALIB_H
     11#include "Slalib.h"
     12#endif
    1013
    1114#include "coord.h"
     15
     16typedef unsigned char byte;
    1217
    1318class StarCatalog
     
    1823    int      fEntries;
    1924
    20     double   fPhi;      // location of observatory
    21     double   fElong;
     25    Slalib   sla;
     26
     27//    double   fPhi;      // location of observatory
     28//    double   fElong;
    2229
    2330    double   fPixSize;  // [rad/pix] size of one pixel
     
    2835
    2936    AltAz    fAltAz;    // [rad]
    30     char     fAz0[360];
     37    byte     fAz0[360];
    3138    int      fAltMin;
    3239    int      fAltMax;
     
    3441
    3542    RaDec    fRaDec;    // [rad]
    36     char     fRa0[360];
     43    byte     fRa0[360];
    3744    int      fRaCnt;
    3845    int      fDecMin;
    3946    int      fDecMax;
    4047
    41     double   fAlpha;
    42     double   fMjd;
    43     double   fAmprms[21];
    44     double   fAoprms[14];
     48//    double   fAlpha;
     49//    double   fMjd;
     50//    double   fAmprms[21];
     51//    double   fAoprms[14];
    4552
    46     void DrawCross(char *img, const int x, const int y);
    47     void DrawCircle(int color, char *img, int xx, int yy, int size);
     53    void DrawCross(byte *img, const int x, const int y);
     54    void DrawCircle(int color, byte *img, int xx, int yy, int size);
    4855
    49     Bool_t DrawAltAz(const int color, char *img, double alt, double az, int size=0);
    50     Bool_t DrawRaDec(const int color, char *img, double ra,  double dec, int size=0);
     56    Bool_t DrawAltAz(const int color, byte *img, double alt, double az, int size=0);
     57    Bool_t DrawRaDec(const int color, byte *img, double ra,  double dec, int size=0);
    5158
    52     Bool_t Draw(const int color, char *img, const AltAz &altaz);
    53     Bool_t Draw(const int color, char *img, const RaDec &radec);
    54     Bool_t Draw(const int color, char *img, const SaoFile *sao);
     59    Bool_t Draw(const int color, byte *img, const AltAz &altaz);
     60    Bool_t Draw(const int color, byte *img, const RaDec &radec);
     61    Bool_t Draw(const int color, byte *img, const SaoFile *sao);
    5562
    56     void   CalcImg(char *);
     63    void   CalcImg(byte *);
    5764
     65    void   SetRaDec(const RaDec &radec);
    5866    void   SetAltAz(const AltAz &altaz);
    59     void   SetMjd(const double mjd);
    60     void   DrawSCAltAz(char *img, const int color);
    61     void   DrawSCRaDec(char *img, const int color);
    62     void   SetRaDec(const RaDec &radec, const RaDec &rdpm);
    63 
     67//    void   SetMjd(const double mjd);
     68    void   DrawSCAltAz(byte *img, const int color);
     69    void   DrawSCRaDec(byte *img, const int color);
     70 
    6471    void   CalcRaDecRange();
    6572    void   CalcAltAzRange();
    6673
    67     RaDec  AltAz2RaDec(const AltAz &altaz) const;
    68     AltAz  RaDec2AltAz(const RaDec &radec, const RaDec &rdpm) const;
     74//    RaDec  AltAz2RaDec(const AltAz &altaz) const;
     75//    AltAz  RaDec2AltAz(const RaDec &radec, const RaDec &rdpm) const;
    6976
    7077public:
     
    7279    virtual ~StarCatalog();
    7380
    74     void   GetImg(char *img, char *cimg, const double utc,
     81    void   GetImg(byte *img, byte *cimg, const double utc,
    7582                  const RaDec &radec);
    76     void   GetImg(char *img, char *cimg, const double utc,
     83    void   GetImg(byte *img, byte *cimg, const double utc,
    7784                  const AltAz &altaz);
    7885
  • trunk/MagicSoft/Cosy/devdrv/macs.cc

    r732 r808  
    1010    : NodeDrv(nodeid, out), fMacId(2*nodeid+1),
    1111    fPos(0), fPosTime(0.0), fPdoPos(0), fPdoTime(0.0),
    12     fPosActive(0), fRpmActive(0), fError(FALSE)
     12    fPosActive(0), fRpmActive(0)
    1313{
    1414}
     
    115115    RequestSDO(0x2004);
    116116    WaitForSdo(0x2004);
    117 
    118 
    119 */
     117    */
     118
    120119    lout << "- Requesting Mac Software Version of " << (int)GetId() << endl;
    121120    RequestSDO(0x100a);
    122121    WaitForSdo(0x100a);
    123     //   
     122
    124123    SetRpmMode(FALSE);
    125124
     
    131130
    132131
    133     SetHome(250000);
     132//    SetHome(250000);
    134133
    135134//    lout << "- Requesting SDO 0x2001 of " << (int)GetId() << endl;
     
    195194    WaitForSdo(0x6003, 2);
    196195
     196    // home also defines the zero point of the system
    197197    SendSDO(0x3001, string('h','o','m','e'));       // home
    198198    WaitForSdo(0x3001);
    199199    lout << "- Home position of #" << (int)GetId() << " reached. " << endl;
     200
     201    SendSDO(0x6003, 0, string('s','e','t'));       // home
     202    WaitForSdo(0x6003, 0);
    200203}
    201204
     
    208211void Macs::SetAcceleration(LWORD_t acc)
    209212{
    210     SendSDO(0x2003, 0, acc);     // acceleration
     213    SendSDO(0x2003, 0, acc);  // acceleration
    211214    WaitForSdo(0x2003, 0);
    212215}
     
    214217void Macs::SetDeceleration(LWORD_t dec)
    215218{
    216     SendSDO(0x2003, 1, dec);     // acceleration
     219    SendSDO(0x2003, 1, dec);  // acceleration
    217220    WaitForSdo(0x2003, 1);
    218221}
     
    223226    // SetRpmMode(FALSE) stop the motor, but lets the position control unit on
    224227    //
    225 
    226228    SendSDO(0x3006, 0, mode ? string('S','T','R','T') : string('S','T','O','P'));
    227229    WaitForSdo(0x3006, 0);
     
    250252    WaitForSdo(0x3008);
    251253}
     254
     255void Macs::SetSyncMode()
     256{
     257    lout << "- Setting Sync Mode #" << (int)GetId() << endl;
     258    SendSDO(0x3007, string('S', 'Y', 'N', 'C'));
     259    WaitForSdo(0x3007);
     260}
    252261/*
    253262void Macs::ReqAxEnd()
     
    283292    LWORDS_t errinf = (data[4]<<24) | (data[5]<<16) | (data[6]<<8) | data[7];
    284293
     294    //
     295    // errnum==0 gives a sudden information that something happened. Now the
     296    // microcontroller is running inside its interrup procedure which
     297    // stopped the normal program. The interrupt procedure should try to clear
     298    // the error state of the hardware. This should never create a new error!
     299    //
    285300    if (!errnum)
    286301    {
    287302        cout << "Mac #" << (int)GetId() << " reports Error occursion." << endl;
    288         fError = TRUE;
     303        SetError(-1);
    289304        return;
    290305    }
     306
     307    //
     308    // Now the error is handled by the hardware now it is the software part
     309    // to react on it. The Error flag now is set to the correct value.
     310    //
     311    if (GetError()>0)
     312        cout << "Mac #" << (int)GetId() << " WARNING! Error #" << GetError() << " unhandled by software." << endl;
     313
     314    SetError(errnum);
    291315
    292316    cout << "Mac #" << (int)GetId() << " reports: ";
     
    305329        return;
    306330
     331    case 11:
    307332    case 25:
    308333        switch (errinf)
    309334        {
     335        case -1:
     336            cout << "Negative";
     337            break;
    310338        case 1:
    311339            cout << "Positive";
    312             break;
    313         case 2:
    314             cout << "Negative";
    315340            break;
    316341        default:
    317342            cout << "-unknown-";
    318343        }
    319         cout << " endswitch activated." << endl;
    320         fError = FALSE;
     344        switch (errnum)
     345        {
     346        case 11:
     347            cout << " software endswitch activated." << endl;
     348            break;
     349        case 25:
     350            cout << " hardware endswitch activated." << endl;
     351            break;
     352        }
    321353        return;
    322354
     
    330362}
    331363
     364void Macs::HandleError()
     365{
     366    //
     367    // If there is no error we must not handle anything
     368    //
     369    if (!HasError())
     370        return;
     371
     372    //
     373    // If the program got into the: HandleError state before the hardware
     374    // has finished handeling the error we have to wait for the hardware
     375    // handeling the error
     376    //
     377    // FIXME: Timeout???
     378    //
     379    while (GetError()<0)
     380        usleep(1);
     381
     382    //
     383    // After this software and hardware should be in a state so that
     384    // we can go on working 'as usual' Eg. Initialize a Display Update
     385    //
     386    cout << "Mac #" << (int)GetId() << " Handling Error #" << GetError() << endl;
     387    switch (GetError())
     388    {
     389    case  6: // home
     390    case  8: // control dev
     391    case  9: // zero idx
     392    case 84: // ON TIME
     393        // Stop program?
     394        return;
     395
     396    case 11: // software endswitch
     397    case 25: // hardware endswitch
     398        DelError();
     399        return;
     400    }
     401}
     402
    332403double Macs::GetTime()
    333404{
     
    350421}
    351422
     423/*   0x2000 0 rw Maximum positioning error     */
     424/*          1 rw Negative Software Endswitch   */
     425/*          2 rw Positive Software Endswitch   */
     426void Macs::SetNegEndswitch(LWORDS_t val)
     427{
     428    SendSDO(0x2000, 1, (LWORD_t)val);
     429    WaitForSdo(0x2000, 1);
     430}
     431
     432void Macs::SetPosEndswitch(LWORDS_t val)
     433{
     434    SendSDO(0x2000, 2, (LWORD_t)val);
     435    WaitForSdo(0x2000, 2);
     436}
     437
     438void Macs::EnableEndswitches(bool neg, bool pos)
     439{
     440    SendSDO(0x2000, 3, (LWORD_t)(neg|(pos<<1)));
     441    WaitForSdo(0x2000, 3);
     442}
  • trunk/MagicSoft/Cosy/devdrv/macs.h

    r732 r808  
    2121    BYTE_t   fPosActive;
    2222    BYTE_t   fRpmActive;
    23 
    24     int      fError;      // Indicater for error state
    2523
    2624    LWORD_t string(BYTE_t b0=0, BYTE_t b1=0, BYTE_t b2=0, BYTE_t b3=0)
     
    5856    void SetVelocity(LWORD_t vel);
    5957    void SetNoWait(BYTE_t flag=TRUE);
     58    void SetSyncMode();
    6059    void SetRpmMode(BYTE_t mode=TRUE);
    6160    void SetRpmVelocity(LWORDS_t cvel);
    6261    void SetPDO1On(BYTE_t flag=TRUE);
     62    void SetPosEndswitch(LWORDS_t val);
     63    void SetNegEndswitch(LWORDS_t val);
     64
     65    void EnableEndswitches(bool neg=true, bool pos=true);
    6366
    6467    void StartRelPos(LWORDS_t pos);
     
    7982    LWORDS_t GetPos()    { return fPos; }
    8083    LWORDS_t GetVel()    { return fVel; }
    81     LWORD_t  GetVelRes() { return fVelRes; }
     84    LWORD_t  GetVelRes() { return fVelRes; } // Velocity units (would be 100 for %)
    8285
    83     int      HasError() { return fError; }
     86    void HandleError();
    8487};
    8588
  • trunk/MagicSoft/Cosy/gui/MGCoordinate.cc

    r732 r808  
    2525MGCoordinate::MGCoordinate(const TGWindow* p,
    2626                           const Bool_t flag, const char *txt,
    27                            const UInt_t deg, const UInt_t min, const UInt_t sec)
     27                           const Int_t deg, const UInt_t min, const UInt_t sec)
    2828: TGFrame(p, 114, flag?76:46, kSunkenFrame|kFixedSize), fDeg(deg), fMin(min), fSec(sec)
    2929{
     
    131131Double_t MGCoordinate::GetVal() const
    132132{
    133     return (Double_t)(60*(60*fDeg+fMin)+fSec)/3600;
     133    const Int_t deg = fDeg<0 ? -fDeg : fDeg;
     134    const Int_t sgn = fDeg<0 ? -1 : 1;
     135
     136    return (Double_t)sgn*(60*(60*deg+fMin)+fSec)/3600;
    134137}
    135138
     
    139142}
    140143
    141 void MGCoordinate::Set(TGLabel *label, UInt_t val)
     144void MGCoordinate::Set(TGLabel *label, Int_t val)
    142145{
    143146    char txt[20];
     
    148151}
    149152
    150 void MGCoordinate::Set(TGTextEntry *entry, UInt_t val)
     153void MGCoordinate::Set(TGTextEntry *entry, Int_t val)
    151154{
    152155    char txt[20];
     
    184187
    185188
    186 Bool_t MGCoordinate::Set(TGLabel *label, UInt_t &val, TGTextEntry *entry)
    187 {
    188     UInt_t newval = atoi(entry->GetText());
    189 
    190     Bool_t ok = (entry == fTextEntryDeg || newval<60);
     189Bool_t MGCoordinate::Set(TGLabel *label, Int_t &val, TGTextEntry *entry)
     190{
     191    Int_t newval = atoi(entry->GetText());
     192
     193    Bool_t ok = (entry == fTextEntryDeg || (newval>=0 && newval<60));
    191194
    192195    if (ok)
  • trunk/MagicSoft/Cosy/gui/MGCoordinate.h

    r732 r808  
    2020class MGCoordinate : public TGFrame
    2121{
    22     UInt_t fDeg;
    23     UInt_t fMin;
    24     UInt_t fSec;
     22    Int_t fDeg;
     23    Int_t fMin;
     24    Int_t fSec;
    2525
    2626    MGList fList;
     
    3636    TGLabel     *fLabel;
    3737
    38     void   Set(TGLabel     *label, const UInt_t val);
    39     void   Set(TGTextEntry *entry, const UInt_t val);
    40     Bool_t Set(TGLabel     *label, UInt_t &val, TGTextEntry *label);
     38    void   Set(TGLabel     *label, const Int_t val);
     39    void   Set(TGTextEntry *entry, const Int_t val);
     40    Bool_t Set(TGLabel     *label, Int_t &val, TGTextEntry *label);
    4141
    4242public:
    4343    MGCoordinate(const TGWindow* p,
    4444                 const Bool_t flag=kTRUE, const char *txt="Coordinates:",
    45                  const UInt_t deg=0, const UInt_t min=0, const UInt_t sec=0);
     45                 const Int_t deg=0, const UInt_t min=0, const UInt_t sec=0);
    4646    ~MGCoordinate();
    4747
  • trunk/MagicSoft/Cosy/gui/MGCoordinates.cc

    r732 r808  
    1414                             const Bool_t flag,
    1515                             const char *txt1, const char *txt2,
    16                              const UInt_t deg1, const UInt_t min1, const UInt_t sec1,
    17                              const UInt_t deg2, const UInt_t min2, const UInt_t sec2)
     16                             const Int_t deg1, const UInt_t min1, const UInt_t sec1,
     17                             const Int_t deg2, const UInt_t min2, const UInt_t sec2)
    1818: TGFrame(p, 234, 76, kFixedSize)
    1919{
  • trunk/MagicSoft/Cosy/gui/MGCoordinates.h

    r732 r808  
    2727                  const char *txt1="Coordinate1:",
    2828                  const char *txt2="Coordinate2:",
    29                   const UInt_t deg1=0, const UInt_t min1=0, const UInt_t sec1=0,
    30                   const UInt_t deg2=0, const UInt_t min2=0, const UInt_t sec2=0);
     29                  const Int_t deg1=0, const UInt_t min1=0, const UInt_t sec1=0,
     30                  const Int_t deg2=0, const UInt_t min2=0, const UInt_t sec2=0);
    3131    ~MGCoordinates();
    3232
  • trunk/MagicSoft/Cosy/gui/MGCosy.cc

    r740 r808  
    1616#include "MGList.h"
    1717#include "MGCoordinates.h"
     18
     19#include "Slalib.h"
    1820
    1921#define IDM_EXIT 1
     
    242244                    t.GetTime();
    243245
     246                    Slalib sla;
     247                    sla.Set(t.GetMjd());
     248
    244249                    XY xy = fCoord->GetCoordinates();
    245250                    RaDec rd(xy.X(), xy.Y());
    246251
    247252                    cout << "Ra/Dec: " << rd.Ra() << kDEG << " " << rd.Dec() << kDEG << endl;
    248                     ZdAz aa=MCosy::RaDec2ZdAz(t.GetMjd(), rd*D2PI/360.0)*360.0/D2PI;
     253                    ZdAz aa=sla.CalcZdAz(rd*D2PI/360.0)*360.0/D2PI;
    249254                    cout << "Zd/Az: " << aa.Zd() << kDEG << " " << aa.Az() << kDEG << endl;
    250255                }
  • trunk/MagicSoft/Cosy/gui/MGImage.cc

    r732 r808  
    195195
    196196
    197 #include <TGClient.h>
    198 void MGImage::DrawImg(const char *buffer)
     197//#include <TGClient.h>
     198void MGImage::DrawImg(const byte *buffer)
    199199{
    200200    if (pthread_mutex_trylock((pthread_mutex_t*)fMuxPixmap))
     
    205205        for (UInt_t x=0; x<fWidth; x++)
    206206        {
    207             const unsigned char col = buffer[y*fWidth+x];
     207            const byte col = buffer[y*fWidth+x];
    208208
    209209            fBody[y][x*2]   = fColors[col][0];
     
    306306}
    307307
    308 void MGImage::DrawColImg(const char *gbuf, const char *cbuf)
     308void MGImage::DrawColImg(const byte *gbuf, const byte *cbuf)
    309309{
    310310    if (pthread_mutex_trylock((pthread_mutex_t*)fMuxPixmap))
     
    315315        for (UInt_t x=0; x<fWidth; x++)
    316316        {
    317             const unsigned char ccol = cbuf[y*fWidth+x];
     317            const byte ccol = cbuf[y*fWidth+x];
    318318
    319319            if (ccol)
     
    324324            else
    325325            {
    326                 const unsigned char gcol = gbuf[y*fWidth+x];
     326                const byte gcol = gbuf[y*fWidth+x];
    327327                fBody[y][x*2]   = fColors[gcol][0];
    328328                fBody[y][x*2+1] = fColors[gcol][1];
  • trunk/MagicSoft/Cosy/gui/MGImage.h

    r732 r808  
    99
    1010#include <TGFrame.h>
     11
     12typedef unsigned char byte;
    1113
    1214class MGImage : public TGFrame
     
    3840    void MoveResize(Int_t x, Int_t y, UInt_t w, UInt_t h);
    3941
    40     void DrawImg(const char *buffer);
    41     void DrawColImg(const char *gbuf, const char *cbuf);
     42    void DrawImg(const byte *buffer);
     43    void DrawColImg(const byte *gbuf, const byte *cbuf);
    4244};
    4345
  • trunk/MagicSoft/Cosy/videodev/Camera.cc

    r738 r808  
    188188
    189189void Camera::Execute(const unsigned long n,
    190                      char *img,
     190                     byte *img,
    191191                     struct timeval *tm)
    192192{
     
    247247            if (!StartGrab(i&1))
    248248                break;
    249             Execute(i, fImg, &fTime);
     249            Execute(i, (byte*)fImg, &fTime);
    250250            i++;
    251251        }
     
    254254        {
    255255            LoopStep(i);
    256             Execute(i, fImg, &fTime);
     256            Execute(i, (byte*)fImg, &fTime);
    257257            i++;
    258258        }
    259259
    260260        LoopStep(i);
    261         Execute(i, fImg, &fTime);
     261        Execute(i, (byte*)fImg, &fTime);
    262262        i++;
    263263
  • trunk/MagicSoft/Cosy/videodev/Camera.h

    r738 r808  
    44#include <pthread.h>
    55#include <sys/time.h>
     6
     7typedef unsigned char byte;
    68
    79class Camera
     
    8587    //
    8688    virtual void Execute(const unsigned long n,
    87                          char *img, struct timeval *tm);
     89                         byte *img, struct timeval *tm);
    8890
    8991    //
  • trunk/MagicSoft/Cosy/videodev/Filter.cc

    r738 r808  
    66void Filter::DrawBox(const int x1, const int y1,
    77                     const int x2, const int y2,
    8                      char *buffer, const int col)
     8                     byte *buffer, const int col)
    99{
    1010    for (int x=x1; x<x2+1; x++)
     
    1313}
    1414
    15 void Filter::MarkPoint(const int x, const int y, char *buffer, const int col)
     15void Filter::MarkPoint(const int x, const int y, byte *buffer, const int col)
    1616{
    1717    DrawBox(x-8, y, x-5, y, buffer, col);
     
    2222}
    2323
    24 float Filter::Mean(const char *buffer, const int offset, int *min, int *max)
     24float Filter::Mean(const byte *buffer, const int offset, int *min, int *max)
    2525{
    2626    double mean = 0.0;
     
    3535        for (int y=offset; y<576-offset; y++)
    3636        {
    37             unsigned char val = (unsigned char)buffer[y*768+x];
     37            byte val = buffer[y*768+x];
    3838
    3939            mean += val;
    4040
    41             if (*max<val)
     41            if (val>*max)
    4242                *max = val;
    4343
    44             if (*min>val)
     44            if (val<*min)
    4545                *min = val;
    4646        }
     
    5151}
    5252
    53 float Filter::SDev(const char *buffer, const int offset, const double mean)
     53float Filter::SDev(const byte *buffer, const int offset, const double mean)
    5454{
    5555    //
     
    6161        for (int y=offset; y<576-offset; y++)
    6262        {
    63             const float val = mean - (unsigned char)buffer[y*768+x];
     63            const float val = mean - buffer[y*768+x];
    6464
    6565            sdev += val*val;
     
    7171}
    7272
    73 int Filter::GetMeanPosition(const char *bitmap, const int x, const int y,
     73int Filter::GetMeanPosition(const byte *bitmap, const int x, const int y,
    7474                            const int box)
    7575{
     
    8282        for (int dy=y-box; dy<y+box+1; dy++)
    8383        {
    84             const unsigned char m = (unsigned char)bitmap[dy*768+dx]; // desc->buffer[3*(x+y*768)]; //
     84            const byte m = bitmap[dy*768+dx]; // desc->buffer[3*(x+y*768)]; //
    8585
    8686            sumx += m*dx;
     
    9595}
    9696
    97 void Filter::Execute(char *img)
     97void Filter::Execute(byte *img)
    9898{
    9999    const int offset = 10;
     
    115115            if (img[y*768+x]>cut)
    116116                continue;
     117
     118            //
     119            // FIXME: Create LOOKUP Table!
     120            //
    117121
    118122            img[y*768+x] = 0;
     
    169173    int points=0;
    170174
    171     char marker[768*576];
     175    byte marker[768*576];
    172176    memset(marker, 0, 768*576);
    173177
  • trunk/MagicSoft/Cosy/videodev/Filter.h

    r738 r808  
    11#ifndef FILTER_H
    22#define FILTER_H
     3
     4typedef unsigned char byte;
    35
    46class Filter
     
    68    static void  DrawBox(const int x1, const int y1,
    79                         const int x2, const int y2,
    8                          char *buffer, const int col);
     10                         byte *buffer, const int col);
    911
    1012    static void  MarkPoint(const int x, const int y,
    11                            char *buffer, const int col);
     13                           byte *buffer, const int col);
    1214
    13     static float Mean(const char *buffer, const int offset,
     15    static float Mean(const byte *buffer, const int offset,
    1416                      int *min, int *max);
    1517
    16     static float SDev(const char *buffer, const int offset,
     18    static float SDev(const byte *buffer, const int offset,
    1719                      const double mean);
    1820
    19     static int   GetMeanPosition(const char *bitmap,
     21    static int   GetMeanPosition(const byte *bitmap,
    2022                                 const int x, const int y,
    2123                                 const int box);
    2224
    2325public:
    24     static void Execute(char *img);
     26    static void Execute(byte *img);
    2527};
    2628
  • trunk/MagicSoft/Cosy/videodev/Writer.cc

    r738 r808  
    99#include "timer.h"
    1010
    11 void Writer::Png(const char *fname, const char *buf,
     11void Writer::Png(const char *fname, const byte *buf,
    1212                 struct timeval *date)
    1313{
     
    106106}
    107107
    108 void Writer::Ppm(const char *fname, const char *img)
     108void Writer::Ppm(const char *fname, const byte *img)
    109109{
    110110    cout << "Writing PPM '" << fname << "'" << endl;
     
    121121    //
    122122    fout << "P6\n768 576\n255\n";
    123     for (char const *buf = img; buf < img+768*576; buf++)
     123    for (byte const *buf = img; buf < img+768*576; buf++)
    124124        fout << *buf << *buf << *buf;
    125125}
  • trunk/MagicSoft/Cosy/videodev/Writer.h

    r738 r808  
    33
    44#include <sys/time.h>
     5
     6typedef unsigned char byte;
    57
    68class Writer;
     
    1012public:
    1113
    12     static void Ppm(const char *fname, const char *img);
    13     static void Png(const char *fname, const char *buf, struct timeval *date);
     14    static void Ppm(const char *fname, const byte *img);
     15    static void Png(const char *fname, const byte *buf, struct timeval *date);
    1416};
    1517
Note: See TracChangeset for help on using the changeset viewer.