Changeset 8865 for trunk/MagicSoft


Ignore:
Timestamp:
02/20/08 19:39:13 (17 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Cosy
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Cosy/Changelog

    r8864 r8865  
    11                                                                  -*-*- END -*-*-
     2
     3 2008/02/20 Thomas Bretz (La Palma)
     4
     5   * candrv/ethernet.[h,cc]:
     6     - return kFALSE even if RecvRaw return a value <0
     7
     8   * devdrv/macs.[h,cc]:
     9     - added setting and reseeting of an armed state disallowing
     10       all movements
     11     - set fPosActive if positiong has been started to prevent lags
     12       in the program flow
     13     - added fArmed to PDO1
     14     - added some debug output
     15
     16   * gui/MGCosy.[h,cc]:
     17     - added "Arm" button to the display in expert mode
     18     - added armed state to the Update member function
     19
     20   * main/MCosy.[h,cc]:
     21     - commented out all accesses to the third MACS
     22     - added code to allow the armed state to be set from the gui
     23     - pipe the armed state to the gui
     24
     25   * tcpip/MTcpIpIO.[h,cc]:
     26     - added a timeout to MTcpIpI when waiting for new data
     27       which is set to 5s by default
     28     - return kFALSE even if RecvRaw return a value <0
     29     - wait for new connection in case of timeout
     30
     31
    232
    333 2008/02/17 Thomas Bretz (La Palma)
  • trunk/MagicSoft/Cosy/candrv/ethernet.cc

    r8864 r8865  
    9090        const Int_t len = rx.RecvRaw(&c, 1);
    9191
    92         // No data received (non-blocking mode)
    93         if (len<0)
    94         {
    95             usleep(1);
    96             continue;
    97         }
    98 
    99         // Data received with zero length! (Connection lost)
    100         if (len==0)
     92        // For details see TSocket::RecvRaw
     93        // -1: // ERROR
     94        // EINVAL, EWOULDBLOCK
     95        // -5: // EPIPE || ECONNRESET = Pipe broken or connection reset by peer
     96        //  0: Data received with zero length! (Connection lost/call interrupted)
     97        if (len<=0)
    10198            return kFALSE;
    10299
     
    112109            if (c>=MSGLEN)
    113110            {
    114                 cout << "Data received from " << address << " too long (> " << MSGLEN << ")" << endl;
     111                gLog << err << "Data received from " << address << " too long (> " << MSGLEN << ")" << endl;
    115112                continue;
    116113            }
  • trunk/MagicSoft/Cosy/devdrv/macs.cc

    r8864 r8865  
    3434    : NodeDrv(nodeid, name), fMacId(2*nodeid+1),
    3535    fPos(0), fPdoPos(0), fPosActive(0), fRpmActive(0),
    36     fStatusPdo3(0xff)
     36    fStatusPdo3(0xff), fArmed(false)
    3737{
    3838//    fTimeout = new TTimer(this, 100); //, kFALSE); // 100ms, asynchronous
     
    7272    case 0xa149: return "Drive controlled interpolated relative positioning lagless with encoder 2";
    7373    case 0xa150: return "Drive controlled positioning with encoder 1";
    74     case 0xa151: return "Drive controlled positioning with encoder 2";
     74    case 0xa151: return "Drive controlled positioning with encoder 1, lagless";
    7575    case 0xa208: return "Jog mode positive";
    7676    case 0xa218: return "Jog mode negative";
     
    9191    case 0xe264: return "Target position out of numerical range";
    9292    case 0xe834: return "Emergency-Stop";
     93    case 0xe842: return "Both end-switches activated";
    9394    case 0xe843: return "Positive end-switch activated";
    9495    case 0xe844: return "Negative end-switch activated";
     
    150151    switch (idx)
    151152    {
     153    case 0x1000:
     154        if (subidx==1)
     155        {
     156            gLog << inf2 << "- " << GetNodeName() << ": Node is" << (val?" ":" not ") << "armed." << endl;
     157            fArmed = val==1;
     158        }
     159        return;
     160
    152161    case 0x1003:
    153162        // FIXME, see Init
     
    382391            //lout << ddev(MLog::eGui);
    383392            gLog << inf2 << "- " << GetNodeName() << ": Absolute positioning started." << endl;
     393            fPosActive = kTRUE; // Make sure that the status is set correctly already before the first PDO
    384394            //lout << edev(MLog::eGui);
    385395            return;
     
    388398            //lout << ddev(MLog::eGui);
    389399            gLog << inf2 << "- " << GetNodeName() << ": Relative positioning started." << endl;
     400            fPosActive = kTRUE; // Make sure that the status is set correctly already before the first PDO
    390401            //lout << edev(MLog::eGui);
    391402            return;
     
    428439    gLog << inf2 << "- " << GetNodeName() << ": Starting Node." << endl;
    429440    SendSDO(0x1000, 1, (LWORD_t)1);
     441    WaitForSdo(0x1000, 1);
     442}
     443
     444void Macs::Arm()
     445{
     446    StartNode();
     447}
     448
     449void Macs::Disarm()
     450{
     451    gLog << inf2 << "- " << GetNodeName() << ": Stopping Node." << endl;
     452    SendSDO(0x1000, 1, (LWORD_t)0);
    430453    WaitForSdo(0x1000, 1);
    431454}
     
    490513    //StartHostGuarding();
    491514
    492     StartNode();
     515    // REMOVE THIS AND LET CC START THE NODE
     516    //StartNode();
     517
     518    gLog << inf2 << "- " << GetNodeName() << ": Checking armed status." << endl;
     519    RequestSDO(0x1000, 1);
     520    WaitForSdo(0x1000, 1);
    493521}
    494522/*
     
    571599void Macs::SetVelocity(LWORD_t vel)
    572600{
     601    gLog << dbg << "- Setting velocity to: " << vel << endl;
    573602    SendSDO(0x2002, vel);     // velocity
    574603    WaitForSdo(0x2002, 0);
    575     cout << "SET VEL: " << vel << endl;
    576604}
    577605
    578606void Macs::SetAcceleration(LWORD_t acc)
    579607{
     608    gLog << dbg << "- Setting acceleration to: " << vel << endl;
    580609    SendSDO(0x2003, 0, acc);  // acceleration
    581610    WaitForSdo(0x2003, 0);
    582     cout << "SET ACC: " << acc << endl;
    583611}
    584612
    585613void Macs::SetDeceleration(LWORD_t dec)
    586614{
    587     SendSDO(0x2003, 1, dec);  // acceleration
     615    gLog << dbg << "- Setting deceleration to: " << vel << endl;
     616    SendSDO(0x2003, 1, dec);
    588617    WaitForSdo(0x2003, 1);
    589     cout << "SET DEC: " << dec << endl;
    590618}
    591619
     
    607635void Macs::StartRelPos(LWORDS_t pos)
    608636{
     637    if (!fIsArmed)
     638    {
     639        gLog << err << GetNodeName() << ": ERROR - Moving without being armed is not allowed." << endl;
     640        return;
     641    }
     642
     643    gLog << dbg << GetNodeName() << ": Starting abolsute positioning to " << (LWORD_t)pos << " ticks." << endl;
    609644    SendSDO(0x6004, 1, (LWORD_t)pos);
    610     cout << "REL POS: " << (LWORD_t)pos << endl;
     645    fPosActive = kTRUE; // Make sure that the status is set correctly already before the first PDO
    611646}
    612647
    613648void Macs::StartAbsPos(LWORDS_t pos)
    614649{
     650    if (!fIsArmed)
     651    {
     652        gLog << err << GetNodeName() << ": ERROR - Moving without being armed is not allowed." << endl;
     653        return;
     654    }
     655    gLog << dbg << GetNodeName() << ": Starting relative positioning by " << (LWORD_t)pos << " ticks." << endl;
    615656    SendSDO(0x6004, 0, (LWORD_t)pos);
    616     cout << "ABS POS: " << (LWORD_t)pos << endl;
     657    fPosActive = kTRUE; // Make sure that the status is set correctly already before the first PDO
    617658}
    618659
     
    681722    fInControl = data[3]&0x40; // motor uncontrolled
    682723              // data[3]&0x80; // axis resetted (after errclr, motor stop, motor on)
     724
     725    fArmed     = data[2]&kIsArmed==kIsArmed;
    683726
    684727    fStatus = data[3];
  • trunk/MagicSoft/Cosy/devdrv/macs.h

    r8864 r8865  
    3434
    3535    BYTE_t   fStatusPdo3;
     36
     37    bool fArmed;
    3638
    3739    void Init();
     
    7375    enum
    7476    {
     77        kIsArmed   = BIT(0),    // Macs will accept movement commands
    7578        kNotMoving = BIT(0),    // motor not moving
    7679        kPosActive = BIT(1),    // positioning active
     
    121124    void StartNode();
    122125
     126    bool IsArmed() const { return fArmed; }
     127    void Arm();
     128    void Disarm();
     129
    123130    int IsPositioning() const { return fPosActive; }
    124131    BYTE_t GetStatus() const { return fStatus; }
  • trunk/MagicSoft/Cosy/gui/MGCosy.cc

    r8864 r8865  
    5858    kPB_TPOINT,
    5959    kPB_ENDSWITCH,
     60    kPB_ARM,
    6061    kPB_START,
    6162    kPB_DISPLAY1,
     
    529530
    530531#ifdef EXPERT
     532    but = new TGTextButton(tf1, "Arm", kPB_ARM);
     533    but->MoveResize(204, 213, 62, 25);
     534    but->SetToolTipText("Arm the telescop (allow for movement).");
     535    but->Associate(this);
     536    fList->Add(but);
     537
     538    ULong_t col;
     539    gClient->GetColorByName("Magenta", col);
     540    but->SetBackgroundColor(col);
     541
    531542    but= new TGTextButton(tf1, "New Position",  kPB_SavePreDef);
    532543    but->MoveResize(165, 197, 80, 25);
     
    554565
    555566    but = new TGTextButton(tf4, "Load", kPB_LoadBending);
    556     but->ResizeMove(151, 185, 50, 25);
     567    but->MoveResize(151, 185, 50, 25);
    557568    but->SetToolTipText("Load bending corrections from file 'bending.txt'");
    558569    but->Associate(this);
     
    10301041
    10311042void MGCosy::Update(ZdAz pos, ZdAz acc, ZdAz vel, /*ZdAz off,*/ RaDec radec,
    1032                     ZdAz soll, UInt_t stat, UInt_t stat2)
     1043                    ZdAz soll, UInt_t stat, UInt_t stat2, Bool_t armed)
    10331044{
    10341045    // acc [rad]
     
    10581069    SetLabelColor(fAvailSe3,  stat2&0x20);
    10591070
    1060     EnableLabel(fArmed, 1);//stat2&0x40);
     1071    EnableLabel(fArmed, armed);//stat2&0x40);
    10611072
    10621073    if (stat&MDriveCom::kTracking)
     
    15021513                StartTrackPos();
    15031514                return kTRUE;
     1515            case kPB_ARM:
     1516                fQueue->PostMsg(WM_ARM);
     1517                return kTRUE;
    15041518            case kPB_DISPLAY1:
    15051519            case kPB_DISPLAY2:
  • trunk/MagicSoft/Cosy/gui/MGCosy.h

    r8820 r8865  
    137137    MGImage    *GetImage()     { return fImage; }
    138138
    139     void Update(ZdAz pos, ZdAz acc, ZdAz vel, /*ZdAz off,*/ RaDec radec, ZdAz soll, UInt_t stat, UInt_t stat2);
     139    void Update(ZdAz pos, ZdAz acc, ZdAz vel, /*ZdAz off,*/ RaDec radec, ZdAz soll, UInt_t stat, UInt_t stat2, Bool_t armed);
    140140    void UpdateWeather(const MCeCoCom &com);
    141141
  • trunk/MagicSoft/Cosy/main/MCosy.cc

    r8864 r8865  
    406406
    407407//#ifdef EXPERT
    408 //    point.SetAccDec(0.4, 0.4);
    409 //    point.SetVelocity(0.2); // fast: 0.6, slow: 0.2
     408    //point.SetPointAccDec(0.3, 0.3);
     409    //point.SetPointVelocity(0.3);
    410410//#else
    411411
     
    413413//
    414414    point.SetPointAccDec(0.2, 0.1);
    415 
    416415    point.SetPointVelocity(0.1);
    417416
    418417
    419418//#endif
    420 
    421 //    point.SetPointAccDec(0.4, 0.4);
    422 //    point.SetPointVelocity(0.4);
    423 
    424419
    425420// original
     
    428423// test
    429424//    return point.SetPosition(dst, kTRUE);
    430 
    431 
    432 
    433425}
    434426
     
    565557        fMac1->HandleError();
    566558        fMac2->HandleError();
    567         if (fMac3)
    568             fMac3->HandleError();
     559        //if (fMac3)
     560        //    fMac3->HandleError();
    569561        if (HasError() || HasZombie())
    570562            return false;
     
    700692        //cout << "WM_TrackPosition: done. (return 0xabcd)" << endl;
    701693        return 0xabcd;
    702 /*
     694
    703695    case WM_ARM:
    704696        //cout << "WM_Position: start." << endl;
    705697        {
    706698            if (!CheckNetwork())
    707                 return (void*)0xebb0;
    708 
    709             const bool arm = *((bool*)mp);
    710             if (arm)
    711             {
     699                return 0xebb0;
     700
     701            //const bool arm = *((bool*)mp);
     702            //if (arm)
     703            //{
    712704                fMac1->Arm();
    713705                fMac2->Arm();
    714                 cout << "ARMED" << endl;
    715             }
    716             else
    717             {
    718                 fMac1->Disarm();
    719                 fMac2->Disarm();
    720                 cout << "DISARMED" << endl;
    721             }
     706                //cout << "ARMED" << endl;
     707            //}
     708            //else
     709            //{
     710            //    fMac1->Disarm();
     711            //    fMac2->Disarm();
     712                //cout << "DISARMED" << endl;
     713            //}
    722714        }
    723715        //cout << "WM_Position: done. (return 0x7777)" << endl;
    724         return (void*)0x9999;
    725   */
     716        return 0x9999;
     717
    726718    case WM_POSITION:
    727719        //cout << "WM_Position: start." << endl;
     
    963955    Bool_t mac1 = fMac1 && !fMac1->IsZombieNode();
    964956    Bool_t mac2 = fMac2 && !fMac2->IsZombieNode();
    965     Bool_t mac3 = fMac3 && !fMac3->IsZombieNode();
     957    //Bool_t mac3 = fMac3 && !fMac3->IsZombieNode();
    966958
    967959    Bool_t zd1  = fZd1  && !fZd1->IsZombieNode();
     
    971963    Double_t x = 0;
    972964    Double_t y = 0;
    973     y = mac1 ? fMac1->GetRes() : (mac3 ? fMac3->GetRes() : env.GetValue("Az_ResRE[re/U_mot]", 1500));
     965//    y = mac1 ? fMac1->GetRes() : (mac3 ? fMac3->GetRes() : env.GetValue("Az_ResRE[re/U_mot]", 1500));
     966    y = mac1 ? fMac1->GetRes() : env.GetValue("Az_ResRE[re/U_mot]", 1500);
    974967    x = mac2 ? fMac2->GetRes() : env.GetValue("Zd_ResRE[re/U_mot]", 1500);
    975968    kResRE.Set(x,y);
     
    12781271    avail |= (fMac1 && !fMac1->IsZombieNode()) ? 0x01 : 0;
    12791272    avail |= (fMac2 && !fMac2->IsZombieNode()) ? 0x02 : 0;
    1280     avail |= (fMac3 && !fMac3->IsZombieNode()) ? 0x04 : 0;
     1273    //avail |= (fMac3 && !fMac3->IsZombieNode()) ? 0x04 : 0;
    12811274    avail |= (fZd1  && !fZd1->IsZombieNode())  ? 0x08 : 0;
    12821275    avail |= (fZd2  && !fZd2->IsZombieNode())  ? 0x10 : 0;
     
    12841277//    avail |= (!(fStatus&MDriveCom::kError) && 1 ? 0x40 : 0;
    12851278
     1279    Bool_t armed = kTRUE;
     1280
     1281    armed &= fMac1 && fMac1->IsArmed();
     1282    armed &= fMac2 && fMac2->IsArmed();
     1283
    12861284    if (HasError())
    12871285        SetStatus(MDriveCom::kError);
     
    12961294    fWin->UpdateWeather(*fCom);
    12971295    fWin->Update(bendist, fTrackingError, fVelocity, /*fOffset,*/
    1298                  fRaDec, fZdAzSoll, fStatus, avail);
     1296                 fRaDec, fZdAzSoll, fStatus, avail, armed);
    12991297
    13001298    gLog.UpdateGui();
     
    14971495    fMac1=new Macs(id1, "Mac/Az");
    14981496    fMac2=new Macs(id3, "Mac/Zd");
    1499     if (id2>=0)
    1500         fMac3=new Macs(id2, "Mac/Az-Sync");
     1497    //if (id2>=0)
     1498    //    fMac3=new Macs(id2, "Mac/Az-Sync");
    15011499
    15021500    fZd1=new ShaftEncoder(id4, "SE/Zd1");
     
    15191517    SetNode(fMac1);
    15201518    SetNode(fMac2);
    1521     if (id2>=0)
    1522         SetNode(fMac3);
     1519    //if (id2>=0)
     1520    //    SetNode(fMac3);
    15231521    SetNode(fZd1);
    15241522    SetNode(fZd2);
     
    16181616MCosy::MCosy(MEnv &env, const char *addr, const char *pointing)
    16191617: Network(), fObservatory(MObservatory::kMagic1), fStarguider(NULL),
    1620 fZd1(0), fZd2(0), fAz(0), fMac1(0), fMac2(0), fMac3(0),
     1618fZd1(0), fZd2(0), fAz(0), fMac1(0), fMac2(0), /*fMac3(0),*/
    16211619fBackground(kBgdNone), fTriggerDisplay(kFALSE), fStatus(MDriveCom::kStopped),
    16221620fOutTp(0), fOutRep(0)
     
    17211719    delete fMac1;
    17221720    delete fMac2;
    1723     if (fMac3)
    1724         delete fMac3;
     1721    //if (fMac3)
     1722    //    delete fMac3;
    17251723
    17261724    gLog << inf2 << "Deleting MGCosy." << endl;
  • trunk/MagicSoft/Cosy/main/MCosy.h

    r8862 r8865  
    8787    Macs *fMac1;
    8888    Macs *fMac2;
    89     Macs *fMac3;
     89    //Macs *fMac3;
    9090
    9191    MGCosy    *fWin;
  • trunk/MagicSoft/Cosy/tcpip/MTcpIpIO.cc

    r8864 r8865  
    1212
    1313#include "MString.h"
     14#include "MTimeout.h"
    1415
    1516#undef DEBUG
     
    8485    }
    8586
    86     const Int_t l = tx.SendRaw(msg, len);
    87     if (l<0)
    88     {
    89         gLog << err << "ERROR - Sending TCP/IP frame to " << GetSocketAddress(tx) << endl;
    90         return false;
    91     }
    92 
    93     if (l!=len)
    94     {
    95         gLog << err << "ERROR - Sent wrong number (" << l << ") of bytes to " << GetSocketAddress(tx) << endl;
    96         return false;
    97     }
    98 
    9987#ifdef DEBUG
    10088    cout << "Tx: " << msg << flush;
    10189#endif
     90
     91    const Int_t l = tx.SendRaw(msg, len);
     92    if (l<0)
     93    {
     94        gLog << err << "ERROR - Sending TCP/IP frame to " << GetSocketAddress(tx) << endl;
     95        return false;
     96    }
     97
     98    if (l!=len)
     99    {
     100        gLog << err << "ERROR - Sent wrong number (" << l << ") of bytes to " << GetSocketAddress(tx) << endl;
     101        return false;
     102    }
    102103
    103104    return true;
     
    164165        const Int_t len = rx.RecvRaw(&c, 1);
    165166
    166         // No data received (non-blocking mode)
    167         if (len<0)
    168         {
    169             usleep(1);
    170             continue;
    171         }
    172 
    173         // Data received with zero length! (Connection lost)
    174         if (len==0)
    175             return kFALSE; // This break is for TEST PURPOSE FIXME!!!
     167        // For details see TSocket::RecvRaw
     168        // -1: // ERROR
     169        // EINVAL, EWOULDBLOCK
     170        // -5: // EPIPE || ECONNRESET = Pipe broken or connection reset by peer
     171        //  0: Data received with zero length! (Connection lost/call interrupted)
     172        if (len<=0)
     173            return kFALSE;
    176174
    177175        // Data received
     
    208206    fConnectionEstablished = kTRUE;
    209207
     208    MTimeout timeout;
     209
    210210    // Get connection on port fPortRx and redirected
    211211    while (!IsThreadCanceled())
     
    220220                return kFALSE;
    221221            }
    222 
    223             // *FALLTHROUGH*
     222            timeout.Start(fTimeout);
     223
     224            // Go on waiting for new data
     225            continue;
     226
    224227        case kFALSE: // Time out, no data yet, go on waiting
     228            if (timeout.HasTimedOut())
     229            {
     230                gLog << warn << "WARNING - Connection to " << MTcpIpO::GetSocketAddress(sock) << " timed out." << endl;
     231                return kFALSE;
     232            }
    225233
    226234            // Go on waiting for new data
     
    248256        while (!IsThreadCanceled())
    249257        {
     258            // Wait for a new connection on RX port
    250259            socket = server.Accept();
    251260
     
    271280        if ((Long_t)socket<=0)
    272281            return;
     282
     283        gLog << all << "Connection established to " << MTcpIpO::GetSocketAddress(*socket) << "..." << endl;
    273284
    274285        if (!WaitForData(*socket))
  • trunk/MagicSoft/Cosy/tcpip/MTcpIpIO.h

    r8864 r8865  
    1818{
    1919private:
    20     Int_t  fPortRx;
     20    Int_t  fPortRx;     // Port on which to listen for connections
     21    Int_t  fTimeout;    // [ms] Timeout to listen for data to be received
     22
    2123    Bool_t fConnectionEstablished;
    2224
     
    2931
    3032public:
    31     MTcpIpI(Int_t rx) : MThread(Form("MTcpIpI::%d", rx)), fPortRx(rx), fConnectionEstablished(kFALSE) { /*RunThread();*/ }
     33    MTcpIpI(Int_t rx, UInt_t timeout=5000) : MThread(Form("MTcpIpI::%d", rx)), fPortRx(rx), fTimeout(timeout), fConnectionEstablished(kFALSE) { /*RunThread();*/ }
    3234    ~MTcpIpI() { CancelThread(); }
    3335
Note: See TracChangeset for help on using the changeset viewer.