forked from Frc2481/hexapod
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hexapod.ino
118 lines (98 loc) · 2.16 KB
/
Hexapod.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
#include <Servo.h>
#define MID_LEG_MID 95
#define MID_LEG_MAX 115
#define MID_LEG_MIN 75
#define LEFT_LEG_MID 90
#define LEFT_LEG_MAX 125
#define LEFT_LEG_MIN 45
#define RIGHT_LEG_MID 90
#define RIGHT_LEG_MAX 125
#define RIGHT_LEG_MIN 45
#define MID_LEG_LIFT_RIGHT MID_LEG_MAX
#define MID_LEG_LIFT_LEFT MID_LEG_MIN
#define LEFT_LEG_FWD LEFT_LEG_MIN
#define LEFT_LEG_REV LEFT_LEG_MAX
#define RIGHT_LEG_FWD RIGHT_LEG_MAX
#define RIGHT_LEG_REV RIGHT_LEG_MIN
Servo midLeg;
Servo leftLeg;
Servo rightLeg;
void setup() {
// put your setup code here, to run once:
midLeg.attach(3);
leftLeg.attach(5);
rightLeg.attach(6);
}
bool first = 1;
void loop() {
// put your main code here, to run repeatedly:
if (first) {
first = 0;
//setMidLeg(MID_LEG_LIFT_LEFT);
walkFwd();
walkFwd();
walkFwd();
delay(5000);
zeroLegs();
}
}
void zeroLegs() {
setMidLeg(MID_LEG_LIFT_LEFT);
delay(500);
setLeftLeg(LEFT_LEG_MID);
delay(200);
setMidLeg(MID_LEG_LIFT_RIGHT);
delay(500);
setRightLeg(RIGHT_LEG_MID);
delay(200);
setMidLeg(MID_LEG_MID);
}
void walkFwd() {
setMidLeg(MID_LEG_LIFT_RIGHT);
delay(500);
setRightLeg(RIGHT_LEG_FWD);
setLeftLeg(LEFT_LEG_REV);
delay(500);
setMidLeg(MID_LEG_LIFT_LEFT);
delay(500);
setRightLeg(RIGHT_LEG_REV);
setLeftLeg(LEFT_LEG_FWD);
delay(500);
}
void walkRev() {
setMidLeg(MID_LEG_LIFT_LEFT);
delay(500);
setRightLeg(RIGHT_LEG_FWD);
setLeftLeg(LEFT_LEG_REV);
delay(500);
setMidLeg(MID_LEG_LIFT_RIGHT);
delay(500);
setRightLeg(RIGHT_LEG_REV);
setLeftLeg(LEFT_LEG_FWD);
delay(500);
//TODO: Implement
}
void walkLeft() {
setMidLeg(MID_LEG_LIFT_RIGHT);
delay(500);
setRightLeg(RIGHT_LEG_FWD);
setLeftLeg(LEFT_LEG_FWD);
delay(500);
setMidLeg(MID_LEG_LIFT_RIGHT);
delay(500);
setRightLeg(RIGHT_LEG_REV);
setLeftLeg(LEFT_LEG_REV);
delay(500);
}
void walkRight() {
//TODO: Implement
}
void setMidLeg(int val) {
midLeg.write(constrain(val, MID_LEG_MIN, MID_LEG_MAX));
}
void setLeftLeg(int val) {
leftLeg.write(constrain(val, LEFT_LEG_MIN, LEFT_LEG_MAX));
}
void setRightLeg(int val) {
rightLeg.write(constrain(val, RIGHT_LEG_MIN, RIGHT_LEG_MAX));
}