Project: engagement_recognition License: BSD Dependencies:
Used by:
None |
engagement_recognition/src/recognition/recognizers/backchannel/backchannel_recognizer.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 "backchannel_recognizer.h" 00036 00037 #include "../../events/event_factory.h" 00038 #include "../../lib/engagement_params.h" 00039 00040 BackchannelRecognizer::BackchannelRecognizer() : 00041 Recognizer(BackchannelRecognizer::type(), NULL) 00042 { 00043 // Set the logger based on this type of recognizer 00044 this->setLogger(EngagementParams::getBCTag()); 00045 00046 // Cast ourselves into a Recognizer 00047 Recognizer *recognizer = (Recognizer*)this; 00048 00049 // Create the start state, and set the state to it 00050 recognizer->setStartState(); 00051 00052 // Grab the recognition/human NodeHandle 00053 ros::NodeHandle *recog_human = EngagementParams::getRecogHumanHandle(); 00054 00055 // Advertise the human initiated backchannel topic 00056 hi_backchannel_pub_ = recog_human->advertise<engagement_msgs::HumanBackchannel>( 00057 engagement::RECOG_BACKCHANNEL_TOPIC, MAX_BUFFER); 00058 00059 this->warn("Initialized recognizer to an empty actor."); 00060 } 00061 00062 BackchannelRecognizer::BackchannelRecognizer(std::string actor, 00063 EventSink *sink) : 00064 Recognizer(BackchannelRecognizer::type(), sink) 00065 { 00066 // Set the logger based on this type of recognizer 00067 this->setLogger(sink->getLogger(), EngagementParams::getBCTag()); 00068 00069 // Set the actor for this recognizer 00070 // Do this BEFORE setting the state 00071 setActor(actor); 00072 00073 // Grab the recognition/human NodeHandle 00074 ros::NodeHandle *recog_human = EngagementParams::getRecogHumanHandle(); 00075 00076 // Advertise the human initiated backchannel topic 00077 hi_backchannel_pub_ = recog_human->advertise<engagement_msgs::HumanBackchannel>( 00078 engagement::RECOG_BACKCHANNEL_TOPIC, MAX_BUFFER); 00079 00080 // Create the start state and set the state to it 00081 this->setStartState(); 00082 } 00083 00084 void BackchannelRecognizer::initialize(initiator::Initiator initiator) 00085 { 00086 Recognizer *rec = (Recognizer*)this; 00087 00088 // Initialize this recognizer with the initiator 00089 rec->initialize(initiator); 00090 } 00091 00092 void BackchannelRecognizer::transition(Event event) 00093 { 00094 // Check the event cases 00095 if (EventFactory::isRobotInitiated(event)) 00096 { 00097 this->debug(8, "ROBOT INITIATED EVENT!"); 00098 00099 // Initialize the connection event 00100 this->initialize(initiator::ROBOT); 00101 00102 this->setState(factory::BC_ROBOT_FLOOR); 00103 } 00104 else if (EventFactory::isHumanInitiated(event)) 00105 { 00106 this->debug(8, "HUMAN INITIATED EVENT"); 00107 00108 // Initialize the connection event 00109 this->initialize(initiator::HUMAN); 00110 00111 this->setState(factory::BC_HUMAN_FLOOR); 00112 } 00113 else if (EventFactory::isSuccess(event)) 00114 { 00115 this->debug(8, "SUCCESS EVENT"); 00116 00117 // Grab the internal node handle 00118 ros::NodeHandle *n = EngagementParams::getConfMFGazeHandle(); 00119 00120 // Grab the max delay from the parameter server 00121 double max_delay = this->getMaxDelayParam(n, 2.0); 00122 00123 // Only send human initiated events if the recognizer is not degraded 00124 if (!EngagementParams::isDegraded()) 00125 { 00126 // Create the human initiated mutual facial gaze message 00127 engagement_msgs::HumanBackchannel bc_msg; 00128 00129 // Set the actor, the timeout duration, and the 00130 // human's utterance for this message 00131 bc_msg.actor.id = this->getActor()->getID(); 00132 bc_msg.timeout = max_delay; 00133 00134 this->debug(5, "Publishing human initiated event."); 00135 // Publish the message 00136 this->hi_backchannel_pub_.publish(bc_msg); 00137 } 00138 00139 // Complete the connection event successfully 00140 this->complete(true); 00141 } 00142 else if (EventFactory::isCycle(event)) 00143 { 00144 this->debug(8, "CYCLE EVENT"); 00145 00146 // Transition to the start state 00147 this->setStartState(); 00148 } 00149 } 00150 00151 std::string BackchannelRecognizer::type() 00152 { 00153 return engagement::BACKCHANNEL_TYPE; 00154 } |