-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHelloSpoon_FactoryCode.ino
More file actions
226 lines (185 loc) · 4.05 KB
/
HelloSpoon_FactoryCode.ino
File metadata and controls
226 lines (185 loc) · 4.05 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
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
/*
HelloSpoon Factory Reset Code.
This code is loaded on the OpenCM-9.04 provided with HelloSpoon robot.
If for any reason you download a different code
and want to return your HelloSpoon to its factory state
you MUST load this code using CM9 IDE or HelloSpoon IDE
to your OpenCM-9.04 board.
For more information about HelloSpoon IDE:
https://github.com/HelloSpoon/HelloSpoon_OpenCMLib
Trunk design:
ID 1: XL-320 2.0 -------- base
ID 2: XL-320 2.0 -------- strong elbow (right)
ID 3: XL-320 2.0 -------- strong elbow (left)
ID 4: XL-320 2.0 -------- elbow near spoon
ID 5: XL-320 2.0 -------- spoon
*/
#include <HelloSpoon.h>
char data = 0;
boolean load_reader = true;
boolean wall = false;
boolean isFriend = true;
HelloSpoon robot;
/*
Reading load on spoon... needs modification!!
*/
void readLoad(){
delay(1000);
Serial2.write(1);
old_ON_Position();
}
/*
Randomly generated motion with random LED routine.
*/
void Dance(){
int rand_pos[4] = {random(250,550), random(250,650), random(250,750), random(150,800)};
char rand_led[4] = {'p', 'w', 'c', 'm'};
for(int i = 1; i < 5; i++){
robot.LED(i, rand_led[i-1]);
robot.moveJoint(i, rand_pos[i-1]);
delay(50);
}
}
/*
LED notification,
activated when a word is recognized by HelloSpoon app.
*/
void LED_notification(){
for(int i = 1; i < 5; i++){
robot.LED(i,"green");
delay(50);
}
delay(500);
for(int i = 1; i < 5; i++){
robot.LED(i,"blue");
delay(50);
}
}
/*
It's possible to set individually the velocity of each actuator
by modifying this function.
*/
void motionsVelocity(){
for(int i = 1; i < 5; i++){
robot.setJointVelocity(i, 80);
delay(10);
}
delay(1000);
}
void old_ON_Position(){
delay(500);
robot.moveJoint(1, 512);
robot.moveJoint(2, 312);
robot.moveJoint(3, 750);
robot.moveJoint(4, 402);
delay(1500);
ON_Position();
}
void ON_Position(){
delay(500);
robot.moveJoint(1, 512);
robot.moveJoint(2, 612);
robot.moveJoint(3, 750);
robot.moveJoint(4, 202);
delay(1500);
}
void Feeding_Init(){
motionsVelocity();
load_reader = true;
robot.moveJoint(1, 679);
robot.moveJoint(2, 347);
robot.moveJoint(3, 810);
robot.moveJoint(4, 295);
delay(1000);
robot.moveJoint(2, 559);
robot.moveJoint(3, 810);
robot.moveJoint(4, 295);
delay(1000);
robot.moveJoint(2, 562);
robot.moveJoint(3, 616);
robot.moveJoint(4, 454);
delay(1000);
robot.moveJoint(2, 649);
robot.moveJoint(3, 370);
robot.moveJoint(4, 562);
delay(1000);
robot.moveJoint(2, 749);
robot.moveJoint(3, 270);
robot.moveJoint(4, 585);
delay(1000);
Scoop_Motion_Bowl();
}
void Scoop_Motion_Bowl(){
robot.setJointVelocity(1, 100);
robot.setJointVelocity(2, 100);
robot.setJointVelocity(3, 100);
robot.setJointVelocity(4, 100);
robot.moveJoint(2, 807);
robot.moveJoint(3, 341);
robot.moveJoint(4, 480);
delay(500);
robot.moveJoint(2, 821);
robot.moveJoint(3, 227);
robot.moveJoint(4, 430);
delay(500);
Scoop_Motion_Mouth_Modif();
}
void Scoop_Motion_Mouth_Modif(){
robot.moveJoint(2, 473);
robot.moveJoint(3, 523);
robot.moveJoint(4, 400);
delay(1000);
robot.moveJoint(2, 453);
robot.moveJoint(3, 540);
robot.moveJoint(4, 450);
delay(1000);
robot.moveJoint(2, 453);
robot.moveJoint(3, 540);
robot.moveJoint(4, 490);
delay(1000);
Neutral();
}
void Neutral(){
robot.moveJoint(1, 512);
delay(3500);
readLoad();
}
void Spoon_Out_Mouth(){
robot.setJointVelocity(1, 50);
robot.setJointVelocity(2, 50);
robot.setJointVelocity(3, 50);
robot.setJointVelocity(4, 50);
robot.moveJoint(2, 373);
robot.moveJoint(3, 770);
robot.moveJoint(4, 302);
delay(500);
}
void setup(){
robot.begin(); //Starts comm with HelloSpoon robot actuators and board.
Serial2.begin(57600); //Starts Bluetooth comm.
delay(500);
robot.activateTrunk();
delay(500);
ON_Position();
}
void loop(){
if(wall){
}
else{
if(Serial2.available()){
data = Serial2.read();
if(data!=0){
if(data == 'w' && isFriend){
for(int i = 0; i < 10; i++){
Dance();
delay(350);
}
ON_Position();
}
else if(data == 'c' && isFriend){
Feeding_Init();
}
}
}
}
}