File: MANJUST\MJ_OFUNK.CPP
1 //#############################################################################
2 // //
3 // MJ_OFUNK.CPP //
4 // //
5 // Subsystem : alte Manuelle Justage / Funktionalität //
6 // Benutzung durch andere Subsysteme erforderlich: NEIN //
7 //---------------------------------------------------------------------------//
8 // Autoren: Thomas Kullmann, Günther Reinecker //
9 // Stand : 12.10.2002 //
10 // //
11 //#############################################################################
12
13 #include "manjust\mj_ofunk.h" // SCHNITTSTELLE für diese Datei
14
15 #include "workflow\workflow.h" // extern Steering
16
17 //--||--\\--||--//--||--\\--||--//--||--\\--||--//--||--\\--||--//--||--\\--||--
18
19 //##############################################################################
20 // externe Abhängigkeiten
21 //##############################################################################
22
23 extern TSteering Steering;
24 extern BOOL bManualMovesCorrected;
25
26 //##############################################################################
27 // TAngleCtl
28 //##############################################################################
29
30 //*****************************************************************************
31 // Konstruktor/Destruktor
32 //*****************************************************************************
33
34 TAngleCtl::TAngleCtl ( void )
35 {
36 m_IsMeasuring= FALSE; // Halbwertsbreite wird nicht gemessen
37 m_MotorCount= mlGetAxisNumber();
38 m_MoveSpeed= new double [GetMotorCount()]; // Liste der Geschwindigkeiten: Länge=Anzahl der Motoren
39 for (UINT i= 0; i < GetMotorCount(); i++)
40 m_MoveSpeed[i]= 0;
41 m_Sensor= TDetectorManager::DetectorManager().GetDetector(); // Pointer auf den akt. Sensor
42 }
43 //-----------------------------------------------------------------------------
44
45 TAngleCtl::~TAngleCtl ( void )
46 {
47 _FREELIST( m_MoveSpeed );
48 }
49
50 //******************************************************************************
51 // Sonstiges
52 //******************************************************************************
53
54 BOOL TAngleCtl::DoInit ( const int aIndex )
55 {
56 if ( !IsIndexValid(aIndex) )
57 return FALSE;
58
59 for (UINT cnt= 0; cnt < GetMotorCount(); cnt++)
60 { // Sichern der Motor-Einstellungen
61 mlSetAxis(cnt);
62 mPushSettings();
63 m_MoveSpeed[cnt]= mGetValue(Speed); // zuletzt benutze Geschwindigkeit := aktuelle Bewegungsgeschwindigkeit
64 }
65 return DoSelectMotor( aIndex );
66 }
67 //-----------------------------------------------------------------------------
68
69 BOOL TAngleCtl::DoInitMotor ( const int aIndex, const BOOL aMaxSpeed )
70 {
71 if ( !IsIndexValid(aIndex) )
72 return FALSE;
73
74 if ( aMaxSpeed )
75 mlSetValue(aIndex, Speed, 10000.0); // Im Schrittbetrieb Maximalgeschwingkeit verwenden; BESSER MaxVelocity verwenden!!!
76 else
77 mlSetValue(aIndex, Speed, m_MoveSpeed[aIndex]); // sonst zuletzt eingegebe Geschwindigkeit
78 return TRUE;
79 }
80
81 //******************************************************************************
82 // Antriebssteuerung
83 //******************************************************************************
84
85 BOOL TAngleCtl::DoDirect ( const int aIndex, const double aPos )
86 {
87 if ( !CanDoDirect(aIndex) )
88 return FALSE;
89
90 DoSelectMotor(aIndex);
91 mActivateDrive(); // Motor aktivieren (sonst bewegt sich der Antrieb nicht, wenn er gestartet wird)
92 mMoveToDistance(aPos);
93 BOOL bValid;
94 return IsMoving(aIndex, bValid);
95 }
96 //-----------------------------------------------------------------------------
97
98 BOOL TAngleCtl::DoStep ( const int aIndex, const BOOL aUp )
99 {
100 if ( !CanDoStep(aIndex, aUp) )
101 return FALSE;
102
103 DoSelectMotor(aIndex);
104 mActivateDrive(); // Motor aktivieren (sonst bewegt sich der Antrieb nicht, wenn er gestartet wird)
105 BOOL bValid;
106 if ( aUp )
107 mMoveToDistance( GetAngle(aIndex, bValid) + GetAngleWidth(aIndex, bValid) );
108 else
109 mMoveToDistance( GetAngle(aIndex, bValid) - GetAngleWidth(aIndex, bValid) );
110 return IsMoving(aIndex, bValid);
111 }
112 //-----------------------------------------------------------------------------
113
114 BOOL TAngleCtl::DoDrive ( const int aIndex, const BOOL aUp )
115 {
116 if ( !CanDoDrive(aIndex, aUp) )
117 return FALSE;
118
119 DoSelectMotor(aIndex);
120 mActivateDrive(); // Motor aktivieren (sonst bewegt sich der Antrieb nicht, wenn er gestartet wird)
121 BOOL bValid;
122 if ( aUp )
123 mMoveToDistance( GetAngleMax(aIndex, bValid) );
124 else
125 mMoveToDistance( GetAngleMin(aIndex, bValid) );
126 return IsMoving(aIndex, bValid);
127 }
128 //-----------------------------------------------------------------------------
129
130 BOOL TAngleCtl::DoStop ( const int aIndex )
131 {
132 if ( !CanDoStop(aIndex) )
133 return FALSE;
134
135 DoSelectMotor(aIndex);
136 mStopDrive(TRUE);
137 DelayTime(5);
138 BOOL bValid;
139 return !IsMoving(aIndex, bValid);
140 }
141 //-----------------------------------------------------------------------------
142
143 void TAngleCtl::DoStopEverything ( const int aIndex )
144 {
145 //zuerst die Halbwertsbreitenmessung stoppen
146 DoStopMeasure(0);
147 //Detektor stoppen
148 if (m_Sensor != TDetectorManager::DetectorManager().GetDetector(0, 1))
149 {
150 m_Sensor->MeasureStop();
151 m_Sensor->PopSettings();
152 m_Sensor->MeasureStart();
153 }
154 //letztendlich auch die Antriebe stoppen
155 for (UINT cnt= 0; cnt < GetMotorCount(); cnt++)
156 if ( DoSelectMotor(cnt) )
157 {
158 mPopSettings(ThisPosition);
159 mSetCorrectionState(FALSE);
160 mStopDrive(TRUE);
161 }
162 DoSelectMotor(aIndex);
163 }
164
165 //******************************************************************************
166 // Statusinformationen
167 //******************************************************************************
168
169 BOOL TAngleCtl::IsIndexValid ( const int aIndex ) const
170 {
171 return ( (0 <= aIndex) && (aIndex < (int)GetMotorCount()) );
172 }
173 //-----------------------------------------------------------------------------
174
175 BOOL TAngleCtl::HasOffset ( const int aIndex, BOOL &aValid ) const
176 {
177 aValid= FALSE;
178 if ( !IsIndexValid(aIndex) )
179 return FALSE;
180
181 aValid= TRUE;
182 return mlIsDistanceRelative(aIndex);
183 }
184 //------------------------------------------------------------------------------
185
186 BOOL TAngleCtl::IsMoving ( const int aIndex, BOOL &aValid ) const
187 {
188 // ist der Partnerantrieb in Bewegung?
189 int idDF= GetMotorIdx(DF);
190 int idDC= GetMotorIdx(DC);
191 if ( (aIndex == idDF) && (Moves(idDC, aValid)) && (aValid) )
192 return TRUE;
193 else if ( (aIndex == idDC) && (Moves(idDF, aValid)) && (aValid) )
194 return TRUE;
195
196 return Moves(aIndex, aValid);
197 }
198 //-----------------------------------------------------------------------------
199
200 BOOL TAngleCtl::IsCalibrated ( const int aIndex, BOOL &aValid ) const
201 {
202 aValid= FALSE;
203 if ( !IsIndexValid(aIndex) )
204 return FALSE;
205
206 aValid= TRUE;
207 return mlIsCalibrated(aIndex);
208 };
209
210 //******************************************************************************
211 // Get-Methoden
212 //******************************************************************************
213
214 double TAngleCtl::GetAngle ( const int aIndex, BOOL &aValid ) const
215 {
216 aValid= FALSE;
217 if ( !IsIndexValid(aIndex) )
218 return 0.0;
219
220 double result;
221 if ( Moves(aIndex, aValid) )
222 {
223 aValid= TRUE;
224 result= mlGetDistanceProcess(aIndex);
225 }
226 else
227 aValid= mlGetDistance(aIndex, result);
228 return result;
229 }
230 //-----------------------------------------------------------------------------
231
232 double TAngleCtl::GetAngleMin ( const int aIndex, BOOL &aValid ) const
233 {
234 aValid= FALSE;
235 if ( !IsIndexValid(aIndex) )
236 return 0.0;
237
238 aValid= TRUE;
239 return min( mlGetAngleRelativeMin(aIndex), mlGetAngleRelativeMax(aIndex) );
240 }
241 //-----------------------------------------------------------------------------
242
243 double TAngleCtl::GetAngleMax ( const int aIndex, BOOL &aValid ) const
244 {
245 aValid= FALSE;
246 if ( !IsIndexValid(aIndex) )
247 return 0.0;
248
249 aValid= TRUE;
250 return max( mlGetAngleRelativeMin(aIndex), mlGetAngleRelativeMax(aIndex) );
251 }
252 //-----------------------------------------------------------------------------
253
254 double TAngleCtl::GetSpeed ( const int aIndex, BOOL &aValid ) const
255 {
256 aValid= FALSE;
257 if ( !IsIndexValid(aIndex) )
258 return 0.0;
259
260 aValid= TRUE;
261 return mlGetValue(aIndex, Speed);
262 }
263 //-----------------------------------------------------------------------------
264
265 double TAngleCtl::GetAngleWidth ( const int aIndex, BOOL &aValid ) const
266 {
267 aValid= FALSE;
268 if ( !IsIndexValid(aIndex) )
269 return 0.0;
270
271 aValid= TRUE;
272 return mlGetValue(aIndex, Width);
273 }
274 //-----------------------------------------------------------------------------
275
276 UINT TAngleCtl::GetDigits ( const int aIndex, BOOL &aValid ) const
277 {
278 aValid= FALSE;
279 if ( !IsIndexValid(aIndex) )
280 return 2;
281
282 aValid= TRUE;
283 return mlGetDigits(aIndex);
284 }
285 //-----------------------------------------------------------------------------
286
287 LPCSTR TAngleCtl::GetUnit ( const int aIndex, BOOL &aValid ) const
288 {
289 aValid= FALSE;
290 if ( !IsIndexValid(aIndex) )
291 return "";
292
293 aValid= TRUE;
294 return mlGetUnitName(aIndex);
295 }
296 //-----------------------------------------------------------------------------
297
298 int TAngleCtl::GetMotorIdx ( const EAxisType aAxis ) const
299 {
300 if ( aAxis == (EAxisType)0 )
301 return -1;
302 else
303 return mlGetIdByName(aAxis);
304 }
305 //-----------------------------------------------------------------------------
306
307 LPCSTR TAngleCtl::GetMotorName ( const int aIndex, BOOL &aValid ) const
308 {
309 aValid= FALSE;
310 if ( !IsIndexValid(aIndex) )
311 return "";
312
313 aValid= TRUE;
314 return mlGetAxisName(aIndex);
315 }
316 //-----------------------------------------------------------------------------
317
318 UINT TAngleCtl::GetMotorCount ( void ) const
319 {
320 return m_MotorCount;
321 }
322 //-----------------------------------------------------------------------------
323
324 int TAngleCtl::GetActualMotor ( void ) const
325 {
326 return mlGetAxis();
327 }
328
329 //******************************************************************************
330 // SET-Methoden
331 //******************************************************************************
332
333 BOOL TAngleCtl::SetSpeed ( const int aIndex, double &aSpeed )
334 {
335 if ( !CanSetSpeed(aIndex) )
336 {
337 BOOL bValid;
338 if ( IsIndexValid(aIndex) )
339 aSpeed= GetSpeed(aIndex, bValid);
340 return FALSE;
341 }
342
343 mlSetValue(aIndex, Speed, aSpeed);
344 aSpeed= mlGetValue(aIndex, Speed);
345 m_MoveSpeed[aIndex]= aSpeed;
346 return TRUE;
347 }
348 //-----------------------------------------------------------------------------
349
350 BOOL TAngleCtl::SetAngleWidth ( const int aIndex, double &aAngleWidth )
351 {
352 if ( !CanSetAngleWidth(aIndex) )
353 {
354 BOOL bValid;
355 if ( IsIndexValid(aIndex) )
356 aAngleWidth= GetAngleWidth(aIndex, bValid);
357 return FALSE;
358 }
359
360 mlSetValue(aIndex, Width, aAngleWidth);
361 aAngleWidth= mlGetValue(aIndex, Width);
362 return TRUE;
363 }
364 //-----------------------------------------------------------------------------
365
366 BOOL TAngleCtl::SetCorrectionState ( const int aIndex )
367 {
368 if ( !IsIndexValid(aIndex) )
369 return FALSE;
370
371 mlSetCorrectionState(aIndex, TRUE);
372 return TRUE;
373 }
374
375 //*****************************************************************************
376 // Relative Null
377 //*****************************************************************************
378
379 BOOL TAngleCtl::SetRelativeZero ( const int aIndex )
380 {
381 if ( !CanSetOffset(aIndex) )
382 return FALSE;
383
384 BOOL bValid;
385 mlSetRelativeZero(aIndex, TRUE, GetAngle(aIndex, bValid)); // relative Null setzen
386 //FEHLER: zu jedem Push muss es ein POP geben mPushSettings(); // Motoreinstellungen sichern
387 return TRUE;
388 }
389 //-----------------------------------------------------------------------------
390
391 BOOL TAngleCtl::ResetRelativeZero ( const int aIndex )
392 {
393 if ( !CanResetRelativeZero(aIndex) )
394 return FALSE;
395
396 mlSetRelativeZero(aIndex, FALSE, 0.0); // relative Null aufheben
397 return TRUE;
398 }
399
400 //*****************************************************************************
401 // Halbwertsbreitenmessung
402 //*****************************************************************************
403
404 BOOL TAngleCtl::DoStartMeasure ( const HWND aWnd )
405 {
406 if ( !CanDoStartMeasure() )
407 return FALSE;
408
409 m_IsMeasuring= TRUE;
410 Steering.Reset();
411 Steering.StartUp(aWnd, 0, m_Sensor); // Fensterhandle zum Fenster, das die Bildschirmaktualisierung des Zählerfensters übernimmt; ausgewählten Detektor setzen; zweiter Paramater ("Beugung fein" wird vom Makro selbst ausgewählt) wird nicht benötigt
412 Steering.Visualising( TRUE, FALSE );
413 Steering.StartMacroExecution(Steering.GetMacroById(InquireHwb), aWnd); // Makro "Inquire Hwb" ausführen
414 return TRUE;
415 }
416 //-----------------------------------------------------------------------------
417
418 BOOL TAngleCtl::DoStopMeasure ( const int aIndex )
419 {
420 if ( !CanDoStopMeasure() )
421 {
422 DoSelectMotor(aIndex);
423 return FALSE;
424 }
425
426 m_IsMeasuring= FALSE;
427 Steering.Reset(); // Reset ist besser als ToggleInterrupt
428 return DoSelectMotor(aIndex);
429 }
430 //-----------------------------------------------------------------------------
431
432 BOOL TAngleCtl::IsMeasuring ( void ) const
433 {
434 return m_IsMeasuring;
435 }
436 //-----------------------------------------------------------------------------
437
438 BOOL TAngleCtl::IsMeasureReset ( void ) const
439 {
440 return Steering.IsReset();
441 }
442 //-----------------------------------------------------------------------------
443
444 double TAngleCtl::GetMeasureHwb ( void ) const
445 {
446 return Steering.GetHwb();
447 }
448 //-----------------------------------------------------------------------------
449
450 BOOL TAngleCtl::MeasureStopped ( const int aIndex )
451 {
452 if ( (!IsIndexValid(aIndex)) || (!m_IsMeasuring) )
453 return FALSE;
454
455 m_IsMeasuring= FALSE;
456 return DoSelectMotor(aIndex);
457 }
458 //-----------------------------------------------------------------------------
459
460 void TAngleCtl::UpdateDetector ( void ) const
461 {
462 m_Sensor->UpdateViews(TRUE);
463 Steering.DetectorRequest(); // wird diese Methode nicht gerufen, verharrt die Halbwertsbreitenmessung in einer Endlosschleife
464 }
465
466 //******************************************************************************
467 // Zustand für Bewegung ermitteln
468 //******************************************************************************
469
470 BOOL TAngleCtl::CanDoDirect ( const int aIndex ) const
471 {
472 BOOL bValid;
473 return ( (!IsMoving(aIndex, bValid)) && (bValid) && (!m_IsMeasuring) );
474 }
475 //-----------------------------------------------------------------------------
476
477 BOOL TAngleCtl::CanDoStep ( const int aIndex, const BOOL aUp ) const
478 {
479 BOOL bValid;
480 if ( (IsMoving(aIndex, bValid)) || (m_IsMeasuring) )
481 return FALSE;
482
483 //Ist die Zielposition des nächsten Schrittes im Intervall
484 if ( aUp )
485 return GetAngle(aIndex, bValid) + GetAngleWidth(aIndex, bValid) < GetAngleMax(aIndex, bValid);
486 else
487 return GetAngleMin(aIndex, bValid) < GetAngle(aIndex, bValid) - GetAngleWidth(aIndex, bValid);
488 }
489 //-----------------------------------------------------------------------------
490
491 BOOL TAngleCtl::CanDoDrive ( const int aIndex, const BOOL aUp ) const
492 {
493 BOOL bValid;
494 if ( (IsMoving(aIndex, bValid)) || (m_IsMeasuring) )
495 return FALSE;
496
497 //Zielposition bereits erreicht?
498 if ( aUp )
499 return ( GetAngle(aIndex, bValid) < GetAngleMax(aIndex, bValid) );
500 else
501 return ( GetAngleMin(aIndex, bValid) < GetAngle(aIndex, bValid) );
502 }
503 //-----------------------------------------------------------------------------
504
505 BOOL TAngleCtl::CanDoStop ( const int aIndex ) const
506 {
507 BOOL bValid;
508 return ( (IsMoving(aIndex, bValid)) && (!m_IsMeasuring) );
509 }
510
511 //*****************************************************************************
512 // Zustand zum Setzen von Parametern
513 //*****************************************************************************
514
515 BOOL TAngleCtl::CanSetSpeed ( const int aIndex ) const
516 {
517 BOOL bValid;
518 return ( (!IsMoving(aIndex, bValid)) && (bValid) && (!m_IsMeasuring) );
519 }
520 //-----------------------------------------------------------------------------
521 BOOL TAngleCtl::CanSetAngleWidth ( const int aIndex ) const
522 {
523 BOOL bValid;
524 return ( (!IsMoving(aIndex, bValid)) && (bValid) && (!m_IsMeasuring) );
525 }
526
527 //-----------------------------------------------------------------------------
528
529 BOOL TAngleCtl::CanSetOffset ( const int aIndex ) const
530 {
531 BOOL bValid;
532 return ( (!IsMoving(aIndex, bValid)) && (bValid) && (!m_IsMeasuring) );
533 }
534 //-----------------------------------------------------------------------------
535
536 BOOL TAngleCtl::CanResetRelativeZero ( const int aIndex ) const
537 {
538 BOOL bValid;
539 return ( (!IsMoving(aIndex, bValid)) && (bValid) && (!m_IsMeasuring) && (HasOffset(aIndex, bValid)) );
540 }
541 //-----------------------------------------------------------------------------
542
543 BOOL TAngleCtl::CanDoStartMeasure ( void ) const
544 {
545 BOOL bValid;
546 for (UINT cnt= 0; cnt < GetMotorCount(); cnt++)
547 if ( IsMoving(cnt, bValid) )
548 return FALSE; // alle Antriebe müssen still stehen
549 return ( (mlIsAxisValid(Omega)) && (Steering.GetMacroById(InquireHwb)) && (!m_IsMeasuring) );
550 }
551 //-----------------------------------------------------------------------------
552
553 BOOL TAngleCtl::CanDoStopMeasure ( void ) const
554 {
555 // es könnte sein, dass die Halbwertsbreitenmessung gerade einen Antrieb bewegt: dann trotzdem stoppen
556 return (m_IsMeasuring);
557 }
558
559 //*****************************************************************************
560 // private
561 //*****************************************************************************
562
563 BOOL TAngleCtl::DoSelectMotor ( const int aIndex ) const
564 {
565 if ( !IsIndexValid(aIndex) )
566 return FALSE;
567
568 mlSetAxis(aIndex);
569 return TRUE;
570 }
571 //-----------------------------------------------------------------------------
572
573 BOOL TAngleCtl::Moves( const int aIndex, BOOL &aValid ) const
574 {
575 aValid= FALSE;
576 if ( !IsIndexValid(aIndex) )
577 return FALSE;
578
579 aValid= TRUE;
580 if ( (!mlIsMoveFinish(aIndex)) || (IsMeasuring()) )
581 return TRUE;
582 return FALSE;
583 }
584
585