Project: engagement_recognition License: BSD Dependencies:
Used by:
None |
engagement_recognition/src/recognition/rnode/callbacks/performing.hGo 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 #ifndef _PERFORMING_H 00036 #define _PERFORMING_H 00037 00038 void RNode::performingLookCallback(const engagement_msgs::PerformanceConstPtr& msg) 00039 { 00040 this->debug(24, "Entered %s %s callback", 00041 engagement::PERFORMING_NAMESPACE.c_str(), 00042 engagement::PERFORMING_LOOK_TOPIC.c_str()); 00043 00044 // Make sure we have a valid message 00045 if (msg) 00046 { 00047 // Grab the message type from the constant pointer 00048 engagement_msgs::Performance temp_msg = *msg; 00049 00050 // Grab the vector of objects from the vector of entities 00051 std::vector<std::string> msg_objects = 00052 objects::getObjectsFromEntities(temp_msg.objects); 00053 00054 // Determine if the message is for an actor 00055 if (temp_msg.actor.id != temp_msg.actor.ROBOT) 00056 { 00057 // Call the method to handle input pertaining to the actor 00058 if (!objects::areObjects(temp_msg.objects)) 00059 this->visionFacialGazeCallback(msg); 00060 else 00061 this->visionLookCallback(msg); 00062 00063 this->debug(24, "Exited %s %s callback", 00064 engagement::PERFORMING_NAMESPACE.c_str(), 00065 engagement::PERFORMING_LOOK_TOPIC.c_str()); 00066 return; 00067 } 00068 00069 // The message is pertaining to the robot's action 00070 00071 // Either actor is looking at another actor, or at a set of objects 00072 if (msg_objects.size() > 0) 00073 { 00074 // Keep track of the objects the robotis looking at 00075 Robot::setLookAt(true, msg_objects); 00076 00077 // If the actor and robot were in facial gaze then end the shared gaze 00078 if (this->shared_gaze_start_ != UNDEFINED_TIME) 00079 this->endSharedGaze(); 00080 } 00081 else 00082 { 00083 // Attempt to locate the actor 00084 Actor *actor = this->findActor(temp_msg.actor.id); 00085 00086 // Ensure that the actor exists, only if the actor is not the robot 00087 if (temp_msg.actor.id != temp_msg.actor.ROBOT && !actor) 00088 { 00089 this->warn("Actor [%s] does not exist.", 00090 temp_msg.actor.id.c_str()); 00091 this->error("Rejected '%s' message.", 00092 engagement::PERFORMING_LOOK_TOPIC.c_str()); 00093 return; 00094 } 00095 00096 // If the robot is currently in facial gaze, and the 00097 // actor is not the same then shared gaze ends 00098 if (!Robot::isFacialGaze(temp_msg.actor.id)) 00099 this->endSharedGaze(); 00100 00101 // Keep track of the facial gaze with the actor 00102 Robot::setFacialGaze(temp_msg.begin.value == 00103 bml_msgs::Flag::BEGIN, temp_msg.actor.id); 00104 } 00105 00106 this->debug(6, "Received a %s %s message.", 00107 engagement::PERFORMING_NAMESPACE.c_str(), 00108 engagement::PERFORMING_LOOK_TOPIC.c_str()); 00109 00110 // Publish the message internally 00111 this->relayToActors(engagement::PERFORMING_NAMESPACE + "/" + 00112 engagement::PERFORMING_LOOK_TOPIC, &temp_msg); 00113 } 00114 00115 this->debug(24, "Exited %s %s callback", 00116 engagement::PERFORMING_NAMESPACE.c_str(), 00117 engagement::PERFORMING_LOOK_TOPIC.c_str()); 00118 } 00119 00120 void RNode::performingShakeCallback(const engagement_msgs::PerformanceConstPtr& msg) 00121 { 00122 this->debug(24, "Entered %s %s callback", 00123 engagement::PERFORMING_NAMESPACE.c_str(), 00124 engagement::PERFORMING_SHAKE_TOPIC.c_str()); 00125 00126 // Make sure we have a valid message 00127 if (msg) 00128 { 00129 engagement_msgs::Performance temp_msg = *msg; 00130 00131 // Determine if the message is for an actor 00132 if (temp_msg.actor.id != temp_msg.actor.ROBOT) 00133 { 00134 // Call the method to handle input pertaining to the actor 00135 this->visionShakeCallback(msg); 00136 return; 00137 } 00138 00139 // The message is pertaining to the robot's action 00140 00141 this->debug(6, "Received a %s %s message.", 00142 engagement::PERFORMING_NAMESPACE.c_str(), 00143 engagement::PERFORMING_SHAKE_TOPIC.c_str()); 00144 00145 // Publish the message internally 00146 this->relayToActors(engagement::PERFORMING_NAMESPACE + "/" + 00147 engagement::PERFORMING_SHAKE_TOPIC, &temp_msg); 00148 } 00149 00150 this->debug(24, "Exited %s %s callback", 00151 engagement::PERFORMING_NAMESPACE.c_str(), 00152 engagement::PERFORMING_SHAKE_TOPIC.c_str()); 00153 } 00154 00155 void RNode::performingNodCallback(const engagement_msgs::PerformanceConstPtr& msg) 00156 { 00157 this->debug(24, "Entered %s %s callback", 00158 engagement::PERFORMING_NAMESPACE.c_str(), 00159 engagement::PERFORMING_NOD_TOPIC.c_str()); 00160 00161 // Make sure we have a valid message 00162 if (msg) 00163 { 00164 engagement_msgs::Performance temp_msg = *msg; 00165 00166 // Determine if the message is for an actor 00167 if (temp_msg.actor.id != temp_msg.actor.ROBOT) 00168 { 00169 // Call the method to handle input pertaining to the actor 00170 this->visionNodCallback(msg); 00171 return; 00172 } 00173 00174 // The message is pertaining to the robot's action 00175 00176 this->debug(6, "Received a %s %s message.", 00177 engagement::PERFORMING_NAMESPACE.c_str(), 00178 engagement::PERFORMING_NOD_TOPIC.c_str()); 00179 00180 // Publish the message internally 00181 this->relayToActors(engagement::PERFORMING_NAMESPACE + "/" + 00182 engagement::PERFORMING_NOD_TOPIC, &temp_msg); 00183 } 00184 00185 this->debug(24, "Exited %s %s callback", 00186 engagement::PERFORMING_NAMESPACE.c_str(), 00187 engagement::PERFORMING_NOD_TOPIC.c_str()); 00188 } 00189 00190 void RNode::performingExtendedActionCallback(const engagement_msgs::PerformanceConstPtr& msg) 00191 { 00192 this->debug(24, "Entered %s %s callback", 00193 engagement::PERFORMING_NAMESPACE.c_str(), 00194 engagement::PERFORMING_EXTENDED_ACTION_TOPIC.c_str()); 00195 00196 // Make sure we have a valid message 00197 if (msg) 00198 { 00199 engagement_msgs::Performance temp_msg = *msg; 00200 00201 // Determine if the message is for an actor 00202 if (temp_msg.actor.id != temp_msg.actor.ROBOT) 00203 { 00204 // Call the method to handle input pertaining to the actor 00205 this->visionExtendedActionCallback(msg); 00206 return; 00207 } 00208 00209 // The message is pertaining to the robot's action 00210 00211 this->debug(6, "Received a %s %s message.", 00212 engagement::PERFORMING_NAMESPACE.c_str(), 00213 engagement::PERFORMING_EXTENDED_ACTION_TOPIC.c_str()); 00214 00215 // Publish the message internally 00216 this->relayToActors(engagement::PERFORMING_NAMESPACE + "/" + 00217 engagement::PERFORMING_EXTENDED_ACTION_TOPIC, &temp_msg); 00218 } 00219 00220 this->debug(24, "Exited %s %s callback", 00221 engagement::PERFORMING_NAMESPACE.c_str(), 00222 engagement::PERFORMING_EXTENDED_ACTION_TOPIC.c_str()); 00223 } 00224 00225 void RNode::performingPointCallback(const engagement_msgs::PerformanceConstPtr& msg) 00226 { 00227 this->debug(24, "Entered %s %s callback", 00228 engagement::PERFORMING_NAMESPACE.c_str(), 00229 engagement::PERFORMING_POINT_TOPIC.c_str()); 00230 00231 // Make sure we have a valid message 00232 if (msg) 00233 { 00234 // Grab the message type from the constant pointer 00235 engagement_msgs::Performance temp_msg = *msg; 00236 00237 // Determine if the message is for an actor 00238 if (temp_msg.actor.id != temp_msg.actor.ROBOT) 00239 { 00240 // Call the method to handle input pertaining to the actor 00241 this->visionPointCallback(msg); 00242 return; 00243 } 00244 00245 // The message is pertaining to the robot's action 00246 00247 // If the robot is pointing, remove the objects the robot was pointing at 00248 Robot::donePoint(); 00249 00250 this->debug(6, "Received a %s %s message.", 00251 engagement::PERFORMING_NAMESPACE.c_str(), 00252 engagement::PERFORMING_POINT_TOPIC.c_str()); 00253 00254 // Publish the message internally 00255 this->relayToActors(engagement::PERFORMING_NAMESPACE + "/" + 00256 engagement::PERFORMING_POINT_TOPIC, &temp_msg); 00257 } 00258 00259 this->debug(24, "Exited %s %s callback", 00260 engagement::PERFORMING_NAMESPACE.c_str(), 00261 engagement::PERFORMING_POINT_TOPIC.c_str()); 00262 } 00263 00264 void RNode::performingUtteranceCallback(const engagement_msgs::SpeechConstPtr& msg) 00265 { 00266 this->debug(24, "Entered %s %s callback", 00267 engagement::PERFORMING_NAMESPACE.c_str(), 00268 engagement::PERFORMING_UTTERANCE_TOPIC.c_str()); 00269 00270 // Make sure we have a valid message 00271 if (msg) 00272 { 00273 // Determine if the message was rejected or not 00274 bool rejected = false; 00275 00276 // Grab the message type from the constant pointer 00277 engagement_msgs::Speech temp_msg = *msg; 00278 00279 // Make sure the actor exists 00280 if (temp_msg.actor.id != temp_msg.actor.ROBOT && 00281 !this->findActor(temp_msg.actor.id)) 00282 { 00283 this->warn("Actor [%s] does not exist.", 00284 temp_msg.actor.id.c_str()); 00285 rejected = true; 00286 } 00287 00288 // Check if the message was rejected 00289 if (rejected) 00290 { 00291 this->error("Rejected '%s' message.", 00292 engagement::PERFORMING_UTTERANCE_TOPIC.c_str()); 00293 return; 00294 } 00295 00296 this->debug(6, "Received a %s %s [%d] [%d] message.", 00297 engagement::PERFORMING_NAMESPACE.c_str(), 00298 engagement::PERFORMING_UTTERANCE_TOPIC.c_str(), 00299 temp_msg.begin.value, temp_msg.response.value); 00300 00301 // If the robot is speaking, and the speech ended, or the 00302 // robot is not speaking and the speech started 00303 if (Robot::isSpeaking() && 00304 temp_msg.begin.value == bml_msgs::Flag::END) 00305 Robot::setSpeaking(false); 00306 else if (!Robot::isSpeaking() && 00307 temp_msg.begin.value == bml_msgs::Flag::BEGIN) 00308 Robot::setSpeaking(true); 00309 00310 // Publish the message internally 00311 this->relayToActors(engagement::PERFORMING_NAMESPACE + "/" + 00312 engagement::PERFORMING_UTTERANCE_TOPIC, &temp_msg); 00313 } 00314 00315 this->debug(24, "Exited %s %s callback", 00316 engagement::PERFORMING_NAMESPACE.c_str(), 00317 engagement::PERFORMING_UTTERANCE_TOPIC.c_str()); 00318 } 00319 00320 #endif // _PERFORMING_H |