- Timestamp:
- 01/14/03 12:08:46 (22 years ago)
- Location:
- trunk/MagicSoft/Cosy
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Cosy/Changelog
r1702 r1703 1 1 -*-*- 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 2 37 3 38 2003/01/13 - Thomas Bretz: -
trunk/MagicSoft/Cosy/candrv/network.cc
r1702 r1703 237 237 lout << "- Setting up Node #" << dec << i << " ("; 238 238 lout << fNodes[i]->GetNodeName() << ")" << endl; 239 fNodes[i]->InitDevice(this); 240 if (!fNodes[i]->IsZombieNode()) 239 if (fNodes[i]->InitDevice(this)) 241 240 fNodeInitialized[i] = TRUE; 242 /*else243 fNodes[i]=NULL;*/241 else 242 lout << "- " << fNodes[i]->GetNodeName() << ": InitDevice failed." << endl; 244 243 } 245 244 lout << "- All Nodes setup." << endl; … … 310 309 bool Network::RebootZombies() 311 310 { 311 bool rc = true; 312 312 313 lout << "- Trying to reboot all Zombies..." << endl; 313 314 for (int i=0; i<32; i++) … … 317 318 { 318 319 lout << "- Failed to reboot " << fNodes[i]->GetNodeName() << "." << endl; 319 r eturnfalse;320 rc = false; 320 321 } 321 322 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 // 334 void 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 35 35 36 36 bool RebootZombies(); 37 void CheckConnections(); 37 38 38 39 ClassDef(Network, 0) // collection of nodes (nodedrv) -
trunk/MagicSoft/Cosy/candrv/nodedrv.cc
r1702 r1703 30 30 // 31 31 // to be overloaded: 32 // virtual void Init Device(Network *net)32 // virtual void Init() 33 33 // virtual void StopDevice() 34 34 // virtual void HandleSDO(WORD_t idx, BYTE_t subidx, LWORD_t val, timeval_t *tv) … … 39 39 // virtual void HandlePDO3(BYTE_t *data, timeval_t *tv) 40 40 // virtual void HandlePDO4(BYTE_t *data, timeval_t *tv) 41 // virtual bool Reboot(); 42 // virtual void CheckConnection(); 41 43 // 42 44 /////////////////////////////////////////////////////////////////////// … … 56 58 // and the node name. The name is a name for debug output. 57 59 // 58 NodeDrv::NodeDrv(BYTE_t nodeid, const char *name, MLog &out) : Log(out), fNetwork(NULL), fId(32), fError(0), fIsZombie(k FALSE)60 NodeDrv::NodeDrv(BYTE_t nodeid, const char *name, MLog &out) : Log(out), fNetwork(NULL), fId(32), fError(0), fIsZombie(kTRUE) 59 61 { 60 62 if (nodeid>0x1f) … … 93 95 { 94 96 fIsZombie = false; 95 return true; 97 98 Init(); 99 100 return !fIsZombie; 96 101 } 97 102 … … 107 112 // SDO tx 108 113 // 109 voidNodeDrv::InitDevice(Network *net)114 bool NodeDrv::InitDevice(Network *net) 110 115 { 111 116 fNetwork = net; … … 117 122 EnableCanMsg(kSDO_RX); 118 123 EnableCanMsg(kSDO_TX); 124 125 fIsZombie = kFALSE; 126 127 Init(); 128 129 return !fIsZombie; 119 130 } 120 131 … … 165 176 // A PDO is carrying up to eight bytes of information. 166 177 // 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 // 181 bool NodeDrv::SendPDO1(BYTE_t data[8]) 182 { 183 if (!fIsZombie) 184 fNetwork->SendPDO1(fId, data); 185 return !fIsZombie; 170 186 } 171 187 … … 175 191 // A PDO is carrying up to eight bytes of information. 176 192 // 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 // 196 bool NodeDrv::SendPDO2(BYTE_t data[8]) 197 { 198 if (!fIsZombie) 199 fNetwork->SendPDO2(fId, data); 200 return !fIsZombie; 180 201 } 181 202 … … 185 206 // A PDO is carrying up to eight bytes of information. 186 207 // 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 // 211 bool NodeDrv::SendPDO1(BYTE_t m0=0, BYTE_t m1=0, BYTE_t m2=0, BYTE_t m3=0, 188 212 BYTE_t m4=0, BYTE_t m5=0, BYTE_t m6=0, BYTE_t m7=0) 189 213 { 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; 191 217 } 192 218 … … 196 222 // A PDO is carrying up to eight bytes of information. 197 223 // 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 // 227 bool NodeDrv::SendPDO2(BYTE_t m0=0, BYTE_t m1=0, BYTE_t m2=0, BYTE_t m3=0, 199 228 BYTE_t m4=0, BYTE_t m5=0, BYTE_t m6=0, BYTE_t m7=0) 200 229 { 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 // 247 bool 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 // 266 bool 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 // 285 bool 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 // 304 bool 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 // 323 bool 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 // 342 bool NodeDrv::SendSDO(WORD_t idx, LWORD_t val) 343 { 344 if (!fIsZombie) 345 fNetwork->SendSDO(fId, idx, val, true); 346 return !fIsZombie; 286 347 } 287 348 … … 294 355 // a subindex of this dictionary entry to access 295 356 // 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 // 360 bool NodeDrv::RequestSDO(WORD_t idx, BYTE_t subidx) 361 { 362 if (!fIsZombie) 363 fNetwork->RequestSDO(fId, idx, subidx); 364 return !fIsZombie; 299 365 } 300 366 … … 303 369 // Send an NMT message (command) to this device 304 370 // 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 // 374 bool NodeDrv::SendNMT(BYTE_t cmd) 375 { 376 if (!fIsZombie) 377 fNetwork->SendNMT(fId, cmd); 378 return !fIsZombie; 308 379 } 309 380 … … 323 394 // You can stop waiting by StopWaitingForSDO. 324 395 // 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.. 325 400 // 326 401 bool NodeDrv::WaitForSdo(WORD_t idx, BYTE_t subidx, WORDS_t timeout) 327 402 { 328 bool rc = fNetwork->WaitForSdo(fId, idx, subidx, timeout);403 bool rc = fNetwork->WaitForSdo(fId, idx, subidx, fIsZombie?-1:timeout); 329 404 330 405 if (!rc) 331 406 fIsZombie = kTRUE; 332 407 333 return rc;408 return fIsZombie ? false : rc; 334 409 } 335 410 -
trunk/MagicSoft/Cosy/candrv/nodedrv.h
r1702 r1703 44 44 Network *GetNetwork() { return fNetwork; } 45 45 46 virtual void InitDevice(Network *net); 46 virtual void Init() = 0; 47 virtual bool InitDevice(Network *net); 47 48 virtual void StopDevice() = 0; 49 virtual bool Reboot(); 50 virtual void CheckConnection() = 0; 48 51 49 52 int GetError() const { return fError; } … … 61 64 virtual void HandlePDO4(BYTE_t *data, timeval_t *tv) {}; 62 65 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, 68 69 BYTE_t m4=0, BYTE_t m5=0, BYTE_t m6=0, BYTE_t m7=0); 69 voidSendPDO2(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, 70 71 BYTE_t m4=0, BYTE_t m5=0, BYTE_t m6=0, BYTE_t m7=0); 71 72 72 voidSendSDO(WORD_t idx, BYTE_t subidx, BYTE_t val, bool store=true);73 voidSendSDO(WORD_t idx, BYTE_t subidx, WORD_t val, bool store=true);74 voidSendSDO(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); 75 76 76 voidSendSDO(WORD_t idx, BYTE_t val);77 voidSendSDO(WORD_t idx, WORD_t val);78 voidSendSDO(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); 79 80 80 voidSendNMT(BYTE_t cmd);81 bool SendNMT(BYTE_t cmd); 81 82 82 voidRequestSDO(WORD_t idx, BYTE_t subidx=0);83 bool RequestSDO(WORD_t idx, BYTE_t subidx=0); 83 84 84 85 void WaitForNextPdo1(); -
trunk/MagicSoft/Cosy/candrv/vmodican.cc
r1702 r1703 232 232 cout << "TxErrCnt=" << (int)msg->data[5] << endl; 233 233 } 234 TerminateApp();234 //FIXME? TerminateApp(); 235 235 return; 236 236 case 0x02: -
trunk/MagicSoft/Cosy/cosy.cc
r1702 r1703 23 23 int main(int argc, char **argv) 24 24 { 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 25 33 Timer time; 26 34 time.Now(); -
trunk/MagicSoft/Cosy/devdrv/macs.cc
r1702 r1703 48 48 case 0x100a: 49 49 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; 50 56 return; 51 57 … … 221 227 } 222 228 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 */ 229 void 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 240 void Macs::Init() 241 { 245 242 lout << "- " << GetNodeName() << ": Requesting Mac Software Version." << endl; 246 243 RequestSDO(0x100a); 247 244 WaitForSdo(0x100a); 248 245 249 if (IsZombie()) 250 return; 246 if (fIsZombie) 247 { 248 lout << GetNodeName() << " - InitDevice failed!" << endl; 249 return; 250 } 251 251 252 252 EnableTimeout(kFALSE); … … 259 259 SendSDO(0x3000, string('o', 'n')); 260 260 WaitForSdo(0x3000); 261 262 261 263 262 // SetHome(250000); … … 413 412 // or by a positioning command (POSA, ...) 414 413 // 415 lout << "- " << GetNodeName() << ": Starting Posi stion Sync Mode." << endl;414 lout << "- " << GetNodeName() << ": Starting Position Sync Mode." << endl; 416 415 SendSDO(0x3007, 1, string('s', 'y', 'n', 'c')); 417 416 WaitForSdo(0x3007, 1); … … 547 546 } 548 547 548 // FIXME? Handling of fIsZombie? 549 549 void Macs::HandleError() 550 550 { -
trunk/MagicSoft/Cosy/devdrv/macs.h
r1702 r1703 11 11 private: 12 12 BYTE_t fMacId; 13 14 LWORD_t fSoftVersion; 13 15 14 16 LWORD_t fVelRes; … … 41 43 Bool_t HandleTimer(TTimer *t); 42 44 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 43 62 public: 63 enum 64 { 65 kNoSync = BIT(0), 66 kPosSync = BIT(1), 67 kVelSync = BIT(2) 68 }; 44 69 enum 45 70 { … … 54 79 Macs(const BYTE_t nodeid, const char *name=NULL, MLog &out=gLog); 55 80 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);68 81 69 82 void SendMsg(BYTE_t data[6]); -
trunk/MagicSoft/Cosy/devdrv/shaftencoder.cc
r1701 r1703 51 51 } 52 52 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; 54 55 return; 55 56 … … 94 95 void ShaftEncoder::DisplayVal() 95 96 { 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 96 108 char text[21]; 97 109 … … 190 202 } 191 203 192 void ShaftEncoder::InitDevice(Network *net) 193 { 194 NodeDrv::InitDevice(net); 195 204 void ShaftEncoder::Init() 205 { 196 206 //----------------------------------------------------------------------- 197 207 // Start Setup of the Shaft Encoder … … 203 213 lout << "- " << GetNodeName() << ": Requesting Hardware Type (0x1000)." << endl; 204 214 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; 209 220 return; 210 221 } … … 265 276 } 266 277 278 void ShaftEncoder::CheckConnection() 279 { 280 // Request Node number 281 RequestSDO(0x100b); 282 WaitForSdo(0x100b); 283 } 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 */ 308 267 309 void ShaftEncoder::ReqPos() 268 310 { … … 277 319 void ShaftEncoder::SetPreset(LWORD_t pre) 278 320 { 321 lout << "- " << GetNodeName() << ": Setting Preset." << endl; 322 323 SendSDO(0x6003, (LWORD_t)fPos); 324 if (!WaitForSdo(0x6003)) 325 return; 326 279 327 fPos = pre%16384; 280 328 fTurn = pre/16384; 281 282 lout << "- " << GetNodeName() << ": Setting Preset." << endl;283 SendSDO(0x6003, (LWORD_t)fPos);284 WaitForSdo(0x6003);285 329 } 286 330 -
trunk/MagicSoft/Cosy/devdrv/shaftencoder.h
r1690 r1703 32 32 void ReqPos(); 33 33 34 void Init(); 35 void CheckConnection(); 36 34 37 public: 35 38 ShaftEncoder(const BYTE_t nodeid, const char *name=NULL, MLog &out=gLog); 36 39 virtual ~ShaftEncoder(); 37 40 38 void InitDevice(Network *); 41 //bool InitDevice(Network *); 42 //bool Reboot(); 39 43 40 44 //void StartDevice(); … … 50 54 void HandlePDO2(BYTE_t *data, timeval_t *tv) { HandlePDOType2(data, tv); } 51 55 52 LWORDS_t GetPos() { return f Pos+fTurn*fTicks; }56 LWORDS_t GetPos() { return fIsZombie ? 0 : fPos+fTurn*fTicks; } // FIXME? 0? 53 57 LWORD_t GetPhysRes() { return fTicks; } 54 58 -
trunk/MagicSoft/Cosy/main/MCosy.cc
r1702 r1703 41 41 //const XY kGearRatio2(GEAR_RATIO_ALT*RES_RE/360.0, GEAR_RATIO_AZ*RES_RE/360.0); //[re/deg] 42 42 43 /* +===================================+ 44 FIXME: What if fMac3 (Sync) died? 45 +===================================+ 46 */ 47 43 48 double MCosy::Rad2SE(double rad) const 44 49 { … … 150 155 // Get the values 151 156 // 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(); 159 160 160 161 // 161 162 // interpolate shaft encoder positions 162 163 // 163 const float a = (float)(a0-a1)/2;164 const float p = (float)(p0-p1)/2; 164 165 165 166 // 166 167 // calculate 'regelabweichung' 167 168 // 168 return ZdAz( a, a2);169 return ZdAz(p, p2); 169 170 } 170 171 … … 177 178 Bool_t MCosy::RequestRePos() 178 179 { 179 if (fMac1->IsZombieNode() || fMac2->IsZombieNode())180 return kTRUE;181 182 180 // 183 181 // Send request … … 189 187 // Wait until the objects are received. 190 188 // 189 // FIXME, what when waiting times out (Zombie) 191 190 WaitForSdos(); 192 191 … … 194 193 // If waiting was not interrupted everything is ok. return. 195 194 // 196 if (!StopWaitingForSDO() )195 if (!StopWaitingForSDO() && !HasZombie()) 197 196 return kTRUE; 198 197 … … 216 215 ZdAz MCosy::GetRePos() 217 216 { 218 return !fMac1->IsZombieNode() && !fMac2->IsZombieNode() ? ZdAz(fMac2->GetPos(), fMac1->GetPos()) : ZdAz(0,0);217 return ZdAz(fMac2->GetPos(), fMac1->GetPos()); 219 218 } 220 219 … … 304 303 int MCosy::StopWaitingForSDO() const 305 304 { 306 return Break() || HasError() || HasZombie();305 return Break() || HasError(); 307 306 } 308 307 … … 316 315 void MCosy::WaitForEndMovement() 317 316 { 317 // FIXME, what when waiting times out (Zombie) 318 318 WaitForSdos(); 319 319 320 while ((fMac1->IsPositioning() || fMac2->IsPositioning()) && !StopWaitingForSDO() )320 while ((fMac1->IsPositioning() || fMac2->IsPositioning()) && !StopWaitingForSDO() && !HasZombie()) 321 321 usleep(1); 322 322 } … … 378 378 // FIXME: Correct by fOffset ? 379 379 380 /* 380 381 if (fMac1->IsZombieNode() || fMac2->IsZombieNode()) 381 382 { … … 383 384 return TRUE; 384 385 } 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; 385 395 386 396 // 387 397 // Calculate new target position (shortest distance to go) 388 398 // 389 const ZdAz src = GetSePos(); //*TMath::Pi()*2/16384;;399 const ZdAz src = GetSePos(); 390 400 391 401 // … … 404 414 cout << "Shortest Dest Zd: " << dest.Zd() << "se Az:" << dest.Az() << "se" << endl; 405 415 406 for (int i=0; i<10 && !StopWaitingForSDO() ; i++)416 for (int i=0; i<10 && !StopWaitingForSDO() && !HasZombie(); i++) 407 417 { 408 418 // … … 450 460 451 461 rd.Round(); 462 463 // FIXME? Check for Error or Zombie? 452 464 453 465 /* … … 477 489 // in case of success, kFALSE in case of failure. 478 490 // 479 Bool_t MCosy::SetVelocity( ZdAzv)491 Bool_t MCosy::SetVelocity(const ZdAz &v) 480 492 { 481 493 // … … 488 500 // Wait for the objects to be OKed. 489 501 // 502 // FIXME, what when waiting times out (Zombie) 490 503 WaitForSdos(); 491 504 … … 493 506 // If the waiting for the objects wasn't interrupted return kTRUE 494 507 // 495 if (!StopWaitingForSDO() )508 if (!StopWaitingForSDO() && !HasZombie()) 496 509 return kTRUE; 497 510 … … 513 526 // revolution mode. 514 527 // 515 void MCosy::InitTracking() 516 { 528 bool MCosy::InitTracking() 529 { 530 // FIXME? Handling of Zombie OK? 517 531 if (fMac1->IsZombieNode() || fMac2->IsZombieNode()) 518 return ;532 return false; 519 533 520 534 // … … 523 537 fMac2->SetAcceleration(0.90*fMac2->GetVelRes()); 524 538 fMac2->SetDeceleration(0.90*fMac2->GetVelRes()); 539 if (fMac2->IsZombieNode()) 540 return false; 525 541 526 542 fMac1->SetAcceleration(0.90*fMac1->GetVelRes()); 527 543 fMac1->SetDeceleration(0.90*fMac1->GetVelRes()); 544 if (fMac1->IsZombieNode()) 545 return false; 528 546 529 547 SetStatus(MCosy::kMoving | MCosy::kTracking); 530 548 531 549 fMac2->SetRpmMode(TRUE); 550 if (fMac2->IsZombieNode()) 551 return false; 552 532 553 fMac1->SetRpmMode(TRUE); 554 if (fMac1->IsZombieNode()) 555 return false; 556 557 return true; 533 558 } 534 559 … … 640 665 // Init accelerations and Rpm Mode 641 666 // 642 InitTracking(); 667 if (!InitTracking()) 668 return; 643 669 644 670 XY xy(Rad2Deg(dst.Ra())*24/360, Rad2Deg(dst.Dec())); … … 655 681 // 656 682 fRaDec = dst; 657 658 if (fMac1->IsZombieNode() || fMac2->IsZombieNode())659 return;660 661 683 fTracking = kTRUE; 662 684 … … 671 693 // 672 694 const float dt = 1; // 1 second 673 while (!StopWaitingForSDO() )695 while (!StopWaitingForSDO() && !HasZombie()) 674 696 { 675 697 // … … 774 796 void MCosy::StopMovement() 775 797 { 776 if (fMac1->IsZombieNode() || fMac2->IsZombieNode())777 return;778 779 798 // 780 799 // Set status to Stopping … … 785 804 // set deceleration to 50% 786 805 // 787 cout << "Stopping positioning..." << endl;806 cout << "Stopping..." << endl; 788 807 fMac1->SetDeceleration(0.5*fMac1->GetVelRes()); 808 if (!fMac1->IsZombieNode()) 809 fMac1->SetRpmMode(FALSE); 810 789 811 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); 797 814 798 815 // … … 809 826 } 810 827 811 void *MCosy::Proc(int msg, void *mp)812 { 813 lout << "Checking for Zombies" << endl;828 bool MCosy::CheckNetwork() 829 { 830 CheckConnections(); 814 831 if (HasZombie()) 815 832 { 816 lout << " Found Zombies" << endl;833 lout << "- Found Zombies in Network..." << endl; 817 834 if (!RebootZombies()) 818 return (void*)0xebb0;835 return false; 819 836 } 820 837 return true; 838 } 839 840 void *MCosy::Proc(int msg, void *mp) 841 { 821 842 switch (msg) 822 843 { … … 827 848 case WM_STOP: 828 849 cout << "MCosy::Proc: Stop." << endl; 850 if (!CheckNetwork()) 851 return (void*)0xebb0; 829 852 StopMovement(); 830 853 return NULL; … … 832 855 case WM_PRESET: 833 856 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(); 837 862 cout << "WM_Preset: done. (return 0xaffe)" << endl; 838 863 return (void*)0xaffe; … … 841 866 { 842 867 cout << "WM_Calib: start." << endl; 868 if (!CheckNetwork()) 869 return (void*)0xebb0; 870 843 871 SlaStars sla; 844 872 sla.SetMjd2Now(); … … 858 886 cout << "Got Zd: " << sepos.Zd() << " Az: " << sepos.Az() << endl; 859 887 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()); 866 891 867 892 cout << "WM_Calib: done. (return 0xaffe)" << endl; … … 897 922 cout << "WM_Position: start." << endl; 898 923 { 924 if (!CheckNetwork()) 925 return (void*)0xebb0; 926 899 927 ZdAz dest = *((ZdAz*)mp); 900 901 928 SetPosition(dest*kDeg2Rad); 902 929 } … … 907 934 cout << "WM_Track: START" << endl; 908 935 { 936 if (!CheckNetwork()) 937 return (void*)0xebb0; 938 909 939 RaDec dest = *((RaDec*)mp); 910 940 TrackPosition(dest*kDeg2Rad); … … 933 963 case WM_HOME: 934 964 cout << "WM_Home: START" << endl; 935 if (!fMac1->IsZombieNode() && !fMac2->IsZombieNode()) 965 if (!CheckNetwork()) 966 return (void*)0xebb0; 967 else 936 968 { 937 969 cout << "Going Home..." << endl; … … 976 1008 case WM_QUIT: 977 1009 cout << "WM_Quit: now." << endl; 1010 if (!CheckNetwork()) 1011 { 1012 lout << "ERROR: Cannot shutdown CANbus network." << endl; 1013 return (void*)0xebb0; 1014 } 978 1015 TerminateApp(); 979 1016 cout << "WM_Quit: done." << endl; … … 1004 1041 resreaz = fMac1->GetRes(); 1005 1042 else 1006 if ( !fMac3->IsZombieNode())1043 if (fMac3 && !fMac3->IsZombieNode()) 1007 1044 resreaz = fMac3->GetRes(); 1008 1045 else … … 1040 1077 } 1041 1078 1079 void 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 1042 1092 void MCosy::TalkThread() 1043 1093 { 1044 if (fMac1->IsZombieNode() || fMac2->IsZombieNode()) 1094 /* ========== FIXME? ============= 1095 if (fMac1->IsZombieNode() || fMac2->IsZombieNode()) 1045 1096 return; 1046 1097 */ 1047 1098 fMac1->ReqPos(); 1048 1099 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 }1059 1100 1060 1101 if (fZd1->IsZombieNode() || fZd2->IsZombieNode() || fAz->IsZombieNode()) … … 1227 1268 // Update Gui, foremer MTGui. 1228 1269 // 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(); 1232 1273 1233 1274 ZdAz seist = GetSePos()*2*TMath::Pi()/16384; // [se] … … 1238 1279 avail |= !fMac1->IsZombieNode() ? 0x01 : 0; 1239 1280 avail |= !fMac2->IsZombieNode() ? 0x02 : 0; 1240 avail |= !fMac3->IsZombieNode() ? 0x04 : 0;1281 avail |= (fMac3 && !fMac3->IsZombieNode()) ? 0x04 : 0; 1241 1282 avail |= !fZd1->IsZombieNode() ? 0x08 : 0; 1242 1283 avail |= !fZd2->IsZombieNode() ? 0x10 : 0; … … 1268 1309 // Don't call this function twice! 1269 1310 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());1289 1311 1290 1312 ReadConfig(); … … 1292 1314 lout << "- Starting TX Thread." << endl; 1293 1315 fTTalk = new MTTalk(this); 1294 // fTGui = new MTGui(this);1295 1316 1296 1317 lout << "- Starting GUI update." << endl; … … 1361 1382 lout << "- Starting GUI." << endl; 1362 1383 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);1369 1384 } 1370 1385 … … 1397 1412 lout << "- Starting GUI." << endl; 1398 1413 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);1405 1414 } 1406 1415 … … 1420 1429 lout << "- Starting GUI." << endl; 1421 1430 fWin=new MGCosy(this, gClient->GetRoot(), 1, 1); 1422 1423 lout.SetOutputGui(fWin->GetLog(), kTRUE);1424 1431 } 1425 1432 … … 1451 1458 } 1452 1459 1460 lout.SetOutputGui(fWin->GetLog(), kTRUE); 1461 1462 fZd1->SetDisplay(fWin->GetLabel2()); 1463 fZd2->SetDisplay(fWin->GetLabel3()); 1464 fAz->SetDisplay(fWin->GetLabel1()); 1465 1453 1466 int i=0; 1454 1467 char name[100]; … … 1503 1516 cout << "Deleting Nodes." << endl; 1504 1517 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; 1511 1525 1512 1526 cout << "Deleting MGCosy." << endl; -
trunk/MagicSoft/Cosy/main/MCosy.h
r1701 r1703 107 107 108 108 Bool_t RequestRePos(); 109 Bool_t SetVelocity( ZdAzv);109 Bool_t SetVelocity(const ZdAz &v); 110 110 void SetPosVelocity(const Float_t ratio, Float_t vel, Float_t acc); 111 111 112 112 void DoRelPos(const ZdAz &rd, const Bool_t axe1, const Bool_t axe2); 113 113 114 void InitTracking(); 114 void InitSync(); 115 bool InitTracking(); 115 116 void LimitSpeed(ZdAz *vt, const ZdAz &vcalc) const; 116 117 … … 135 136 void ReadConfig(); 136 137 138 bool CheckNetwork(); 139 137 140 public: 138 141 MCosy(int mode, const char *dev, const int baud, MLog &out=gLog);
Note:
See TracChangeset
for help on using the changeset viewer.