Ignore:
Timestamp:
09/07/01 12:44:16 (23 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Cosy/devdrv
Files:
2 edited

Legend:

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

    r920 r925  
    1212    fPosActive(0), fRpmActive(0)
    1313{
     14    fTimeout = new TTimer(this, 100, kFALSE); // 100ms
    1415}
    1516
    1617Macs::~Macs()
    1718{
     19    fTimerOn = kFALSE;
     20    delete fTimeout;
    1821}
    1922
     
    3033        fVel = val;
    3134        return;
     35
     36    case 0x4000:
     37        switch (subidx)
     38        {
     39        case 1:
     40            cout << "Timeout timer is " << (val?"en":"dis") << "abled." << endl;
     41            return;
     42        case 2:
     43            cout << "Actual timeout time: " << dec << val << "ms" << endl;
     44            return;
     45        }
     46        break;
    3247
    3348    case 0x6004:
     
    7489
    7590    case 0x6002:
    76         lout << "- Velocity resolution #" << (int)GetId() << ": " << dec << val << " ticks/min" << endl;
     91        lout << "- Velocity resolution Node#" << (int)GetId() << ": " << dec << val << " ticks/min" << endl;
    7792        fVelRes = val;
    7893        return;
     
    8297}
    8398
     99void Macs::SetTimeoutTime(LWORD_t ms)
     100{
     101    fTimeoutTime = ms/2;
     102
     103    SendSDO(0x4000, 2, ms);
     104    WaitForSdo(0x4000, 2);
     105}
     106
     107void Macs::ReqTimeoutTime()
     108{
     109    RequestSDO(0x4000, 2);
     110    WaitForSdo(0x4000, 2);
     111}
     112
     113void 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}
     136
    84137void Macs::ReqVelRes()
    85138{
    86     lout << "- Requesting velocity resolution (velres, 0x3007) of " << (int)GetId() << endl;
     139    lout << "- Requesting velocity resolution (velres, 0x6002) of " << (int)GetId() << endl;
    87140    RequestSDO(0x6002);
    88141    WaitForSdo(0x6002);
     
    116169    WaitForSdo(0x2004);
    117170    */
     171    EnableTimeout(kFALSE);
    118172
    119173    lout << "- Requesting Mac Software Version of " << (int)GetId() << endl;
     
    126180
    127181    lout << "- Motor on of " << (int)GetId() << endl;
    128     SendSDO(0x3000, string('O', 'N'));
     182    SendSDO(0x3000, string('o', 'n'));
    129183    WaitForSdo(0x3000);
    130184
     
    147201    // Stop the motor and switch off the position control unit
    148202    //
    149     SendSDO(0x3000, string('S','T','O','P'));
     203    SendSDO(0x3000, string('s','t','o','p'));
    150204    WaitForSdo(0x3000);
    151205}
     
    153207void Macs::StopDevice()
    154208{
     209    EnableTimeout(kFALSE);
     210
    155211    SetNoWait(FALSE);
    156212
     
    164220
    165221    lout << "- Motor off of " << (int)GetId() << endl;
    166     SendSDO(0x3000, string('O', 'F', 'F'));
     222    SendSDO(0x3000, string('o', 'f', 'f'));
    167223    WaitForSdo(0x3000);
    168224
     
    227283    // SetRpmMode(FALSE) stop the motor, but lets the position control unit on
    228284    //
    229     SendSDO(0x3006, 0, mode ? string('S','T','R','T') : string('S','T','O','P'));
     285    SendSDO(0x3006, 0, mode ? string('s','t','r','t') : string('s','t','o','p'));
    230286    WaitForSdo(0x3006, 0);
    231287}
     
    250306{
    251307    lout << "- Setting NOWAIT " << (flag?"ON":"OFF") << " #" << (int)GetId() << endl;
    252     SendSDO(0x3008, flag ? string('O', 'N') : string('O', 'F', 'F'));
     308    SendSDO(0x3008, flag ? string('o', 'n') : string('o', 'f', 'f'));
    253309    WaitForSdo(0x3008);
    254310}
     
    261317    //
    262318    lout << "- Setting Vel Sync Mode #" << (int)GetId() << endl;
    263     SendSDO(0x3007, 0, string('S', 'Y', 'N', 'C'));
     319    SendSDO(0x3007, 0, string('s', 'y', 'n', 'c'));
    264320    WaitForSdo(0x3007, 0);
    265321}
     
    272328    //
    273329    lout << "- Setting Pos Sync Mode #" << (int)GetId() << endl;
    274     SendSDO(0x3007, 1, string('S', 'Y', 'N', 'C'));
     330    SendSDO(0x3007, 1, string('s', 'y', 'n', 'c'));
    275331    WaitForSdo(0x3007, 1);
    276332}
     
    403459    switch (GetError())
    404460    {
    405     case  6: // home
    406     case  8: // control dev
    407     case  9: // zero idx
    408     case 84: // ON TIME
     461    case   6: // home
     462    case   8: // control dev
     463    case   9: // zero idx
     464    case  84: // ON TIME
     465    case 100: // timeout
    409466        // Stop program?
    410467        return;
     
    457514    WaitForSdo(0x2000, 3);
    458515}
     516
     517Bool_t Macs::HandleTimer(TTimer *t)
     518{
     519    /*
     520     Fons:
     521     -----
     522
     523     timers never trigger at the same time or when in a TTimer::Notify.
     524     Little explanation:
     525
     526     - there are two types of timers synchronous and a-synchronous.
     527     - synchronous timers are only handled via the ROOT eventloop
     528       (see TUnixSystem::DispatchOneEvent()). If there are no mouse/keyboard
     529       events then the synchronous timer queue is checked. So if the processing
     530       of a mouse/keyboard event takes a long time synchronous timers are not
     531       called for a while. To prevent this from happening one can call in long
     532       procedures gSystem->ProcessEvents(). The system schedules only the
     533       next timer in the queue when the current one's Notify() has finished.
     534     - a-synchronous timers are triggered via SIGALARM, i.e. the program is
     535       interupted and execution jumps to the Notify() function. When the
     536       notify is finished the next a-sync timer is scheduled and the system
     537       resumes from the place where it was initially interrupted. One of the
     538       things to remember when using a-sync timers is don't make any graphics
     539       calls in them. X11 is not re-entrant and it might be that the SIGALARM
     540       signal interrupted the system while being in X11. A-sync timers are best
     541       used to set flags that you can test at a convenient and controlled
     542       time.
     543       */
     544    SendSDO(0x4000);
     545    WaitForSdo(0x4000, 0, kDontWait);
     546    if (fTimerOn)
     547        fTimeout->Start(fTimeoutTime, kTRUE);
     548    return kTRUE;
     549}
  • trunk/MagicSoft/Cosy/devdrv/macs.h

    r920 r925  
    11#ifndef MACS_H
    22#define MACS_H
     3
     4#include <TObject.h>
    35
    46#include "nodedrv.h"
    57#include "base/timer.h"
    68
    7 class Macs : public NodeDrv
     9class Macs : public NodeDrv, public TObject
    810{
    911private:
     
    2224    BYTE_t   fRpmActive;
    2325
     26    TTimer  *fTimeout;
     27    Bool_t   fTimerOn;
     28    LWORD_t  fTimeoutTime;
     29
    2430    LWORD_t string(BYTE_t b0=0, BYTE_t b1=0, BYTE_t b2=0, BYTE_t b3=0)
    2531    {
    2632        return (LWORD_t)(b0<<24 | b1<<16 | b2<<8 | b3);
    2733    }
     34
     35    Bool_t HandleTimer(TTimer *t);
    2836
    2937public:
     
    7078    void StartAbsPos(LWORDS_t pos);
    7179
     80    void SetTimeoutTime(LWORD_t ms);
     81    void ReqTimeoutTime();
     82
     83    void EnableTimeout(bool enable=true, LWORDS_t ms=-1);
     84
    7285    void StopMotor();
    7386
Note: See TracChangeset for help on using the changeset viewer.