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

Last change on this file since 5059 was 4255, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 38.7 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 fTrackingPosRaw = za*TMath::RadToDeg();
412 fTrackingPos = fBending.CorrectBack(za)*TMath::RadToDeg();
413 //cout << "RE2: " << fTrackingPos.Zd() << " " << fTrackingPos.Az() << endl;
414}
415
416void MCosy::TrackPosition(const RaDec &dst) // ra, dec [rad]
417{
418 MTracking track(this, lout);
419 track.SetOut(fOutRep);
420//#ifdef EXPERT
421// track.SetPointAccDec(0.4, 0.4);
422// track.SetPointVelocity(0.2); // fast: 0.6, slow: 0.2
423//#else
424 track.SetPointAccDec(0.2, 0.1);
425 track.SetPointVelocity(0.1);
426//#endif
427 track.SetTrackAccDec(0.1, 0.1);
428
429 track.TrackPosition(dst);
430}
431
432// --------------------------------------------------------------------------
433//
434// Stops the movement of both motors.
435//
436// Sets the status to stopping. Sets the deceleration to 50% of the maximum.
437// stops. Quits the revolution mode and wait for the end of the movement.
438//
439void MCosy::StopMovement()
440{
441 //
442 // Set status to Stopping
443 //
444 SetStatus(MDriveCom::kStopping);
445
446 //
447 // set deceleration to 50%
448 //
449 cout << "Stopping movement (dec=30%)..." << endl;
450 if (fMac1 && fMac2)
451 {
452#ifdef EXPERT
453 fMac1->SetDeceleration(0.5*fMac1->GetVelRes());
454 fMac2->SetDeceleration(0.5*fMac2->GetVelRes());
455#else
456 fMac1->SetDeceleration(0.3*fMac1->GetVelRes());
457 fMac2->SetDeceleration(0.3*fMac2->GetVelRes());
458#endif
459 fMac1->SetRpmMode(FALSE);
460 fMac2->SetRpmMode(FALSE);
461 }
462
463/*
464 fMac1->SetDeceleration(0.3*fMac1->GetVelRes());
465 fMac2->SetDeceleration(0.3*fMac2->GetVelRes());
466
467 fMac2->SendSDO(0x3000, Macs::string('s','t','o','p'));
468 fMac1->SendSDO(0x3000, Macs::string('s','t','o','p'));
469 fMac2->WaitForSdo(0x3000, 0);
470 fMac1->WaitForSdo(0x3000, 0);
471 fMac1->SetRpmMode(FALSE);
472 fMac2->SetRpmMode(FALSE);
473 */
474
475 //
476 // Wait for the movement to really be finished.
477 //
478#ifdef EXPERT
479 cout << "Waiting for end of movement..." << endl;
480#endif
481 WaitForEndMovement();
482
483 //
484 // Check whether everything works fine.
485 //
486 CheckForError();
487#ifdef EXPERT
488 cout << "Movement stopped." << endl;
489#endif
490}
491
492bool MCosy::CheckNetwork()
493{
494 //return kTRUE;
495 //CheckConnections();
496
497 CheckForError();
498
499 if (HasZombie())
500 {
501 lout << "- Found Zombies in Network..." << endl;
502 if (!RebootZombies())
503 return false;
504 }
505
506 /*
507 FIXME HANDLING ERROR
508 */
509 if (HasError())
510 {
511 fMac1->HandleError();
512 fMac2->HandleError();
513 fMac3->HandleError();
514 if (HasError() || HasZombie())
515 return false;
516 }
517
518 CheckForError();
519 return true;
520}
521
522void *MCosy::Proc(int msg, void *mp)
523{
524 switch (msg)
525 {
526 case WM_WAIT:
527 cout << "Wait for execution of Proc(WM_*, ): done." << endl;
528 return NULL;
529
530 case WM_STOP:
531 //cout << "MCosy::Proc: Stop." << endl;
532 if (!CheckNetwork())
533 return (void*)0xebb0;
534 StopMovement();
535 return NULL;
536/*
537 case WM_PRESET:
538 cout << "WM_Preset: start." << endl;
539 if (!CheckNetwork())
540 return (void*)0xebb0;
541 fZd1->SetPreset();
542 fZd2->SetPreset();
543 fAz->SetPreset();
544 cout << "WM_Preset: done. (return 0xaffe)" << endl;
545 return (void*)0xaffe;
546*/
547 /*
548 case WM_CALIB:
549 {
550 cout << "WM_Calib: start." << endl;
551 if (!CheckNetwork())
552 return (void*)0xebb0;
553
554 SlaStars sla(fObservatory);
555 sla.Now();
556
557 RaDec rd = *((RaDec*)mp);
558
559 //RaDec rd(37.94, 89.2644); // POLARIS
560 //RaDec rd(213.915417, 19.1825); // ARCTURUS
561
562 cout << "Calibrating to: " << rd.Ra()*24/360 << "h " << rd.Dec() << "°" << endl;
563
564 ZdAz za=sla.CalcZdAz(rd*kDeg2Rad)*16384.0/k2Pi;
565
566 cout << "Calc Zd: " << za.Zd() << " Az: " << za.Az() << endl;
567
568 ZdAz sepos = GetSePos();
569 cout << "Got Zd: " << sepos.Zd() << " Az: " << sepos.Az() << endl;
570
571 fZd1->SetPreset(za.Zd());
572 fZd2->SetPreset(-za.Zd());
573 fAz->SetPreset(za.Az());
574
575 cout << "WM_Calib: done. (return 0xaffe)" << endl;
576 }
577 return (void*)0xaffe;
578 */
579 case WM_TPOINT:
580 {
581 //cout << "WM_TPoint: start." << endl;
582 SlaStars sla(fObservatory);
583 sla.Now();
584
585 RaDec rd = *((RaDec*)mp);
586 cout << "TPoint Star: " << rd.Ra()/15 << "h " << rd.Dec() << "°" << endl;
587
588 AltAz za=sla.CalcAltAz(rd*kDeg2Rad)*kRad2Deg;
589
590 if (!fOutTp)
591 {
592 //
593 // open tpoint file
594 //
595 const TString name = GetFileName("tpoint/tpoint_%s.txt");
596 cout << "TPoint-Cosy File ********* " << name << " ********** " << endl;
597
598 fOutTp = new ofstream(name);
599 *fOutTp << "Magic Model TPOINT data file" << endl;
600 *fOutTp << ": ALTAZ" << endl;
601 *fOutTp << "49 48 0 ";
602 *fOutTp << sla.GetTime().Year() << " " << sla.GetTime().Month() << " " << sla.GetTime().Day() << " ";
603 *fOutTp << /*"20 1013.25 300 0.5 0.55 0.0065" <<*/ endl;
604 // temp(°C) pressure(mB) height(m) humidity(1) wavelength(microm) troplapserate(K/m)
605 }
606
607 cout << " Alt/Az: " << za.Alt() << "° " << za.Az() << "°" << endl;
608 *fOutTp << setprecision(7) << za.Az() << " " << za.Alt() << " ";
609
610 ZdAz sepos = GetSePos()*TMath::TwoPi()/kResSE;
611 za.Set(TMath::Pi()/2-sepos.Zd(), sepos.Az());
612 za *= kRad2Deg;
613
614 cout << " SE-Pos: " << za.Alt() << "° " << za.Az() << "°" << endl;
615 *fOutTp << fmod(za.Az()+360, 360) << " " << za.Alt() << " ";
616
617 if (fStarguider)
618 {
619 XY tp = fStarguider->GetCoordinates();
620 *fOutTp << 90-tp.X() << " " << tp.Y() << " ";
621 }
622
623 *fOutTp << rd.Ra()/15 << " " << rd.Dec() << " " << setprecision(11) << sla.GetMjd() << endl;
624
625 //cout << "WM_TPoint: done. (return 0xaffe)" << endl;
626 }
627 return (void*)0xca1b;
628
629 case WM_TRACKPOS:
630 //cout << "WM_TrackPosition: start." << endl;
631 {
632 if (!CheckNetwork())
633 return (void*)0xebb0;
634
635 ZdAz dest = *((ZdAz*)mp) * kDeg2Rad;
636 if (!SetPosition(dest))
637 return (void*)0x1234;
638
639 SlaStars sla(fObservatory);
640 sla.Now();
641
642 RaDec rd = sla.CalcRaDec(dest);
643 TrackPosition(rd);
644 }
645 //cout << "WM_TrackPosition: done. (return 0xabcd)" << endl;
646 return (void*)0xabcd;
647
648 case WM_POSITION:
649 //cout << "WM_Position: start." << endl;
650 {
651 if (!CheckNetwork())
652 return (void*)0xebb0;
653
654 ZdAz dest = *((ZdAz*)mp);
655 SetPosition(dest*kDeg2Rad);
656 }
657 //cout << "WM_Position: done. (return 0x7777)" << endl;
658 return (void*)0x7777;
659
660 case WM_POSITION1:
661 //cout << "WM_Position1: start." << endl;
662 {
663 if (!CheckNetwork())
664 return (void*)0xebb0;
665
666 ZdAz dest = *((ZdAz*)mp);
667 SetPosition(dest*kDeg2Rad, kTRUE);
668 }
669 //cout << "WM_Position: done. (return 0x7777)" << endl;
670 return (void*)0x7777;
671
672 case WM_TESTSE:
673 //cout << "WM_TestSe: start." << endl;
674 fBackground = mp ? kBgdSeTest : kBgdNone;
675 //cout << "WM_TestSe: done. (return 0x1e51)" << endl;
676 return (void*)0x1e51;
677
678 case WM_GEAR:
679 //cout << "WM_Gear: start." << endl;
680 fBackground = mp ? kBgdGear : kBgdNone;
681 //cout << "WM_Gear: done. (return 0xfeaf)" << endl;
682 return (void*)0xfeaf;
683
684 case WM_DISPLAY:
685 //cout << "WM_Display: start." << endl;
686 fTriggerDisplay = kTRUE;
687 //cout << "WM_Disply: done. (return 0xd1e1)" << endl;
688 return (void*)0xd1e1;
689
690 case WM_TRACK:
691 //cout << "WM_Track: START" << endl;
692 {
693 RaDec dest = ((RaDec*)mp)[0];
694 if (fStarguider)
695 fStarguider->SetPointingPosition(((RaDec*)mp)[1]);
696 if (!CheckNetwork())
697 return (void*)0xebb0;
698 TrackPosition(dest*kDeg2Rad);
699 }
700 //cout << "WM_Track: done. (return 0x8888)" << endl;
701 return (void*)0x8888;
702
703 case WM_NEWTRACK:
704 //cout << "WM_NewTrack: START" << endl;
705 fRaDec = *((RaDec*)mp);
706 //cout << "WM_NewTrack: done. (return 0x9999)" << endl;
707 return (void*)0x9999;
708
709 case WM_LOADBENDING:
710 //cout << "WM_LoadBending: START" << endl;
711 fBending.Load("bending.txt");
712 //cout << "WM_LoadBending: done. (return 0xbe0d)" << endl;
713 return (void*)0xbe0d;
714
715 case WM_RESETBENDING:
716 //cout << "WM_ResetBending: START" << endl;
717 fBending.Reset();
718 //cout << "WM_ResetBending: done. (return 0xbe0e)" << endl;
719 return (void*)0xbe0e;
720
721 case WM_HOME:
722 //cout << "WM_Home: START" << endl;
723 if (!CheckNetwork())
724 return (void*)0xebb0;
725 else
726 {
727 cout << "HOME NOT ALLOWED... for Magic." << endl;
728 /*
729 cout << "Going Home..." << endl;
730 TEnv env(".cosyrc");
731
732 SetStatus(MDriveCom::kMoving);
733
734 fMac1->SetHome(250000, env.GetValue("Az_MaxTime2ReachHome[s]", 100));
735 fMac2->SetHome(250000, env.GetValue("Zd_MaxTime2ReachHome[s]", 100));
736
737 lout << "SETHOME DONE" << endl;
738
739 SetStatus(HasError() ? MDriveCom::kError : MDriveCom::kStopped);
740
741 fAz->SetPreset();
742 fZd1->SetPreset();
743 fZd2->SetPreset();
744
745 fMac1->ReqPos();
746 fMac2->ReqPos();
747 fMac3->StopMotor();
748 */
749 }
750 //cout << "WM_Home: done. (return 0x403e)" << endl;
751 return (void*)0x403e;
752
753 case WM_CALCALTAZ:
754 {
755 cout << endl;
756
757 SlaStars sla(fObservatory);
758 sla.Now();
759
760 XY xy = *((XY*)mp);
761 RaDec rd(xy.X()*15., xy.Y()); // [deg]
762
763 ZdAz a1 = sla.CalcZdAz(rd*kDeg2Rad); // [rad]
764
765 cout << "Ra/Dec source: " << xy.X() << "h " << xy.Y() << "°" << endl;
766 cout << "Zd/Az target: " << a1.Zd()*kRad2Deg << "° " << a1.Az()*kRad2Deg << "°" << endl;
767
768 if (fZd1 && fZd2 && fAz)
769 a1 = AlignTrackingPos(a1);
770
771 a1 = fBending(a1);
772 CheckRange(a1);
773 a1 *= kRad2Deg;
774
775 const ZdAz a2 = a1*kResSE/360;
776
777 cout << "Zd/Az bended: " << a1.Zd() << "° " << a1.Az() << "°" << endl;
778 cout << "SE bended: " << a2.Zd() << " " << a2.Az() << endl;
779 }
780 return (void*)0xa17a;
781
782 case WM_ENDSWITCH:
783 {
784 ZdAz pos = GetSePos()*TMath::TwoPi()/kResSE;
785 pos = fBending.SubtractOffsets(pos)*kRad2Deg;
786
787 cout << "Endswitch Position: Zd=" << pos.Zd() << "° Az=";
788 cout << pos.Az() << "°" << endl;
789 }
790
791 return (void*)0x1010;
792
793 case WM_QUIT:
794 cout << "WM_Quit: now." << endl;
795 if (!CheckNetwork())
796 {
797 lout << "ERROR: Cannot shutdown CANbus network." << endl;
798 return (void*)0xebb0;
799 }
800 TerminateApp();
801 cout << "WM_Quit: done." << endl;
802 return (void*)0xaaaa;
803 }
804 cout << "MCosy::Proc: Unknown message 0x" << msg << endl;
805 return (void*)0xffffffff;
806}
807
808void *MTTalk::Thread()
809{
810 fCosy->TalkThread();
811 return NULL;
812}
813
814void MCosy::ReadConfig()
815{
816 cout << "Reading configuration file..." << flush;
817 TEnv env(".cosyrc");
818 cout << "done." << endl;
819
820 cout << "Reading telescope range..." << flush;
821 const Double_t amin = env.GetValue("Az_Min[deg]", -95.0);
822 const Double_t zmin = env.GetValue("Zd_Min[deg]", -75.0);
823 fMin.Set(zmin, amin);
824
825 const Double_t amax = env.GetValue("Az_Max[deg]", 305.0);
826 const Double_t zmax = env.GetValue("Zd_Max[deg]", 98.25);
827 fMax.Set(zmax, amax);
828 cout << "done." << endl;
829
830 cout << " * Min: " << zmin << "deg " << amin << "deg" << endl;
831 cout << " * Max: " << zmax << "deg " << amax << "deg" << endl;
832
833 fMin = fBending.AddOffsets(fMin/kRad2Deg);
834 fMax = fBending.AddOffsets(fMax/kRad2Deg);
835
836 cout << " * Min': " << fMin.Zd()*kRad2Deg << "deg " << fMin.Az()*kRad2Deg << "deg" << endl;
837 cout << " * Max': " << fMax.Zd()*kRad2Deg << "deg " << fMax.Az()*kRad2Deg << "deg" << endl;
838
839 cout << "Reading gear ratios..." << flush;
840 kGear.X(env.GetValue("Zd_GearRatio[U_mot/U_tel]", 1000.0));
841 kGear.Y(env.GetValue("Az_GearRatio[U_mot/U_tel]", 1000.0));
842
843 kResRE.Y(0);
844 if (fMac1 && !fMac1->IsZombieNode())
845 kResRE.Y(fMac1->GetRes());
846 else
847 if (fMac3 && !fMac3->IsZombieNode())
848 kResRE.Y(fMac3->GetRes());
849 else
850 kResRE.Y(env.GetValue("Az_ResRE[re/U_mot]", 1500));
851
852 kResRE.X(0);
853 if (fMac2 && !fMac2->IsZombieNode())
854 kResRE.X(fMac2->GetRes());
855 else
856 kResRE.X(env.GetValue("Zd_ResRE[re/U_mot]", 1500));
857
858 kResSE.X(0);
859 if (fZd1 && !fZd1->IsZombieNode())
860 kResSE.X(fZd1->GetPhysRes());
861 else
862 if (fZd2 && !fZd2->IsZombieNode())
863 kResSE.X(fZd2->GetPhysRes());
864 else
865 kResSE.X(env.GetValue("Zd_ResSE[se/U_mot]", 16384));
866
867 kResSE.Y(0);
868 if (fAz && !fAz->IsZombieNode())
869 kResSE.Y(fAz->GetPhysRes());
870 else
871 kResSE.Y(env.GetValue("Az_ResSE[se/U_mot]", 16384));
872
873 // believing the Macs manual '*4' shouldn't be necessary, but it is.
874 // Because the a RE is 4 quad counts.
875 // Calculating speeds we have to convert back to qc
876 kResRE *= 4;
877 kGearTot = kResRE*kGear;
878
879 cout << "done." << endl;
880
881 cout << " * Setting Gear Ratios:" << endl;
882 cout << " --------------------" << endl;
883 cout << " * X: " << kGear.X() << "*" << kResRE.X()/4 << "/" << kResSE.X() << "=4*" << kGearTot.X() << "/" << kResSE.X() << endl;
884 cout << " * Y: " << kGear.Y() << "*" << kResRE.Y()/4 << "/" << kResSE.Y() << "=4*" << kGearTot.Y() << "/" << kResSE.Y() << endl;
885}
886/*
887void MCosy::InitSync()
888{
889 if (!fMac3)
890 {
891 lout << "Unable to Init Sync! Mac3 not available." << endl;
892 return;
893 }
894
895 const int res = fMac3->GetVelRes();
896
897 fMac3->SetVelocity(0.3*res);
898 fMac3->SetAcceleration(0.2*res);
899 fMac3->SetDeceleration(0.2*res);
900 fMac3->StartPosSync();
901}
902*/
903void MCosy::TalkThreadSeTest()
904{
905// if (fZd1->IsZombieNode() || fZd2->IsZombieNode())
906 // return;
907
908 if (fHist)
909 {
910 lout << "You are much too fast... try again." << endl;
911 return;
912 }
913
914 fHist = new TH2F("Diff", "Difference of SE values",
915 201, fMin.Zd(), fMax.Zd(), 41, -10.5, 10.5);
916 fHist->SetXTitle("ZA [\\circ]");
917 fHist->SetYTitle("\\Delta SE");
918
919 Double_t offset = 0;
920
921 int cnt = 0;
922
923 lout << "Starting Shaftencoder Test..." << endl;
924
925 while (fBackground==kBgdSeTest)
926 {
927 fZd1->ResetPosHasChanged();
928 fZd2->ResetPosHasChanged();
929
930 while (!fZd1->PosHasChanged() && !fZd2->PosHasChanged() &&
931 fBackground==kBgdSeTest)
932 usleep(1);
933
934 const Double_t pos[3] = {
935 (fZd1->GetPos()+8192)%16384,
936 (fZd2->GetPos()+8192)%16384,
937 fAz->GetPos() };
938
939 //
940 // Estimate Offset from the first ten positions
941 //
942 if (cnt++<10)
943 {
944 offset += pos[0]+pos[1];
945 continue;
946 }
947 if (cnt==11)
948 {
949 offset /= 10;
950 cnt++;
951 }
952
953 Double_t apos = (pos[0]-pos[1])/2 * TMath::TwoPi() / kResSE.X();
954
955 ZdAz bend = fBending.CorrectBack(ZdAz(apos, pos[2]))*kRad2Deg;
956 fHist->Fill(bend.Zd(), pos[0]+pos[1]-offset);
957 }
958
959 lout << "Shaftencoder Test Stopped... displaying Histogram." << endl;
960
961 fBackground=kBgdSeTestDispl;
962}
963
964void MCosy::TalkThreadGear()
965{
966// if (fZd1->IsZombieNode() || fZd2->IsZombieNode())
967 // return;
968
969 if (fHist)
970 {
971 lout << "You are much too fast... try again." << endl;
972 return;
973 }
974
975 fHist = new TH3F("Gear", "Gear Ratio Re/Se",
976 (int)((fMax.Zd()-fMin.Zd())/2.5+1), fMin.Zd(), fMax.Zd(),
977 (int)((fMax.Az()-fMin.Az())/2.5+1), fMin.Az(), fMax.Az(),
978 61, 349.5, 500.5);
979
980 fHist->SetXTitle("Zd [\\circ]");
981 fHist->SetYTitle("Az [\\circ]");
982 fHist->SetZTitle("Re/Se");
983
984 lout << "Starting Gear determination..." << endl;
985
986 ZdAz se0 = GetSePos();
987 ZdAz re0 = GetRePosPdo();
988
989 while (fBackground==kBgdGear)
990 {
991 fZd1->ResetPosHasChanged();
992 fZd2->ResetPosHasChanged();
993 fAz->ResetPosHasChanged();
994
995 while (!fZd1->PosHasChanged() && !fZd2->PosHasChanged() &&
996 !fAz->PosHasChanged() && fBackground==kBgdGear)
997 usleep(1);
998
999 ZdAz se = GetSePos();
1000 ZdAz re = GetRePosPdo();
1001
1002 ZdAz dse = se-se0;
1003 ZdAz dre = re-re0;
1004
1005 if (fabs(dse.Zd())*144>kResSE.X()) // Each 2.5deg (144)
1006 {
1007 se0.Zd(se.Zd());
1008 re0.Zd(re.Zd());
1009
1010 se -= dse/2;
1011
1012 ZdAz bend = fBending.CorrectBack(se*TMath::TwoPi()/kResSE)*kRad2Deg;
1013 ((TH3*)fHist)->Fill(bend.Zd(), bend.Az(), dre.Zd()/dse.Zd());
1014 }
1015
1016 if (fabs(dse.Az())*144>kResSE.Y()) // Each 2.5deg (144)
1017 {
1018 se0.Az(se.Az());
1019 re0.Az(re.Az());
1020
1021 se -= dse/2;
1022
1023 ZdAz bend = fBending.CorrectBack(se*TMath::TwoPi()/kResSE)*kRad2Deg;
1024 ((TH3*)fHist)->Fill(bend.Az(), bend.Az(), dre.Az()/dse.Az());
1025 }
1026 }
1027 lout << "Gear Test Stopped... displaying Histogram." << endl;
1028
1029 fBackground=kBgdGearDispl;
1030}
1031
1032void MCosy::TalkThread()
1033{
1034 /* ========== FIXME? =============
1035 if (fMac1->IsZombieNode() || fMac2->IsZombieNode())
1036 return;
1037 */
1038
1039 if (fMac1 && fMac2)
1040 {
1041 fMac1->ReqPos();
1042 fMac2->ReqPos();
1043 }
1044
1045 //InitSync();
1046
1047 /*** FOR DEMO MODE ***/
1048 if (!fZd1 || !fZd2 || !fAz)
1049 return;
1050 /*** FOR DEMO MODE ***/
1051
1052 //
1053 // Start the Network
1054 //
1055 while (1)
1056 {
1057 //
1058 // wait until a tracking session is started
1059 //
1060 while (fBackground==kBgdNone)
1061 usleep(1);
1062
1063 switch (fBackground)
1064 {
1065 case kBgdNone:
1066 continue;
1067/*#ifndef NEWALGO
1068 case kBgdTracking:
1069 TalkThreadTracking();
1070 continue;
1071#endif*/
1072 case kBgdSeTest:
1073 TalkThreadSeTest();
1074 continue;
1075
1076 case kBgdGear:
1077 TalkThreadGear();
1078 continue;
1079
1080 default:
1081 continue;
1082 }
1083 }
1084}
1085
1086ZdAz MCosy::GetPointingPos() const
1087{
1088 if (fZd1->IsZombieNode() || fZd2->IsZombieNode() || fAz->IsZombieNode())
1089 return ZdAz(0, 0);
1090
1091 // GetPointingPos [deg]
1092 const ZdAz seist = GetSePos()*TMath::TwoPi()/kResSE; // [rad]
1093 return fBending.CorrectBack(seist)*TMath::RadToDeg();
1094}
1095
1096Bool_t MCosy::HandleTimer(TTimer *t)
1097{
1098 const Int_t rc = fMutexGui.TryLock();
1099 if (rc==13)
1100 cout << "MCosy::HandleTimer - mutex is already locked by this thread" << endl;
1101
1102 if (rc)
1103 {
1104 lout << "* GUI update skipped due to locked mutex." << endl;
1105 return kTRUE;
1106 }
1107
1108 //
1109 // Update Gui, foremer MTGui.
1110 //
1111 if (fZd1)
1112 fZd1->DisplayVal();
1113 if (fZd2)
1114 fZd2->DisplayVal();
1115 if (fAz)
1116 fAz->DisplayVal();
1117
1118 Byte_t avail = 0;
1119
1120 avail |= (fMac1 && !fMac1->IsZombieNode()) ? 0x01 : 0;
1121 avail |= (fMac2 && !fMac2->IsZombieNode()) ? 0x02 : 0;
1122 avail |= (fMac3 && !fMac3->IsZombieNode()) ? 0x04 : 0;
1123 avail |= (fZd1 && !fZd1->IsZombieNode()) ? 0x08 : 0;
1124 avail |= (fZd2 && !fZd2->IsZombieNode()) ? 0x10 : 0;
1125 avail |= (fAz && !fAz->IsZombieNode()) ? 0x20 : 0;
1126
1127 if (HasError())
1128 SetStatus(MDriveCom::kError);
1129
1130
1131 ZdAz bendist = fStatus&MDriveCom::kTracking ? fTrackingPos : GetPointingPos();
1132
1133 //cout << (fStatus&MDriveCom::kTracking?"TRA: ":"POS: ") << bendist.Zd() << " " << bendist.Az() << endl;
1134
1135 fCom->SendReport(fStatus, fRaDec, fZdAzSoll, bendist, fTrackingError);
1136
1137 fWin->UpdateWeather(*fCom);
1138 fWin->Update(bendist, fTrackingError, fVelocity, /*fOffset,*/
1139 fRaDec, fZdAzSoll, fStatus, avail);
1140
1141 lout.UpdateGui();
1142
1143 const Bool_t trigger = fTriggerDisplay;
1144 fTriggerDisplay = kFALSE;
1145
1146 if (fBackground==kBgdSeTestDispl || (trigger&&fBackground==kBgdSeTest))
1147 DisplayHistTestSe(!trigger);
1148
1149 if (fBackground==kBgdGearDispl || (trigger&&fBackground==kBgdGear))
1150 DisplayHistGear(!trigger);
1151
1152 if (fMutexGui.UnLock()==13)
1153 cout << "MCosy::HandleTimer - tried to unlock mutex locked by other thread." << endl;
1154
1155 return kTRUE;
1156}
1157
1158void MCosy::DisplayHistTestSe(Bool_t del)
1159{
1160 lout << "Displaying histogram..." << endl;
1161
1162 TH2F &hist = *(TH2F*)fHist;
1163
1164 if (del)
1165 {
1166 fHist = NULL;
1167 fBackground = kBgdNone;
1168 }
1169
1170 TCanvas *c=new TCanvas("c1", "", 1000, 1000);
1171 c->Divide(1,2);
1172
1173 c->cd(1);
1174 TH2 *h=(TH2*)hist.DrawCopy();
1175
1176 TProfile *p = h->ProfileX("_pfx", -1, 9999, "s");
1177 p->SetLineColor(kBlue);
1178 p->Draw("same");
1179 p->SetBit(kCanDelete);
1180
1181 c->cd(2);
1182
1183 TH1F p2("spread", "Spread of the differences", hist.GetNbinsX(), hist.GetBinLowEdge(1),
1184 hist.GetBinLowEdge(hist.GetNbinsX()+1));
1185 p2.SetXTitle("Zd [\\circ]");
1186 for (int i=0; i<hist.GetNbinsX(); i++)
1187 p2.SetBinError(i, p->GetBinError(i));
1188 p2.SetLineColor(kRed);
1189 p2.SetStats(0);
1190 p2.DrawCopy();
1191
1192 if (del)
1193 delete &hist;
1194}
1195
1196void MCosy::DisplayHistGear(Bool_t del)
1197{
1198 lout << "Displaying histogram..." << endl;
1199
1200 TH3F &hist = *(TH3F*)fHist;
1201
1202 if (del)
1203 {
1204 fHist = NULL;
1205 fBackground = kBgdNone;
1206 }
1207
1208 TCanvas *c=new TCanvas("c1", "", 1000, 1000);
1209 c->Divide(2,2);
1210
1211 // ----------
1212
1213 c->cd(1);
1214 TH2D &h1=*(TH2D*)hist.Project3D("zx"); // Zd
1215 h1.SetTitle(" Gear Ratio Zenith Distance [re/se] ");
1216 h1.SetXTitle("Zd [\\circ]");
1217 h1.Draw();
1218 h1.SetBit(kCanDelete);
1219
1220 TProfile *p1 = h1.ProfileX("_pfx", -1, 9999, "s");
1221 p1->SetLineColor(kBlue);
1222 p1->Draw("same");
1223 p1->SetBit(kCanDelete);
1224
1225 // ----------
1226
1227 c->cd(2);
1228 TH2D &h2=*(TH2D*)hist.Project3D("zy"); // Az
1229 h2.SetTitle(" Gear Ratio Azimuth [re/se] ");
1230 h2.SetXTitle("Zd [\\circ]");
1231 h2.Draw();
1232 h2.SetBit(kCanDelete);
1233
1234 TProfile *p2 = h2.ProfileX("_pfx", -1, 9999, "s");
1235 p2->SetLineColor(kBlue);
1236 p2->Draw("same");
1237 p2->SetBit(kCanDelete);
1238
1239 // ----------
1240
1241 c->cd(3);
1242
1243 TAxis &axe1 = *h1.GetXaxis();
1244
1245 TH1F f1("spreadzd", " Spread Zenith Distance ",
1246 axe1.GetNbins(), axe1.GetXmin(), axe1.GetXmax());
1247 f1.SetXTitle("Zd [\\circ]");
1248 for (int i=0; i<axe1.GetNbins(); i++)
1249 f1.SetBinError(i, p1->GetBinError(i));
1250 f1.SetLineColor(kRed);
1251 f1.SetStats(0);
1252 f1.DrawCopy();
1253
1254 c->cd(4);
1255
1256 // ----------
1257
1258 TAxis &axe2 = *h2.GetXaxis();
1259
1260 TH1F f2("spreadaz", " Spread Azimuth ",
1261 axe2.GetNbins(), axe2.GetXmin(), axe2.GetXmax());
1262 f2.SetXTitle("Az [\\circ]");
1263 for (int i=0; i<axe2.GetNbins(); i++)
1264 f2.SetBinError(i, p2->GetBinError(i));
1265 f2.SetLineColor(kRed);
1266 f2.SetStats(0);
1267 f2.DrawCopy();
1268
1269 // ----------
1270
1271 if (del)
1272 delete &hist;
1273}
1274
1275// --------------------------------------------------------------------------
1276//
1277// Start the work of the application:
1278//
1279// Start the Can-Network.
1280// Start the MCosy::TalkThread thread.
1281// turn on the gui update
1282//
1283void MCosy::Start()
1284{
1285 // Don't call this function twice!
1286 Network::Start();
1287
1288 CheckForError();
1289
1290 ReadConfig();
1291
1292 lout << "- Starting TX Thread." << endl;
1293 fTTalk = new MTTalk(this);
1294
1295 lout << "- Starting GUI update." << endl;
1296 fUpdateGui->TurnOn();
1297}
1298
1299// --------------------------------------------------------------------------
1300//
1301// Start the work of the application:
1302//
1303// Turn of the gui update
1304// stop the MCosy::TalkThread thread.
1305// Stop the network
1306//
1307void MCosy::Stop()
1308{
1309 lout << "- Stopping GUI update." << endl;
1310 fUpdateGui->TurnOff();
1311 lout << "- GUI Update stopped." << endl;
1312
1313 delete fTTalk;
1314 lout << "- TX Thread stopped." << endl;
1315
1316 Network::Stop();
1317}
1318
1319// --------------------------------------------------------------------------
1320//
1321// Disable the synchronization by using a negative CAN Id for id2.
1322//
1323void MCosy::Constructor(Int_t id1, Int_t id2, Int_t id3,
1324 Int_t id4, Int_t id5, Int_t id6)
1325{
1326 //
1327 // Create Nodes
1328 //
1329 lout << "- Setting up network." << endl;
1330
1331 fMac1=new Macs(id1, "Mac/Az", lout);
1332 fMac2=new Macs(id3, "Mac/Zd", lout);
1333 if (id2>=0)
1334 fMac3=new Macs(id2, "Mac/Az-Sync", lout);
1335
1336 fZd1=new ShaftEncoder(id4, "SE/Zd1", lout);
1337 fZd2=new ShaftEncoder(id5, "SE/Zd2", lout);
1338 fAz =new ShaftEncoder(id6, "SE/Az", lout);
1339
1340 fZd1->SetReport(fOutRep);
1341 fZd2->SetReport(fOutRep);
1342 fAz->SetReport(fOutRep);
1343
1344 fAz->SetMotor(fMac1);
1345 fZd1->SetMotor(fMac2);
1346 fZd2->SetMotor(fMac2);
1347
1348 lout << "- Connecting devices to network." << endl;
1349
1350 //
1351 // Connect the devices to the network
1352 //
1353 SetNode(fMac1);
1354 SetNode(fMac2);
1355 if (id2>=0)
1356 SetNode(fMac3);
1357 SetNode(fZd1);
1358 SetNode(fZd2);
1359 SetNode(fAz);
1360
1361 //
1362 // Create Gui Event timer and Gui
1363 //
1364 lout << "- Initializing GUI Timer." << endl;
1365 fUpdateGui = new TTimer(this, 100); // 100ms
1366
1367 lout << "- Starting GUI." << endl;
1368 fWin=new MGCosy(fObservatory, this, gClient->GetRoot(), 1, 1);
1369}
1370/*
1371void MCosy::ConstructorSE(Int_t id4, Int_t id5, Int_t id6)
1372{
1373 //
1374 // Create Nodes
1375 //
1376 lout << "- Setting up network." << endl;
1377
1378 fZd1=new ShaftEncoder(id4, "SE/Zd1", lout);
1379 fZd2=new ShaftEncoder(id5, "SE/Zd2", lout);
1380 fAz =new ShaftEncoder(id6, "SE/Az", lout);
1381
1382 lout << "- Connecting devices to network." << endl;
1383
1384 //
1385 // Connect the devices to the network
1386 //
1387 SetNode(fZd1);
1388 SetNode(fZd2);
1389 SetNode(fAz);
1390
1391 //
1392 // Create Gui Event timer and Gui
1393 //
1394 lout << "- Initializing GUI Timer." << endl;
1395 fUpdateGui = new TTimer(this, 100); // 100ms
1396
1397 lout << "- Starting GUI." << endl;
1398 fWin=new MGCosy(fObservatory, this, gClient->GetRoot(), 1, 1);
1399}
1400
1401void MCosy::ConstructorDemo()
1402{
1403 //
1404 // Create Nodes
1405 //
1406 lout << "- Setting up network." << endl;
1407
1408 //
1409 // Create Gui Event timer and Gui
1410 //
1411 lout << "- Initializing GUI Timer." << endl;
1412 fUpdateGui = new TTimer(this, 100); // 100ms
1413
1414 lout << "- Starting GUI." << endl;
1415 fWin=new MGCosy(fObservatory, this, gClient->GetRoot(), 1, 1);
1416}
1417*/
1418
1419TString MCosy::GetFileName(const char *fmt)
1420{
1421 // FIXME: Timeout missing
1422 while (1)
1423 {
1424 MTime time(-1);
1425 const TString name = Form(fmt, (const char*)time.GetFileName());
1426 if (gSystem->AccessPathName(name, kFileExists))
1427 return name;
1428 break;
1429
1430 usleep(1000);
1431 }
1432 return "";
1433}
1434
1435MCosy::MCosy(/*int mode,*/ const char *dev, const int baud, MLog &out)
1436: 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)
1437{
1438 TEnv env(".cosyrc");
1439 const Int_t id1 = env.GetValue("Az_Id-MAC1", 1); //1
1440 const Int_t id2 = env.GetValue("Az_Id-MAC2", 2); //2
1441 const Int_t id3 = env.GetValue("Zd_Id-MAC", 3); //3
1442 const Int_t id4 = env.GetValue("Zd_Id-SE1", 4); //4
1443 const Int_t id5 = env.GetValue("Zd_Id-SE2", 5); //5
1444 const Int_t id6 = env.GetValue("Az_Id-SE", 6); //6
1445
1446 TString name = GetFileName("rep/cosy_%s.rep");
1447 cout << "Open Repfile: " << name << endl;
1448 fOutRep = new MLog(name, kTRUE);
1449 *fOutRep << "[Drive Report File]" << endl;
1450 *fOutRep << "Version <cvs>" << endl;
1451 *fOutRep << "Date " << MTime(-1) << endl;
1452 *fOutRep << "[Reports]" << endl;
1453
1454/*
1455 lout << "- Program in ";
1456 switch (mode)
1457 {
1458 case 0:
1459 lout << "<<Standard mode>>" << endl;*/
1460 fBending.Load("bending.txt");
1461 Constructor(id1, id2, id3, id4, id5, id6);/*
1462 break;
1463 case 1:
1464 lout << "<<SE mode>>" << endl;
1465 fBending.Load("bending.txt");
1466 ConstructorSE(id4, id5, id6);
1467 break;
1468 default:
1469 lout << "<<Demo mode>>" << endl;
1470 ConstructorDemo();
1471 }
1472*/
1473 lout.SetOutputGui(fWin->GetLog(), kTRUE);
1474
1475 fZd1->SetDisplay(fWin->GetLabel2());
1476 fZd2->SetDisplay(fWin->GetLabel3());
1477 fAz->SetDisplay(fWin->GetLabel1());
1478
1479 fCom = new MDriveCom(this, *fOutRep);
1480 fCom->Start();
1481}
1482
1483void MCosy::TerminateApp()
1484{
1485 cout << "MCosy::TerminateApp()" << endl;
1486/*
1487 Int_t rc;
1488 TGMessageBox msg(this, gClient->GetRoot(),
1489 "Information",
1490 "Cosy is shutting down the system - this may take wa while!",
1491 kMBIconExclamation,
1492 kMBOK, //kMBClose
1493 &rc, 0);
1494*/
1495
1496 lout.DisableOutputDevice(MLog::eGui);
1497 // FIXME: WHY DOES THIS CRASH THE APPLICATIOn WHILE TRAKING?
1498 // lout.SetOutputGui(NULL, kFALSE);
1499
1500 gApplication->Terminate(0);
1501}
1502
1503MCosy::~MCosy()
1504{
1505 if (fOutTp)
1506 {
1507 *fOutTp << "END" << endl;
1508 delete fOutTp;
1509 }
1510 delete fOutRep;
1511
1512 cout << "Deleting GUI timer." << endl;
1513
1514 delete fUpdateGui;
1515 delete fCom;
1516
1517 cout << "Deleting Nodes." << endl;
1518
1519 fZd1->SetReport(0);
1520 fZd2->SetReport(0);
1521 fAz->SetReport(0);
1522
1523 delete fAz;
1524 delete fZd1;
1525 delete fZd2;
1526 delete fMac1;
1527 delete fMac2;
1528 if (fMac3)
1529 delete fMac3;
1530
1531 cout << "Deleting MGCosy." << endl;
1532
1533 lout.DisableOutputDevice(MLog::eGui);
1534
1535 delete fWin;
1536
1537 cout << "MGCosy destructed." << endl;
1538}
Note: See TracBrowser for help on using the repository browser.