LAT Hologramm-Software 2.0
Loading...
Searching...
No Matches
Spitfire_Arduino.m
Go to the documentation of this file.
1%
2classdef Spitfire_Arduino < Laser
3
4 properties
5 %Arduino Properties
6 comPortArduino;
7 baudRateArduino = 9600;
8 ArduinoPort = 1;
9 ArduinoMessages;
10
11 %Shutter Properties
12 %true = open; Aktueller Zustand des Shutters
13 shutter = false;
14 %Winkel in DEG des Servomotors, bei dem der Shutter geöffnet ist
15 angleOpen = 20;%°
16 %Winkel in DEG des Servomotors, bei dem der Shutter geschlossen ist
17 angleClose = 120; %°
18
19 %Power Control Properties
20 comPortELL14;
21 ELL14Connected = false;
22 baudRateELL14 = 9600;
23 ELL14Port = 1;
24 ELL14Angle = 0;
25 ELL14Step = 1; %[°]
26 ELL14SafetyWarning = false;
27 ELL14SafetyWarningType = 'Warning Message';
28 end
29
30 methods
31 function obj = Spitfire_Arduino()
32 obj.wavelength = 800;
33 obj.rawBeamDiameter = 5.1;
34 obj.aperture = 1000;
35 end
37 function connect(obj)
38
39 obj.comPortArduino = serialport(strcat("COM", num2str(obj.ArduinoPort)), obj.baudRateArduino);
40 obj.connected = true;
41 %Warten, bis Arduino verbunden ist
42 pause(1);
43 %Setzen der Shutterwinkel
44 obj.setShutterOpenAngle();
45 pause(1);
46 obj.setShutterCloseAngle();
47 end
48
49 function disconnect(obj)
50 obj.comPortArduino = [];
51 obj.connected =false;
52 %#muss hier auch Verbindung zum ELL14 gelöscht werden?
53 end
54
55 function laserOn(obj)
56 obj.arduinoCommandQuick("LaserOpen");
57 obj.emission = true;
58 end
60 function laserOff(obj)
61 obj.arduinoCommandQuick("LaserClose");
62 obj.emission = false;
63 end
64
65 function shutterOpen(obj)
66 obj.arduinoCommandQuick("ShutterOpen");
67 obj.shutter = true;
68 end
69
70 function shutterClose(obj)
71 obj.arduinoCommandQuick("ShutterClose");
72 obj.shutter = false;
73 end
74
75 function setShutterOpenAngle(obj)
76 obj.arduinoCommand(strcat("ServoPositionOpen ",num2str(obj.angleOpen)));
77 end
78
79 function setShutterCloseAngle(obj)
80 obj.arduinoCommand(strcat("ServoPositionClose ",num2str(obj.angleClose)));
81 end
82
83 function laserTime(obj, time)
84 obj.arduinoCommand(strcat("LaserTime ",num2str(time*1000)));
85
86 end
87
88 %ARDUINO
89 function text = arduinoCommand(obj, command)
90 %Wartet Antwort des Arduinio ab und schreibt sie ins Protokoll
91 writeline(obj.comPortArduino,command);
92 message = strcat("send: ",command);
93 obj.ArduinoMessages = [message obj.ArduinoMessages];
94 response = "got: ";
95
96 i = 1;
97 while (response == "got: ")
98 value = readline(obj.comPortArduino);
99 response = strcat("got: ",value);
100 i = i+1;
101 if i>10000
102 msgbox("ERROR - no response from Arduino");
103 end
104 end
105 obj.ArduinoMessages = [strcat(datestr(now), response) obj.ArduinoMessages];
106 text = value;
107
108 %#prüfen, was wirklich zurückgegeben werden muss
109 end
110
111 function arduinoCommandQuick (obj, command)
112 writeline(obj.comPortArduino,command);
113
114 end
116 %Methoden ELL14
117 function PowerAdjustmentConnect(obj)
118 obj.comPortELL14 = serialport(strcat("COM", num2str(obj.ELL14Port)), obj.baudRateELL14);
119 obj.ELL14Connected = true;
120 end
121
122 function PowerAdjustmentDisconnect(obj)
123 obj.comPortELL14 = [];
124 obj.ELL14Connected = false;
125 end
126
127 function PowerAdjustmentRotate(obj)
128 hexstr = dec2hex(single(round(obj.ELL14Angle*398.2)));%398.2 ausgelesener Wert aus ELL-Software
129 while length(hexstr)<8
130 hexstr = ['0' hexstr];
131 end
132 code = strcat('0ma',hexstr);
133 writeline(obj.comPortELL14,code);
134 end
136 function PowerPlus(obj)
137 obj.ELL14Angle = obj.ELL14Angle + obj.ELL14Step;
138 obj.PowerAdjustmentRotate();
139 end
140
141 function PowerMinus(obj)
142 obj.ELL14Angle = obj.ELL14Angle - obj.ELL14Step;
143 obj.PowerAdjustmentRotate();
144 end
145
146 function value = powerAdjustmentWarning(obj)
147 if(obj.ELL14SafetyWarning)
148 if(obj.ELL14SafetyWarningType == "Warning Message")
149 %Dialog öffnen, ob Leistung verstellt werden soll
150 answer = questdlg('This will change the Power. Are you sure that the beam will not hit critical components?', ...
151 'Warning', ...
152 'Yes','No --> Cancel');
153 % Handle response
154 switch answer
155 case 'Yes'
156 value = true;
157 case 'No --> Cancel'
158 value = false;
159 end
160 elseif(obj.ELL14SafetyWarningType == "Only at Closed Shutter")
161 %Leistungsänderung nur erlauben, wenn Shutter
162 %geschlossen ist
163 if(obj.connected && obj.shutter == false)
164 value = true;
165 else
166 value = false;
167 end
168 elseif(obj.ELL14SafetyWarningType == "Only During Power Measurement")
169 %Leistungsänderung nur erlauben, wenn Leistung auf
170 %Powermeter angezeigt wird
171 if(Powermeter.getPower() > 0.002)
172 value = true;
173 else
174 value = false;
175 end
176 end
177
178 else
179 value = true;
180 end
181 end
182 end
183end
184
Definition: Laser.m:7
virtual getPower(in obj)
#define true
Definition: nuts_bolts.h:26
#define false
Definition: nuts_bolts.h:25