-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModified.cpp
More file actions
155 lines (130 loc) · 3.07 KB
/
Copy pathModified.cpp
File metadata and controls
155 lines (130 loc) · 3.07 KB
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
// SECOND FILE: Minor modification
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
#include <ESP8266WiFi.h>
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
#define SERVOMIN 150
#define SERVOMAX 600
#define LEG1_HIP 0
#define LEG1_KNEE 1
#define LEG1_ANKLE 2
#define LEG2_HIP 3
#define LEG2_KNEE 4
#define LEG2_ANKLE 5
#define LEG3_HIP 6
#define LEG3_KNEE 7
#define LEG3_ANKLE 8
#define LEG4_HIP 9
#define LEG4_KNEE 10
#define LEG4_ANKLE 11
int angleToPulse(int angle) {
return map(angle, 0, 180, SERVOMIN, SERVOMAX);
}
void moveServo(int channel, int angle) {
pwm.setPWM(channel, 0, angleToPulse(angle));
}
void sit() {
moveServo(LEG1_HIP, 90);
moveServo(LEG1_KNEE, 90);
moveServo(LEG1_ANKLE, 90);
moveServo(LEG2_HIP, 90);
moveServo(LEG2_KNEE, 90);
moveServo(LEG2_ANKLE, 90);
moveServo(LEG3_HIP, 90);
moveServo(LEG3_KNEE, 90);
moveServo(LEG3_ANKLE, 90);
moveServo(LEG4_HIP, 90);
moveServo(LEG4_KNEE, 90);
moveServo(LEG4_ANKLE, 90);
}
void standBy() {
moveServo(LEG1_HIP, 90);
moveServo(LEG1_KNEE, 90);
moveServo(LEG1_ANKLE, 90);
moveServo(LEG2_HIP, 90);
moveServo(LEG2_KNEE, 90);
moveServo(LEG2_ANKLE, 90);
moveServo(LEG3_HIP, 90);
moveServo(LEG3_KNEE, 90);
moveServo(LEG3_ANKLE, 90);
moveServo(LEG4_HIP, 90);
moveServo(LEG4_KNEE, 90);
moveServo(LEG4_ANKLE, 90);
}
void forwardWalk() {
moveServo(LEG1_HIP, 90);
moveServo(LEG1_KNEE, 70);
moveServo(LEG1_ANKLE, 90);
moveServo(LEG2_HIP, 90);
moveServo(LEG2_KNEE, 110);
moveServo(LEG2_ANKLE, 90);
moveServo(LEG3_HIP, 90);
moveServo(LEG3_KNEE, 70);
moveServo(LEG3_ANKLE, 90);
moveServo(LEG4_HIP, 90);
moveServo(LEG4_KNEE, 110);
moveServo(LEG4_ANKLE, 90);
standBy();
}
void byeBye() {
moveServo(LEG1_HIP, 60);
moveServo(LEG1_KNEE, 120);
moveServo(LEG1_ANKLE, 90);
delay(500);
moveServo(LEG1_HIP, 120);
moveServo(LEG1_KNEE, 60);
moveServo(LEG1_ANKLE, 90);
delay(500);
moveServo(LEG1_HIP, 90);
moveServo(LEG1_KNEE, 90);
moveServo(LEG1_ANKLE, 90);
standBy();
}
// MARK: ORIGINAL CODE
// void hello() {
// moveServo(LEG1_HIP, 120);
// moveServo(LEG1_KNEE, 90);
// moveServo(LEG1_ANKLE, 90);
// moveServo (LEG1_HIP, 120);
// moveServo(LEG1_KNEE, 90);
// moveServo(LEG1_ANKLE, 90);
// standBy();
// }
void hello() {
moveServo(LEG1_HIP, 120);
moveServo(LEG1_KNEE, 90);
moveServo(LEG1_ANKLE, 90);
// Add a delay to simulate the waving motion
delay(500);
moveServo(LEG1_HIP, 60);
moveServo(LEG1_KNEE, 90);
moveServo(LEG1_ANKLE, 90);
// Return to the standby position
standBy();
}
// CODE WRITTEN ABOVE IS BY GITHUB
void setup() {
Serial.begin(115200);
pwm.begin();
pwm.setPWMFreq(60);
standBy();
}
void loop() {
if (Serial.available()) {
String command = Serial.readStringUntil('\n');
command.trim();
if (command == "F") {
forwardWalk();
} else if (command == "Y") {
byeBye();
} else if (command == "H") {
hello();
} else if (command == "S") {
sit();
} else if (command == "s") {
standBy();
} else {
Serial.println("Invalid command");
}
}
}