Project: engagement_recognition License: BSD Dependencies:
Used by:
None |
engagement_recognition/src/recognition/recognizers/adjacency_pair/ap_human_waiting_state.cppGo to the documentation of this file.00001 /* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Copyright (c) 2010, Worcester Polytechnic Institute 00005 * All rights reserved. 00006 * 00007 * Redistribution and use in source and binary forms, with or without 00008 * modification, are permitted provided that the following conditions 00009 * are met: 00010 * 00011 * * Redistributions of source code must retain the above copyright 00012 * notice, this list of conditions and the following disclaimer. 00013 * * Redistributions in binary form must reproduce the above 00014 * copyright notice, this list of conditions and the following 00015 * disclaimer in the documentation and/or other materials provided 00016 * with the distribution. 00017 * * Neither the name of Worcester Polytechnic Institute. nor the names 00018 * of its contributors may be used to endorse or promote products 00019 * derived from this software without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00022 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00023 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00024 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00025 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00026 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00027 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00028 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00029 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00030 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00031 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00032 * POSSIBILITY OF SUCH DAMAGE. 00033 */ 00034 // @author Brett Ponsler (bponsler (at) wpi (dot) edu) 00035 #include "ap_human_waiting_state.h" 00036 00037 #include "../../events/event_factory.h" 00038 #include "../../lib/engagement_params.h" 00039 #include "../../objects/engagement_objects.h" 00040 00041 APHumanWaitingState::APHumanWaitingState() : 00042 State(APHumanWaitingState::type(), "", NULL) 00043 { 00044 // Set the logger based on this type of recognizer 00045 this->setLogger(EngagementParams::getStateTag(APHumanWaitingState::type())); 00046 00047 this->warn("Initialized with an invalid actor, and EventSink."); 00048 } 00049 00050 APHumanWaitingState::APHumanWaitingState(std::string actor, EventSink *sink) : 00051 State(APHumanWaitingState::type(), actor, sink) 00052 { 00053 // Set the logger based on this type of recognizer 00054 this->setLogger(sink->getLogger(), 00055 EngagementParams::getStateTag(APHumanWaitingState::type())); 00056 } 00057 00058 APHumanWaitingState::~APHumanWaitingState() 00059 { 00060 } 00061 00062 Event APHumanWaitingState::received(std::string topic, 00063 engagement_msgs::ActorIDStatus *message) 00064 { 00065 if (topic == engagement::RECOGNITION_NAMESPACE + "/" + 00066 engagement::HUMAN_NAMESPACE + "/" + 00067 engagement::RECOG_STATUS_TOPIC.c_str()) 00068 return this->engageStatusCallback(message); 00069 00070 return Event(); 00071 } 00072 00073 Event APHumanWaitingState::received(std::string topic, 00074 engagement_msgs::Performance *message) 00075 { 00076 if (topic == engagement::PERFORMING_NAMESPACE + "/" + engagement::PERFORMING_NOD_TOPIC) 00077 return this->performingNodCallback(message); 00078 else if (topic == engagement::PERFORMING_NAMESPACE + "/" + engagement::PERFORMING_SHAKE_TOPIC) 00079 return this->performingShakeCallback(message); 00080 else if (topic == engagement::PERFORMING_NAMESPACE + "/" + engagement::PERFORMING_LOOK_TOPIC) 00081 return this->performingLookCallback(message); 00082 else if (topic == engagement::PERFORMING_NAMESPACE + "/" + engagement::PERFORMING_POINT_TOPIC) 00083 return this->performingPointCallback(message); 00084 00085 return Event(); 00086 } 00087 00088 Event APHumanWaitingState::received(std::string topic, 00089 engagement_msgs::Speech *message) 00090 { 00091 if (topic == engagement::PERFORMING_NAMESPACE + "/" + engagement::PERFORMING_UTTERANCE_TOPIC) 00092 return this->performingUtteranceCallback(message); 00093 00094 return Event(); 00095 } 00096 00097 Event APHumanWaitingState::engageStatusCallback(const engagement_msgs::ActorIDStatus *msg) 00098 { 00099 this->debug(25, "Entered %s %s %s", 00100 engagement::RECOGNITION_NAMESPACE.c_str(), 00101 engagement::HUMAN_NAMESPACE.c_str(), 00102 engagement::RECOG_STATUS_TOPIC.c_str()); 00103 00104 // Make sure we have a valid message 00105 if (msg) 00106 { 00107 // Grab the message type from the constant pointer 00108 engagement_msgs::ActorIDStatus temp_msg = *msg; 00109 00110 // Cast ourselves into a state 00111 State *state = (State*)this; 00112 00113 // Grab the actor from the state 00114 Actor *actor = state->getActor(); 00115 00116 // Make sure the actor in the message is the same 00117 // and that the message flag is FALSE (unengaged) 00118 if (actor != NULL && temp_msg.actor.id == actor->getID() && 00119 temp_msg.status.value == bml_msgs::Flag::FALSE) 00120 { 00121 // The actor for this recognizer has become unengaged 00122 // the connection event has failed. 00123 this->debug(7, "Received false %s message.", 00124 engagement::RECOG_STATUS_TOPIC.c_str()); 00125 00126 // Create the failure event 00127 return EventFactory::failed(); 00128 } 00129 } 00130 00131 return Event(); 00132 } 00133 00134 Event APHumanWaitingState::performingUtteranceCallback(const engagement_msgs::Speech *msg) 00135 { 00136 this->debug(25, "Entered %s %s", 00137 engagement::PERFORMING_NAMESPACE.c_str(), 00138 engagement::PERFORMING_UTTERANCE_TOPIC.c_str()); 00139 00140 // Make sure we have a valid message 00141 if (msg) 00142 { 00143 // Grab the message type from the constant pointer 00144 engagement_msgs::Speech temp_msg = *msg; 00145 00146 // Cast ourselves into a state 00147 State *state = (State*)this; 00148 00149 // Grab the actor from the state 00150 Actor *actor = state->getActor(); 00151 00152 // If this relates to this actor, and is beginning 00153 if (actor != NULL && temp_msg.actor.id == actor->getID() && 00154 temp_msg.begin.value == bml_msgs::Flag::BEGIN) 00155 { 00156 this->debug(7, "Received [%s] start Utterance message.", 00157 temp_msg.actor.id.c_str()); 00158 00159 // Create the human initiated event 00160 return EventFactory::humanInitiated(); 00161 } 00162 else if (temp_msg.actor.id == temp_msg.actor.ROBOT && 00163 temp_msg.begin.value == bml_msgs::Flag::BEGIN) 00164 { 00165 this->debug(7, "Received ROBOT start %s message.", 00166 engagement::PERFORMING_UTTERANCE_TOPIC.c_str()); 00167 00168 // Add the speech action used to succeed the event to the additional data 00169 std::vector<std::string> additional = std::vector<std::string>(); 00170 additional.push_back(Action::SPEECH); 00171 additional.push_back("determine what the robot said"); 00172 00173 // Create the success event 00174 return EventFactory::success(additional); 00175 } 00176 else if (actor != NULL && temp_msg.actor.id == actor->getID() && 00177 temp_msg.begin.value == bml_msgs::Flag::END && 00178 temp_msg.response.value == bml_msgs::Flag::OPTIONAL_RESPONSE) 00179 { 00180 this->debug(7, "Received [%s] end %s message.", 00181 temp_msg.actor.id.c_str(), 00182 engagement::PERFORMING_UTTERANCE_TOPIC.c_str()); 00183 00184 // Create the failed event 00185 return EventFactory::failed(); 00186 } 00187 } 00188 00189 return Event(); 00190 } 00191 00192 Event APHumanWaitingState::performingShakeCallback(const engagement_msgs::Performance *msg) 00193 { 00194 this->debug(25, "Entered %s %s", 00195 engagement::PERFORMING_NAMESPACE.c_str(), 00196 engagement::PERFORMING_SHAKE_TOPIC.c_str()); 00197 00198 // Make sure we have a valid message 00199 if (msg) 00200 { 00201 this->debug(7, "Received %s %s message.", 00202 engagement::PERFORMING_NAMESPACE.c_str(), 00203 engagement::PERFORMING_SHAKE_TOPIC.c_str()); 00204 00205 // Add the shake action used to succeed the event to the additional data 00206 std::vector<std::string> additional = std::vector<std::string>(); 00207 additional.push_back(Action::SHAKE); 00208 00209 // Create the completed event 00210 return EventFactory::completed(additional); 00211 } 00212 00213 return Event(); 00214 } 00215 00216 Event APHumanWaitingState::performingNodCallback(const engagement_msgs::Performance *msg) 00217 { 00218 this->debug(25, "Entered %s %s", 00219 engagement::PERFORMING_NAMESPACE.c_str(), 00220 engagement::PERFORMING_NOD_TOPIC.c_str()); 00221 00222 // Make sure we have a valid message 00223 if (msg) 00224 { 00225 this->debug(7, "Received %s %s message.", 00226 engagement::PERFORMING_NAMESPACE.c_str(), 00227 engagement::PERFORMING_NOD_TOPIC.c_str()); 00228 00229 // Add the nod action used to succeed the event to the additional data 00230 std::vector<std::string> additional = std::vector<std::string>(); 00231 additional.push_back(Action::NOD); 00232 00233 // Create the completed event 00234 return EventFactory::completed(additional); 00235 } 00236 00237 return Event(); 00238 } 00239 00240 Event APHumanWaitingState::performingLookCallback(const engagement_msgs::Performance *msg) 00241 { 00242 this->debug(25, "Entered %s %s", 00243 engagement::PERFORMING_NAMESPACE.c_str(), 00244 engagement::PERFORMING_LOOK_TOPIC.c_str()); 00245 00246 // Make sure we have a valid message 00247 if (msg) 00248 { 00249 // Grab the message type from the constant pointer 00250 engagement_msgs::Performance temp_msg = *msg; 00251 00252 // Check the message begin flag to be BEGIN (begin looking) 00253 if (temp_msg.begin.value == bml_msgs::Flag::BEGIN) 00254 { 00255 // It does not matter what objects were looked at 00256 this->debug(7, "Received %s %s message.", 00257 engagement::PERFORMING_NAMESPACE.c_str(), 00258 engagement::PERFORMING_LOOK_TOPIC.c_str()); 00259 00260 // Add the look action used to succeed the event to the additional data 00261 std::vector<std::string> additional = std::vector<std::string>(); 00262 additional.push_back(Action::LOOK); 00263 00264 if (temp_msg.objects.size() > 0) 00265 additional.push_back(temp_msg.objects.at(0).id); 00266 00267 // Create the completed event 00268 return EventFactory::completed(additional); 00269 } 00270 } 00271 00272 return Event(); 00273 } 00274 00275 Event APHumanWaitingState::performingPointCallback(const engagement_msgs::Performance *msg) 00276 { 00277 this->debug(25, "Entered %s %s", 00278 engagement::PERFORMING_NAMESPACE.c_str(), 00279 engagement::PERFORMING_POINT_TOPIC.c_str()); 00280 00281 // Make sure we have a valid message 00282 if (msg) 00283 { 00284 // Grab the message type from the constant pointer 00285 engagement_msgs::Performance temp_msg = *msg; 00286 00287 // Check the message begin flag to be BEGIN (begin looking) 00288 if (temp_msg.begin.value == bml_msgs::Flag::BEGIN) 00289 { 00290 // It does not matter what objects were pointed at 00291 this->debug(7, "Received %s %s message.", 00292 engagement::PERFORMING_NAMESPACE.c_str(), 00293 engagement::PERFORMING_POINT_TOPIC.c_str()); 00294 00295 // Add the point action used to succeed the event to the additional data 00296 std::vector<std::string> additional = std::vector<std::string>(); 00297 additional.push_back(Action::POINT); 00298 00299 if (temp_msg.objects.size() > 0) 00300 additional.push_back(temp_msg.objects.at(0).id); 00301 00302 // Create the completed event 00303 return EventFactory::completed(additional); 00304 } 00305 } 00306 00307 return Event(); 00308 } 00309 00310 std::string APHumanWaitingState::type() 00311 { 00312 return "ap_human_waiting"; 00313 } |