ROSComm.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2009 by Ulrich Friedrich Klank <klank@in.tum.de>
00003  *
00004  * This program is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation; either version 3 of the License, or
00007  * (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016  */
00017 
00018 
00019 #ifndef USE_YARP_COMM /*Only this or Yarp*/
00020 
00021 #ifndef ROSCOMM_H
00022 #define ROSCOMM_H
00023 
00024 #include "RelPose.h"
00025 #include "VisFinder.h"
00026 #include "PerceptionPrimitive.h"
00027 #include "Comm.h"
00028 
00029 
00030 #include <map>
00031 
00032 #include <vision_srvs/cop_call.h>
00033 #include <vision_srvs/cop_save.h>
00034 #include <vision_msgs/cop_answer.h>
00035 #include <vision_msgs/cop_feedback.h>
00036 #include <vision_msgs/cop_status.h>
00037 #include <vision_srvs/cop_get_methods_list.h>
00038 #include <std_msgs/String.h>
00039 #include <ros/ros.h>
00040 
00041 #define STD_COP_OUTPUT_PORT "/tracking/out"
00042 #ifdef BOOST_THREAD
00043 #include <boost/thread.hpp>
00044 #include <boost/bind.hpp>
00045 using namespace boost;
00046 #endif
00047 
00048 
00049 namespace cop
00050 {
00051   /*****************************************************************************************
00052   *  class ROSComm                                                                        */
00053   /*****************************************************************************************
00054   *   This class implements a ros service that answers cop_querys
00055   ******************************************************************************************/
00056   class ROSComm : public Comm
00057   {
00058   public:
00059     ROSComm(VisFinder* visFinder, PossibleLocations_t* pose, PerceptionPrimitive& vis, ros::Publisher * pub,
00060                int numOfObjects, int actionType, std::string callerid, std::map<std::string, std::vector<std::string> > &callerids) :
00061       m_visFinder(visFinder),
00062       m_pose(pose),
00063       m_visPrim(vis),
00064       m_publisher(pub),
00065       m_numOfObjects(numOfObjects),
00066       m_actionType(actionType),
00067       m_callerid(callerid),
00068       m_calleridMap(callerids)
00069     {
00070     }
00071 
00072     ~ROSComm();
00073 
00074     /*****************************************************************************************
00075     *  NotifyPoseUpdate                                                                        */
00076     /*****************************************************************************************
00077     *  Call back that is called whenever a new pose is set for a certain model
00078     *  This callback must be told the signature that is tracked
00079     ******************************************************************************************/
00080     virtual void NotifyPoseUpdate(RelPose* pose, bool sendObjectRelation = true);
00081 
00082     /*****************************************************************************************
00083     *  NotifyNewObject                                                                        */
00084     /*****************************************************************************************
00085     *  Call back that is called whenever a object fullfilling the requested object prototype
00086     *  The prototype can be set by the
00087     ******************************************************************************************/
00088     virtual void NotifyNewObject(Signature* sig, RelPose* pose);
00089 
00090 
00091     /*****************************************************************************************
00092     *  Start                                                                                */
00093     /*****************************************************************************************
00094     *  Calls the yarp threadfunc, with a new thread if this is possible
00095     ******************************************************************************************/
00096     void Start();
00097 private:
00098     /*****************************************************************************************
00099     *  ProcessCall                                                                           */
00100     /*****************************************************************************************
00101     *  Action: calls visual finder, and writes the results on a topic
00102     ******************************************************************************************/
00103     void ProcessCall();
00104 
00105 
00106     /*****************************************************************************************
00107     *  PublishAnswer                                                                           */
00108     /*****************************************************************************************
00109     *  Mutex around publish to topic, checks if topic is up
00110     ******************************************************************************************/
00111     void PublishAnswer(vision_msgs::cop_answer &answer);
00112 
00113     /*yarp::os::BufferedPort<yarp::os::Bottle>* m_port;*/
00114     VisFinder* m_visFinder;
00115     PossibleLocations_t* m_pose;
00116     PerceptionPrimitive& m_visPrim;
00117     ros::Publisher* m_publisher;
00118     int m_numOfObjects;
00119     int m_actionType;
00120     std::string m_callerid;
00121     std::map<std::string, std::vector<std::string> >  &m_calleridMap;
00122   };
00123 
00124   class ROSTopicManager
00125   {
00126   public:
00127     ROSTopicManager(VisFinder* s_visFinder, SignatureDB *s_sigDb);
00128     ~ROSTopicManager();
00129 
00130     void CloseROSTopic(std::string name);
00131 
00132     void Listen(std::string name, volatile bool &g_stopall, ros::NodeHandle* node);
00133     bool ListenCallBack(vision_srvs::cop_call::Request& request, vision_srvs::cop_call::Response&  answer);
00134 
00135     bool SaveCallBack(vision_srvs::cop_save::Request& msg, vision_srvs::cop_save::Response&  answer);
00136     bool ListProgramCallBack(vision_srvs::cop_get_methods_list::Request& msg, vision_srvs::cop_get_methods_list::Response& answer);
00137 
00138     void NewSignatureCallBack(std_msgs::String::ConstPtr xmlFilename);
00139     void FeedbackCallBack(vision_msgs::cop_feedback::ConstPtr feedback);
00140     
00141     void StatusThread();
00142 
00143     /*void ListenCallBack(const boost::shared_ptr<const cop::cop_call> &msg);*/
00144     bool OpenCommOnROSTopic(std::string st);
00145 
00146     void Subscriber(const ros::SingleSubscriberPublisher& subs);
00147 
00148 
00149     std::map<std::string, ros::Publisher*> m_openTopics;
00150 
00151     ros::Publisher m_statusPublisher;
00152 
00153     VisFinder* m_visFinder;
00154     SignatureDB* m_sig;
00155     std::map<std::string, std::vector<std::string> > m_subscriberPerTopics;
00156   };
00157 }
00158 #endif /* ROSCOMM_H */
00159 
00160 #endif /*USE_YARP_COMM */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines


cognitive_perception
Author(s): Ulrich F Klank
autogenerated on Thu May 23 2013 07:38:35