Project: engagement_recognition License: BSD Dependencies:
Used by:
None |
engagement_recognition/src/recognition/response/action.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 "action.h" 00036 #include "engagement_msgs/APAction.h" 00037 00038 // Define all the action types 00039 const std::string Action::NO_ACTION = "NO_ACTION"; 00040 const std::string Action::NOD = "NOD"; 00041 const std::string Action::SHAKE = "SHAKE"; 00042 const std::string Action::SPEECH = "SPEECH"; 00043 const std::string Action::POINT = "POINT"; 00044 const std::string Action::LOOK = "LOOK"; 00045 const std::string Action::EXTENDED_ACTION = "EXTENDED_ACTION"; 00046 00047 Action::Action(std::string action, std::string data) 00048 { 00049 this->action_ = action; 00050 this->data_ = data; 00051 } 00052 00053 Action::Action() 00054 { 00055 this->action_ = Action::NO_ACTION; 00056 this->data_ = ""; 00057 } 00058 00059 Action Action::noAction() 00060 { 00061 return Action(); 00062 } 00063 00064 Action Action::nod() 00065 { 00066 return Action(Action::NOD, ""); 00067 } 00068 00069 Action Action::shake() 00070 { 00071 return Action(Action::SHAKE, ""); 00072 } 00073 00074 Action Action::speech(std::string data) 00075 { 00076 return Action(Action::SPEECH, data); 00077 } 00078 00079 Action Action::point(std::string data) 00080 { 00081 return Action(Action::POINT, data); 00082 } 00083 00084 Action Action::look(std::string data) 00085 { 00086 return Action(Action::LOOK, data); 00087 } 00088 00089 Action Action::extendedAction(std::string data) 00090 { 00091 return Action(Action::EXTENDED_ACTION, data); 00092 } 00093 00094 bool Action::isNoAction() 00095 { 00096 return (this->action_ == Action::NO_ACTION); 00097 } 00098 00099 bool Action::isNod() 00100 { 00101 return (this->action_ == Action::NOD); 00102 } 00103 00104 bool Action::isShake() 00105 { 00106 return (this->action_ == Action::SHAKE); 00107 } 00108 00109 bool Action::isSpeech() 00110 { 00111 return (this->action_ == Action::SPEECH); 00112 } 00113 00114 bool Action::isPoint() 00115 { 00116 return (this->action_ == Action::POINT); 00117 } 00118 00119 bool Action::isLook() 00120 { 00121 return (this->action_ == Action::LOOK); 00122 } 00123 00124 bool Action::isExtendedAction() 00125 { 00126 return (this->action_ == Action::EXTENDED_ACTION); 00127 } 00128 00129 bool Action::equals(Action a) 00130 { 00131 return (this->action_ == a.action_); 00132 } 00133 00134 std::string Action::getData() 00135 { 00136 return this->data_; 00137 } 00138 00139 void Action::setData(std::string data) 00140 { 00141 this->data_ = data; 00142 } 00143 00144 Action Action::fromString(std::string str) 00145 { 00146 // Determine which action this is 00147 if (str == Action::NOD) 00148 return Action::nod(); 00149 else if (str == Action::SHAKE) 00150 return Action::shake(); 00151 else if (str == Action::SPEECH) 00152 return Action::speech(); 00153 else if (str == Action::POINT) 00154 return Action::point(); 00155 else if (str == Action::LOOK) 00156 return Action::look(); 00157 else if (str == Action::EXTENDED_ACTION) 00158 return Action::extendedAction(); 00159 else 00160 return Action::noAction(); 00161 } 00162 00163 const char *Action::toString() 00164 { 00165 // Use a static string so the string stays in scope 00166 static std::string result = ""; 00167 00168 // Set the result to the action 00169 result = std::string(this->action_); 00170 00171 return result.c_str(); 00172 } 00173 00174 int Action::toValue() 00175 { 00176 if (this->action_ == Action::NOD) 00177 return engagement_msgs::APAction::NOD; 00178 else if (this->action_ == Action::SHAKE) 00179 return engagement_msgs::APAction::SHAKE; 00180 else if (this->action_ == Action::SPEECH) 00181 return engagement_msgs::APAction::SPEECH; 00182 else if (this->action_ == Action::POINT) 00183 return engagement_msgs::APAction::POINT; 00184 else if (this->action_ == Action::LOOK) 00185 return engagement_msgs::APAction::LOOK; 00186 else if (this->action_ == Action::EXTENDED_ACTION) 00187 return engagement_msgs::APAction::EXTENDED_ACTION; 00188 else 00189 return engagement_msgs::APAction::NO_ACTION; 00190 } |