Changeset 1703


Ignore:
Timestamp:
01/14/03 12:08:46 (22 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Cosy
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Cosy/Changelog

    r1702 r1703  
    11                                                                  -*-*- END -*-*-
     2 2003/01/14 - Thomas Bretz:
     3
     4   * cosy.cc:
     5     - added output
     6   
     7   * candrv/network.[cc,h]:
     8     - small change to Start
     9     - added CheckConnections
     10
     11   * candrv/nodedrv.[h,cc]:
     12     - new Init
     13     - new CheckConnections
     14     - replaced virtual InitDevice by a common function
     15     - replaced virtual Reboot by a common function
     16     - Don't send anything to a Zombie node
     17     - Delete SDO from list in case of Zombie status instead of waiting
     18     
     19   * candrv/vmodican.cc:
     20     - Don't terminate when having a noisy network
     21   
     22   * devdrv/macs.[h,cc], devdrv/shaftencoder.[h,cc]:
     23     - added fSoftVersion
     24     - added SDO 0x100b
     25     - moved init stuff from InitDevice to Init
     26     - removed InitDevice and Reboot
     27     - added CheckConnection
     28
     29   * devdrv/shaftencoder.[h,cc]:
     30     - Don't display something when having Zombie status
     31   
     32   * main/MCosy.[h,cc]:
     33     - reworked all Zombie-stuff
     34     - implemented checking of network
     35
     36
    237
    338 2003/01/13 - Thomas Bretz:
  • trunk/MagicSoft/Cosy/candrv/network.cc

    r1702 r1703  
    237237            lout << "- Setting up Node #" << dec << i << " (";
    238238            lout << fNodes[i]->GetNodeName() << ")" << endl;
    239             fNodes[i]->InitDevice(this);
    240             if (!fNodes[i]->IsZombieNode())
     239            if (fNodes[i]->InitDevice(this))
    241240                fNodeInitialized[i] = TRUE;
    242             /*else
    243                 fNodes[i]=NULL;*/
     241            else
     242                lout << "- " << fNodes[i]->GetNodeName() << ": InitDevice failed." << endl;
    244243        }
    245244    lout << "- All Nodes setup." << endl;
     
    310309bool Network::RebootZombies()
    311310{
     311    bool rc = true;
     312
    312313    lout << "- Trying to reboot all Zombies..." << endl;
    313314    for (int i=0; i<32; i++)
     
    317318                {
    318319                    lout << "- Failed to reboot " << fNodes[i]->GetNodeName() << "." << endl;
    319                     return false;
     320                    rc = false;
    320321                }
    321322
    322     lout << "- All Zombies rebooted." << endl;
    323 
    324     return true;
    325 }
     323    if (rc)
     324        lout << "- All Zombies rebooted." << endl;
     325
     326    return rc;
     327}
     328
     329// --------------------------------------------------------------------------
     330//
     331// Check the connections to all nodes. (This can also mean: Validate
     332// the correct setup, etc)
     333//
     334void Network::CheckConnections()
     335{
     336    for (int i=0; i<32; i++)
     337        if (fNodes[i])
     338            fNodes[i]->CheckConnection();
     339}
     340
  • trunk/MagicSoft/Cosy/candrv/network.h

    r1702 r1703  
    3535
    3636    bool RebootZombies();
     37    void CheckConnections();
    3738
    3839    ClassDef(Network, 0) // collection of nodes (nodedrv)
  • trunk/MagicSoft/Cosy/candrv/nodedrv.cc

    r1702 r1703  
    3030//
    3131// to be overloaded:
    32 //  virtual void InitDevice(Network *net)
     32//  virtual void Init()
    3333//  virtual void StopDevice()
    3434//  virtual void HandleSDO(WORD_t idx, BYTE_t subidx, LWORD_t val, timeval_t *tv)
     
    3939//  virtual void HandlePDO3(BYTE_t *data, timeval_t *tv)
    4040//  virtual void HandlePDO4(BYTE_t *data, timeval_t *tv)
     41//  virtual bool Reboot();
     42//  virtual void CheckConnection();
    4143//
    4244///////////////////////////////////////////////////////////////////////
     
    5658// and the node name. The name is a name for debug output.
    5759//
    58 NodeDrv::NodeDrv(BYTE_t nodeid, const char *name, MLog &out) : Log(out), fNetwork(NULL), fId(32), fError(0), fIsZombie(kFALSE)
     60NodeDrv::NodeDrv(BYTE_t nodeid, const char *name, MLog &out) : Log(out), fNetwork(NULL), fId(32), fError(0), fIsZombie(kTRUE)
    5961{
    6062    if (nodeid>0x1f)
     
    9395{
    9496    fIsZombie = false;
    95     return true;
     97
     98    Init();
     99
     100    return !fIsZombie;
    96101}
    97102
     
    107112//   SDO tx
    108113//
    109 void NodeDrv::InitDevice(Network *net)
     114bool NodeDrv::InitDevice(Network *net)
    110115{
    111116    fNetwork = net;
     
    117122    EnableCanMsg(kSDO_RX);
    118123    EnableCanMsg(kSDO_TX);
     124
     125    fIsZombie = kFALSE;
     126
     127    Init();
     128
     129    return !fIsZombie;
    119130}
    120131
     
    165176// A PDO is carrying up to eight bytes of information.
    166177//
    167 void NodeDrv::SendPDO1(BYTE_t data[8])
    168 {
    169     fNetwork->SendPDO1(fId, data);
     178// The message is not send if the node has the status Zombie.
     179// In this case false is returned, otherwise true
     180//
     181bool NodeDrv::SendPDO1(BYTE_t data[8])
     182{
     183    if (!fIsZombie)
     184        fNetwork->SendPDO1(fId, data);
     185    return !fIsZombie;
    170186}
    171187
     
    175191// A PDO is carrying up to eight bytes of information.
    176192//
    177 void NodeDrv::SendPDO2(BYTE_t data[8])
    178 {
    179     fNetwork->SendPDO2(fId, data);
     193// The message is not send if the node has the status Zombie.
     194// In this case false is returned, otherwise true
     195//
     196bool NodeDrv::SendPDO2(BYTE_t data[8])
     197{
     198    if (!fIsZombie)
     199        fNetwork->SendPDO2(fId, data);
     200    return !fIsZombie;
    180201}
    181202
     
    185206// A PDO is carrying up to eight bytes of information.
    186207//
    187 void NodeDrv::SendPDO1(BYTE_t m0=0, BYTE_t m1=0, BYTE_t m2=0, BYTE_t m3=0,
     208// The message is not send if the node has the status Zombie.
     209// In this case false is returned, otherwise true
     210//
     211bool NodeDrv::SendPDO1(BYTE_t m0=0, BYTE_t m1=0, BYTE_t m2=0, BYTE_t m3=0,
    188212                       BYTE_t m4=0, BYTE_t m5=0, BYTE_t m6=0, BYTE_t m7=0)
    189213{
    190     fNetwork->SendPDO1(fId, m0, m1, m2, m3, m4, m5, m6, m7);
     214    if (!fIsZombie)
     215        fNetwork->SendPDO1(fId, m0, m1, m2, m3, m4, m5, m6, m7);
     216    return !fIsZombie;
    191217}
    192218
     
    196222// A PDO is carrying up to eight bytes of information.
    197223//
    198 void NodeDrv::SendPDO2(BYTE_t m0=0, BYTE_t m1=0, BYTE_t m2=0, BYTE_t m3=0,
     224// The message is not send if the node has the status Zombie.
     225// In this case false is returned, otherwise true
     226//
     227bool NodeDrv::SendPDO2(BYTE_t m0=0, BYTE_t m1=0, BYTE_t m2=0, BYTE_t m3=0,
    199228                       BYTE_t m4=0, BYTE_t m5=0, BYTE_t m6=0, BYTE_t m7=0)
    200229{
    201     fNetwork->SendPDO2(fId, m0, m1, m2, m3, m4, m5, m6, m7);
    202 }
    203 
    204 // --------------------------------------------------------------------------
    205 //
    206 // Sends the given SDO through the network to this device
    207 // An SDO message contains
    208 //  an address (this device)
    209 //  an index of the dictionary entry to address
    210 //  a subindex of this dictionary entry to access
    211 //  and a value to set for this dictionary entry
    212 //
    213 void NodeDrv::SendSDO(WORD_t idx, BYTE_t subidx, BYTE_t val, bool store)
    214 {
    215     fNetwork->SendSDO(fId, idx, subidx, val, store);
    216 }
    217 
    218 // --------------------------------------------------------------------------
    219 //
    220 // Sends the given SDO through the network to this device
    221 // An SDO message contains
    222 //  an address (this device)
    223 //  an index of the dictionary entry to address
    224 //  a subindex of this dictionary entry to access
    225 //  and a value to set for this dictionary entry
    226 //
    227 void NodeDrv::SendSDO(WORD_t idx, BYTE_t subidx, WORD_t val, bool store)
    228 {
    229     fNetwork->SendSDO(fId, idx, subidx, val, store);
    230 }
    231 
    232 // --------------------------------------------------------------------------
    233 //
    234 // Sends the given SDO through the network to this device
    235 // An SDO message contains
    236 //  an address (this device)
    237 //  an index of the dictionary entry to address
    238 //  a subindex of this dictionary entry to access
    239 //  and a value to set for this dictionary entry
    240 //
    241 void NodeDrv::SendSDO(WORD_t idx, BYTE_t subidx, LWORD_t val, bool store)
    242 {
    243     fNetwork->SendSDO(fId, idx, subidx, val, store);
    244 }
    245 
    246 // --------------------------------------------------------------------------
    247 //
    248 // Sends the given SDO through the network to this device
    249 // An SDO message contains
    250 //  an address (this device)
    251 //  an index of the dictionary entry to address
    252 //  a subindex of this dictionary entry to access
    253 //  and a value to set for this dictionary entry
    254 //
    255 void NodeDrv::SendSDO(WORD_t idx, BYTE_t val)
    256 {
    257     fNetwork->SendSDO(fId, idx, val, true);
    258 }
    259 
    260 // --------------------------------------------------------------------------
    261 //
    262 // Sends the given SDO through the network to this device
    263 // An SDO message contains
    264 //  an address (this device)
    265 //  an index of the dictionary entry to address
    266 //  a subindex of this dictionary entry to access
    267 //  and a value to set for this dictionary entry
    268 //
    269 void NodeDrv::SendSDO(WORD_t idx, WORD_t val)
    270 {
    271     fNetwork->SendSDO(fId, idx, val, true);
    272 }
    273 
    274 // --------------------------------------------------------------------------
    275 //
    276 // Sends the given SDO through the network to this device
    277 // An SDO message contains
    278 //  an address (this device)
    279 //  an index of the dictionary entry to address
    280 //  a subindex of this dictionary entry to access
    281 //  and a value to set for this dictionary entry
    282 //
    283 void NodeDrv::SendSDO(WORD_t idx, LWORD_t val)
    284 {
    285     fNetwork->SendSDO(fId, idx, val, true);
     230    if (!fIsZombie)
     231        fNetwork->SendPDO2(fId, m0, m1, m2, m3, m4, m5, m6, m7);
     232    return !fIsZombie;
     233}
     234
     235// --------------------------------------------------------------------------
     236//
     237// Sends the given SDO through the network to this device
     238// An SDO message contains
     239//  an address (this device)
     240//  an index of the dictionary entry to address
     241//  a subindex of this dictionary entry to access
     242//  and a value to set for this dictionary entry
     243//
     244// The message is not send if the node has the status Zombie.
     245// In this case false is returned, otherwise true
     246//
     247bool NodeDrv::SendSDO(WORD_t idx, BYTE_t subidx, BYTE_t val, bool store)
     248{
     249    if (!fIsZombie)
     250        fNetwork->SendSDO(fId, idx, subidx, val, store);
     251    return !fIsZombie;
     252}
     253
     254// --------------------------------------------------------------------------
     255//
     256// Sends the given SDO through the network to this device
     257// An SDO message contains
     258//  an address (this device)
     259//  an index of the dictionary entry to address
     260//  a subindex of this dictionary entry to access
     261//  and a value to set for this dictionary entry
     262//
     263// The message is not send if the node has the status Zombie.
     264// In this case false is returned, otherwise true
     265//
     266bool NodeDrv::SendSDO(WORD_t idx, BYTE_t subidx, WORD_t val, bool store)
     267{
     268    if (!fIsZombie)
     269        fNetwork->SendSDO(fId, idx, subidx, val, store);
     270    return !fIsZombie;
     271}
     272
     273// --------------------------------------------------------------------------
     274//
     275// Sends the given SDO through the network to this device
     276// An SDO message contains
     277//  an address (this device)
     278//  an index of the dictionary entry to address
     279//  a subindex of this dictionary entry to access
     280//  and a value to set for this dictionary entry
     281//
     282// The message is not send if the node has the status Zombie.
     283// In this case false is returned, otherwise true
     284//
     285bool NodeDrv::SendSDO(WORD_t idx, BYTE_t subidx, LWORD_t val, bool store)
     286{
     287    if (!fIsZombie)
     288        fNetwork->SendSDO(fId, idx, subidx, val, store);
     289    return !fIsZombie;
     290}
     291
     292// --------------------------------------------------------------------------
     293//
     294// Sends the given SDO through the network to this device
     295// An SDO message contains
     296//  an address (this device)
     297//  an index of the dictionary entry to address
     298//  a subindex of this dictionary entry to access
     299//  and a value to set for this dictionary entry
     300//
     301// The message is not send if the node has the status Zombie.
     302// In this case false is returned, otherwise true
     303//
     304bool NodeDrv::SendSDO(WORD_t idx, BYTE_t val)
     305{
     306    if (!fIsZombie)
     307        fNetwork->SendSDO(fId, idx, val, true);
     308    return !fIsZombie;
     309}
     310
     311// --------------------------------------------------------------------------
     312//
     313// Sends the given SDO through the network to this device
     314// An SDO message contains
     315//  an address (this device)
     316//  an index of the dictionary entry to address
     317//  a subindex of this dictionary entry to access
     318//  and a value to set for this dictionary entry
     319//
     320// The message is not send if the node has the status Zombie.
     321// In this case false is returned, otherwise true
     322//
     323bool NodeDrv::SendSDO(WORD_t idx, WORD_t val)
     324{
     325    if (!fIsZombie)
     326        fNetwork->SendSDO(fId, idx, val, true);
     327    return !fIsZombie;
     328}
     329
     330// --------------------------------------------------------------------------
     331//
     332// Sends the given SDO through the network to this device
     333// An SDO message contains
     334//  an address (this device)
     335//  an index of the dictionary entry to address
     336//  a subindex of this dictionary entry to access
     337//  and a value to set for this dictionary entry
     338//
     339// The message is not send if the node has the status Zombie.
     340// In this case false is returned, otherwise true
     341//
     342bool NodeDrv::SendSDO(WORD_t idx, LWORD_t val)
     343{
     344    if (!fIsZombie)
     345        fNetwork->SendSDO(fId, idx, val, true);
     346    return !fIsZombie;
    286347}
    287348
     
    294355//  a subindex of this dictionary entry to access
    295356//
    296 void NodeDrv::RequestSDO(WORD_t idx, BYTE_t subidx)
    297 {
    298     fNetwork->RequestSDO(fId, idx, subidx);
     357// The message is not send if the node has the status Zombie.
     358// In this case false is returned, otherwise true
     359//
     360bool NodeDrv::RequestSDO(WORD_t idx, BYTE_t subidx)
     361{
     362    if (!fIsZombie)
     363        fNetwork->RequestSDO(fId, idx, subidx);
     364    return !fIsZombie;
    299365}
    300366
     
    303369// Send an NMT message (command) to this device
    304370//
    305 void NodeDrv::SendNMT(BYTE_t cmd)
    306 {
    307     fNetwork->SendNMT(fId, cmd);
     371// The message is not send if the node has the status Zombie.
     372// In this case false is returned, otherwise true
     373//
     374bool NodeDrv::SendNMT(BYTE_t cmd)
     375{
     376    if (!fIsZombie)
     377        fNetwork->SendNMT(fId, cmd);
     378    return !fIsZombie;
    308379}
    309380
     
    323394// You can stop waiting by StopWaitingForSDO.
    324395// Return false if waiting timed out.
     396// If waiting timed out the node is set to status Zombie.
     397//
     398// If the node is already a zombie node, the message is deleted from the
     399// queue and no waiting is done, false is returned..
    325400//
    326401bool NodeDrv::WaitForSdo(WORD_t idx, BYTE_t subidx, WORDS_t timeout)
    327402{
    328     bool rc = fNetwork->WaitForSdo(fId, idx, subidx, timeout);
     403    bool rc = fNetwork->WaitForSdo(fId, idx, subidx, fIsZombie?-1:timeout);
    329404
    330405    if (!rc)
    331406        fIsZombie = kTRUE;
    332407
    333     return rc;
     408    return fIsZombie ? false : rc;
    334409}
    335410
  • trunk/MagicSoft/Cosy/candrv/nodedrv.h

    r1702 r1703  
    4444    Network    *GetNetwork()        { return fNetwork; }
    4545
    46     virtual void InitDevice(Network *net);
     46    virtual void Init() = 0;
     47    virtual bool InitDevice(Network *net);
    4748    virtual void StopDevice() = 0;
     49    virtual bool Reboot();
     50    virtual void CheckConnection() = 0;
    4851
    4952    int  GetError() const { return fError; }
     
    6164    virtual void HandlePDO4(BYTE_t *data, timeval_t *tv) {};
    6265
    63     virtual bool Reboot();
    64 
    65     void SendPDO1(BYTE_t data[8]);
    66     void SendPDO2(BYTE_t data[8]);
    67     void SendPDO1(BYTE_t m0=0, BYTE_t m1=0, BYTE_t m2=0, BYTE_t m3=0,
     66    bool SendPDO1(BYTE_t data[8]);
     67    bool SendPDO2(BYTE_t data[8]);
     68    bool SendPDO1(BYTE_t m0=0, BYTE_t m1=0, BYTE_t m2=0, BYTE_t m3=0,
    6869                  BYTE_t m4=0, BYTE_t m5=0, BYTE_t m6=0, BYTE_t m7=0);
    69     void SendPDO2(BYTE_t m0=0, BYTE_t m1=0, BYTE_t m2=0, BYTE_t m3=0,
     70    bool SendPDO2(BYTE_t m0=0, BYTE_t m1=0, BYTE_t m2=0, BYTE_t m3=0,
    7071                  BYTE_t m4=0, BYTE_t m5=0, BYTE_t m6=0, BYTE_t m7=0);
    7172
    72     void SendSDO(WORD_t idx, BYTE_t subidx, BYTE_t val, bool store=true);
    73     void SendSDO(WORD_t idx, BYTE_t subidx, WORD_t val, bool store=true);
    74     void SendSDO(WORD_t idx, BYTE_t subidx, LWORD_t val, bool store=true);
     73    bool SendSDO(WORD_t idx, BYTE_t subidx, BYTE_t val, bool store=true);
     74    bool SendSDO(WORD_t idx, BYTE_t subidx, WORD_t val, bool store=true);
     75    bool SendSDO(WORD_t idx, BYTE_t subidx, LWORD_t val, bool store=true);
    7576
    76     void SendSDO(WORD_t idx, BYTE_t val);
    77     void SendSDO(WORD_t idx, WORD_t val);
    78     void SendSDO(WORD_t idx, LWORD_t val=0);
     77    bool SendSDO(WORD_t idx, BYTE_t val);
     78    bool SendSDO(WORD_t idx, WORD_t val);
     79    bool SendSDO(WORD_t idx, LWORD_t val=0);
    7980
    80     void SendNMT(BYTE_t cmd);
     81    bool SendNMT(BYTE_t cmd);
    8182
    82     void RequestSDO(WORD_t idx, BYTE_t subidx=0);
     83    bool RequestSDO(WORD_t idx, BYTE_t subidx=0);
    8384
    8485    void WaitForNextPdo1();
  • trunk/MagicSoft/Cosy/candrv/vmodican.cc

    r1702 r1703  
    232232                cout << "TxErrCnt=" << (int)msg->data[5] << endl;
    233233            }
    234             TerminateApp();
     234            //FIXME? TerminateApp();
    235235            return;
    236236        case 0x02:
  • trunk/MagicSoft/Cosy/cosy.cc

    r1702 r1703  
    2323int main(int argc, char **argv)
    2424{
     25    gLog << "==================================================" << endl;
     26    gLog << "                    Cosy V0.1                     " << endl;
     27    gLog << "       Magic Drive Control System Softwware       " << endl;
     28    gLog << "            Compiled on <" << __DATE__ << ">"       << endl;
     29    gLog << "               Using ROOT v" << ROOTVER             << endl;
     30    gLog << "==================================================" << endl;
     31    gLog << endl;
     32
    2533    Timer time;
    2634    time.Now();
  • trunk/MagicSoft/Cosy/devdrv/macs.cc

    r1702 r1703  
    4848    case 0x100a:
    4949        lout << "- " << GetNodeName() << ": Using Software Version V" << dec << (int)(val>>16) << "." << (int)(val&0xff) << endl;
     50        fSoftVersion = val;
     51        return;
     52
     53    case 0x100b:
     54        // Do not display, this is used for CheckConnection
     55        // lout << "Node ID: " << dec << val << endl;
    5056        return;
    5157
     
    221227}
    222228
    223 void Macs::InitDevice(Network *net)
    224 {
    225     lout << "- " << GetNodeName() << ": MAC Init device." << endl;
    226     NodeDrv::InitDevice(net);
    227     lout << "- " << GetNodeName() << ": MAC Init device...done." << endl;
    228 
    229 //    SendSDO(0x4003, (LWORD_t)('E'<<24 | 'X'<<16 | 'I'<<8 'T'));
    230 //    WaitForSdo(0x4003, 0);
    231 
    232 /*
    233     lout << "- Requesting SDO 0x2002 (vel) of " << (int)GetId() << endl;
    234     RequestSDO(0x2002);
    235     WaitForSdo(0x2002);
    236 
    237     lout << "- Requesting SDO 0x2003 of " << (int)GetId() << endl;
    238     RequestSDO(0x2003);
    239     WaitForSdo(0x2003);
    240 
    241     lout << "- Requesting SDO 0x2004 of " << (int)GetId() << endl;
    242     RequestSDO(0x2004);
    243     WaitForSdo(0x2004);
    244     */
     229void Macs::CheckConnection()
     230{
     231    RequestSDO(0x100b);
     232    WaitForSdo(0x100b);
     233
     234    // FIXME! Not statically linked!
     235    //    if (fSoftVersion<0x00000035)
     236    //        fIsZombie = true;
     237}
     238
     239
     240void Macs::Init()
     241{
    245242    lout << "- " << GetNodeName() << ": Requesting Mac Software Version." << endl;
    246243    RequestSDO(0x100a);
    247244    WaitForSdo(0x100a);
    248245
    249     if (IsZombie())
    250         return;
     246    if (fIsZombie)
     247    {
     248        lout << GetNodeName() << " - InitDevice failed!" << endl;
     249        return;
     250    }
    251251
    252252    EnableTimeout(kFALSE);
     
    259259    SendSDO(0x3000, string('o', 'n'));
    260260    WaitForSdo(0x3000);
    261 
    262261
    263262//    SetHome(250000);
     
    413412    // or by a positioning command (POSA, ...)
    414413    //
    415     lout << "- " << GetNodeName() << ": Starting Posistion Sync Mode." << endl;
     414    lout << "- " << GetNodeName() << ": Starting Position Sync Mode." << endl;
    416415    SendSDO(0x3007, 1, string('s', 'y', 'n', 'c'));
    417416    WaitForSdo(0x3007, 1);
     
    547546}
    548547
     548// FIXME? Handling of fIsZombie?
    549549void Macs::HandleError()
    550550{
  • trunk/MagicSoft/Cosy/devdrv/macs.h

    r1702 r1703  
    1111private:
    1212    BYTE_t   fMacId;
     13
     14    LWORD_t  fSoftVersion;
    1315
    1416    LWORD_t  fVelRes;
     
    4143    Bool_t HandleTimer(TTimer *t);
    4244
     45    void Init();
     46    //bool Reboot();
     47
     48    //bool InitDevice(Network *);
     49
     50    //void StartDevice();
     51    void StopDevice();
     52
     53    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); }
     56
     57    void HandlePDO1(BYTE_t *data, timeval_t *tv);
     58    void HandlePDO2(BYTE_t *data, timeval_t *tv);
     59
     60    void CheckConnection();
     61
    4362public:
     63    enum
     64    {
     65        kNoSync = BIT(0),
     66        kPosSync = BIT(1),
     67        kVelSync = BIT(2)
     68    };
    4469    enum
    4570    {
     
    5479    Macs(const BYTE_t nodeid, const char *name=NULL, MLog &out=gLog);
    5580    virtual ~Macs();
    56 
    57     void InitDevice(Network *);
    58 
    59     //void StartDevice();
    60     void StopDevice();
    61 
    62     void HandleSDO(WORD_t idx, BYTE_t subidx, LWORD_t val, timeval_t *tv);
    63     void HandleSDOOK(WORD_t idx, BYTE_t subidx);
    64     void HandleSDOError(LWORD_t data)           { NodeDrv::HandleSDOError(data); }
    65 
    66     void HandlePDO1(BYTE_t *data, timeval_t *tv);
    67     void HandlePDO2(BYTE_t *data, timeval_t *tv);
    6881
    6982    void SendMsg(BYTE_t data[6]);
  • trunk/MagicSoft/Cosy/devdrv/shaftencoder.cc

    r1701 r1703  
    5151        }
    5252    case 0x100b:
    53         lout << "Node ID: " << dec << val << endl;
     53        // Do not display, this is used for CheckConnection
     54        // lout << "Node ID: " << dec << val << endl;
    5455        return;
    5556
     
    9495void ShaftEncoder::DisplayVal()
    9596{
     97    if (fIsZombie)
     98    {
     99        fLabel[0]->SetText(new TGString(""));
     100        fLabel[1]->SetText(new TGString(""));
     101        fLabel[2]->SetText(new TGString(""));
     102        fUpdPos = ~fPos;
     103        fUpdVel = ~fVel;
     104        fUpdAcc = ~fAcc;
     105        return;
     106    }
     107
    96108    char text[21];
    97109
     
    190202}
    191203
    192 void ShaftEncoder::InitDevice(Network *net)
    193 {
    194     NodeDrv::InitDevice(net);
    195 
     204void ShaftEncoder::Init()
     205{
    196206    //-----------------------------------------------------------------------
    197207    //                    Start Setup of the Shaft Encoder
     
    203213    lout << "- " << GetNodeName() << ": Requesting Hardware Type (0x1000)." << endl;
    204214    RequestSDO(0x1000);
    205     if (!WaitForSdo(0x1000))
    206     {
    207         lout << "  ... failed." << endl;
    208         fIsZombie = true;
     215    WaitForSdo(0x1000);
     216
     217    if (fIsZombie)
     218    {
     219        lout << GetNodeName() << " - Init failed!" << endl;
    209220        return;
    210221    }
     
    265276}
    266277
     278void ShaftEncoder::CheckConnection()
     279{
     280    // Request Node number
     281    RequestSDO(0x100b);
     282    WaitForSdo(0x100b);
     283}
     284/*
     285bool 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//
     299bool ShaftEncoder::Reboot()
     300{
     301    fIsZombie = false;
     302
     303    Init();
     304
     305    return !fIsZombie;
     306}
     307*/
     308
    267309void ShaftEncoder::ReqPos()
    268310{
     
    277319void ShaftEncoder::SetPreset(LWORD_t pre)
    278320{
     321    lout << "- " << GetNodeName() << ": Setting Preset." << endl;
     322
     323    SendSDO(0x6003, (LWORD_t)fPos);
     324    if (!WaitForSdo(0x6003))
     325        return;
     326
    279327    fPos  = pre%16384;
    280328    fTurn = pre/16384;
    281 
    282     lout << "- " << GetNodeName() << ": Setting Preset." << endl;
    283     SendSDO(0x6003, (LWORD_t)fPos);
    284     WaitForSdo(0x6003);
    285329}
    286330
  • trunk/MagicSoft/Cosy/devdrv/shaftencoder.h

    r1690 r1703  
    3232    void ReqPos();
    3333
     34    void Init();
     35    void CheckConnection();
     36
    3437public:
    3538    ShaftEncoder(const BYTE_t nodeid, const char *name=NULL, MLog &out=gLog);
    3639    virtual ~ShaftEncoder();
    3740
    38     void InitDevice(Network *);
     41    //bool InitDevice(Network *);
     42    //bool Reboot();
    3943
    4044    //void StartDevice();
     
    5054    void HandlePDO2(BYTE_t *data, timeval_t *tv) { HandlePDOType2(data, tv); }
    5155
    52     LWORDS_t GetPos() { return fPos+fTurn*fTicks; }
     56    LWORDS_t GetPos() { return fIsZombie ? 0 : fPos+fTurn*fTicks; } // FIXME? 0?
    5357    LWORD_t  GetPhysRes() { return fTicks; }
    5458
  • trunk/MagicSoft/Cosy/main/MCosy.cc

    r1702 r1703  
    4141//const XY kGearRatio2(GEAR_RATIO_ALT*RES_RE/360.0,  GEAR_RATIO_AZ*RES_RE/360.0);    //[re/deg]
    4242
     43/* +===================================+
     44    FIXME: What if fMac3 (Sync) died?
     45   +===================================+
     46*/
     47
    4348double MCosy::Rad2SE(double rad) const
    4449{
     
    150155    // Get the values
    151156    //
    152     const int p0 = !fZd1->IsZombieNode() ? fZd1->GetPos() : 0;
    153     const int p1 = !fZd2->IsZombieNode() ? fZd2->GetPos() : 0;
    154     const int p2 = !fAz->IsZombieNode()  ? fAz->GetPos()  : 0;
    155 
    156     const int a0 = p0; //p0>8192?p0-16384:p0;
    157     const int a1 = p1; //p1>8192?p1-16384:p1;
    158     const int a2 = p2; //p2>8192?p2-16384:p2;
     157    const int p0 = fZd1->GetPos();
     158    const int p1 = fZd2->GetPos();
     159    const int p2 = fAz->GetPos();
    159160
    160161    //
    161162    // interpolate shaft encoder positions
    162163    //
    163     const float a = (float)(a0-a1)/2;
     164    const float p = (float)(p0-p1)/2;
    164165
    165166    //
    166167    // calculate 'regelabweichung'
    167168    //
    168     return ZdAz(a, a2);
     169    return ZdAz(p, p2);
    169170}
    170171
     
    177178Bool_t MCosy::RequestRePos()
    178179{
    179     if (fMac1->IsZombieNode() || fMac2->IsZombieNode())
    180         return kTRUE;
    181 
    182180    //
    183181    // Send request
     
    189187    // Wait until the objects are received.
    190188    //
     189    // FIXME, what when waiting times out (Zombie)
    191190    WaitForSdos();
    192191
     
    194193    // If waiting was not interrupted everything is ok. return.
    195194    //
    196     if (!StopWaitingForSDO())
     195    if (!StopWaitingForSDO() && !HasZombie())
    197196        return kTRUE;
    198197
     
    216215ZdAz MCosy::GetRePos()
    217216{
    218     return !fMac1->IsZombieNode() && !fMac2->IsZombieNode() ? ZdAz(fMac2->GetPos(), fMac1->GetPos()) : ZdAz(0,0);
     217    return ZdAz(fMac2->GetPos(), fMac1->GetPos());
    219218}
    220219
     
    304303int MCosy::StopWaitingForSDO() const
    305304{
    306     return Break() || HasError() || HasZombie();
     305    return Break() || HasError();
    307306}
    308307
     
    316315void MCosy::WaitForEndMovement()
    317316{
     317    // FIXME, what when waiting times out (Zombie)
    318318    WaitForSdos();
    319319
    320     while ((fMac1->IsPositioning() || fMac2->IsPositioning()) && !StopWaitingForSDO())
     320    while ((fMac1->IsPositioning() || fMac2->IsPositioning()) && !StopWaitingForSDO() && !HasZombie())
    321321        usleep(1);
    322322}
     
    378378    // FIXME: Correct by fOffset ?
    379379
     380    /*
    380381    if (fMac1->IsZombieNode() || fMac2->IsZombieNode())
    381382    {
     
    383384        return TRUE;
    384385    }
     386    */
     387
     388    //
     389    // Make sure that the motors are in sync mode (necessary if the
     390    // MACS has been rebooted from a Zombie state.
     391    //
     392    InitSync();
     393    if (fMac3->IsZombieNode())
     394        return false;
    385395
    386396    //
    387397    // Calculate new target position (shortest distance to go)
    388398    //
    389     const ZdAz src = GetSePos();//*TMath::Pi()*2/16384;;
     399    const ZdAz src = GetSePos();
    390400
    391401    //
     
    404414    cout << "Shortest Dest Zd: " << dest.Zd() << "se  Az:" << dest.Az() << "se" << endl;
    405415
    406     for (int i=0; i<10 && !StopWaitingForSDO(); i++)
     416    for (int i=0; i<10 && !StopWaitingForSDO() && !HasZombie(); i++)
    407417    {
    408418        //
     
    450460
    451461        rd.Round();
     462
     463        // FIXME? Check for Error or Zombie?
    452464
    453465        /*
     
    477489// in case of success, kFALSE in case of failure.
    478490//
    479 Bool_t MCosy::SetVelocity(ZdAz v)
     491Bool_t MCosy::SetVelocity(const ZdAz &v)
    480492{
    481493    //
     
    488500    // Wait for the objects to be OKed.
    489501    //
     502    // FIXME, what when waiting times out (Zombie)
    490503    WaitForSdos();
    491504
     
    493506    // If the waiting for the objects wasn't interrupted return kTRUE
    494507    //
    495     if (!StopWaitingForSDO())
     508    if (!StopWaitingForSDO() && !HasZombie())
    496509        return kTRUE;
    497510
     
    513526// revolution mode.
    514527//
    515 void MCosy::InitTracking()
    516 {
     528bool MCosy::InitTracking()
     529{
     530    // FIXME? Handling of Zombie OK?
    517531    if (fMac1->IsZombieNode() || fMac2->IsZombieNode())
    518         return;
     532        return false;
    519533
    520534    //
     
    523537    fMac2->SetAcceleration(0.90*fMac2->GetVelRes());
    524538    fMac2->SetDeceleration(0.90*fMac2->GetVelRes());
     539    if (fMac2->IsZombieNode())
     540        return false;
    525541
    526542    fMac1->SetAcceleration(0.90*fMac1->GetVelRes());
    527543    fMac1->SetDeceleration(0.90*fMac1->GetVelRes());
     544    if (fMac1->IsZombieNode())
     545        return false;
    528546
    529547    SetStatus(MCosy::kMoving | MCosy::kTracking);
    530548
    531549    fMac2->SetRpmMode(TRUE);
     550    if (fMac2->IsZombieNode())
     551        return false;
     552
    532553    fMac1->SetRpmMode(TRUE);
     554    if (fMac1->IsZombieNode())
     555        return false;
     556
     557    return true;
    533558}
    534559
     
    640665    // Init accelerations and Rpm Mode
    641666    //
    642     InitTracking();
     667    if (!InitTracking())
     668        return;
    643669
    644670    XY xy(Rad2Deg(dst.Ra())*24/360, Rad2Deg(dst.Dec()));
     
    655681    //
    656682    fRaDec = dst;
    657 
    658     if (fMac1->IsZombieNode() || fMac2->IsZombieNode())
    659         return;
    660 
    661683    fTracking = kTRUE;
    662684
     
    671693    //
    672694    const float dt = 1;  // 1 second
    673     while (!StopWaitingForSDO())
     695    while (!StopWaitingForSDO() && !HasZombie())
    674696    {
    675697        //
     
    774796void MCosy::StopMovement()
    775797{
    776     if (fMac1->IsZombieNode() || fMac2->IsZombieNode())
    777         return;
    778 
    779798    //
    780799    // Set status to Stopping
     
    785804    // set deceleration to 50%
    786805    //
    787     cout << "Stopping  positioning..." << endl;
     806    cout << "Stopping..." << endl;
    788807    fMac1->SetDeceleration(0.5*fMac1->GetVelRes());
     808    if (!fMac1->IsZombieNode())
     809        fMac1->SetRpmMode(FALSE);
     810
    789811    fMac2->SetDeceleration(0.5*fMac2->GetVelRes());
    790 
    791     //
    792     // Stop revolution mode (movement)
    793     //
    794     cout << "Stopping possibleRPM mode..." << endl;
    795     fMac1->SetRpmMode(FALSE);
    796     fMac2->SetRpmMode(FALSE);
     812    if (!fMac2->IsZombieNode())
     813        fMac2->SetRpmMode(FALSE);
    797814
    798815    //
     
    809826}
    810827
    811 void *MCosy::Proc(int msg, void *mp)
    812 {
    813     lout << "Checking for Zombies" << endl;
     828bool MCosy::CheckNetwork()
     829{
     830    CheckConnections();
    814831    if (HasZombie())
    815832    {
    816         lout << "Found Zombies" << endl;
     833        lout << "- Found Zombies in Network..." << endl;
    817834        if (!RebootZombies())
    818             return (void*)0xebb0;
     835            return false;
    819836    }
    820 
     837    return true;
     838}
     839
     840void *MCosy::Proc(int msg, void *mp)
     841{
    821842    switch (msg)
    822843    {
     
    827848    case WM_STOP:
    828849        cout << "MCosy::Proc: Stop." << endl;
     850        if (!CheckNetwork())
     851            return (void*)0xebb0;
    829852        StopMovement();
    830853        return NULL;
     
    832855    case WM_PRESET:
    833856        cout << "WM_Preset: start." << endl;
    834         if (!fZd1->IsZombieNode()) fZd1->SetPreset();
    835         if (!fZd2->IsZombieNode()) fZd2->SetPreset();
    836         if (!fAz->IsZombieNode())  fAz->SetPreset();
     857        if (!CheckNetwork())
     858            return (void*)0xebb0;
     859        fZd1->SetPreset();
     860        fZd2->SetPreset();
     861        fAz->SetPreset();
    837862        cout << "WM_Preset: done. (return 0xaffe)" << endl;
    838863        return (void*)0xaffe;
     
    841866        {
    842867            cout << "WM_Calib: start." << endl;
     868            if (!CheckNetwork())
     869                return (void*)0xebb0;
     870
    843871            SlaStars sla;
    844872            sla.SetMjd2Now();
     
    858886            cout << "Got  Zd: " << sepos.Zd() << " Az: " << sepos.Az() << endl;
    859887
    860             if (!fZd1->IsZombieNode())
    861                 fZd1->SetPreset(za.Zd());
    862             if (!fZd2->IsZombieNode())
    863                 fZd2->SetPreset(-za.Zd());
    864             if (!fAz->IsZombieNode())
    865                 fAz->SetPreset(za.Az());
     888            fZd1->SetPreset(za.Zd());
     889            fZd2->SetPreset(-za.Zd());
     890            fAz->SetPreset(za.Az());
    866891
    867892            cout << "WM_Calib: done. (return 0xaffe)" << endl;
     
    897922        cout << "WM_Position: start." << endl;
    898923        {
     924            if (!CheckNetwork())
     925                return (void*)0xebb0;
     926
    899927            ZdAz dest = *((ZdAz*)mp);
    900 
    901928            SetPosition(dest*kDeg2Rad);
    902929        }
     
    907934        cout << "WM_Track: START" << endl;
    908935        {
     936            if (!CheckNetwork())
     937                return (void*)0xebb0;
     938
    909939            RaDec dest = *((RaDec*)mp);
    910940            TrackPosition(dest*kDeg2Rad);
     
    933963    case WM_HOME:
    934964        cout << "WM_Home: START" << endl;
    935         if (!fMac1->IsZombieNode() && !fMac2->IsZombieNode())
     965        if (!CheckNetwork())
     966            return (void*)0xebb0;
     967        else
    936968        {
    937969            cout << "Going Home..." << endl;
     
    9761008    case WM_QUIT:
    9771009        cout << "WM_Quit: now." << endl;
     1010        if (!CheckNetwork())
     1011        {
     1012            lout << "ERROR: Cannot shutdown CANbus network." << endl;
     1013            return (void*)0xebb0;
     1014        }
    9781015        TerminateApp();
    9791016        cout << "WM_Quit: done." << endl;
     
    10041041        resreaz = fMac1->GetRes();
    10051042    else
    1006         if (!fMac3->IsZombieNode())
     1043        if (fMac3 && !fMac3->IsZombieNode())
    10071044            resreaz = fMac3->GetRes();
    10081045        else
     
    10401077}
    10411078
     1079void MCosy::InitSync()
     1080{
     1081    if (!fMac3)
     1082        return;
     1083
     1084    const int res = fMac3->GetVelRes();
     1085
     1086    fMac3->SetVelocity(res);
     1087    fMac3->SetAcceleration(res);
     1088    fMac3->SetDeceleration(res);
     1089    fMac3->StartPosSync();
     1090}
     1091
    10421092void MCosy::TalkThread()
    10431093{
    1044     if (fMac1->IsZombieNode() || fMac2->IsZombieNode())
     1094    /* ========== FIXME? =============
     1095     if (fMac1->IsZombieNode() || fMac2->IsZombieNode())
    10451096        return;
    1046 
     1097     */
    10471098    fMac1->ReqPos();
    10481099    fMac2->ReqPos();
    1049 
    1050     if (fMac3)
    1051     {
    1052         const int res = fMac3->GetVelRes();
    1053 
    1054         fMac3->SetVelocity(res);
    1055         fMac3->SetAcceleration(res);
    1056         fMac3->SetDeceleration(res);
    1057         fMac3->StartPosSync();
    1058     }
    10591100
    10601101    if (fZd1->IsZombieNode() || fZd2->IsZombieNode() || fAz->IsZombieNode())
     
    12271268    // Update Gui, foremer MTGui.
    12281269    //
    1229     if (!fZd1->IsZombieNode()) fZd1->DisplayVal();
    1230     if (!fZd2->IsZombieNode()) fZd2->DisplayVal();
    1231     if (!fAz->IsZombieNode())  fAz->DisplayVal();
     1270    fZd1->DisplayVal();
     1271    fZd2->DisplayVal();
     1272    fAz->DisplayVal();
    12321273
    12331274    ZdAz seist = GetSePos()*2*TMath::Pi()/16384; // [se]
     
    12381279    avail |= !fMac1->IsZombieNode() ? 0x01 : 0;
    12391280    avail |= !fMac2->IsZombieNode() ? 0x02 : 0;
    1240     avail |= !fMac3->IsZombieNode() ? 0x04 : 0;
     1281    avail |= (fMac3 && !fMac3->IsZombieNode()) ? 0x04 : 0;
    12411282    avail |= !fZd1->IsZombieNode()  ? 0x08 : 0;
    12421283    avail |= !fZd2->IsZombieNode()  ? 0x10 : 0;
     
    12681309    // Don't call this function twice!
    12691310    Network::Start();
    1270 /*
    1271     if (fMac1)
    1272         if (fMac1->IsZombieNode()) { delete fMac1; fMac1=NULL; }
    1273     if (fMac2)
    1274         if (fMac2->IsZombieNode()) { delete fMac2; fMac2=NULL; }
    1275     if (fMac3)
    1276         if (fMac3->IsZombieNode()) { delete fMac3; fMac3=NULL; }
    1277 */
    1278 /*    if (fZd1)
    1279         if (fZd1->IsZombieNode())  { delete fZd1;  fZd1=NULL; }
    1280         else */fZd1->SetDisplay(fWin->GetLabel2());
    1281 
    1282 /*    if (fZd2)
    1283         if (fZd2->IsZombieNode())  { delete fZd2;  fZd2=NULL; }
    1284         else */fZd2->SetDisplay(fWin->GetLabel3());
    1285 
    1286 /*    if (fAz)
    1287         if (fAz->IsZombieNode())   { delete fAz;   fAz=NULL; }
    1288         else */fAz->SetDisplay(fWin->GetLabel1());
    12891311
    12901312    ReadConfig();
     
    12921314    lout << "- Starting TX Thread." << endl;
    12931315    fTTalk = new MTTalk(this);
    1294     //    fTGui = new MTGui(this);
    12951316
    12961317    lout << "- Starting GUI update." << endl;
     
    13611382    lout << "- Starting GUI." << endl;
    13621383    fWin=new MGCosy(this, gClient->GetRoot(), 1, 1);
    1363 
    1364     fAz->SetDisplay(fWin->GetLabel1());
    1365     fZd1->SetDisplay(fWin->GetLabel2());
    1366     fZd2->SetDisplay(fWin->GetLabel3());
    1367 
    1368     lout.SetOutputGui(fWin->GetLog(), kTRUE);
    13691384}
    13701385
     
    13971412    lout << "- Starting GUI." << endl;
    13981413    fWin=new MGCosy(this, gClient->GetRoot(), 1, 1);
    1399 
    1400     fAz->SetDisplay(fWin->GetLabel1());
    1401     fZd1->SetDisplay(fWin->GetLabel2());
    1402     fZd2->SetDisplay(fWin->GetLabel3());
    1403 
    1404     lout.SetOutputGui(fWin->GetLog(), kTRUE);
    14051414}
    14061415
     
    14201429    lout << "- Starting GUI." << endl;
    14211430    fWin=new MGCosy(this, gClient->GetRoot(), 1, 1);
    1422 
    1423     lout.SetOutputGui(fWin->GetLog(), kTRUE);
    14241431}
    14251432
     
    14511458    }
    14521459
     1460    lout.SetOutputGui(fWin->GetLog(), kTRUE);
     1461
     1462    fZd1->SetDisplay(fWin->GetLabel2());
     1463    fZd2->SetDisplay(fWin->GetLabel3());
     1464    fAz->SetDisplay(fWin->GetLabel1());
     1465
    14531466    int i=0;
    14541467    char name[100];
     
    15031516    cout << "Deleting Nodes." << endl;
    15041517
    1505     if (fAz)   delete fAz;
    1506     if (fZd1)  delete fZd1;
    1507     if (fZd2)  delete fZd2;
    1508     if (fMac1) delete fMac1;
    1509     if (fMac2) delete fMac2;
    1510     if (fMac3) delete fMac3;
     1518    delete fAz;
     1519    delete fZd1;
     1520    delete fZd2;
     1521    delete fMac1;
     1522    delete fMac2;
     1523    if (fMac3)
     1524        delete fMac3;
    15111525
    15121526    cout << "Deleting MGCosy." << endl;
  • trunk/MagicSoft/Cosy/main/MCosy.h

    r1701 r1703  
    107107
    108108    Bool_t RequestRePos();
    109     Bool_t SetVelocity(ZdAz v);
     109    Bool_t SetVelocity(const ZdAz &v);
    110110    void SetPosVelocity(const Float_t ratio, Float_t vel, Float_t acc);
    111111
    112112    void DoRelPos(const ZdAz &rd, const Bool_t axe1, const Bool_t axe2);
    113113
    114     void InitTracking();
     114    void InitSync();
     115    bool InitTracking();
    115116    void LimitSpeed(ZdAz *vt, const ZdAz &vcalc) const;
    116117
     
    135136    void ReadConfig();
    136137
     138    bool CheckNetwork();
     139
    137140public:
    138141    MCosy(int mode, const char *dev, const int baud, MLog &out=gLog);
Note: See TracChangeset for help on using the changeset viewer.