- Timestamp:
- 02/20/08 19:39:13 (17 years ago)
- Location:
- trunk/MagicSoft/Cosy
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Cosy/Changelog
r8864 r8865 1 1 -*-*- END -*-*- 2 3 2008/02/20 Thomas Bretz (La Palma) 4 5 * candrv/ethernet.[h,cc]: 6 - return kFALSE even if RecvRaw return a value <0 7 8 * devdrv/macs.[h,cc]: 9 - added setting and reseeting of an armed state disallowing 10 all movements 11 - set fPosActive if positiong has been started to prevent lags 12 in the program flow 13 - added fArmed to PDO1 14 - added some debug output 15 16 * gui/MGCosy.[h,cc]: 17 - added "Arm" button to the display in expert mode 18 - added armed state to the Update member function 19 20 * main/MCosy.[h,cc]: 21 - commented out all accesses to the third MACS 22 - added code to allow the armed state to be set from the gui 23 - pipe the armed state to the gui 24 25 * tcpip/MTcpIpIO.[h,cc]: 26 - added a timeout to MTcpIpI when waiting for new data 27 which is set to 5s by default 28 - return kFALSE even if RecvRaw return a value <0 29 - wait for new connection in case of timeout 30 31 2 32 3 33 2008/02/17 Thomas Bretz (La Palma) -
trunk/MagicSoft/Cosy/candrv/ethernet.cc
r8864 r8865 90 90 const Int_t len = rx.RecvRaw(&c, 1); 91 91 92 // No data received (non-blocking mode) 93 if (len<0) 94 { 95 usleep(1); 96 continue; 97 } 98 99 // Data received with zero length! (Connection lost) 100 if (len==0) 92 // For details see TSocket::RecvRaw 93 // -1: // ERROR 94 // EINVAL, EWOULDBLOCK 95 // -5: // EPIPE || ECONNRESET = Pipe broken or connection reset by peer 96 // 0: Data received with zero length! (Connection lost/call interrupted) 97 if (len<=0) 101 98 return kFALSE; 102 99 … … 112 109 if (c>=MSGLEN) 113 110 { 114 cout<< "Data received from " << address << " too long (> " << MSGLEN << ")" << endl;111 gLog << err << "Data received from " << address << " too long (> " << MSGLEN << ")" << endl; 115 112 continue; 116 113 } -
trunk/MagicSoft/Cosy/devdrv/macs.cc
r8864 r8865 34 34 : NodeDrv(nodeid, name), fMacId(2*nodeid+1), 35 35 fPos(0), fPdoPos(0), fPosActive(0), fRpmActive(0), 36 fStatusPdo3(0xff) 36 fStatusPdo3(0xff), fArmed(false) 37 37 { 38 38 // fTimeout = new TTimer(this, 100); //, kFALSE); // 100ms, asynchronous … … 72 72 case 0xa149: return "Drive controlled interpolated relative positioning lagless with encoder 2"; 73 73 case 0xa150: return "Drive controlled positioning with encoder 1"; 74 case 0xa151: return "Drive controlled positioning with encoder 2";74 case 0xa151: return "Drive controlled positioning with encoder 1, lagless"; 75 75 case 0xa208: return "Jog mode positive"; 76 76 case 0xa218: return "Jog mode negative"; … … 91 91 case 0xe264: return "Target position out of numerical range"; 92 92 case 0xe834: return "Emergency-Stop"; 93 case 0xe842: return "Both end-switches activated"; 93 94 case 0xe843: return "Positive end-switch activated"; 94 95 case 0xe844: return "Negative end-switch activated"; … … 150 151 switch (idx) 151 152 { 153 case 0x1000: 154 if (subidx==1) 155 { 156 gLog << inf2 << "- " << GetNodeName() << ": Node is" << (val?" ":" not ") << "armed." << endl; 157 fArmed = val==1; 158 } 159 return; 160 152 161 case 0x1003: 153 162 // FIXME, see Init … … 382 391 //lout << ddev(MLog::eGui); 383 392 gLog << inf2 << "- " << GetNodeName() << ": Absolute positioning started." << endl; 393 fPosActive = kTRUE; // Make sure that the status is set correctly already before the first PDO 384 394 //lout << edev(MLog::eGui); 385 395 return; … … 388 398 //lout << ddev(MLog::eGui); 389 399 gLog << inf2 << "- " << GetNodeName() << ": Relative positioning started." << endl; 400 fPosActive = kTRUE; // Make sure that the status is set correctly already before the first PDO 390 401 //lout << edev(MLog::eGui); 391 402 return; … … 428 439 gLog << inf2 << "- " << GetNodeName() << ": Starting Node." << endl; 429 440 SendSDO(0x1000, 1, (LWORD_t)1); 441 WaitForSdo(0x1000, 1); 442 } 443 444 void Macs::Arm() 445 { 446 StartNode(); 447 } 448 449 void Macs::Disarm() 450 { 451 gLog << inf2 << "- " << GetNodeName() << ": Stopping Node." << endl; 452 SendSDO(0x1000, 1, (LWORD_t)0); 430 453 WaitForSdo(0x1000, 1); 431 454 } … … 490 513 //StartHostGuarding(); 491 514 492 StartNode(); 515 // REMOVE THIS AND LET CC START THE NODE 516 //StartNode(); 517 518 gLog << inf2 << "- " << GetNodeName() << ": Checking armed status." << endl; 519 RequestSDO(0x1000, 1); 520 WaitForSdo(0x1000, 1); 493 521 } 494 522 /* … … 571 599 void Macs::SetVelocity(LWORD_t vel) 572 600 { 601 gLog << dbg << "- Setting velocity to: " << vel << endl; 573 602 SendSDO(0x2002, vel); // velocity 574 603 WaitForSdo(0x2002, 0); 575 cout << "SET VEL: " << vel << endl;576 604 } 577 605 578 606 void Macs::SetAcceleration(LWORD_t acc) 579 607 { 608 gLog << dbg << "- Setting acceleration to: " << vel << endl; 580 609 SendSDO(0x2003, 0, acc); // acceleration 581 610 WaitForSdo(0x2003, 0); 582 cout << "SET ACC: " << acc << endl;583 611 } 584 612 585 613 void Macs::SetDeceleration(LWORD_t dec) 586 614 { 587 SendSDO(0x2003, 1, dec); // acceleration 615 gLog << dbg << "- Setting deceleration to: " << vel << endl; 616 SendSDO(0x2003, 1, dec); 588 617 WaitForSdo(0x2003, 1); 589 cout << "SET DEC: " << dec << endl;590 618 } 591 619 … … 607 635 void Macs::StartRelPos(LWORDS_t pos) 608 636 { 637 if (!fIsArmed) 638 { 639 gLog << err << GetNodeName() << ": ERROR - Moving without being armed is not allowed." << endl; 640 return; 641 } 642 643 gLog << dbg << GetNodeName() << ": Starting abolsute positioning to " << (LWORD_t)pos << " ticks." << endl; 609 644 SendSDO(0x6004, 1, (LWORD_t)pos); 610 cout << "REL POS: " << (LWORD_t)pos << endl;645 fPosActive = kTRUE; // Make sure that the status is set correctly already before the first PDO 611 646 } 612 647 613 648 void Macs::StartAbsPos(LWORDS_t pos) 614 649 { 650 if (!fIsArmed) 651 { 652 gLog << err << GetNodeName() << ": ERROR - Moving without being armed is not allowed." << endl; 653 return; 654 } 655 gLog << dbg << GetNodeName() << ": Starting relative positioning by " << (LWORD_t)pos << " ticks." << endl; 615 656 SendSDO(0x6004, 0, (LWORD_t)pos); 616 cout << "ABS POS: " << (LWORD_t)pos << endl;657 fPosActive = kTRUE; // Make sure that the status is set correctly already before the first PDO 617 658 } 618 659 … … 681 722 fInControl = data[3]&0x40; // motor uncontrolled 682 723 // data[3]&0x80; // axis resetted (after errclr, motor stop, motor on) 724 725 fArmed = data[2]&kIsArmed==kIsArmed; 683 726 684 727 fStatus = data[3]; -
trunk/MagicSoft/Cosy/devdrv/macs.h
r8864 r8865 34 34 35 35 BYTE_t fStatusPdo3; 36 37 bool fArmed; 36 38 37 39 void Init(); … … 73 75 enum 74 76 { 77 kIsArmed = BIT(0), // Macs will accept movement commands 75 78 kNotMoving = BIT(0), // motor not moving 76 79 kPosActive = BIT(1), // positioning active … … 121 124 void StartNode(); 122 125 126 bool IsArmed() const { return fArmed; } 127 void Arm(); 128 void Disarm(); 129 123 130 int IsPositioning() const { return fPosActive; } 124 131 BYTE_t GetStatus() const { return fStatus; } -
trunk/MagicSoft/Cosy/gui/MGCosy.cc
r8864 r8865 58 58 kPB_TPOINT, 59 59 kPB_ENDSWITCH, 60 kPB_ARM, 60 61 kPB_START, 61 62 kPB_DISPLAY1, … … 529 530 530 531 #ifdef EXPERT 532 but = new TGTextButton(tf1, "Arm", kPB_ARM); 533 but->MoveResize(204, 213, 62, 25); 534 but->SetToolTipText("Arm the telescop (allow for movement)."); 535 but->Associate(this); 536 fList->Add(but); 537 538 ULong_t col; 539 gClient->GetColorByName("Magenta", col); 540 but->SetBackgroundColor(col); 541 531 542 but= new TGTextButton(tf1, "New Position", kPB_SavePreDef); 532 543 but->MoveResize(165, 197, 80, 25); … … 554 565 555 566 but = new TGTextButton(tf4, "Load", kPB_LoadBending); 556 but-> ResizeMove(151, 185, 50, 25);567 but->MoveResize(151, 185, 50, 25); 557 568 but->SetToolTipText("Load bending corrections from file 'bending.txt'"); 558 569 but->Associate(this); … … 1030 1041 1031 1042 void MGCosy::Update(ZdAz pos, ZdAz acc, ZdAz vel, /*ZdAz off,*/ RaDec radec, 1032 ZdAz soll, UInt_t stat, UInt_t stat2 )1043 ZdAz soll, UInt_t stat, UInt_t stat2, Bool_t armed) 1033 1044 { 1034 1045 // acc [rad] … … 1058 1069 SetLabelColor(fAvailSe3, stat2&0x20); 1059 1070 1060 EnableLabel(fArmed, 1);//stat2&0x40);1071 EnableLabel(fArmed, armed);//stat2&0x40); 1061 1072 1062 1073 if (stat&MDriveCom::kTracking) … … 1502 1513 StartTrackPos(); 1503 1514 return kTRUE; 1515 case kPB_ARM: 1516 fQueue->PostMsg(WM_ARM); 1517 return kTRUE; 1504 1518 case kPB_DISPLAY1: 1505 1519 case kPB_DISPLAY2: -
trunk/MagicSoft/Cosy/gui/MGCosy.h
r8820 r8865 137 137 MGImage *GetImage() { return fImage; } 138 138 139 void Update(ZdAz pos, ZdAz acc, ZdAz vel, /*ZdAz off,*/ RaDec radec, ZdAz soll, UInt_t stat, UInt_t stat2 );139 void Update(ZdAz pos, ZdAz acc, ZdAz vel, /*ZdAz off,*/ RaDec radec, ZdAz soll, UInt_t stat, UInt_t stat2, Bool_t armed); 140 140 void UpdateWeather(const MCeCoCom &com); 141 141 -
trunk/MagicSoft/Cosy/main/MCosy.cc
r8864 r8865 406 406 407 407 //#ifdef EXPERT 408 // point.SetAccDec(0.4, 0.4);409 // point.SetVelocity(0.2); // fast: 0.6, slow: 0.2 408 //point.SetPointAccDec(0.3, 0.3); 409 //point.SetPointVelocity(0.3); 410 410 //#else 411 411 … … 413 413 // 414 414 point.SetPointAccDec(0.2, 0.1); 415 416 415 point.SetPointVelocity(0.1); 417 416 418 417 419 418 //#endif 420 421 // point.SetPointAccDec(0.4, 0.4);422 // point.SetPointVelocity(0.4);423 424 419 425 420 // original … … 428 423 // test 429 424 // return point.SetPosition(dst, kTRUE); 430 431 432 433 425 } 434 426 … … 565 557 fMac1->HandleError(); 566 558 fMac2->HandleError(); 567 if (fMac3)568 fMac3->HandleError();559 //if (fMac3) 560 // fMac3->HandleError(); 569 561 if (HasError() || HasZombie()) 570 562 return false; … … 700 692 //cout << "WM_TrackPosition: done. (return 0xabcd)" << endl; 701 693 return 0xabcd; 702 /* 694 703 695 case WM_ARM: 704 696 //cout << "WM_Position: start." << endl; 705 697 { 706 698 if (!CheckNetwork()) 707 return (void*)0xebb0;708 709 const bool arm = *((bool*)mp);710 if (arm)711 {699 return 0xebb0; 700 701 //const bool arm = *((bool*)mp); 702 //if (arm) 703 //{ 712 704 fMac1->Arm(); 713 705 fMac2->Arm(); 714 cout << "ARMED" << endl;715 }716 else717 {718 fMac1->Disarm();719 fMac2->Disarm();720 cout << "DISARMED" << endl;721 }706 //cout << "ARMED" << endl; 707 //} 708 //else 709 //{ 710 // fMac1->Disarm(); 711 // fMac2->Disarm(); 712 //cout << "DISARMED" << endl; 713 //} 722 714 } 723 715 //cout << "WM_Position: done. (return 0x7777)" << endl; 724 return (void*)0x9999;725 */ 716 return 0x9999; 717 726 718 case WM_POSITION: 727 719 //cout << "WM_Position: start." << endl; … … 963 955 Bool_t mac1 = fMac1 && !fMac1->IsZombieNode(); 964 956 Bool_t mac2 = fMac2 && !fMac2->IsZombieNode(); 965 Bool_t mac3 = fMac3 && !fMac3->IsZombieNode();957 //Bool_t mac3 = fMac3 && !fMac3->IsZombieNode(); 966 958 967 959 Bool_t zd1 = fZd1 && !fZd1->IsZombieNode(); … … 971 963 Double_t x = 0; 972 964 Double_t y = 0; 973 y = mac1 ? fMac1->GetRes() : (mac3 ? fMac3->GetRes() : env.GetValue("Az_ResRE[re/U_mot]", 1500)); 965 // y = mac1 ? fMac1->GetRes() : (mac3 ? fMac3->GetRes() : env.GetValue("Az_ResRE[re/U_mot]", 1500)); 966 y = mac1 ? fMac1->GetRes() : env.GetValue("Az_ResRE[re/U_mot]", 1500); 974 967 x = mac2 ? fMac2->GetRes() : env.GetValue("Zd_ResRE[re/U_mot]", 1500); 975 968 kResRE.Set(x,y); … … 1278 1271 avail |= (fMac1 && !fMac1->IsZombieNode()) ? 0x01 : 0; 1279 1272 avail |= (fMac2 && !fMac2->IsZombieNode()) ? 0x02 : 0; 1280 avail |= (fMac3 && !fMac3->IsZombieNode()) ? 0x04 : 0;1273 //avail |= (fMac3 && !fMac3->IsZombieNode()) ? 0x04 : 0; 1281 1274 avail |= (fZd1 && !fZd1->IsZombieNode()) ? 0x08 : 0; 1282 1275 avail |= (fZd2 && !fZd2->IsZombieNode()) ? 0x10 : 0; … … 1284 1277 // avail |= (!(fStatus&MDriveCom::kError) && 1 ? 0x40 : 0; 1285 1278 1279 Bool_t armed = kTRUE; 1280 1281 armed &= fMac1 && fMac1->IsArmed(); 1282 armed &= fMac2 && fMac2->IsArmed(); 1283 1286 1284 if (HasError()) 1287 1285 SetStatus(MDriveCom::kError); … … 1296 1294 fWin->UpdateWeather(*fCom); 1297 1295 fWin->Update(bendist, fTrackingError, fVelocity, /*fOffset,*/ 1298 fRaDec, fZdAzSoll, fStatus, avail );1296 fRaDec, fZdAzSoll, fStatus, avail, armed); 1299 1297 1300 1298 gLog.UpdateGui(); … … 1497 1495 fMac1=new Macs(id1, "Mac/Az"); 1498 1496 fMac2=new Macs(id3, "Mac/Zd"); 1499 if (id2>=0)1500 fMac3=new Macs(id2, "Mac/Az-Sync");1497 //if (id2>=0) 1498 // fMac3=new Macs(id2, "Mac/Az-Sync"); 1501 1499 1502 1500 fZd1=new ShaftEncoder(id4, "SE/Zd1"); … … 1519 1517 SetNode(fMac1); 1520 1518 SetNode(fMac2); 1521 if (id2>=0)1522 SetNode(fMac3);1519 //if (id2>=0) 1520 // SetNode(fMac3); 1523 1521 SetNode(fZd1); 1524 1522 SetNode(fZd2); … … 1618 1616 MCosy::MCosy(MEnv &env, const char *addr, const char *pointing) 1619 1617 : Network(), fObservatory(MObservatory::kMagic1), fStarguider(NULL), 1620 fZd1(0), fZd2(0), fAz(0), fMac1(0), fMac2(0), fMac3(0),1618 fZd1(0), fZd2(0), fAz(0), fMac1(0), fMac2(0), /*fMac3(0),*/ 1621 1619 fBackground(kBgdNone), fTriggerDisplay(kFALSE), fStatus(MDriveCom::kStopped), 1622 1620 fOutTp(0), fOutRep(0) … … 1721 1719 delete fMac1; 1722 1720 delete fMac2; 1723 if (fMac3)1724 delete fMac3;1721 //if (fMac3) 1722 // delete fMac3; 1725 1723 1726 1724 gLog << inf2 << "Deleting MGCosy." << endl; -
trunk/MagicSoft/Cosy/main/MCosy.h
r8862 r8865 87 87 Macs *fMac1; 88 88 Macs *fMac2; 89 Macs *fMac3;89 //Macs *fMac3; 90 90 91 91 MGCosy *fWin; -
trunk/MagicSoft/Cosy/tcpip/MTcpIpIO.cc
r8864 r8865 12 12 13 13 #include "MString.h" 14 #include "MTimeout.h" 14 15 15 16 #undef DEBUG … … 84 85 } 85 86 86 const Int_t l = tx.SendRaw(msg, len);87 if (l<0)88 {89 gLog << err << "ERROR - Sending TCP/IP frame to " << GetSocketAddress(tx) << endl;90 return false;91 }92 93 if (l!=len)94 {95 gLog << err << "ERROR - Sent wrong number (" << l << ") of bytes to " << GetSocketAddress(tx) << endl;96 return false;97 }98 99 87 #ifdef DEBUG 100 88 cout << "Tx: " << msg << flush; 101 89 #endif 90 91 const Int_t l = tx.SendRaw(msg, len); 92 if (l<0) 93 { 94 gLog << err << "ERROR - Sending TCP/IP frame to " << GetSocketAddress(tx) << endl; 95 return false; 96 } 97 98 if (l!=len) 99 { 100 gLog << err << "ERROR - Sent wrong number (" << l << ") of bytes to " << GetSocketAddress(tx) << endl; 101 return false; 102 } 102 103 103 104 return true; … … 164 165 const Int_t len = rx.RecvRaw(&c, 1); 165 166 166 // No data received (non-blocking mode) 167 if (len<0) 168 { 169 usleep(1); 170 continue; 171 } 172 173 // Data received with zero length! (Connection lost) 174 if (len==0) 175 return kFALSE; // This break is for TEST PURPOSE FIXME!!! 167 // For details see TSocket::RecvRaw 168 // -1: // ERROR 169 // EINVAL, EWOULDBLOCK 170 // -5: // EPIPE || ECONNRESET = Pipe broken or connection reset by peer 171 // 0: Data received with zero length! (Connection lost/call interrupted) 172 if (len<=0) 173 return kFALSE; 176 174 177 175 // Data received … … 208 206 fConnectionEstablished = kTRUE; 209 207 208 MTimeout timeout; 209 210 210 // Get connection on port fPortRx and redirected 211 211 while (!IsThreadCanceled()) … … 220 220 return kFALSE; 221 221 } 222 223 // *FALLTHROUGH* 222 timeout.Start(fTimeout); 223 224 // Go on waiting for new data 225 continue; 226 224 227 case kFALSE: // Time out, no data yet, go on waiting 228 if (timeout.HasTimedOut()) 229 { 230 gLog << warn << "WARNING - Connection to " << MTcpIpO::GetSocketAddress(sock) << " timed out." << endl; 231 return kFALSE; 232 } 225 233 226 234 // Go on waiting for new data … … 248 256 while (!IsThreadCanceled()) 249 257 { 258 // Wait for a new connection on RX port 250 259 socket = server.Accept(); 251 260 … … 271 280 if ((Long_t)socket<=0) 272 281 return; 282 283 gLog << all << "Connection established to " << MTcpIpO::GetSocketAddress(*socket) << "..." << endl; 273 284 274 285 if (!WaitForData(*socket)) -
trunk/MagicSoft/Cosy/tcpip/MTcpIpIO.h
r8864 r8865 18 18 { 19 19 private: 20 Int_t fPortRx; 20 Int_t fPortRx; // Port on which to listen for connections 21 Int_t fTimeout; // [ms] Timeout to listen for data to be received 22 21 23 Bool_t fConnectionEstablished; 22 24 … … 29 31 30 32 public: 31 MTcpIpI(Int_t rx ) : MThread(Form("MTcpIpI::%d", rx)), fPortRx(rx), fConnectionEstablished(kFALSE) { /*RunThread();*/ }33 MTcpIpI(Int_t rx, UInt_t timeout=5000) : MThread(Form("MTcpIpI::%d", rx)), fPortRx(rx), fTimeout(timeout), fConnectionEstablished(kFALSE) { /*RunThread();*/ } 32 34 ~MTcpIpI() { CancelThread(); } 33 35
Note:
See TracChangeset
for help on using the changeset viewer.