-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathomnicode8directionArduino.c
69 lines (67 loc) · 1.74 KB
/
omnicode8directionArduino.c
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
#include <stdio.h>
#include <math.h>
double radians(double x){
return x*M_PI/180.0;
}
struct Tuple {
int a, b, c;
};
struct Tuple calc(int Fx, int Fy){
struct Tuple result;
int maxSpeed = 100;
float tang = fabs((float)Fy/(float)Fx);
if (tang >= tan(radians(67.5)) && Fy >= 0){
result.a = maxSpeed;
result.b = maxSpeed;
result.c = 0;
return result;
}
else if (tang < tan(radians(67.5)) && tang >= tan(radians(22.5)) && Fy >= 0 && Fx >= 0){
result.a = maxSpeed/sqrt(2);
result.b = maxSpeed/sqrt(2);
result.c = 0;
return result;
}
else if (tang < tan(radians(22.5)) && Fx >= 0){
result.a = 0;
result.b = 2*maxSpeed/sqrt(3);
result.c = maxSpeed/sqrt(3);
return result;
}
else if (tang < tan(radians(67.5)) && tang >= tan(radians(22.5)) && Fy < 0 && Fx >= 0){
result.a = 2*maxSpeed/sqrt(6);
result.b = 0;
result.c = (maxSpeed/sqrt(2)+maxSpeed/sqrt(6));
return result;
}
else if (tang >= tan(radians(67.5)) && Fy < 0){
result.a = 0;
result.b = 0;
result.c = maxSpeed;
return result;
}
else if (tang < tan(radians(67.5)) && tang >= tan(radians(22.5)) && Fy < 0 && Fx < 0){
result.a = 2*maxSpeed/sqrt(6);
result.b = 0;
result.c = (maxSpeed/sqrt(2)+maxSpeed/sqrt(6));
return result;
}
else if (tang < tan(radians(22.5)) && Fx < 0){
result.a = 2*maxSpeed/sqrt(3);
result.b = 0;
result.c = maxSpeed/sqrt(3);
return result;
}
else if (tang < tan(radians(67.5)) && tang >= tan(radians(22.5)) && Fy >= 0 && Fx < 0){
result.a = maxSpeed/sqrt(2);
result.b = maxSpeed/sqrt(2);
result.c = 0;
return result;
}
}
int main()
{
struct Tuple temp = calc(-255,-5);
printf("%d,%d,%d\n", temp.a,temp.b,temp.c);
return 0;
}