-
Notifications
You must be signed in to change notification settings - Fork 0
/
MoveSample.cpp
144 lines (114 loc) · 4.13 KB
/
MoveSample.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
// E816_DLL_CONSOLE_SAMPLE.cpp : Defines the entry point for the console application.
//
#ifdef WIN32
#include "stdafx.h"
#include "pzt.h"
#include "camera.h"
#include "conio.h" // for getch()
#include <Windows.h>
#else
#include <stdlib.h>
#include <stdio.h>
#endif
#define SINGLE_AXIS 1
#define INTERFACE_USB
int main(int argc, char* argv[])
{
// try to open communication
int ID = -1;
#ifdef INTERFACE_RS232
ID = OpenConnection(RS232)
#endif
#ifdef INTERFACE_SETUP_DLG
ID = OpenConnection(Dialog);
#endif
#ifdef INTERFACE_USB
ID = OpenConnection(USB);
#endif
if (ID < 0)
{
std::cout << "Unable to connect.";
return 1;
}
MyCamera camera;
if (!camera.OpenCamera())
{
throw std::runtime_error("Unable to Open Camera.");
};
try
{
PrintControllerIdentification(ID);
////////////////////////////////////////////////////////////////////////////////
char* sspa = "AAAAAAAAAA";
double spa[10];
int spacmd[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
int svo[2] = { 1, 1 };
char sSAI[1024];
if (!E816_qSAI(ID, sSAI, 1023)) ReportError(ID);
printf("SAI?: \"%s\"\n\n", sSAI);
printf("SPA TEST ");
if (!E816_qSPA(ID, sspa, spacmd, spa)) ReportError(ID);
printf("SPA for A:");
for (int i = 0; i < 10; i++)
printf(" %d:%f\n", i + 1, spa[i]);
////////////////////////////////////////////////////////////////////////////////
std::string sAxis = "A";
SetServoState(ID, sAxis, SERVO_ON);
double minPosLimit = GetMinPositionLimit(ID, sAxis);
double maxPosLimit = GetMaxPositionLimit(ID, sAxis);
double initial_pos = 0.0;
if (!E816_qPOS(ID, sAxis.c_str(), &initial_pos)) ReportError(ID);
printf("Pzt initial position%8.4f\n", initial_pos);
//double start_position = 35.2; // Initial Position
double start_position = 36.4; // 50-0.068*200 Change NO.1
if (!E816_MOV(ID, sAxis.c_str(), &start_position))
{
throw std::runtime_error("Unable to approach initial_position.");
}
WaitForMotionDone(ID, sAxis);
printf("Pzt move to start position%8.4f\n", start_position);
int range = 400;
double interval = 0.068; // White Light 60nm NO.1
double targetPos = start_position;
for (int i=0; i<range; i++)
{
//if (!(i%10)) printf(".");
targetPos = targetPos + interval;
if ((targetPos < minPosLimit) || (targetPos > maxPosLimit)){
throw std::runtime_error("Unable to approach minimum or Maximum position limit.");
}
if(! E816_MOV(ID, sAxis.c_str(), &targetPos))
{
throw std::runtime_error("Unable to approach tgt position.");
}
WaitForMotionDone(ID, sAxis);
//Sleep(10);
double pos=0.0;
for (int j=0; j<2; j++)
{
if (! E816_qPOS(ID, sAxis.c_str(), &pos) ) ReportError(ID);
printf("postion %d Current position of E-816: ", i);
printf("B = %8.4f\n", pos);
}
camera.getImage(i);
}
if (!E816_MOV(ID, sAxis.c_str(), &initial_pos))
throw std::runtime_error("Unable to approach tgt position.");
WaitForMotionDone(ID, sAxis);
double end_pos = 0.0;
if (!E816_qPOS(ID, sAxis.c_str(), &end_pos)) ReportError(ID);
printf("Pzt back to the initial position%8.4f\n", end_pos);
SetServoState(ID, sAxis, SERVO_OFF);
E816_CloseConnection(ID);
std::cout << "Closing Pzt connection." << std::endl;
camera.CloseCamera();
std::cout << "Closing Camera connection." << std::endl;
}
catch (std::runtime_error e)
{
CloseConnectionWithComment(ID, e.what());
camera.CloseCamera();
return 1;
}
return 0;
}