-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathZaber.h
More file actions
202 lines (174 loc) · 6.13 KB
/
Zaber.h
File metadata and controls
202 lines (174 loc) · 6.13 KB
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/* Zaber.h
* -------
* Header file for the Zaber class. This object controls the HAWK stage and
* z actuator. The header file also contains the Movement structure definition
* and function to determine the Movement necessary between two points,
* presumably the target and cantilever.
*
* Created by John Whitworth on 8/26/14.
* Copyright 2015 Eileen Mazzochette, et al <emazz86@stanford.edu>
*/
#pragma once
#pragma managed(push,off)
#include <cv.h>
#pragma managed(pop)
#define MICROSTEP 0
#define MICROMETER 1
#define MILLIMETER 2
#define CENTIMETER 3
/* Structure: Movement
* -------------------
* Made up of two doubles, each corresponding to a movement
* in one axis of the xy plane.
*/
struct Movement {
double x;
double y;
};
/* Class: Zaber
* ------------
* This object controls communication betwwen the HAWK and the Zaber
* controller. That includes movement in the x, y, and z directions.
*/
public ref class Zaber {
//properties
public:
//(#defines above) are possible values for this property
int moveUnit;
// holds the value for the home, hover, and scan positions of the acutator zaber.
double homePosition;
double hoverPosition;
double scanPosition;
private:
//port to communicate with Zaber Controller
System::IO::Ports::SerialPort ^port;
//device = 1 (x-axis), 2 (y-axis), 3 (z-axis)
System::Byte device;
//command to be sent to device (i.e. move absolute)
System::Byte command;
//data associated with the comment.
int data;
//placeholders for data in microsteps
unsigned int microstepsX;
unsigned int microstepsY;
unsigned int microstepsZ;
//prototypes
public:
/* Function: Zaber
* ---------------
* Constructor for a Zaber object. Sets up the port and initial moveUnit.
*/
Zaber();
/* Function: openPort
* ------------------
* If the port is not open, it is opened. Returns 0 if the port was opened,
* returns -1 if the port failed to open.
*/
int openPort(void);
/* Function: closePort
* -------------------
* If the port is not closed, it is closed. Returns 0 if the port was closed,
* returns -1 if the port failed to close.
*/
int closePort(void);
/* Function: waitForStaticStage
* ----------------------------
* A while loop keeps going until the stage is not moving
*/
void waitForStaticStage(void);
void waitForStaticActuator(void);
int requestZaberActuatorStatus(void);
/* Function: moveStage
* -------------------
* Takes a Movement as a parameter and directs the stage to move by that much.
*/
void moveStage(Movement move);
/* Function: moveActuator
* ----------------------
* Takes a double as a parameter and directs the z actuator to move by that much.
* Waits for the movement to complete.
*/
void moveActuator(double distance);
/* Function: moveActuatorToPosition
* --------------------------------
* Takes a double as a parameter and directs the z actuator to move to that
* location. Waits for the movement to complete.
*/
void moveActuatorToPosition(double position);
/* Function: moveActuatorHome
* --------------------------
* Directs the z actuator to move to position 0. This does not wait for the
* movement to complete.
*/
void moveActuatorHome(void);
/* Function: getStagePosition
* --------------------------
* Returns a CV Point_ of two doubles corresponding to the current stage
* position in microns.
*/
cv::Point2d getStagePosition(void);
/*Function: get ActuatorPosition
* --------------------------
* Returns the current position of the zaber holding the actuator
*/
double getActuatorPosition(void);
private:
/* Function: requestZaberStatus
* ----------------------------
* Calls for and returns the current status of the zaber stage.
*/
int requestZaberStatus(void);
/* Function: sendCommand
* ---------------------
* Transmits whatever command is in the Zaber properties to the
* Zaber controller.
*/
void sendCommand(void);
/* Function: sendCommand
* ---------------------
* Receives whatever command is being sent from the Zaber controller
* and stores its information in the properties.
*/
void receiveReply(void);
/* Function: waitForReply
* ----------------------
* Enters a while loop until a message is received regarding a certain
* device and command.
*/
void waitForReply(System::Byte expectDevice, System::Byte expectCommand);
/* Function: waitForReplyEitherDevice
* ----------------------------------
* Enters a while loop until a message is received regarding either of the
* specified device, command combinations.
*/
void waitForReplyEitherDevice(System::Byte expectDevice1, System::Byte expectCommand1, System::Byte expectDevice2, System::Byte expectCommand2);
/* Function: convertToStageMicrosteps
* ----------------------------------
* Returns the stage microstep value for the double parameter it takes,
* assumes that that parameter is in the current MoveUnit
*/
int convertToStageMicrosteps(double distanceInMoveUnit);
/* Function: convertFromStageMicrosteps
* ------------------------------------
* Returns the move unit value of the stage microstep value given in the parameter.
*/
double convertFromStageMicrosteps(int distanceInMicroSteps);
/* Function: convertToActuatorMicrosteps
* -------------------------------------
* Returns the z actuator microstep value for the double parameter it takes,
* assumes that that parameter is in the current MoveUnit
*/
int convertToActuatorMicrosteps(double distanceInMoveUnit);
/* Function: convertFromStageMicrosteps
* ------------------------------------
* Returns the move unit value of the z actuator microstep value given in
* the parameter.
*/
double convertFromActuatorMicrosteps(int distanceInMicroSteps);
};
/* Function: determineStageMovement
* --------------------------------
* Takes two opencv Points corresponding to the target and the cantilever and
* returns the Movement necessary between those points.
*/
Movement determineStageMovement(cv::Point target, cv::Point cantilever);