Project: engagement_recognition License: BSD Dependencies:
Used by:
None |
engagement_recognition/src/recognition/recognizers/adjacency_pair/ap_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 "ap_start_state.h" 00036 00037 #include "../../events/event_factory.h" 00038 #include "../../lib/engagement_params.h" 00039 #include "../../objects/engagement_objects.h" 00040 00041 APStartState::APStartState() : 00042 State(APStartState::type(), "", NULL) 00043 { 00044 // Set the logger based on this type of recognizer 00045 this->setLogger(EngagementParams::getStateTag(APStartState::type())); 00046 00047 this->warn("Initialized with an invalid actor, and EventSink."); 00048 } 00049 00050 APStartState::APStartState(std::string actor, EventSink *sink) : 00051 State(APStartState::type(), actor, sink) 00052 { 00053 // Set the logger based on this type of recognizer 00054 this->setLogger(sink->getLogger(), 00055 EngagementParams::getStateTag(APStartState::type())); 00056 00057 if (actor == "") 00058 this->warn("Initialized with an invalid actor."); 00059 } 00060 00061 APStartState::~APStartState() 00062 { 00063 } 00064 00065 Event APStartState::received(std::string topic, 00066 engagement_srvs::RobotAdjacencyPair::Request *message) 00067 { 00068 if (topic == engagement::RECOGNITION_NAMESPACE + "/" + 00069 engagement::ROBOT_NAMESPACE + "/" + engagement::RECOG_ADJACENCY_PAIR_TOPIC) 00070 return this->recogAPCallback(message); 00071 00072 return Event(); 00073 } 00074 00075 Event APStartState::received(std::string topic, engagement_msgs::Speech *message) 00076 { 00077 if (topic == engagement::PERFORMING_NAMESPACE + "/" + engagement::PERFORMING_UTTERANCE_TOPIC) 00078 return this->performingUtteranceCallback(message); 00079 00080 return Event(); 00081 } 00082 00083 Event APStartState::received(std::string topic, engagement_msgs::Performance *message) 00084 { 00085 if (topic == engagement::VISION_NAMESPACE + "/" + engagement::PERFORMING_EXTENDED_ACTION_TOPIC) 00086 return this->visionExtendedActionCallback(message); 00087 00088 return Event(); 00089 } 00090 00091 Event APStartState::performingUtteranceCallback(const engagement_msgs::Speech *msg) 00092 { 00093 this->debug(25, "Entered %s %s", engagement::PERFORMING_NAMESPACE.c_str(), 00094 engagement::PERFORMING_UTTERANCE_TOPIC.c_str()); 00095 00096 // Make sure we have a valid message 00097 if (msg) 00098 { 00099 // Grab the message type from the constant pointer 00100 engagement_msgs::Speech temp_msg = *msg; 00101 00102 // Cast ourselves into a state 00103 State *state = (State*)this; 00104 00105 // Grab the actor from the state 00106 Actor *actor = state->getActor(); 00107 00108 // If this message deals with the same actor, and 00109 // the utterance is ending and requires a response 00110 if (actor != NULL && temp_msg.actor.id == actor->getID() && 00111 temp_msg.begin.value == bml_msgs::Flag::END && 00112 temp_msg.response.value == bml_msgs::Flag::OPTIONAL_RESPONSE) 00113 { 00114 this->debug(7, "Received end %s no response.", 00115 engagement::PERFORMING_UTTERANCE_TOPIC.c_str()); 00116 00117 // Store the human's action as the additional data 00118 std::vector<std::string> additional = std::vector<std::string>(); 00119 additional.push_back(Action::SPEECH); 00120 additional.push_back("determine what the human said"); 00121 00122 // Create the human initiated event 00123 return EventFactory::humanInitiated(additional); 00124 } 00125 } 00126 00127 return Event(); 00128 } 00129 00130 Event APStartState::visionExtendedActionCallback(const engagement_msgs::Performance *msg) 00131 { 00132 this->debug(25, "Entered %s %s", engagement::VISION_NAMESPACE.c_str(), 00133 engagement::PERFORMING_EXTENDED_ACTION_TOPIC.c_str()); 00134 00135 // Make sure we have a valid message 00136 if (msg) 00137 { 00138 // Grab the message type from the constant pointer 00139 engagement_msgs::Performance temp_msg = *msg; 00140 00141 // Cast ourselves into a state 00142 State *state = (State*)this; 00143 00144 // Grab the actor from the state 00145 Actor *actor = state->getActor(); 00146 00147 // If this message relates to this actor, and is beginning 00148 if (actor != NULL && temp_msg.actor.id == actor->getID() && 00149 temp_msg.begin.value == bml_msgs::Flag::BEGIN) 00150 { 00151 this->debug(7, "Received %s %s message.", 00152 engagement::VISION_NAMESPACE.c_str(), 00153 engagement::PERFORMING_EXTENDED_ACTION_TOPIC.c_str()); 00154 00155 // Add the extended action used to succeed the event 00156 std::vector<std::string> additional = std::vector<std::string>(); 00157 additional.push_back(Action::EXTENDED_ACTION); 00158 00159 // Make sure there are objects 00160 if (temp_msg.objects.size() > 0) 00161 additional.push_back(temp_msg.objects.at(0).id); 00162 00163 // Create the complete event 00164 return EventFactory::humanInitiated(additional); 00165 } 00166 } 00167 00168 return Event(); 00169 } 00170 00171 Event APStartState::recogAPCallback(const engagement_srvs::RobotAdjacencyPair::Request *msg) 00172 { 00173 this->debug(25, "Entered %s %s", 00174 engagement::RECOGNITION_NAMESPACE.c_str(), 00175 engagement::RECOG_ADJACENCY_PAIR_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::RobotAdjacencyPair::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 this message deals with the same actor 00190 if (actor != NULL && temp_msg.actor.id == actor->getID()) 00191 { 00192 this->debug(7, "Received %s %s message.", 00193 engagement::RECOGNITION_NAMESPACE.c_str(), 00194 engagement::RECOG_ADJACENCY_PAIR_TOPIC.c_str()); 00195 00196 // Create the human initiated event 00197 return EventFactory::robotInitiated(); 00198 } 00199 } 00200 00201 return Event(); 00202 } 00203 00204 std::string APStartState::type() 00205 { 00206 return "ap_start"; 00207 } |