-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
190 lines (148 loc) · 4.51 KB
/
main.cpp
File metadata and controls
190 lines (148 loc) · 4.51 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
#include <iostream>
#include <fstream>
#include <string>
#include <rapp-robots-api/info/info.hpp>
#include <rapp-robots-api/communication/communication.hpp>
#include <rapp-robots-api/navigation/navigation.hpp>
std::vector<std::string> getRecipies(){
std::vector<std::string> recipies;
recipies.push_back("one");
recipies.push_back("two");
return recipies;
}
void tellRecipies(rapp::robot::communication &comm)
{
comm.text_to_speech("Say one for pancake.");
comm.text_to_speech("Say two for omlette.");
return;
}
std::string getRecipeName(std::string result)
{
std::string name;
if(result == "one")
name = "share/recipe-book/pancake.txt";
else if(result == "two")
name = "share/recipe-book/omlette.txt";
return name;
}
void sorry(rapp::robot::navigation &nav)
{
nav.moveJoint({"HeadYaw"}, {0.5}, 1.0f);
nav.moveJoint({"HeadYaw"}, {-0.5}, 1.0f);
nav.moveJoint({"HeadYaw"}, {0}, 1.0f);
}
void highFive(rapp::robot::navigation &nav){
nav.moveJoint({"LShoulderPitch","LShoulderRoll","LElbowYaw", "LElbowRoll", "LWristYaw", "LHand"},
{0,1.5,-1.6,-1.6,0,1}, 0.5);
}
int main(int argc, char * argv[]) {
rapp::robot::info info(argc, argv);
rapp::robot::communication comm(argc, argv);
rapp::robot::navigation nav(argc, argv);
nav.moveJoint({"HeadYaw","HeadPitch"}, {0,0}, 1.0f);
nav.rest("SitRelax");
comm.text_to_speech("What do you want to cook?");
tellRecipies(comm);
// create list of words for recognition
std::vector<std::string> words = getRecipies();
words.push_back("abort");
std::string result;
// start word spotting until proper word will be recognized
do {
result = comm.word_spotting(words);
if (result == "abort") {
comm.text_to_speech("Ok, Goodbye!");
return 0;
}
else{
bool isUnderstand = false;
for(int i = 0 ; i < words.size() ; i++)
if(words[i] == result){
isUnderstand = true;
break;
}
if(isUnderstand)
break;
}
sorry(nav);
comm.text_to_speech("Sorry, I don't understand you!");
} while (1);
result = getRecipeName(result);
std::ifstream recipeFile;
recipeFile.open(info.get_path(result));
if(!recipeFile.is_open()){
comm.text_to_speech("Warning! Recipe missing!");
return 0;
}
std::vector<std::string> ingredients;
comm.text_to_speech("We need the following ingredients.");
std::string line;
while(std::getline(recipeFile, line)){
if(line == "@")
break;
else{
ingredients.push_back(line);
comm.text_to_speech(line);
}
}
words.clear();
words.push_back("yes");
words.push_back("no");
words.push_back("all");
words.push_back("help");
int i=0;
while(ingredients.size()!=0){
comm.text_to_speech("Do we have "+ingredients[i]+"?");
result = comm.word_spotting(words);
if(result=="all")break;
else if(result=="help")
{
comm.text_to_speech("We need the following ingredients.");
for(int j=0;j<ingredients.size();j++)
comm.text_to_speech(ingredients[j]);
continue;
}
else if(result=="yes")
{
ingredients.erase(ingredients.begin()+i);
if (i==ingredients.size())i=0;
}
else if(result=="no")
{
i++;
if (i==ingredients.size())i=0;
}
else
{
sorry(nav);
comm.text_to_speech("Sorry, I don't understand you.");
}
}
comm.text_to_speech("We have all of the ingredients.");
comm.text_to_speech("Lets start cooking!");
words.clear();
words.push_back("done");
words.push_back("repeat");
std::getline(recipeFile, line);
bool isUnderstand=true;
do{
if(isUnderstand)comm.text_to_speech(line);
result = comm.word_spotting(words);
isUnderstand=true;
if(result=="repeat")
continue;
else if(result=="done"){
std::getline(recipeFile, line);
if(line=="@")break;
}
else {
sorry(nav);
comm.text_to_speech("Sorry, I don't understand you!");
isUnderstand=false;
}
}while(1);
comm.text_to_speech("We cooked a dish!");
highFive(nav);
comm.text_to_speech("High five!");
return 0;
}