Changeset 1111 for trunk/MagicSoft/Cosy/main
- Timestamp:
- 12/12/01 13:26:34 (23 years ago)
- Location:
- trunk/MagicSoft/Cosy/main
- Files:
-
- 1 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Cosy/main/MCosy.cc
r926 r1111 22 22 //#include <sys/resource.h> // PRIO_PROCESS 23 23 24 ClassImp(MCosy); 25 24 26 typedef struct tm tm_t; 25 27 … … 32 34 double Rad2SE(double rad) 33 35 { 34 return 16384.0/ D2PI*rad;36 return 16384.0/k2Pi*rad; 35 37 } 36 38 37 39 double Rad2ZdRE(double rad) 38 40 { 39 return 16384.0/ D2PI*rad*kGearRatio.X();41 return 16384.0/k2Pi*rad*kGearRatio.X(); 40 42 } 41 43 42 44 double Rad2AzRE(double rad) 43 45 { 44 return 16384.0/ D2PI*rad*kGearRatio.Y();46 return 16384.0/k2Pi*rad*kGearRatio.Y(); 45 47 } 46 48 … … 68 70 69 71 ZdAz source = src * 360.0/16384.0; 70 ZdAz dest = dst * 360.0/D2PI;72 ZdAz dest = dst * kRad2Deg; 71 73 72 74 if (dest.Zd()>-1e-6 && dest.Zd()<1e-6) 73 return dst*(16384.0/ D2PI);75 return dst*(16384.0/k2Pi); 74 76 75 77 const float fZdMin = -67; … … 122 124 } 123 125 124 126 // -------------------------------------------------------------------------- 127 // 128 // GetSePos, reads the Shaftencoder positions from the Can-drivers 129 // for the shaftencoders. The two shaft encoders at the elevation axis 130 // are avaraged. The values are returned as a ZdAz object. 131 // 132 // The positions are alway up-to-date because the shaftencoders are 133 // sending all changes immediatly. 134 // 125 135 ZdAz MCosy::GetSePos() 126 136 { 137 // 138 // Get the values 139 // 127 140 const int p0 = fZd1->GetPos(); 128 141 const int p1 = fZd2->GetPos(); … … 144 157 } 145 158 159 // -------------------------------------------------------------------------- 160 // 161 // request the current positions from the rotary encoders. 162 // use GetRePos to get the psotions. If the request fails the function 163 // returns kFALSE, otherwise kTRUE 164 // 165 Bool_t MCosy::RequestRePos() 166 { 167 // 168 // Send request 169 // 170 fMac2->RequestSDO(0x6004); 171 fMac1->RequestSDO(0x6004); 172 173 // 174 // Wait until the objects are received. 175 // 176 WaitForSdos(); 177 178 // 179 // If waitng was not interrupted everything is ok. return. 180 // 181 if (!StopWaitingForSDO()) 182 return kTRUE; 183 184 // 185 // If the waiting was interrupted due to a network error, 186 // print some logging message. 187 // 188 if (HasError()) 189 lout << "Error #6004 (requesting re pos from Macs) happened." << endl; 190 191 return kFALSE; 192 } 193 194 // -------------------------------------------------------------------------- 195 // 196 // reads the Rotary encoder positions from the last request of the Macs. 197 // 198 // The positions are returned as a ZdAz object. Use RequestRePos to request 199 // the current positions first. 200 // 146 201 ZdAz MCosy::GetRePos() 147 202 { … … 149 204 } 150 205 206 // -------------------------------------------------------------------------- 207 // 208 // reads the Rotary encoder positions from the Macs. 209 // 210 // The positions are returned as a ZdAz object. The positions are the ones 211 // which are send as PDOs to the computer. This is done at a given 212 // frequency. Which means, that this positions are not ought to be 213 // up-to-date. 214 // 151 215 ZdAz MCosy::GetRePosPdo() 152 216 { … … 154 218 } 155 219 220 // -------------------------------------------------------------------------- 221 // 222 // set the velocity and accelerations for position maneuvers. 223 // 224 // The acceleratin is set as given (in percent of maximum). 225 // The velocity is given in percent, depending on the ratio (<1 or >1) 226 // one of the axis becomes a slower velocity. This is used for maneuvers 227 // in which both axis are moved synchromously and should reach their 228 // target position at the same time. 229 // 156 230 void MCosy::SetPosVelocity(const Float_t ratio, Float_t vel, Float_t acc) 157 231 { … … 186 260 } 187 261 262 // -------------------------------------------------------------------------- 263 // 264 // Does a relative positioning. 265 // 266 // The steps to move are given in a ZdAz object relative to the current 267 // position. The coordinates are given in Roteryencoder steps. 268 // Axis 1 is moved only if axe1==kTRUE, Axis 2 is moved only 269 // if Axis 2==kTRUE. The function waits for the movement to be finished. 270 // 188 271 void MCosy::DoRelPos(const ZdAz &rd, const Bool_t axe1, const Bool_t axe2) 189 272 { 190 SetStatus( kMoving);273 SetStatus(MCosy::kMoving); 191 274 192 275 if (axe1) fMac2->StartRelPos(rd.Zd()); … … 200 283 } 201 284 285 // -------------------------------------------------------------------------- 286 // 287 // check for a break-signal (from the msgqueue) and errors. 288 // 289 int MCosy::StopWaitingForSDO() const 290 { 291 return Break() || HasError(); 292 } 293 294 // -------------------------------------------------------------------------- 295 // 296 // Waits for a movement to become finished. 297 // 298 // First waits for all peding Sdos, then waits until both motors are stopped 299 // or waiting for SDOs was stopped (either by an error or by Break) 300 // 301 void MCosy::WaitForEndMovement() 302 { 303 WaitForSdos(); 304 305 while ((fMac1->IsPositioning() || fMac2->IsPositioning()) && !StopWaitingForSDO()) 306 usleep(1); 307 } 308 309 // -------------------------------------------------------------------------- 310 // 311 // Check for an error... 312 // 313 // This is ment for usage after the Action: All Motors Stop. 314 // 202 315 void MCosy::CheckForError() 203 316 { 317 // 318 // Check all Can-Nodes for an Error. If there is no error the motor 319 // status is set to stopped. 320 // 204 321 if (!HasError()) 205 322 { 206 SetStatus( kStopped);323 SetStatus(MCosy::kStopped); 207 324 return; 208 325 } 209 326 210 SetStatus(kError); 327 // 328 // If there is an error, the error status is set to Error. 329 // 330 SetStatus(MCosy::kError); 331 332 // 333 // No try to handle the error. 334 // 211 335 fMac1->HandleError(); 212 336 fMac2->HandleError(); 337 338 // 339 // If the error couldn't get solved return 340 // 213 341 if (HasError()) 214 342 return; 215 343 216 SetStatus(kStopped); 217 } 218 344 // 345 // Set motor status to stopped 346 // 347 SetStatus(MCosy::kStopped); 348 } 349 350 // -------------------------------------------------------------------------- 351 // 352 // Move the telescope to the given position. The position must be given in 353 // a ZdAz object in rad. 354 // 355 // The first positioning is done absolutely. If we didn't reach the 356 // correct psotion we try to correct for this by 10 relative position 357 // maneuvers. If this doesn't help positioning failed. 358 // 359 // As a reference the shaftencoder values are used. 360 // 219 361 int MCosy::SetPosition(const ZdAz &dst) // [rad] 220 362 { … … 296 438 } 297 439 298 Bool_t MCosy::RequestRePos() 299 { 300 301 fMac2->RequestSDO(0x6004); 302 fMac1->RequestSDO(0x6004); 440 // -------------------------------------------------------------------------- 441 // 442 // Sets the tracking velocity 443 // 444 // The velocities are given in a ZdAz object in re/min. Return kTRUE 445 // in case of success, kFALSE in case of failure. 446 // 447 Bool_t MCosy::SetVelocity(ZdAz v) 448 { 449 // 450 // Send the new velocities for both axes. 451 // 452 fMac2->SendSDO(0x3006, 1, (LWORD_t)v.Zd()); // SetRpmVelocity [re/min] 453 fMac1->SendSDO(0x3006, 1, (LWORD_t)v.Az()); // SetRpmVelocity [re/min] 454 455 // 456 // Wait for the objects to be OKed. 457 // 303 458 WaitForSdos(); 459 460 // 461 // If the waiting for the objects wasn't interrupted return kTRUE 462 // 304 463 if (!StopWaitingForSDO()) 305 464 return kTRUE; 306 465 307 if (HasError()) 308 lout << "Error #6004 (requesting re pos from Macs) happened." << endl; 309 310 return kFALSE; 311 } 312 313 Bool_t MCosy::SetVelocity(ZdAz v) 314 { 315 fMac2->SendSDO(0x3006, 1, (LWORD_t)v.Zd()); // SetRpmVelocity [re/min] 316 fMac1->SendSDO(0x3006, 1, (LWORD_t)v.Az()); // SetRpmVelocity [re/min] 317 WaitForSdos(); 318 if (!StopWaitingForSDO()) 319 return kTRUE; 320 466 // 467 // print a message if the interruption was due to a Can-node Error 468 // 321 469 if (HasError()) 322 470 lout << "Error #3006 (setting velocity of Macs) happened." << endl; … … 325 473 } 326 474 475 // -------------------------------------------------------------------------- 476 // 477 // Initializes Tracking mode 478 // 479 // Initializes the accelerations of both axes with 90% of the maximum 480 // acceleration. Set the status for moving and tracking and starts thr 481 // revolution mode. 482 // 327 483 void MCosy::InitTracking() 328 484 { … … 336 492 fMac1->SetDeceleration(0.90*fMac1->GetVelRes()); 337 493 338 SetStatus( kMoving |kTracking);494 SetStatus(MCosy::kMoving | MCosy::kTracking); 339 495 340 496 fMac2->SetRpmMode(TRUE); … … 342 498 } 343 499 500 // -------------------------------------------------------------------------- 501 // 502 // Limits the speed. 503 // 504 // This function should work as a limiter. If a tracking error is too large 505 // to be corrected fast enough we would get enormous velocities. These 506 // velocities are limited to the maximum velocity. 507 // 344 508 void MCosy::LimitSpeed(ZdAz *vt, const ZdAz &vcalc) const 345 509 { … … 527 691 } 528 692 529 int MCosy::IsPositioning() const 530 { 531 return (fMac1->IsPositioning() || fMac2->IsPositioning()) && !StopWaitingForSDO(); 532 } 533 534 void MCosy::WaitForEndMovement() 535 { 536 WaitForSdos(); 537 538 while (IsPositioning()) 539 usleep(1); 540 } 541 693 // -------------------------------------------------------------------------- 694 // 695 // Stops the movement of both motors. 696 // 697 // Sets the status to stopping. Sets the deceleration to 50% of the maximum. 698 // stops. Quits the revolution mode and wait for the end of the movement. 699 // 542 700 void MCosy::StopMovement() 543 701 { 544 SetStatus(kStopping); 545 702 // 703 // Set status to stopped 704 // 705 SetStatus(MCosy::kStopping); 706 707 // 708 // set deceleration to 50% 709 // 546 710 cout << "Stopping positioning..." << endl; 547 711 fMac1->SetDeceleration(0.5*fMac1->GetVelRes()); 548 712 fMac2->SetDeceleration(0.5*fMac2->GetVelRes()); 549 713 550 cout << "Stoping possible RPM mode..." << endl; 714 // 715 // Stop revolution mode (movement) 716 // 717 cout << "Stoping possibleRPM mode..." << endl; 551 718 fMac1->SetRpmMode(FALSE); 552 719 fMac2->SetRpmMode(FALSE); 553 720 721 // 722 // Wait for the movement to really be finished. 723 // 554 724 cout << "Waiting for silence..." << endl; 555 725 WaitForEndMovement(); 556 726 727 // 728 // Check whether everything works fine. 729 // 557 730 CheckForError(); 558 559 731 cout << "Movement stopped." << endl; 560 732 } … … 587 759 588 760 RaDec rd(37.94, 89.2644); 589 ZdAz za=sla.CalcZdAz(rd* D2PI/360.0)*16384.0/D2PI;761 ZdAz za=sla.CalcZdAz(rd*kDeg2Rad)*16384.0/k2Pi; 590 762 591 763 cout << "Calc Zd: " << za.Zd() << " Az: " << za.Az() << endl; … … 607 779 ZdAz dest = *((ZdAz*)mp); 608 780 609 SetPosition(dest* D2PI/360.0);781 SetPosition(dest*kDeg2Rad); 610 782 } 611 783 cout << "WM_Position: done. (return 0x7777)" << endl; … … 616 788 { 617 789 RaDec dest = *((RaDec*)mp); 618 TrackPosition(dest* D2PI/360.0);790 TrackPosition(dest*kDeg2Rad); 619 791 } 620 792 cout << "WM_Track: done. (return 0x8888)" << endl; … … 843 1015 844 1016 845 int MCosy::StopWaitingForSDO() const 846 { 847 return Break() || HasError(); 848 } 849 1017 // -------------------------------------------------------------------------- 1018 // 1019 // Start the work of the application: 1020 // 1021 // Start the Can-Network. 1022 // Start the MCosy::TalkThread thread. 1023 // turn on the gui update 1024 // 850 1025 void MCosy::Start() 851 1026 { … … 861 1036 } 862 1037 1038 // -------------------------------------------------------------------------- 1039 // 1040 // Start the work of the application: 1041 // 1042 // Turn of the gui update 1043 // stop the MCosy::TalkThread thread. 1044 // Stop the network 1045 // 863 1046 void MCosy::Stop() 864 1047 { -
trunk/MagicSoft/Cosy/main/MCosy.h
r926 r1111 37 37 }; 38 38 39 #define kError 0x0140 #define kMoving 0x0241 #define kTracking 0x0442 #define kStopping 0x0843 #define kStopped 0x1044 39 45 40 class TTimer; … … 50 45 51 46 private: 47 enum 48 { 49 kError = 0x01, 50 kMoving = 0x02, 51 kTracking = 0x04, 52 kStopping = 0x08, 53 kStopped = 0x10 54 }; 55 52 56 ShaftEncoder *fZd1; 53 57 ShaftEncoder *fZd2; … … 99 103 100 104 int StopWaitingForSDO() const; 101 int IsPositioning() const;102 105 void CheckForError(); 103 106 … … 117 120 118 121 static ZdAz CorrectTarget(const ZdAz &src, const ZdAz &dst); 119 // static ZdAz RaDec2ZdAz(const double mjd, const RaDec &pos, const RaDec &pm=RaDec(0,0));122 // static ZdAz RaDec2ZdAz(const double mjd, const RaDec &pos, const RaDec &pm=RaDec(0,0)); 120 123 124 ClassDef(MCosy, 0) 121 125 }; 122 126 -
trunk/MagicSoft/Cosy/main/MainLinkDef.h
r924 r1111 5 5 #pragma link off all functions; 6 6 7 #pragma link C++ class MCosy; 8 7 9 #endif -
trunk/MagicSoft/Cosy/main/Makefile
r924 r1111 35 35 MStarguider.cc 36 36 37 SRCS = $(SRCFILES) 38 HEADERS = $(SRCFILES:.cc=.h) 39 OBJS = $(SRCFILES:.cc=.o) 37 SRCS = $(SRCFILES) 38 HEADERS = $(SRCFILES:.cc=.h) 39 OBJS = $(SRCFILES:.cc=.o) 40 CINTHEADERS = $(HEADERS) 40 41 41 42 ############################################################
Note:
See TracChangeset
for help on using the changeset viewer.