-
Notifications
You must be signed in to change notification settings - Fork 0
/
robocat.ino
279 lines (221 loc) · 5.8 KB
/
robocat.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
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(); // Initiates library.
#define SERVOMIN 110 // Minimum pulse length count out of 4096.
#define SERVOMAX 510 // Maximum pulse length count out of 4096.
int servoNo = 0; // Defines a counter for servos.
//правая верхняя
int time_to_do_0 = millis();
bool do_rev_0 = false;
int pos_0 = 390;
int time_to_do_1 = millis();
bool do_rev_1 = false;
int pos_1 = 300;
//правая нижняя
int time_to_do_4 = millis();
bool do_rev_4 = true;
int pos_4 = 355;
int time_to_do_5 = millis();
bool do_rev_5 = true;
int pos_5 = 370;
//левая верхняя
int time_to_do_8 = millis();
bool do_rev_8 = true;
int pos_8 = 375;
int time_to_do_9 = millis();
bool do_rev_9 = true;
int pos_9 = 360;
//левая нижняя
int time_to_do_12 = millis();
bool do_rev_12 = false;
int pos_12 = 340;
int time_to_do_13 = millis();
bool do_rev_13 = false;
int pos_13 = 490;
void setup()
{
Serial.begin(9600); // Starts serial connecton at 9600 baud rate.
pwm.begin(); // Sends PWM signals.
pwm.setPWMFreq(60); // Makes servos run at 60 Hz rate.
//pwm.setPWM(2, 0, 350);
//pwm.setPWM(6, 0, 330);
//pwm.setPWM(10, 0, 350);
//pwm.setPWM(14, 0, 370);
//занять прямое положение
pwm.setPWM(0, 0, 390);
pwm.setPWM(1, 0, 300);
pwm.setPWM(2, 0, 390);
pwm.setPWM(4, 0, 390);
pwm.setPWM(5, 0, 220);
pwm.setPWM(6, 0, 350);
pwm.setPWM(8, 0, 340);
pwm.setPWM(9, 0, 430);
pwm.setPWM(10, 0, 350);
pwm.setPWM(12, 0, 340);
pwm.setPWM(13, 0, 500);
pwm.setPWM(14, 0, 370);
delay(1000);
//занять положение полуприсяд
pwm.setPWM(0, 0, 355);
pwm.setPWM(1, 0, 370);
pwm.setPWM(2, 0, 390);
pwm.setPWM(4, 0, 355);
pwm.setPWM(5, 0, 290);
pwm.setPWM(6, 0, 350);
pwm.setPWM(8, 0, 375);
pwm.setPWM(9, 0, 360);
pwm.setPWM(10, 0, 350);
pwm.setPWM(12, 0, 375);
pwm.setPWM(13, 0, 430);
pwm.setPWM(14, 0, 370);
delay(1000);
//готовность к ходу
pwm.setPWM(0, 0, 390);
pwm.setPWM(1, 0, 300);
pwm.setPWM(2, 0, 390);
pwm.setPWM(4, 0, 355);
pwm.setPWM(5, 0, 290);
pwm.setPWM(6, 0, 350);
pwm.setPWM(8, 0, 375);
pwm.setPWM(9, 0, 360);
pwm.setPWM(10, 0, 350);
pwm.setPWM(12, 0, 340);
pwm.setPWM(13, 0, 500);
pwm.setPWM(14, 0, 370);
delay(1000);
time_to_do_0 = millis();
time_to_do_1 = millis();
time_to_do_4 = millis();
time_to_do_5 = millis();
time_to_do_8 = millis();
time_to_do_9 = millis();
time_to_do_12 = millis();
time_to_do_13 = millis();
}
void loop()
{
//правая верхняя нога
if(pos_0 < 390 and do_rev_0 == true and millis() - time_to_do_0 >= 500){
pos_0++;
if(pos_0 >= 390){
do_rev_0 = false;
time_to_do_0 = millis();
}
}
else if(pos_0 > 355 and do_rev_0 == false and millis() - time_to_do_0 >= 500){
pos_0--;
if(pos_0 <= 355){
do_rev_0 = true;
time_to_do_0 = millis();
}
}
pwm.setPWM(0, 0, pos_0);
if(pos_1 > 300 and do_rev_1 == true and millis() - time_to_do_1 >= 500){
pos_1 -= 2;
if(pos_1 <= 300){
do_rev_1 = false;
time_to_do_1 = millis();
}
}
else if(pos_1 < 370 and do_rev_1 == false and millis() - time_to_do_1 >= 500){
pos_1 += 2;
if(pos_1 >= 370){
do_rev_1 = true;
time_to_do_1 = millis();
}
}
pwm.setPWM(1, 0, pos_1);
//правая нижняя нога
if(pos_4 < 390 and do_rev_4 == true and millis() - time_to_do_4 >= 500){
pos_4++;
if(pos_4 >= 390){
do_rev_4 = false;
time_to_do_4 = millis();
}
}
else if(pos_4 > 355 and do_rev_4 == false and millis() - time_to_do_4 >= 500){
pos_4--;
if(pos_4 <= 355){
do_rev_4 = true;
time_to_do_4 = millis();
}
}
pwm.setPWM(4, 0, pos_4);
if(pos_5 > 220 and do_rev_5 == true and millis() - time_to_do_5 >= 500){
pos_5 -= 2;
if(pos_5 <= 220){
do_rev_5 = false;
time_to_do_5 = millis();
}
}
else if(pos_5 < 290 and do_rev_5 == false and millis() - time_to_do_5 >= 500){
pos_5 += 2;
if(pos_5 >= 290){
do_rev_5 = true;
time_to_do_5 = millis();
}
}
pwm.setPWM(5, 0, pos_5);
//левая верхняя нога
if(pos_8 < 375 and do_rev_8 == false and millis() - time_to_do_8 >= 500){
pos_8++;
if(pos_8 >= 375){
do_rev_8 = true;
time_to_do_8 = millis();
}
}
else if(pos_8 > 340 and do_rev_8 == true and millis() - time_to_do_8 >= 500){
pos_8--;
if(pos_8 <= 340){
do_rev_8 = false;
time_to_do_8 = millis();
}
}
pwm.setPWM(8, 0, pos_8);
if(pos_9 > 360 and do_rev_9 == false and millis() - time_to_do_9 >= 500){
pos_9 -= 2;
if(pos_9 <= 360){
do_rev_9 = true;
time_to_do_9 = millis();
}
}
else if(pos_9 < 430 and do_rev_9 == true and millis() - time_to_do_9 >= 500){
pos_9 += 2;
if(pos_9 >= 430){
do_rev_9 = false;
time_to_do_9 = millis();
}
}
pwm.setPWM(9, 0, pos_9);
//левая нижняя нога
if(pos_12 < 375 and do_rev_12 == false and millis() - time_to_do_12 >= 500){
pos_12++;
if(pos_12 >= 375){
do_rev_12 = true;
time_to_do_12 = millis();
}
}
else if(pos_12 > 340 and do_rev_12 == true and millis() - time_to_do_4 >= 500){
pos_12--;
if(pos_12 <= 340){
do_rev_12 = false;
time_to_do_12 = millis();
}
}
pwm.setPWM(12, 0, pos_12);
if(pos_13 > 430 and do_rev_13 == false and millis() - time_to_do_13 >= 500){
pos_13 -= 2;
if(pos_13 <= 430){
do_rev_13 = true;
time_to_do_13 = millis();
}
}
else if(pos_13 < 500 and do_rev_13 == true and millis() - time_to_do_13 >= 500){
pos_13 += 2;
if(pos_13 >= 500){
do_rev_13 = false;
time_to_do_13 = millis();
}
}
pwm.setPWM(13, 0, pos_13);
}