diff options
| author | Gustav Sörnäs <gusso230@student.liu.se> | 2019-11-13 01:00:03 +0100 |
|---|---|---|
| committer | Gustav Sörnäs <gusso230@student.liu.se> | 2019-11-13 01:00:03 +0100 |
| commit | d68ff43bbaaa55aa07a9a9839ef139ebb5cce4fb (patch) | |
| tree | e0d89ab0e6d059b03653feaabf427958a7b0cdd9 /Kod/bilbana/yc4/do_car.m | |
| parent | fae98d23d1932f346c469d4a13098ff0e3aa1e10 (diff) | |
| download | tfyy51-d68ff43bbaaa55aa07a9a9839ef139ebb5cce4fb.tar.gz | |
Add do_car-function (not tested)
Diffstat (limited to 'Kod/bilbana/yc4/do_car.m')
| -rw-r--r-- | Kod/bilbana/yc4/do_car.m | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/Kod/bilbana/yc4/do_car.m b/Kod/bilbana/yc4/do_car.m new file mode 100644 index 0000000..118aaec --- /dev/null +++ b/Kod/bilbana/yc4/do_car.m @@ -0,0 +1,111 @@ +function [car, stop] = do_car(car) + +stop = false; + +if car.running == true + [car.new_lap, car.new_check_point, car.time] = get_car_position(car.num); + if car.new_check_point == true && rand < car.miss_probability && car.lap >= 4 + disp('Hoppar �ver givare'); + car.new_check_point = false; + beep; + end +end + +%% CHECK LAP AND CHECKPOINT +if car.running == true + if car.lap ~= 0 + 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'); + if car.response == 'J' + car.seg_tic = tic; + else + stop = true; + return; + end + end + end + %% CALC POSITION + if car.lap > 1 + car.last_seg_times = car.seg_times(car.lap - 1, 1:9); + aprox_v = get_aprox_v(car.segment + detect_missed(car.position, car.segment, car.num), car.lap, car.seg_times, car.num); + car.position = get_position(aprox_v, car.position, t); + if detect_missed( car.position, car.segment, car.num) + disp('Miss?'); + + %disp(toc(car.miss_time)); + %if car.miss_time == 0 + % car.miss_time = tic; + %end + end + end + if car.new_check_point == true + if car.new_lap == false % choose_position krachar vid nytt varv (seg 10) + if car.lap ~= 0 + car.seg_times(car.lap, car.segment) = toc(car.seg_tic); + end + car.segment = car.segment + 1; + car.seg_tic = tic; + if car.lap > 2 % S�kerhetsmarginal (B�r vara 1?) + disp(car); + [new_position, seg_plus] = ... + choose_position(car.position, car.segment, car.num); + if seg_plus ~= 0 && car.segment == 1 + disp('Hoppar �ver missad givare 1/2'); + else + car.position = new_position; + car.segment = car.segment + seg_plus; + end + %car.miss_time = uint64(0); + else + car.position = car.seg_len(car.segment); + %car.miss_time = uint64(0); + end + end + end + if car.new_lap == true + car.new_lap = false; + beep; + if car.lap == 0 + % dont save time for first lap + car.segment = 1; + car.lap = car.lap + 1; + car.seg_tic = tic; + car.lap_tic = tic; + else + % beep; + car.seg_times(car.lap, car.segment) = toc(car.seg_tic); + car.seg_tic = tic; + car.lap_times(car.lap) = toc(car.lap_tic); + car.lap_tic = tic; + car.position = 0; + + display_data = {display_data, put_text(100, 16 + (16 * car.num), 'L', strjoin({num2str(car.lap), get_time_as_string(round(car.lap_times(car.lap) * 1000))}, ' '))}; + + car.segment = 1; + car.lap = car.lap + 1; + end + end +end + +%% CALCULATE +if car.running == true && car.automatic == true + car.car_constant = get_car_constant(car.num); + car.v = get_new_v(car.position, car.map); + car.track_u_constant = get_track_u_constant(); + car.u = get_new_u(car.v, car.car_constant, car.track_u_constant); +end + +%% CONTROLLER +if car.running == true && car.automatic == false + 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); +end +end |
