summaryrefslogtreecommitdiffstats
path: root/Kod/bilbana
diff options
context:
space:
mode:
Diffstat (limited to 'Kod/bilbana')
-rw-r--r--Kod/bilbana/yc4/clamp.m6
-rw-r--r--Kod/bilbana/yc4/display/bar_graph.m6
-rw-r--r--Kod/bilbana/yc4/display/box.m (renamed from Kod/bilbana/yc4/display/draw_box.m)2
-rw-r--r--Kod/bilbana/yc4/display/continue_line.m2
-rw-r--r--Kod/bilbana/yc4/display/define_bar_graph.m7
-rw-r--r--Kod/bilbana/yc4/display/delete_bar_graph.m7
-rw-r--r--Kod/bilbana/yc4/display/draw_line.m (renamed from Kod/bilbana/yc4/display/draw_single_line.m)2
-rw-r--r--Kod/bilbana/yc4/display/flashing_area.m (renamed from Kod/bilbana/yc4/display/define_flashing_area.m)2
-rw-r--r--Kod/bilbana/yc4/display/flashing_area_with_pattern.m (renamed from Kod/bilbana/yc4/display/define_flashing_area_with_pattern.m)2
-rw-r--r--Kod/bilbana/yc4/display/frame.m (renamed from Kod/bilbana/yc4/display/draw_frame.m)2
-rw-r--r--Kod/bilbana/yc4/display/frame_box.m (renamed from Kod/bilbana/yc4/display/draw_frame_box.m)2
-rw-r--r--Kod/bilbana/yc4/display/get_bars_from_values.m44
-rw-r--r--Kod/bilbana/yc4/display/get_response.m2
-rw-r--r--Kod/bilbana/yc4/display/key.m (renamed from Kod/bilbana/yc4/display/define_touch_key.m)2
-rw-r--r--Kod/bilbana/yc4/display/point.m (renamed from Kod/bilbana/yc4/display/draw_point.m)2
-rw-r--r--Kod/bilbana/yc4/display/put_text.m2
-rw-r--r--Kod/bilbana/yc4/display/scenes/draw_lap_graph.m183
-rw-r--r--Kod/bilbana/yc4/display/scenes/draw_segment_bars.m57
-rw-r--r--Kod/bilbana/yc4/display/set_add_line_spacing.m3
-rw-r--r--Kod/bilbana/yc4/display/set_line_spacing.m3
-rw-r--r--Kod/bilbana/yc4/display/switch.m (renamed from Kod/bilbana/yc4/display/define_touch_switch.m)0
-rw-r--r--Kod/bilbana/yc4/display/toggle.m7
-rw-r--r--Kod/bilbana/yc4/do_car.m6
-rw-r--r--Kod/bilbana/yc4/main.m222
24 files changed, 456 insertions, 117 deletions
diff --git a/Kod/bilbana/yc4/clamp.m b/Kod/bilbana/yc4/clamp.m
new file mode 100644
index 0000000..78ddedd
--- /dev/null
+++ b/Kod/bilbana/yc4/clamp.m
@@ -0,0 +1,6 @@
+function val = clamp(n, m, M)
+% returns n if n is between m and M, otherwise
+ % m if n < m
+ % M if n > m
+val = min(max(n, m), M);
+end
diff --git a/Kod/bilbana/yc4/display/bar_graph.m b/Kod/bilbana/yc4/display/bar_graph.m
new file mode 100644
index 0000000..bc04406
--- /dev/null
+++ b/Kod/bilbana/yc4/display/bar_graph.m
@@ -0,0 +1,6 @@
+function pkg = bar_graph(direction, no, x1, y1, x2, y2, start_value, end_value, type, pattern)
+args = [no, get_bytes(x1), get_bytes(y1), get_bytes(x2), get_bytes(y2)];
+args = [args, start_value, end_value, type, pattern]; %TODO get_bytes or no ?
+
+pkg = get_package(strjoin({'B', direction}, ''), args);
+end
diff --git a/Kod/bilbana/yc4/display/draw_box.m b/Kod/bilbana/yc4/display/box.m
index 7ac4b70..786f95e 100644
--- a/Kod/bilbana/yc4/display/draw_box.m
+++ b/Kod/bilbana/yc4/display/box.m
@@ -1,4 +1,4 @@
-function pkg = draw_box(x1, y1, x2, y2, n1)
+function pkg = box(x1, y1, x2, y2, n1)
arg = [get_bytes(x1), get_bytes(y1), get_bytes(x2), get_bytes(y2), n1];
pkg = get_package('RO', arg);
end
diff --git a/Kod/bilbana/yc4/display/continue_line.m b/Kod/bilbana/yc4/display/continue_line.m
index 99b4074..fe863f7 100644
--- a/Kod/bilbana/yc4/display/continue_line.m
+++ b/Kod/bilbana/yc4/display/continue_line.m
@@ -1,4 +1,4 @@
function pkg = continue_line(x2, y2)
arg = [get_bytes(x2), get_bytes(y2)];
-pkg = get_package('GW', arg)
+pkg = get_package('GW', arg);
end
diff --git a/Kod/bilbana/yc4/display/define_bar_graph.m b/Kod/bilbana/yc4/display/define_bar_graph.m
deleted file mode 100644
index d915cf1..0000000
--- a/Kod/bilbana/yc4/display/define_bar_graph.m
+++ /dev/null
@@ -1,7 +0,0 @@
-function pkg = define_bar_graph(direction, no, x1, y1, x2, y2, start_value, end_value, type, pattern)
-pkg = []
-args = [no, get_bytes(x1), get_bytes(y1), get_bytes(x2), get_bytes(y2)]
-args = [args, start_value, end_value, type, pattern] %TODO get_bytes or no ?
-
-pkg = get_package(strjoin({'B', direction}, ''), args)
-end
diff --git a/Kod/bilbana/yc4/display/delete_bar_graph.m b/Kod/bilbana/yc4/display/delete_bar_graph.m
deleted file mode 100644
index 093cb2b..0000000
--- a/Kod/bilbana/yc4/display/delete_bar_graph.m
+++ /dev/null
@@ -1,7 +0,0 @@
-function pkg = define_bar_graph(num, keep_visible)
-if keep_visible
- keep_visible = 1
-else
- keep_visible = 0
-pkg = get_package('BD', [num, keep_visible])
-end
diff --git a/Kod/bilbana/yc4/display/draw_single_line.m b/Kod/bilbana/yc4/display/draw_line.m
index c1da8ab..0a43ef7 100644
--- a/Kod/bilbana/yc4/display/draw_single_line.m
+++ b/Kod/bilbana/yc4/display/draw_line.m
@@ -1,4 +1,4 @@
-function pkg = draw_single_line(x1, y1, x2, y2)
+function pkg = draw_line(x1, y1, x2, y2)
arg = [mod(x1, 255), fix(x1 / 255), y1, 0, mod(x2, 255), fix(x2 / 255), y2, 0];
pkg = get_package('GD', arg);
end
diff --git a/Kod/bilbana/yc4/display/define_flashing_area.m b/Kod/bilbana/yc4/display/flashing_area.m
index 3e581ea..e3ba624 100644
--- a/Kod/bilbana/yc4/display/define_flashing_area.m
+++ b/Kod/bilbana/yc4/display/flashing_area.m
@@ -1,4 +1,4 @@
-function pkg = define_flashing_area(x1, y1, x2, y2)
+function pkg = flashing_area(x1, y1, x2, y2)
arg = [get_bytes(x1), get_bytes(y1), get_bytes(x2), get_bytes(y2)];
pkg = get_package('QI', arg);
end
diff --git a/Kod/bilbana/yc4/display/define_flashing_area_with_pattern.m b/Kod/bilbana/yc4/display/flashing_area_with_pattern.m
index c5c190f..e6dd61b 100644
--- a/Kod/bilbana/yc4/display/define_flashing_area_with_pattern.m
+++ b/Kod/bilbana/yc4/display/flashing_area_with_pattern.m
@@ -1,4 +1,4 @@
-function pkg = define_flashing_area_with_pattern(x1, y1, x2, y2, n1)
+function pkg = flashing_area_with_pattern(x1, y1, x2, y2, n1)
arg = [get_bytes(x1), get_bytes(y1), get_bytes(x2), get_bytes(y2), n1];
pkg = get_package('QM', arg);
end
diff --git a/Kod/bilbana/yc4/display/draw_frame.m b/Kod/bilbana/yc4/display/frame.m
index 1a6ce3b..093d6b5 100644
--- a/Kod/bilbana/yc4/display/draw_frame.m
+++ b/Kod/bilbana/yc4/display/frame.m
@@ -1,4 +1,4 @@
-function pkg = draw_frame(x1, y1, x2, y2, n1)
+function pkg = frame(x1, y1, x2, y2, n1)
arg = [get_bytes(x1), get_bytes(y1), get_bytes(x2), get_bytes(y2)];
pkg = get_package('RR', arg);
end
diff --git a/Kod/bilbana/yc4/display/draw_frame_box.m b/Kod/bilbana/yc4/display/frame_box.m
index f2a247e..b28c61d 100644
--- a/Kod/bilbana/yc4/display/draw_frame_box.m
+++ b/Kod/bilbana/yc4/display/frame_box.m
@@ -1,4 +1,4 @@
-function pkg = draw_frame_box(x1, y1, x2, y2, n1)
+function pkg = frame_box(x1, y1, x2, y2, n1)
arg = [get_bytes(x1), get_bytes(y1), get_bytes(x2), get_bytes(y2), n1];
pkg = get_package('RT', arg);
end
diff --git a/Kod/bilbana/yc4/display/get_bars_from_values.m b/Kod/bilbana/yc4/display/get_bars_from_values.m
new file mode 100644
index 0000000..cbae702
--- /dev/null
+++ b/Kod/bilbana/yc4/display/get_bars_from_values.m
@@ -0,0 +1,44 @@
+function [bars, max_val, min_y, height] = get_bars_from_values(values1, values2)
+bars = [];
+
+% CONSTANT VALUES
+min_y = 200;
+height = 156;
+min_x = 16+13;
+bar_width = 10; % for a single bar, doubled if only one track
+bar_inner_gap_width = 1; % double effect
+bar_gap_width = 10;
+
+% switch 1 and 2 if 1 is empty
+if isempty(values1) && ~isempty(values2)
+ values1 = values2;
+ values2 = [];
+end
+
+max1 = max(values1);
+max2 = 0;
+if ~isempty(values2)
+ max2 = max(values2);
+end
+max_val = max([max1 max2]);
+
+for i = 1:9
+ bar = struct;
+ bar.x_lo = min_x + ((bar_width + bar_width + bar_gap_width) * (i-1));
+ bar.x_hi = bar.x_lo;
+ bar.y_lo = min_y;
+ bar.y_hi = min_y - round(height * (values1(i) / max_val));
+ if isempty(values2)
+ bar.x_hi = bar.x_lo + 2*bar_width;
+ bars = [bars bar];
+ else
+ bar.x_hi = bar.x_lo + bar_width;
+ bar2 = struct;
+ bar2.x_lo = bar.x_hi + bar_inner_gap_width*2;
+ bar2.x_hi = bar2.x_lo + bar_width;
+ bar2.y_lo = min_y;
+ bar2.y_hi = min_y - round((height * (values2(i) / max_val)));
+ bars = [bars bar bar2];
+ end
+end
+end
diff --git a/Kod/bilbana/yc4/display/get_response.m b/Kod/bilbana/yc4/display/get_response.m
index 0c77a00..aab66a6 100644
--- a/Kod/bilbana/yc4/display/get_response.m
+++ b/Kod/bilbana/yc4/display/get_response.m
@@ -36,7 +36,7 @@ pointer = pointer + 1;
% total length
data = struct;
-while pointer < length(display_data) - 1 % last value is bcc
+while pointer < length(display_data) - 1 % (last value is bcc)
pointer = pointer + 1;
if display_data(pointer) ~= 27
% TODO: no ESC?
diff --git a/Kod/bilbana/yc4/display/define_touch_key.m b/Kod/bilbana/yc4/display/key.m
index 69ed130..0187755 100644
--- a/Kod/bilbana/yc4/display/define_touch_key.m
+++ b/Kod/bilbana/yc4/display/key.m
@@ -1,4 +1,4 @@
-function pkg = define_touch_key(x1, y1, x2, y2, down_code, up_code, just, text)
+function pkg = key(x1, y1, x2, y2, down_code, up_code, just, text)
arg_location = [get_bytes(x1), get_bytes(y1), get_bytes(x2), get_bytes(y2)];
arg_text = double(strjoin({just; text}, ''));
arg_null = 0;
diff --git a/Kod/bilbana/yc4/display/draw_point.m b/Kod/bilbana/yc4/display/point.m
index 34ba683..cfb6b34 100644
--- a/Kod/bilbana/yc4/display/draw_point.m
+++ b/Kod/bilbana/yc4/display/point.m
@@ -1,4 +1,4 @@
-function pkg = draw_point(x1, y1)
+function pkg = point(x1, y1)
arg = [get_bytes(x1), get_bytes(y1)];
pkg = get_package('GP', arg);
end
diff --git a/Kod/bilbana/yc4/display/put_text.m b/Kod/bilbana/yc4/display/put_text.m
index 8455c83..8157a65 100644
--- a/Kod/bilbana/yc4/display/put_text.m
+++ b/Kod/bilbana/yc4/display/put_text.m
@@ -1,5 +1,5 @@
function [pkg] = put_text(x, y, justification, text)
-arg1 = [mod(x, 256), x ./ 256, mod(y, 256), y ./ 256];
+arg1 = [get_bytes(x), get_bytes(y)];
arg2 = text;
arg3 = 0;
diff --git a/Kod/bilbana/yc4/display/scenes/draw_lap_graph.m b/Kod/bilbana/yc4/display/scenes/draw_lap_graph.m
new file mode 100644
index 0000000..ebee57e
--- /dev/null
+++ b/Kod/bilbana/yc4/display/scenes/draw_lap_graph.m
@@ -0,0 +1,183 @@
+function [] = draw_lap_graph(car1_laptimes, car2_laptimes, ref_time, change_car)
+dt = 0.2; % delay for display
+
+% don't have to re-draw static elements, just the graphs
+persistent in_clipboard;
+if isempty(in_clipboard)
+ in_clipboard = false;
+end
+
+% draw the other car every time the function is called if the change_car flag is set
+% (this value is ignored if only one set of lap times are given)
+persistent current_car;
+if isempty(current_car)
+ % first call to function
+ current_car = 1;
+else
+ % switch current_car
+ disp('switching current car');
+ if change_car
+ if current_car == 1
+ current_car = 2;
+ else
+ current_car = 1;
+ end
+ end
+end
+
+%% STRIP EMPTY VALUES
+tmp = [];
+for i = 1:length(car1_laptimes)
+ if car1_laptimes(i) ~= 0
+ tmp = [tmp car1_laptimes(i)];
+ end
+end
+car1_laptimes = tmp;
+
+tmp = [];
+for i = 1:length(car2_laptimes)
+ if car2_laptimes(i) ~= 0
+ tmp = [tmp car2_laptimes(i)];
+ end
+end
+car2_laptimes = tmp;
+
+pause(dt);
+matlabclient(1, get_smallpackage(clear_display()));
+pause(dt);
+
+%% DRAW STATICS (OR COPY STATICS FROM CLIPBOARD)
+if ~(in_clipboard)
+ matlabclient(1, get_smallpackage([ ...
+ put_text(160, 8, 'C', 'Varvtider'), ...
+ key(0 , 216, 107, 240, 51, 61, 'C', 'Varv'), ...
+ key(107, 216, 213, 240, 52, 62, 'C', 'Segment'), ...
+ key(213, 216, 320, 240, 53, 63, 'C', 'Avsluta'), ...
+ key(260, 0 , 320, 24 , 70, 71, 'C', 'Byt bil') ...
+ ]));
+ pause(dt);
+
+ matlabclient(1, get_smallpackage([ ...
+ draw_line(20, 24, 20, 144), ... % y-axis
+ put_text(9, 25, 'C', 's'), ... % label y-axis
+ continue_line(304, 144), ... % x-axis
+ draw_line(16, 32, 20, 24), ... % arrow on y, left part
+ continue_line(24, 32), ... % arrow on y, right part
+ draw_line(304, 140, 304, 148) ... % line on x
+ ]));
+ pause(dt);
+
+ y = 166;
+ margin_top = 6;
+ matlabclient(1, get_smallpackage([ ...
+ draw_line(0, y, 320, y), ...
+ put_text(53 , y + margin_top, 'C', 'target'), ...
+ put_text(160, y + margin_top, 'C', 'mean'), ...
+ put_text(266, y + margin_top, 'C', 'stdev') ...
+ ]));
+ pause(dt);
+
+ car1 = struct;
+ car1.avg = '--.-';
+ car1.dev = '-.--';
+ if ~isempty(car1_laptimes)
+ car1.avg = num2str(mean(car1_laptimes), 3);
+ car1.dev = num2str(std(car1_laptimes), 2);
+ end
+ car2 = struct;
+ car2.avg = '--.-';
+ car2.dev = '-.--';
+ if ~isempty(car2_laptimes)
+ car2.avg = num2str(mean(car2_laptimes), 3);
+ car2.dev = num2str(std(car2_laptimes), 2);
+ end
+
+ line = 12;
+ matlabclient(1, get_smallpackage([ ...
+ put_text(6 , y + 3 + margin_top + line*1, 'L', '1'), ...
+ put_text(6 , y + 3 + margin_top + line*2, 'L', '2'), ...
+ put_text(53 , y + 2 + margin_top + line*1, 'C', num2str(ref_time)), ...
+ put_text(53 , y + 2 + margin_top + line*2, 'C', num2str(ref_time)), ...
+ put_text(160, y + 2 + margin_top + line*1, 'C', car1.avg), ...
+ put_text(160, y + 2 + margin_top + line*2, 'C', car2.avg), ...
+ put_text(266, y + 2 + margin_top + line*1, 'C', car1.dev), ...
+ put_text(266, y + 2 + margin_top + line*2, 'C', car2.dev), ...
+ ]));
+ pause(dt);
+
+ matlabclient(1, get_smallpackage(save_display_to_clipboard()));
+ pause(dt);
+else
+ matlabclient(1, get_smallpackage(restore_display_from_clipboard()));
+ pause(dt);
+end
+
+%% DRAW GRAPH FOR CAR
+
+laps = -1;
+% want to keep the same scale in x-axis for both cars so set laps to max of both
+laps = max(length(car1_laptimes), length(car2_laptimes)); % TODO check if max([]) == 0
+x_min = 20;
+dx_max = 260;
+% x[lap] = x_min + (dx_max * (i / laps)))
+
+y_min_val = ref_time - 1.5; % val for lowest y
+y_max_val = ref_time + 1.5; % val for highest y
+y_min = 144;
+dy_max = -50;
+max_diff_val = 1;
+y_mid = y_min + (dy_max);
+% y[lap] = clamp(y_min, y_mid + (dy_max * (lap[i] / ref_time)), y_min + 2*dy_max)
+
+times = [];
+% choose which lap-times to graph
+car = 0;
+if current_car == 1 && ~isempty(car1_laptimes)
+ times = car1_laptimes;
+ car = 1;
+elseif current_car == 2 && ~isempty(car2_laptimes)
+ times = car2_laptimes;
+ car = 2;
+% ignore current_car and choose the only carn_laptimes that exist
+elseif ~isempty(car1_laptimes)
+ times = car1_laptimes;
+ car = 1;
+elseif ~isempty(car2_laptimes)
+ times = car2_laptimes;
+ car = 2;
+else
+ % not supposed to get here
+end
+
+for i = 1:(length(times))
+ x = round(x_min + (dx_max * (i/laps)));
+ y = clamp(round(y_mid + dy_max), ...
+ round(y_mid + (dy_max * ((times(i) - ref_time) / max_diff_val))), ...
+ round(y_mid - dy_max) ...
+ );
+ matlabclient(1, get_smallpackage([ ...
+ set_point_size(3, 3), ...
+ point(x, y), ...
+ set_point_size(1, 1), ...
+ draw_line(x, 144-2, x, 144+2) ...
+ ]));
+ pause(dt);
+end
+max_lap_nums = 9;
+d_lap = floor(laps/max_lap_nums) + 1;
+% examples:
+% laps = 8
+ % d_lap = floor(8/9) + 1 = 0 + 1 = 1
+% laps = 10
+ % d_lap = floor(10/9) + 1 = 1 + 1 = 2
+for i = 1:(length(times))
+ if mod(i, d_lap) == 0
+ x = round(x_min + (dx_max * (i/laps)));
+ y = y_min + 4;
+ matlabclient(1, get_smallpackage([ ...
+ put_text(x, y, 'C', num2str(i)) ...
+ ]));
+ pause(dt);
+ end
+end
+end
diff --git a/Kod/bilbana/yc4/display/scenes/draw_segment_bars.m b/Kod/bilbana/yc4/display/scenes/draw_segment_bars.m
new file mode 100644
index 0000000..6df2dab
--- /dev/null
+++ b/Kod/bilbana/yc4/display/scenes/draw_segment_bars.m
@@ -0,0 +1,57 @@
+function [] = draw_segment_bars(values1, values2)
+dt = 0.2; % delay for display
+queue = []; % internal queue for packages to send to display
+
+pause(dt);
+matlabclient(1, get_smallpackage(clear_display()));
+pause(dt);
+
+matlabclient(1, get_smallpackage(put_text(160, 8, 'C', 'Genomsnittlig tid per segment')))
+pause(dt);
+
+% input('');
+matlabclient(1, get_smallpackage([ ...
+ key(0 , 216, 107, 240, 51, 61, 'C', 'Varv'), ...
+ key(107, 216, 213, 240, 52, 62, 'C', 'Segment'), ...
+ key(213, 216, 320, 240, 53, 63, 'C', 'Avsluta') ...
+]));
+pause(dt);
+
+matlabclient(1, get_smallpackage([ ...
+ draw_line(20, 24, 20, 200), ... % y-axis
+ put_text(9, 25, 'C', 's'), ... % label y-axis
+ continue_line(304, 200), ... % x-axis
+ draw_line(16, 32, 20, 24), ... % arrow on y, left part
+ continue_line(24, 32), ... % arrow on y, right part
+ draw_line(304, 196, 304, 204) ... % line on x
+]));
+pause(dt);
+
+[bars, max_val, min_y, max_height] = get_bars_from_values(values1, values2);
+
+for bar = bars
+ matlabclient(1, get_smallpackage(fill_area(bar.x_lo, bar.y_lo, bar.x_hi, bar.y_hi)));
+ pause(dt);
+end
+
+for i = 0:8
+ x = 16+13 + 10 + 30*i;
+ queue = [queue put_text(x, 204, 'C', num2str(i + 1))];
+ if i == 4 || i == 8
+ matlabclient(1, get_smallpackage(queue));
+ queue = [];
+ pause(dt);
+ end
+end
+
+for i = 1:floor(max_val)
+ x = 20;
+ y = min_y - round(max_height * (i/max_val));
+ matlabclient(1, get_smallpackage([...
+ draw_line(x, y, 320, y), ...
+ put_text(x-6, y-2, 'C', num2str(i))...
+ ]));
+ pause(dt);
+end
+end
+
diff --git a/Kod/bilbana/yc4/display/set_add_line_spacing.m b/Kod/bilbana/yc4/display/set_add_line_spacing.m
deleted file mode 100644
index 33a0b4a..0000000
--- a/Kod/bilbana/yc4/display/set_add_line_spacing.m
+++ /dev/null
@@ -1,3 +0,0 @@
-function pkg = set_add_line_spacing(val)
-pkg = get_package('ZY', [val])
-end
diff --git a/Kod/bilbana/yc4/display/set_line_spacing.m b/Kod/bilbana/yc4/display/set_line_spacing.m
new file mode 100644
index 0000000..95bfc49
--- /dev/null
+++ b/Kod/bilbana/yc4/display/set_line_spacing.m
@@ -0,0 +1,3 @@
+function pkg = set_line_spacing(val)
+pkg = get_package('ZY', [val])
+end
diff --git a/Kod/bilbana/yc4/display/define_touch_switch.m b/Kod/bilbana/yc4/display/switch.m
index e45f512..e45f512 100644
--- a/Kod/bilbana/yc4/display/define_touch_switch.m
+++ b/Kod/bilbana/yc4/display/switch.m
diff --git a/Kod/bilbana/yc4/display/toggle.m b/Kod/bilbana/yc4/display/toggle.m
new file mode 100644
index 0000000..9dc42b0
--- /dev/null
+++ b/Kod/bilbana/yc4/display/toggle.m
@@ -0,0 +1,7 @@
+function pkg = toggle(x1, y1, x2, y2, down_code, up_code, just, text)
+arg_location = [get_bytes(x1), get_bytes(y1), get_bytes(x2), get_bytes(y2)];
+arg_text = double(strjoin({just; text}, ''));
+arg_null = 0;
+
+pkg = get_package('AK', [arg_location, down_code, up_code, arg_text, arg_null]);
+end
diff --git a/Kod/bilbana/yc4/do_car.m b/Kod/bilbana/yc4/do_car.m
index cf534fa..4792ca7 100644
--- a/Kod/bilbana/yc4/do_car.m
+++ b/Kod/bilbana/yc4/do_car.m
@@ -1,4 +1,4 @@
-function [car, stop, display_data] = do_car(car, t, display_data, boot)
+function [car, halt, display_data] = do_car(car, t, display_data, boot)
%DO_CAR Ger nya värden till struct car, avgör om koden ska stoppas samt hämtar displaydata.
%{
Input/Output:
@@ -27,7 +27,7 @@ anrop
stop - Huruvida koden ska stoppas eller inte
%}
-stop = false;
+halt = false;
if car.running == true
[car.new_lap, car.new_check_point, car.time] = get_car_position(car.num);
if car.new_check_point == true && rand < car.miss_probability && car.lap >= 4
@@ -53,7 +53,7 @@ if car.running == true
if car.response == 'J'
car.seg_tic = tic;
else
- stop = true;
+ halt = true;
return;
end
end
diff --git a/Kod/bilbana/yc4/main.m b/Kod/bilbana/yc4/main.m
index 7f5264b..519fbf9 100644
--- a/Kod/bilbana/yc4/main.m
+++ b/Kod/bilbana/yc4/main.m
@@ -20,14 +20,14 @@ global log_verbose;
log_verbose = false;
% INIT DISPLAY
if display_active
- addpath display/ClientServerApp/Release
- cd display/ClientServerApp/Release
- !startServer
- cd ../../..
+ addpath display/ClientServerApp/Release
+ cd display/ClientServerApp/Release
+ !startServer
+ cd ../../..
end
display = struct;
-display.data = [clear_display()];
+display.data = [];
display.out = 0;
display.shm = 0;
display.shm_interp = struct;
@@ -35,7 +35,6 @@ display.shm_interp.ack = 0;
display.shm_interp.start_code = '';
display.shm_interp.data = [];
display.last_send = tic;
-display.last_request = tic;
display.send_interval = 0.5;
load('bilbana\files\Bana1.mat')
@@ -94,49 +93,99 @@ boot2 = struct;
boot2.status = false;
boot2.time = 0;
+halt = false;
+
+ref_time = 13;
+
t = 0;
highToc = 0;
-%% ASK ACTIVE CARS
-disp('J = Ja (automatiskt), M = Ja (manuellt), N = Nej');
-
-car1.response = input('Vill du köra bil 1? [N] ', 's');
-if car1.response == 'J'
- car1.running = true;
- car1.automatic = true;
- boot1.status = true;
- boot1.time = tic;
-elseif car1.response == 'M'
- car1.running = true;
- car1.automatic = false;
-else
- car1.running = false;
-end
+%% DRAW DISPLAY
+matlabclient(1, get_smallpackage([ ...
+ put_text(160, 30, 'C', 'Choose which car to drive'), ...
+ define_touch_switch(98 , 60 , 130, 90 , 11, 12, 'C', '1'), ... % ACTIVATE TRACK 1
+ define_touch_switch(102, 98 , 126, 122, 13, 14, 'C', 'M'), ... % MANUAL CONTROL TRACK 1
+ define_touch_switch(190, 60 , 222, 90 , 21, 22, 'C', '2'), ... % ACTIVATE TRACK 2
+ define_touch_switch(194, 98 , 218, 122, 23, 61, 'C', 'M') ... % MANUAL CONTROL TRACK 2
+ ]));
+pause(0.5);
+matlabclient(1, get_smallpackage([ ...
+ put_text(160, 120, 'C', '13.0'), ... % CURRENT REFERENCE TIME
+ define_touch_key( 98 , 110, 130, 140, 41, 42, 'C', '-'), ... % DECREASE REFERENCE TIME
+ define_touch_key( 190, 110, 220, 140, 43, 44, 'C', '+'), ... % INCREASE REFERENCE TIME
+ define_touch_key( 272, 192, 304, 224, 31, 32, 'C', 'S') ... % START BUTTON
+ %TODO CLEAR BUTTON
+ ]));
+
+%% CHECK DISPLAY BUTTONS
+display.last_check = tic;
+done = false;
+while 1
+ pause(0.1);
+ if toc(display.last_check) > 0.4
+ display.last_check = tic;
+ % read internal mem from last send
+ [display.out, display.shm] = matlabclient(2);
+ [display.shm_interp.ack, display.shm_interp.start_code, display.shm_interp.data] = get_response(display.shm);
-car2.response = input('Vill du köra bil 2? [N] ', 's');
-if car2.response == 'J'
- car2.running = true;
- car2.automatic = true;
- boot2.status = true;
- boot2.time = tic;
-elseif car2.response == 'M'
- car2.running = true;
- car2.automatic = false;
-else
- car2.running = false;
-end
-%{
-ref_time = input('Vilken referenstid ska användas? [13] ', 's');
-ref_time = str2double(ref_time);
-if isnan(ref_time)
- ref_time = 13;
-elseif not(isreal(ref_time))
- ref_time = 13;
+ % request internal mem
+ matlabclient(1, hex2dec(['12'; '01'; '53'; '66']));
+ if isempty(display.shm_interp.data)
+ continue
+ end
+ update_ref_time = false;
+ for i = 1:length(display.shm_interp.data)
+ disp(num2str(length(display.shm_interp.data)))
+ data = display.shm_interp.data(i);
+ disp(data)
+ if data.data == 32
+ done = true;
+ elseif data.data == 11
+ car1.running = true;
+ elseif data.data == 12
+ car1.running = false;
+ elseif data.data == 13
+ car1.automatic = false;
+ elseif data.data == 14
+ car1.automatic = true;
+ elseif data.data == 21
+ car2.running = true;
+ elseif data.data == 22
+ car2.running = false;
+ elseif data.data == 23
+ car2.automatic = false;
+ elseif data.data == 24
+ car2.automatic = true;
+ elseif data.data == 41
+ % ignore
+ elseif data.data == 42
+ ref_time = max(ref_time - 0.5, 12.0);
+ update_ref_time = true;
+ elseif data.data == 43
+ % ignore
+ elseif data.data == 44
+ ref_time = min(ref_time + 0.5, 15.0);
+ update_ref_time = true;
+ end
+ end
+ if done == true
+ break
+ end
+ if update_ref_time == true
+ pause(0.4);
+ matlabclient(1, get_smallpackage(put_text(160, 120, 'C', num2str(ref_time, '%.1f'))));
+ end
+ display.last_check = tic;
+ end
end
-%}
-car1.ref_time = 15;
-car2.ref_time = 15;
+
+debug('DISPLAY', ['CAR1.RUNNING=', car1.running, ', CAR1.AUTOMATIC=', car1.automatic])
+debug('DISPLAY', ['CAR2.RUNNING=', car2.running, ', CAR2.AUTOMATIC=', car2.automatic])
+debug('DISPLAY', ['CHOSEN REFERENCE TIME=', ref_time])
+
+matlabclient(1, get_smallpackage([define_bar_graph('O', 2, 266, 30, 290, 210, 0, 64, 1, 1)]));
+
%% MAIN LOOP
while 1
readTime = tic;
@@ -148,52 +197,53 @@ while 1
car1.stopping = true;
car2.stopping = true;
end
+end
- figure(hf)
- drawnow
-
- %% CORE OF LOOP
- [car1, car1.stop, display.data] = do_car(car1, t, display.data, boot1);
- [car2, car2.stop, display.data] = do_car(car2, t, display.data, boot2);
- %% BOOTSTRAP
- if boot1.status
- [car1, boot1] = do_boot(car1, boot1);
- end
- if boot2.status
- [car2, boot2] = do_boot(car2, boot2);
- end
- %% GOVERNOR
- if not(boot1.status) && car1.lap ~= 0
- car1 = do_gov(car1);
- end
- if not(boot2.status) && car2.lap ~= 0
- car2 = do_gov(car2);
- end
- %%
- if car1.stop == true
- disp('stopped by car 1');
- break;
- end
- if car2.stop == true
- disp('stopped by car 2');
- break;
- end
+figure(hf)
+drawnow
- if (~car2.running && car1.stopped) || (~car1.running && car2.stopped) || (car1.stopped && car2.stopped)
- break;
- end
+[car1, halt, display.data] = do_car(car1, t, display.data);
+if halt
+ break
+end
+[car2, halt, display.data] = do_car(car2, t, display.data);
+if halt
+ break
+end
+
+%% BOOTSTRAP
+if boot1.status
+ [car1, boot1] = do_boot(car1, boot1);
+end
+if boot2.status
+ [car2, boot2] = do_boot(car2, boot2);
+end
+%% GOVERNOR
+if not(boot1.status) && car1.lap ~= 0
+ car1 = do_gov(car1);
+end
+if not(boot2.status) && car2.lap ~= 0
+ car2 = do_gov(car2);
+end
+%%
- %% END OF LOOP
- while 1 %Whileloop med paus som k�rs till pausen �verskridit 0.07 sekunder
- % DISPLAY
- display.send_delay = tic;
- if toc(display.last_send) > display.send_interval && display_active
+if (~car2.running && car1.stopped) || (~car1.running && car2.stopped) || (car1.stopped && car2.stopped)
+ break;
+end
+
+%% END OF LOOP
+while 1 %Whileloop med paus som k�rs till pausen �verskridit 0.07 sekunder
+ % DISPLAY
+ display.send_delay = tic;
+ if toc(display.last_send) > display.send_interval && display_active
% queue control signal
if car1.running && car1.automatic
% display.data = [display.data, put_text(20, 16 + (16 * 1), 'L', num2str(car1.u))];
+ display.data = [display.data, update_bar_graph(1, car1.u)];
end
if car2.running && car2.automatic
% display.data = [display.data, put_text(20, 16 + (16 * 2), 'L', num2str(car2.u))];
+ display.data = [display.data, update_bar_graph(2, car2.u)];
end
% send all queued data
@@ -235,7 +285,7 @@ disp(car2);
terminate(1);
terminate(2);
if display_active
- matlabclient(3);
+ matlabclient(3);
end
%% DISPLAY GRAPHS
@@ -253,10 +303,10 @@ dateStr = datestr(now, 'yyyy-mm-dd');
timeStr = datestr(now, 'HH.MM');
if car1.lap > 2
- filenameMat1 = strjoin({'bilbana1_', dateStr, 'T', timeStr, '.mat'}, '');
- save(filenameMat1, '-struct', 'car1');
+ filenameMat1 = strjoin({'bilbana1_', dateStr, 'T', timeStr, '.mat'}, '');
+ save(filenameMat1, '-struct', 'car1');
end
if car2.lap > 2
- filenameMat2 = strjoin({'bilbana2_', dateStr, 'T', timeStr, '.mat'}, '');
- save(filenameMat2, '-struct', 'car2');
-end \ No newline at end of file
+ filenameMat2 = strjoin({'bilbana2_', dateStr, 'T', timeStr, '.mat'}, '');
+ save(filenameMat2, '-struct', 'car2');
+end