diff options
| -rw-r--r-- | Kod/bilbana/yc4/choose_position.m | 6 | ||||
| -rw-r--r-- | Kod/bilbana/yc4/main.m | 11 |
2 files changed, 11 insertions, 6 deletions
diff --git a/Kod/bilbana/yc4/choose_position.m b/Kod/bilbana/yc4/choose_position.m index ae900d6..035d6e3 100644 --- a/Kod/bilbana/yc4/choose_position.m +++ b/Kod/bilbana/yc4/choose_position.m @@ -17,18 +17,20 @@ for i = 1:length(track_len) if i == 1 near = [i,diff]; else - if diff < near(i) + if diff < near(2) near = [i,diff]; end end end +disp(near); %% Beräkning av passerad givare if near(1) == segment new_position = set_pos( track, segment); seg_plus = 0; + disp('In right segment'); else seg_plus = near(1) - segment - new_position = set_pos( track, segment) + new_position = set_pos( track, segment + seg_plus) beep end % TODO Bättre att utgå ifrån ingen missad givare ifall ingen annan givare diff --git a/Kod/bilbana/yc4/main.m b/Kod/bilbana/yc4/main.m index 950a9f8..0ff21c8 100644 --- a/Kod/bilbana/yc4/main.m +++ b/Kod/bilbana/yc4/main.m @@ -111,7 +111,9 @@ while 1 if car1.lap ~= 0 car1.seg_times(car1.lap, car1.segment) = toc(car1.seg_tic); end - car1.segment = car1.segment + 1; + if car1.segment < 9 + car1.segment = car1.segment + 1; + end car1.seg_tic = tic; %approximation = car1.position; % Måste vara innan nästa rad %car1.position = car1.seg_len(car1.segment); @@ -119,9 +121,10 @@ while 1 %approximation = approximation - car1.position; %car1.approximation(car1.lap, car1.segment) = approximation; if car1.lap > 2 %Säkerhetsmarginal (Bör vara 1?) - x = choose_position(car1.position,car1.segment, 1); - car1.position = x(1); - car1.segment = car1.segment + x(2); + disp(car1); + [car1.position,seg_plus] = choose_position(car1.position,car1.segment, 1); + %car1.position = x(1); + car1.segment = car1.segment + seg_plus; else car1.position = car1.seg_len(car1.segment); end |
