Changeset 808
- Timestamp:
- 05/25/01 16:51:24 (24 years ago)
- Location:
- trunk/MagicSoft/Cosy
- Files:
-
- 1 added
- 29 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Cosy/Changelog
r807 r808 3 3 2001/05/25 - Thomas Bretz: 4 4 5 * .cosyrc: 6 - added 7 5 8 * MCosy.[h,cc]: 6 9 - changed the error handling os SetPosition -
trunk/MagicSoft/Cosy/MCosy.cc
r738 r808 6 6 7 7 #include <TROOT.h> 8 #include <TEnv.h> 8 9 #include <TSystem.h> 9 10 #include <TApplication.h> 10 11 11 12 #include "MGCosy.h" 13 #include "Slalib.h" 12 14 13 15 #include "macs.h" 14 16 #include "timer.h" 15 #include "slalib.h"16 #include "slamac.h"17 17 #include "shaftencoder.h" 18 18 … … 59 59 ZdAz MCosy::CorrectTarget(const ZdAz &src, const ZdAz &dst) 60 60 { 61 // CorrectTarget [se] 62 61 63 // src [se] 62 64 // dst [rad] … … 71 73 72 74 if (dest.Zd()>-1e-6 && dest.Zd()<1e-6) 73 return dst ;75 return dst*(16384.0/D2PI); 74 76 75 77 const float fZdMin = -67; … … 119 121 min = dist; 120 122 } 123 cout << "Shortest Zd: " << ret.Zd() << " Az:" << ret.Az() << endl; 121 124 return ret*(16384.0/360.0); 122 125 } … … 160 163 161 164 cout << "Positioning to Target:" << endl; 162 // cout << "Source Alt: " << src.Alt() << "se Az:" << src.Az() << "se -> Alt: " << srcd.Alt() << kDEG << " Az:" << srcd.Az() << kDEG << endl; 163 // cout << "Shortest Dest Alt: " << dest.Alt() << "se Az:" << dest.Az() << "se -> Alt: " << sed.Alt() << kDEG << " Az:" << sed.Az() << kDEG << endl; 164 165 for (int i=0; i<10; i++) 165 //cout << "Source Zd: " << src.Zd() << "se Az:" << src.Az() << "se" << endl; 166 //cout << "Destination Zd: " << Rad2SE(dst.Zd()) << "se Az:" << Rad2SE(dst.Az()) << "se" << endl; 167 cout << "Shortest Dest Zd: " << dest.Zd() << "se Az:" << dest.Az() << "se" << endl; 168 169 for (int i=0; i<10 && !StopWaitingForSDO(); i++) 166 170 { 167 171 // … … 242 246 cout << "SDO..." << flush; 243 247 244 while (fMac1->IsPositioning() || fMac2->IsPositioning()) 245 { 246 if (StopWaitingForSDO()) 247 return FALSE; 248 248 while (fMac1->IsPositioning() || fMac2->IsPositioning() && !StopWaitingForSDO()) 249 249 usleep(1); 250 }251 250 252 251 cout << "done." << endl; 252 } 253 254 if (StopWaitingForSDO()) 255 { 256 fMac1->HandleError(); 257 fMac2->HandleError(); 253 258 } 254 259 … … 259 264 void MCosy::TrackPosition(const RaDec &dst) // ra, dec [rad] 260 265 { 266 Slalib sla; 267 261 268 // 262 269 // Position to actual position … … 265 272 t.GetTime(); 266 273 267 RaDec pm;268 ZdAz dest = RaDec2ZdAz(t.GetMjd(), dst, pm);274 sla.Set(t.GetMjd()); 275 ZdAz dest = sla.CalcZdAz(dst); 269 276 270 277 if (!SetPosition(dest)) … … 273 280 return; 274 281 } 275 276 if (StopWaitingForSDO())277 return;278 282 279 283 // … … 299 303 fMac2->SetAcceleration(0.90*fMac2->GetVelRes()); 300 304 fMac2->SetDeceleration(0.90*fMac2->GetVelRes()); 305 301 306 fMac1->SetAcceleration(0.90*fMac1->GetVelRes()); 302 307 fMac1->SetDeceleration(0.90*fMac1->GetVelRes()); … … 315 320 fTracking = kTRUE; 316 321 322 ofstream fout("cosy.pos"); 323 fout << " Mjd/10ms Offset/RE Deviation/RE V/RE/MIN/4" << endl; 324 317 325 // 318 326 // We want to reach the theoretical position exactly in about 0.5s … … 330 338 // Request theoretical Position for a time in the future (To+dt) from CPU 331 339 // 332 dest = CorrectTarget(GetSePos(), RaDec2ZdAz(t.GetMjd()+dt/(60*60*24), dst, pm)); 340 sla.Set(t.GetMjd()+dt/(60*60*24)); 341 dest = CorrectTarget(GetSePos(), sla.CalcZdAz(dst)); 333 342 334 343 fMac2->RequestSDO(0x6004); … … 392 401 // calculate control deviation - for the moment for convinience 393 402 // 394 if (fMac1->GetTime()-s > 1) 395 { 396 ZdAz dest0=CorrectTarget(GetSePos(), 397 RaDec2ZdAz(fMac2->GetMjd(), dst, pm)); 403 404 //if (fMac1->GetTime()-s > 1) 405 { 406 const double mjd = fMac2->GetMjd(); 407 sla.Set(mjd); 408 ZdAz dest0=CorrectTarget(GetSePos(), sla.CalcZdAz(dst)); 398 409 dest0 *= kGearRatio; 399 410 dest0 -= GetRePos()+offset; 400 411 dest0.Round(); 401 cout << "Control deviation: "; 402 cout << setw(4) << (int)fOffset.Zd() << " "; 403 cout << setw(4) << (int)fOffset.Az() << " re "; 404 405 cout << setw(4) << dest0.Zd() << " "; 406 cout << setw(4) << dest0.Az() << " re V: "; 407 cout << setw(4) << vt.Zd() << " "; 408 cout << setw(4) << vt.Az() << " re/min/4" << endl; 412 //cout << "Control deviation: "; 413 fout << setprecision(15) << setw(15) << mjd*60.*60.*24. << " "; 414 fout << setw(4) << (int)fOffset.Zd() << " "; 415 fout << setw(4) << (int)fOffset.Az() << " "; 416 417 fout << setw(4) << dest0.Zd() << " "; 418 fout << setw(4) << dest0.Az() << " "; 419 fout << setw(4) << vt.Zd() << " "; 420 fout << setw(4) << vt.Az() << endl; 409 421 s = (int)fMac1->GetTime(); 410 422 } … … 427 439 428 440 cout << "Tracking stopped." << endl; 429 } 430 431 ZdAz MCosy::RaDec2ZdAz(const double mjd, const RaDec &dst, const RaDec &pm) 432 { 433 int status; 434 435 // 436 // calculate observers location (goe) 437 // 438 double fPhi, fElong; 439 slaDaf2r(51, 38, 48.0, &fPhi, &status); 440 slaDaf2r( 9, 56, 36.0, &fElong, &status); 441 442 // cout << "fPhi: 51ø38'48.0\" = " << 360.0/D2PI*fPhi << endl; 443 // cout << "fElong: 9ø56'36.0\" = " << 360.0/D2PI*fElong << endl; 444 445 // 446 // ----- calculate star independent parameters ---------- 447 // 448 double fAmprms[21]; 449 double fAoprms[14]; 450 slaMappa(2000.0, mjd, fAmprms); 451 slaAoppa(mjd, 0, // mjd, UT1-UTC 452 fElong, fPhi, 148, // gttingen long, lat, height 453 0, 0, // polar motion x, y-coordinate (radians) 454 273.155, 1013.25, 0.5, // temp, pressure, humidity 455 0.2, 0.0065, // wavelength, tropo lapse rate 456 fAoprms); 457 458 // 459 // ---- Mean to apparent ---- 460 // 461 double r=0, d=0; 462 slaMapqkz(dst.Ra(), dst.Dec(), (double*)fAmprms, &r, &d); 463 // 464 // Doesn't work - don't know why 465 // 466 // slaMapqk(dst.Ra(), dst.Dec(), pm.Ra(), pm.Dec(), // ra, dec (rad), r, d (rad) 467 // 0, 0, fAmprms, &r, &d); 468 // 469 470 // 471 // -- apparent to observed -- 472 // 473 double r1=0; // ra 474 double d1=0; // dec 475 double h0=0; // ha 476 477 double az, zd; 478 slaAopqk (r, d, fAoprms, 479 &az, // observed azimuth (radians: N=0,E=90) 480 &zd, // observed zenith distance (radians) 481 &h0, // observed hour angle (radians) 482 &d1, // observed declination (radians) 483 &r1); // observed right ascension (radians) 484 485 return ZdAz(zd, az); 441 442 if (StopWaitingForSDO()) 443 { 444 fMac1->HandleError(); 445 fMac2->HandleError(); 446 } 486 447 } 487 448 … … 490 451 switch (msg) 491 452 { 453 case WM_WAIT: 454 cout << "Wait for execution of Proc: done." << endl; 455 return NULL; 456 492 457 case WM_STOP: 493 458 cout << "Stopping positioning." << endl; … … 514 479 { 515 480 cout << "WM_POLARIS: START" << endl; 481 Slalib sla; 482 516 483 Timer t; 517 484 t.GetTime(); 518 485 486 sla.Set(t.GetMjd()); 487 519 488 RaDec rd(37.94, 89.2644); 520 ZdAz za= MCosy::RaDec2ZdAz(t.GetMjd(),rd*D2PI/360.0)*16384.0/D2PI;489 ZdAz za=sla.CalcZdAz(rd*D2PI/360.0)*16384.0/D2PI; 521 490 522 491 cout << "Calc Zd: " << za.Zd() << " Az: " << za.Az() << endl; … … 537 506 { 538 507 ZdAz dest = *((ZdAz*)mp); 508 539 509 SetPosition(dest*D2PI/360.0); 540 510 } … … 561 531 // 562 532 Network::Start(); 533 534 const int res = fMac3->GetVelRes(); 535 536 fMac3->SetVelocity(res); 537 fMac3->SetAcceleration(res); 538 fMac3->SetDeceleration(res); 539 540 fMac3->SetSyncMode(); 541 542 fMac1->SetHome(250000); 543 fMac2->SetHome(250000); 563 544 PostMsg(WM_PRESET, 0, 0); 545 PostMsg(WM_WAIT, 0, 0); 546 547 fMac1->ReqPos(); 548 fMac2->ReqPos(); 549 550 const ZdAz repos=GetRePos(); 551 cout << "APOS: " << repos.Zd() << "re, " << repos.Az() << "re" << endl; 552 553 TEnv env(".cosyrc"); 554 555 cout << Deg2AzRE(env.GetValue("MinAz[Deg]", -1.0)) << " < Az < " 556 << Deg2AzRE(env.GetValue("MaxAz[Deg]", +1.0)) << "RE" << endl; 557 cout << env.GetValue("MinAz[Deg]", -1.0) << " < Az < " 558 << env.GetValue("MaxAz[Deg]", +1.0) << kDEG << endl; 559 cout << Deg2ZdRE(env.GetValue("MinZd[Deg]", -1.0)) << "RE < Zd < " 560 << Deg2ZdRE(env.GetValue("MaxZd[Deg]", +1.0)) << "RE" << endl; 561 562 fMac1->SetNegEndswitch(Deg2AzRE(env.GetValue("MinAz[Deg]", -1.0))); 563 fMac1->SetPosEndswitch(Deg2AzRE(env.GetValue("MaxAz[Deg]", +1.0))); 564 565 /* 566 fMac2->SetNegEndswitch(Deg2ZdRE(env.GetValue("MinZd[Deg]", -1.0))); 567 fMac2->SetPosEndswitch(Deg2ZdRE(env.GetValue("MaxZd[Deg]", +1.0))); 568 */ 569 fMac3->SetSyncMode(); 564 570 /* 565 571 cout << "PostMsg(WM_PRESET)" << endl; … … 584 590 setpriority(PRIO_PROCESS, 0, 10); 585 591 592 Slalib sla; 586 593 while (1) 587 594 { … … 592 599 usleep(1); 593 600 594 RaDec pm;595 601 ZdAz sollalt; // [se] 596 602 ZdAz sollaz; // [se] … … 641 647 // calculate were we should be 642 648 // 643 sollalt = CorrectTarget(ist, RaDec2ZdAz(t, fRaDec, pm)); 649 sla.Set(t); 650 sollalt = CorrectTarget(ist, sla.CalcZdAz(fRaDec)); 644 651 645 652 old.Zd(ist.Zd()); … … 659 666 // calculate were we should be 660 667 // 661 sollaz = CorrectTarget(ist, RaDec2ZdAz(t, fRaDec, pm)); 668 sla.Set(t); 669 sollaz = CorrectTarget(ist, sla.CalcZdAz(fRaDec)); 662 670 663 671 old.Az(ist.Az()); … … 724 732 fMac1=new Macs(1, lout); 725 733 fMac2=new Macs(2, lout); 734 fMac3=new Macs(3, lout); 726 735 fAlt1=new ShaftEncoder(4, lout); 727 736 fAlt2=new ShaftEncoder(5, lout); … … 733 742 SetNode(fMac1); 734 743 SetNode(fMac2); 744 SetNode(fMac3); 735 745 SetNode(fAlt1); 736 746 SetNode(fAlt2); … … 756 766 delete fMac1; 757 767 delete fMac2; 768 delete fMac3; 758 769 759 770 delete fWin; -
trunk/MagicSoft/Cosy/MCosy.h
r738 r808 13 13 #define WM_STOP 0x1003 14 14 #define WM_POLARIS 0x1004 15 #define WM_WAIT 0x1005 15 16 16 17 class ShaftEncoder; … … 27 28 Macs *fMac1; 28 29 Macs *fMac2; 30 Macs *fMac3; 29 31 30 32 MGCosy *fWin; … … 60 62 61 63 static ZdAz CorrectTarget(const ZdAz &src, const ZdAz &dst); 62 static ZdAz RaDec2ZdAz(const double mjd, const RaDec &pos, const RaDec &pm=RaDec(0,0));64 // static ZdAz RaDec2ZdAz(const double mjd, const RaDec &pos, const RaDec &pm=RaDec(0,0)); 63 65 }; 64 66 -
trunk/MagicSoft/Cosy/Makefile
r748 r808 92 92 catalog/SaoFile.cc \ 93 93 catalog/StarCatalog.cc \ 94 catalog/Slalib.cc \ 94 95 videodev/Camera.cc \ 95 96 videodev/Filter.cc \ -
trunk/MagicSoft/Cosy/Starguider.cc
r748 r808 293 293 } 294 294 295 void Starguider::Execute(const unsigned long n, char*img, struct timeval *tm)295 void Starguider::Execute(const unsigned long n, byte *img, struct timeval *tm) 296 296 { 297 297 … … 329 329 if (fDisplay->IsEntryChecked(IDM_kCatalog)) 330 330 { 331 charcimg[768*576];331 byte cimg[768*576]; 332 332 333 333 XY xy = fCRaDec->GetCoordinates(); -
trunk/MagicSoft/Cosy/Starguider.h
r748 r808 60 60 // Execution of one frame - this function may be overloaded! 61 61 // 62 void Execute(const unsigned long n, char*img, struct timeval *tm);62 void Execute(const unsigned long n, byte *img, struct timeval *tm); 63 63 }; 64 64 -
trunk/MagicSoft/Cosy/aposs/Magic.m
r738 r808 3 3 /*-------------------------------------------------------------------------*/ 4 4 5 DIM errlist[9] 5 DIM errlist[9] /* idx 1=number of valid entries */ 6 6 7 7 /* ----------------------------------------------------------------------- */ … … 10 10 /* */ 11 11 kVERSION = 0 /* */ 12 kSUBVERSION = 50/* */12 kSUBVERSION = 62 /* */ 13 13 /* */ 14 14 /* HISTORY: */ 15 /* */ 16 /* * V0.62: */ 17 /* - changed handling of 0x2000/1/2 added /3 */ 18 /* */ 19 /* * V0.61: */ 20 /* - corrected problems with the error handling */ 21 /* */ 22 /* * V0.60: */ 23 /* - introduced syncronisation */ 24 /* */ 25 /* * V0.52: */ 26 /* - changed the handling of the endswitch error (unknown switch) */ 27 /* */ 28 /* * V0.51: */ 29 /* - made errlist working */ 15 30 /* */ 16 31 /* * V0.50: */ … … 65 80 /* 0x1800 x rw Enable PDO1 (Axe Status, Position) */ 66 81 /* 0x2000 0 rw Maximum positioning error */ 67 /* 1 rw Negative Software Endswitch */ 68 /* 2 rw Positive Software Endswitch */ 82 /* 1 rw Negative Software Endswitch Value (Set=Enable) */ 83 /* 2 rw Positive Software Endswitch Value (Set=Enable) */ 84 /* 3 rw Enable/Disable Software Endswitch */ 69 85 /* 0x2002 x rw Velocity */ 70 86 /* 0x2003 0 wo Acceleration */ … … 76 92 /* 0x3006 0 wo Velocity Mode 'strt', 'stop' */ 77 93 /* 1 wo VelMode Velocity */ 94 /* 0x3007 x wo Syncronisation 'sync' */ 78 95 /* 0x3008 x wo Nowait 'on', 'off' */ 79 96 /* 0x6000 x rw Rotation Direction */ 80 97 /* 0x6002 x rw Velocity Resolution */ 81 /* 0x6003 0 wo Define present position as origin 98 /* 0x6003 0 wo Define present position as origin ('set') */ 82 99 /* 1 wo Define new origin (0=delete) */ 83 100 /* 2 rw Home Offset */ … … 99 116 SET ENCODERTYPE 0 /* Incremental Encoder */ 100 117 SET ENCODER 500 /* Encoder has 500 Ticks */ 118 SET MENCODERTYPE 0 /* Incremental Encoder (Master) */ 119 SET MENCODER 500 /* Encoder has 500 Ticks (Master) */ 101 120 SET VELMAX 3600 /* Motor: Maximum rounds per minute */ 102 121 SET POSERR 1500 /* Maximum tolarable Position error (qc) 0.1° */ … … 112 131 113 132 /*----------------*/ 133 /* syncronisation */ 134 /*----------------*/ 135 SET MENCODERTYPE 0 /* Incremental Encoder (Master) */ 136 SET MENCODER 500 /* Encoder has 500 Ticks (Master) */ 137 SET SYNCFACTM 1 /* Master Sync Velocity factor */ 138 SET SYNCFACTS 1 /* Slave Sync Velocity factor */ 139 SET SYNCPOSOFFS 0 /* Sync Position offset between M/S */ 140 SET SYNCACCURACY 50 /* When to set Accuracy Flag */ 141 SET REVERS 0 /* How to handle reversation of vel */ 142 143 /*----------------*/ 114 144 /* Inputs */ 115 145 /*----------------*/ … … 181 211 /*-------------------------------------------------------------------------*/ 182 212 /* ON CANMSG GOSUB PROC_CANMSG */ 183 i = 8213 i = 9 184 214 while (i) do 185 215 errlist[i] = 0 … … 197 227 198 228 PRINT "Starting Mainloop..." 229 199 230 MAINLOOP: 200 231 rc = CANIN sdorx 0 0 canhi canlo … … 225 256 */ 226 257 if (idx == 0x1003 and subidx == 0 and sdoval == 0) then 227 i = 0228 while (i <9) do258 i = 9 259 while (i) do 229 260 errlist[i] = 0 230 i = i +1261 i = i - 1 231 262 endwhile 232 263 elseif (idx == 0x1010 and sdoval == 's'<<24|'a'<<16|'v'<<8|'e') then … … 244 275 SET POSERR sdoval 245 276 elseif (subidx == 1) then 246 if ((sdoval>>30)&1) then 247 SET NEGLIMIT sdoval & 0x3fffffff 248 SET SWNEGLIMACT 1 249 else 250 SET SWNEGLIMACT 0 251 endif 277 SET NEGLIMIT sdoval 278 SET SWNEGLIMACT 1 252 279 elseif (subidx == 2) then 253 if ((sdoval>>31)&1) then 254 SET POSLIMIT sdoval & 0x3fffffff 255 SET SWPOSLIMACT 1 256 else 257 SET SWPOSLIMACT 0 258 endif 280 SET POSLIMIT sdoval 281 SET SWPOSLIMACT 1 282 elseif (subidx == 3) then 283 SET SWNEGLIMACT sdoval&1 284 SET SWPOSLIMACT (sdoval>>1)&1 259 285 endif 260 286 elseif (idx == 0x2002) then … … 306 332 CVEL sdoval 307 333 endif 334 elseif (idx == 0x3007 and sdoval == 's'<<24|'y'<<16|'n'<<8|'c') then 335 SYNCP 308 336 elseif (idx == 0x3008) then 309 337 if (sdoval == 'o'<<24|'n'<<16) then … … 325 353 SET POSDRCT 1 326 354 endif 327 /* elseif (idx == 0x6001) then328 SET ENCODER sdoval*/329 355 elseif (idx == 0x6002) then 330 356 SET VELRES sdoval 331 357 elseif (idx == 0x6003) then 332 if (subidx == 0 ) then358 if (subidx == 0 and sdoval == 's'<<24|'e'<<16|'t'<<8) then 333 359 DEF ORIGIN 334 360 elseif (subidx == 1) then … … 383 409 if (idx == 0x1003) then 384 410 if (subidx >=0 and subidx<=9) then 385 sdoval = errlist[subidx ]411 sdoval = errlist[subidx-1] 386 412 endif 387 413 elseif (idx == 0x1004) then … … 422 448 elseif (subidx == 2) then 423 449 sdoval = GET POSLIMIT | (GET SWPOSLIMACT) << 31 450 elseif (subidx == 3) then 451 sdoval = (GET SWNEGLIMACT) | ((GET SWPOSLIMACT)<<1) 424 452 endif 425 453 elseif (idx == 0x2001) then … … 514 542 SUBPROG PROC_ERROR 515 543 MOTOR STOP 516 errinf = 0517 544 518 545 /* Tell the bus that an error occured */ 519 546 CANOUT pdo2 0 0 520 547 521 i = errlist[ 0] + 1522 while (i> 1) do548 i = errlist[1] + 1 /* Fill status of array */ 549 while (i>2) do /* shift errors by one */ 523 550 errlist[i] = errlist[i-1] 524 551 i = i - 1 525 endwhile 526 errlist[1] = ERRNO 527 if (errlist[0]<8) then 528 errlist[0] = errlist[0] + 1 529 endif 530 552 endwhile /* set new errornumber */ 553 errlist[2] = ERRNO 554 if (errlist[1]<8) then /* write new size if enhanced */ 555 errlist[1] = errlist[1] + 1 556 endif 557 558 errinf = 0 559 531 560 /* check if the error is repairable and repair */ 532 if (errlist[ 1]==6) then561 if (errlist[2]==6) then 533 562 PRINT "No home forced!" 534 563 ERRCLR 535 elseif (errlist[ 1]==8) then536 PRINT " Schleppabstand überschritten"564 elseif (errlist[2]==8) then 565 PRINT "Control deviation overflow." 537 566 ERRCLR 538 567 errinf = 0xaffe 539 elseif (errlist[ 1]==9) then568 elseif (errlist[2]==9) then 540 569 PRINT "Did'n find zero index." 541 570 ERRCLR 542 elseif (errlist[1]==25) then 543 lsw = -(GET I_POSLIMITSW) 544 if (IN lsw == 0) then 571 elseif (errlist[2]==11) then 572 poslsw = GET POSLIMIT 573 neglsw = GET NEGLIMIT 574 if ((GET SWNEGLIMACT) and APOS<=neglsw) then 575 PRINT "Negative software endswitch (", neglsw, ") activated at position ", APOS 576 SET SWNEGLIMACT 0 577 ERRCLR 578 CVEL (vres%100) 579 ACC (10*vres%100) 580 DEC (10*vres%100) 581 POSA neglsw + 100 582 SET SWNEGLIMACT 1 583 errinf = -1 584 elseif ((GET SWPOSLIMACT) and APOS>=poslsw) then 585 PRINT "Positive software endswitch (", poslsw, ") activated at position ", APOS 586 SET SWPOSLIMACT 0 587 ERRCLR 588 CVEL (vres%100) /* 1% */ 589 ACC (10*vres%100) /* 10% */ 590 DEC (10*vres%100) /* 10% */ 591 POSA poslsw - 100 592 SET SWPOSLIMACT 1 593 errinf = 1 594 else 595 PRINT "Software endswitch activated - command skipped. Pos: ", APOS 596 ERRCLR 597 endif 598 elseif (errlist[2]==25) then 599 /* FIXME: To handle this correct you must make sure, 600 that the endswitch numbers are negative */ 601 poslsw = -(GET I_POSLIMITSW) 602 neglsw = -(GET I_NEGLIMITSW) 603 if (IN poslsw == 0) then 545 604 PRINT "Positive endswitch activated at position ", APOS 546 605 SET I_POSLIMITSW 0 547 606 ERRCLR 548 CVEL (vres%100) /*1% */549 ACC (10*vres%100) 550 DEC (10*vres%100) 607 CVEL (vres%100) /* 1% */ 608 ACC (10*vres%100) /* 10% */ 609 DEC (10*vres%100) /* 10% */ 551 610 CSTART 552 WHILE (IN lsw == 0) DO ENDWHILE611 WHILE (IN poslsw == 0) DO ENDWHILE 553 612 CSTOP 554 SET I_POSLIMITSW - lsw613 SET I_POSLIMITSW -poslsw 555 614 errinf = 1 556 endif 557 lsw = -(GET I_NEGLIMITSW) 558 if (IN lsw == 0) then 615 elseif (IN neglsw == 0) then 559 616 PRINT "Negative endswitch activated at position ", APOS 560 617 SET I_NEGLIMITSW 0 … … 564 621 ACC (10*vres%100) /* 10% */ 565 622 DEC (10*vres%100) /* 10% */ 566 OUT 1 1567 MOTOR ON568 623 CSTART 569 WHILE (IN lsw == 0) DO ENDWHILE624 WHILE (IN poslsw == 0) DO ENDWHILE 570 625 CSTOP 571 SET I_NEGLIMITSW - lsw626 SET I_NEGLIMITSW -poslsw 572 627 errinf = -1 573 628 endif 574 elseif (errlist[ 1]==84) then629 elseif (errlist[2]==84) then 575 630 PRINT "Too many (>12) ON TIME interrupts." 576 631 ERRCLR 577 632 ELSE 578 PRINT "Error Function Called: ERRNO=", errlist[ 1]633 PRINT "Error Function Called: ERRNO=", errlist[2] 579 634 endif 580 635 581 636 /* tell the bus what exactly happened */ 582 CANOUT pdo2 errlist[ 1] errinf637 CANOUT pdo2 errlist[2] errinf 583 638 RETURN 584 639 -
trunk/MagicSoft/Cosy/base/timer.h
r738 r808 34 34 double GetMjd(); 35 35 36 int H() const { return fHor; } 37 int M() const { return fMin; } 38 int S() const { return fSec; } 39 36 40 const char *GetTimeStr(); 37 41 -
trunk/MagicSoft/Cosy/candrv/network.cc
r732 r808 166 166 } 167 167 168 bool Network::HasError() 169 { 170 for (int i=0; i<32; i++) 171 if (fNodes[i] && fNodes[i]->HasError()) 172 return true; 173 174 return false; 175 } -
trunk/MagicSoft/Cosy/candrv/network.h
r732 r808 30 30 virtual void Start(); 31 31 virtual void Stop(); 32 33 bool HasError(); 32 34 }; 33 35 -
trunk/MagicSoft/Cosy/candrv/nodedrv.cc
r732 r808 6 6 #include "network.h" 7 7 8 NodeDrv::NodeDrv(BYTE_t nodeid, ostream &out) : Log(out), fNetwork(NULL), fId(32) 8 NodeDrv::NodeDrv(BYTE_t nodeid, ostream &out) : Log(out), fNetwork(NULL), fId(32), fError(0) 9 9 { 10 10 if (nodeid>31) -
trunk/MagicSoft/Cosy/candrv/nodedrv.h
r732 r808 13 13 BYTE_t fId; 14 14 15 int fError; 16 17 protected: 18 void SetError(int err) { fError = err; } 19 void DelError() { fError = 0; } 20 int GetError() { return fError; } 21 15 22 public: 16 23 NodeDrv(BYTE_t nodeid, ostream &out=cout); … … 21 28 virtual void InitDevice(Network *net); 22 29 virtual void StopDevice() = 0; 30 31 bool HasError() { return fError; } 23 32 24 33 virtual void HandleSDO(WORD_t idx, BYTE_t subidx, LWORD_t val, struct timeval *tv); -
trunk/MagicSoft/Cosy/catalog/StarCatalog.cc
r748 r808 16 16 17 17 // 18 // calculate observers location (goe)19 //20 int status;21 slaDaf2r(51, 38, 48.0, &fPhi, &status);22 slaDaf2r( 9, 56, 36.0, &fElong, &status);23 24 cout << "fPhi: 51ø38'48.0\" = " << 360.0/D2PI*fPhi << endl;25 cout << "fElong: 9ø56'36.0\" = " << 360.0/D2PI*fElong << endl;26 27 //28 18 // read index file 29 19 // … … 78 68 cout << " Az: " << fAltAz.Az() << endl; 79 69 80 fRaDec = AltAz2RaDec(fAltAz);70 fRaDec = sla.CalcRaDec(fAltAz); 81 71 82 72 cout << "Ra: " << 360.0/D2PI*fRaDec.Ra(); … … 87 77 } 88 78 89 RaDec StarCatalog::AltAz2RaDec(const AltAz &altaz) const 90 { 91 // 92 // -- observed to apparent -- 93 // Workaraound for slalib: discard const 94 // 95 double r=0, d=0; 96 slaOapqk ("A", altaz.Az(), DPI/2-altaz.Alt(), (double*)fAoprms, &r, &d); 97 98 // 99 // -- apparent to mean -- 100 // Workaraound for slalib: discard const 101 // 102 double ra, dec; 103 slaAmpqk(r, d, (double*)fAmprms, &ra, &dec); 104 105 return RaDec(ra, dec); 106 } 107 108 AltAz StarCatalog::RaDec2AltAz(const RaDec &radec, const RaDec &rdpm) const 109 { 110 // 111 // ---- Mean to apparent ---- 112 // 113 114 double r=0, d=0; 115 slaMapqkz(radec.Ra(), radec.Dec(), (double*)fAmprms, &r, &d); 116 // 117 // Doesn't work - don't know why 118 // 119 // slaMapqk (radec.Ra(), radec.Dec(), rdpm.Ra(), rdpm.Dec(), 120 // 0, 0, (double*)fAmprms, &r, &d); 121 // 122 123 // 124 // -- apparent to observed -- 125 // 126 double r1=0; // ra 127 double d1=0; // dec 128 double h0=0; // ha 129 130 double zd; 131 double az; 132 slaAopqk (r, d, (double*)fAoprms, 133 &az, // observed azimuth (radians: N=0,E=90) 134 &zd, // observed zenith distance (radians) [-pi/2, pi/2] 135 &h0, // observed hour angle (radians) 136 &d1, // observed declination (radians) 137 &r1); // observed right ascension (radians) 138 139 return AltAz(DPI/2-zd, az); 140 } 141 142 void StarCatalog::SetRaDec(const RaDec &radec, const RaDec &rdpm) 79 void StarCatalog::SetRaDec(const RaDec &radec) 143 80 { 144 81 fRaDec = radec; 145 82 fRaDec *= D2PI/360.0; 146 83 147 RaDec pm = rdpm * D2PI/360.0; 148 149 fAltAz = RaDec2AltAz(fRaDec, pm); 84 fAltAz = sla.CalcAltAz(fRaDec); 150 85 151 86 cout << "Alt: " << 360.0/D2PI*fAltAz.Alt() << " "; … … 158 93 void StarCatalog::CalcAltAzRange() 159 94 { 160 charfAlt0[180];95 byte fAlt0[180]; 161 96 162 97 for (int h=0; h<180; h++) … … 248 183 // check whether altaz north- or south-pole is in the visible region 249 184 // 250 charimg[768*576];185 byte img[768*576]; 251 186 if (DrawAltAz(0, img, 90, 0)) 252 187 { … … 263 198 cout << "fAltMax: " << setw(3) << fAltMax << endl; 264 199 } 200 265 201 void StarCatalog::CalcRaDecRange() 266 202 { … … 268 204 // calculate range to search in 269 205 // 270 charfDec[180];206 byte fDec[180]; 271 207 272 208 for (int h=0; h<180; h++) … … 279 215 double de0, de1; 280 216 217 const double phi = sla.GetPhi(); 218 const double alpha = sla.GetAlpha(); 281 219 // 282 220 // scan horizontal border … … 286 224 double dx, dy; 287 225 slaDh2e(DPI-x*fPixSize, -fHeight, DPI/2-fAltAz.Alt(), &dx, &dy); 288 slaDh2e(fAltAz.Az()+dx, -dy, fPhi, &ha0, &de0);226 slaDh2e(fAltAz.Az()+dx, -dy, phi, &ha0, &de0); 289 227 290 228 slaDh2e(DPI-x*fPixSize, +fHeight, DPI/2-fAltAz.Alt(), &dx, &dy); 291 slaDh2e(fAltAz.Az()+dx, -dy, fPhi, &ha1, &de1);292 293 const int h0 = ((int)(360.0/D2PI*( fAlpha-ha0))+360)%360;229 slaDh2e(fAltAz.Az()+dx, -dy, phi, &ha1, &de1); 230 231 const int h0 = ((int)(360.0/D2PI*(alpha-ha0))+360)%360; 294 232 const int d0 = (int)(360.0/D2PI*de0); 295 233 … … 299 237 fDec[d0+90] = kTRUE; 300 238 301 const int h1 = ((int)(360.0/D2PI*( fAlpha-ha1))+360)%360;239 const int h1 = ((int)(360.0/D2PI*(alpha-ha1))+360)%360; 302 240 const int d1 = (int)(360.0/D2PI*de1); 303 241 … … 315 253 double dx, dy; 316 254 slaDh2e(DPI-fWidth, -y*fPixSize, DPI/2-fAltAz.Alt(), &dx, &dy); 317 slaDh2e(fAltAz.Az()+dx, -dy, fPhi, &ha0, &de0);255 slaDh2e(fAltAz.Az()+dx, -dy, phi, &ha0, &de0); 318 256 319 257 slaDh2e(DPI+fWidth, -y*fPixSize, DPI/2-fAltAz.Alt(), &dx, &dy); 320 slaDh2e(fAltAz.Az()+dx, -dy, fPhi, &ha1, &de1);321 322 const int h0 = ((int)(360.0/D2PI*( fAlpha-ha0))+360)%360;258 slaDh2e(fAltAz.Az()+dx, -dy, phi, &ha1, &de1); 259 260 const int h0 = ((int)(360.0/D2PI*(alpha-ha0))+360)%360; 323 261 const int d0 = (int)(360.0/D2PI*de0); 324 262 … … 328 266 fDec[d0+90] = kTRUE; 329 267 330 const int h1 = ((int)(360.0/D2PI*( fAlpha-ha1))+360)%360;268 const int h1 = ((int)(360.0/D2PI*(alpha-ha1))+360)%360; 331 269 const int d1 = (int)(360.0/D2PI*de1); 332 270 … … 364 302 // check whether radec north- or south-pole is in the visible region 365 303 // 366 charimg[768*576];304 byte img[768*576]; 367 305 if (DrawRaDec(0, img, 0, 90)) 368 306 { … … 380 318 } 381 319 382 void StarCatalog::DrawSCAltAz( char*img, const int color)320 void StarCatalog::DrawSCAltAz(byte *img, const int color) 383 321 { 384 322 // … … 414 352 } 415 353 416 void StarCatalog::DrawSCRaDec( char*img, const int color)354 void StarCatalog::DrawSCRaDec(byte *img, const int color) 417 355 { 418 356 // … … 446 384 } 447 385 } 448 449 // DrawRaDec(color, img, 37.953, 89.2641, 10); 450 } 451 452 453 void StarCatalog::SetMjd(const double mjd) 454 { 455 fMjd = mjd; 456 fAlpha = slaGmst(mjd) + fElong; 457 458 cout << "UTC: " << mjd << endl; 459 460 // 461 // ----- calculate star independent parameters ---------- 462 // 463 slaMappa(2000.0, fMjd, fAmprms); 464 slaAoppa(fMjd, 0, // mjd, UT1-UTC 465 fElong, fPhi, 148, // gttingen long, lat, height 466 0, 0, // polar motion x, y-coordinate (radians) 467 273.155, 1013.25, 0.5, // temp, pressure, humidity 468 0.2, 0.0065, // wavelength, tropo lapse rate 469 fAoprms); 470 471 } 472 473 void StarCatalog::DrawCross(char *img, const int x, const int y) 386 } 387 388 void StarCatalog::DrawCross(byte *img, const int x, const int y) 474 389 { 475 390 for (int dx=-4; dx<5; dx++) … … 480 395 } 481 396 482 void StarCatalog::GetImg( char *img, char*cimg, const double utc,397 void StarCatalog::GetImg(byte *img, byte *cimg, const double utc, 483 398 const RaDec &radec) 484 399 { … … 486 401 memset(cimg, 0, 768*576); 487 402 488 SetMjd(utc);489 490 SetRaDec(radec , RaDec());403 sla.Set(utc); 404 //fAlpha = sla.GetAlpha(); 405 SetRaDec(radec); 491 406 492 407 DrawSCAltAz(cimg, 2<<4); … … 498 413 } 499 414 500 void StarCatalog::GetImg( char *img, char*cimg, const double utc,415 void StarCatalog::GetImg(byte *img, byte *cimg, const double utc, 501 416 const AltAz &altaz) 502 417 { … … 504 419 memset(cimg, 0, 768*576); 505 420 506 SetMjd(utc);507 421 sla.Set(utc); 422 //fAlpha = sla.GetAlpha(); 508 423 SetAltAz(altaz); 509 424 … … 516 431 } 517 432 518 void StarCatalog::DrawCircle(int color, char*img, int xx, int yy, int size)433 void StarCatalog::DrawCircle(int color, byte *img, int xx, int yy, int size) 519 434 { 520 435 for (int x=xx-size; x<xx+size+1; x++) … … 537 452 } 538 453 539 Bool_t StarCatalog::DrawAltAz(const int color, char*img, double alt, double az, int size)454 Bool_t StarCatalog::DrawAltAz(const int color, byte *img, double alt, double az, int size) 540 455 { 541 456 // … … 571 486 } 572 487 573 Bool_t StarCatalog::Draw(const int color, char*img, const AltAz &altaz)488 Bool_t StarCatalog::Draw(const int color, byte *img, const AltAz &altaz) 574 489 { 575 490 return DrawAltAz(color, img, altaz.Alt(), altaz.Az()); 576 491 } 577 492 578 Bool_t StarCatalog::Draw(const int color, char*img, const SaoFile *sao)493 Bool_t StarCatalog::Draw(const int color, byte *img, const SaoFile *sao) 579 494 { 580 495 // 581 496 // ---- mean to observed --- 582 497 // 583 AltAz altaz= RaDec2AltAz(sao->GetRaDec(), sao->GetRaDecPm()) * 360.0/D2PI;498 AltAz altaz=sla.CalcAltAz(sao->GetRaDec()) * 360.0/D2PI; 584 499 585 500 if (sao->MagV() > fLimitMag) … … 594 509 } 595 510 596 Bool_t StarCatalog::DrawRaDec(const int color, char*img, double ra, double dec, int size)511 Bool_t StarCatalog::DrawRaDec(const int color, byte *img, double ra, double dec, int size) 597 512 { 598 513 // … … 605 520 // radec[rad] -> hadec[rad] 606 521 // 607 const double ha = fAlpha-ra;522 const double ha = sla.GetAlpha()-ra; 608 523 609 524 // … … 611 526 // 612 527 double alt, az; 613 slaDe2h(ha, dec, fPhi, &az, &alt);528 slaDe2h(ha, dec, sla.GetPhi(), &az, &alt); 614 529 615 530 // … … 622 537 } 623 538 624 Bool_t StarCatalog::Draw(const int color, char*img, const RaDec &radec)539 Bool_t StarCatalog::Draw(const int color, byte *img, const RaDec &radec) 625 540 { 626 541 return DrawRaDec(color, img, radec.Ra(), radec.Dec()); 627 542 } 628 543 629 void StarCatalog::CalcImg( char*img)544 void StarCatalog::CalcImg(byte *img) 630 545 { 631 546 -
trunk/MagicSoft/Cosy/catalog/StarCatalog.h
r740 r808 8 8 #include "SaoFile.h" 9 9 #endif 10 #ifndef SLALIB_H 11 #include "Slalib.h" 12 #endif 10 13 11 14 #include "coord.h" 15 16 typedef unsigned char byte; 12 17 13 18 class StarCatalog … … 18 23 int fEntries; 19 24 20 double fPhi; // location of observatory 21 double fElong; 25 Slalib sla; 26 27 // double fPhi; // location of observatory 28 // double fElong; 22 29 23 30 double fPixSize; // [rad/pix] size of one pixel … … 28 35 29 36 AltAz fAltAz; // [rad] 30 charfAz0[360];37 byte fAz0[360]; 31 38 int fAltMin; 32 39 int fAltMax; … … 34 41 35 42 RaDec fRaDec; // [rad] 36 charfRa0[360];43 byte fRa0[360]; 37 44 int fRaCnt; 38 45 int fDecMin; 39 46 int fDecMax; 40 47 41 double fAlpha;42 double fMjd;43 double fAmprms[21];44 double fAoprms[14];48 // double fAlpha; 49 // double fMjd; 50 // double fAmprms[21]; 51 // double fAoprms[14]; 45 52 46 void DrawCross( char*img, const int x, const int y);47 void DrawCircle(int color, char*img, int xx, int yy, int size);53 void DrawCross(byte *img, const int x, const int y); 54 void DrawCircle(int color, byte *img, int xx, int yy, int size); 48 55 49 Bool_t DrawAltAz(const int color, char *img, double alt, double az,int size=0);50 Bool_t DrawRaDec(const int color, char*img, double ra, double dec, int size=0);56 Bool_t DrawAltAz(const int color, byte *img, double alt, double az, int size=0); 57 Bool_t DrawRaDec(const int color, byte *img, double ra, double dec, int size=0); 51 58 52 Bool_t Draw(const int color, char*img, const AltAz &altaz);53 Bool_t Draw(const int color, char*img, const RaDec &radec);54 Bool_t Draw(const int color, char*img, const SaoFile *sao);59 Bool_t Draw(const int color, byte *img, const AltAz &altaz); 60 Bool_t Draw(const int color, byte *img, const RaDec &radec); 61 Bool_t Draw(const int color, byte *img, const SaoFile *sao); 55 62 56 void CalcImg( char*);63 void CalcImg(byte *); 57 64 65 void SetRaDec(const RaDec &radec); 58 66 void SetAltAz(const AltAz &altaz); 59 void SetMjd(const double mjd); 60 void DrawSCAltAz(char *img, const int color); 61 void DrawSCRaDec(char *img, const int color); 62 void SetRaDec(const RaDec &radec, const RaDec &rdpm); 63 67 // void SetMjd(const double mjd); 68 void DrawSCAltAz(byte *img, const int color); 69 void DrawSCRaDec(byte *img, const int color); 70 64 71 void CalcRaDecRange(); 65 72 void CalcAltAzRange(); 66 73 67 RaDec AltAz2RaDec(const AltAz &altaz) const;68 AltAz RaDec2AltAz(const RaDec &radec, const RaDec &rdpm) const;74 // RaDec AltAz2RaDec(const AltAz &altaz) const; 75 // AltAz RaDec2AltAz(const RaDec &radec, const RaDec &rdpm) const; 69 76 70 77 public: … … 72 79 virtual ~StarCatalog(); 73 80 74 void GetImg( char *img, char*cimg, const double utc,81 void GetImg(byte *img, byte *cimg, const double utc, 75 82 const RaDec &radec); 76 void GetImg( char *img, char*cimg, const double utc,83 void GetImg(byte *img, byte *cimg, const double utc, 77 84 const AltAz &altaz); 78 85 -
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 -
trunk/MagicSoft/Cosy/gui/MGCoordinate.cc
r732 r808 25 25 MGCoordinate::MGCoordinate(const TGWindow* p, 26 26 const Bool_t flag, const char *txt, 27 const UInt_t deg, const UInt_t min, const UInt_t sec)27 const Int_t deg, const UInt_t min, const UInt_t sec) 28 28 : TGFrame(p, 114, flag?76:46, kSunkenFrame|kFixedSize), fDeg(deg), fMin(min), fSec(sec) 29 29 { … … 131 131 Double_t MGCoordinate::GetVal() const 132 132 { 133 return (Double_t)(60*(60*fDeg+fMin)+fSec)/3600; 133 const Int_t deg = fDeg<0 ? -fDeg : fDeg; 134 const Int_t sgn = fDeg<0 ? -1 : 1; 135 136 return (Double_t)sgn*(60*(60*deg+fMin)+fSec)/3600; 134 137 } 135 138 … … 139 142 } 140 143 141 void MGCoordinate::Set(TGLabel *label, UInt_t val)144 void MGCoordinate::Set(TGLabel *label, Int_t val) 142 145 { 143 146 char txt[20]; … … 148 151 } 149 152 150 void MGCoordinate::Set(TGTextEntry *entry, UInt_t val)153 void MGCoordinate::Set(TGTextEntry *entry, Int_t val) 151 154 { 152 155 char txt[20]; … … 184 187 185 188 186 Bool_t MGCoordinate::Set(TGLabel *label, UInt_t &val, TGTextEntry *entry)187 { 188 UInt_t newval = atoi(entry->GetText());189 190 Bool_t ok = (entry == fTextEntryDeg || newval<60);189 Bool_t MGCoordinate::Set(TGLabel *label, Int_t &val, TGTextEntry *entry) 190 { 191 Int_t newval = atoi(entry->GetText()); 192 193 Bool_t ok = (entry == fTextEntryDeg || (newval>=0 && newval<60)); 191 194 192 195 if (ok) -
trunk/MagicSoft/Cosy/gui/MGCoordinate.h
r732 r808 20 20 class MGCoordinate : public TGFrame 21 21 { 22 UInt_t fDeg;23 UInt_t fMin;24 UInt_t fSec;22 Int_t fDeg; 23 Int_t fMin; 24 Int_t fSec; 25 25 26 26 MGList fList; … … 36 36 TGLabel *fLabel; 37 37 38 void Set(TGLabel *label, const UInt_t val);39 void Set(TGTextEntry *entry, const UInt_t val);40 Bool_t Set(TGLabel *label, UInt_t &val, TGTextEntry *label);38 void Set(TGLabel *label, const Int_t val); 39 void Set(TGTextEntry *entry, const Int_t val); 40 Bool_t Set(TGLabel *label, Int_t &val, TGTextEntry *label); 41 41 42 42 public: 43 43 MGCoordinate(const TGWindow* p, 44 44 const Bool_t flag=kTRUE, const char *txt="Coordinates:", 45 const UInt_t deg=0, const UInt_t min=0, const UInt_t sec=0);45 const Int_t deg=0, const UInt_t min=0, const UInt_t sec=0); 46 46 ~MGCoordinate(); 47 47 -
trunk/MagicSoft/Cosy/gui/MGCoordinates.cc
r732 r808 14 14 const Bool_t flag, 15 15 const char *txt1, const char *txt2, 16 const UInt_t deg1, const UInt_t min1, const UInt_t sec1,17 const UInt_t deg2, const UInt_t min2, const UInt_t sec2)16 const Int_t deg1, const UInt_t min1, const UInt_t sec1, 17 const Int_t deg2, const UInt_t min2, const UInt_t sec2) 18 18 : TGFrame(p, 234, 76, kFixedSize) 19 19 { -
trunk/MagicSoft/Cosy/gui/MGCoordinates.h
r732 r808 27 27 const char *txt1="Coordinate1:", 28 28 const char *txt2="Coordinate2:", 29 const UInt_t deg1=0, const UInt_t min1=0, const UInt_t sec1=0,30 const UInt_t deg2=0, const UInt_t min2=0, const UInt_t sec2=0);29 const Int_t deg1=0, const UInt_t min1=0, const UInt_t sec1=0, 30 const Int_t deg2=0, const UInt_t min2=0, const UInt_t sec2=0); 31 31 ~MGCoordinates(); 32 32 -
trunk/MagicSoft/Cosy/gui/MGCosy.cc
r740 r808 16 16 #include "MGList.h" 17 17 #include "MGCoordinates.h" 18 19 #include "Slalib.h" 18 20 19 21 #define IDM_EXIT 1 … … 242 244 t.GetTime(); 243 245 246 Slalib sla; 247 sla.Set(t.GetMjd()); 248 244 249 XY xy = fCoord->GetCoordinates(); 245 250 RaDec rd(xy.X(), xy.Y()); 246 251 247 252 cout << "Ra/Dec: " << rd.Ra() << kDEG << " " << rd.Dec() << kDEG << endl; 248 ZdAz aa= MCosy::RaDec2ZdAz(t.GetMjd(),rd*D2PI/360.0)*360.0/D2PI;253 ZdAz aa=sla.CalcZdAz(rd*D2PI/360.0)*360.0/D2PI; 249 254 cout << "Zd/Az: " << aa.Zd() << kDEG << " " << aa.Az() << kDEG << endl; 250 255 } -
trunk/MagicSoft/Cosy/gui/MGImage.cc
r732 r808 195 195 196 196 197 #include <TGClient.h>198 void MGImage::DrawImg(const char*buffer)197 //#include <TGClient.h> 198 void MGImage::DrawImg(const byte *buffer) 199 199 { 200 200 if (pthread_mutex_trylock((pthread_mutex_t*)fMuxPixmap)) … … 205 205 for (UInt_t x=0; x<fWidth; x++) 206 206 { 207 const unsigned charcol = buffer[y*fWidth+x];207 const byte col = buffer[y*fWidth+x]; 208 208 209 209 fBody[y][x*2] = fColors[col][0]; … … 306 306 } 307 307 308 void MGImage::DrawColImg(const char *gbuf, const char*cbuf)308 void MGImage::DrawColImg(const byte *gbuf, const byte *cbuf) 309 309 { 310 310 if (pthread_mutex_trylock((pthread_mutex_t*)fMuxPixmap)) … … 315 315 for (UInt_t x=0; x<fWidth; x++) 316 316 { 317 const unsigned charccol = cbuf[y*fWidth+x];317 const byte ccol = cbuf[y*fWidth+x]; 318 318 319 319 if (ccol) … … 324 324 else 325 325 { 326 const unsigned chargcol = gbuf[y*fWidth+x];326 const byte gcol = gbuf[y*fWidth+x]; 327 327 fBody[y][x*2] = fColors[gcol][0]; 328 328 fBody[y][x*2+1] = fColors[gcol][1]; -
trunk/MagicSoft/Cosy/gui/MGImage.h
r732 r808 9 9 10 10 #include <TGFrame.h> 11 12 typedef unsigned char byte; 11 13 12 14 class MGImage : public TGFrame … … 38 40 void MoveResize(Int_t x, Int_t y, UInt_t w, UInt_t h); 39 41 40 void DrawImg(const char*buffer);41 void DrawColImg(const char *gbuf, const char*cbuf);42 void DrawImg(const byte *buffer); 43 void DrawColImg(const byte *gbuf, const byte *cbuf); 42 44 }; 43 45 -
trunk/MagicSoft/Cosy/videodev/Camera.cc
r738 r808 188 188 189 189 void Camera::Execute(const unsigned long n, 190 char*img,190 byte *img, 191 191 struct timeval *tm) 192 192 { … … 247 247 if (!StartGrab(i&1)) 248 248 break; 249 Execute(i, fImg, &fTime);249 Execute(i, (byte*)fImg, &fTime); 250 250 i++; 251 251 } … … 254 254 { 255 255 LoopStep(i); 256 Execute(i, fImg, &fTime);256 Execute(i, (byte*)fImg, &fTime); 257 257 i++; 258 258 } 259 259 260 260 LoopStep(i); 261 Execute(i, fImg, &fTime);261 Execute(i, (byte*)fImg, &fTime); 262 262 i++; 263 263 -
trunk/MagicSoft/Cosy/videodev/Camera.h
r738 r808 4 4 #include <pthread.h> 5 5 #include <sys/time.h> 6 7 typedef unsigned char byte; 6 8 7 9 class Camera … … 85 87 // 86 88 virtual void Execute(const unsigned long n, 87 char*img, struct timeval *tm);89 byte *img, struct timeval *tm); 88 90 89 91 // -
trunk/MagicSoft/Cosy/videodev/Filter.cc
r738 r808 6 6 void Filter::DrawBox(const int x1, const int y1, 7 7 const int x2, const int y2, 8 char*buffer, const int col)8 byte *buffer, const int col) 9 9 { 10 10 for (int x=x1; x<x2+1; x++) … … 13 13 } 14 14 15 void Filter::MarkPoint(const int x, const int y, char*buffer, const int col)15 void Filter::MarkPoint(const int x, const int y, byte *buffer, const int col) 16 16 { 17 17 DrawBox(x-8, y, x-5, y, buffer, col); … … 22 22 } 23 23 24 float Filter::Mean(const char*buffer, const int offset, int *min, int *max)24 float Filter::Mean(const byte *buffer, const int offset, int *min, int *max) 25 25 { 26 26 double mean = 0.0; … … 35 35 for (int y=offset; y<576-offset; y++) 36 36 { 37 unsigned char val = (unsigned char)buffer[y*768+x];37 byte val = buffer[y*768+x]; 38 38 39 39 mean += val; 40 40 41 if ( *max<val)41 if (val>*max) 42 42 *max = val; 43 43 44 if ( *min>val)44 if (val<*min) 45 45 *min = val; 46 46 } … … 51 51 } 52 52 53 float Filter::SDev(const char*buffer, const int offset, const double mean)53 float Filter::SDev(const byte *buffer, const int offset, const double mean) 54 54 { 55 55 // … … 61 61 for (int y=offset; y<576-offset; y++) 62 62 { 63 const float val = mean - (unsigned char)buffer[y*768+x];63 const float val = mean - buffer[y*768+x]; 64 64 65 65 sdev += val*val; … … 71 71 } 72 72 73 int Filter::GetMeanPosition(const char*bitmap, const int x, const int y,73 int Filter::GetMeanPosition(const byte *bitmap, const int x, const int y, 74 74 const int box) 75 75 { … … 82 82 for (int dy=y-box; dy<y+box+1; dy++) 83 83 { 84 const unsigned char m = (unsigned char)bitmap[dy*768+dx]; // desc->buffer[3*(x+y*768)]; //84 const byte m = bitmap[dy*768+dx]; // desc->buffer[3*(x+y*768)]; // 85 85 86 86 sumx += m*dx; … … 95 95 } 96 96 97 void Filter::Execute( char*img)97 void Filter::Execute(byte *img) 98 98 { 99 99 const int offset = 10; … … 115 115 if (img[y*768+x]>cut) 116 116 continue; 117 118 // 119 // FIXME: Create LOOKUP Table! 120 // 117 121 118 122 img[y*768+x] = 0; … … 169 173 int points=0; 170 174 171 charmarker[768*576];175 byte marker[768*576]; 172 176 memset(marker, 0, 768*576); 173 177 -
trunk/MagicSoft/Cosy/videodev/Filter.h
r738 r808 1 1 #ifndef FILTER_H 2 2 #define FILTER_H 3 4 typedef unsigned char byte; 3 5 4 6 class Filter … … 6 8 static void DrawBox(const int x1, const int y1, 7 9 const int x2, const int y2, 8 char*buffer, const int col);10 byte *buffer, const int col); 9 11 10 12 static void MarkPoint(const int x, const int y, 11 char*buffer, const int col);13 byte *buffer, const int col); 12 14 13 static float Mean(const char*buffer, const int offset,15 static float Mean(const byte *buffer, const int offset, 14 16 int *min, int *max); 15 17 16 static float SDev(const char*buffer, const int offset,18 static float SDev(const byte *buffer, const int offset, 17 19 const double mean); 18 20 19 static int GetMeanPosition(const char*bitmap,21 static int GetMeanPosition(const byte *bitmap, 20 22 const int x, const int y, 21 23 const int box); 22 24 23 25 public: 24 static void Execute( char*img);26 static void Execute(byte *img); 25 27 }; 26 28 -
trunk/MagicSoft/Cosy/videodev/Writer.cc
r738 r808 9 9 #include "timer.h" 10 10 11 void Writer::Png(const char *fname, const char*buf,11 void Writer::Png(const char *fname, const byte *buf, 12 12 struct timeval *date) 13 13 { … … 106 106 } 107 107 108 void Writer::Ppm(const char *fname, const char*img)108 void Writer::Ppm(const char *fname, const byte *img) 109 109 { 110 110 cout << "Writing PPM '" << fname << "'" << endl; … … 121 121 // 122 122 fout << "P6\n768 576\n255\n"; 123 for ( charconst *buf = img; buf < img+768*576; buf++)123 for (byte const *buf = img; buf < img+768*576; buf++) 124 124 fout << *buf << *buf << *buf; 125 125 } -
trunk/MagicSoft/Cosy/videodev/Writer.h
r738 r808 3 3 4 4 #include <sys/time.h> 5 6 typedef unsigned char byte; 5 7 6 8 class Writer; … … 10 12 public: 11 13 12 static void Ppm(const char *fname, const char*img);13 static void Png(const char *fname, const char*buf, struct timeval *date);14 static void Ppm(const char *fname, const byte *img); 15 static void Png(const char *fname, const byte *buf, struct timeval *date); 14 16 }; 15 17
Note:
See TracChangeset
for help on using the changeset viewer.