Ignore:
Timestamp:
09/10/01 14:32:27 (23 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Cosy/devdrv
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Cosy/devdrv/macs.cc

    r925 r926  
    66#include "timer.h"
    77#include "network.h"
    8 
    9 Macs::Macs(BYTE_t nodeid, MLog &out)
    10     : NodeDrv(nodeid, out), fMacId(2*nodeid+1),
     8#include "MLogManip.h"
     9
     10Macs::Macs(const BYTE_t nodeid, const char *name, MLog &out)
     11    : NodeDrv(nodeid, name, out), fMacId(2*nodeid+1),
    1112    fPos(0), fPosTime(0.0), fPdoPos(0), fPdoTime(0.0),
    1213    fPosActive(0), fRpmActive(0)
     
    2627    {
    2728    case 0x100a:
    28         lout << "- Mac using Software Version V" << dec << (int)(val>>16) << "." << (int)(val&0xff) << endl;
     29        lout << "- " << GetNodeName() << ": Using Software Version V" << dec << (int)(val>>16) << "." << (int)(val&0xff) << endl;
    2930        return;
    3031
    3132    case 0x2002:
    32         cout << "Actual velocity: " << dec << val << endl;
     33        cout << GetNodeName() << ": Actual velocity: " << dec << val << endl;
    3334        fVel = val;
    3435        return;
     
    3839        {
    3940        case 1:
    40             cout << "Timeout timer is " << (val?"en":"dis") << "abled." << endl;
     41            cout << GetNodeName() << ": Timeout timer is " << (val?"en":"dis") << "abled." << endl;
    4142            return;
    4243        case 2:
    43             cout << "Actual timeout time: " << dec << val << "ms" << endl;
     44            cout << GetNodeName() << ": Actual timeout time: " << dec << val << "ms" << endl;
    4445            return;
    4546        }
     
    8990
    9091    case 0x6002:
    91         lout << "- Velocity resolution Node#" << (int)GetId() << ": " << dec << val << " ticks/min" << endl;
     92        lout << "- Velocity resolution " << GetNodeName() << ": " << dec << val << " ticks/min" << endl;
    9293        fVelRes = val;
    9394        return;
     
    9798}
    9899
    99 void Macs::SetTimeoutTime(LWORD_t ms)
    100 {
    101     fTimeoutTime = ms/2;
    102 
    103     SendSDO(0x4000, 2, ms);
    104     WaitForSdo(0x4000, 2);
    105 }
    106 
    107 void Macs::ReqTimeoutTime()
    108 {
    109     RequestSDO(0x4000, 2);
    110     WaitForSdo(0x4000, 2);
    111 }
    112 
    113 void Macs::EnableTimeout(bool enable, LWORDS_t ms)
    114 {
    115     if (!enable)
    116     {
    117         SendSDO(0x4000, 1, string('o', 'f', 'f'));
    118         WaitForSdo(0x4000, 1);
    119 
    120         cout << "--> Turn Off. " << endl;
    121         fTimerOn = kFALSE;
    122     }
    123     else
    124     {
    125         if (ms>0)
    126             SetTimeoutTime(ms);
    127 
    128         cout << "--> Turn On." << endl;
    129         fTimerOn = kTRUE;
    130         fTimeout->Start(fTimeoutTime, kTRUE);
    131 
    132         SendSDO(0x4000, 1, string('o', 'n'));
    133         WaitForSdo(0x4000, 1);
    134     }
    135 }
     100void Macs::HandleSDOOK(WORD_t idx, BYTE_t subidx)
     101{
     102    if (idx==0x4000 && subidx==0 && fTimerOn)
     103    {
     104        ResetTimeout();
     105        return;
     106    }
     107    NodeDrv::HandleSDOOK(idx, subidx);
     108}
     109
    136110
    137111void Macs::ReqVelRes()
    138112{
    139     lout << "- Requesting velocity resolution (velres, 0x6002) of " << (int)GetId() << endl;
     113    lout << "- Requesting velocity resolution (velres, 0x6002) of " << GetNodeName() << endl;
    140114    RequestSDO(0x6002);
    141115    WaitForSdo(0x6002);
     
    144118void Macs::SetPDO1On(BYTE_t flag)
    145119{
    146     lout << "- " << (flag?"Enable":"Disable") << " PDO1 of #" << (int)GetId() << endl;
     120    lout << "- " << (flag?"Enable":"Disable") << " PDO1 of " << GetNodeName() << endl;
    147121    SendSDO(0x1800, 1, (LWORD_t)(flag?0:1)<<31);
    148122    WaitForSdo(0x1800, 1);           
     
    171145    EnableTimeout(kFALSE);
    172146
    173     lout << "- Requesting Mac Software Version of " << (int)GetId() << endl;
     147    lout << "- Requesting Mac Software Version of " << GetNodeName() << endl;
    174148    RequestSDO(0x100a);
    175149    WaitForSdo(0x100a);
     
    179153    ReqVelRes(); // Init fVelRes
    180154
    181     lout << "- Motor on of " << (int)GetId() << endl;
     155    lout << "- Motor on of " << GetNodeName() << endl;
    182156    SendSDO(0x3000, string('o', 'n'));
    183157    WaitForSdo(0x3000);
     
    219193    SetPDO1On(FALSE);
    220194
    221     lout << "- Motor off of " << (int)GetId() << endl;
     195    lout << "- Motor off of " << GetNodeName() << endl;
    222196    SendSDO(0x3000, string('o', 'f', 'f'));
    223197    WaitForSdo(0x3000);
     
    232206void Macs::ReqPos()
    233207{
    234     lout << "- Requesting Position of #" << (int)GetId() << endl;
     208    lout << "- Requesting Position of " << GetNodeName() << endl;
    235209    RequestSDO(0x6004);
    236210    WaitForSdo(0x6004);
     
    239213void Macs::ReqVel()
    240214{
    241     lout << "- Requesting Velocity of #" << (int)GetId() << endl;
     215    lout << "- Requesting Velocity of " << GetNodeName() << endl;
    242216    RequestSDO(0x2002);
    243217    WaitForSdo(0x2002);
     
    246220void Macs::SetHome(LWORDS_t pos, WORD_t maxtime)
    247221{
    248     lout << "- Driving #" << (int)GetId() << " to home position, Offset=" << dec << pos << endl;
     222    lout << "- Driving " << GetNodeName() << " to home position, Offset=" << dec << pos << endl;
    249223    SendSDO(0x6003, 2, (LWORD_t)pos);       // home
    250224    WaitForSdo(0x6003, 2);
     
    254228    SendSDO(0x3001, string('h','o','m','e'));       // home
    255229    WaitForSdo(0x3001, 0, maxtime*1000);
    256     lout << "- Home position of #" << (int)GetId() << " reached. " << endl;
     230    lout << "- Home position of " << GetNodeName() << " reached. " << endl;
    257231
    258232    SendSDO(0x6003, 0, string('s','e','t'));       // home
     
    305279void Macs::SetNoWait(BYTE_t flag)
    306280{
    307     lout << "- Setting NOWAIT " << (flag?"ON":"OFF") << " #" << (int)GetId() << endl;
     281    lout << "- Setting NOWAIT " << (flag?"ON ":"OFF ") << GetNodeName() << endl;
    308282    SendSDO(0x3008, flag ? string('o', 'n') : string('o', 'f', 'f'));
    309283    WaitForSdo(0x3008);
     
    316290    // or by a positioning command (POSA, ...)
    317291    //
    318     lout << "- Setting Vel Sync Mode #" << (int)GetId() << endl;
     292    lout << "- Setting Vel Sync Mode of " << GetNodeName() << endl;
    319293    SendSDO(0x3007, 0, string('s', 'y', 'n', 'c'));
    320294    WaitForSdo(0x3007, 0);
     
    327301    // or by a positioning command (POSA, ...)
    328302    //
    329     lout << "- Setting Pos Sync Mode #" << (int)GetId() << endl;
     303    lout << "- Setting Pos Sync Mode of " << GetNodeName() << endl;
    330304    SendSDO(0x3007, 1, string('s', 'y', 'n', 'c'));
    331305    WaitForSdo(0x3007, 1);
     
    372346    if (!errnum)
    373347    {
    374         cout << "Mac #" << (int)GetId() << " reports Error occursion." << endl;
     348        cout << "Mac " << GetNodeName() << " reports Error occursion." << endl;
    375349        SetError(-1);
    376350        return;
     
    382356    //
    383357    if (GetError()>0)
    384         cout << "Mac #" << (int)GetId() << " WARNING! Error #" << GetError() << " unhandled by software." << endl;
     358        cout << "Mac " << GetNodeName() << " WARNING! Error #" << GetError() << " unhandled by software." << endl;
    385359
    386360    SetError(errnum);
    387361
    388     cout << "Mac #" << (int)GetId() << " reports: ";
     362    cout << "Mac " << GetNodeName() << " reports: ";
    389363    switch (errnum)
    390364    {
     
    429403        return;
    430404
     405    case 100:
     406        cout << "Connection timed out." << endl;
     407        return;
     408
    431409    default:
    432410        cout << "Error Nr. " << errnum << ", " << errinf << endl;
     
    456434    // we can go on working 'as usual' Eg. Initialize a Display Update
    457435    //
    458     cout << "Mac #" << (int)GetId() << " Handling Error #" << GetError() << endl;
     436    cout << "Mac " << GetNodeName() << " Handling Error #" << GetError() << endl;
    459437    switch (GetError())
    460438    {
     
    463441    case   9: // zero idx
    464442    case  84: // ON TIME
    465     case 100: // timeout
    466443        // Stop program?
    467444        return;
    468445
    469     case 11: // software endswitch
    470     case 25: // hardware endswitch
     446    case 11:  // software endswitch
     447    case 25:  // hardware endswitch
     448    case 100: // timeout (movement has been stopped, so we can go on)
     449        DelError();
     450        return;
     451
     452    case 101:
     453        lout << "Warning: " << GetNodeName() << " didn't respond in timeout window - try again." << endl;
    471454        DelError();
    472455        return;
     
    513496    SendSDO(0x2000, 3, (LWORD_t)(neg|(pos<<1)));
    514497    WaitForSdo(0x2000, 3);
     498}
     499
     500void Macs::ReqTimeoutTime()
     501{
     502    RequestSDO(0x4000, 2);
     503    WaitForSdo(0x4000, 2);
     504}
     505
     506void Macs::EnableTimeout(bool enable, LWORDS_t ms)
     507{
     508    if (!enable)
     509    {
     510        SendSDO(0x4000, 1, string('o', 'f', 'f'));
     511        WaitForSdo(0x4000, 1);
     512
     513        fTimeout->Stop(); //kTRUE);
     514
     515        fTimerOn = kFALSE;
     516    }
     517    else
     518    {
     519        if (ms>0)
     520            SetTimeoutTime(ms);
     521
     522        ResetTimeout();
     523
     524        fTimerOn = kTRUE;
     525        fTimeout->Start(fGuardTime, kFALSE); //kTRUE);
     526
     527        SendSDO(0x4000, 1, string('o', 'n'));
     528        WaitForSdo(0x4000, 1);
     529    }
     530    lout << "- Timeout timer of " << GetNodeName() << " turned "
     531        << (enable?"on.":"off.") << endl;
    515532}
    516533
     
    542559       time.
    543560       */
    544     SendSDO(0x4000);
    545     WaitForSdo(0x4000, 0, kDontWait);
    546     if (fTimerOn)
    547         fTimeout->Start(fTimeoutTime, kTRUE);
     561
     562    //
     563    //  FIXME! Use NMT!
     564    //
     565    SendSDO(0x4000, 0, (LWORD_t)0, false);
     566
     567    Timer time;
     568    if (time.Now() > fTimeoutTime)
     569    {
     570        lout << ddev(MLog::eGui);
     571        lout << "Warning: " << GetNodeName() << " didn't respond in timeout window." << endl;
     572        lout << edev(MLog::eGui);
     573        SetError(101);
     574    }
     575
     576
     577    //WaitForSdo(0x4000, 0, kDontWait);
     578    //    if (fTimerOn)
     579    //        fTimeout->Start(fGuardTime, kTRUE);
     580
    548581    return kTRUE;
    549582}
     583
     584void Macs::ResetTimeout()
     585{
     586    Timer time;
     587    fTimeoutTime = time.Now() + 2.*fGuardTime/1000.; //[usec]
     588}
     589
     590void Macs::SetTimeoutTime(LWORD_t ms)
     591{
     592    fGuardTime = ms/2; // FIXME: Is '/2' the best choose?
     593
     594    SendSDO(0x4000, 2, ms);
     595    WaitForSdo(0x4000, 2);
     596}
     597
  • trunk/MagicSoft/Cosy/devdrv/macs.h

    r925 r926  
    2626    TTimer  *fTimeout;
    2727    Bool_t   fTimerOn;
    28     LWORD_t  fTimeoutTime;
     28    LWORD_t  fGuardTime;
     29    double   fTimeoutTime;
    2930
    3031    LWORD_t string(BYTE_t b0=0, BYTE_t b1=0, BYTE_t b2=0, BYTE_t b3=0)
     
    3334    }
    3435
     36    void ResetTimeout();
    3537    Bool_t HandleTimer(TTimer *t);
    3638
    3739public:
    38     Macs(BYTE_t nodeid, MLog &out=gLog);
     40    Macs(const BYTE_t nodeid, const char *name=NULL, MLog &out=gLog);
    3941    virtual ~Macs();
    4042
     
    4547
    4648    void HandleSDO(WORD_t idx, BYTE_t subidx, LWORD_t val, struct timeval *tv);
    47     void HandleSDOOK(WORD_t idx, BYTE_t subidx) { NodeDrv::HandleSDOOK(idx, subidx); }
     49    void HandleSDOOK(WORD_t idx, BYTE_t subidx);
    4850    void HandleSDOError(LWORD_t data)           { NodeDrv::HandleSDOError(data); }
    4951
  • trunk/MagicSoft/Cosy/devdrv/shaftencoder.cc

    r921 r926  
    1313#include <sys/resource.h>  // PRIO_PROCESS
    1414
    15 ShaftEncoder::ShaftEncoder(BYTE_t nodeid, MLog &out) : NodeDrv(nodeid, out), fLabel(NULL), fPosHasChanged(false)
     15ShaftEncoder::ShaftEncoder(const BYTE_t nodeid, const char *name, MLog &out)
     16    : NodeDrv(nodeid, name, out), fLabel(NULL), fPosHasChanged(false)
    1617{
    1718}
     
    195196    // Requesting and checking (FIXME) type of encoder
    196197    //
    197     lout << "- Requesting Hardware Type (SDO 0x1000) of " << (int)GetId() << endl;
     198    lout << "- Requesting Hardware Type (SDO 0x1000) of " << GetNodeName() << endl;
    198199    RequestSDO(0x1000);
    199200    WaitForSdo(0x1000);
     
    202203    // Read physical ticks per revolution
    203204    //
    204     lout << "- Requesting physical ticks/revolution (SDO 0x6501) of " << (int)GetId() << endl;
     205    lout << "- Requesting physical ticks/revolution (SDO 0x6501) of " << GetNodeName() << endl;
    205206    RequestSDO(0x6501);
    206207    WaitForSdo(0x6501);
     
    209210    // Read number of possible ticks per revolution
    210211    //
    211     lout << "- Requesting possible ticks/revolution (SDO 0x6502) of " << (int)GetId() << endl;
     212    lout << "- Requesting possible ticks/revolution (SDO 0x6502) of " << GetNodeName() << endl;
    212213    RequestSDO(0x6502);
    213214    WaitForSdo(0x6502);
     
    216217    // Set logic ticks/revolution = physical ticks/revolution => scale factor = 1
    217218    //
    218     lout << "- Configuring SDO 0x6001 of " << (int)GetId() << endl;
     219    lout << "- Configuring SDO 0x6001 of " << GetNodeName() << endl;
    219220    SendSDO(0x6001, fTicks);
    220221    WaitForSdo(0x6001);
     
    223224    // Set maximum number of ticks (ticks * turns)
    224225    //
    225     lout << "- Configuring SDO 0x6002 of " << (int)GetId() << endl;
     226    lout << "- Configuring SDO 0x6002 of " << GetNodeName() << endl;
    226227    SendSDO(0x6002, (LWORD_t)(fTicks*fTurns));
    227228    WaitForSdo(0x6002);
     
    230231    // Configure PDOs
    231232    //
    232     lout << "- Configuring SDO 0x1802 of " << (int)GetId() << endl;
     233    lout << "- Configuring SDO 0x1802 of " << GetNodeName() << endl;
    233234    SendSDO(0x1802, 1, (LWORD_t)0x281);
    234235    WaitForSdo(0x1802, 1);
     
    237238    // Delete preset Value
    238239    //
    239     lout << "- Configuring SDO 0x6003 of " << (int)GetId() << endl;
     240    lout << "- Configuring SDO 0x6003 of " << GetNodeName() << endl;
    240241    SendSDO(0x6003, (LWORD_t)0xffffffff);
    241242    WaitForSdo(0x6003);
     
    244245    // Request Parameter
    245246    //
    246     lout << "- Requesting SDO 0x6000 of " << (int)GetId() << endl;
     247    lout << "- Requesting SDO 0x6000 of " << GetNodeName() << endl;
    247248    RequestSDO(0x6000);
    248249    WaitForSdo(0x6000);
     
    250251    ReqPos();
    251252
    252     lout << "- Start Node " << (int)GetId() << endl;
     253    lout << "- Start Node " << GetNodeName() << endl;
    253254    SendNMT(kNMT_START);
    254255}
     
    259260    // Request Position
    260261    //
    261     lout << "- Requesting Position of #" << (int)GetId() << endl;
     262    lout << "- Requesting Position of " << GetNodeName() << endl;
    262263    RequestSDO(0x6004);
    263264    WaitForSdo(0x6004);
     
    269270    fTurn = pre/16384;
    270271
    271     lout << " - Setting Preset #" << (int)GetId() << endl;
     272    lout << " - Setting Preset " << GetNodeName() << endl;
    272273    SendSDO(0x6003, (LWORD_t)fPos);
    273274    WaitForSdo(0x6003);
     
    276277void ShaftEncoder::StopDevice()
    277278{
    278     lout << "- Start Node " << (int)GetId() << endl;
     279    lout << "- Start Node " << GetNodeName() << endl;
    279280    SendNMT(kNMT_STOP);
    280281}
  • trunk/MagicSoft/Cosy/devdrv/shaftencoder.h

    r924 r926  
    3333
    3434public:
    35     ShaftEncoder(BYTE_t nodeid, MLog &out=gLog);
     35    ShaftEncoder(const BYTE_t nodeid, const char *name=NULL, MLog &out=gLog);
    3636    virtual ~ShaftEncoder();
    3737
Note: See TracChangeset for help on using the changeset viewer.