source: trunk/MagicSoft/Cosy/main/MCosy.cc@ 4150

Last change on this file since 4150 was 4107, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 38.5 KB
Line 
1#include "MCosy.h"
2
3#include <iomanip.h>
4#include <fstream.h>
5#include <iostream.h>
6
7#include <TROOT.h>
8#include <TEnv.h>
9#include <TSystem.h>
10#include <TApplication.h>
11#include <TTimer.h>
12
13#include <TH2.h>
14#include <TH3.h>
15#include <TProfile.h>
16#include <TCanvas.h>
17
18#include "MGCosy.h"
19#include "MTime.h"
20#include "MDriveCom.h"
21#include "MStarguider.h"
22#include "SlaStars.h"
23#include "MPointing.h"
24#include "MTracking.h"
25
26#include "slalib/slalib.h" // FIXME: REMOVE
27
28#include "macs.h"
29#include "shaftencoder.h"
30
31ClassImp(MCosy);
32
33typedef struct tm tm_t;
34
35/* +===================================+
36 FIXME: What if fMac3 (Sync) died?
37 +===================================+
38*/
39
40//#define EXPERT
41#undef EXPERT
42
43/*
44ZdAz MCosy::CorrectTarget(const ZdAz &src, const ZdAz &dst)
45{
46 // CorrectTarget [se]
47
48 // src [se]
49 // dst [rad]
50
51 // fAltMax = 70
52 // fAltMin = -105/110
53 // fAzMin = -355
54 // fAzMax = 355
55
56 ZdAz source = src * 360.0/16384.0;
57 ZdAz dest = dst * kRad2Deg;
58
59 if (dest.Zd()>-3 && dest.Zd()<3)
60 dest.Zd(dest.Zd()<0?-3:3);
61
62 if (dest.Zd()>-1e-6 && dest.Zd()<1e-6)
63 return dst*(16384.0/k2Pi);
64
65 const float fZdMin = -67;
66 const float fZdMax = 67;
67 const float fAzMin = -29;
68 const float fAzMax = 423;
69
70 //
71 // This corrects to target for the shortest distance, not for the fastest move!
72 //
73 ZdAz s = source-dest;
74
75 float min = s.Sqr();
76
77 //
78 // Is it enought to search inside one revolution?
79 //
80 ZdAz ret = dest;
81
82 for (int i=-5; i<5+1; i++)
83 {
84 const ZdAz p(i%2 ? -dest.Zd() : dest.Zd(), dest.Az() - i*180);
85
86 //
87 // Range Check
88 //
89 if (p.Zd()<fZdMin || p.Zd()>fZdMax)
90 continue;
91
92 if (p.Az()<fAzMin || p.Az()>fAzMax)
93 continue;
94
95 //
96 // Calculate distance
97 //
98 s = source-p;
99
100 const float dist = s.Sqr();
101
102 if (dist > min)
103 continue;
104
105 //
106 // New shortest distance
107 //
108 ret = p;
109 min = dist;
110 }
111 return ret*(16384.0/360.0);
112}
113*/
114
115// --------------------------------------------------------------------------
116//
117// GetSePos, reads the Shaftencoder positions from the Can-drivers
118// for the shaftencoders. The two shaft encoders at the elevation axis
119// are avaraged. The values are returned as a ZdAz object.
120//
121// If one of the two shaftencoders on the elevation axis is missing
122// the other one's position is returned.
123//
124// The positions are alway up-to-date because the shaftencoders are
125// sending all changes immediatly.
126//
127ZdAz MCosy::GetSePos() const
128{
129 const int pa = fAz->GetPos();
130 if (fZd1->IsZombieNode() && fZd2->IsZombieNode())
131 return ZdAz(0, pa);
132
133 //
134 // Get the values
135 //
136 int p1 = (fZd1->GetPos()+8192)%16384;
137 int p2 = -(fZd2->GetPos()+8192)%16384;
138
139 if (fZd1->IsZombieNode())
140 return ZdAz(p2, pa);
141 if (fZd2->IsZombieNode())
142 return ZdAz(p1, pa);
143
144 //
145 // interpolate shaft encoder positions
146 //
147 float p = (float)(p1+p2)/2;
148
149 return ZdAz(p, pa);
150}
151
152// --------------------------------------------------------------------------
153//
154// reads the Rotary encoder positions from the last request of the Macs.
155//
156// The positions are returned as a ZdAz object. Use RequestRePos to request
157// the current positions first.
158//
159ZdAz MCosy::GetRePos()
160{
161 return ZdAz(fMac2->GetPos(), fMac1->GetPos());
162}
163
164// --------------------------------------------------------------------------
165//
166// reads the Rotary encoder positions from the Macs.
167//
168// The positions are returned as a ZdAz object. The positions are the ones
169// which are send as PDOs to the computer. This is done at a given
170// frequency. Which means, that this positions are not ought to be
171// up-to-date.
172//
173ZdAz MCosy::GetRePosPdo()
174{
175 return ZdAz(fMac2->GetPdoPos(), fMac1->GetPdoPos());
176}
177
178// --------------------------------------------------------------------------
179//
180// check for a break-signal (from the msgqueue) and errors.
181//
182int MCosy::StopWaitingForSDO() const
183{
184 return 0/*Break() || HasError()*/;
185}
186
187// --------------------------------------------------------------------------
188//
189// Waits for a movement to become finished.
190//
191// First waits for all peding Sdos, then waits until both motors are stopped
192// or waiting for SDOs was stopped (either by an error or by Break)
193//
194void MCosy::WaitForEndMovement()
195{
196 // FIXME, what when waiting times out (Zombie)
197 if (!fMac1 || !fMac2)
198 return;
199
200 while ((fMac1->IsPositioning() || fMac2->IsPositioning()) &&
201 !(Break() || HasError() || HasZombie()))
202 usleep(1);
203
204 if (!Break() && !HasError() && !HasZombie())
205 return;
206
207 MTime t(-1);
208 lout << t << " - MCosy::WaitForEndMovement aborted...";
209 if (Break())
210 lout << " Break signal...";
211 if (HasError())
212 lout << " Network has error...";
213 if (HasZombie())
214 lout << " Network has zombie...";
215 lout << endl;
216}
217
218// --------------------------------------------------------------------------
219//
220// Check for an error...
221//
222// This is ment for usage after the Action: All Motors Stop.
223//
224void MCosy::CheckForError()
225{
226 //
227 // Check all Can-Nodes for an Error. If there is no error the motor
228 // status is set to stopped.
229 //
230 if (HasError() || HasZombie())
231 {
232 SetStatus(MDriveCom::kError);
233 return;
234 }
235
236 if (fMac1->IsPositioning() || fMac2->IsPositioning())
237 SetStatus(MDriveCom::kMoving);
238 else
239 SetStatus(MDriveCom::kStopped);
240
241 //
242 // If there is an error, the error status is set to Error.
243 //
244
245 /*
246 FIXME: HANDLINGE ERROR
247
248 //
249 // Now try to handle the error.
250 //
251 fMac1->HandleError();
252 fMac2->HandleError();
253
254 //
255 // If the error couldn't get solved return
256 //
257 if (HasError())
258 return;
259
260 //
261 // Set motor status to stopped
262 //
263 SetStatus(MDriveCom::kStopped);
264 */
265}
266
267Bool_t MCosy::CheckRange(const ZdAz &d) const
268{
269 // d [rad]
270
271 if (d.Zd()<fMin.Zd())
272 {
273 lout << "ERROR: Requested Zenith Angle below negative endswitch." << endl;
274 return kFALSE;
275 }
276
277 if (d.Zd()>fMax.Zd())
278 {
279 lout << "ERROR: Requested Zenith Angle behind positive endswitch." << endl;
280 return kFALSE;
281 }
282
283 if (d.Az()<fMin.Az())
284 {
285 lout << "ERROR: Requested Azimuth Angle below negative endswitch." << endl;
286 return kFALSE;
287 }
288
289 if (d.Az()>fMax.Az())
290 {
291 lout << "ERROR: Requested Azimuth Angle behind positive endswitch." << endl;
292 return kFALSE;
293 }
294
295
296 return kTRUE;
297}
298
299ZdAz MCosy::AlignTrackingPos(ZdAz pointing) const
300{
301 // pointing [rad]
302 // AlignTrackingPos [deg]
303
304 pointing *= kRad2Deg;
305
306 if (pointing.Zd()<0)
307 {
308 pointing.Zd(-pointing.Zd());
309 pointing.Az(pointing.Az()+180);
310 //lout << "ZD=-ZD Az+=180" << endl;
311 }
312
313 const ZdAz se = GetSePos()*TMath::TwoPi()/kResSE; // [rad]
314 const ZdAz unbendedse = fBending.CorrectBack(se)*kRad2Deg; // ist pointing
315
316 //lout << "Unbended: " << unbendedse.Zd() << " " << unbendedse.Az() << endl;
317
318 do
319 {
320 const Double_t d = unbendedse.Az() - pointing.Az();
321 if (d>-180 && d<=180)
322 break;
323
324 //lout << "AZ += " << TMath::Sign(360., d) << endl;
325
326 pointing.Az(pointing.Az()+TMath::Sign(360., d));
327 } while (1);
328
329 return pointing/kRad2Deg;
330/*
331 const Bool_t rc = CheckRange(pointing);
332 za = pointing/kRad2Deg; // [rad]
333
334 if (!rc)
335 lout << "Error: Aligned position out of Range." << endl;
336
337 return rc;*/
338}
339
340Double_t MCosy::Starguider(Double_t mjd, ZdAz &dest) const
341{
342 ifstream fin("pointingpos.txt");
343 if (!fin)
344 return -1;
345
346 Double_t mjd0, zd, az;
347 fin >> mjd0 >> zd >> az;
348
349 mjd0 += 52000;
350
351 if (mjd0+1./24/60 <mjd)
352 return -1;
353
354 ZdAz point=AlignTrackingPos(ZdAz(zd, az)/kRad2Deg);
355 /*
356 if (!AlignTrackingPos(ZdAz(zd, az), point))
357 {
358 cout << "Starguider position couldn't be aligned..." << endl;
359 return -1;
360 }*/
361
362 // FIXME: Check Range missing!
363
364 const ZdAz diff = (dest-point)*kRad2Deg;
365
366 if (diff.Zd()>5 || diff.Az()>5)
367 {
368 cout << "Starguider deviation too large... dZd=" << diff.Zd() <<" dAz="<<diff.Az() << endl;
369 return -1;
370 }
371
372 dest -= point;
373 dest *= -kGearTot/TMath::TwoPi(); // [re]
374
375 cout << "Using Starguider... dZd=" << dest.Zd() << " dAz=" << dest.Az() << endl;
376
377 return (mjd-mjd0) * (24*60*60); // [s]
378}
379
380// --------------------------------------------------------------------------
381//
382// Move the telescope to the given position. The position must be given in
383// a ZdAz object in rad.
384//
385// The first positioning is done absolutely. If we didn't reach the
386// correct psotion we try to correct for this by 10 relative position
387// maneuvers. If this doesn't help positioning failed.
388//
389// As a reference the shaftencoder values are used.
390//
391int MCosy::SetPosition(const ZdAz &dst, Bool_t track) // [rad]
392{
393 MPointing point(this, lout);
394
395//#ifdef EXPERT
396// point.SetAccDec(0.4, 0.4);
397// point.SetVelocity(0.2); // fast: 0.6, slow: 0.2
398//#else
399 point.SetPointAccDec(0.2, 0.1);
400 point.SetPointVelocity(0.1);
401//#endif
402
403 return point.SetPosition(dst, track);
404}
405
406void MCosy::SetTrackingPosRE(ZdAz za)
407{
408 za /= kGearTot; // [U_tel]
409 za *= TMath::TwoPi(); // [rad]
410 //cout << "RE1: " << za.Zd()*180/3.1415 << " " << za.Az()*180/3.1415 << endl;
411 fTrackingPos = fBending.CorrectBack(za)*TMath::RadToDeg();
412 //cout << "RE2: " << fTrackingPos.Zd() << " " << fTrackingPos.Az() << endl;
413}
414
415void MCosy::TrackPosition(const RaDec &dst) // ra, dec [rad]
416{
417 MTracking track(this, lout);
418 track.SetOut(fOutRep);
419//#ifdef EXPERT
420// track.SetPointAccDec(0.4, 0.4);
421// track.SetPointVelocity(0.2); // fast: 0.6, slow: 0.2
422//#else
423 track.SetPointAccDec(0.2, 0.1);
424 track.SetPointVelocity(0.1);
425//#endif
426 track.SetTrackAccDec(0.1, 0.1);
427
428 track.TrackPosition(dst);
429}
430
431// --------------------------------------------------------------------------
432//
433// Stops the movement of both motors.
434//
435// Sets the status to stopping. Sets the deceleration to 50% of the maximum.
436// stops. Quits the revolution mode and wait for the end of the movement.
437//
438void MCosy::StopMovement()
439{
440 //
441 // Set status to Stopping
442 //
443 SetStatus(MDriveCom::kStopping);
444
445 //
446 // set deceleration to 50%
447 //
448 cout << "Stopping movement (dec=30%)..." << endl;
449 if (fMac1 && fMac2)
450 {
451#ifdef EXPERT
452 fMac1->SetDeceleration(0.5*fMac1->GetVelRes());
453 fMac2->SetDeceleration(0.5*fMac2->GetVelRes());
454#else
455 fMac1->SetDeceleration(0.3*fMac1->GetVelRes());
456 fMac2->SetDeceleration(0.3*fMac2->GetVelRes());
457#endif
458 fMac1->SetRpmMode(FALSE);
459 fMac2->SetRpmMode(FALSE);
460 }
461
462/*
463 fMac1->SetDeceleration(0.3*fMac1->GetVelRes());
464 fMac2->SetDeceleration(0.3*fMac2->GetVelRes());
465
466 fMac2->SendSDO(0x3000, Macs::string('s','t','o','p'));
467 fMac1->SendSDO(0x3000, Macs::string('s','t','o','p'));
468 fMac2->WaitForSdo(0x3000, 0);
469 fMac1->WaitForSdo(0x3000, 0);
470 fMac1->SetRpmMode(FALSE);
471 fMac2->SetRpmMode(FALSE);
472 */
473
474 //
475 // Wait for the movement to really be finished.
476 //
477#ifdef EXPERT
478 cout << "Waiting for end of movement..." << endl;
479#endif
480 WaitForEndMovement();
481
482 //
483 // Check whether everything works fine.
484 //
485 CheckForError();
486#ifdef EXPERT
487 cout << "Movement stopped." << endl;
488#endif
489}
490
491bool MCosy::CheckNetwork()
492{
493 //return kTRUE;
494 //CheckConnections();
495
496 CheckForError();
497
498 if (HasZombie())
499 {
500 lout << "- Found Zombies in Network..." << endl;
501 if (!RebootZombies())
502 return false;
503 }
504
505 /*
506 FIXME HANDLING ERROR
507 */
508 if (HasError())
509 {
510 fMac1->HandleError();
511 fMac2->HandleError();
512 fMac3->HandleError();
513 if (HasError() || HasZombie())
514 return false;
515 }
516
517 CheckForError();
518 return true;
519}
520
521void *MCosy::Proc(int msg, void *mp)
522{
523 switch (msg)
524 {
525 case WM_WAIT:
526 cout << "Wait for execution of Proc(WM_*, ): done." << endl;
527 return NULL;
528
529 case WM_STOP:
530 //cout << "MCosy::Proc: Stop." << endl;
531 if (!CheckNetwork())
532 return (void*)0xebb0;
533 StopMovement();
534 return NULL;
535/*
536 case WM_PRESET:
537 cout << "WM_Preset: start." << endl;
538 if (!CheckNetwork())
539 return (void*)0xebb0;
540 fZd1->SetPreset();
541 fZd2->SetPreset();
542 fAz->SetPreset();
543 cout << "WM_Preset: done. (return 0xaffe)" << endl;
544 return (void*)0xaffe;
545*/
546 /*
547 case WM_CALIB:
548 {
549 cout << "WM_Calib: start." << endl;
550 if (!CheckNetwork())
551 return (void*)0xebb0;
552
553 SlaStars sla(fObservatory);
554 sla.Now();
555
556 RaDec rd = *((RaDec*)mp);
557
558 //RaDec rd(37.94, 89.2644); // POLARIS
559 //RaDec rd(213.915417, 19.1825); // ARCTURUS
560
561 cout << "Calibrating to: " << rd.Ra()*24/360 << "h " << rd.Dec() << "°" << endl;
562
563 ZdAz za=sla.CalcZdAz(rd*kDeg2Rad)*16384.0/k2Pi;
564
565 cout << "Calc Zd: " << za.Zd() << " Az: " << za.Az() << endl;
566
567 ZdAz sepos = GetSePos();
568 cout << "Got Zd: " << sepos.Zd() << " Az: " << sepos.Az() << endl;
569
570 fZd1->SetPreset(za.Zd());
571 fZd2->SetPreset(-za.Zd());
572 fAz->SetPreset(za.Az());
573
574 cout << "WM_Calib: done. (return 0xaffe)" << endl;
575 }
576 return (void*)0xaffe;
577 */
578 case WM_TPOINT:
579 {
580 //cout << "WM_TPoint: start." << endl;
581 SlaStars sla(fObservatory);
582 sla.Now();
583
584 RaDec rd = *((RaDec*)mp);
585 cout << "TPoint Star: " << rd.Ra()/15 << "h " << rd.Dec() << "°" << endl;
586
587 AltAz za=sla.CalcAltAz(rd*kDeg2Rad)*kRad2Deg;
588
589 if (!fOutTp)
590 {
591 //
592 // open tpoint file
593 //
594 const TString name = GetFileName("tpoint/tpoint_%s.txt");
595 cout << "TPoint-Cosy File ********* " << name << " ********** " << endl;
596
597 fOutTp = new ofstream(name);
598 *fOutTp << "Magic Model TPOINT data file" << endl;
599 *fOutTp << ": ALTAZ" << endl;
600 *fOutTp << "49 48 0 ";
601 *fOutTp << sla.GetTime().Year() << " " << sla.GetTime().Month() << " " << sla.GetTime().Day() << " ";
602 *fOutTp << /*"20 1013.25 300 0.5 0.55 0.0065" <<*/ endl;
603 // temp(°C) pressure(mB) height(m) humidity(1) wavelength(microm) troplapserate(K/m)
604 }
605
606 cout << " Alt/Az: " << za.Alt() << "° " << za.Az() << "°" << endl;
607 *fOutTp << setprecision(7) << za.Az() << " " << za.Alt() << " ";
608
609 ZdAz sepos = GetSePos()*TMath::TwoPi()/kResSE;
610 za.Set(TMath::Pi()/2-sepos.Zd(), sepos.Az());
611 za *= kRad2Deg;
612
613 cout << " SE-Pos: " << za.Alt() << "° " << za.Az() << "°" << endl;
614 *fOutTp << fmod(za.Az()+360, 360) << " " << za.Alt() << " ";
615
616 if (fStarguider)
617 {
618 XY tp = fStarguider->GetCoordinates();
619 *fOutTp << 90-tp.X() << " " << tp.Y() << " ";
620 }
621
622 *fOutTp << rd.Ra()/15 << " " << rd.Dec() << " " << setprecision(11) << sla.GetMjd() << endl;
623
624 //cout << "WM_TPoint: done. (return 0xaffe)" << endl;
625 }
626 return (void*)0xca1b;
627
628 case WM_TRACKPOS:
629 //cout << "WM_TrackPosition: start." << endl;
630 {
631 if (!CheckNetwork())
632 return (void*)0xebb0;
633
634 ZdAz dest = *((ZdAz*)mp) * kDeg2Rad;
635 if (!SetPosition(dest))
636 return (void*)0x1234;
637
638 SlaStars sla(fObservatory);
639 sla.Now();
640
641 RaDec rd = sla.CalcRaDec(dest);
642 TrackPosition(rd);
643 }
644 //cout << "WM_TrackPosition: done. (return 0xabcd)" << endl;
645 return (void*)0xabcd;
646
647 case WM_POSITION:
648 //cout << "WM_Position: start." << endl;
649 {
650 if (!CheckNetwork())
651 return (void*)0xebb0;
652
653 ZdAz dest = *((ZdAz*)mp);
654 SetPosition(dest*kDeg2Rad);
655 }
656 //cout << "WM_Position: done. (return 0x7777)" << endl;
657 return (void*)0x7777;
658
659 case WM_POSITION1:
660 //cout << "WM_Position1: start." << endl;
661 {
662 if (!CheckNetwork())
663 return (void*)0xebb0;
664
665 ZdAz dest = *((ZdAz*)mp);
666 SetPosition(dest*kDeg2Rad, kTRUE);
667 }
668 //cout << "WM_Position: done. (return 0x7777)" << endl;
669 return (void*)0x7777;
670
671 case WM_TESTSE:
672 //cout << "WM_TestSe: start." << endl;
673 fBackground = mp ? kBgdSeTest : kBgdNone;
674 //cout << "WM_TestSe: done. (return 0x1e51)" << endl;
675 return (void*)0x1e51;
676
677 case WM_GEAR:
678 //cout << "WM_Gear: start." << endl;
679 fBackground = mp ? kBgdGear : kBgdNone;
680 //cout << "WM_Gear: done. (return 0xfeaf)" << endl;
681 return (void*)0xfeaf;
682
683 case WM_DISPLAY:
684 //cout << "WM_Display: start." << endl;
685 fTriggerDisplay = kTRUE;
686 //cout << "WM_Disply: done. (return 0xd1e1)" << endl;
687 return (void*)0xd1e1;
688
689 case WM_TRACK:
690 //cout << "WM_Track: START" << endl;
691 {
692 RaDec dest = ((RaDec*)mp)[0];
693 if (fStarguider)
694 fStarguider->SetPointingPosition(((RaDec*)mp)[1]);
695 if (!CheckNetwork())
696 return (void*)0xebb0;
697 TrackPosition(dest*kDeg2Rad);
698 }
699 //cout << "WM_Track: done. (return 0x8888)" << endl;
700 return (void*)0x8888;
701
702 case WM_NEWTRACK:
703 //cout << "WM_NewTrack: START" << endl;
704 fRaDec = *((RaDec*)mp);
705 //cout << "WM_NewTrack: done. (return 0x9999)" << endl;
706 return (void*)0x9999;
707
708 case WM_LOADBENDING:
709 //cout << "WM_LoadBending: START" << endl;
710 fBending.Load("bending.txt");
711 //cout << "WM_LoadBending: done. (return 0xbe0d)" << endl;
712 return (void*)0xbe0d;
713
714 case WM_RESETBENDING:
715 //cout << "WM_ResetBending: START" << endl;
716 fBending.Reset();
717 //cout << "WM_ResetBending: done. (return 0xbe0e)" << endl;
718 return (void*)0xbe0e;
719
720 case WM_HOME:
721 //cout << "WM_Home: START" << endl;
722 if (!CheckNetwork())
723 return (void*)0xebb0;
724 else
725 {
726 cout << "HOME NOT ALLOWED... for Magic." << endl;
727 /*
728 cout << "Going Home..." << endl;
729 TEnv env(".cosyrc");
730
731 SetStatus(MDriveCom::kMoving);
732
733 fMac1->SetHome(250000, env.GetValue("Az_MaxTime2ReachHome[s]", 100));
734 fMac2->SetHome(250000, env.GetValue("Zd_MaxTime2ReachHome[s]", 100));
735
736 lout << "SETHOME DONE" << endl;
737
738 SetStatus(HasError() ? MDriveCom::kError : MDriveCom::kStopped);
739
740 fAz->SetPreset();
741 fZd1->SetPreset();
742 fZd2->SetPreset();
743
744 fMac1->ReqPos();
745 fMac2->ReqPos();
746 fMac3->StopMotor();
747 */
748 }
749 //cout << "WM_Home: done. (return 0x403e)" << endl;
750 return (void*)0x403e;
751
752 case WM_CALCALTAZ:
753 {
754 cout << endl;
755
756 SlaStars sla(fObservatory);
757 sla.Now();
758
759 XY xy = *((XY*)mp);
760 RaDec rd(xy.X()*15., xy.Y()); // [deg]
761
762 ZdAz a1 = sla.CalcZdAz(rd*kDeg2Rad); // [rad]
763
764 cout << "Ra/Dec source: " << xy.X() << "h " << xy.Y() << "°" << endl;
765 cout << "Zd/Az target: " << a1.Zd()*kRad2Deg << "° " << a1.Az()*kRad2Deg << "°" << endl;
766
767 if (fZd1 && fZd2 && fAz)
768 a1 = AlignTrackingPos(a1);
769
770 a1 = fBending(a1);
771 CheckRange(a1);
772 a1 *= kRad2Deg;
773
774 const ZdAz a2 = a1*kResSE/360;
775
776 cout << "Zd/Az bended: " << a1.Zd() << "° " << a1.Az() << "°" << endl;
777 cout << "SE bended: " << a2.Zd() << " " << a2.Az() << endl;
778 }
779 return (void*)0xa17a;
780
781 case WM_ENDSWITCH:
782 {
783 ZdAz pos = GetSePos()*TMath::TwoPi()/kResSE;
784 pos = fBending.SubtractOffsets(pos)*kRad2Deg;
785
786 cout << "Endswitch Position: Zd=" << pos.Zd() << "° Az=";
787 cout << pos.Az() << "°" << endl;
788 }
789
790 return (void*)0x1010;
791
792 case WM_QUIT:
793 cout << "WM_Quit: now." << endl;
794 if (!CheckNetwork())
795 {
796 lout << "ERROR: Cannot shutdown CANbus network." << endl;
797 return (void*)0xebb0;
798 }
799 TerminateApp();
800 cout << "WM_Quit: done." << endl;
801 return (void*)0xaaaa;
802 }
803 cout << "MCosy::Proc: Unknown message 0x" << msg << endl;
804 return (void*)0xffffffff;
805}
806
807void *MTTalk::Thread()
808{
809 fCosy->TalkThread();
810 return NULL;
811}
812
813void MCosy::ReadConfig()
814{
815 cout << "Reading configuration file..." << flush;
816 TEnv env(".cosyrc");
817 cout << "done." << endl;
818
819 cout << "Reading telescope range..." << flush;
820 const Double_t amin = env.GetValue("Az_Min[deg]", -95.0);
821 const Double_t zmin = env.GetValue("Zd_Min[deg]", -75.0);
822 fMin.Set(zmin, amin);
823
824 const Double_t amax = env.GetValue("Az_Max[deg]", 305.0);
825 const Double_t zmax = env.GetValue("Zd_Max[deg]", 98.25);
826 fMax.Set(zmax, amax);
827 cout << "done." << endl;
828
829 cout << " * Min: " << zmin << "deg " << amin << "deg" << endl;
830 cout << " * Max: " << zmax << "deg " << amax << "deg" << endl;
831
832 fMin = fBending.AddOffsets(fMin/kRad2Deg);
833 fMax = fBending.AddOffsets(fMax/kRad2Deg);
834
835 cout << " * Min': " << fMin.Zd()*kRad2Deg << "deg " << fMin.Az()*kRad2Deg << "deg" << endl;
836 cout << " * Max': " << fMax.Zd()*kRad2Deg << "deg " << fMax.Az()*kRad2Deg << "deg" << endl;
837
838 cout << "Reading gear ratios..." << flush;
839 kGear.X(env.GetValue("Zd_GearRatio[U_mot/U_tel]", 1000.0));
840 kGear.Y(env.GetValue("Az_GearRatio[U_mot/U_tel]", 1000.0));
841
842 kResRE.Y(0);
843 if (fMac1 && !fMac1->IsZombieNode())
844 kResRE.Y(fMac1->GetRes());
845 else
846 if (fMac3 && !fMac3->IsZombieNode())
847 kResRE.Y(fMac3->GetRes());
848 else
849 kResRE.Y(env.GetValue("Az_ResRE[re/U_mot]", 1500));
850
851 kResRE.X(0);
852 if (fMac2 && !fMac2->IsZombieNode())
853 kResRE.X(fMac2->GetRes());
854 else
855 kResRE.X(env.GetValue("Zd_ResRE[re/U_mot]", 1500));
856
857 kResSE.X(0);
858 if (fZd1 && !fZd1->IsZombieNode())
859 kResSE.X(fZd1->GetPhysRes());
860 else
861 if (fZd2 && !fZd2->IsZombieNode())
862 kResSE.X(fZd2->GetPhysRes());
863 else
864 kResSE.X(env.GetValue("Zd_ResSE[se/U_mot]", 16384));
865
866 kResSE.Y(0);
867 if (fAz && !fAz->IsZombieNode())
868 kResSE.Y(fAz->GetPhysRes());
869 else
870 kResSE.Y(env.GetValue("Az_ResSE[se/U_mot]", 16384));
871
872 // believing the Macs manual '*4' shouldn't be necessary, but it is.
873 // Because the a RE is 4 quad counts.
874 // Calculating speeds we have to convert back to qc
875 kResRE *= 4;
876 kGearTot = kResRE*kGear;
877
878 cout << "done." << endl;
879
880 cout << " * Setting Gear Ratios:" << endl;
881 cout << " --------------------" << endl;
882 cout << " * X: " << kGear.X() << "*" << kResRE.X()/4 << "/" << kResSE.X() << "=4*" << kGearTot.X() << "/" << kResSE.X() << endl;
883 cout << " * Y: " << kGear.Y() << "*" << kResRE.Y()/4 << "/" << kResSE.Y() << "=4*" << kGearTot.Y() << "/" << kResSE.Y() << endl;
884}
885/*
886void MCosy::InitSync()
887{
888 if (!fMac3)
889 {
890 lout << "Unable to Init Sync! Mac3 not available." << endl;
891 return;
892 }
893
894 const int res = fMac3->GetVelRes();
895
896 fMac3->SetVelocity(0.3*res);
897 fMac3->SetAcceleration(0.2*res);
898 fMac3->SetDeceleration(0.2*res);
899 fMac3->StartPosSync();
900}
901*/
902void MCosy::TalkThreadSeTest()
903{
904// if (fZd1->IsZombieNode() || fZd2->IsZombieNode())
905 // return;
906
907 if (fHist)
908 {
909 lout << "You are much too fast... try again." << endl;
910 return;
911 }
912
913 fHist = new TH2F("Diff", "Difference of SE values",
914 201, fMin.Zd(), fMax.Zd(), 41, -10.5, 10.5);
915 fHist->SetXTitle("ZA [\\circ]");
916 fHist->SetYTitle("\\Delta SE");
917
918 Double_t offset = 0;
919
920 int cnt = 0;
921
922 lout << "Starting Shaftencoder Test..." << endl;
923
924 while (fBackground==kBgdSeTest)
925 {
926 fZd1->ResetPosHasChanged();
927 fZd2->ResetPosHasChanged();
928
929 while (!fZd1->PosHasChanged() && !fZd2->PosHasChanged() &&
930 fBackground==kBgdSeTest)
931 usleep(1);
932
933 const Double_t pos[3] = {
934 (fZd1->GetPos()+8192)%16384,
935 (fZd2->GetPos()+8192)%16384,
936 fAz->GetPos() };
937
938 //
939 // Estimate Offset from the first ten positions
940 //
941 if (cnt++<10)
942 {
943 offset += pos[0]+pos[1];
944 continue;
945 }
946 if (cnt==11)
947 {
948 offset /= 10;
949 cnt++;
950 }
951
952 Double_t apos = (pos[0]-pos[1])/2 * TMath::TwoPi() / kResSE.X();
953
954 ZdAz bend = fBending.CorrectBack(ZdAz(apos, pos[2]))*kRad2Deg;
955 fHist->Fill(bend.Zd(), pos[0]+pos[1]-offset);
956 }
957
958 lout << "Shaftencoder Test Stopped... displaying Histogram." << endl;
959
960 fBackground=kBgdSeTestDispl;
961}
962
963void MCosy::TalkThreadGear()
964{
965// if (fZd1->IsZombieNode() || fZd2->IsZombieNode())
966 // return;
967
968 if (fHist)
969 {
970 lout << "You are much too fast... try again." << endl;
971 return;
972 }
973
974 fHist = new TH3F("Gear", "Gear Ratio Re/Se",
975 (int)((fMax.Zd()-fMin.Zd())/2.5+1), fMin.Zd(), fMax.Zd(),
976 (int)((fMax.Az()-fMin.Az())/2.5+1), fMin.Az(), fMax.Az(),
977 61, 349.5, 500.5);
978
979 fHist->SetXTitle("Zd [\\circ]");
980 fHist->SetYTitle("Az [\\circ]");
981 fHist->SetZTitle("Re/Se");
982
983 lout << "Starting Gear determination..." << endl;
984
985 ZdAz se0 = GetSePos();
986 ZdAz re0 = GetRePosPdo();
987
988 while (fBackground==kBgdGear)
989 {
990 fZd1->ResetPosHasChanged();
991 fZd2->ResetPosHasChanged();
992 fAz->ResetPosHasChanged();
993
994 while (!fZd1->PosHasChanged() && !fZd2->PosHasChanged() &&
995 !fAz->PosHasChanged() && fBackground==kBgdGear)
996 usleep(1);
997
998 ZdAz se = GetSePos();
999 ZdAz re = GetRePosPdo();
1000
1001 ZdAz dse = se-se0;
1002 ZdAz dre = re-re0;
1003
1004 if (fabs(dse.Zd())*144>kResSE.X()) // Each 2.5deg (144)
1005 {
1006 se0.Zd(se.Zd());
1007 re0.Zd(re.Zd());
1008
1009 se -= dse/2;
1010
1011 ZdAz bend = fBending.CorrectBack(se*TMath::TwoPi()/kResSE)*kRad2Deg;
1012 ((TH3*)fHist)->Fill(bend.Zd(), bend.Az(), dre.Zd()/dse.Zd());
1013 }
1014
1015 if (fabs(dse.Az())*144>kResSE.Y()) // Each 2.5deg (144)
1016 {
1017 se0.Az(se.Az());
1018 re0.Az(re.Az());
1019
1020 se -= dse/2;
1021
1022 ZdAz bend = fBending.CorrectBack(se*TMath::TwoPi()/kResSE)*kRad2Deg;
1023 ((TH3*)fHist)->Fill(bend.Az(), bend.Az(), dre.Az()/dse.Az());
1024 }
1025 }
1026 lout << "Gear Test Stopped... displaying Histogram." << endl;
1027
1028 fBackground=kBgdGearDispl;
1029}
1030
1031void MCosy::TalkThread()
1032{
1033 /* ========== FIXME? =============
1034 if (fMac1->IsZombieNode() || fMac2->IsZombieNode())
1035 return;
1036 */
1037
1038 if (fMac1 && fMac2)
1039 {
1040 fMac1->ReqPos();
1041 fMac2->ReqPos();
1042 }
1043
1044 //InitSync();
1045
1046 /*** FOR DEMO MODE ***/
1047 if (!fZd1 || !fZd2 || !fAz)
1048 return;
1049 /*** FOR DEMO MODE ***/
1050
1051 //
1052 // Start the Network
1053 //
1054 while (1)
1055 {
1056 //
1057 // wait until a tracking session is started
1058 //
1059 while (fBackground==kBgdNone)
1060 usleep(1);
1061
1062 switch (fBackground)
1063 {
1064 case kBgdNone:
1065 continue;
1066/*#ifndef NEWALGO
1067 case kBgdTracking:
1068 TalkThreadTracking();
1069 continue;
1070#endif*/
1071 case kBgdSeTest:
1072 TalkThreadSeTest();
1073 continue;
1074
1075 case kBgdGear:
1076 TalkThreadGear();
1077 continue;
1078
1079 default:
1080 continue;
1081 }
1082 }
1083}
1084
1085ZdAz MCosy::GetPointingPos() const
1086{
1087 if (fZd1->IsZombieNode() || fZd2->IsZombieNode() || fAz->IsZombieNode())
1088 return ZdAz(0, 0);
1089
1090 // GetPointingPos [deg]
1091 const ZdAz seist = GetSePos()*TMath::TwoPi()/kResSE; // [rad]
1092 return fBending.CorrectBack(seist)*TMath::RadToDeg();
1093}
1094
1095Bool_t MCosy::HandleTimer(TTimer *t)
1096{
1097 const Int_t rc = fMutexGui.TryLock();
1098 if (rc==13)
1099 cout << "MCosy::HandleTimer - mutex is already locked by this thread" << endl;
1100
1101 if (rc)
1102 {
1103 lout << "* GUI update skipped due to locked mutex." << endl;
1104 return kTRUE;
1105 }
1106
1107 //
1108 // Update Gui, foremer MTGui.
1109 //
1110 if (fZd1)
1111 fZd1->DisplayVal();
1112 if (fZd2)
1113 fZd2->DisplayVal();
1114 if (fAz)
1115 fAz->DisplayVal();
1116
1117 Byte_t avail = 0;
1118
1119 avail |= (fMac1 && !fMac1->IsZombieNode()) ? 0x01 : 0;
1120 avail |= (fMac2 && !fMac2->IsZombieNode()) ? 0x02 : 0;
1121 avail |= (fMac3 && !fMac3->IsZombieNode()) ? 0x04 : 0;
1122 avail |= (fZd1 && !fZd1->IsZombieNode()) ? 0x08 : 0;
1123 avail |= (fZd2 && !fZd2->IsZombieNode()) ? 0x10 : 0;
1124 avail |= (fAz && !fAz->IsZombieNode()) ? 0x20 : 0;
1125
1126 if (HasError())
1127 SetStatus(MDriveCom::kError);
1128
1129
1130 ZdAz bendist = fStatus&MDriveCom::kTracking ? fTrackingPos : GetPointingPos();
1131
1132 //cout << (fStatus&MDriveCom::kTracking?"TRA: ":"POS: ") << bendist.Zd() << " " << bendist.Az() << endl;
1133
1134 fCom->SendReport(fStatus, fRaDec, fZdAzSoll, bendist, fTrackingError);
1135
1136 fWin->UpdateWeather(*fCom);
1137 fWin->Update(bendist, fTrackingError, fVelocity, /*fOffset,*/
1138 fRaDec, fZdAzSoll, fStatus, avail);
1139
1140 lout.UpdateGui();
1141
1142 const Bool_t trigger = fTriggerDisplay;
1143 fTriggerDisplay = kFALSE;
1144
1145 if (fBackground==kBgdSeTestDispl || (trigger&&fBackground==kBgdSeTest))
1146 DisplayHistTestSe(!trigger);
1147
1148 if (fBackground==kBgdGearDispl || (trigger&&fBackground==kBgdGear))
1149 DisplayHistGear(!trigger);
1150
1151 if (fMutexGui.UnLock()==13)
1152 cout << "MCosy::HandleTimer - tried to unlock mutex locked by other thread." << endl;
1153
1154 return kTRUE;
1155}
1156
1157void MCosy::DisplayHistTestSe(Bool_t del)
1158{
1159 lout << "Displaying histogram..." << endl;
1160
1161 TH2F &hist = *(TH2F*)fHist;
1162
1163 if (del)
1164 {
1165 fHist = NULL;
1166 fBackground = kBgdNone;
1167 }
1168
1169 TCanvas *c=new TCanvas("c1", "", 1000, 1000);
1170 c->Divide(1,2);
1171
1172 c->cd(1);
1173 TH2 *h=(TH2*)hist.DrawCopy();
1174
1175 TProfile *p = h->ProfileX("_pfx", -1, 9999, "s");
1176 p->SetLineColor(kBlue);
1177 p->Draw("same");
1178 p->SetBit(kCanDelete);
1179
1180 c->cd(2);
1181
1182 TH1F p2("spread", "Spread of the differences", hist.GetNbinsX(), hist.GetBinLowEdge(1),
1183 hist.GetBinLowEdge(hist.GetNbinsX()+1));
1184 p2.SetXTitle("Zd [\\circ]");
1185 for (int i=0; i<hist.GetNbinsX(); i++)
1186 p2.SetBinError(i, p->GetBinError(i));
1187 p2.SetLineColor(kRed);
1188 p2.SetStats(0);
1189 p2.DrawCopy();
1190
1191 if (del)
1192 delete &hist;
1193}
1194
1195void MCosy::DisplayHistGear(Bool_t del)
1196{
1197 lout << "Displaying histogram..." << endl;
1198
1199 TH3F &hist = *(TH3F*)fHist;
1200
1201 if (del)
1202 {
1203 fHist = NULL;
1204 fBackground = kBgdNone;
1205 }
1206
1207 TCanvas *c=new TCanvas("c1", "", 1000, 1000);
1208 c->Divide(2,2);
1209
1210 // ----------
1211
1212 c->cd(1);
1213 TH2D &h1=*(TH2D*)hist.Project3D("zx"); // Zd
1214 h1.SetTitle(" Gear Ratio Zenith Distance [re/se] ");
1215 h1.SetXTitle("Zd [\\circ]");
1216 h1.Draw();
1217 h1.SetBit(kCanDelete);
1218
1219 TProfile *p1 = h1.ProfileX("_pfx", -1, 9999, "s");
1220 p1->SetLineColor(kBlue);
1221 p1->Draw("same");
1222 p1->SetBit(kCanDelete);
1223
1224 // ----------
1225
1226 c->cd(2);
1227 TH2D &h2=*(TH2D*)hist.Project3D("zy"); // Az
1228 h2.SetTitle(" Gear Ratio Azimuth [re/se] ");
1229 h2.SetXTitle("Zd [\\circ]");
1230 h2.Draw();
1231 h2.SetBit(kCanDelete);
1232
1233 TProfile *p2 = h2.ProfileX("_pfx", -1, 9999, "s");
1234 p2->SetLineColor(kBlue);
1235 p2->Draw("same");
1236 p2->SetBit(kCanDelete);
1237
1238 // ----------
1239
1240 c->cd(3);
1241
1242 TAxis &axe1 = *h1.GetXaxis();
1243
1244 TH1F f1("spreadzd", " Spread Zenith Distance ",
1245 axe1.GetNbins(), axe1.GetXmin(), axe1.GetXmax());
1246 f1.SetXTitle("Zd [\\circ]");
1247 for (int i=0; i<axe1.GetNbins(); i++)
1248 f1.SetBinError(i, p1->GetBinError(i));
1249 f1.SetLineColor(kRed);
1250 f1.SetStats(0);
1251 f1.DrawCopy();
1252
1253 c->cd(4);
1254
1255 // ----------
1256
1257 TAxis &axe2 = *h2.GetXaxis();
1258
1259 TH1F f2("spreadaz", " Spread Azimuth ",
1260 axe2.GetNbins(), axe2.GetXmin(), axe2.GetXmax());
1261 f2.SetXTitle("Az [\\circ]");
1262 for (int i=0; i<axe2.GetNbins(); i++)
1263 f2.SetBinError(i, p2->GetBinError(i));
1264 f2.SetLineColor(kRed);
1265 f2.SetStats(0);
1266 f2.DrawCopy();
1267
1268 // ----------
1269
1270 if (del)
1271 delete &hist;
1272}
1273
1274// --------------------------------------------------------------------------
1275//
1276// Start the work of the application:
1277//
1278// Start the Can-Network.
1279// Start the MCosy::TalkThread thread.
1280// turn on the gui update
1281//
1282void MCosy::Start()
1283{
1284 // Don't call this function twice!
1285 Network::Start();
1286
1287 CheckForError();
1288
1289 ReadConfig();
1290
1291 lout << "- Starting TX Thread." << endl;
1292 fTTalk = new MTTalk(this);
1293
1294 lout << "- Starting GUI update." << endl;
1295 fUpdateGui->TurnOn();
1296}
1297
1298// --------------------------------------------------------------------------
1299//
1300// Start the work of the application:
1301//
1302// Turn of the gui update
1303// stop the MCosy::TalkThread thread.
1304// Stop the network
1305//
1306void MCosy::Stop()
1307{
1308 lout << "- Stopping GUI update." << endl;
1309 fUpdateGui->TurnOff();
1310 lout << "- GUI Update stopped." << endl;
1311
1312 delete fTTalk;
1313 lout << "- TX Thread stopped." << endl;
1314
1315 Network::Stop();
1316}
1317
1318// --------------------------------------------------------------------------
1319//
1320// Disable the synchronization by using a negative CAN Id for id2.
1321//
1322void MCosy::Constructor(Int_t id1, Int_t id2, Int_t id3,
1323 Int_t id4, Int_t id5, Int_t id6)
1324{
1325 //
1326 // Create Nodes
1327 //
1328 lout << "- Setting up network." << endl;
1329
1330 fMac1=new Macs(id1, "Mac/Az", lout);
1331 fMac2=new Macs(id3, "Mac/Zd", lout);
1332 if (id2>=0)
1333 fMac3=new Macs(id2, "Mac/Az-Sync", lout);
1334
1335 fZd1=new ShaftEncoder(id4, "SE/Zd1", lout);
1336 fZd2=new ShaftEncoder(id5, "SE/Zd2", lout);
1337 fAz =new ShaftEncoder(id6, "SE/Az", lout);
1338
1339 fZd1->SetReport(fOutRep);
1340 fZd2->SetReport(fOutRep);
1341 fAz->SetReport(fOutRep);
1342
1343 fAz->SetMotor(fMac1);
1344 fZd1->SetMotor(fMac2);
1345 fZd2->SetMotor(fMac2);
1346
1347 lout << "- Connecting devices to network." << endl;
1348
1349 //
1350 // Connect the devices to the network
1351 //
1352 SetNode(fMac1);
1353 SetNode(fMac2);
1354 if (id2>=0)
1355 SetNode(fMac3);
1356 SetNode(fZd1);
1357 SetNode(fZd2);
1358 SetNode(fAz);
1359
1360 //
1361 // Create Gui Event timer and Gui
1362 //
1363 lout << "- Initializing GUI Timer." << endl;
1364 fUpdateGui = new TTimer(this, 100); // 100ms
1365
1366 lout << "- Starting GUI." << endl;
1367 fWin=new MGCosy(fObservatory, this, gClient->GetRoot(), 1, 1);
1368}
1369/*
1370void MCosy::ConstructorSE(Int_t id4, Int_t id5, Int_t id6)
1371{
1372 //
1373 // Create Nodes
1374 //
1375 lout << "- Setting up network." << endl;
1376
1377 fZd1=new ShaftEncoder(id4, "SE/Zd1", lout);
1378 fZd2=new ShaftEncoder(id5, "SE/Zd2", lout);
1379 fAz =new ShaftEncoder(id6, "SE/Az", lout);
1380
1381 lout << "- Connecting devices to network." << endl;
1382
1383 //
1384 // Connect the devices to the network
1385 //
1386 SetNode(fZd1);
1387 SetNode(fZd2);
1388 SetNode(fAz);
1389
1390 //
1391 // Create Gui Event timer and Gui
1392 //
1393 lout << "- Initializing GUI Timer." << endl;
1394 fUpdateGui = new TTimer(this, 100); // 100ms
1395
1396 lout << "- Starting GUI." << endl;
1397 fWin=new MGCosy(fObservatory, this, gClient->GetRoot(), 1, 1);
1398}
1399
1400void MCosy::ConstructorDemo()
1401{
1402 //
1403 // Create Nodes
1404 //
1405 lout << "- Setting up network." << endl;
1406
1407 //
1408 // Create Gui Event timer and Gui
1409 //
1410 lout << "- Initializing GUI Timer." << endl;
1411 fUpdateGui = new TTimer(this, 100); // 100ms
1412
1413 lout << "- Starting GUI." << endl;
1414 fWin=new MGCosy(fObservatory, this, gClient->GetRoot(), 1, 1);
1415}
1416*/
1417
1418TString MCosy::GetFileName(const char *fmt)
1419{
1420 // FIXME: Timeout missing
1421 while (1)
1422 {
1423 MTime time(-1);
1424 const TString name = Form(fmt, (const char*)time.GetFileName());
1425 if (gSystem->AccessPathName(name, kFileExists))
1426 return name;
1427 break;
1428
1429 usleep(1000);
1430 }
1431 return "";
1432}
1433
1434MCosy::MCosy(/*int mode,*/ const char *dev, const int baud, MLog &out)
1435: Network(dev, baud, out), fObservatory(MObservatory::kMagic1), fStarguider(NULL), fZd1(0), fZd2(0), fAz(0), fMac1(0), fMac2(0), fMac3(0), fBackground(kBgdNone), fStatus(MDriveCom::kStopped), fOutTp(0), fOutRep(0)
1436{
1437 TEnv env(".cosyrc");
1438 const Int_t id1 = env.GetValue("Az_Id-MAC1", 1); //1
1439 const Int_t id2 = env.GetValue("Az_Id-MAC2", 2); //2
1440 const Int_t id3 = env.GetValue("Zd_Id-MAC", 3); //3
1441 const Int_t id4 = env.GetValue("Zd_Id-SE1", 4); //4
1442 const Int_t id5 = env.GetValue("Zd_Id-SE2", 5); //5
1443 const Int_t id6 = env.GetValue("Az_Id-SE", 6); //6
1444
1445 TString name = GetFileName("rep/cosy_%s.rep");
1446 cout << "Open Repfile: " << name << endl;
1447 fOutRep = new MLog(name, kTRUE);
1448
1449/*
1450 lout << "- Program in ";
1451 switch (mode)
1452 {
1453 case 0:
1454 lout << "<<Standard mode>>" << endl;*/
1455 fBending.Load("bending.txt");
1456 Constructor(id1, id2, id3, id4, id5, id6);/*
1457 break;
1458 case 1:
1459 lout << "<<SE mode>>" << endl;
1460 fBending.Load("bending.txt");
1461 ConstructorSE(id4, id5, id6);
1462 break;
1463 default:
1464 lout << "<<Demo mode>>" << endl;
1465 ConstructorDemo();
1466 }
1467*/
1468 lout.SetOutputGui(fWin->GetLog(), kTRUE);
1469
1470 fZd1->SetDisplay(fWin->GetLabel2());
1471 fZd2->SetDisplay(fWin->GetLabel3());
1472 fAz->SetDisplay(fWin->GetLabel1());
1473
1474 fCom = new MDriveCom(this, *fOutRep);
1475 fCom->Start();
1476}
1477
1478void MCosy::TerminateApp()
1479{
1480 cout << "MCosy::TerminateApp()" << endl;
1481/*
1482 Int_t rc;
1483 TGMessageBox msg(this, gClient->GetRoot(),
1484 "Information",
1485 "Cosy is shutting down the system - this may take wa while!",
1486 kMBIconExclamation,
1487 kMBOK, //kMBClose
1488 &rc, 0);
1489*/
1490
1491 lout.DisableOutputDevice(MLog::eGui);
1492 // FIXME: WHY DOES THIS CRASH THE APPLICATIOn WHILE TRAKING?
1493 // lout.SetOutputGui(NULL, kFALSE);
1494
1495 gApplication->Terminate(0);
1496}
1497
1498MCosy::~MCosy()
1499{
1500 if (fOutTp)
1501 {
1502 *fOutTp << "END" << endl;
1503 delete fOutTp;
1504 }
1505 delete fOutRep;
1506
1507 cout << "Deleting GUI timer." << endl;
1508
1509 delete fUpdateGui;
1510 delete fCom;
1511
1512 cout << "Deleting Nodes." << endl;
1513
1514 fZd1->SetReport(0);
1515 fZd2->SetReport(0);
1516 fAz->SetReport(0);
1517
1518 delete fAz;
1519 delete fZd1;
1520 delete fZd2;
1521 delete fMac1;
1522 delete fMac2;
1523 if (fMac3)
1524 delete fMac3;
1525
1526 cout << "Deleting MGCosy." << endl;
1527
1528 lout.DisableOutputDevice(MLog::eGui);
1529
1530 delete fWin;
1531
1532 cout << "MGCosy destructed." << endl;
1533}
Note: See TracBrowser for help on using the repository browser.