summaryrefslogtreecommitdiffstats
path: root/Kod/bilbana/yc4/main.m
diff options
context:
space:
mode:
Diffstat (limited to 'Kod/bilbana/yc4/main.m')
-rw-r--r--Kod/bilbana/yc4/main.m155
1 files changed, 84 insertions, 71 deletions
diff --git a/Kod/bilbana/yc4/main.m b/Kod/bilbana/yc4/main.m
index fcff963..885d518 100644
--- a/Kod/bilbana/yc4/main.m
+++ b/Kod/bilbana/yc4/main.m
@@ -1,4 +1,23 @@
+clear all;
+
+%% INIT TRACK
+disp('Startar bilbanan. Avsluta med q.')
+hf=figure('position', [0 0 eps eps], 'menubar', 'none');
+
+initialize_counters(1)
+initialize_counters(2)
+
+config_IOs
+
+start_race(1)
+start_race(2)
+
%% INIT
+global log_debug;
+log_debug = true;
+global log_verbose;
+log_verbose = false;
+
% INIT DISPLAY
addpath display/ClientServerApp/Release
cd display/ClientServerApp/Release
@@ -17,20 +36,9 @@ display.last_send = tic;
display.last_request = tic;
display.send_interval = 0.5;
-disp('Startar bilbanan. Avsluta med q.')
-hf=figure('position', [0 0 eps eps], 'menubar', 'none');
-
-initialize_counters(1)
-initialize_counters(2)
-
-config_IOs
-
load('bilbana\files\Bana1.mat')
load('bilbana\files\Bana2.mat')
-start_race(1)
-start_race(2)
-
car1 = struct;
car1.num = 1;
car1.running = false;
@@ -41,11 +49,13 @@ car1.segment = 1;
car1.lap = 0;
car1.lap_times = [];
car1.seg_times = [];
+car1.seg_constant_list = []; % TODO
car1.position = 0;
car1.seg_len = [0.0 2.53 3.05 4.73 7.68 8.98 10.93 14.69 17.57];
car1.map = Bana1;
car1.approximation = [];
car1.miss_probability = 0.0;
+car1.lap_constants = [1,1,1,1,1,1,1,1,1]; % TODO
car2 = struct;
car2.num = 2;
@@ -60,7 +70,9 @@ car2.seg_times = [];
car2.position = 0;
car2.seg_len = [0.0 2.53 3.05 4.92 7.60 8.84 10.65 14.68 17.76];
car2.map = Bana2;
-car2.miss_probability = 0.05;
+car2.miss_probability = 0.1;
+car2.seg_constant_list = []; % TODO
+car2.lap_constants = [1,1,1,1,1,1,1,1,1]; % TODO
t = 0;
highToc = 0;
@@ -94,87 +106,88 @@ end
ref_time = input('Vilken referenstid ska användas? [13] ', 's');
ref_time = str2double(ref_time);
if isnan(ref_time)
- ref_time = 13;
+ ref_time = 13;
elseif not(isreal(ref_time))
- ref_time = 13;
+ ref_time = 13;
end
%}
ref_time = 13;
+
%% MAIN LOOP
while 1
- readTime = tic;
- %% PRE-LOOP
- if strcmp(get(hf,'currentcharacter'),'q')
- close(hf)
- break
+ readTime = tic;
+ %% PRE-LOOP
+ if strcmp(get(hf,'currentcharacter'),'q')
+ close(hf)
+ break
elseif strcmp(get(hf, 'currentcharacter'), 's')
car1.stopping = true;
car2.stopping = true;
- end
-
- figure(hf)
- drawnow
-
+ end
+
+ 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);
if car1.stop == true
disp('stopped by car 1');
break;
- end
- if car2.stop == true
+ end
+ if car2.stop == true
disp('stopped by car 2');
break;
- end
-
+ end
+
if (~car2.running && car1.stopped) || (~car1.running && car2.stopped) || (car1.stopped && car2.stopped)
break;
end
- %% END OF LOOP
- 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
- % queue control signal
- if car1.running && car1.automatic
- display.data = [display.data, put_text(20, 16 + (16 * 1), 'L', num2str(car1.u))];
- end
- if car2.running && car2.automatic
- display.data = [display.data, put_text(20, 16 + (16 * 2), 'L', num2str(car2.u))];
- end
-
- % send all queued data
- if ~isempty(display.data)
- [display.out] = matlabclient(1, get_smallpackage(display.data));
- display.data = [];
- end
- display.last_send = 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);
-
- % request internal mem
- % matlabclient(1, hex2dec(['12'; '01'; '53'; '66']));
- end
- % disp(strjoin({'display took additional ', num2str(toc(display.send_delay))}));
- % ACTUAL END OF LOOP
- t = toc(readTime);
-
- if t > 0.07
- if t > highToc
- highToc = t; %Om det nya v�rdet p� pausen �r h�gre �n den tidigare h�gsta s� sparas det som den h�gsta
- end
- if t > 0.1
- % beep;
- end
- break;
- end
- pause(0.001);
- end
+ %% END OF LOOP
+ 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
+ % queue control signal
+ if car1.running && car1.automatic
+ % display.data = [display.data, put_text(20, 16 + (16 * 1), 'L', num2str(car1.u))];
+ end
+ if car2.running && car2.automatic
+ % display.data = [display.data, put_text(20, 16 + (16 * 2), 'L', num2str(car2.u))];
+ end
+
+ % send all queued data
+ if ~isempty(display.data)
+ [display.out] = matlabclient(1, get_smallpackage(display.data));
+ display.data = [];
+ end
+ display.last_send = 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);
+
+ % request internal mem
+ % matlabclient(1, hex2dec(['12'; '01'; '53'; '66']));
+ end
+ % disp(strjoin({'display took additional ', num2str(toc(display.send_delay))}));
+ % ACTUAL END OF LOOP
+ t = toc(readTime);
+
+ if t > 0.07
+ if t > highToc
+ highToc = t; %Om det nya v�rdet p� pausen �r h�gre �n den tidigare h�gsta s� sparas det som den h�gsta
+ end
+ if t > 0.1
+ % beep;
+ end
+ break;
+ end
+ pause(0.001);
+ end
end
-
+
%% END OF PROGRAM
disp(highToc);
disp(car1);