Project: engagement_recognition License: BSD Dependencies:
Used by:
None |
engagement_recognition/src/recognition/rnode/rnode.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 disclAaimer. 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 _RNODE_H 00035 #define _RNODE_H 00036 00037 #include <ros/ros.h> 00038 #include <map> 00039 00040 // Include topics and message types 00041 #include "../lib/engagement_macros.h" 00042 00043 // Include the Actor and Robot classes 00044 #include "../actors/actor.h" 00045 #include "../actors/robot.h" 00046 00047 #include "../events/event_sink.h" 00048 #include "../events/event.h" 00049 00059 class RNode : public EventSink 00060 { 00061 private: 00063 pthread_t *master_thread_; 00064 00066 std::vector<pthread_t*> old_threads_; 00067 00069 double window_size_; 00070 00072 unsigned long shared_gaze_start_; 00073 00075 Duration shared_gaze_; 00076 00079 ros::ServiceServer recog_statistics_srv_; 00081 ros::ServiceServer recog_dir_gaze_srv_; 00083 ros::ServiceServer recog_mf_gaze_srv_; 00085 ros::ServiceServer recog_adjacency_pair_srv_; 00086 00088 ros::Subscriber performing_look_sub_; 00090 ros::Subscriber performing_point_sub_; 00092 ros::Subscriber performing_shake_sub_; 00094 ros::Subscriber performing_nod_sub_; 00096 ros::Subscriber performing_ext_action_sub_; 00098 ros::Subscriber performing_utterance_sub_; 00099 00101 ros::Subscriber vision_face_sub_; 00102 00104 ros::Publisher status_pub_; 00105 00112 static void *spin(void *param); 00113 public: 00117 ~RNode(); 00118 00122 RNode(); 00123 00129 RNode(EventSink *parent); 00130 00134 void subscribe(); 00135 00139 void advertise(); 00140 00144 void startSharedGaze(); 00145 00149 void endSharedGaze(); 00150 00158 void relayToActors(std::string topic, ros::Message *message); 00159 00168 void castEvent(Event event); 00169 00177 bool compareAdditional(std::vector<std::string> additional, 00178 std::string compare); 00179 00191 bool foundActor(std::string id); 00192 00202 bool lostActor(std::string id); 00203 00214 Actor* findActor(std::string id); 00215 00222 bool recogStatisticsService(engagement_srvs::ActorStatistics::Request &req, 00223 engagement_srvs::ActorStatistics::Response &res); 00224 00231 bool recogDirGazeService(engagement_srvs::RobotDirectedGaze::Request &req, 00232 engagement_srvs::RobotDirectedGaze::Response &res); 00233 00240 bool recogMFGazeService(engagement_srvs::RobotMutualFacialGaze::Request &req, 00241 engagement_srvs::RobotMutualFacialGaze::Response &res); 00242 00249 bool recogAdjacencyPairService(engagement_srvs::RobotAdjacencyPair::Request &req, 00250 engagement_srvs::RobotAdjacencyPair::Response &res); 00251 00257 void performingLookCallback(const engagement_msgs::PerformanceConstPtr& msg); 00258 00264 void performingShakeCallback(const engagement_msgs::PerformanceConstPtr& msg); 00265 00271 void performingNodCallback(const engagement_msgs::PerformanceConstPtr& msg); 00272 00278 void performingExtendedActionCallback(const engagement_msgs::PerformanceConstPtr& msg); 00279 00285 void performingPointCallback(const engagement_msgs::PerformanceConstPtr& msg); 00286 00292 void performingUtteranceCallback(const engagement_msgs::SpeechConstPtr& msg); 00293 00299 void visionFacialGazeCallback(const engagement_msgs::PerformanceConstPtr& msg); 00300 00306 void visionLookCallback(const engagement_msgs::PerformanceConstPtr& msg); 00307 00313 void visionPointCallback(const engagement_msgs::PerformanceConstPtr& msg); 00314 00320 void visionShakeCallback(const engagement_msgs::PerformanceConstPtr& msg); 00321 00327 void visionNodCallback(const engagement_msgs::PerformanceConstPtr& msg); 00328 00334 void visionExtendedActionCallback(const engagement_msgs::PerformanceConstPtr& msg); 00335 00341 void visionFaceCallback(const engagement_msgs::ActorIDStatusConstPtr& msg); 00342 00346 void spawnThread(); 00347 00353 bool masterExists(); 00354 00358 void updateOldThreads(); 00359 00361 #define RNODE_SUBSCRIBE(h, t, c) h->subscribe(engagement::t, MAX_BUFFER, \ 00362 c, this) 00363 00364 #define RNODE_SERVICE(h, t, c) h->advertiseService(engagement::t, c, this) 00365 00367 #define RNODE_ADVERTISE(handle, type, topic) \ 00368 handle->advertise<engagement_msgs::type>(topic, MAX_BUFFER) 00369 }; 00370 00371 #endif // _RNODE_H |