Changeset 808 for trunk/MagicSoft/Cosy/devdrv
- Timestamp:
- 05/25/01 16:51:24 (24 years ago)
- Location:
- trunk/MagicSoft/Cosy/devdrv
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Cosy/devdrv/macs.cc
r732 r808 10 10 : NodeDrv(nodeid, out), fMacId(2*nodeid+1), 11 11 fPos(0), fPosTime(0.0), fPdoPos(0), fPdoTime(0.0), 12 fPosActive(0), fRpmActive(0) , fError(FALSE)12 fPosActive(0), fRpmActive(0) 13 13 { 14 14 } … … 115 115 RequestSDO(0x2004); 116 116 WaitForSdo(0x2004); 117 118 119 */ 117 */ 118 120 119 lout << "- Requesting Mac Software Version of " << (int)GetId() << endl; 121 120 RequestSDO(0x100a); 122 121 WaitForSdo(0x100a); 123 // 122 124 123 SetRpmMode(FALSE); 125 124 … … 131 130 132 131 133 SetHome(250000);132 // SetHome(250000); 134 133 135 134 // lout << "- Requesting SDO 0x2001 of " << (int)GetId() << endl; … … 195 194 WaitForSdo(0x6003, 2); 196 195 196 // home also defines the zero point of the system 197 197 SendSDO(0x3001, string('h','o','m','e')); // home 198 198 WaitForSdo(0x3001); 199 199 lout << "- Home position of #" << (int)GetId() << " reached. " << endl; 200 201 SendSDO(0x6003, 0, string('s','e','t')); // home 202 WaitForSdo(0x6003, 0); 200 203 } 201 204 … … 208 211 void Macs::SetAcceleration(LWORD_t acc) 209 212 { 210 SendSDO(0x2003, 0, acc); 213 SendSDO(0x2003, 0, acc); // acceleration 211 214 WaitForSdo(0x2003, 0); 212 215 } … … 214 217 void Macs::SetDeceleration(LWORD_t dec) 215 218 { 216 SendSDO(0x2003, 1, dec); 219 SendSDO(0x2003, 1, dec); // acceleration 217 220 WaitForSdo(0x2003, 1); 218 221 } … … 223 226 // SetRpmMode(FALSE) stop the motor, but lets the position control unit on 224 227 // 225 226 228 SendSDO(0x3006, 0, mode ? string('S','T','R','T') : string('S','T','O','P')); 227 229 WaitForSdo(0x3006, 0); … … 250 252 WaitForSdo(0x3008); 251 253 } 254 255 void Macs::SetSyncMode() 256 { 257 lout << "- Setting Sync Mode #" << (int)GetId() << endl; 258 SendSDO(0x3007, string('S', 'Y', 'N', 'C')); 259 WaitForSdo(0x3007); 260 } 252 261 /* 253 262 void Macs::ReqAxEnd() … … 283 292 LWORDS_t errinf = (data[4]<<24) | (data[5]<<16) | (data[6]<<8) | data[7]; 284 293 294 // 295 // errnum==0 gives a sudden information that something happened. Now the 296 // microcontroller is running inside its interrup procedure which 297 // stopped the normal program. The interrupt procedure should try to clear 298 // the error state of the hardware. This should never create a new error! 299 // 285 300 if (!errnum) 286 301 { 287 302 cout << "Mac #" << (int)GetId() << " reports Error occursion." << endl; 288 fError = TRUE;303 SetError(-1); 289 304 return; 290 305 } 306 307 // 308 // Now the error is handled by the hardware now it is the software part 309 // to react on it. The Error flag now is set to the correct value. 310 // 311 if (GetError()>0) 312 cout << "Mac #" << (int)GetId() << " WARNING! Error #" << GetError() << " unhandled by software." << endl; 313 314 SetError(errnum); 291 315 292 316 cout << "Mac #" << (int)GetId() << " reports: "; … … 305 329 return; 306 330 331 case 11: 307 332 case 25: 308 333 switch (errinf) 309 334 { 335 case -1: 336 cout << "Negative"; 337 break; 310 338 case 1: 311 339 cout << "Positive"; 312 break;313 case 2:314 cout << "Negative";315 340 break; 316 341 default: 317 342 cout << "-unknown-"; 318 343 } 319 cout << " endswitch activated." << endl; 320 fError = FALSE; 344 switch (errnum) 345 { 346 case 11: 347 cout << " software endswitch activated." << endl; 348 break; 349 case 25: 350 cout << " hardware endswitch activated." << endl; 351 break; 352 } 321 353 return; 322 354 … … 330 362 } 331 363 364 void Macs::HandleError() 365 { 366 // 367 // If there is no error we must not handle anything 368 // 369 if (!HasError()) 370 return; 371 372 // 373 // If the program got into the: HandleError state before the hardware 374 // has finished handeling the error we have to wait for the hardware 375 // handeling the error 376 // 377 // FIXME: Timeout??? 378 // 379 while (GetError()<0) 380 usleep(1); 381 382 // 383 // After this software and hardware should be in a state so that 384 // we can go on working 'as usual' Eg. Initialize a Display Update 385 // 386 cout << "Mac #" << (int)GetId() << " Handling Error #" << GetError() << endl; 387 switch (GetError()) 388 { 389 case 6: // home 390 case 8: // control dev 391 case 9: // zero idx 392 case 84: // ON TIME 393 // Stop program? 394 return; 395 396 case 11: // software endswitch 397 case 25: // hardware endswitch 398 DelError(); 399 return; 400 } 401 } 402 332 403 double Macs::GetTime() 333 404 { … … 350 421 } 351 422 423 /* 0x2000 0 rw Maximum positioning error */ 424 /* 1 rw Negative Software Endswitch */ 425 /* 2 rw Positive Software Endswitch */ 426 void Macs::SetNegEndswitch(LWORDS_t val) 427 { 428 SendSDO(0x2000, 1, (LWORD_t)val); 429 WaitForSdo(0x2000, 1); 430 } 431 432 void Macs::SetPosEndswitch(LWORDS_t val) 433 { 434 SendSDO(0x2000, 2, (LWORD_t)val); 435 WaitForSdo(0x2000, 2); 436 } 437 438 void Macs::EnableEndswitches(bool neg, bool pos) 439 { 440 SendSDO(0x2000, 3, (LWORD_t)(neg|(pos<<1))); 441 WaitForSdo(0x2000, 3); 442 } -
trunk/MagicSoft/Cosy/devdrv/macs.h
r732 r808 21 21 BYTE_t fPosActive; 22 22 BYTE_t fRpmActive; 23 24 int fError; // Indicater for error state25 23 26 24 LWORD_t string(BYTE_t b0=0, BYTE_t b1=0, BYTE_t b2=0, BYTE_t b3=0) … … 58 56 void SetVelocity(LWORD_t vel); 59 57 void SetNoWait(BYTE_t flag=TRUE); 58 void SetSyncMode(); 60 59 void SetRpmMode(BYTE_t mode=TRUE); 61 60 void SetRpmVelocity(LWORDS_t cvel); 62 61 void SetPDO1On(BYTE_t flag=TRUE); 62 void SetPosEndswitch(LWORDS_t val); 63 void SetNegEndswitch(LWORDS_t val); 64 65 void EnableEndswitches(bool neg=true, bool pos=true); 63 66 64 67 void StartRelPos(LWORDS_t pos); … … 79 82 LWORDS_t GetPos() { return fPos; } 80 83 LWORDS_t GetVel() { return fVel; } 81 LWORD_t GetVelRes() { return fVelRes; } 84 LWORD_t GetVelRes() { return fVelRes; } // Velocity units (would be 100 for %) 82 85 83 int HasError() { return fError; }86 void HandleError(); 84 87 }; 85 88
Note:
See TracChangeset
for help on using the changeset viewer.