Project: engagement_recognition License: BSD Dependencies:
Used by:
None |
engagement_recognition/src/recognition/recognizers/mutual_facial_gaze/mfg_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 "mfg_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 MFGHumanWaitingState::MFGHumanWaitingState() : 00042 State(MFGHumanWaitingState::type(), "", NULL) 00043 { 00044 // Set the logger based on this type of recognizer 00045 this->setLogger(EngagementParams::getStateTag(MFGHumanWaitingState::type())); 00046 00047 this->warn("Initialized with an invalid actor, and EventSink."); 00048 } 00049 00050 MFGHumanWaitingState::MFGHumanWaitingState(std::string actor, EventSink *sink) : 00051 State(MFGHumanWaitingState::type(), actor, sink) 00052 { 00053 // Set the logger based on this type of recognizer 00054 this->setLogger(sink->getLogger(), 00055 EngagementParams::getStateTag(MFGHumanWaitingState::type())); 00056 } 00057 00058 MFGHumanWaitingState::~MFGHumanWaitingState() 00059 { 00060 } 00061 00062 Event MFGHumanWaitingState::received(std::string topic, 00063 engagement_srvs::RobotMutualFacialGaze::Request *message) 00064 { 00065 if (topic == engagement::RECOGNITION_NAMESPACE + "/" + 00066 engagement::ROBOT_NAMESPACE + "/" + engagement::RECOG_MUTUAL_FACIAL_GAZE_TOPIC) 00067 return this->recogMFGazeCallback(message); 00068 00069 return Event(); 00070 } 00071 00072 Event MFGHumanWaitingState::received(std::string topic, 00073 engagement_msgs::ActorIDStatus *message) 00074 { 00075 if (topic == engagement::RECOGNITION_NAMESPACE + "/" + 00076 engagement::HUMAN_NAMESPACE + "/" + 00077 engagement::RECOG_STATUS_TOPIC.c_str()) 00078 return this->engageStatusCallback(message); 00079 00080 return Event(); 00081 } 00082 00083 Event MFGHumanWaitingState::received(std::string topic, 00084 engagement_msgs::Performance *message) 00085 { 00086 if (topic == engagement::VISION_NAMESPACE + "/" + engagement::PERFORMING_FACIAL_GAZE_TOPIC) 00087 return this->visionFacialGazeCallback(message); 00088 else if (topic == engagement::PERFORMING_NAMESPACE + "/" + engagement::PERFORMING_LOOK_TOPIC) 00089 return this->performingLookCallback(message); 00090 else if (topic == engagement::VISION_NAMESPACE + "/" + engagement::PERFORMING_LOOK_TOPIC) 00091 return this->visionLookCallback(message); 00092 00093 return Event(); 00094 } 00095 00096 Event MFGHumanWaitingState::engageStatusCallback(const engagement_msgs::ActorIDStatus *msg) 00097 { 00098 this->debug(25, "Entered %s %s %s", 00099 engagement::RECOGNITION_NAMESPACE.c_str(), 00100 engagement::HUMAN_NAMESPACE.c_str(), 00101 engagement::RECOG_STATUS_TOPIC.c_str()); 00102 00103 // Make sure we have a valid message 00104 if (msg) 00105 { 00106 // Grab the message type from the constant pointer 00107 engagement_msgs::ActorIDStatus temp_msg = *msg; 00108 00109 // Cast ourselves into a state 00110 State *state = (State*)this; 00111 00112 // Grab the actor from the state 00113 Actor *actor = state->getActor(); 00114 00115 // Make sure the actor in the message is the same 00116 // and that the message flag is FALSE (unengaged) 00117 if (actor != NULL && temp_msg.actor.id == actor->getID() && 00118 temp_msg.status.value == bml_msgs::Flag::FALSE) 00119 { 00120 // The actor for this recognizer has become unengaged 00121 // the connection event has failed. 00122 this->debug(7, "Received %s message.", 00123 engagement::RECOG_STATUS_TOPIC.c_str()); 00124 00125 // Create the failure event 00126 return EventFactory::failed(); 00127 } 00128 } 00129 00130 return Event(); 00131 } 00132 00133 Event MFGHumanWaitingState::performingLookCallback(const engagement_msgs::Performance *msg) 00134 { 00135 this->debug(25, "Entered %s %s", 00136 engagement::PERFORMING_NAMESPACE.c_str(), 00137 engagement::PERFORMING_LOOK_TOPIC.c_str()); 00138 00139 // Make sure we have a valid message 00140 if (msg) 00141 { 00142 // Grab the message type from the constant pointer 00143 engagement_msgs::Performance temp_msg = *msg; 00144 00145 // Cast ourselves into a state 00146 State *state = (State*)this; 00147 00148 // Grab the actor from the state 00149 Actor *actor = state->getActor(); 00150 00151 this->debug(0, "performing look actor: [%s]", temp_msg.actor.id.c_str()); 00152 00153 // So long as this message is instructing us to BEGIN looking 00154 // at the SAME actor we enter shared gaze 00155 if (actor != NULL && temp_msg.actor.id == temp_msg.actor.ROBOT && 00156 temp_msg.begin.value == bml_msgs::Flag::BEGIN && 00157 objects::isFace(temp_msg.objects, actor->getID())) 00158 { 00159 this->debug(7, "Received %s %s message.", 00160 engagement::PERFORMING_NAMESPACE.c_str(), 00161 engagement::PERFORMING_LOOK_TOPIC.c_str()); 00162 00163 // Create the shared gaze event 00164 return EventFactory::sharedGaze(); 00165 } 00166 } 00167 00168 return Event(); 00169 } 00170 00171 Event MFGHumanWaitingState::recogMFGazeCallback(const engagement_srvs::RobotMutualFacialGaze::Request *msg) 00172 { 00173 this->debug(25, "Entered %s %s", 00174 engagement::RECOGNITION_NAMESPACE.c_str(), 00175 engagement::RECOG_MUTUAL_FACIAL_GAZE_TOPIC.c_str()); 00176 00177 // Make sure we have a valid message 00178 if (msg) 00179 { 00180 // Grab the message type from the constant pointer 00181 engagement_srvs::RobotMutualFacialGaze::Request temp_msg = *msg; 00182 00183 // Cast ourselves into a state 00184 State *state = (State*)this; 00185 00186 // Grab the actor from the state 00187 Actor *actor = state->getActor(); 00188 00189 // If the mutual facial gaze is for the same actor then complete 00190 if (actor != NULL && temp_msg.actor.id == actor->getID()) 00191 { 00192 // There are no requirements on this message. If we received it 00193 // we want to issue a shared gaze event. 00194 this->debug(7, "Received %s %s message.", 00195 engagement::RECOGNITION_NAMESPACE.c_str(), 00196 engagement::RECOG_MUTUAL_FACIAL_GAZE_TOPIC.c_str()); 00197 00198 // Create a shared gaze event 00199 return EventFactory::sharedGaze(); 00200 } 00201 } 00202 00203 return Event(); 00204 } 00205 00206 Event MFGHumanWaitingState::visionLookCallback(const engagement_msgs::Performance *msg) 00207 { 00208 this->debug(25, "Entered %s %s", 00209 engagement::VISION_NAMESPACE.c_str(), 00210 engagement::PERFORMING_LOOK_TOPIC.c_str()); 00211 00212 // Make sure we have a valid message 00213 if (msg) 00214 { 00215 // Grab the message type from the constant pointer 00216 engagement_msgs::Performance temp_msg = *msg; 00217 00218 // Cast ourselves into a state 00219 State *state = (State*)this; 00220 00221 // Grab the actor from the state 00222 Actor *actor = state->getActor(); 00223 00224 // So long as the message relates to the SAME actor 00225 // STARTING to look at objects we fail 00226 if (actor != NULL && temp_msg.actor.id == actor->getID() && 00227 temp_msg.begin.value == bml_msgs::Flag::BEGIN) 00228 { 00229 this->debug(7, "Received %s %s message.", 00230 engagement::VISION_NAMESPACE.c_str(), 00231 engagement::PERFORMING_LOOK_TOPIC.c_str()); 00232 00233 // Create the failure event 00234 return EventFactory::failed(); 00235 } 00236 } 00237 00238 return Event(); 00239 } 00240 00241 Event MFGHumanWaitingState::visionFacialGazeCallback(const engagement_msgs::Performance *msg) 00242 { 00243 this->debug(25, "Entered %s %s", 00244 engagement::VISION_NAMESPACE.c_str(), 00245 engagement::PERFORMING_FACIAL_GAZE_TOPIC.c_str()); 00246 00247 // Make sure we have a valid message 00248 if (msg) 00249 { 00250 // Grab the message type from the constant pointer 00251 engagement_msgs::Performance temp_msg = *msg; 00252 00253 // Cast ourselves into a state 00254 State *state = (State*)this; 00255 00256 // Grab the actor from the state 00257 Actor *actor = state->getActor(); 00258 00259 // So long as the message indicates the SAME actor is ENDING facial gaze 00260 if (actor != NULL && temp_msg.actor.id == actor->getID() && 00261 temp_msg.begin.value == bml_msgs::Flag::END && 00262 objects::isFace(temp_msg.objects, temp_msg.actor.ROBOT)) 00263 { 00264 this->debug(7, "Received %s %s message.", 00265 engagement::VISION_NAMESPACE.c_str(), 00266 engagement::PERFORMING_FACIAL_GAZE_TOPIC.c_str()); 00267 00268 // Create the failure event 00269 return EventFactory::failed(); 00270 } 00271 } 00272 00273 return Event(); 00274 } 00275 00276 std::string MFGHumanWaitingState::type() 00277 { 00278 return "mfg_human_waiting"; 00279 } 00280 |