Project: engagement_recognition License: BSD Dependencies:
Used by:
None |
engagement_recognition/src/recognition/recognizers/directed_gaze/dg_shared_gaze_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 "dg_shared_gaze_state.h" 00036 00037 #include "../../events/event_factory.h" 00038 #include "../../lib/engagement_params.h" 00039 #include "../../objects/engagement_objects.h" 00040 00041 DGSharedGazeState::DGSharedGazeState() : 00042 State(DGSharedGazeState::type(), "", NULL) 00043 { 00044 // Set the logger based on this type of recognizer 00045 this->setLogger(EngagementParams::getStateTag(DGSharedGazeState::type())); 00046 00047 this->warn("[%s] state initialized with an invalid actor, and EventSink."); 00048 } 00049 00050 DGSharedGazeState::DGSharedGazeState(std::string actor, EventSink *sink) : 00051 State(DGSharedGazeState::type(), actor, sink) 00052 { 00053 // Set the logger based on this type of recognizer 00054 this->setLogger(sink->getLogger(), 00055 EngagementParams::getStateTag(DGSharedGazeState::type())); 00056 00057 if (actor == "") 00058 this->warn("Initialized with an invalid actor."); 00059 } 00060 00061 DGSharedGazeState::~DGSharedGazeState() 00062 { 00063 } 00064 00065 Event DGSharedGazeState::received(std::string topic, 00066 engagement_srvs::RobotMutualFacialGaze::Request *message) 00067 { 00068 if (topic == engagement::RECOGNITION_NAMESPACE + "/" + 00069 engagement::ROBOT_NAMESPACE + "/" + engagement::RECOG_MUTUAL_FACIAL_GAZE_TOPIC) 00070 return this->recogMFGazeCallback(message); 00071 00072 return Event(); 00073 } 00074 00075 Event DGSharedGazeState::received(std::string topic, engagement_msgs::ActorIDStatus *message) 00076 { 00077 if (topic == engagement::RECOGNITION_NAMESPACE + "/" + 00078 engagement::HUMAN_NAMESPACE + "/" + 00079 engagement::RECOG_STATUS_TOPIC.c_str()) 00080 return this->engageStatusCallback(message); 00081 00082 return Event(); 00083 } 00084 00085 Event DGSharedGazeState::received(std::string topic, 00086 engagement_msgs::Performance *message) 00087 { 00088 if (topic == engagement::VISION_NAMESPACE + "/" + engagement::PERFORMING_FACIAL_GAZE_TOPIC) 00089 return this->visionFacialGazeCallback(message); 00090 else if (topic == engagement::VISION_NAMESPACE + "/" + engagement::PERFORMING_LOOK_TOPIC) 00091 return this->visionLookCallback(message); 00092 else if (topic == engagement::PERFORMING_NAMESPACE + "/" + engagement::PERFORMING_LOOK_TOPIC) 00093 return this->performingLookCallback(message); 00094 00095 return Event(); 00096 } 00097 00098 Event DGSharedGazeState::received(std::string topic, engagement_srvs::RobotDirectedGaze::Request *message) 00099 { 00100 if (topic == engagement::RECOGNITION_NAMESPACE + "/" + 00101 engagement::ROBOT_NAMESPACE + "/" + engagement::RECOG_DIRECTED_GAZE_TOPIC) 00102 return this->recogDirGazeCallback(message); 00103 00104 return Event(); 00105 } 00106 00107 Event DGSharedGazeState::performingLookCallback(const engagement_msgs::Performance *msg) 00108 { 00109 this->debug(25, "Entered %s %s", 00110 engagement::PERFORMING_NAMESPACE.c_str(), 00111 engagement::PERFORMING_LOOK_TOPIC.c_str()); 00112 00113 // Make sure we have a valid message 00114 if (msg) 00115 { 00116 // Grab the message type from the constant pointer 00117 engagement_msgs::Performance temp_msg = *msg; 00118 00119 // Grab the objects from the entities in the message 00120 std::vector<std::string> objects = 00121 objects::getObjectsFromEntities(temp_msg.objects); 00122 00123 // Determine if this is beginning or ending 00124 if (temp_msg.begin.value == bml_msgs::Flag::BEGIN) 00125 { 00126 // Success is contingent upon whether or not the objects are different 00127 if (!this->compareAdditional(objects, EventSink::CONTAINS)) 00128 { 00129 this->debug(7, "Received begin %s %s message", 00130 engagement::PERFORMING_NAMESPACE.c_str(), 00131 engagement::PERFORMING_LOOK_TOPIC.c_str()); 00132 00133 // A connection event completed successfully 00134 return EventFactory::success(); 00135 } 00136 } 00137 else 00138 { 00139 // Success is contingent upon whether or not the objects are the same 00140 if (this->compareAdditional(objects, EventSink::CONTAINS)) 00141 { 00142 this->debug(7, "Received end %s %s message.", 00143 engagement::PERFORMING_NAMESPACE.c_str(), 00144 engagement::PERFORMING_LOOK_TOPIC.c_str()); 00145 00146 // A connection event completed successfully 00147 return EventFactory::success(); 00148 } 00149 } 00150 } 00151 00152 return Event(); 00153 } 00154 00155 Event DGSharedGazeState::recogMFGazeCallback(const engagement_srvs::RobotMutualFacialGaze::Request *msg) 00156 { 00157 this->debug(25, "Entered %s %s", 00158 engagement::RECOGNITION_NAMESPACE.c_str(), 00159 engagement::RECOG_MUTUAL_FACIAL_GAZE_TOPIC.c_str()); 00160 00161 // Make sure we have a valid message 00162 if (msg) 00163 { 00164 // Grab the message type from the constant pointer 00165 engagement_srvs::RobotMutualFacialGaze::Request temp_msg = *msg; 00166 00167 // Cast ourselves into a state 00168 State *state = (State*)this; 00169 00170 // Grab the actor from the state 00171 Actor *actor = state->getActor(); 00172 00173 // Make sure this message relates to the actor for this recognizer 00174 // and that the action is beginning 00175 if (actor != NULL && temp_msg.actor.id == actor->getID()) 00176 { 00177 this->debug(7, "Received %s %s message", 00178 engagement::RECOGNITION_NAMESPACE.c_str(), 00179 engagement::RECOG_MUTUAL_FACIAL_GAZE_TOPIC.c_str()); 00180 00181 // A connection event completed successfully 00182 return EventFactory::success(); 00183 } 00184 } 00185 00186 return Event(); 00187 } 00188 00189 Event DGSharedGazeState::recogDirGazeCallback(const engagement_srvs::RobotDirectedGaze::Request *msg) 00190 { 00191 this->debug(25, "Entered %s %s", 00192 engagement::RECOGNITION_NAMESPACE.c_str(), 00193 engagement::RECOG_DIRECTED_GAZE_TOPIC.c_str()); 00194 00195 // Make sure we have a valid message 00196 if (msg) 00197 { 00198 // Grab the message type from the constant pointer 00199 engagement_srvs::RobotDirectedGaze::Request temp_msg = *msg; 00200 00201 // Grab the objects from the entities in the message 00202 std::vector<std::string> objects = 00203 objects::getObjectsFromEntities(temp_msg.objects); 00204 00205 // As long as the message is beginning we complete successfully 00206 if (temp_msg.done.value == bml_msgs::Flag::NOT_DONE) 00207 { 00208 // If the objects are the same we cycle 00209 if (this->compareAdditional(objects, EventSink::CONTAINS)) 00210 { 00211 this->debug(7, "Received %s %s at same objects message.", 00212 engagement::RECOGNITION_NAMESPACE.c_str(), 00213 engagement::RECOG_DIRECTED_GAZE_TOPIC.c_str()); 00214 00215 // A connection event completed successfully 00216 return EventFactory::sharedGaze(); 00217 } 00218 else 00219 { 00220 this->debug(7, "Received %s %s at different objects message.", 00221 engagement::RECOGNITION_NAMESPACE.c_str(), 00222 engagement::RECOG_DIRECTED_GAZE_TOPIC.c_str()); 00223 00224 // A Robot initiated event 00225 return EventFactory::robotInitiated(); 00226 } 00227 } 00228 } 00229 00230 return Event(); 00231 } 00232 00233 Event DGSharedGazeState::visionLookCallback(const engagement_msgs::Performance *msg) 00234 { 00235 this->debug(25, "Entered %s %s", 00236 engagement::VISION_NAMESPACE.c_str(), 00237 engagement::PERFORMING_LOOK_TOPIC.c_str()); 00238 00239 // Make sure we have a valid message 00240 if (msg) 00241 { 00242 // Grab the message type from the constant pointer 00243 engagement_msgs::Performance temp_msg = *msg; 00244 00245 // Cast ourselves into a state 00246 State *state = (State*)this; 00247 00248 // Grab the actor from the state 00249 Actor *actor = state->getActor(); 00250 std::vector<std::string> objects = 00251 objects::getObjectsFromEntities(temp_msg.objects); 00252 00253 // Make sure this message relates to the actor for this recognizer 00254 if (actor != NULL && temp_msg.actor.id == actor->getID()) 00255 { 00256 // Determine if the look is starting or ending 00257 if (temp_msg.begin.value == bml_msgs::Flag::BEGIN) 00258 { 00259 // Success is contingent upon whether or not the objects are different 00260 if (!this->compareAdditional(objects, EventSink::CONTAINS)) 00261 { 00262 this->debug(7, "Received Begin %s %s message", 00263 engagement::VISION_NAMESPACE.c_str(), 00264 engagement::PERFORMING_LOOK_TOPIC.c_str()); 00265 00266 // Create a success event 00267 return EventFactory::success(); 00268 } 00269 } 00270 else 00271 { 00272 // Success is contingent upon whether or not the objects are the same 00273 if (this->compareAdditional(objects, EventSink::CONTAINS)) 00274 { 00275 this->debug(7, "Received End %s %s message.", 00276 engagement::VISION_NAMESPACE.c_str(), 00277 engagement::PERFORMING_LOOK_TOPIC.c_str()); 00278 00279 // Create a success event 00280 return EventFactory::success(); 00281 } 00282 } 00283 } 00284 } 00285 00286 return Event(); 00287 } 00288 00289 Event DGSharedGazeState::visionFacialGazeCallback(const engagement_msgs::Performance *msg) 00290 { 00291 this->debug(25, "Entered %s %s", 00292 engagement::VISION_NAMESPACE.c_str(), 00293 engagement::PERFORMING_FACIAL_GAZE_TOPIC.c_str()); 00294 00295 // Make sure we have a valid message 00296 if (msg) 00297 { 00298 // Grab the message type from the constant pointer 00299 engagement_msgs::Performance temp_msg = *msg; 00300 00301 // Cast ourselves into a state 00302 State *state = (State*)this; 00303 00304 // Grab the actor from the state 00305 Actor *actor = state->getActor(); 00306 00307 // Make sure this message relates to the actor for this recognizer 00308 // and that the point is starting 00309 if (actor != NULL && temp_msg.actor.id == actor->getID() && 00310 temp_msg.begin.value == bml_msgs::Flag::BEGIN) 00311 { 00312 this->debug(7, "Received Begin %s %s message.", 00313 engagement::VISION_NAMESPACE.c_str(), 00314 engagement::PERFORMING_FACIAL_GAZE_TOPIC.c_str()); 00315 00316 // Create a success event 00317 return EventFactory::success(); 00318 } 00319 } 00320 00321 return Event(); 00322 } 00323 00324 Event DGSharedGazeState::engageStatusCallback(const engagement_msgs::ActorIDStatus *msg) 00325 { 00326 this->debug(25, "Entered %s %s %s", 00327 engagement::RECOGNITION_NAMESPACE.c_str(), 00328 engagement::HUMAN_NAMESPACE.c_str(), 00329 engagement::RECOG_STATUS_TOPIC.c_str()); 00330 00331 // Make sure we have a valid message 00332 if (msg) 00333 { 00334 // Grab the message type from the constant pointer 00335 engagement_msgs::ActorIDStatus temp_msg = *msg; 00336 00337 // Cast ourselves into a state 00338 State *state = (State*)this; 00339 00340 // Grab the actor from the state 00341 Actor *actor = state->getActor(); 00342 00343 // Make sure it has to deal with this actor, and that the flag is FALSE 00344 if (actor != NULL && temp_msg.actor.id == actor->getID() && 00345 temp_msg.status.value == bml_msgs::Flag::FALSE) 00346 { 00347 this->debug(7, "Received false %s message.", 00348 engagement::RECOG_STATUS_TOPIC.c_str()); 00349 00350 // Create a success event 00351 return EventFactory::success(); 00352 } 00353 } 00354 00355 return Event(); 00356 } 00357 00358 std::string DGSharedGazeState::type() 00359 { 00360 return "dg_shared_gaze"; 00361 } 00362 |