-
Notifications
You must be signed in to change notification settings - Fork 0
/
jumpPriority.m
52 lines (48 loc) · 1.2 KB
/
jumpPriority.m
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
function out = jumpPriority(z,rule)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Matlab M-file Author: Ricardo Sanfelice
%
% Project: Simulation of a hybrid system
%
%
% Name: jumpPriority.m
%
% Description: Jump priority function
%
% Version: 0.4
% Required files: -
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% state
flowFlag = z(1);
jumpFlag = z(2);
stateFlag = z(3);
randomInput = z(4);
% rule = 1 -> priority for jumps
% rule = 2 -> priority for flows
% rule = 3 -> no priority, random selection when simultaneous conditions
if (rule == 1) & (jumpFlag == 1)
out = 1;
elseif (rule == 1) & (jumpFlag == 0)
out = 0;
elseif (rule == 2) & (flowFlag == 1)
out = 0;
elseif (rule == 2) & (flowFlag == 0) & (jumpFlag == 0)
out = 0;
elseif (rule == 2) & (flowFlag == 0) & (jumpFlag == 1)
out = 1;
elseif (rule == 3)
if (flowFlag == 1) & (jumpFlag == 0)
out = 0;
elseif (flowFlag == 0) & (jumpFlag == 1)
out = 1;
elseif (flowFlag == 1) & (jumpFlag == 1)
% aux = 0.4 + (0.6-0.4).*rand;
if (randomInput >= 0.5)
out = 1;
else
out = 0;
end
else
out = 0;
end
end