summaryrefslogtreecommitdiffstats
path: root/Kod/bilbana
diff options
context:
space:
mode:
Diffstat (limited to 'Kod/bilbana')
-rw-r--r--Kod/bilbana/yc4/do_boot.m89
-rw-r--r--Kod/bilbana/yc4/do_car.m2
-rw-r--r--Kod/bilbana/yc4/main.m47
3 files changed, 126 insertions, 12 deletions
diff --git a/Kod/bilbana/yc4/do_boot.m b/Kod/bilbana/yc4/do_boot.m
new file mode 100644
index 0000000..645e100
--- /dev/null
+++ b/Kod/bilbana/yc4/do_boot.m
@@ -0,0 +1,89 @@
+function [car] = do_boot(car, boot_time)
+%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);
+ if t > 1
+ car.constant = car.constant + 0.05;
+ boot_time = tic;
+ end
+ end
+end
+end \ No newline at end of file
diff --git a/Kod/bilbana/yc4/do_car.m b/Kod/bilbana/yc4/do_car.m
index 08c25fe..96b328d 100644
--- a/Kod/bilbana/yc4/do_car.m
+++ b/Kod/bilbana/yc4/do_car.m
@@ -120,7 +120,7 @@ if car.running == true
%% NEW LAP
if car.new_lap == true
- car.lap_constants = gov_set(get_car_constant(car.num));
+ car.lap_constants = gov_set(car.constant);
car.new_lap = false; %TODO remove
beep;
if car.lap == 0
diff --git a/Kod/bilbana/yc4/main.m b/Kod/bilbana/yc4/main.m
index e5ac062..7b9a2b1 100644
--- a/Kod/bilbana/yc4/main.m
+++ b/Kod/bilbana/yc4/main.m
@@ -1,4 +1,5 @@
clear all;
+display_active = false;
%% INIT TRACK
disp('Startar bilbanan. Avsluta med q.')
@@ -17,12 +18,14 @@ global log_debug;
log_debug = true;
global log_verbose;
log_verbose = false;
-
% INIT DISPLAY
-addpath display/ClientServerApp/Release
-cd display/ClientServerApp/Release
-!startServer
-cd ../../..
+if display_active
+
+ addpath display/ClientServerApp/Release
+ cd display/ClientServerApp/Release
+ !startServer
+ cd ../../..
+end
display = struct;
display.data = [clear_display()];
@@ -57,6 +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;
car2 = struct;
car2.num = 2;
@@ -76,6 +81,14 @@ 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;
+
+boot = struct;
+boot.car1 = false;
+boot.car2 = false;
+boot.car1_time = 0;
+boot.car2_time = 0;
t = 0;
highToc = 0;
@@ -87,6 +100,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;
elseif car1.response == 'M'
car1.running = true;
car1.automatic = false;
@@ -99,6 +114,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;
elseif car2.response == 'M'
car2.running = true;
car2.automatic = false;
@@ -114,8 +131,7 @@ elseif not(isreal(ref_time))
ref_time = 13;
end
%}
-ref_time = 13;
-
+ref_time = 13
%% MAIN LOOP
while 1
readTime = tic;
@@ -130,9 +146,18 @@ while 1
figure(hf)
drawnow
-
- [car1, car1.stop, display.data] = do_car(car1, t, display.data);
- [car2, car2.stop, display.data] = do_car(car2, t, display.data);
+
+ %% CORE OF LOOP
+ if car1.boot
+ car1 = boot(car1, boot);
+ else
+ [car1, car1.stop, display.data] = do_car(car1, t, display.data);
+ end
+ if car2.boot
+ car2 = boot(car2, boot);
+ else
+ [car2, car2.stop, display.data] = do_car(car2, t, display.data);
+ end
if car1.stop == true
disp('stopped by car 1');
@@ -151,7 +176,7 @@ while 1
while 1 %Whileloop med paus som k�rs till pausen �verskridit 0.07 sekunder
% DISPLAY
display.send_delay = tic;
- if toc(display.last_send) > display.send_interval
+ if toc(display.last_send) > display.send_interval && display_active
% queue control signal
if car1.running && car1.automatic
% display.data = [display.data, put_text(20, 16 + (16 * 1), 'L', num2str(car1.u))];