Changeset 1727 for trunk/MagicSoft/Cosy


Ignore:
Timestamp:
01/23/03 13:32:58 (22 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Cosy
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Cosy/Changelog

    r1703 r1727  
    11                                                                  -*-*- END -*-*-
     2
     3 2003/01/23 - Thomas Bretz:
     4 
     5   * cosy.cc:
     6     - changed baudrate to 125kbps
     7   
     8   * base/msgqueue.cc:
     9     - changed output
     10     - ignore pending messages
     11   
     12   * candrv/canopen.[h,cc]:
     13     - added Emergency Message
     14     - added EnableNodeguard
     15     - added SendNodeguard
     16     
     17   * candrv/network.[h,cc]:
     18     - call handles only if Fnodes[node]!=NULL
     19     - added time to HandleSDOOK
     20     - changed output
     21     - added HandleNodeguard
     22     - added HandleEmergency
     23
     24   * candrv/nodedrv.[h,cc]:
     25     - added fTimeout for Nodeguarding
     26     - Enable Nodeguard and Emergency messages
     27     - added time to HandleSDOOK
     28     - added SendNodeguard
     29     - added StartGuarding
     30     - added StopGuarding
     31     - added HandleTimer
     32     - added HandleNodeguard
     33     - added SetZombie
     34
     35   * candrv/vmodican.[h,cc]:
     36     - fixed a typo
     37     - added rtr to SendCanFrame
     38   
     39   * devdrv/macs.[h,cc]:
     40     - removed guarding stuff (moved to nodedrv)
     41     - changed 0x4000 handling to 0.63 style
     42     - added check for software version
     43     - added time to HandleSDOOk
     44     - set node to Zombie in case of error
     45     - don't do any error handling for the moment
     46     - removed ReqTimeoutTime
     47     - overload SendNodeguard
     48     - removed EnableTimeout
     49     - removed HandleTimer
     50     - removed ResetTimeout
     51     - added Start/StopHostGuarding
     52
     53   * devdrv/shaftencoder.[h,cc]:
     54     - added 0x100c, 0x100d, 0x100e
     55     - added Start/StopGuarding to Init
     56
     57   * gui/MGCosy.cc:
     58     - enhanced labels for Offset
     59     - changed 'soll' to 'nominal'
     60     - changed the demo mode for tests
     61   
     62   * gui/MGSkyPosition.[h,cc]:
     63     - added saturn
     64     - changed the colors a bit
     65
     66
     67
     68 2003/01/20 - Thomas Bretz:
     69
     70   * aposs/Manual.m
     71     - added support for the elevation axis brake
     72     - enabled check for operation mode (remote control/pc)     
     73     - added 'reset' label                                       
     74     - moved syncv/cstart to setting rf                         
     75
     76
     77
    278 2003/01/14 - Thomas Bretz:
    379
  • trunk/MagicSoft/Cosy/base/msgqueue.cc

    r1275 r1727  
    7777    while(1)
    7878    {
    79         while (!fStart) usleep(1);
     79        while (!fStart)
     80            usleep(1);
    8081        fStart = 0;
    8182
     
    8889        pthread_mutex_unlock(&fMuxMsg);
    8990
    90         cout << "Processing Msg 0x" << hex << fMsg << endl;
     91        cout << "MsgQueue::Thread: Processing Msg 0x" << hex << fMsg << endl;
    9192        // --- bool quit = fMsg==WM_QUIT;
    9293        fRc=Proc(fMsg, fMp);
    93         cout << "Msg 0x" << hex << fMsg << " processed." << endl;
     94        cout << "MsgQueue::PostMsg: Msg 0x" << hex << fMsg << " processed (rc=" << fRc << ")" << endl;
    9495
    9596        // --- if (quit)
     
    118119    // stopped and the messages are processed serialized
    119120    //
    120     cout << "Locking MsgQueue mutex..." << flush;
     121    cout << "MsgQueue::PostMsg: Locking MsgQueue mutex..." << flush;
    121122    pthread_mutex_lock(&fMuxMsg);
    122123    cout << "done." << endl;
     
    129130    // This is some kind of controlled user break without using signals
    130131    //
     132    /**** NEW 20/01/2003 ****/
     133    if (fBreak)
     134    {
     135        pthread_mutex_unlock(&fMuxMsg);
     136        cout << "------------> MsgQueue::PostMsg: Proc still pending... Message IGNORED." << endl;
     137        return NULL;
     138    }
     139    /**** NEW 20/01/2003 ****/
     140    cout << "MsgQueue::PostMsg: ---> Break <---" << endl;
    131141    fBreak = 1;
    132142
     
    146156    // Start Proc()
    147157    //
     158    cout << "MsgQueue::PostMsg: Releasing MsgQueue mutex..." << flush;
    148159    fStart = 1;
    149     cout << "Releasing MsgQueue mutex..." << flush;
    150160    pthread_mutex_unlock(&fMuxMsg);
    151161    cout << "done." << endl;
    152     while (fStart)
    153         usleep(1);
    154 
    155     cout << "Returning rc = 0x" << hex << rc << endl;
     162
     163    /*
     164     * **** NEW 20/01/2003 ***
     165     *
     166     * This can halt the main thread, because it is waiting until
     167     * Proc has finished its execution which can take a while
     168     *
     169     * A side effect is, because you don't wait for the end of
     170     * the execution of Proc, if a new message is posted fBreak
     171     * and fStart is set again, new values are copied to fMsg and
     172     * fMp (FIXME? Harmefull?) and the message is not processed at all.
     173     */
     174    //while (fStart)
     175    //    usleep(1);
     176 
     177    cout << "MsgQueue::PostMsg: Returning rc = " << hex << rc << endl;
    156178    return rc;
    157179}
    158 
     180/*
     181Start positioning.
     182MsgQueue::PostMsg: Locking MsgQueue mutex...done.
     183MsgQueue::PostMsg: ---> Break <---
     184+++++ MsgQueue::PostMsg: Releasing MsgQueue mutex...done.
     185
     186===== MsgQueue::PostMsg: Returning rc = (nil)
     187PostMsg (WM_Position) returned.
     188done.
     189Stopping movement...Movement stopped.
     190WM_Position: done. (return 0x7777)
     191MsgQueue::PostMsg: Msg 0x1001 processed (rc=0x7777)
     192MsgQueue::Thread: Processing Msg 0x1001
     193WM_Position: start.
     194Positioning to Target...
     195 */
     196/*
     197Start positioning.
     198MsgQueue::PostMsg: Locking MsgQueue mutex...done.
     199MsgQueue::PostMsg: ---> Break <---
     200+++++ MsgQueue::PostMsg: Releasing MsgQueue mutex...done.
     201
     202done.
     203Stopping movement...Movement stopped.
     204WM_Position: done. (return 0x7777)
     205MsgQueue::PostMsg: Msg 0x1001 processed (rc=0x7777)
     206MsgQueue::Thread: Processing Msg 0x1001
     207WM_Position: start.
     208Positioning to Target...
     209===== MsgQueue::PostMsg: Returning rc = (nil)
     210*/
  • trunk/MagicSoft/Cosy/candrv/canopen.cc

    r1275 r1727  
    1616!
    1717!
    18 !   Author(s): Thomas Bretz <mailto:tbretz@uni-sw.gwdg.de>, 2001
    19 !
    20 !   Copyright: MAGIC Software Development, 2000-2001
     18!   Author(s): Thomas Bretz <mailto:tbretz@astro.uni-wuerzburg.de>, 2003
     19!
     20!   Copyright: MAGIC Software Development, 2000-2003
    2121!
    2222!
     
    8484{
    8585    const WORD_t fcode = cobid >> 7;
     86    const BYTE_t  node = cobid & 0x1f;
    8687
    8788    switch (fcode)
     
    9495        return;
    9596
    96     case kSYNC:
    97         cout << "Sync" << endl;
     97    case kEMERGENCY: // also case kSYNC:
     98        if (cobid==0)
     99            cout << "Sync" << endl;
     100        else
     101        {
     102            cout << "EMERGENCY Node #" << dec << (int)data[1] << endl;
     103            HandleEmergency(node, tv);
     104        }
     105        return;
     106
     107    case kNodeguard:
     108        //cout << "Nodeguard Node #" << dec << (int)node << endl;
     109        HandleNodeguard(node, tv);
    98110        return;
    99111
    100112    case kSDO_RX:
    101113        {
    102             const BYTE_t  node   = cobid & 0x1f;
    103114            const BYTE_t  cmd    = data[0];
    104115            const LWORD_t dat    = data[4] | (data[5]<<8) | (data[6]<<16) | (data[7]<<24);
     
    114125    case kPDO1_TX:
    115126        {
    116             const BYTE_t node = cobid & 0x1f;
    117127            HandlePDO1(node, data, tv);
    118128            pthread_cond_broadcast(&fPdoCond[node-1][0]);
     
    122132    case kPDO2_TX:
    123133        {
    124             const BYTE_t node = cobid & 0x1f;
    125134            HandlePDO2(node, data, tv);
    126135            pthread_cond_broadcast(&fPdoCond[node-1][1]);
     
    130139    case kPDO3_TX:
    131140        {
    132             const BYTE_t node = cobid & 0x1f;
    133141            HandlePDO3(node, data, tv);
    134142            pthread_cond_broadcast(&fPdoCond[node-1][2]);
     
    138146    case kPDO4_TX:
    139147        {
    140             const BYTE_t node = cobid & 0x1f;
    141148            HandlePDO4(node, data, tv);
    142149            pthread_cond_broadcast(&fPdoCond[node-1][3]);
     
    145152    }
    146153
    147     const BYTE_t node = cobid & 0x1f;
    148     cout << "Function Code: 0x" << hex << fcode << "  Node: " << dec << (int)node << endl;
     154    cout << "CanOpen::HandleCanMessage - Unhandled Message: Function Code=0x" << hex << fcode << "  Node #" << dec << (int)node << endl;
    149155}
    150156
     
    168174{
    169175    EnableCanMsg(node, kEMERGENCY);
     176}
     177
     178// --------------------------------------------------------------------------
     179//
     180// Enables Nodeguard messages for a given node
     181//
     182void CanOpen::EnableNodeguard(BYTE_t node)
     183{
     184    EnableCanMsg(node, kNodeguard);
    170185}
    171186
     
    372387// --------------------------------------------------------------------------
    373388//
    374 // Send an NMT Message to the given node with command cmd
     389// Send a NMT Message to the given node with command cmd
    375390//
    376391void CanOpen::SendNMT(BYTE_t node, BYTE_t cmd)
     
    381396// --------------------------------------------------------------------------
    382397//
     398// Send a Nodeguard Message to the given node with command cmd
     399//
     400void CanOpen::SendNodeguard(BYTE_t node)
     401{
     402    BYTE_t msg[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
     403    SendCanFrame(CobId(node, kNodeguard), msg, 1);
     404}
     405
     406// --------------------------------------------------------------------------
     407//
    383408// Decodes node and function code into a CobId
    384409//
  • trunk/MagicSoft/Cosy/candrv/network.cc

    r1703 r1727  
    8989void Network::HandleSDO(BYTE_t node, BYTE_t cmd, WORD_t idx, BYTE_t subidx, LWORD_t data, timeval_t *tv)
    9090{
    91     switch (cmd)
    92     {
    93     case kSDO_TX4:       // answer to 0x40 with 4 bytes of data
    94         if (fNodes[node])
     91    if (fNodes[node])
     92        switch (cmd)
    9593        {
     94        case kSDO_TX4:       // answer to 0x40 with 4 bytes of data
    9695            fNodes[node]->HandleSDO(idx, subidx, data, tv);
    9796            return;
     97
     98        case kSDO_TX3:       // answer to 0x40 with 2 bytes of data
     99            fNodes[node]->HandleSDO(idx, subidx, data>>16, tv);
     100            return;
     101
     102        case kSDO_TX1:       // answer to 0x40 with 1 byte  of data
     103            fNodes[node]->HandleSDO(idx, subidx, data>>24, tv);
     104            return;
     105
     106        case kSDO_TX_OK:     // answer to a SDO_TX message
     107            fNodes[node]->HandleSDOOK(idx, subidx, tv);
     108            return;
     109
     110        case kSDO_TX_ERROR:  // error message (instead of 0x60)
     111            fNodes[node]->HandleSDOError(data);
     112            return;
    98113        }
    99         break;
    100 
    101     case kSDO_TX3:       // answer to 0x40 with 2 bytes of data
    102         if (fNodes[node])
    103         {
    104             fNodes[node]->HandleSDO(idx, subidx, data>>16, tv);
    105             return;
    106         }
    107         break;
    108 
    109     case kSDO_TX1:       // answer to 0x40 with 1 byte  of data
    110         if (fNodes[node])
    111         {
    112             fNodes[node]->HandleSDO(idx, subidx, data>>24, tv);
    113             return;
    114         }
    115         break;
    116 
    117     case kSDO_TX_OK:     // answer to a SDO_TX message
    118         if (fNodes[node])
    119         {
    120             fNodes[node]->HandleSDOOK(idx, subidx);
    121             return;
    122         }
    123         break;
    124 
    125     case kSDO_TX_ERROR:  // error message (instead of 0x60)
    126         if (fNodes[node])
    127         {
    128             fNodes[node]->HandleSDOError(data);
    129             return;
    130         }
    131         break;
    132     }
     114
    133115    cout << dec << setfill('0');
    134     cout << "Node=" << (int)node  << " Cmd=0x" << hex << (int)cmd << ": ";
     116    cout << "Network::HandleSDO: Node=" << (int)node  << " Cmd=0x" << hex << (int)cmd << ": ";
    135117    cout << "Sdo=" << idx  << "/" << (int)subidx << ": 0x" << setw(8) << data;
    136118    cout << endl;
     
    145127    if (!fNodes[node])
    146128    {
    147         cout << "Node " << dec << (int)node << ", PDO1: " << hex;
     129        cout << "Network::HandlePDO1: Node #" << dec << (int)node << " not found - PDO1: " << hex;
    148130        for (int i=0; i<8; i++)
    149131            cout << " 0x" << (int)data[i];
     
    163145    if (!fNodes[node])
    164146    {
    165         cout << "Node " << dec << (int)node << ", PDO2: " << hex;
     147        cout << "Network::HandlePDO2: Node #" << dec << (int)node << " not found - PDO2: " << hex;
    166148        for (int i=0; i<8; i++)
    167149            cout << " 0x" << (int)data[i];
     
    181163    if (!fNodes[node])
    182164    {
    183         cout << "Node " << dec << (int)node << ", PDO3: " << hex;
     165        cout << "Network::HandlePDO3: Node #" << dec << (int)node << " not found - PDO3: " << hex;
    184166        for (int i=0; i<8; i++)
    185167            cout << " 0x" << (int)data[i];
     
    199181    if (!fNodes[node])
    200182    {
    201         cout << "Node " << dec << (int)node << ", PDO4: " << hex;
     183        cout << "Network::HandlePDO4: Node #" << dec << (int)node << " not found - PDO4: " << hex;
    202184        for (int i=0; i<8; i++)
    203185            cout << " 0x" << (int)data[i];
     
    208190    fNodes[node]->HandlePDO4(data, tv);
    209191}
     192
     193// --------------------------------------------------------------------------
     194//
     195// Distributes Nodeguard messages to the correspoding node calling
     196// HandleNodeguard
     197//
     198void Network::HandleNodeguard(BYTE_t node, timeval_t *tv)
     199{
     200    if (!fNodes[node])
     201    {
     202        cout << "Network::HandleNodeguard: Node #" << dec << (int)node << " not found: Nodeguard." << endl;
     203        return;
     204    }
     205
     206    fNodes[node]->HandleNodeguard(tv);
     207}
     208
     209// --------------------------------------------------------------------------
     210//
     211// Distributes Emergency messages to the correspoding node calling
     212// HandleEmergency
     213//
     214void Network::HandleEmergency(BYTE_t node, timeval_t *tv)
     215{
     216    if (!fNodes[node])
     217    {
     218        cout << "Network::HandleEmergency: Node #" << dec << (int)node << " not found: Emergency." << endl;
     219        return;
     220    }
     221
     222    fNodes[node]->HandleEmergency(tv);
     223}
     224
    210225
    211226// --------------------------------------------------------------------------
     
    281296            continue;
    282297
    283         lout << "- Node #" << dec << i << " '" << fNodes[i]->GetNodeName();
    284         lout << "' has error #" << fNodes[i]->GetError() << endl;
     298        //lout << "- Node #" << dec << i << " '" << fNodes[i]->GetNodeName();
     299        //lout << "' has error #" << fNodes[i]->GetError() << endl;
    285300    }
    286301
  • trunk/MagicSoft/Cosy/candrv/network.h

    r1703 r1727  
    1616    void HandlePDO3(BYTE_t node, BYTE_t *data, timeval_t *tv);
    1717    void HandlePDO4(BYTE_t node, BYTE_t *data, timeval_t *tv);
     18    void HandleNodeguard(BYTE_t node, timeval_t *tv);
     19    void HandleEmergency(BYTE_t node, timeval_t *tv);
    1820
    1921    void InitNodes();
  • trunk/MagicSoft/Cosy/candrv/nodedrv.cc

    r1703 r1727  
    3333//  virtual void StopDevice()
    3434//  virtual void HandleSDO(WORD_t idx, BYTE_t subidx, LWORD_t val, timeval_t *tv)
    35 //  virtual void HandleSDOOK(WORD_t idx, BYTE_t subidx)
     35//  virtual void HandleSDOOK(WORD_t idx, BYTE_t subidx, timeval_t *tv)
    3636//  virtual void HandleSDOError(LWORD_t data)
    3737//  virtual void HandlePDO1(BYTE_t *data, timeval_t *tv)
     
    4848#include <iostream.h>
    4949
     50#include <TTimer.h>
     51
     52#include "base/timer.h"
    5053#include "network.h"
    5154#include "MLogManip.h"
     
    7679    }
    7780
     81    fTimerOn = kFALSE;
     82    fTimeout = new TTimer(this, 100, kFALSE); // 100ms, asynchronous
     83
    7884    lout << "- Node #" << (int)nodeid << " (" << name << ") initialized." << endl;
    79 }
    80 
    81 // --------------------------------------------------------------------------
    82 //
    83 // Empty destructor
     85
     86}
     87
     88// --------------------------------------------------------------------------
     89//
     90// destructor
    8491//
    8592NodeDrv::~NodeDrv()
    8693{
     94    fTimerOn = kFALSE;
     95    delete fTimeout;
    8796}
    8897
     
    122131    EnableCanMsg(kSDO_RX);
    123132    EnableCanMsg(kSDO_TX);
     133    EnableCanMsg(kNodeguard);
     134    EnableCanMsg(kEMERGENCY);
    124135
    125136    fIsZombie = kFALSE;
     
    135146// This output is never redirected to the GUI
    136147//
    137 void NodeDrv::HandleSDOOK(WORD_t idx, BYTE_t subidx)
     148void NodeDrv::HandleSDOOK(WORD_t idx, BYTE_t subidx, timeval_t *tv)
    138149{
    139150    const Bool_t gui = lout.IsOutputDeviceEnabled(MLog::eGui);
     
    367378// --------------------------------------------------------------------------
    368379//
    369 // Send an NMT message (command) to this device
     380// Send a NMT message (command) to this device
    370381//
    371382// The message is not send if the node has the status Zombie.
     
    377388        fNetwork->SendNMT(fId, cmd);
    378389    return !fIsZombie;
     390}
     391
     392// --------------------------------------------------------------------------
     393//
     394// Send a Nodeguard message (command) to this device
     395//
     396void NodeDrv::SendNodeguard()
     397{
     398    fNetwork->SendNodeguard(fId);
    379399}
    380400
     
    404424
    405425    if (!rc)
     426    {
     427        lout << "NodeDrv::WaitForSdo: 0x" << hex << idx << "/" << dec << (int)subidx << " " << GetNodeName() << " --> ZOMBIE!" << endl;
     428        SetZombie();
     429    }
     430/*
     431    if (HasError())
     432    {
     433        lout << "NodeDrv::WaitForSdo: HasError 0x" << hex << idx << "/" << dec << (int)subidx << " " << GetNodeName() << " --> ZOMBIE!" << endl;
    406434        fIsZombie = kTRUE;
    407 
     435    }
     436*/
    408437    return fIsZombie ? false : rc;
    409438}
     
    453482}
    454483
     484// --------------------------------------------------------------------------
     485//
     486// Start the standard CANopen guarding of the device.
     487// While ms is the guard time in millisec. This is the time between
     488// two requests for a Nodeguard message.
     489// ltf is the LifeTimeFactor. This means how often it is checked, that at
     490// least one Nodeguard message was answered.
     491//
     492void NodeDrv::StartGuarding()
     493{
     494    if (fTimerOn)
     495        return;
     496
     497    SendNodeguard();
     498
     499    fTimerOn = kTRUE;
     500    fTimeout->SetTime(fGuardTime);
     501    fTimeout->Reset();
     502    fTimeout->TurnOn();
     503    //fTimeout->Start(fGuardTime, kTRUE);
     504
     505    lout << "- " << GetNodeName() << ": Guarding (" << dec;
     506    lout << fLifeTimeFactor << "*" << fGuardTime << "ms) started." << endl;
     507}
     508
     509void NodeDrv::StartGuarding(Int_t ms, Int_t ltf)
     510{
     511    if (fTimerOn)
     512    {
     513        lout << "- " << GetNodeName() << ": ERROR - Guarding already started." << endl;
     514        return;
     515    }
     516    fGuardTime      = ms;
     517    fLifeTimeFactor = ltf;
     518
     519    StartGuarding();
     520}
     521
     522void NodeDrv::StopGuarding()
     523{
     524    fTimeout->TurnOff();
     525    fTimerOn = kFALSE;
     526
     527    lout << "- " << GetNodeName() << ": Guarding stopped." << endl;
     528}
     529
     530// --------------------------------------------------------------------------
     531//
     532// Handle the Nodeguard-Timer Event.
     533// It checks whether the node timed out. If it timed out it is set to
     534// the Zombie state.
     535// A new Nodeguard request is send and a new timer event is triggered.
     536//
     537Bool_t NodeDrv::HandleTimer(TTimer *t)
     538{
     539    //
     540    // WARNING:
     541    //           It seems, that you should never access ANY output from
     542    //           here. Neither the GUI, nor COUT. This can result in
     543    //           'unexpected async reply'
     544    //
     545
     546   /*
     547     Fons:
     548     -----
     549
     550     timers never trigger at the same time or when in a TTimer::Notify.
     551     Little explanation:
     552
     553     - there are two types of timers synchronous and a-synchronous.
     554     - synchronous timers are only handled via the ROOT eventloop
     555       (see TUnixSystem::DispatchOneEvent()). If there are no mouse/keyboard
     556       events then the synchronous timer queue is checked. So if the processing
     557       of a mouse/keyboard event takes a long time synchronous timers are not
     558       called for a while. To prevent this from happening one can call in long
     559       procedures gSystem->ProcessEvents(). The system schedules only the
     560       next timer in the queue when the current one's Notify() has finished.
     561     - a-synchronous timers are triggered via SIGALARM, i.e. the program is
     562       interupted and execution jumps to the Notify() function. When the
     563       notify is finished the next a-sync timer is scheduled and the system
     564       resumes from the place where it was initially interrupted. One of the
     565       things to remember when using a-sync timers is don't make any graphics
     566       calls in them. X11 is not re-entrant and it might be that the SIGALARM
     567       signal interrupted the system while being in X11. A-sync timers are best
     568       used to set flags that you can test at a convenient and controlled
     569       time.
     570       */
     571    if (fIsZombie)
     572        return kTRUE;
     573
     574    Timer time;
     575    Double_t now = time.Now();
     576    if (now > fTimeoutTime)
     577    {
     578        //cout << "ERROR - " << GetNodeName() << " didn't respond in timeout window." << endl;
     579        //lout << "ERROR - " << GetNodeName() << " didn't respond in timeout window." << endl;
     580        //cout << dec << "+" << (int)GetId() << ": Handle: " << fmod(now, 500) << endl;
     581        //cout << dec << "+" << (int)GetId() << ": Handle: " << fmod(fTimeoutTime, 500) << endl;
     582        //cout << fGuardTime << endl;
     583        fIsZombie = true;
     584        //SetZombie();
     585
     586        return kTRUE;
     587    }
     588
     589    SendNodeguard();
     590
     591    return kTRUE;
     592}
     593
     594// --------------------------------------------------------------------------
     595//
     596// Set the timeout timer to the time the event was received plus the
     597// guard time times lifetimefactor.
     598//
     599void NodeDrv::HandleNodeguard(timeval_t *tv)
     600{
     601    Timer t(tv);
     602    fTimeoutTime = t + (fGuardTime*fLifeTimeFactor/1000.);
     603}
     604
     605void NodeDrv::SetZombie()
     606{
     607    fIsZombie = true;
     608    StopGuarding();
     609}
  • trunk/MagicSoft/Cosy/candrv/nodedrv.h

    r1703 r1727  
    2020class Network;
    2121
    22 class NodeDrv : public Log
     22class NodeDrv : public Log, public TObject
    2323{
    2424private:
     
    3030    int fError;
    3131
     32    Bool_t fIsZombie; // A Zombie node is a node which doesn't answer...
     33
     34    TTimer  *fTimeout;
     35    Int_t    fGuardTime;      // Guardtime [ms]
     36    Int_t    fLifeTimeFactor;
     37    Double_t fTimeoutTime;
     38    Bool_t   fTimerOn;
     39
     40    Bool_t HandleTimer(TTimer *t);
     41
    3242protected:
    3343    void SetError(int err) { fError = err; }
    3444    void DelError()        { fError = 0; }
    3545
    36     Bool_t fIsZombie; // A Zombie node is a node which doesn't answer...
     46    Int_t GetLifeTimeFactor() const { return fLifeTimeFactor; }
     47    Int_t GetGuardTime() const      { return fGuardTime; }
     48
     49    virtual void SetZombie();
    3750
    3851public:
     
    5669
    5770    virtual void HandleSDO(WORD_t idx, BYTE_t subidx, LWORD_t val, timeval_t *tv);
    58     virtual void HandleSDOOK(WORD_t idx, BYTE_t subidx);
     71    virtual void HandleSDOOK(WORD_t idx, BYTE_t subidx, timeval_t *tv);
    5972    virtual void HandleSDOError(LWORD_t data);
    6073
    61     virtual void HandlePDO1(BYTE_t *data, timeval_t *tv) {};
    62     virtual void HandlePDO2(BYTE_t *data, timeval_t *tv) {};
    63     virtual void HandlePDO3(BYTE_t *data, timeval_t *tv) {};
    64     virtual void HandlePDO4(BYTE_t *data, timeval_t *tv) {};
     74    virtual void HandlePDO1(BYTE_t *data, timeval_t *tv) {}
     75    virtual void HandlePDO2(BYTE_t *data, timeval_t *tv) {}
     76    virtual void HandlePDO3(BYTE_t *data, timeval_t *tv) {}
     77    virtual void HandlePDO4(BYTE_t *data, timeval_t *tv) {}
     78    virtual void HandleNodeguard(timeval_t *tv);
     79    virtual void HandleEmergency(timeval_t *tv) {}
    6580
    6681    bool SendPDO1(BYTE_t data[8]);
     
    8095
    8196    bool SendNMT(BYTE_t cmd);
     97    virtual void SendNodeguard();
    8298
    8399    bool RequestSDO(WORD_t idx, BYTE_t subidx=0);
     
    93109    void EnableCanMsg(BYTE_t fcode);
    94110
     111    void StartGuarding();
     112    void StartGuarding(Int_t ms, Int_t ltf);
     113    void StopGuarding();
     114
    95115    ClassDef(NodeDrv, 0) // base class for an object describing hardware
    96116};
  • trunk/MagicSoft/Cosy/candrv/vmodican.cc

    r1703 r1727  
    409409    while (!Send(&msg));      /* transmitt to module */
    410410
    411     lout << "- Baudrate set to " << rate << "bps" << endl;
     411    lout << "- Baudrate set to " << rate << "kbps" << endl;
    412412}
    413413
     
    904904//   */
    905905//
    906 void VmodIcan::SendCanFrame(WORD_t cobid, BYTE_t m[8])
    907 {
    908     const WORD_t desc = MsgDescr(cobid, 8);
     906void VmodIcan::SendCanFrame(WORD_t cobid, BYTE_t m[8], BYTE_t rtr)
     907{
     908    const WORD_t desc = MsgDescr(cobid, 8, rtr);
    909909
    910910    Message msg;
  • trunk/MagicSoft/Cosy/candrv/vmodican.h

    r1140 r1727  
    7373    void EnableCobId(WORD_t cobid, int flag=TRUE);
    7474
    75     void SendCanFrame(WORD_t cobid, BYTE_t m[8]);
     75    void SendCanFrame(WORD_t cobid, BYTE_t m[8], BYTE_t rtr=0);
    7676    void SendCanFrame(WORD_t cobid,
    7777                      BYTE_t m0=0, BYTE_t m1=0, BYTE_t m2=0, BYTE_t m3=0,
  • trunk/MagicSoft/Cosy/cosy.cc

    r1703 r1727  
    7373        }
    7474
    75     MCosy *cosy = new MCosy(mode, "/dev/dpm_00", 500, lout);
     75    MCosy *cosy = new MCosy(mode, "/dev/dpm_00", 125, lout);
    7676
    7777    clog("- Starting MCosy.");
  • trunk/MagicSoft/Cosy/devdrv/macs.cc

    r1703 r1727  
    3333    fPosActive(0), fRpmActive(0)
    3434{
    35     fTimeout = new TTimer(this, 100, kFALSE); // 100ms, asynchronous
     35//    fTimeout = new TTimer(this, 100); //, kFALSE); // 100ms, asynchronous
    3636}
    3737
    3838Macs::~Macs()
    3939{
    40     fTimerOn = kFALSE;
    41     delete fTimeout;
     40    //fTimerOn = kFALSE;
     41  //  delete fTimeout;
    4242}
    4343
     
    6060        fVel = val;
    6161        return;
    62 
    63     case 0x4000:
    64         switch (subidx)
    65         {
    66         case 1:
    67             cout << GetNodeName() << ": Timeout timer is " << (val?"en":"dis") << "abled." << endl;
    68             return;
    69         case 2:
    70             cout << GetNodeName() << ": Actual timeout time: " << dec << val << "ms" << endl;
    71             return;
    72         }
    73         break;
    7462
    7563    case 0x6004:
     
    129117}
    130118
    131 void Macs::HandleSDOOK(WORD_t idx, BYTE_t subidx)
     119void Macs::HandleSDOOK(WORD_t idx, BYTE_t subidx, timeval_t *tv)
    132120{
    133121    switch (idx)
     
    137125        {
    138126        case 0:
    139             lout << ddev(MLog::eGui);
     127            //lout << ddev(MLog::eGui);
    140128            lout << "- " << GetNodeName() << ": Velocity set." << endl;
    141             lout << edev(MLog::eGui);
     129            //lout << edev(MLog::eGui);
    142130            return;
    143131        }
    144132        break;
     133
    145134    case 0x2003:
    146135        switch (subidx)
    147136        {
    148137        case 0:
    149             lout << ddev(MLog::eGui);
     138            //lout << ddev(MLog::eGui);
    150139            lout << "- " << GetNodeName() << ": Acceleration set." << endl;
    151             lout << edev(MLog::eGui);
     140            //lout << edev(MLog::eGui);
    152141            return;
    153142        case 1:
    154             lout << ddev(MLog::eGui);
     143            //lout << ddev(MLog::eGui);
    155144            lout << "- " << GetNodeName() << ": Decceleration set." << endl;
    156             lout << edev(MLog::eGui);
     145            //lout << edev(MLog::eGui);
    157146            return;
    158147        }
    159148        break;
     149
    160150    case 0x3006:
    161151        switch (subidx)
    162152        {
    163153        case 0:
    164             lout << ddev(MLog::eGui);
     154            //lout << ddev(MLog::eGui);
    165155            lout << "- " << GetNodeName() << ": RPM mode switched." << endl;
    166             lout << edev(MLog::eGui);
     156            //lout << edev(MLog::eGui);
    167157            return;
    168158
     
    176166        }
    177167        break;
     168
    178169    case 0x4000:
    179         if (subidx==0 && fTimerOn)
    180         {
    181             ResetTimeout();
    182             return;
    183         }
    184         break;
     170        HandleNodeguard(tv);
     171        return;
     172
    185173    case 0x6004:
    186174        switch (subidx)
    187175        {
    188176        case 0:
    189             lout << ddev(MLog::eGui);
     177            //lout << ddev(MLog::eGui);
    190178            lout << "- " << GetNodeName() << ": Absolute positioning started." << endl;
    191             lout << edev(MLog::eGui);
     179            //lout << edev(MLog::eGui);
    192180            return;
    193181
    194182        case 1:
    195             lout << ddev(MLog::eGui);
     183            //lout << ddev(MLog::eGui);
    196184            lout << "- " << GetNodeName() << ": Relative positioning started." << endl;
    197             lout << edev(MLog::eGui);
     185            //lout << edev(MLog::eGui);
    198186            return;
    199187        }
     
    202190
    203191    }
    204     NodeDrv::HandleSDOOK(idx, subidx);
     192    NodeDrv::HandleSDOOK(idx, subidx, tv);
    205193}
    206194
     
    231219    RequestSDO(0x100b);
    232220    WaitForSdo(0x100b);
    233 
    234     // FIXME! Not statically linked!
    235     //    if (fSoftVersion<0x00000035)
    236     //        fIsZombie = true;
    237221}
    238222
     
    240224void Macs::Init()
    241225{
     226    if (HasError())
     227    {
     228        lout << "Macs::Init: " << GetNodeName() << " has error --> ZOMBIE!" << endl;
     229        SetZombie();
     230    }
     231
     232    StopHostGuarding();
     233    StopGuarding();
     234
     235    usleep(2000.*GetGuardTime());
     236
    242237    lout << "- " << GetNodeName() << ": Requesting Mac Software Version." << endl;
    243238    RequestSDO(0x100a);
    244239    WaitForSdo(0x100a);
    245240
    246     if (fIsZombie)
     241    if (IsZombieNode())
    247242    {
    248243        lout << GetNodeName() << " - InitDevice failed!" << endl;
     
    250245    }
    251246
    252     EnableTimeout(kFALSE);
     247    // FIXME! Not statically linked!
     248    if (fSoftVersion<0x00000042) // 00.66
     249    {
     250        lout << GetNodeName() << " - Software Version too old!" << endl;
     251        SetZombie();
     252        return;
     253    }
     254
    253255    SetRpmMode(FALSE);
    254256
     
    270272
    271273    SetNoWait(TRUE);
     274
     275    StartGuarding(100, 2);
     276    StartHostGuarding();
    272277}
    273278
     
    283288void Macs::StopDevice()
    284289{
    285     EnableTimeout(kFALSE);
     290    //EnableTimeout(kFALSE);
    286291
    287292    SetNoWait(FALSE);
     
    348353{
    349354    SendSDO(0x2002, vel);     // velocity
    350     WaitForSdo(0x2002);
     355    WaitForSdo(0x2002, 0);
    351356}
    352357
     
    466471    {
    467472        lout << "- " << GetNodeName() << ": reports Error occursion." << endl;
     473        lout << "Macs::HandlePDO2: " << GetNodeName() << " --> ZOMBIE!" << endl;
     474        SetZombie();
    468475        SetError(-1);
    469476        return;
     
    537544
    538545    case 100:
    539         lout << "Connection timed out." << endl;
    540         EnableTimeout(false);
     546        //lout << "Connection timed out." << endl;
     547        //EnableTimeout(false);
    541548        return;
    542549
     
    562569    // FIXME: Timeout???
    563570    //
    564     while (GetError()<0)
    565         usleep(1);
     571//  while (GetError()<0)
     572//      usleep(1);
    566573
    567574    //
     
    569576    // we can go on working 'as usual' Eg. Initialize a Display Update
    570577    //
    571     cout << GetNodeName() << " Handling Error #" << GetError() << endl;
     578    cout << GetNodeName() << " Handling Error #" << dec << GetError() << endl;
    572579    switch (GetError())
    573580    {
     
    576583    case   9: // zero idx
    577584    case  84: // ON TIME
    578         // Stop program?
     585        lout << "- " << GetNodeName() << ": Cannot handle error #" << GetError() << endl;
    579586        return;
    580587
    581588    case 11:  // software endswitch
    582589    case 25:  // hardware endswitch
     590        lout << "- " << GetNodeName() << ": Cannot handle error 'Endswitch!'" << endl;
     591        return;
     592
    583593    case 100: // timeout (movement has been stopped, so we can go on)
    584594        DelError();
    585595        return;
    586 
     596/*
    587597    case 101:
    588         lout << "Warning: " << GetNodeName() << " didn't respond in timeout window - try again." << endl;
     598        //lout << "Warning: " << GetNodeName() << " didn't respond in timeout window - try again." << endl;
    589599        DelError();
    590600        return;
     601        */
     602    default:
     603        lout << "- " << GetNodeName() << ": Cannot handle error #" << GetError() << endl;
     604 
    591605    }
    592606}
     
    633647}
    634648
    635 void Macs::ReqTimeoutTime()
    636 {
    637     RequestSDO(0x4000, 2);
    638     WaitForSdo(0x4000, 2);
    639 }
    640 
    641 void Macs::EnableTimeout(bool enable, LWORDS_t ms)
    642 {
    643     lout << "- " << GetNodeName() << ": " << (enable?"En":"Dis") << "able timeout, " << dec << ms << "ms." << endl;
    644     if (!enable)
    645     {
    646         SendSDO(0x4000, 1, string('o', 'f', 'f'));
    647         WaitForSdo(0x4000, 1);
    648 
    649         lout << "- " << GetNodeName() << ": Stopping handshake (PC)." << endl;
    650 
    651         fTimeout->Stop(); //kTRUE);
    652 
    653         fTimerOn = kFALSE;
    654     }
    655     else
    656     {
    657         if (ms>0)
    658             SetTimeoutTime(ms);
    659 
    660         ResetTimeout();
    661 
    662         fTimerOn = kTRUE;
    663         fTimeout->Start(fGuardTime/*/3*2*/, kTRUE); //kFALSE); //TRUE);
    664 
    665         //
    666         // Start with kFALSE would be a continous timer, but this
    667         // timer seems to stop it's activity at some stage without
    668         // any reason
    669         //
    670         lout << "- " << GetNodeName() << ": starting handshake." << endl;
    671         SendSDO(0x4000, 1, string('o', 'n'));
    672         WaitForSdo(0x4000, 1);
    673     }
    674     lout << "- " << GetNodeName() << ": Timeout timer turned "
    675         << (enable?"on.":"off.") << endl;
    676 }
    677 
    678 Bool_t Macs::HandleTimer(TTimer *t)
    679 {
    680     /*
    681      Fons:
    682      -----
    683 
    684      timers never trigger at the same time or when in a TTimer::Notify.
    685      Little explanation:
    686 
    687      - there are two types of timers synchronous and a-synchronous.
    688      - synchronous timers are only handled via the ROOT eventloop
    689        (see TUnixSystem::DispatchOneEvent()). If there are no mouse/keyboard
    690        events then the synchronous timer queue is checked. So if the processing
    691        of a mouse/keyboard event takes a long time synchronous timers are not
    692        called for a while. To prevent this from happening one can call in long
    693        procedures gSystem->ProcessEvents(). The system schedules only the
    694        next timer in the queue when the current one's Notify() has finished.
    695      - a-synchronous timers are triggered via SIGALARM, i.e. the program is
    696        interupted and execution jumps to the Notify() function. When the
    697        notify is finished the next a-sync timer is scheduled and the system
    698        resumes from the place where it was initially interrupted. One of the
    699        things to remember when using a-sync timers is don't make any graphics
    700        calls in them. X11 is not re-entrant and it might be that the SIGALARM
    701        signal interrupted the system while being in X11. A-sync timers are best
    702        used to set flags that you can test at a convenient and controlled
    703        time.
    704        */
    705 
    706     //
    707     //  FIXME! Use NMT!
    708     //
    709     // --- lout << ddev(MLog::eGui);
    710     // --- lout << "Send 0x4000: " << GetNodeName() << endl;
    711 
     649void Macs::SendNodeguard()
     650{
    712651    SendSDO(0x4000, 0, (LWORD_t)0, false);
    713 
    714     // --- lout << "Done 0x4000: " << GetNodeName() << endl;
    715 
    716     Timer time;
    717 
    718     // --- lout << "dT " << GetNodeName() << ": " <<  dec <<(int)((fTimeoutTime-time.Now())*1000) << endl;
    719     // --- lout << edev(MLog::eGui);
    720 
    721     if (time.Now() > fTimeoutTime)
    722     {
    723         lout << ddev(MLog::eGui);
    724         lout << "Warning: " << GetNodeName() << " didn't respond in timeout window." << endl;
    725         lout << edev(MLog::eGui);
    726         SetError(101);
    727     }
    728 
    729     //WaitForSdo(0x4000, 0, kDontWait);
    730     //
    731     // Would not be necessary if I would Start the timer with
    732     // kFALSE. This would be a continous timer, but this
    733     // timer seems to stop it's activity at some stage without
    734     // any reason
    735     //
    736     if (fTimerOn)
    737         fTimeout->Start(fGuardTime/*/3*2*/, kTRUE);
    738 
    739     return kTRUE;
    740 }
    741 
    742 void Macs::ResetTimeout()
    743 {
    744     Timer time;
    745 
    746     // --- lout << ddev(MLog::eGui);
    747     // --- lout << "Reset " << GetNodeName() << ": " << dec << (int)((fTimeoutTime-time.Now())*1000) << endl;
    748     // --- lout << edev(MLog::eGui);
    749 
    750     fTimeoutTime = time.Now() + 3.*fGuardTime/1000.;
    751 }
    752 
    753 void Macs::SetTimeoutTime(LWORD_t ms)
    754 {
    755     // FIXME: Is '/2' the best choose?
    756     fGuardTime = ms/3;      // how often do we send/request the handshake
    757 
    758     SendSDO(0x4000, 2, ms*2); // How often do we check for the handshake
    759     WaitForSdo(0x4000, 2);
    760 }
    761 
     652}
     653
     654// --------------------------------------------------------------------------
     655//
     656// This starts the host guarding. The host guarding is only available
     657// if the node guarding is running. The host guarding works with the
     658// guardtime and the lifetimefactor from the nodeguarding.
     659//
     660void Macs::StartHostGuarding()
     661{
     662    SendSDO(0x100c, 0, (LWORD_t)GetGuardTime());
     663    WaitForSdo(0x100c);
     664
     665    SendSDO(0x100d, 0, (LWORD_t)GetLifeTimeFactor());
     666    WaitForSdo(0x100d);
     667
     668    lout << "- " << GetNodeName() << ": Hostguarding started (" << dec;
     669    lout << GetLifeTimeFactor() << "*" << GetGuardTime() << "ms)" << endl;
     670}
     671
     672// --------------------------------------------------------------------------
     673//
     674// Stop the host guarding.
     675//
     676void Macs::StopHostGuarding()
     677{
     678    SendSDO(0x100c, 0, (LWORD_t)0);
     679    WaitForSdo(0x100c);
     680
     681    SendSDO(0x100d, 0, (LWORD_t)0);
     682    WaitForSdo(0x100d);
     683
     684    lout << "- " << GetNodeName() << ": Hostguarding stopped." << endl;
     685}
     686
  • trunk/MagicSoft/Cosy/devdrv/macs.h

    r1703 r1727  
    11#ifndef MACS_H
    22#define MACS_H
    3 
    4 #include <TObject.h>
    53
    64#include "nodedrv.h"
    75#include "base/timer.h"
    86
    9 class Macs : public NodeDrv, public TObject
     7class Macs : public NodeDrv
    108{
    119private:
     
    3028    BYTE_t   fStatus;
    3129
    32     TTimer  *fTimeout;
    33     Bool_t   fTimerOn;
    34     LWORD_t  fGuardTime;
    35     double   fTimeoutTime;
    36 
    3730    LWORD_t string(BYTE_t b0=0, BYTE_t b1=0, BYTE_t b2=0, BYTE_t b3=0)
    3831    {
     
    4033    }
    4134
    42     void ResetTimeout();
    43     Bool_t HandleTimer(TTimer *t);
    44 
    4535    void Init();
    46     //bool Reboot();
    47 
    48     //bool InitDevice(Network *);
    49 
    50     //void StartDevice();
    5136    void StopDevice();
    5237
    5338    void HandleSDO(WORD_t idx, BYTE_t subidx, LWORD_t val, timeval_t *tv);
    54     void HandleSDOOK(WORD_t idx, BYTE_t subidx);
    55     void HandleSDOError(LWORD_t data)          { NodeDrv::HandleSDOError(data); }
     39    void HandleSDOOK(WORD_t idx, BYTE_t subidx, timeval_t *tv);
     40    //void HandleSDOError(LWORD_t data) { NodeDrv::HandleSDOError(data); }
    5641
    5742    void HandlePDO1(BYTE_t *data, timeval_t *tv);
    5843    void HandlePDO2(BYTE_t *data, timeval_t *tv);
     44    //void HandleNodeguard(timeval_t *tv);
     45
     46    void SendNodeguard();
    5947
    6048    void CheckConnection();
     
    10896    void StartAbsPos(LWORDS_t pos);
    10997
    110     void SetTimeoutTime(LWORD_t ms);
    111     void ReqTimeoutTime();
    112 
    113     void EnableTimeout(bool enable=true, LWORDS_t ms=-1);
    114 
    11598    void StopMotor();
    11699
     
    131114    LWORD_t  GetRes()    const { return fRes; }    // Encoder resolution
    132115
     116    void StartHostGuarding();
     117    void StopHostGuarding();
     118
    133119    void HandleError();
    134120
  • trunk/MagicSoft/Cosy/devdrv/shaftencoder.cc

    r1703 r1727  
    11#include "shaftencoder.h"
    22
    3 #include "timer.h"
     3#include "base/timer.h"
    44#include "network.h"
    55
     
    1717ShaftEncoder::ShaftEncoder(const BYTE_t nodeid, const char *name, MLog &out)
    1818    : NodeDrv(nodeid, name, out), fLabel(NULL), fPosHasChanged(false)
    19 {
    20 }
    21 
    22 ShaftEncoder::~ShaftEncoder()
    2319{
    2420}
     
    5551        return;
    5652
     53    case 0x100c:
     54        lout << "- Guardtime: " << dec << val << "ms" << endl;
     55        return;
     56
     57    case 0x100d:
     58        lout << "- Lifetimefactor: " << dec << val << endl;
     59        return;
     60
     61    case 0x100e:
     62        lout << "- CobId for guarding: 0x" << hex << val << endl;
     63        return;
     64
    5765    case 0x6000:
    5866    case 0x6500:
    59         lout << "- Counting: " << (val&1   ?"anti-clockwise":"clockwise") << "  ";
     67        lout << "- Counting: " << (val&1 ?"anti-clockwise":"clockwise") << "  ";
    6068        lout << "HwTest: " <<   (val&2   ?"on":"off") << "  ";
    6169        lout << "Scaling: " <<  (val&4   ?"on":"off") << "  ";
     
    95103void ShaftEncoder::DisplayVal()
    96104{
    97     if (fIsZombie)
     105    if (IsZombieNode())
    98106    {
    99107        fLabel[0]->SetText(new TGString(""));
     
    162170}
    163171
     172//#include <fstream.h>
     173//ofstream fout("log/shaftencoder.log");
     174
    164175void ShaftEncoder::HandlePDOType2(BYTE_t *data, timeval_t *tv)
    165176{
     
    188199    fPos  = pos;
    189200    fTurn = turn;
     201
     202    //fout << dec << (int)GetId() << " " << turn << " " << pos << endl;
     203
    190204    fTime.SetTimer(tv);
    191205    fPosHasChanged=true;
     
    208222    //-----------------------------------------------------------------------
    209223
     224    StopGuarding();
     225
    210226    //
    211227    // Requesting and checking (FIXME) type of encoder
     
    215231    WaitForSdo(0x1000);
    216232
    217     if (fIsZombie)
     233    if (IsZombieNode())
    218234    {
    219235        lout << GetNodeName() << " - Init failed!" << endl;
     
    274290    lout << "- " << GetNodeName() << ": Start Node (NMT)." << endl;
    275291    SendNMT(kNMT_START);
     292
     293    StartGuarding(125, 2);
    276294}
    277295
     
    282300    WaitForSdo(0x100b);
    283301}
    284 /*
    285 bool ShaftEncoder::InitDevice(Network *net)
    286 {
    287     NodeDrv::InitDevice(net);
    288 
    289     Init();
    290 
    291     return !fIsZombie;
    292 }
    293 
    294 // --------------------------------------------------------------------------
    295 //
    296 // This should be called from a master or main thread to get a node out
    297 // of the Zombie-Status.
    298 //
    299 bool ShaftEncoder::Reboot()
    300 {
    301     fIsZombie = false;
    302 
    303     Init();
    304 
    305     return !fIsZombie;
    306 }
    307 */
    308302
    309303void ShaftEncoder::ReqPos()
     
    321315    lout << "- " << GetNodeName() << ": Setting Preset." << endl;
    322316
    323     SendSDO(0x6003, (LWORD_t)fPos);
     317    SendSDO(0x6003, (LWORD_t)pre);
    324318    if (!WaitForSdo(0x6003))
    325319        return;
  • trunk/MagicSoft/Cosy/devdrv/shaftencoder.h

    r1703 r1727  
    22#define SHAFTENCODER_H
    33
    4 #include "timer.h"
     4#include "base/timer.h"
    55#include "nodedrv.h"
    66
     
    1717    WORD_t   fTurns; // Number of possible turns
    1818
    19     TGLabel **fLabel;
    20     LWORDS_t  fUpdPos;   // ticks
    21     WORDS_t   fUpdVel;   // ticks per 5ms
    22     WORDS_t   fUpdAcc;   // ticks per 25ms^2
     19    TGLabel **fLabel;     //
     20    LWORDS_t  fUpdPos;    // ticks
     21    WORDS_t   fUpdVel;    // ticks per 5ms
     22    WORDS_t   fUpdAcc;    // ticks per 25ms^2
    2323
    24     bool fPosHasChanged;
     24    bool fPosHasChanged;  //!
    2525
    2626    Timer fTime;
     
    3737public:
    3838    ShaftEncoder(const BYTE_t nodeid, const char *name=NULL, MLog &out=gLog);
    39     virtual ~ShaftEncoder();
    4039
    41     //bool InitDevice(Network *);
    42     //bool Reboot();
    43 
    44     //void StartDevice();
    4540    void StopDevice();
    4641
     
    4843
    4944    void HandleSDO(WORD_t idx, BYTE_t subidx, LWORD_t val, timeval_t *tv);
    50     void HandleSDOOK(WORD_t idx, BYTE_t subidx) { NodeDrv::HandleSDOOK(idx, subidx); }
    51     void HandleSDOError(LWORD_t data)           { NodeDrv::HandleSDOError(data); }
    52 
     45    /*
     46     void HandleSDOOK(WORD_t idx, BYTE_t subidx, timeval_t *tv) { NodeDrv::HandleSDOOK(idx, subidx, tv); }
     47     void HandleSDOError(LWORD_t data)           { NodeDrv::HandleSDOError(data); }
     48     */
    5349    void HandlePDO1(BYTE_t *data, timeval_t *tv) { HandlePDOType2(data, tv); }
    5450    void HandlePDO2(BYTE_t *data, timeval_t *tv) { HandlePDOType2(data, tv); }
    5551
    56     LWORDS_t GetPos() { return fIsZombie ? 0 : fPos+fTurn*fTicks; } // FIXME? 0?
     52    LWORDS_t GetPos() { return IsZombieNode() ? 0 : fPos+fTurn*fTicks; } // FIXME? 0?
    5753    LWORD_t  GetPhysRes() { return fTicks; }
    5854
  • trunk/MagicSoft/Cosy/gui/MGCosy.cc

    r1702 r1727  
    180180    fList->Add(l);
    181181
    182     fOffsetZd = new TGLabel(f, "0000000");
    183     fOffsetAz = new TGLabel(f, "0000000");
     182    fOffsetZd = new TGLabel(f, "000000000");
     183    fOffsetAz = new TGLabel(f, "000000000");
    184184    fOffsetZd->SetTextJustify(kTextRight);
    185185    fOffsetAz->SetTextJustify(kTextRight);
    186     fOffsetZd->Move(x, y+102);
    187     fOffsetAz->Move(x, y+119);
     186    fOffsetZd->Move(x+15, y+102);
     187    fOffsetAz->Move(x+15, y+119);
    188188    fList->Add(fOffsetZd);
    189189    fList->Add(fOffsetAz);
     
    193193    fList->Add(l);
    194194
    195     l = new TGLabel(f, "Ra (soll):");
     195    l = new TGLabel(f, "Ra (nominal):");
    196196    l->Move(x-60, y+159);
    197197    fList->Add(l);
     
    201201    fList->Add(l);
    202202
    203     l = new TGLabel(f, "Dec (soll):");
     203    l = new TGLabel(f, "Dec (nominal):");
    204204    l->Move(x-60, y+199);
    205205    fList->Add(l);
    206206
    207     l = new TGLabel(f, "Zd (soll):");
     207    l = new TGLabel(f, "Zd (nominal):");
    208208    l->Move(x-60, y+222);
    209209    fList->Add(l);
    210210
    211     l = new TGLabel(f, "Az (soll):");
     211    l = new TGLabel(f, "Az (nominal):");
    212212    l->Move(x-60, y+239);
    213213    fList->Add(l);
     
    836836    {
    837837        zd = (int)test.Zd();
    838         sprintf(text, "%c%dh %.1fm", soll.Zd()<0?'-':'+', abs((int)soll.Zd()), 0.1*(abs((int)test.Zd())%600));
     838        sprintf(text, "%c%dd %.1fm", soll.Zd()<0?'-':'+', abs((int)soll.Zd()), 0.1*(abs((int)test.Zd())%600));
    839839        fZdSoll->SetText(new TGString(text));
    840840    }
     
    984984            Timer tm;
    985985            tm.Now();
    986 
     986            /*
    987987            Float_t h = 2.+tm.H()+(10.7+tm.M())/60.;
    988988            RaDec dest(h*15, 129.7);
     
    994994            int i = 0;
    995995            while (!HasStopFlag() && i++<60)  // 2.5min
    996                 usleep(1000000);
     996            usleep(1000000);
    997997            if (HasStopFlag())
    998998                break;
     999            */
    9991000
    10001001            //fQueue->PostMsg(WM_STOP, 0, 0);
    10011002
    1002             ZdAz dest1(fRand.Integer(36)+25, fRand.Integer(360));
     1003            ZdAz dest1((float)fRand.Integer(120)-60., 0);//fRand.Integer(25)+90);
    10031004
    10041005            cout << "Demo: Zd=" << dest1.Zd() << "° Az=" << dest1.Az() << "°" << endl;
     
    10061007            fQueue->PostMsg(WM_POSITION, &dest1, sizeof(dest1));
    10071008
    1008             i = 0;
    1009             while (!HasStopFlag() && i++<15)  // 30s
     1009            int i = 0;
     1010            while (!HasStopFlag() && i++<5/*5*/)  // 30s
    10101011                usleep(1000000);
    10111012            if (HasStopFlag())
  • trunk/MagicSoft/Cosy/gui/MGSkyPosition.cc

    r1702 r1727  
    5656    fMoon    = new TArc(0, 0, 3, 290, 70);
    5757    fSun     = new TArc(0, 0, 2);
    58 
    59     InitArc(fMars,    1001, 13, 12);
     58    fSaturn  = new TArc(0, 0, 1);
     59
     60    fSaturnRing = new TArc(0, 0, 2);
     61    fSaturnRing->SetFillStyle(4000);      // (s. TAttFill)
     62    fSaturnRing->SetLineColor(kRed);
     63    fSaturnRing->Draw();
     64
     65    InitArc(fMars,    1001, kRed/*13*/, kRed/*12*/);
    6066    InitArc(fVenus,   1001, 15, 14);
    6167    InitArc(fJupiter, 1001, 17, 16);
    6268    InitArc(fMoon,    1001, 19, 15);
    63     InitArc(fSun,     1001, 10, 19);
     69    InitArc(fSaturn,  1001, kYellow/*17*/, 16);
    6470
    6571    for (int i=0; i<4; i++)
     
    7278        fList->Add(fSunL[i]);
    7379    }
     80    InitArc(fSun, 1001, kYellow/*10*/, kYellow/*19*/);
    7481
    7582    fList->Add(fMars);
     
    7885    fList->Add(fMoon);
    7986    fList->Add(fSun);
     87    fList->Add(fSaturn);
    8088
    8189    //
     
    317325    UpdatePlanet(kEVenus,   fVenus);
    318326    UpdatePlanet(kEMars,    fMars);
     327    UpdatePlanet(kESaturn,  fSaturn);
    319328
    320329    RaDec radec = fSlaStar->CalcRaDecFast(pos*kDeg2Rad);
     
    363372    SetModified();
    364373
    365     if (planet!=kESun)
    366         return;
    367 
    368     // cout << "Sun: x=" << x << " y=" << y;
    369     // cout << "   Zd=" << deg << " Az=" << 360./D2PI*zdaz.Az() << endl;
    370 
    371     fSunL[0]->SetX1(x-3.5); fSunL[0]->SetX2(x+3.5);
    372     fSunL[1]->SetX1(x-2.5); fSunL[1]->SetX2(x+2.5);
    373     fSunL[2]->SetX1(x-2.5); fSunL[2]->SetX2(x+2.5);
    374     fSunL[3]->SetX1(x);     fSunL[3]->SetX2(x);
    375 
    376     fSunL[0]->SetY1(y);     fSunL[0]->SetY2(y);
    377     fSunL[1]->SetY1(y-2.5); fSunL[1]->SetY2(y+2.5);
    378     fSunL[2]->SetY1(y+2.5); fSunL[2]->SetY2(y-2.5);
    379     fSunL[3]->SetY1(y-3.5); fSunL[3]->SetY2(y+3.5);
    380 }
     374    if (planet==kESaturn)
     375    {
     376        fSaturnRing->SetX1(x);
     377        fSaturnRing->SetY1(y);
     378    }
     379
     380    if (planet==kESun)
     381    {
     382        fSunL[0]->SetX1(x-3.5); fSunL[0]->SetX2(x+3.5);
     383        fSunL[1]->SetX1(x-2.5); fSunL[1]->SetX2(x+2.5);
     384        fSunL[2]->SetX1(x-2.5); fSunL[2]->SetX2(x+2.5);
     385        fSunL[3]->SetX1(x);     fSunL[3]->SetX2(x);
     386
     387        fSunL[0]->SetY1(y);     fSunL[0]->SetY2(y);
     388        fSunL[1]->SetY1(y-2.5); fSunL[1]->SetY2(y+2.5);
     389        fSunL[2]->SetY1(y+2.5); fSunL[2]->SetY2(y-2.5);
     390        fSunL[3]->SetY1(y-3.5); fSunL[3]->SetY2(y+3.5);
     391    }
     392}
  • trunk/MagicSoft/Cosy/gui/MGSkyPosition.h

    r1690 r1727  
    2929    TArc       *fMars;
    3030    TArc       *fSun;
     31    TArc       *fSaturn;
     32
     33    TArc       *fSaturnRing;
    3134
    3235    TArc       *fDot[6];
Note: See TracChangeset for help on using the changeset viewer.