forked from worranhin/RMDControl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
96 lines (80 loc) · 1.83 KB
/
main.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
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
#include "RMDControl.h"
void TestGoAngle();
void TestGetAngle();
void TestGetPI();
int main() {
RMD_Init("COM7");
TestGetAngle();
TestGetPI();
RMD_GoAngleRelative(1000);
Sleep(1000);
RMD_GoAngleRelative(-1000);
Sleep(1000);
RMD_DeInit();
return 0;
}
void TestGetAngle() {
int64_t angle;
if (RMD_GetMultiAngle_S(&angle) == 0) {
printf("Curent multi angle: %lld\n", angle);
} else {
printf("RMD_GetMultiAngle_S error\n");
}
}
void TestGoAngle() {
char key = 0;
int num = 0;
bool isReadingNum = false;
int numSign = 1;
printf("Enter an angle to go to(unit: 0.01 degree)\n");
printf("Enter \'s\' to stop.\n");
printf("Enter \'q\' to quit.\n");
while (1) {
key = getchar();
if (isReadingNum && !isdigit(key)) {
RMD_GoAngleAbsolute(num);
}
if (key == 'q') {
break;
} else if (key == 's') {
RMD_Stop();
continue;
} else if (key == '+') {
isReadingNum = true;
numSign = 1;
num = 0;
} else if (key == '-') {
isReadingNum = true;
numSign = -1;
num = 0;
} else if (isdigit(key)) {
isReadingNum = true;
num = num * 10 + key - '0';
while ((key = getchar()) != '\n') {
num = num * 10 + key - '0';
}
num *= numSign;
if (num > 9000 || num < -9000) {
printf("输入角度超出范围\n");
continue;
} else {
RMD_GoAngleAbsolute(num);
num = 0;
numSign = 1;
}
}
// if (num > 9000 || num < -9000) {
// printf("输入角度超出范围\n");
// continue;
// }
// GoToAngle(num);
}
}
void TestGetPI() {
uint8_t arrPI[6];
if (RMD_GetPI(arrPI) == 0) {
printf("Curent PI: %d, %d, %d, %d, %d, %d\n", arrPI[0], arrPI[1], arrPI[2], arrPI[3], arrPI[4], arrPI[5]);
} else {
printf("RMD_GetPI error\n");
}
}