-
Notifications
You must be signed in to change notification settings - Fork 0
/
commonFunction.h
137 lines (125 loc) · 2.5 KB
/
commonFunction.h
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
void delay(int t)//seconds
{
t = t*1000;
usleep(t);
}
int minimum(int *p,int k)
{
int in = 0;
int m = p[in];
for(b = 0; b < k; b++)
{
if(p[b]<=m)
{
m = p[b];
in = b;
}
}
return in;
}
int maximum(int *p,int k)
{
int in = 0;
int m = p[in];
for(b = 0; b < k; b++)
{
if(p[b]>=m)
{
m = p[b];
in = b;
}
}
return in;
}
int equality(int a, int b, int c)
{
if(a == b)
{
if(b == c)
{
return 1;
}
}
return 0;
}
int findmode(int *p,int count_steps)
{
int mode,count_mode,prev_count_mode;
int i,j;
for(i=0;i<count_steps;i++)
{
count_mode = 0;
for(j = i;j<count_steps;j++)
{
if(p[i] == p[j])
{
count_mode ++;
}
}
if(count_mode !=0 && count_mode > prev_count_mode)
{
mode = p[i];
}
prev_count_mode = count_mode;
}
return mode;
}
int findmean(int *p,int count_steps)
{
int i,sum=0;
for(i=0;i<count_steps;i++)
{
sum += p[i];
}
return sum/count_steps;
}
void decision_algorithm(bool door, bool stair, bool human, bool ground)
{
if(door == true)
{
cout<<"Door"<<endl;
if(door_toggledetect == 1 && door_prevtoggledetect == 0)
doordetect(1);
}
else if(door == false)
{
cout<<"No Door"<<endl;
if(door_toggledetect == 0 && door_prevtoggledetect == 1)
doordetect(0);
}
if(stair == true)
{
cout<<"Stair"<<endl;
if(stair_toggledetect == 1 && stair_prevtoggledetect == 0)
stairdetect(1);
}
else if(door == false)
{
cout<<"No Door"<<endl;
if(stair_toggledetect == 0 && stair_prevtoggledetect == 1)
stairdetect(0);
}
if(human == true)
{
cout<<"Human"<<endl;
if(human_toggledetect == 1 && human_prevtoggledetect == 0)
humandetect(1);
}
else if(human == false)
{
cout<<"No Human"<<endl;
if(human_toggledetect == 0 && human_prevtoggledetect == 1)
humandetect(0);
}
if(ground == true)
{
cout<<"Ground"<<endl;
}
else if(ground == false)
{
cout<<"No Ground"<<endl;
}
human_prevtoggledetect = human_toggledetect;
door_prevtoggledetect = door_toggledetect;
stair_prevtoggledetect = stair_toggledetect;
}