Project: engagement_recognition License: BSD Dependencies:
Used by:
None |
engagement_recognition/src/recognition/recognizers/mutual_facial_gaze/mfg_start_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_start_state.h" 00036 00037 #include "../../events/event_factory.h" 00038 #include "../../lib/engagement_params.h" 00039 #include "../../objects/engagement_objects.h" 00040 00041 MFGStartState::MFGStartState() : 00042 State(MFGStartState::type(), "", NULL) 00043 { 00044 // Set the logger based on this type of recognizer 00045 this->setLogger(EngagementParams::getStateTag(MFGStartState::type())); 00046 00047 this->warn("Initialized with an invalid actor, and EventSink."); 00048 } 00049 00050 MFGStartState::MFGStartState(std::string actor, EventSink *sink) : 00051 State(MFGStartState::type(), actor, sink) 00052 { 00053 // Set the logger based on this type of recognizer 00054 this->setLogger(sink->getLogger(), 00055 EngagementParams::getStateTag(MFGStartState::type())); 00056 00057 if (actor == "") 00058 this->warn("Initialized with an invalid actor."); 00059 } 00060 00061 MFGStartState::~MFGStartState() 00062 { 00063 } 00064 00065 Event MFGStartState::received(std::string topic, engagement_srvs::RobotMutualFacialGaze::Request *message) 00066 { 00067 if (topic == engagement::RECOGNITION_NAMESPACE + "/" + 00068 engagement::ROBOT_NAMESPACE + "/" + engagement::RECOG_MUTUAL_FACIAL_GAZE_TOPIC) 00069 return this->recogMFGazeCallback(message); 00070 00071 return Event(); 00072 } 00073 00074 Event MFGStartState::received(std::string topic, engagement_msgs::Performance *message) 00075 { 00076 if (topic == engagement::VISION_NAMESPACE + "/" + engagement::PERFORMING_FACIAL_GAZE_TOPIC) 00077 return this->visionFacialGazeCallback(message); 00078 00079 return Event(); 00080 } 00081 00082 Event MFGStartState::recogMFGazeCallback(const engagement_srvs::RobotMutualFacialGaze::Request *msg) 00083 { 00084 this->debug(25, "Entered %s %s", 00085 engagement::RECOGNITION_NAMESPACE.c_str(), 00086 engagement::RECOG_MUTUAL_FACIAL_GAZE_TOPIC.c_str()); 00087 00088 // Make sure we have a valid message 00089 if (msg) 00090 { 00091 // Grab the message type from the constant pointer 00092 engagement_srvs::RobotMutualFacialGaze::Request temp_msg = *msg; 00093 00094 // Cast ourselves into a state 00095 State *state = (State*)this; 00096 00097 // Grab the actor from the state 00098 Actor *actor = state->getActor(); 00099 00100 // Make sure this message relates to the actor for this recognizer and that 00101 // the message flag is TRUE 00102 if (actor != NULL && temp_msg.actor.id == actor->getID()) 00103 { 00104 // Determine if the actor is already looking at the robot's face 00105 if (actor->isFacialGaze()) 00106 { 00107 this->debug(7, "Received %s %s message.", 00108 engagement::RECOGNITION_NAMESPACE.c_str(), 00109 engagement::RECOG_MUTUAL_FACIAL_GAZE_TOPIC.c_str()); 00110 00111 // Create the additional vector with the robot as the initiator 00112 std::vector<std::string> additional; 00113 additional.push_back("ROBOT"); 00114 00115 // Create the shared gaze event, with the additional data 00116 return EventFactory::sharedGaze(additional); 00117 } 00118 else 00119 { 00120 this->debug(7, "Received %s %s message.", 00121 engagement::RECOGNITION_NAMESPACE.c_str(), 00122 engagement::RECOG_MUTUAL_FACIAL_GAZE_TOPIC.c_str()); 00123 00124 // Create a Robot initiated event 00125 return EventFactory::robotInitiated(); 00126 } 00127 } 00128 } 00129 00130 return Event(); 00131 } 00132 00133 Event MFGStartState::visionFacialGazeCallback(const engagement_msgs::Performance *msg) 00134 { 00135 this->debug(25, "Entered %s %s", 00136 engagement::VISION_NAMESPACE.c_str(), 00137 engagement::PERFORMING_FACIAL_GAZE_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 // Make sure this message relates to the actor for this recognizer 00152 // and that the facial gaze is starting 00153 if (actor != NULL && temp_msg.actor.id == actor->getID() && 00154 temp_msg.begin.value == bml_msgs::Flag::BEGIN && 00155 objects::isFace(temp_msg.objects, temp_msg.actor.ROBOT)) 00156 { 00157 this->debug(7, "Received begin %s %s message.", 00158 engagement::VISION_NAMESPACE.c_str(), 00159 engagement::PERFORMING_FACIAL_GAZE_TOPIC.c_str()); 00160 00161 // Success is contingent upon whether the robot is already looking 00162 // at the actor's face 00163 if (Robot::isFacialGaze(temp_msg.actor.id)) 00164 { 00165 // Create the additional vector with the human as the initiator 00166 std::vector<std::string> additional; 00167 additional.push_back("HUMAN"); 00168 00169 // Create a shared gaze event, with the additional data 00170 return EventFactory::sharedGaze(additional); 00171 } 00172 else 00173 { 00174 // Create the human initiated event 00175 return EventFactory::humanInitiated(); 00176 } 00177 } 00178 } 00179 00180 return Event(); 00181 } 00182 00183 std::string MFGStartState::type() 00184 { 00185 return "mfg_start"; 00186 } 00187 |