summaryrefslogtreecommitdiffstats
path: root/Kod
diff options
context:
space:
mode:
authorGustav Sörnäs <gusso230@student.liu.se>2019-11-25 12:34:32 +0100
committerGustav Sörnäs <gusso230@student.liu.se>2019-11-25 12:34:32 +0100
commit2246ff7466c252dff4e22ed894dee3f152f0f4e1 (patch)
tree93413bd113aac4d16a4713ed2e2d879ecc692ee8 /Kod
parent28de2319217341f7dd2ce8b8ecc091328a60eeaa (diff)
downloadtfyy51-2246ff7466c252dff4e22ed894dee3f152f0f4e1.tar.gz
Changes
- Add semicolons - Fix clamp - Fix syntax - Make testing (somewhat) modular
Diffstat (limited to 'Kod')
-rw-r--r--Kod/bilbana/yc4/clamp.m4
-rw-r--r--Kod/bilbana/yc4/display/scenes/draw_lap_graph.m43
-rw-r--r--Kod/bilbana/yc4/display/scenes/draw_segment_bars.m4
-rw-r--r--Kod/scripts/display_post_race_graphs.m12
4 files changed, 36 insertions, 27 deletions
diff --git a/Kod/bilbana/yc4/clamp.m b/Kod/bilbana/yc4/clamp.m
index 97d21a5..78ddedd 100644
--- a/Kod/bilbana/yc4/clamp.m
+++ b/Kod/bilbana/yc4/clamp.m
@@ -1,6 +1,6 @@
-function val = clamp(m, n, M)
+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(m, n), N)
+val = min(max(n, m), M);
end
diff --git a/Kod/bilbana/yc4/display/scenes/draw_lap_graph.m b/Kod/bilbana/yc4/display/scenes/draw_lap_graph.m
index b67b6f0..ebee57e 100644
--- a/Kod/bilbana/yc4/display/scenes/draw_lap_graph.m
+++ b/Kod/bilbana/yc4/display/scenes/draw_lap_graph.m
@@ -3,18 +3,19 @@ dt = 0.2; % delay for display
% don't have to re-draw static elements, just the graphs
persistent in_clipboard;
-if is_empty(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 is_empty(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;
@@ -52,7 +53,7 @@ if ~(in_clipboard)
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') ...
+ key(260, 0 , 320, 24 , 70, 71, 'C', 'Byt bil') ...
]));
pause(dt);
@@ -77,17 +78,17 @@ if ~(in_clipboard)
pause(dt);
car1 = struct;
- car1.avg = '--.-'
- car1.dev = '-.--'
+ car1.avg = '--.-';
+ car1.dev = '-.--';
if ~isempty(car1_laptimes)
- car1.avg = num2str(mean(car1_laptimes), 1);
+ car1.avg = num2str(mean(car1_laptimes), 3);
car1.dev = num2str(std(car1_laptimes), 2);
end
car2 = struct;
- car2.avg = '--.-'
- car2.dev = '-.--'
+ car2.avg = '--.-';
+ car2.dev = '-.--';
if ~isempty(car2_laptimes)
- car2.avg = num2str(mean(car2_laptimes), 1);
+ car2.avg = num2str(mean(car2_laptimes), 3);
car2.dev = num2str(std(car2_laptimes), 2);
end
@@ -97,10 +98,10 @@ if ~(in_clipboard)
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)), ...
+ 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);
@@ -113,9 +114,9 @@ end
%% DRAW GRAPH FOR CAR
-laps = -1
+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
+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)))
@@ -124,7 +125,8 @@ 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;
-y_mid = y_min + (dy_max)
+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 = [];
@@ -142,16 +144,16 @@ elseif ~isempty(car1_laptimes)
car = 1;
elseif ~isempty(car2_laptimes)
times = car2_laptimes;
- car = 2
+ car = 2;
else
% not supposed to get here
end
for i = 1:(length(times))
x = round(x_min + (dx_max * (i/laps)));
- y = clamp(y_min, ...
- round(y_mid + (dy_max * (times(i) / ref_time))), ...
- y_min + 2*dy_max ...
+ 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), ...
@@ -175,6 +177,7 @@ for i = 1:(length(times))
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
index f34aa04..6df2dab 100644
--- a/Kod/bilbana/yc4/display/scenes/draw_segment_bars.m
+++ b/Kod/bilbana/yc4/display/scenes/draw_segment_bars.m
@@ -36,8 +36,8 @@ end
for i = 0:8
x = 16+13 + 10 + 30*i;
- queue = [queue put_text(x, 204, 'C', num2str(i + 1))]
- if i == 4 or i == 8
+ queue = [queue put_text(x, 204, 'C', num2str(i + 1))];
+ if i == 4 || i == 8
matlabclient(1, get_smallpackage(queue));
queue = [];
pause(dt);
diff --git a/Kod/scripts/display_post_race_graphs.m b/Kod/scripts/display_post_race_graphs.m
index 4db9ffb..77336ce 100644
--- a/Kod/scripts/display_post_race_graphs.m
+++ b/Kod/scripts/display_post_race_graphs.m
@@ -1,3 +1,5 @@
+clear all;
+
addpath display/ClientServerApp/Release
cd display/ClientServerApp/Release
!startServer
@@ -15,6 +17,10 @@ pause(0.2);
%% CHECK DISPLAY BUTTONS
display.last_check = tic;
done = false;
+
+laptime_1 = [12 12.1 12.2 12.3 12.4 12.5 12.6 12.7 12.8 12.9 13];
+laptime_2 = [11 11.2 11.4 11.6 11.8 12 12.5 13 13.5 14 14.2 14.6 14.8 15];
+
while 1
pause(0.1);
if toc(display.last_check) > 0.4
@@ -34,16 +40,16 @@ while 1
disp(num2str(length(display.shm_interp.data)))
data = display.shm_interp.data(i);
if data.data == 51
- draw_lap_graph([13 13 13.2 13.1 13 12.9 12.75], [], 13, false);
+ draw_lap_graph(laptime_1, laptime_2, 13, false);
elseif data.data == 52
- draw_segment_bars([1 2 3 4 5 6 7 8 9], []);
+ draw_segment_bars([1 2 3 4 5 6 7 8 9], [9 8 7 6 5 4 3 2 1]);
elseif data.data == 53
pause(0.2);
matlabclient(1, get_smallpackage(clear_display()));
pause(0.2);
done = true;
elseif data.data == 70
- draw_lap_graph([13 13 13.2 13.1 13 12.9 12.75], [], 13, true);
+ draw_lap_graph(laptime_1, laptime_2, 13, true);
end
end
if done == true