Project: engagement_recognition License: BSD Dependencies:
Used by:
None |
engagement_recognition/src/recognition/recognizers/recognizer.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 #ifndef _ENGAGEMENT_RECOGNIZER_H 00035 #define _ENGAGEMENT_RECOGNIZER_H 00036 00037 #include "../events/event_sink.h" 00038 #include "../actors/actor.h" 00039 #include "../lib/engagement_macros.h" 00040 00041 // Include actions and service responses 00042 #include "../response/action.h" 00043 #include "../response/service_response.h" 00044 00045 // Include the headers for threads and semaphores 00046 #include <boost/thread.hpp> 00047 #include "../semaphores/semaphore.h" 00048 00049 // include the state class and the state factory 00050 #include "../states/state.h" 00051 #include "../states/state_factory.h" 00052 00053 // Use the initiator namespace for the Initiator enumeration 00054 namespace initiator 00055 { 00056 00060 typedef enum 00061 { 00063 NO_INIT = 0, 00065 ROBOT = 1, 00067 HUMAN = 2 00068 } Initiator; 00069 00070 } // initiator namespace 00071 00080 class Recognizer : public EventSink 00081 { 00082 protected: 00084 bool succeeded_; 00085 00087 Semaphore *state_semaphore_; 00088 00090 State *state_; 00091 00093 initiator::Initiator initiator_; 00094 00096 std::string actor_; 00097 00099 double max_delay_; 00100 00102 Semaphore *semaphore_; 00103 00105 ServiceResponse status_; 00106 00108 Action action_; 00109 00111 unsigned long start_time_; 00112 00114 unsigned long end_time_; 00115 00117 unsigned long start_delay_; 00118 00120 unsigned long end_delay_; 00121 00123 std::string type_; 00124 public: 00128 virtual ~Recognizer(); 00129 00133 Recognizer(); 00134 00141 Recognizer(std::string type, EventSink *sink); 00142 00152 Recognizer(State *state, std::string type, std::string actor, 00153 EventSink *sink); 00154 00161 void received(std::string topic, ros::Message *message); 00162 00168 void callService(boost::barrier *barrier); 00169 00179 void castEvent(Event event); 00180 00184 void setStartState(); 00185 00191 void setState(factory::StateType type); 00192 00198 void succeed(Action action); 00199 00205 const char *getStateName(); 00206 00212 void initialize(initiator::Initiator initiator); 00213 00221 virtual bool compareAdditional(std::vector<std::string> additional, 00222 std::string compare); 00223 00230 virtual std::string getObject(); 00231 00237 virtual void transition(Event event) = 0; 00238 00244 void complete(bool success); 00245 00251 void setActor(std::string actor); 00252 00258 Actor *getActor(); 00259 00265 ServiceResponse getStatus(); 00266 00274 double getMaxDelayParam(ros::NodeHandle *handle, double def); 00275 00282 void setAction(Action action); 00283 00290 Action getAction(); 00291 00295 void block(); 00296 00305 void unblock(ServiceResponse status, Action action); 00306 }; 00307 00308 #endif // _ENGAGEMENT_RECOGNIZER_H |