-
Notifications
You must be signed in to change notification settings - Fork 0
/
myStage.cpp
1063 lines (824 loc) · 35.3 KB
/
myStage.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
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// # include <iostream>
// # include <windows.h>
// # include <tuple>
// # include <list>
// # include <array>
// # include <vector>
// # include <string>
// # include <filesystem>
// # include <charconv>
#pragma warning(disable : 4996)
# include "myStage.h"
# include "pch.h"
//#include <Windows.h>
using namespace std;
// // Import Thorlabs dependencies
// #include "Thorlabs.MotionControl.IntegratedStepperMotors.h"
// // Import prior sceintific dependencies
// # include "Prior_stage/stdafx.h"
// # include "Prior_stage/PriorScientificSDK.h"
// // Import Marzhauser dependencies
// # include "Marzhauser_stage/Tango.h"
//myStage::myStage(void){}; // constructor
//CTango stageObject_M;
//myStage::stageObject_M = new CTango();
//My Data structures
struct myData {
char stage_name, msg, model, Dll_ver;
int SsesID, Port, err_code, n_stages,Thor_sel,step;
vector<char *> serialNos;
std::tuple<int, int, int> ports{2,8,7};
std::tuple<int, int, int> Dpos = {0,0,0}; // real units (mm, mm/s, mm/s2 or um for microstage)
std::tuple<double, double, double> Rpos = {0,0,0};
int Dvel,Daccn = 0;
double Rvel,Raccn = 0;
bool IsConn, IsBus = false;
string serial;
};
struct OutThor { // struct for collecting connected thorlabs stage serials
vector<char *> all_serialNos;
vector<char *> Desc;
short n;
};
void myStage::getThorStages(OutThor *Out_Thor){ // get serial numbers list for LTS devices that are connected
char desc[65];
if (TLI_BuildDeviceList() == 0){ // put this in a separate function
Out_Thor->n = TLI_GetDeviceListSize(); // get device list size
char serialNos[100];
TLI_GetDeviceListByTypeExt(serialNos,100,45); // get LTS serial numbers
// output list of matching devices
{
char* searchContext = nullptr;
char* p = strtok_s(serialNos, ",", &searchContext);
while (p != nullptr) {
TLI_DeviceInfo deviceInfo; // get device info from device
TLI_GetDeviceInfo(p, &deviceInfo);// get strings from device info structure
char desc[65];
strncpy_s(desc, deviceInfo.description, 64);
desc[64] = '\0';
char serialNo[9];
strncpy_s(serialNo, deviceInfo.serialNo, 8);
serialNo[8] = '\0';
// append
Out_Thor->all_serialNos.back() = serialNo;
Out_Thor->Desc.back() = desc;
// output
p = strtok_s(nullptr, ",", &searchContext);
}
}
}
}
string myStage::selectThor (vector<char *> serialNos, int Thor_sel){ // Selec which thor labs stage to connect to
string serial;
serial = *serialNos[Thor_sel];
return serial;
};
void myStage::getStage(myData *Data){ // set stage name
Data->n_stages = 1;
OutThor Out_Thor; // a struct containing serial numbers list for LTS devices that are connected
switch (Data->stage_name){
case 'Thor':
Data->Port = std::get<0>(Data->ports);
getThorStages(&Out_Thor);// check for stage info, serials, number, etc...
Data->serialNos = Out_Thor.all_serialNos;
Data->serial = selectThor(Data->serialNos, Data->Thor_sel);
Data->model = *Out_Thor.Desc[Data->Thor_sel];
Data->n_stages = Out_Thor.n;
Data->SsesID = 0;
Data->err_code = 0;
break;
case 'Prio':
Data->Port = std::get<1>(Data->ports);
// check
Data->err_code = PriorScientificSDK_Version(&Data->Dll_ver); // DLL version
int Inits = PriorScientificSDK_Initialise(); // initialize dll api, to configure internal data structures
Data->SsesID = PriorScientificSDK_OpenNewSession(); // creates session/instance of stage
char pr_serial[64];
Data->err_code = PriorScientificSDK_cmd(Data->SsesID, "controller.serialnumber.get", pr_serial);
Data->serial = pr_serial;
Data->err_code = PriorScientificSDK_cmd(Data->SsesID, "controller.model.get", &Data->model);
break;
case 'Marz':
Data->Port = std::get<2>(Data->ports);
try {
Data->SsesID = 1;
char mz_serial[64];
// get name, dll_version
stageObject_M->GetDLLVersionString(&Data->Dll_ver, 5); // get dll version string
stageObject_M->EnableCommandRetry(TRUE); // enables/disables repeated sending of commands in case of errors
stageObject_M->GetSerialNr(mz_serial, 512); // get stage serial number
stageObject_M->GetError(&Data->err_code); // retrives error code
//Data->model = 'Marzhauser_stage';
Data->serial = mz_serial;
}
catch (...) {
Data->SsesID = 0;
stageObject_M->GetError(&Data->err_code);// retrieves error code
Data->msg = sprintf(&Data->msg, "Could NOT connect to Stage, check documentaion for error code %d", Data->err_code);
};
break;
default:
Data->Port = NULL;
Data->n_stages = 0;
Data->SsesID = -1;
}
}
void myStage::connectStage(myData *Data){ // connects stage, returns serial, id, stage object, error, index
//stageObject_M = new CTango();
char buf[50];
switch (Data->stage_name){
case 'Thor':
char testSerialNo[16];
strcpy(testSerialNo, Data->serial.c_str());
try{
if(ISC_Open(testSerialNo) == 0){ // if we can open the specified stage
ISC_StartPolling(testSerialNo, 200); // start polling stage at 200 ms intervals
Sleep(2000); // wait 2 seconds for stage to connect
// reset stage to default
ISC_ResetStageToDefaults(testSerialNo);
// go home
goHome(Data);
}
//Data->msg = *testSerialNo+ ', '+Data->model+' is successfully connected';
Data->msg = sprintf(buf, "%s, %s is successfully connected", testSerialNo, Data->model);
}
catch(...){
//Data->msg = *testSerialNo+ ', '+Data->model+' Failed to connect';
Data->msg = sprintf(buf, "%s, Failed to connect'", testSerialNo);
}
break;
case 'Prio':
int correct = 1;
char res[64];
char my_cmd[64],my_cmd2[64];
sprintf(my_cmd,"controller.connect COM%d",Data->Port);
sprintf(my_cmd2,"controller.stage.correction.enabled.set %d", correct);
char testSerialNo[16];
strcpy(testSerialNo, Data->serial.c_str());
try{
Data->err_code = PriorScientificSDK_cmd(Data->SsesID, my_cmd, res); // Connect --> return error code should be "0"
PriorScientificSDK_cmd(Data->SsesID, "controller.stage.servo.xy.enabled.set 1", res); // enable servo
try {
PriorScientificSDK_cmd(Data->SsesID, "controller.stage.encoder.xy.enabled.set 0", res); // enable Encoder
}
catch (...) {
//Data->msg = 'Encoder disable NOT applicable';
Data->msg = sprintf(buf,"Encoder disable NOT applicable");
}
PriorScientificSDK_cmd(Data->SsesID, my_cmd2,res); // set stage correction on
//Data->msg = *testSerialNo+ ', '+Data->model+' is successfully connected';
Data->msg = sprintf(buf, "%s, %s is successfully connected", testSerialNo, Data->model);
// go home
goHome(Data);
}
catch(...){
//Data->msg = *testSerialNo+ ', '+Data->model+' Failed to connect';
Data->msg = sprintf(buf, "%s, Failed to connect'", testSerialNo);
}
break;
case 'Marz':
try{
char comPort;
char str[5];
comPort = 'COM'+ sprintf(str, "%d", Data->Port);
int interType = 1; // interface type is always 1 for RS232, PCI and USB
int baudRate = 57600;
stageObject_M->ConnectSimple(interType, &comPort, baudRate, TRUE); // Connect to Tango
// calibrate stage
int xflag, yflag;
xflag = 0;
yflag = 1;
stageObject_M->CalibrateEx(xflag); // calibrate x axis
stageObject_M->CalibrateEx(yflag); // calibrate y axis
// set stage units to um
int x_units, y_units, z_units = 1;
stageObject_M->SetDimensions(x_units, y_units, z_units,1);
stageObject_M->SetTVROutResolution(5,5,4,3); // set resolution to 10nm in X and Y, 0.1um in z and 1um in r axis
// enable limit switch
stageObject_M->SetSwitchActive(7,7,7,0);
// go home
goHome(Data);
// enable joystick and handwheel
enableJoystick(Data,1);
// Data->msg = Data->model+' is successfully connected';
Data->msg = sprintf(buf, "%s, %s is successfully connected", testSerialNo, Data->model);
}
catch(...){
Data->msg = sprintf(buf, "%s, Failed to connect'", testSerialNo);
}
break;
default:
break;
}
// return {msg, err_code};
};
void myStage::goHome(myData *Data){ // move stage home
char buf[50];
switch(Data->stage_name){
case 'Thor':
char testSerialNo[16];
strcpy(testSerialNo, Data->serial.c_str());
ISC_ClearMessageQueue(testSerialNo);
ISC_Home(testSerialNo);
// wait for completion
WORD messageType;
WORD messageId;
DWORD messageData;
ISC_WaitForMessage(testSerialNo, &messageType, &messageId, &messageData);
while(messageType != 2 || messageId != 0)
{
ISC_WaitForMessage(testSerialNo, &messageType, &messageId, &messageData);
}
Data->err_code = 0;
//Data->msg = *testSerialNo+' Homed succefully';
Data->msg = sprintf(buf, "%s, Homed succefully", testSerialNo);
break;
case 'Prio':
char res[64];
// PriorScientificSDK_cmd(SsesID, "controller.stage.fitted.get", res);
Data->err_code = PriorScientificSDK_cmd(Data->SsesID, "controller.shuttle.goto-home", res);
// err_code = 0;
if (Data->err_code == 0){
//Data->msg = 'Prior stage homed succefully';
Data->msg = sprintf(buf, "Prior stage Homed succefully");
}
break;
case 'Marz':
// calibrate stage move stage to [0,0] position
int xflag, yflag;
xflag = 0;
yflag = 1;
stageObject_M->CalibrateEx(xflag); // calibrate x axis
stageObject_M->CalibrateEx(yflag); // calibrate y axis
Data->err_code = 0;
//Data->msg = 'Marz stage homed succefully';
Data->msg = sprintf(buf, "Marzhauser stage Homed succefully");
break;
}
// return {msg,err_code};
};
void myStage::getAllParams(myData *Data){ // get all parameters (step, position, velocity, acceleration)
switch(Data->stage_name){
case 'Thor':
char testSerialNo[16];
strcpy(testSerialNo, Data->serial.c_str());
int vel_d, acc_d, pos_d;
double vel_r, acc_r,pos_r;
ISC_ClearMessageQueue(testSerialNo);
//get velocity and acceleration
ISC_GetVelParams(testSerialNo,&vel_d,&acc_d); // both in device units
//get position
pos_d = ISC_GetPosition(testSerialNo); // in device unit
// convert from device units to real units
ISC_GetRealValueFromDeviceUnit(testSerialNo,pos_d,&pos_r,0);
ISC_GetRealValueFromDeviceUnit(testSerialNo,vel_d,&vel_r,1);
ISC_GetRealValueFromDeviceUnit(testSerialNo,acc_d,&acc_r,2);
//
Data->Dpos = {pos_d,NULL,NULL};
Data->Dvel = vel_d;
Data->Daccn = acc_d;
Data->Rpos = {pos_r,NULL,NULL};
Data->Rvel = vel_r;
Data->Raccn = acc_r;
Data->err_code = 0;
Data->msg = 'Done';
break;
case 'Prio':
// get current position (x,y in um)
char pos[64];
Data->err_code = PriorScientificSDK_cmd(Data->SsesID, "controller.stage.position.get", pos); // return error code should be "0"
// find x, y values assign them to res variables
char* chars_array = strtok(pos, ",");
int i = 1;
while (chars_array != NULL) {
chars_array = strtok (NULL, ",");
if (i == 1) {std::get<0>(Data->Rpos) = atoi(chars_array);}
else if (i == 2) {std::get<1>(Data->Rpos) = atoi(chars_array);}
i++;
}
// get current velocity (in um/s)
char vel[64];
Data->err_code = PriorScientificSDK_cmd(Data->SsesID, "controller.stage.speed.get", vel);
Data->Rvel = atoi(vel);
// get current acceleration
char acc[64];
Data->err_code = PriorScientificSDK_cmd(Data->SsesID, "controller.stage.acc.get", acc);
Data->Raccn = atoi(acc);
// device units
Data->Dpos = {static_cast<int>(std::get<0>(Data->Rpos)),static_cast<int>(std::get<1>(Data->Rpos)),static_cast<int>(std::get<2>(Data->Rpos))};
Data->Dvel = static_cast<int>(Data->Rvel);
Data->Daccn = static_cast<int>(Data->Raccn);
Data->msg = 'Done';
break;
case 'Marz':
double posX,posY,posZ, posA;
double velX,velY,velZ, velA;
double accX,accY,accZ, accA;
// get velocity and acceleration
stageObject_M->GetVel(&velX,&velY,&velZ,&velA);
stageObject_M->GetAccel(&accX,&accY,&accZ,&accA);
// get position in x, y and z coordinates
stageObject_M->GetPos(&posX,&posY,&posZ,&posA);
Data->Rpos = {posX,posY,posZ};
Data->Dpos = {static_cast<int>(posX),static_cast<int>(posY),static_cast<int>(posZ)};
Data->Raccn = accX; // only one velocity and acceleration are returned
Data->Rvel = velX;
Data->Daccn = static_cast<int>(Data->Raccn);
Data->Dvel = static_cast<int>(Data->Rvel);
Data->err_code = 0;
Data->msg = 'Done';
break;
};
};
void myStage::disconnectStage(myData *Data){ // disconnect stage
char buf[50];
switch(Data->stage_name){
case 'Thor':
char testSerialNo[16];
strcpy(testSerialNo, Data->serial.c_str());
ISC_ClearMessageQueue(testSerialNo);
ISC_StopImmediate(testSerialNo);//stop motion
ISC_StopPolling(testSerialNo);// stop stage polling
ISC_Close(testSerialNo); // close stage object
Data->err_code = 0;
//Data->msg = *testSerialNo;+' Disconnected Successfully';
Data->msg = sprintf(buf, "%s, Disconnected Successfully", testSerialNo);
break;
case 'Prio':
char res[64];
// stop all motion smoothly
myStage::stopMotion(Data);
//turn off servo and encoder
PriorScientificSDK_cmd(Data->SsesID, "controller.stage.servo.xy.enabled.set 0", res);
try {
PriorScientificSDK_cmd(Data->SsesID, "controller.stage.encoder.xy.enabled.set 0", res);
}
catch (...) {
//Data->msg = 'Encoder disable NOT applicable';
Data->msg = sprintf(buf, "Encoder disable NOT applicable");
}
// enable joystick
enableJoystick(Data, 1);
// disconnect controller
Data->err_code = PriorScientificSDK_cmd(Data->SsesID, "controller.disconnect", res);
Data->err_code = PriorScientificSDK_CloseSession(Data->SsesID);
//Data->msg = 'Prior stage Disconnected Successfully';
Data->msg = sprintf(buf, "Prior stage Disconnected Successfully");
break;
case 'Marz':
// stop all motion
stageObject_M->StopAxes();
// enable joystic and handwheel
enableJoystick(Data, 1);
// disconect stage and tango from dll
stageObject_M->Disconnect();
// Free LSID
// no need
Data->err_code = 0;
//Data->msg = 'Marzhauser stage Disconnected Successfully';
Data->msg = sprintf(buf, "Marzhauser stage Disconnected Successfully");
break;
}
}
void myStage::stopMotion(myData *Data){ // suspend all stage movements
char buf[50];
switch(Data->stage_name){
case 'Thor':
char testSerialNo[16];
strcpy(testSerialNo, Data->serial.c_str());
ISC_ClearMessageQueue(testSerialNo);
ISC_StopImmediate(testSerialNo);//stop motion
Data->err_code = 0;
//Data->msg = 'Stage stopped';
Data->msg = sprintf(buf, "Stage Stopped Successfully");
break;
case 'Prio':
char res[64];
// stop all motion smoothly
Data->err_code = PriorScientificSDK_cmd(Data->SsesID, "controller.stop.smoothly", res);
//Data->msg = 'Stage stopped';
Data->msg = sprintf(buf, "Stage Stopped Successfully");
break;
case 'Marz':
stageObject_M->StopAxes();
Data->err_code = 0;
//Data->msg = 'Stage stopped';
Data->msg = sprintf(buf, "Stage Stopped Successfully");
break;
}
};
void myStage::setAllParams(myData *Data){ // set all parameters (step, position, velocity, acceleration)
switch(Data->stage_name){
case 'Thor':
int vel_d, acc_d, pos_d;
double vel_r, acc_r, pos_r;
char testSerialNo[16];
strcpy(testSerialNo, Data->serial.c_str());
vel_r = Data->Rvel;
acc_r = Data->Raccn;
pos_r = std::get<0>(Data->Rpos);
// convert real units to device units
ISC_GetDeviceUnitFromRealValue(testSerialNo,vel_r,&vel_d,1); // velocity
ISC_GetDeviceUnitFromRealValue(testSerialNo,acc_r,&acc_d,2); // acceleration
ISC_GetDeviceUnitFromRealValue(testSerialNo,pos_r,&pos_d,0); // position
// set acceleration and velocity
ISC_ClearMessageQueue(testSerialNo);
ISC_SetVelParams(testSerialNo, acc_d, vel_d);
// set new position
ISC_MoveToPosition(testSerialNo, pos_d);
Data->Dpos = {pos_d,NULL,NULL};
Data->Dvel = vel_d;
Data->Daccn = acc_d;
Data->Rpos = {pos_r,NULL,NULL};
Data->Rvel = vel_r;
Data->Raccn = acc_r;
Data->err_code = 0;
Data->msg = 'Done';
break;
case 'Prio':
char res[64];
char my_cmd1[64], my_cmd2[64], my_cmd3[64];
sprintf(my_cmd1,"controller.stage.acc.set %d",Data->Raccn);
sprintf(my_cmd2,"controller.stage.speed.set %d",Data->Rvel);
sprintf(my_cmd3,"controller.stage.goto-position %d %d",std::get<0>(Data->Rpos),std::get<1>(Data->Rpos));
Data->err_code = PriorScientificSDK_cmd(Data->SsesID, my_cmd1, res);
Data->err_code = PriorScientificSDK_cmd(Data->SsesID, my_cmd2, res);
Data->err_code = PriorScientificSDK_cmd(Data->SsesID, my_cmd3, res);
Data->Dpos = Data->Rpos;
Data->Dvel = Data->Rvel;
Data->Daccn = Data->Raccn;
Data->msg = 'Done';
break;
case 'Marz':
double vel = Data->Rvel;
double acc = Data->Raccn;
double posX, posY,posZ,posA;
posX = std::get<0>(Data->Rpos);
posY = std::get<1>(Data->Rpos);
posZ = std::get<2>(Data->Rpos);
posA = 0;
enableJoystick(Data,0);
// set velocity and acceleration
stageObject_M->SetVel(vel,vel,vel,0);
stageObject_M->SetAccel(acc,acc,acc,0);
// move to absolute position
stageObject_M->SetPos(posX,posY,posZ,posA);
// assignments
Data->Rpos = {posX,posY,posZ};
Data->Dpos = {static_cast<int>(posX),static_cast<int>(posY),static_cast<int>(posZ)};
Data->Raccn = acc; // only one velocity and acceleration are returned
Data->Rvel = vel;
Data->Daccn = static_cast<int>(Data->Raccn);
Data->Dvel = static_cast<int>(Data->Rvel);
enableJoystick(Data,1);
Data->err_code = 0;
Data->msg = 'Done';
break;
}
}
void myStage::getStep(myData *Data){ // get stage step size
char buf[50];
switch(Data->stage_name){
case 'Thor':
char testSerialNo[16];
strcpy(testSerialNo, Data->serial.c_str());
int step_d;
double step_r;
ISC_ClearMessageQueue(testSerialNo);
step_d = ISC_GetJogStepSize(testSerialNo);
ISC_GetRealValueFromDeviceUnit(testSerialNo,step_d,&step_r,0);
Data->step = step_r;
Data->err_code = 0;
Data->msg = 'Done';
break;
case 'Prio':
char res[64];
// get step size
Data->err_code = PriorScientificSDK_cmd(Data->SsesID, "controller.stage.ss.get", res);
Data->step = atoi(res); // OR // sscanf(res,"%d",&Data->step);
sprintf(&Data->msg,"Step size = %d",Data->step);
break;
case 'Marz':
double step_x, step_y, step_z, step_a;
stageObject_M->GetControllerSteps(&step_x, &step_y, &step_z,&step_a);
Data->step = step_x;
Data->err_code = 0;
Data->msg = 'Done';
break;
}
};
void myStage::setStep(myData *Data){ // set stage step size
switch(Data->stage_name){
case 'Thor' :
char testSerialNo[16];
strcpy(testSerialNo, Data->serial.c_str());
int step_d;
double step_r;
step_r = Data->step;
ISC_GetDeviceUnitFromRealValue(testSerialNo,step_r,&step_d,0);
ISC_ClearMessageQueue(testSerialNo);
ISC_SetJogStepSize(testSerialNo,step_d);
Data->err_code = 0;
Data->msg = 'Done';
break;
case 'Prio' :
char res[64];
char my_cmd[64];
sprintf(my_cmd,"controller.connect %d",Data->step);
Data->err_code = PriorScientificSDK_cmd(Data->SsesID, my_cmd, res);
Data->msg = 'Done';
break;
case 'Marz' :
double stepp;
stepp = Data->step;
stageObject_M->SetControllerSteps(stepp, stepp, stepp,0);
Data->step = stepp;
Data->err_code = 0;
Data->msg = 'Done';
break;
}
};
void myStage::getVelParams(myData *Data){ // get velocity parameters (vel and acc)
switch(Data->stage_name){
case 'Thor':
char testSerialNo[16];
strcpy(testSerialNo, Data->serial.c_str());
int vel_d, acc_d;
double vel_r, acc_r;
ISC_ClearMessageQueue(testSerialNo);
//get velocity and acceleration
ISC_GetVelParams(testSerialNo,&vel_d,&acc_d); // both in device units
// convert from device units to real units
ISC_GetRealValueFromDeviceUnit(testSerialNo,vel_d,&vel_r,1);
ISC_GetRealValueFromDeviceUnit(testSerialNo,acc_d,&acc_r,2);
Data->Dvel = vel_d;
Data->Daccn = acc_d;
Data->Rvel = vel_r;
Data->Raccn = acc_r;
Data->err_code = 0;
Data->msg = 'Done';
break;
case 'Prio':
// get current velocity (in um/s)
char vel[64];
Data->err_code = PriorScientificSDK_cmd(Data->SsesID, "controller.stage.speed.get", vel);
Data->Rvel = atoi(vel);
// get current acceleration
char acc[64];
Data->err_code = PriorScientificSDK_cmd(Data->SsesID, "controller.stage.acc.get", acc);
Data->Raccn = atoi(acc);
Data->Dvel = Data->Rvel;
Data->Daccn = Data->Raccn;
Data->msg = 'Done';
break;
case 'Marz':
double velX,velY,velZ, velA;
double accX,accY,accZ, accA;
// get velocity and acceleration
stageObject_M->GetVel(&velX,&velY,&velZ,&velA);
stageObject_M->GetAccel(&accX,&accY,&accZ,&accA);
Data->Raccn = accX; // only one velocity and acceleration are returned
Data->Rvel = velX;
Data->Daccn = static_cast<int>(Data->Raccn);
Data->Dvel = static_cast<int>(Data->Rvel);
Data->err_code = 0;
Data->msg = 'Done';
break;
}
};
void myStage::setVelParams(myData *Data){ // get velocity parameters
switch(Data->stage_name){
case 'Thor':
int vel_d, acc_d;
double vel_r, acc_r;
char testSerialNo[16];
strcpy(testSerialNo, Data->serial.c_str());
vel_r = Data->Rvel;
acc_r = Data->Raccn;
// convert real units to device units
ISC_GetDeviceUnitFromRealValue(testSerialNo,vel_r,&vel_d,1); // velocity
ISC_GetDeviceUnitFromRealValue(testSerialNo,acc_r,&acc_d,2); // acceleration
// set acceleration and velocity
ISC_ClearMessageQueue(testSerialNo);
ISC_SetVelParams(testSerialNo, acc_d, vel_d);
Data->Dvel = vel_d;
Data->Daccn = acc_d;
Data->Rvel = vel_r;
Data->Raccn = acc_r;
Data->err_code = 0;
Data->msg = 'Done';
break;
case 'Prio':
char res[64];
char my_cmd1[64], my_cmd2[64];
sprintf(my_cmd1,"controller.stage.acc.set %d",Data->Raccn);
sprintf(my_cmd2,"controller.stage.speed.set %d",Data->Rvel);
Data->err_code = PriorScientificSDK_cmd(Data->SsesID, my_cmd1, res);
Data->err_code = PriorScientificSDK_cmd(Data->SsesID, my_cmd2, res);
Data->Dvel = Data->Rvel;
Data->Daccn = Data->Raccn;
Data->msg = 'Done';
break;
case 'Marz':
double vel,acc;
vel = Data->Rvel;
acc = Data->Raccn;
// set velocity and acceleration
stageObject_M->SetVel(vel,vel,vel,0);
stageObject_M->SetAccel(acc,acc,acc,0);
// assignments
Data->Rvel = vel;
Data->Raccn = acc;
Data->Daccn = static_cast<int>(Data->Raccn);
Data->Dvel = static_cast<int>(Data->Rvel);
Data->err_code = 0;
Data->msg = 'Done';
break;
}
};
void myStage::moveAbs(myData *Data){ // move stage to Absolute position
switch(Data->stage_name){
case 'Thor':
char testSerialNo[16];
strcpy(testSerialNo, Data->serial.c_str());
int pos_d;
double pos_r;
pos_r = std::get<0>(Data->Rpos);
// convert real to device units
ISC_GetDeviceUnitFromRealValue(testSerialNo,pos_r,&pos_d,0);
ISC_ClearMessageQueue(testSerialNo);
// move ABS to
ISC_MoveToPosition(testSerialNo,pos_d);
Data->Rpos = {pos_r,NULL,NULL};
Data->Dpos = {pos_d,NULL,NULL};
Data->err_code = 0;
Data->msg = 'Done';
break;
case 'Prio':
char res[64];
char my_cmd1[64];
sprintf(my_cmd1,"controller.stage.goto-position %d %d",std::get<0>(Data->Rpos),std::get<1>(Data->Rpos));
Data->err_code = PriorScientificSDK_cmd(Data->SsesID, my_cmd1, res);
Data->Dpos = Data->Rpos;
Data->msg = 'Done';
break;
case 'Marz':
double posX, posY,posZ,posA;
posX = std::get<0>(Data->Rpos);
posY = std::get<1>(Data->Rpos);
posZ = std::get<2>(Data->Rpos);
posA = 0;
enableJoystick(Data,0);
// move to absolute position
stageObject_M->MoveAbs(posX,posY,posZ,posA,true);
// assignments
Data->Rpos = {posX,posY,posZ};
Data->Dpos = {static_cast<int>(posX),static_cast<int>(posY),static_cast<int>(posZ)};
enableJoystick(Data,1);
Data->err_code = 0;
Data->msg = 'Done';
break;
}
};
void myStage::getPos(myData *Data){ // get current stage position
switch(Data->stage_name){
case 'Thor':
char testSerialNo[16];
strcpy(testSerialNo, Data->serial.c_str());
int pos_d;
double pos_r;
ISC_ClearMessageQueue(testSerialNo);
pos_d = ISC_GetPosition(testSerialNo);
ISC_GetRealValueFromDeviceUnit(testSerialNo,pos_d,&pos_r,0);
Data->Rpos = {pos_r,NULL,NULL};
Data->Dpos = {pos_d,NULL,NULL};
Data->err_code = 0;
Data->msg = 'Done';
break;
case 'Prio':
// get current position (x,y in um)
char pos[64];
Data->err_code = PriorScientificSDK_cmd(Data->SsesID, "controller.stage.position.get", pos); // return error code should be "0"
// find x, y values assign them to res variables
char* chars_array = strtok(pos, ",");
int i = 1;
while (chars_array != NULL) {
chars_array = strtok (NULL, ",");
if (i == 1) {std::get<0>(Data->Rpos) = atoi(chars_array);}
else if (i == 2) {std::get<1>(Data->Rpos) = atoi(chars_array);}
i++;
}
Data->Dpos = Data->Rpos;
Data->msg = 'Done';
break;
case 'Marz':
double posX, posY,posZ,posA;
// move to absolute position
stageObject_M->GetPos(&posX,&posY,&posZ,&posA);
// assignments
Data->Rpos = {posX,posY,posZ};
Data->Dpos = {static_cast<int>(posX),static_cast<int>(posY),static_cast<int>(posZ)};
Data->err_code = 0;
Data->msg = 'Done';
break;
}
};
void myStage::isBusy(myData *Data){ // is stage moving
switch(Data->stage_name){
case 'Thor':
char testSerialNo[16];
strcpy(testSerialNo, Data->serial.c_str());
WORD messageType;
WORD messageId;
DWORD messageData;
Data->IsBus = false;
ISC_WaitForMessage(testSerialNo, &messageType, &messageId, &messageData);
if(messageType != 2 || messageId != 0)
{
Data->IsBus = true;
}
Data->err_code = 0;
Data->msg = 'Done';
break;
case 'Prio':
char buzi[64];
Data->err_code = PriorScientificSDK_cmd(Data->SsesID, "controller.stage.busy.get", buzi);
int choice = atoi(buzi);
if (choice==0){
Data->IsBus = false;
}
else {
Data->IsBus = true;
};
Data->msg = 'Done';
break;
case 'Marz':
char status;
string str_status;
stageObject_M->GetStatusAxis(&status,16);
str_status = status;
if (str_status.find('@')){
Data->IsBus = false;
}
else{
Data->IsBus = true;
}
Data->err_code = 0;
Data->msg = status;
break;
}
};
void myStage::getLastError(myData *Data){ // get last error
switch(Data->stage_name){
case 'Thor':