31 for (
unsigned int d = 0; d < objectList->size(); d++) {
32 std::string name = objectList->get(d).asString().c_str();
35 o = iCub->opc->addOrRetrieveEntity<
Object>(name);
37 o = iCub->opc->addEntity<
Object>(name);
39 yInfo() <<
" [configureOPC] object " << o->
name() <<
"added" ;
47 Bottle bToPasar, bFromPasar;
48 bToPasar.addString(
"pointing");
50 bToPasar.addString(
"on");
52 bToPasar.addString(
"off");
54 if (!Network::connect(portToPasar.getName().c_str(),
"/pasar/rpc")) {
55 yError() <<
"Could not connect to pasar";
56 iCub->say(
"Could not connect to pasar");
59 portToPasar.write(bToPasar, bFromPasar);
60 if(bFromPasar.get(0).asString()!=
"ack") {
61 yError() <<
"Pasar did not change pointing to on";
62 iCub->say(
"Pasar did not change pointing to on");
72 std::string sNameBestEntity =
"none", sNameSecondBest =
"none";
74 double start = yarp::os::Time::now();
76 while (!bFound && start + 8.0 > yarp::os::Time::now()) {
77 iCub->opc->checkout();
78 std::list<std::shared_ptr<Entity>> lEntities = iCub->opc->EntitiesCacheCopy();
80 double highestSaliency = 0.0;
81 double secondSaliency = 0.0;
83 for (
auto& entity : lEntities) {
84 if (entity->name().find(
"unknown")==0) {
88 yError() <<
"Could not cast " << entity->
name() <<
" to an object";
89 iCub->say(
"Could not cast " + entity->name() +
" to an object");
92 if (secondSaliency != 0.0) {
93 secondSaliency = highestSaliency;
96 sNameBestEntity = temp->
name();
100 sNameSecondBest = temp->
name();
108 yDebug() << sNameBestEntity <<
" has highest saliency: " << highestSaliency;
109 yDebug() << sNameSecondBest <<
" has second highest saliency: " << secondSaliency;
112 if (highestSaliency > thresholdSalienceDetection) {
114 if (secondSaliency != 0.0) {
116 if ((highestSaliency / secondSaliency) > thresholdDistinguishObjectsRatio) {
117 yDebug() <<
"Two objects are salient, but one is much more";
121 yDebug() <<
"Two objects are similarly salient";
124 yDebug() <<
"Only one object is salient, take this one";
129 if (sNameBestEntity ==
"none") {
130 yDebug() <<
"No object is salient";
135 return sNameBestEntity;
144 yDebug() <<
"Going to load grammar.";
145 string grammar, expectedresponse=
"error", semanticfield=
"error";
147 grammar = GrammarAskNameAgent;
148 expectedresponse =
"SENTENCEAGENT";
149 semanticfield =
"agent";
151 grammar = GrammarAskNameObject;
152 expectedresponse =
"SENTENCEOBJECT";
153 semanticfield =
"object";
155 grammar = GrammarAskNameBodypart;
156 expectedresponse =
"SENTENCEBODYPART";
157 semanticfield =
"fingerName";
159 yError() <<
" error in proactiveTagging::recogName | for " << entityType <<
" | Entity Type not managed";
160 bOutput.addString(
"error");
161 bOutput.addString(
"Entity Type not managed");
162 iCub->say(
"I do not know what you want from me. Can you please ask me something else?");
168 bool recognizedCorrectGrammar=
false;
169 while(!recognizedCorrectGrammar) {
170 bRecognized = iCub->getRecogClient()->recogFromGrammarLoop(
grammarToString(grammar), 20);
171 bAnswer = *bRecognized.get(1).asList();
172 if(bAnswer.get(1).asList()->get(0).toString() != expectedresponse) {
173 iCub->say(
"I did not understand you. Can you please repeat?");
174 yError() <<
"Wrong sentence type returned (not " << expectedresponse <<
")";
176 recognizedCorrectGrammar =
true;
180 yDebug() <<
"Response from recogClient: " << bRecognized.toString();
182 if (bRecognized.get(0).asInt() == 0)
184 yError() <<
" error in proactiveTagging::askName | for " << entityType <<
" | Error in speechRecog";
185 bOutput.addString(
"error");
186 bOutput.addString(
"error in speechRecog");
190 iCub->say(
"I've understood " + bAnswer.get(0).asString());
192 Bottle bSemantic = *bAnswer.get(1).asList();
193 string sName = bSemantic.check(semanticfield, Value(
"error")).asString();
194 bOutput.addString(sName);
199 std::list<std::shared_ptr<Entity>> currentEntitiesList = iCub->opc->EntitiesCacheCopy();
202 for (
unsigned int d = 0; d < bodyPartList->size(); d++) {
203 bool foundSame =
false;
204 for(
auto& e : currentEntitiesList) {
205 if(
Bodypart* bp = dynamic_cast<Bodypart*>(e.get())) {
206 if(bp->m_joint_number == bodyPartJointList->get(d).asInt()) {
207 yWarning() <<
"Joint" << bp->m_joint_number <<
"already existing";
216 std::string name = bodyPartList->get(d).asString().c_str();
219 o = iCub->opc->addOrRetrieveEntity<
Bodypart>(name);
221 o = iCub->opc->addEntity<
Bodypart>(name);
223 yInfo() <<
" [configureOPC] Bodypart " << o->
name() <<
"added";
226 if(d < bodyPartJointList->size()) {
228 yInfo() <<
" [configureOPC] Bodypart " << o->
name() <<
" has now a joint " << o->
m_joint_number ;
230 iCub->opc->commit(o);
237 yDebug() <<
"Populating OPC...";
240 Bottle grpOPC_AOR = rf.findGroup(
"OPC_AddOrRetrieve");
241 bool shouldPopulate_AOR = grpOPC_AOR.find(
"populateOPC").asInt() == 1;
242 if (shouldPopulate_AOR) {
243 Bottle *objectList = grpOPC_AOR.find(
"objectName").asList();
244 subPopulateObjects(objectList,
true);
246 Bottle *bodyPartList = grpOPC_AOR.find(
"bodypartName").asList();
247 Bottle *bodyPartJointList = grpOPC_AOR.find(
"bodypartJoint").asList();
248 subPopulateBodyparts(bodyPartList, bodyPartJointList,
true);
252 Bottle grpOPC_Add = rf.findGroup(
"OPC_Add");
253 bool shouldPopulate_Add = grpOPC_Add.find(
"populateOPC").asInt() == 1;
254 if (shouldPopulate_Add) {
255 Bottle *objectList = grpOPC_Add.find(
"objectName").asList();
256 subPopulateObjects(objectList,
false);
258 Bottle *bodyPartList = grpOPC_Add.find(
"bodypartName").asList();
259 Bottle *bodyPartJointList = grpOPC_Add.find(
"bodypartJoint").asList();
260 subPopulateBodyparts(bodyPartList, bodyPartJointList,
false);
263 yDebug() <<
"configureOPC done";
267 std::string out = bodypart;
268 if(bodypart ==
"index" || bodypart ==
"middle" || bodypart ==
"ring" || bodypart ==
"little") {
269 out = out +
" finger";
bool setPasarPointing(bool on)
Ask pasar to increase saliency when a human is pointing to an object.
std::string getBestEntity(std::string sTypeTarget)
Loop through all objects in the OPC, and check their saliency.
double m_present
Is the object present in the scene A value of 1.0 means that the object currently is in the scene A v...
std::string grammarToString(const std::string &sPath)
Get the context path of a .grxml grammar, and return it as a string.
Represent any physical entity (including objects and agents) that can be stored within the OPC...
int m_joint_number
Joint number of the represented body part.
void subPopulateObjects(yarp::os::Bottle *objectList, bool addOrRetrieve)
std::string getBodyPartNameForSpeech(const std::string bodypart)
Return a "nice" version of a body part name, eg given "index" as input, it returns "index finger"...
Represents a body part of the robot.
void subPopulateBodyparts(yarp::os::Bottle *bodyPartList, yarp::os::Bottle *bodyPartJointList, bool addOrRetrieve)
void configureOPC(yarp::os::ResourceFinder &rf)
Read config file and fill OPC accordingly.
std::string name() const
Return the name of an entity (which has to be unique within the OPC)
double m_saliency
A measurement of the object saliency [0,1].
yarp::os::Bottle recogName(std::string entityType)
Recognize the name of an unknown entity (communicate with speech recognizer)