summaryrefslogtreecommitdiffstats
path: root/Kod/scripts/test_givare_kompenserad.m
blob: 2ac0841acd6e7033f49af51ca0070d7ee431eb58 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
disp('Startar bilbanan. Avsluta med q.')
hf=figure('position',[0 0 eps eps],'menubar','none');

initialize_counters(1)
initialize_counters(2)

start_race(1)
start_race(2)

config_IOs

car1 = struct;
car2 = struct;    

while 1
    %% PRE-LOOP
    if strcmp(get(hf,'currentcharacter'),'q')
        close(hf)
        break
    end
    
    figure(hf)
    drawnow
    
    %% READ
    [car1.new_lap, car1.new_check_point, car1.time] = get_car_position(1);
    [car2.new_lap, car2.new_check_point, car2.time] = get_car_position(2);
    
    if car1.new_lap || car1.new_check_point == true || car2.new_lap == true || car2.new_check_point == true
       disp('###')
    end
    
    if car1.new_check_point
        beep;
        disp('car 1 cp')
    end
    if car2.new_check_point
        beep;
        disp('car 2 cp')
    end
    if car1.new_lap
        beep;
        disp('car 1 lap')
    end
    if car2.new_lap
        beep;
        disp('car 2 lap')
    end
    % KOMPENSERA FÖR TRASIG BANA
    if car1.new_lap && (car2.new_check_point || car1.new_check_point)
        car2.new_lap = 0;
    elseif car1.new_lap
        car2.new_lap = 1;
    end
    pause(0.1)
    
    if car1.new_lap || car1.new_check_point == true || car2.new_lap == true || car2.new_check_point == true
       disp('---')
    end
    
    if car1.new_lap
        disp('New lap car 1')
    end
    if car1.new_check_point
        disp('New checkpoint car 1')
    end
    if car2.new_lap
       disp('NEW LAP CAR 2!')
    end
    if car2.new_check_point
        disp('NEW CHECKPOINT CAR 2!')
    end
    
    pause(0.1)
end

%%
terminate(1)
terminate(2)