Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef TOUCH_EVENT_REGISTER_HPP
00019 #define TOUCH_EVENT_REGISTER_HPP
00020
00021 #include <string>
00022
00023 #include <boost/make_shared.hpp>
00024 #include <boost/shared_ptr.hpp>
00025 #include <boost/thread/mutex.hpp>
00026 #include <boost/enable_shared_from_this.hpp>
00027
00028 #include <qi/session.hpp>
00029
00030 #include <ros/ros.h>
00031 #include <naoqi_bridge_msgs/Bumper.h>
00032 #include <naoqi_bridge_msgs/HandTouch.h>
00033 #include <naoqi_bridge_msgs/HeadTouch.h>
00034
00035 #include <naoqi_driver/tools.hpp>
00036 #include <naoqi_driver/recorder/globalrecorder.hpp>
00037
00038
00039 #include "../src/converters/touch.hpp"
00040
00041 #include "../src/publishers/basic.hpp"
00042
00043 #include "../recorder/basic_event.hpp"
00044
00045 namespace naoqi
00046 {
00047
00055 template<class T>
00056 class TouchEventRegister: public boost::enable_shared_from_this<TouchEventRegister<T> >
00057 {
00058
00059 public:
00060
00064 TouchEventRegister();
00065 TouchEventRegister(const std::string& name, const std::vector<std::string> keys, const float& frequency, const qi::SessionPtr& session );
00066 ~TouchEventRegister();
00067
00068 void resetPublisher( ros::NodeHandle& nh );
00069 void resetRecorder( boost::shared_ptr<naoqi::recorder::GlobalRecorder> gr );
00070
00071 void startProcess();
00072 void stopProcess();
00073
00074 void writeDump(const ros::Time& time);
00075 void setBufferDuration(float duration);
00076
00077 void isRecording(bool state);
00078 void isPublishing(bool state);
00079 void isDumping(bool state);
00080
00081 void touchCallback(std::string &key, qi::AnyValue &value, qi::AnyValue &message);
00082 void touchCallbackMessage(std::string &key, bool &state, naoqi_bridge_msgs::Bumper &msg);
00083 void touchCallbackMessage(std::string &key, bool &state, naoqi_bridge_msgs::HandTouch &msg);
00084 void touchCallbackMessage(std::string &key, bool &state, naoqi_bridge_msgs::HeadTouch &msg);
00085
00086
00087 private:
00088 void registerCallback();
00089 void unregisterCallback();
00090 void onEvent();
00091
00092 private:
00093 boost::shared_ptr<converter::TouchEventConverter<T> > converter_;
00094 boost::shared_ptr<publisher::BasicPublisher<T> > publisher_;
00095
00096
00097 qi::SessionPtr session_;
00098 qi::AnyObject p_memory_;
00099 unsigned int serviceId;
00100 std::string name_;
00101
00102 boost::mutex mutex_;
00103
00104 bool isStarted_;
00105 bool isPublishing_;
00106 bool isRecording_;
00107 bool isDumping_;
00108
00109 protected:
00110 std::vector<std::string> keys_;
00111 };
00112
00113
00114 class BumperEventRegister: public TouchEventRegister<naoqi_bridge_msgs::Bumper>
00115 {
00116 public:
00117 BumperEventRegister( const std::string& name, const std::vector<std::string> keys, const float& frequency, const qi::SessionPtr& session ) : TouchEventRegister<naoqi_bridge_msgs::Bumper>(name, keys, frequency, session) {}
00118 };
00119
00120 class HeadTouchEventRegister: public TouchEventRegister<naoqi_bridge_msgs::HeadTouch>
00121 {
00122 public:
00123 HeadTouchEventRegister( const std::string& name, const std::vector<std::string> keys, const float& frequency, const qi::SessionPtr& session ) : TouchEventRegister<naoqi_bridge_msgs::HeadTouch>(name, keys, frequency, session) {}
00124 };
00125
00126 class HandTouchEventRegister: public TouchEventRegister<naoqi_bridge_msgs::HandTouch>
00127 {
00128 public:
00129 HandTouchEventRegister( const std::string& name, const std::vector<std::string> keys, const float& frequency, const qi::SessionPtr& session ) : TouchEventRegister<naoqi_bridge_msgs::HandTouch>(name, keys, frequency, session) {}
00130 };
00131
00132
00133
00134
00135 static bool _qiregisterTouchEventRegisterBumper() {
00136 ::qi::ObjectTypeBuilder<TouchEventRegister<naoqi_bridge_msgs::Bumper> > b;
00137 QI_VAARGS_APPLY(__QI_REGISTER_ELEMENT, TouchEventRegister<naoqi_bridge_msgs::Bumper>, touchCallback)
00138 b.registerType();
00139 return true;
00140 }
00141 static bool BOOST_PP_CAT(__qi_registration, __LINE__) = _qiregisterTouchEventRegisterBumper();
00142
00143 static bool _qiregisterTouchEventRegisterHandTouch() {
00144 ::qi::ObjectTypeBuilder<TouchEventRegister<naoqi_bridge_msgs::HandTouch> > b;
00145 QI_VAARGS_APPLY(__QI_REGISTER_ELEMENT, TouchEventRegister<naoqi_bridge_msgs::HandTouch>, touchCallback)
00146 b.registerType();
00147 return true;
00148 }
00149 static bool BOOST_PP_CAT(__qi_registration, __LINE__) = _qiregisterTouchEventRegisterHandTouch();
00150
00151 static bool _qiregisterTouchEventRegisterHeadTouch() {
00152 ::qi::ObjectTypeBuilder<TouchEventRegister<naoqi_bridge_msgs::HeadTouch> > b;
00153 QI_VAARGS_APPLY(__QI_REGISTER_ELEMENT, TouchEventRegister<naoqi_bridge_msgs::HeadTouch>, touchCallback)
00154 b.registerType();
00155 return true;
00156 }
00157 static bool BOOST_PP_CAT(__qi_registration, __LINE__) = _qiregisterTouchEventRegisterHeadTouch();
00158
00159 }
00160
00161 #endif