-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpiezo_PI_linux.cpp
100 lines (89 loc) · 2.6 KB
/
piezo_PI_linux.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
#pragma once
#include <cstdlib>
#include <iostream>
#include <string>
#include <PI_GCS2_DLL.h>
using namespace std;
class Stage{
public:
Stage(double step, double center, double start_point, const char* id = "/dev/ttyUSB0");
void piezo_initializer();
int move_onestep();
void exit();
private:
char* sz_buffer;
const char* sz_description;
const char* dev_id;
int controller_id=-1;
const char* axes_id="1";
const double* pdLowvoltageArray;
BOOL servo_mode=TRUE;
BOOL atz_flag=FALSE;
int connection_flag=-1;
int servo_flag=FALSE;
BOOL ont_flag=FALSE;
BOOL ont_state=FALSE;
double min_range;
double max_range;
double step_length;
double trace_center;
double start_point;
};
Stage::PI_Stage(double step, double center, double start_point, const char* id = "/dev/ttyUSB0"):dev_id (id), step_length (step), trace_center(center), start_point(start_point){}
void Stage::piezo_initializer(){
controller_id=PI_ConnectRS232ByDevName(dev_id, 115200);
connection_flag=PI_IsConnected(controller_id);
if (connection_flag){
cout<<"Connect Successfully!"<<endl;
}else{
cout<<"error_code: "<<connection_flag<<"->:Something is wrong when trying to connect!"<<endl;
}
servo_flag=PI_SVO(controller_id, axes_id, &servo_mode);
if (servo_flag){
cout<<"Stage is in Closed-Loop mode!"<<endl;
}else{
cout<<"Something is wrong when trying to set closed-loop!"<<endl;
}
atz_flag=PI_ATZ(controller_id, axes_id, pdLowvoltageArray, &servo_mode);
if (atz_flag){
cout<<"Auto zero Successfully!"<<endl;
}else{
cout<<"Something is wrong when trying to autozero!"<<endl;
}
//PI_qTMN(controller_id, axes_id, &min_range);
//PI_qTMX(controller_id, axes_id, &max_range);
PI_MOV(controller_id, axes_id, &start_point);
//if (!(ont_flag&&ont_state)){
while (!(ont_flag&&ont_state)){
ont_flag=PI_qONT(controller_id, axes_id, &ont_state);
}
if (ont_flag&&ont_state){
cout<<"Successfully initialize the stage!!!"<<endl;
return;
}
else{
cout<<"Fail to initialize the stage!!!"<<endl;
return;
}
}
int Stage::move_onestep(){
PI_MVR(controller_id, axes_id, &step_length);
ont_flag=PI_qONT(controller_id, axes_id, &ont_state);
// while (!(ont_flag&&ont_state)){
// ont_flag=PI_qONT(controller_id, axes_id, &ont_state);
// }
// if (ont_flag&&ont_state){
// return 0;
// }
// else{
// cout<<"error_code"<<(ont_flag&&ont_state)<<"Fail to move the stage!!!"<<endl;
// return -1;
// }
return 0;
}
void Stage::exit(){
PI_MOV(controller_id, axes_id, &trace_center);
PI_CloseConnection (controller_id);
return;
}
extern PI_Stage stage;