diff options
| author | Albin <albwa833@student.liu.se> | 2019-11-29 11:35:42 +0100 |
|---|---|---|
| committer | Albin <albwa833@student.liu.se> | 2019-11-29 11:39:26 +0100 |
| commit | eb9ecb33847612eca9d48dd3a88b4cf1396b70dd (patch) | |
| tree | 0ee140f0286745ffb9c920f33a5f27e4b27bc45a /Kod/bilbana/yc4 | |
| parent | aaaf94f0834c47cbed457b8b6ea4ab6aa18c2d72 (diff) | |
| download | tfyy51-eb9ecb33847612eca9d48dd3a88b4cf1396b70dd.tar.gz | |
Inför bp5
Diffstat (limited to 'Kod/bilbana/yc4')
| -rw-r--r-- | Kod/bilbana/yc4/display/scenes/draw_lap_graph.m | 8 | ||||
| -rw-r--r-- | Kod/bilbana/yc4/do_boot.m | 35 | ||||
| -rw-r--r-- | Kod/bilbana/yc4/do_car.m | 35 | ||||
| -rw-r--r-- | Kod/bilbana/yc4/get_aprox_v.m | 2 | ||||
| -rw-r--r-- | Kod/bilbana/yc4/main.m | 20 |
5 files changed, 46 insertions, 54 deletions
diff --git a/Kod/bilbana/yc4/display/scenes/draw_lap_graph.m b/Kod/bilbana/yc4/display/scenes/draw_lap_graph.m index 9fd669b..ca5ec83 100644 --- a/Kod/bilbana/yc4/display/scenes/draw_lap_graph.m +++ b/Kod/bilbana/yc4/display/scenes/draw_lap_graph.m @@ -83,15 +83,15 @@ if ~(in_clipboard) car1.avg = '--.-'; car1.dev = '-.--'; if length(car1_laptimes) > 5 - car1.avg = num2str(mean(car1_laptimes(6, length(car1_laptimes))), 3); - car1.dev = num2str(std(car1_laptimes(6, length(car1_laptimes))), 2); + car1.avg = num2str(mean(car1_laptimes(6:length(car1_laptimes))), 3); + car1.dev = num2str(std(car1_laptimes(6:length(car1_laptimes))), 2); end car2 = struct; car2.avg = '--.-'; car2.dev = '-.--'; if length(car2_laptimes) > 5 - car2.avg = num2str(mean(car2_laptimes(6, length(car2_laptimes))), 3); - car2.dev = num2str(std(car2_laptimes(6, length(car2_laptimes))), 2); + car2.avg = num2str(mean(car2_laptimes(6:length(car2_laptimes))), 3); + car2.dev = num2str(std(car2_laptimes(6:length(car2_laptimes))), 2); end line = 12; diff --git a/Kod/bilbana/yc4/do_boot.m b/Kod/bilbana/yc4/do_boot.m index a9306ef..5b60eb8 100644 --- a/Kod/bilbana/yc4/do_boot.m +++ b/Kod/bilbana/yc4/do_boot.m @@ -7,27 +7,31 @@ if car.running == true t = toc(boot.time); if t > 0.7 car.constant = car.constant + 0.12; - disp('###') - disp(car.num) - disp(car.constant) + % disp('###') + % disp(car.num) + % disp(car.constant) boot.time = tic; end end %% WHEN NEW LAP if car.new_lap == 1 car.constant = car.constant + 0.2; - disp('###') - disp(car.num) - disp(car.constant) + % disp('###') + % disp(car.num) + % disp(car.constant) end %% First segments if car.lap == 1 && car.segment == 1 || car.lap == 1 && car.segment == 2 t = toc(boot.time); if t > 1.2 - car.constant = car.constant + 0.04; - disp('###') - disp(car.num) - disp(car.constant) + if car.num == 1 + car.constant = car.constant + 0.06; + else + car.constant = car.constant + 0.04; + end + % disp('###') + % disp(car.num) + % disp(car.constant) boot.time = tic; end @@ -42,20 +46,19 @@ if car.running == true % disp(car.constant) % boot.time = tic; % end - % % end %% END BOOTSTRAP if car.segment > 3 car.governs(length(car.governs) + 1) = car.constant; - disp(car.constant); - status = car.forecasts_naive(car.lap, car.segment-1)/20; + % disp(car.constant); + status = car.forecasts_naive(car.lap, car.segment-1) / 15; car.constant = car.constant + (status - 1) * 0.08; boot.status = 0; - disp('END OF BOOTSTRAP') - disp(car.num) - disp(car.constant) + % disp('END OF BOOTSTRAP') + % disp(car.num) + % disp(car.constant) car.governs(length(car.governs) + 1) = car.constant; end end diff --git a/Kod/bilbana/yc4/do_car.m b/Kod/bilbana/yc4/do_car.m index 0aed013..92e4f8d 100644 --- a/Kod/bilbana/yc4/do_car.m +++ b/Kod/bilbana/yc4/do_car.m @@ -58,9 +58,9 @@ if car.running == true if toc(car.seg_tic) > 9.0 set_car_speed(1, 0); set_car_speed(2, 0); - %disp(strjoin({'AvÃ¥kning bil', num2str(car.num)})); - disp('J = Ja, N = Nej') - car.response = input('Vill du fortsätta? [N] ', 's'); + disp(strjoin({'Avåkning bil', num2str(car.num)})); + disp('(J = Ja, N = Nej)'); + car.response = input('Vill du fortsätta? [N] ', 's'); if car.response == 'J' car.seg_tic = tic; else @@ -76,11 +76,11 @@ if car.running == true aprox_v = get_aprox_v(car.segment + detect_missed(car.position, car.segment, car.num, car.pos_at), car); car.position = get_position(aprox_v, car.position, t); if car.lap == 2 && car.segment < 4 - disp('####') - disp(car.position) + % disp('####') + % disp(car.position) end if detect_missed( car.position, car.segment, car.num, car.pos_at) - disp('Miss?'); + % disp('Miss?'); %disp(toc(car.miss_time)); %if car.miss_time == 0 @@ -115,9 +115,9 @@ if car.running == true track_remaining = car.pos_at(length(car.pos_at)) - car.pos_at(car.segment + 1); car.forecasts(car.lap, car.segment) = lap_time_now + track_remaining/prev_seg_v; - car.forecasts_naive(car.lap, car.segment) = toc(car.seg_tic) / car.percents(car.segment) + car.forecasts_naive(car.lap, car.segment) = toc(car.seg_tic) / car.percents(car.segment); - car.segment = car.segment + 1; + car.segment = min(9, car.segment + 1); car.seg_tic = tic; if car.automatic && car.lap > 2 % S�kerhetsmarginal (B�r vara 1?) @@ -127,7 +127,7 @@ if car.running == true disp('Hoppar �ver missad givare 1/2'); else car.position = new_position; - car.segment = car.segment + seg_plus; + car.segment = min(9, car.segment + seg_plus); end if seg_plus ~= 0 && car.segment ~= 2 car.seg_times(car.lap, car.segment - seg_plus - 1) = 0; @@ -147,7 +147,7 @@ if car.running == true if car.new_lap == true disp('NEW LAP') beep; - if car.lap == 0 + if car.lap == 0 % dont save time for first lap car.segment = 1; car.lap = car.lap + 1; @@ -191,14 +191,19 @@ end %% CONTROLLER if car.running == true && car.automatic == false - mult = 100; - max = 55; - div = 55; - set_car_speed(car.num, mult * ((max - get_manual_speed(car.num)) / div)) + mult_ = 100; + max_ = 55; + div_ = 55; + set_car_speed(car.num, mult_ * ((max_ - get_manual_speed(car.num)) / div_)) end %% EXECUTE if car.running == true && car.automatic == true - set_car_speed(car.num, car.u); + disp(strjoin({num2str(car.num), num2str(car.u), num2str(car.position)})) + if not(boot.status) + set_car_speed(car.num, max(car.u, 16)); + else + set_car_speed(car.num, car.u); + end end end diff --git a/Kod/bilbana/yc4/get_aprox_v.m b/Kod/bilbana/yc4/get_aprox_v.m index 2ed2a04..5b6808b 100644 --- a/Kod/bilbana/yc4/get_aprox_v.m +++ b/Kod/bilbana/yc4/get_aprox_v.m @@ -12,7 +12,7 @@ if cur_seg > 9 end %% Kompensera för väldigt långsamt segment 1 första varvet if cur_seg == 1 && lap == 2 - v = car.seg_len(1)/(1.5*car.seg_times(1,9)) + v = car.seg_len(1)/(1.5*car.seg_times(1,9)); return end %% Sätt v diff --git a/Kod/bilbana/yc4/main.m b/Kod/bilbana/yc4/main.m index 18fa982..4ca058a 100644 --- a/Kod/bilbana/yc4/main.m +++ b/Kod/bilbana/yc4/main.m @@ -15,7 +15,7 @@ start_race(2) %% INIT global log_debug; -log_debug = true; +log_debug = false; global log_verbose; log_verbose = false; % INIT DISPLAY @@ -55,7 +55,7 @@ car1.seg_len = [2.53 0.53 1.68 2.92 1.2 2.01 3.83 2.89 1.99]; car1.percents = [0.088, 0.022, 0.102, 0.15, 0.058, 0.11, 0.212, 0.146, 0.113]; % TODO car1.map = Bana1; %car1.approximation = []; -car1.miss_probability = 0.0; +car1.miss_probability = 0.05; car1.constant = 0.1; car1.stop = false; car1.governs = []; @@ -124,64 +124,48 @@ done = false; while 1 pause(0.1); if toc(display.last_check) > 0.4 - verbose('DISPLAY', 'toc > 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); - verbose('DISPLAY', 'Requesting internal mem for next cycle...'); % request internal mem matlabclient(1, hex2dec(['12'; '01'; '53'; '66'])); if isempty(display.shm_interp.data) - verbose('DISPLAY', 'No response'); continue end - debug('DISPLAY', ['Reading ', num2str(length(display.shm_interp.data)), ' package(-s)']); update_ref_time = false; for i = 1:length(display.shm_interp.data) data = display.shm_interp.data(i); if data.data == 32 - debug('DISPLAY', ... - 'Start-button pressed, exiting when no more packages'); done = true; elseif data.data == 11 - debug('DISPLAY', 'Enabling car 1'); car1.running = true; elseif data.data == 12 - debug('DISPLAY', 'Disabling car 1'); car1.running = false; elseif data.data == 13 - debug('DISPLAY', 'Enabling car 1 manual'); car1.automatic = false; elseif data.data == 14 - debug('DISPLAY', 'Disabling car 1'); car1.automatic = true; elseif data.data == 21 - debug('DISPLAY', 'Enabling car 2'); car2.running = true; elseif data.data == 22 - debug('DISPLAY', 'Disabling car 2'); car2.running = false; elseif data.data == 23 - debug('DISPLAY', 'Enabling car 2 manual'); car2.automatic = false; elseif data.data == 24 - debug('DISPLAY', 'Disabling car 2 manual'); car2.automatic = true; elseif data.data == 41 % ignore elseif data.data == 42 - debug('DISPLAY', ['Decreasing ref_time to ', num2str(ref_time)]); ref_time = max(ref_time - 0.5, 12.0); update_ref_time = true; elseif data.data == 43 % ignore elseif data.data == 44 - debug('DISPLAY', ['Increasing ref_time to ', num2str(ref_time)]); ref_time = min(ref_time + 0.5, 15.0); update_ref_time = true; end |
