-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestearm.txt
173 lines (151 loc) · 2.67 KB
/
testearm.txt
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
// The sequence of control signals for 4 control wires is as follows:
//
// Step C0 C1 C2 C3
// 1 1 0 1 0
// 2 0 1 1 0
// 3 0 1 0 1
// 4 1 0 0 1
PARA_FRENTE = 1.0;
PARA_TRAS = -1.0;
STEPS_PER_CLICK = 50;
PIN1 = 0.0;
PIN2 = 0.0;
PIN3 = 0.0;
PIN4 = 0.0;
CURR_STEP = 0.0;
CURR_DIR = PARA_FRENTE;
FUNCTION STEP_MOTOR() {
IF (CURR_STEP == 0.0) {
OUT PIN1 = 255.0;
OUT PIN2 = 0.0;
OUT PIN3 = 255.0;
OUT PIN4 = 0.0;
}
ELSE IF (CURR_STEP == 1.0) {
OUT PIN1 = 0.0;
OUT PIN2 = 255.0;
OUT PIN3 = 255.0;
OUT PIN4 = 0.0;
}
ELSE IF (CURR_STEP == 2.0) {
OUT PIN1 = 0.0;
OUT PIN2 = 255.0;
OUT PIN3 = 0.0;
OUT PIN4 = 255.0;
}
ELSE IF (CURR_STEP == 3.0) {
OUT PIN1 = 255.0;
OUT PIN2 = 0.0;
OUT PIN3 = 0.0;
OUT PIN4 = 255.0;
}
//MICROS = 60L * 1000L * 1000L / this->number_of_steps / RPM;
RPM = (60.0 * 1000.0) / 4096.0 / 4.0;
DELAY RPM;
CURR_STEP = CURR_STEP + CURR_DIR;
IF (CURR_STEP == 4.0) {
CURR_STEP = 0.0;
}
ELSE IF (CURR_STEP == -1.0) {
CURR_STEP = 3.0;
}
}
FUNCTION MOTOR_SHUTDOWN() {
OUT PIN1 = 0.0;
OUT PIN2 = 0.0;
OUT PIN3 = 0.0;
OUT PIN4 = 0.0;
}
FUNCTION LOOP_STEPS() {
I = 0.0;
WHILE (I < STEPS_PER_CLICK) {
STEP_MOTOR();
I = I + 1.0;
}
MOTOR_SHUTDOWN();
}
STEP_DE = 0.0;
FUNCTION STEP_RIGHT_LEFT() {
CURR_STEP = STEP_DE;
PIN1 = 14.0; // A0
PIN2 = 4.0;
PIN3 = 3.0;
PIN4 = 5.0;
LOOP_STEPS();
STEP_DE = CURR_STEP;
}
STEP_UD = 0.0;
FUNCTION STEP_UP_DOWN() {
CURR_STEP = STEP_UD;
PIN1 = 10.0;
PIN2 = 12.0;
PIN3 = 11.0;
PIN4 = 13.0;
LOOP_STEPS();
STEP_UD = CURR_STEP;
}
STEP_FB = 0.0;
FUNCTION STEP_FRONT_BACK() {
CURR_STEP = STEP_FB;
PIN1 = 6.0;
PIN2 = 8.0;
PIN3 = 7.0;
PIN4 = 9.0;
LOOP_STEPS();
STEP_FB = CURR_STEP;
}
FUNCTION OPEN_GRIP() {
Z = SERVO_POS_INC();
}
FUNCTION CLOSE_GRIP() {
Y = SERVO_POS_DEC();
}
FUNCTION BLINK_FAST() {
OUT 13 = 255.0;
DELAY 100.0;
OUT 13 = 0.0;
DELAY 100.0;
}
FUNCTION BLINK() {
OUT 13 = 255.0;
DELAY 500.0;
OUT 13 = 0.0;
DELAY 500.0;
}
// MAIN LOOP
BLINK();
BLINK();
TRUE = 1.0;
WHILE (TRUE >= 1.0) {
F = READ_IR();
IF (F == 3041526525.0) { // UP
CURR_DIR = PARA_FRENTE;
STEP_UP_DOWN();
}
ELSE IF (F == 3041559165.0) { // DOWN
CURR_DIR = PARA_TRAS;
STEP_UP_DOWN();
}
ELSE IF (F == 3041542845.0) { // LEFT
CURR_DIR = PARA_FRENTE;
STEP_RIGHT_LEFT();
}
ELSE IF (F == 3041575485.0) { // RIGHT
CURR_DIR = PARA_TRAS;
STEP_RIGHT_LEFT();
}
ELSE IF (F == 4111076595.0) { // AUDIO
CURR_DIR = PARA_FRENTE;
STEP_FRONT_BACK();
}
ELSE IF (F == 3041570895.0) { // RIGHT
CURR_DIR = PARA_TRAS;
STEP_FRONT_BACK();
}
ELSE IF (F == 3041546415.0) { // OPEN GRIP
OPEN_GRIP();
}
ELSE IF (F == 3041579055.0) { // CLOSE GRIP
CLOSE_GRIP();
}
}