-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathECU_Functions.ino
84 lines (68 loc) · 1.42 KB
/
ECU_Functions.ino
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
/*===============================================Functions=====================================================*/
int indexSearch(int value, int arr[], int arrLength) {
int first, last, middle;
first = 0;
last = arrLength - 1;
middle = (first + last) / 2;
if (value <= arr[first])
return 0;
if (value >= arr[last])
return last;
while (first <= last) {
if ( arr[middle] < value ) {
first = middle + 1;
}
else if ( arr[middle] == value ) {
return middle;
}
else {
last = middle - 1;
}
middle = (first + last) / 2;
}
if ((value - arr[middle]) < (arr[middle + 1] - value))
return middle;
else
return middle + 1;
}
/*===============================================NN Functions=====================================================*/
float ud1(int h){
return w11*ryev_del[h][0] + w21*ryev_del[h][1];
}
float ud2(int h){
return w12*ryev_del[h][0] + w22*ryev_del[h][1];
}
float ud3(int h){
return w13*ryev_del[h][0] + w23*ryev_del[h][1];
}
float xd1(int h){
return satlin(ud1(h));
}
float xd2(int h){
if (h < 1){
return 0;
}
else {}
return satlin(iDelay + ud2(h));
}
float xd3(int h){
return satlin(ud3(h) - ud3Delay);
}
float satlin (float a){
if(a > lim){
return lim;
}
else if(a < -lim){
return -lim;
}
else{
return a;
}
}
float findDif(float a, float b){
if (a==b){
return 0.01;
}else{
return a-b;
}
}