This repository has been archived by the owner on Aug 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gui.m
203 lines (177 loc) · 9.14 KB
/
gui.m
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
%% GUI Erstellen
function gui
close all
warning('off', 'all');
%% GUI
% Erstellung des Hauptfensters
handle.fig = figure(...
'Units', 'pixel',...
'Position', [1100 600 500 400],...
'Position', [1200 1600 500 400],... % zweiter Bildschirm (oben)
'Name', 'Delta Plotter',...
'MenuBar', 'none',...
'ToolBar', 'none');
% Kontrollelemente
handle.axes = axes('Units', 'pixel',...
'XTick', [],...
'YTick', [],...
'Position', [30 30 355 260],...
'Parent', handle.fig);
handle.popup_group = uicontrol('Style','popup','Callback',@popup_group_callback,'String','Ordner auswählen','Position',[30 350 180 20],'Units','pixel','Parent',handle.fig);
handle.popup_group.String = {'111564-university', '182316-education', '327741-future-technology', '333190-valentines-day'};
handle.popup_pic = uicontrol('Style','popup','Callback',@popup_pic_callback,'String','Grafik auswählen','Position',[30 320 180 20],'Units','pixel','Parent',handle.fig);
uicontrol('String','Stift unten Position: ','Style','text','Units','pixel','Parent',handle.fig,'Position',[230 355 125 15]);
handle.pendown = uicontrol('Style', 'slider','Min',-280,'Max',-170,'SliderStep',[1/110,5/110],'Units','pixel','Position', [230 335 125 20],'Callback',@pendown_callback);
handle.pendown_text = uicontrol('String',0,'Style','text','Units','pixel','Parent',handle.fig,'Position',[230 320 125 15]);
handle.btn = uicontrol('Style','pushbutton','Units','pixel','Position',[395 350 100 20],'Parent',handle.fig,'Callback',@start_callback,'String','Start');
handle.btn_nikolaus = uicontrol('Style','pushbutton','Units','pixel','Position',[395 320 100 20],'Parent',handle.fig,'Callback',@btn_nikolaus_callback,'String','Nikolaus');
handle.btn_nullpunkt = uicontrol('Style','pushbutton','Units','pixel','Position',[395 30 100 20],'Parent',handle.fig,'Callback',@btn_nullpunkt_callback,'String','Nullpunkt');
handle.btn_batterie = uicontrol('Style','pushbutton','Units','pixel','Position',[395 80 100 20],'Parent',handle.fig,'Callback',@btn_batterie_callback,'String','Batteriespannung');
handle.batterie_text = uicontrol('String',0,'Style','text','Units','pixel','Parent',handle.fig,'Position',[395 65 100 15]);
% handle.status = uicontrol('String','0','Style','text','Position',[115 130 30 15],'Units','pixel','Parent',handle.fig);
% voltage = NXT_GetBatteryLevel();
%% NXT
% Verbindung zum NXT
COM_CloseNXT('all');
disp('Verbinde zu NXT...');
NXT = COM_OpenNXTEx('Any', '0016531B83BC', 'bluetooth.ini');
COM_SetDefaultNXT(NXT);
disp('...Verbindung hergestellt');
%% Maschinenparameter
handle.machine = struct();
handle.machine.E0 = struct('x', 0, 'y', 0, 'z', 0); % Effektor Position
handle.machine.theta = struct('a', 0, 'b', 0, 'c', 0); % Motorwinkel
handle.machine.f = 500; % Kantenlänge Motorplattform in mm
handle.machine.e = 140; % Kantenlänge Effektor in mm
handle.machine.rf = 136; % Oberarmlänge in mm
handle.machine.re = 264; % Unterarmlänge in mm
handle.machine.fr = handle.machine.f/2*tan(pi*1/6); % Motorplattform Radius in mm
handle.machine.er = handle.machine.e/2*tan(pi*1/6); % Effektor Radius in mm
handle.machine.Position = struct('x', 0, 'y', 0, 'z', 0);
handle.machine.gearRatio = 5; % Getriebe Übersetzung
handle.machine.Power = 35;
handle.machine.zhome = -110;
handle.machine.penup = -230;
handle.machine.pendown = handle.machine.penup-20;
handle.machine.maxauslenkung = 50;
%% Motoren
% Motor A
handle.machine.motorA = NXTMotor(MOTOR_A);
handle.machine.motorA.SmoothStart = false;
handle.machine.motorA.SpeedRegulation = false;
handle.machine.motorA.ActionAtTachoLimit = 'Brake';
% Motor B
handle.machine.motorB = handle.machine.motorA;
handle.machine.motorB.Port = MOTOR_B;
% Motor C
handle.machine.motorC = handle.machine.motorA;
handle.machine.motorC.Port = MOTOR_C;
handle.pendown_text.String = handle.machine.pendown;
handle.pendown.Value = handle.machine.pendown;
%% Sichern des Handles
guidata(handle.fig, handle);
%% Init Funktionen
popup_group_callback(handle.popup_group, 'init');
handle.popup_pic.Value = 16;
popup_pic_callback(handle.popup_pic, 'init');
btn_batterie_callback(handle.btn_batterie, 'init');
end
%% Popup Group Callback
function popup_group_callback(hObject, event)
handle = guidata(hObject);
group = handle.popup_group.String(handle.popup_group.Value);
group = group{1};
pics = dir(['svg/',group,'/svg/*.svg']);
handle.popup_pic.String = '';
handle.popup_pic.Value = 1;
pn = string();
for i=1:numel(pics)
pn(i) = pics(i).name;
end
handle.popup_pic.String = cellstr(pn);
popup_pic_callback(handle.popup_pic, 'init');
end
%% Popup Pic Callback
function popup_pic_callback(hObject, event)
handle = guidata(hObject);
group = string(handle.popup_group.String(handle.popup_group.Value));
pic = string(handle.popup_pic.String(handle.popup_pic.Value));
pic = char(strcat('svg/', group, '/png/', strrep(pic, 'svg', 'png')));
axes(handle.axes);
[img, map, transparency] = imread(pic, 'png', 'BackgroundColor', {1,0,0});
imshow(abs(1./img));
end
%% Button Start Callback
function start_callback(hObject, event)
handle = guidata(hObject);
group = string(handle.popup_group.String(handle.popup_group.Value));
pic = string(handle.popup_pic.String(handle.popup_pic.Value));
pic = char(strcat('svg/', group, '/svg/', pic));
svg = readsvg(pic);
handle.axes.XTick = [];
handle.axes.YTick = [];
drawnow;
% svg.maxX * ((handle.machine.maxauslenkung*2)/(svg.maxX-svg.minX)) - handle.machine.maxauslenkung
% svg.minX * ((handle.machine.maxauslenkung*2)/(svg.maxX-svg.minX)) - handle.machine.maxauslenkung
% svg.maxY * ((handle.machine.maxauslenkung*2)/(svg.maxY-svg.minY)) - handle.machine.maxauslenkung
% svg.minY * ((handle.machine.maxauslenkung*2)/(svg.maxY-svg.minY)) - handle.machine.maxauslenkung
scaleX = ((handle.machine.maxauslenkung*2)/(svg.maxX-svg.minX));
scaleY = ((handle.machine.maxauslenkung*2)/(svg.maxY-svg.minY));
for i=1:numel(svg.path)
move(handle.machine, ...
svg.path{i}{1}(1) * scaleX - handle.machine.maxauslenkung,...
svg.path{i}{2}(1) * scaleY - handle.machine.maxauslenkung,...
handle.machine.penup);
for j=1:numel(svg.path{i}{1})
move(handle.machine, ...
svg.path{i}{1}(j) * scaleX - handle.machine.maxauslenkung,...
svg.path{i}{2}(j) * scaleY - handle.machine.maxauslenkung,...
handle.machine.pendown);
end
move(handle.machine, ...
svg.path{i}{1}(j) * scaleX - handle.machine.maxauslenkung,...
svg.path{i}{2}(j) * scaleY - handle.machine.maxauslenkung,...
handle.machine.penup);
end
move(handle.machine,0,0,handle.machine.zhome);
end
%% Button Nikolaus Callback
function btn_nikolaus_callback(hObject, event)
handle = guidata(hObject);
d=handle.machine.maxauslenkung; % Kantenlänge in mm / 2
% handle.machine.pendown
move(handle.machine, -d,-d,handle.machine.penup);
move(handle.machine, -d,-d,handle.machine.pendown);
move(handle.machine, -d,+d,handle.machine.pendown);
move(handle.machine, +d,-d,handle.machine.pendown);
move(handle.machine, -d,-d,handle.machine.pendown);
move(handle.machine, +d,+d,handle.machine.pendown);
move(handle.machine, 0,2*d,handle.machine.pendown);
move(handle.machine, -d,+d,handle.machine.pendown);
move(handle.machine, +d,+d,handle.machine.pendown);
move(handle.machine, +d,-d,handle.machine.pendown);
move(handle.machine, +d,-d,handle.machine.penup);
move(handle.machine, 0,0,handle.machine.zhome);
end
%% Button Nullpunkt Callback
function btn_nullpunkt_callback(hObject, event)
% Motor von Hand zum Nullpunkt fahren und Motorpositionen auf 0 setzten
nullpunkt(hObject);
end
%% Button Batterie Callback
function btn_batterie_callback(hObject, event)
handle = guidata(hObject);
handle.batterie_text.String = [num2str(NXT_GetBatteryLevel()/1000), 'V'];
end
%% Button pendown slider Callback
function pendown_callback(hObject, event)
handle = guidata(hObject);
handle.machine.pendown = handle.pendown.Value;
handle.machine.penup = handle.pendown.Value + 20;
handle.pendown_text.String = handle.pendown.Value;
drawnow;
move(handle.machine, 0,0,handle.machine.penup);
move(handle.machine, 0,0,handle.machine.pendown);
move(handle.machine, 0,0,handle.machine.zhome);
guidata(handle.fig, handle);
end