source: trunk/MagicSoft/AMC/activemirrorcontrol/activemirrorcontrol/defocusthread.cpp@ 3401

Last change on this file since 3401 was 3401, checked in by merck, 21 years ago
nitial checkin of AMC project
File size: 2.5 KB
Line 
1// DefocusThread.cpp: Implementierung der Klasse DefocusThread.
2//
3//////////////////////////////////////////////////////////////////////
4
5#include "defocusthread.h"
6#include "motorthreaddialog.h"
7#include "threadevent.h"
8#include "amcmirrorpanel.h"
9#include "amcmotor.h"
10#include "amcserialport.h"
11#include "amcerror.h"
12#include <qmessagebox.h>
13#include <qevent.h>
14#include <qthread.h>
15#include <qstring.h>
16#include <stdio.h>
17#include <stdlib.h>
18#include <math.h>
19
20#define MAX(a,b) ((a>b) ? a : b )
21
22extern AMCSerialPort* g_pPort[];
23
24//////////////////////////////////////////////////////////////////////
25// Konstruktion/Destruktion
26//////////////////////////////////////////////////////////////////////
27
28DefocusThread::DefocusThread( QObject* p_pReceiver )
29 : m_pPanel( NULL ), m_pReceiver( p_pReceiver )
30{
31}
32
33DefocusThread::~DefocusThread()
34{
35}
36
37void DefocusThread::run()
38{
39 QString qsMsg;
40 qsMsg.sprintf( "Panel (%d,%d) Port: %d, Box:%d, Driver:%d",
41 m_pPanel->i(), m_pPanel->j(), m_pPanel->port(), m_pPanel->box(), m_pPanel->driver() );
42 QThread::postEvent( m_pReceiver, new ThreadEvent( qsMsg ) );
43
44 QTime t;
45 t.start(); // start clock
46
47
48 // We use only one motor instance and reuse it for each panel
49 AMCSerialPort* pPort = g_pPort[ m_pPanel->port()-1 ];
50 AMCMotor* pMotor = new AMCMotor( pPort );
51
52 try
53 {
54 int x = m_pPanel->getRefX();
55 int y = m_pPanel->getRefY();
56 if( x >= 0 )
57 x -= 1500;
58 else
59 x += 1500;
60 if( y >= 0 )
61 y -= 1500;
62 else
63 y += 1500;
64 x -= m_pPanel->getX();
65 y -= m_pPanel->getY();
66
67 int steps = MAX( abs(x), abs(y) );
68 if( ! ((x == 0) && (y == 0)) ) // only move is necesary
69 {
70 pMotor->unselectBox();
71 pMotor->selectBox( m_pPanel->box() );
72 pMotor->selectDriver( m_pPanel->driver() );
73 pMotor->getFrequency();
74 pMotor->moveMotors(x,y);
75 pMotor->waitForMotors( pMotor->calcTimeout(steps) );
76 m_pPanel->setX( m_pPanel->getX() + x );
77 m_pPanel->setY( m_pPanel->getY() + y );
78 }
79 }
80 catch( AMCError& e )
81 {
82 qsMsg.sprintf( "AMCError: Panel (%d,%d) Port: %d, Box:%d, Driver:%d -- ",
83 m_pPanel->i(), m_pPanel->j(), m_pPanel->port(), m_pPanel->box(), m_pPanel->driver() );
84 qsMsg.append( e.getErrorText() );
85 QThread::postEvent( m_pReceiver, new ThreadErrorEvent( qsMsg, e ) );
86 pMotor->resetBox();
87
88 }
89 delete pMotor;
90
91 qsMsg.sprintf( "Time: %dms", t.elapsed() );
92 QThread::postEvent( m_pReceiver, new ThreadEvent( qsMsg ) );
93 QThread::postEvent( m_pReceiver, new QCustomEvent( PROGRESS_EVENT ) );
94
95}
96
97void DefocusThread::setPanel(AMCMirrorPanel* p_pPanel)
98{
99 m_pPanel = p_pPanel;
100}
Note: See TracBrowser for help on using the repository browser.