Project: engagement_recognition License: BSD Dependencies:
Used by:
None |
engagement_recognition/src/recognition/recognizers/directed_gaze/dg_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 "dg_start_state.h" 00036 00037 #include "../../events/event_factory.h" 00038 #include "../../lib/engagement_params.h" 00039 #include "../../objects/engagement_objects.h" 00040 00041 DGStartState::DGStartState(): 00042 State(DGStartState::type(), "", NULL) 00043 { 00044 // Set the logger based on this type of recognizer 00045 this->setLogger(EngagementParams::getStateTag(DGStartState::type())); 00046 00047 this->warn("Initialized with an invalid actor, and EventSink."); 00048 } 00049 00050 DGStartState::DGStartState(std::string actor, EventSink *sink): 00051 State(DGStartState::type(), actor, sink) 00052 { 00053 // Set the logger based on this type of recognizer 00054 this->setLogger(sink->getLogger(), 00055 EngagementParams::getStateTag(DGStartState::type())); 00056 00057 if (actor == "") 00058 this->warn("Initialized with an invalid actor."); 00059 } 00060 00061 DGStartState::~DGStartState() 00062 { 00063 } 00064 00065 Event DGStartState::received(std::string topic, 00066 engagement_msgs::Performance *message) 00067 { 00068 if (topic == engagement::VISION_NAMESPACE + "/" + engagement::PERFORMING_LOOK_TOPIC) 00069 return this->visionLookCallback(message); 00070 else if (topic == engagement::VISION_NAMESPACE + "/" + engagement::PERFORMING_POINT_TOPIC) 00071 return this->visionPointCallback(message); 00072 00073 return Event(); 00074 } 00075 00076 Event DGStartState::received(std::string topic, 00077 engagement_srvs::RobotDirectedGaze::Request *message) 00078 { 00079 if (topic == engagement::RECOGNITION_NAMESPACE + "/" + 00080 engagement::ROBOT_NAMESPACE + "/" + engagement::RECOG_DIRECTED_GAZE_TOPIC) 00081 return this->recogDirGazeCallback(message); 00082 00083 return Event(); 00084 } 00085 00086 Event DGStartState::recogDirGazeCallback(const engagement_srvs::RobotDirectedGaze::Request *msg) 00087 { 00088 this->debug(25, "Entered %s %s", 00089 engagement::RECOGNITION_NAMESPACE.c_str(), 00090 engagement::RECOG_DIRECTED_GAZE_TOPIC.c_str()); 00091 00092 // Make sure we have a valid message 00093 if (msg) 00094 { 00095 // Grab the message type from the constant pointer 00096 engagement_srvs::RobotDirectedGaze::Request temp_msg = *msg; 00097 00098 // Cast ourselves into a state 00099 State *state = (State*)this; 00100 00101 // Grab the actor from the state 00102 Actor *actor = state->getActor(); 00103 std::vector<std::string> objects = 00104 objects::getObjectsFromEntities(temp_msg.objects); 00105 00106 // Ensure that the message pertains to this recognizer's object 00107 if (this->compareAdditional(objects, EventSink::CONTAINS)) 00108 { 00109 this->debug(7, "Action refers to this object."); 00110 00111 // Make sure this message relates to the actor for this recognizer 00112 if (actor != NULL && temp_msg.actor.id == actor->getID()) 00113 { 00114 this->debug(7, "Received %s %s message.", 00115 engagement::RECOGNITION_NAMESPACE.c_str(), 00116 engagement::RECOG_DIRECTED_GAZE_TOPIC.c_str()); 00117 00118 // Determine if the actor is already looking at the set of objects 00119 if (actor->isLooking(objects)) 00120 return EventFactory::success(); 00121 else 00122 return EventFactory::robotInitiated(); 00123 } 00124 } 00125 else 00126 this->debug(7, "Action does not refer to this object."); 00127 } 00128 00129 return Event(); 00130 } 00131 00132 Event DGStartState::visionLookCallback(const engagement_msgs::Performance *msg) 00133 { 00134 this->debug(25, "Entered %s %s", 00135 engagement::VISION_NAMESPACE.c_str(), 00136 engagement::PERFORMING_LOOK_TOPIC.c_str()); 00137 00138 // Make sure we have a valid message 00139 if (msg) 00140 { 00141 // Grab the message type from the constant pointer 00142 engagement_msgs::Performance temp_msg = *msg; 00143 00144 // Cast ourselves into a state 00145 State *state = (State*)this; 00146 00147 // Grab the actor from the state 00148 Actor *actor = state->getActor(); 00149 std::vector<std::string> objects = 00150 objects::getObjectsFromEntities(temp_msg.objects); 00151 00152 // Ensure that the message pertains to this recognizer's object 00153 if (this->compareAdditional(objects, EventSink::CONTAINS)) 00154 { 00155 this->debug(7, "Action refers to this object."); 00156 00157 // Make sure this message relates to the actor for this recognizer 00158 // and that the look is starting 00159 if (actor != NULL && temp_msg.actor.id == actor->getID() && 00160 temp_msg.begin.value == bml_msgs::Flag::BEGIN) 00161 { 00162 this->debug(7, "Received %s %s message.", 00163 engagement::VISION_NAMESPACE.c_str(), 00164 engagement::PERFORMING_LOOK_TOPIC.c_str()); 00165 00166 // Success is contingent upon whether the robot is already looking 00167 // at the same objects 00168 if (Robot::isLooking(objects)) 00169 return EventFactory::success(); 00170 else 00171 { 00172 std::vector<std::string> additional = std::vector<std::string>(); 00173 additional.push_back(Action::LOOK); 00174 00175 return EventFactory::humanInitiated(additional); 00176 } 00177 } 00178 } 00179 else 00180 this->debug(7, "Action does not refer to this object."); 00181 } 00182 00183 return Event(); 00184 } 00185 00186 Event DGStartState::visionPointCallback(const engagement_msgs::Performance *msg) 00187 { 00188 this->debug(25, "Entered %s %s", 00189 engagement::VISION_NAMESPACE.c_str(), 00190 engagement::PERFORMING_POINT_TOPIC.c_str()); 00191 00192 // Make sure we have a valid message 00193 if (msg) 00194 { 00195 // Grab the message type from the constant pointer 00196 engagement_msgs::Performance temp_msg = *msg; 00197 00198 // Cast ourselves into a state 00199 State *state = (State*)this; 00200 00201 // Grab the actor from the state 00202 Actor *actor = state->getActor(); 00203 std::vector<std::string> objects = 00204 objects::getObjectsFromEntities(temp_msg.objects); 00205 00206 // Ensure that the message pertains to this recognizer's object 00207 if (this->compareAdditional(objects, EventSink::CONTAINS)) 00208 { 00209 this->debug(7, "Action refers to this object."); 00210 00211 // Make sure this message relates to the actor for this recognizer 00212 // and that the point is starting 00213 if (actor != NULL && temp_msg.actor.id == actor->getID() && 00214 temp_msg.begin.value == bml_msgs::Flag::BEGIN) 00215 { 00216 this->debug(7, "Received %s %s message.", 00217 engagement::VISION_NAMESPACE.c_str(), 00218 engagement::PERFORMING_POINT_TOPIC.c_str()); 00219 00220 // Success is contingent upon whether or not the robot is already 00221 // looking at the same objects 00222 if (Robot::isLooking(objects)) 00223 return EventFactory::success(); 00224 else 00225 { 00226 std::vector<std::string> additional = std::vector<std::string>(); 00227 additional.push_back(Action::POINT); 00228 00229 return EventFactory::humanInitiated(additional); 00230 } 00231 } 00232 } 00233 else 00234 this->debug(7, "Action does not refer to this object."); 00235 } 00236 00237 return Event(); 00238 } 00239 00240 std::string DGStartState::type() 00241 { 00242 return "dg_start"; 00243 } 00244 |