summaryrefslogtreecommitdiffstats
path: root/Kod/bilbana
diff options
context:
space:
mode:
authorGustav Sörnäs <gusso230@student.liu.se>2019-11-23 23:05:05 +0100
committerGustav Sörnäs <gusso230@student.liu.se>2019-11-23 23:05:05 +0100
commitd195a43eef3817d6a1f926725eeaba6770345c17 (patch)
tree146f926568ee307b5761a68af32309783791cb64 /Kod/bilbana
parent457b052ca449b0653368c81e4218b20d76cd515a (diff)
downloadtfyy51-d195a43eef3817d6a1f926725eeaba6770345c17.tar.gz
more work
Diffstat (limited to 'Kod/bilbana')
-rw-r--r--Kod/bilbana/yc4/display/scenes/draw_lap_graph.m157
-rw-r--r--Kod/bilbana/yc4/main.m68
2 files changed, 116 insertions, 109 deletions
diff --git a/Kod/bilbana/yc4/display/scenes/draw_lap_graph.m b/Kod/bilbana/yc4/display/scenes/draw_lap_graph.m
index 8c7a5d0..68cfecf 100644
--- a/Kod/bilbana/yc4/display/scenes/draw_lap_graph.m
+++ b/Kod/bilbana/yc4/display/scenes/draw_lap_graph.m
@@ -1,11 +1,28 @@
-function [] = draw_lap_graph(car1_laptimes, car2_laptimes, ref_time)
+function [] = draw_lap_graph(car1_laptimes, car2_laptimes, ref_time, change_car)
dt = 0.2; % delay for display
-if isempty(car1_laptimes)
- car1_laptimes = car2_laptimes;
- car2_laptimes = [];
+% don't have to re-draw static elements, just the graphs
+persistent in_clipboard;
+if is_empty(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 is_empty(current_car)
+ % first call to function
+ current_car = 1;
+else
+ % switch current_car
+ if change_car
+ if current_car == 1
+ current_car = 2;
+ else
+ current_car = 1;
+ end
+ end
+end
%% strip empty values
tmp = [];
@@ -24,67 +41,103 @@ for i = 1:length(car2_laptimes)
end
car2_laptimes = tmp;
-% laps = max(length(graphs.car1.lap_times), length(graphs.car2.lap_times));
-
pause(dt);
matlabclient(1, get_smallpackage(clear_display()));
pause(dt);
-matlabclient(1, get_smallpackage(put_text(160, 8, 'C', 'Varvtider')))
-pause(dt);
+% laps = max(length(graphs.car1.lap_times), length(graphs.car2.lap_times));
+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(300, 0 , 320, 24 , 70, 71, 'C', 'Byt bil') ...
+ ]));
+ pause(dt);
-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, 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);
-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', 'std') ...
+ ]));
+ 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', 'std') ...
-]));
-pause(dt);
+ car1 = struct;
+ car1.avg = '--.-'
+ car1.dev = '-.--'
+ if ~isempty(car1_laptimes)
+ car1.avg = num2str(mean(car1_laptimes), 1);
+ car1.dev = num2str(std(car1_laptimes), 2);
+ end
+ car2 = struct;
+ car2.avg = '--.-'
+ car2.dev = '-.--'
+ if ~isempty(car2_laptimes)
+ car2.avg = num2str(mean(car2_laptimes), 1);
+ 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', num2str(mean(car1_laptimes), 1)), ...
- put_text(160, y + 2 + margin_top + line*2, 'C', num2str(mean(car2_laptimes), 1), ...
- put_text(266, y + 2 + margin_top + line*1, 'C', num2str(std(car1_laptimes), 2)), ...
- put_text(266, y + 2 + margin_top + line*2, 'C', num2str(std(car2_laptimes), 2)), ...
-]));
-pause(dt);
+ 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
+
+times = [];
+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;
+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
-times = [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16];
for i = 0:(length(times)-1)
-x = 28 + i*10;
-y = 144 - round(100 * (times(i+1) / max(times)));
-matlabclient(1, get_smallpackage([ ...
+ x = 28 + i*10;
+ y = 144 - round(100 * (times(i+1) / max(times)));
+ 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(0.15);
+ ]));
+ pause(dt);
end
-
-% matlabclient(1, get_smallpackage(save_display_to_clipboard()));
end
diff --git a/Kod/bilbana/yc4/main.m b/Kod/bilbana/yc4/main.m
index 0d0f5f1..64951aa 100644
--- a/Kod/bilbana/yc4/main.m
+++ b/Kod/bilbana/yc4/main.m
@@ -69,15 +69,15 @@ matlabclient(1, get_smallpackage([ ...
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
+ 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;
@@ -85,8 +85,8 @@ done = false;
while 1
pause(0.1);
if toc(display.last_check) > 0.4
- display.last_check = tic;
-
+ 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);
@@ -146,9 +146,9 @@ 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;
+ ref_time = 13;
+ elseif not(isreal(ref_time))
+ ref_time = 13;
end
%}
@@ -181,52 +181,6 @@ while 1
disp('stopped by car 2');
break;
end
-<<<<<<< HEAD
-
- %% 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
- % queue control signal
- if car1.running && car1.automatic
- % display.data = [display.data, put_text(20, 16 + (16 * 1), 'L', num2str(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
- if ~isempty(display.data)
- [display.out] = matlabclient(1, get_smallpackage(display.data));
- display.data = [];
- end
- display.last_send = 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);
-
- % request internal mem
- % matlabclient(1, hex2dec(['12'; '01'; '53'; '66']));
- end
- % disp(strjoin({'display took additional ', num2str(toc(display.send_delay))}));
- % ACTUAL END OF LOOP
- t = toc(readTime);
-
- if t > 0.07
- if t > highToc
- highToc = t; %Om det nya v�rdet p� pausen �r h�gre �n den tidigare h�gsta s� sparas det som den h�gsta
- end
- if t > 0.1
- % beep;
- end
- break;
- end
- pause(0.001);
- end
-=======
%% END OF LOOP
while 1 %Whileloop med paus som k�rs till pausen �verskridit 0.07 sekunder
@@ -235,10 +189,11 @@ while 1
if toc(display.last_send) > display.send_interval
% 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, put_text(20, 16 + (16 * 1), 'L', num2str(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, 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
@@ -270,7 +225,6 @@ while 1
end
pause(0.001);
end
->>>>>>> respond to buttons pressed + indents
end
%% END OF PROGRAM