diff options
Diffstat (limited to 'Kod/bilbana')
| -rw-r--r-- | Kod/bilbana/yc4/clamp.m | 4 | ||||
| -rw-r--r-- | Kod/bilbana/yc4/display/scenes/draw_lap_graph.m | 43 | ||||
| -rw-r--r-- | Kod/bilbana/yc4/display/scenes/draw_segment_bars.m | 4 |
3 files changed, 27 insertions, 24 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); |
