summaryrefslogtreecommitdiffstats
path: root/Kod/bilbana
diff options
context:
space:
mode:
authorAlbin <albwa833@student.liu.se>2019-11-20 18:17:25 +0100
committerAlbin <albwa833@student.liu.se>2019-11-20 18:17:25 +0100
commit92c7372b418f3160d50fbe2fe5ab795aac1ccb4f (patch)
treefa6ef5fc8fcac4e2aefceed2bab825189dc72e0b /Kod/bilbana
parente5f92b8b507861769c7439b1873ef580e1400538 (diff)
downloadtfyy51-92c7372b418f3160d50fbe2fe5ab795aac1ccb4f.tar.gz
Funkar nästan
Diffstat (limited to 'Kod/bilbana')
-rw-r--r--Kod/bilbana/yc4/do_boot.m82
-rw-r--r--Kod/bilbana/yc4/main.m45
2 files changed, 27 insertions, 100 deletions
diff --git a/Kod/bilbana/yc4/do_boot.m b/Kod/bilbana/yc4/do_boot.m
index 645e100..ffa7878 100644
--- a/Kod/bilbana/yc4/do_boot.m
+++ b/Kod/bilbana/yc4/do_boot.m
@@ -1,88 +1,14 @@
-function [car] = do_boot(car, boot_time)
+function [car, boot] = do_boot(car, boot)
%BOOT Summary of this function goes here
% Detailed explanation goes here
if car.running == true
- [car.new_lap, car.new_check_point, car.time] = get_car_position(car.num);
- %% CHECK POINT
- 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);
- car.seg_constant_list(car.lap, car.segment) = car.seg_constant;
- 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, car.pos_at);
- if seg_plus ~= 0 && car.segment == 2
- disp('Hoppar �ver missad givare 1/2');
- else
- car.position = new_position;
- car.segment = car.segment + seg_plus;
- end
- if seg_plus ~= 0
- car.seg_times(car.lap, car.segment - seg_plus - 1) = 0;
- car.seg_constant_list(car.lap, car.segment - seg_plus - 1) = 0;
- disp(car.seg_times(car.lap, :))
- disp(seg_plus)
- end
- %car.miss_time = uint64(0);
- else
- car.position = car.pos_at(car.segment);
- %car.miss_time = uint64(0);
- end
- end
- end
- %% NEW LAP
- if car.new_lap == true
- car.lap_constants = gov_set(car.constant);
- car.new_lap = false; %TODO remove
- 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;
- % Spara inte seg_time om missad givare
- if car.segment == 9
- car.seg_times(car.lap, car.segment) = toc(car.seg_tic);
- car.seg_constant_list(car.lap, car.segment) = car.seg_constant;
- end
- car.seg_tic = tic;
- car.lap_times(car.lap) = toc(car.lap_tic);
- car.lap_tic = tic;
- car.position = 0;
-
- if car.lap == 1 && size(car.seg_times, 2) < 9
- disp('FEL: För få segment!!')
- car.stopped = true;
- other_car.stopped = true;
- return
- end
-
- 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
- %% CALCULATE
- if car.running == true && car.automatic == true
- car.v = get_new_v(car.position, car.map);
- car.seg_constant = get_seg_constant(car.position, car.lap_constants, car.num, car.pos_at);
- car.u = get_new_u(car.v, car.seg_constant);
- end
%% BEFORE FIRST LAP
if car.lap == 0
- t = toc(boot_time);
+ t = toc(boot.time);
if t > 1
car.constant = car.constant + 0.05;
- boot_time = tic;
+ disp(car.constant)
+ boot.time = tic;
end
end
end
diff --git a/Kod/bilbana/yc4/main.m b/Kod/bilbana/yc4/main.m
index 7b9a2b1..5481aa0 100644
--- a/Kod/bilbana/yc4/main.m
+++ b/Kod/bilbana/yc4/main.m
@@ -60,8 +60,8 @@ car1.map = Bana1;
car1.approximation = [];
car1.miss_probability = 0.0;
car1.lap_constants = [1,1,1,1,1,1,1,1,1]; % TODO
-car1.constant = 0.5;
-car1.boot = false;
+car1.constant = 0.1;
+car1.stop = false;
car2 = struct;
car2.num = 2;
@@ -81,14 +81,16 @@ car2.miss_probability = 0.1;
car2.seg_constant_list = []; % TODO
car2.lap_constants = [1,1,1,1,1,1,1,1,1]; % TODO
car2.seg_constant = 1;
-car2.constant = 0.5;
-car2.boot = false;
+car2.constant = 0.1;
+car2.stop = false;
-boot = struct;
-boot.car1 = false;
-boot.car2 = false;
-boot.car1_time = 0;
-boot.car2_time = 0;
+boot1 = struct;
+boot1.status = false;
+boot1.time = 0;
+
+boot2 = struct;
+boot2.status = false;
+boot2.time = 0;
t = 0;
highToc = 0;
@@ -100,8 +102,8 @@ car1.response = input('Vill du köra bil 1? [N] ', 's');
if car1.response == 'J'
car1.running = true;
car1.automatic = true;
- boot.car1 = true;
- boot.car1_time = tic;
+ boot1.status = true;
+ boot1.time = tic;
elseif car1.response == 'M'
car1.running = true;
car1.automatic = false;
@@ -114,8 +116,8 @@ car2.response = input('Vill du köra bil 2? [N] ', 's');
if car2.response == 'J'
car2.running = true;
car2.automatic = true;
- boot.car2 = true;
- boot.car2_time = tic;
+ boot2.status = true;
+ boot2.time = tic;
elseif car2.response == 'M'
car2.running = true;
car2.automatic = false;
@@ -148,15 +150,14 @@ while 1
drawnow
%% CORE OF LOOP
- if car1.boot
- car1 = boot(car1, boot);
- else
- [car1, car1.stop, display.data] = do_car(car1, t, display.data);
+ [car1, car1.stop, display.data] = do_car(car1, t, display.data);
+ [car2, car2.stop, display.data] = do_car(car2, t, display.data);
+ %% BOOTSTRAP
+ if boot1.status
+ [car1, boot1] = do_boot(car1, boot1);
end
- if car2.boot
- car2 = boot(car2, boot);
- else
- [car2, car2.stop, display.data] = do_car(car2, t, display.data);
+ if boot2.status
+ [car2, boot2] = do_boot(car2, boot2);
end
if car1.stop == true
@@ -222,7 +223,7 @@ disp(car1);
disp(car2);
terminate(1);
-terminate(2);
+terminate(2)
matlabclient(3);