event/touch.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2015 Aldebaran
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 
18 #ifndef TOUCH_EVENT_REGISTER_HPP
19 #define TOUCH_EVENT_REGISTER_HPP
20 
21 #include <string>
22 
23 #include <boost/make_shared.hpp>
24 #include <boost/shared_ptr.hpp>
25 #include <boost/thread/mutex.hpp>
26 #include <boost/enable_shared_from_this.hpp>
27 
28 #include <qi/session.hpp>
29 
30 #include <ros/ros.h>
31 #include <naoqi_bridge_msgs/Bumper.h>
32 #include <naoqi_bridge_msgs/HandTouch.h>
33 #include <naoqi_bridge_msgs/HeadTouch.h>
34 
35 #include <naoqi_driver/tools.hpp>
37 
38 // Converter
39 #include "../src/converters/touch.hpp"
40 // Publisher
41 #include "../src/publishers/basic.hpp"
42 // Recorder
43 #include "../recorder/basic_event.hpp"
44 
45 namespace naoqi
46 {
47 
55 template<class T>
56 class TouchEventRegister: public boost::enable_shared_from_this<TouchEventRegister<T> >
57 {
58 
59 public:
60 
65  TouchEventRegister(const std::string& name, const std::vector<std::string> keys, const float& frequency, const qi::SessionPtr& session );
67 
68  void resetPublisher( ros::NodeHandle& nh );
70 
71  void startProcess();
72  void stopProcess();
73 
74  void writeDump(const ros::Time& time);
75  void setBufferDuration(float duration);
76 
77  void isRecording(bool state);
78  void isPublishing(bool state);
79  void isDumping(bool state);
80 
81  void touchCallback(std::string &key, qi::AnyValue &value, qi::AnyValue &message);
82  void touchCallbackMessage(std::string &key, bool &state, naoqi_bridge_msgs::Bumper &msg);
83  void touchCallbackMessage(std::string &key, bool &state, naoqi_bridge_msgs::HandTouch &msg);
84  void touchCallbackMessage(std::string &key, bool &state, naoqi_bridge_msgs::HeadTouch &msg);
85 
86 
87 private:
88  void registerCallback();
89  void unregisterCallback();
90  void onEvent();
91 
92 private:
95  //boost::shared_ptr<recorder::BasicEventRecorder<T> > recorder_;
96 
97  qi::SessionPtr session_;
98  qi::AnyObject p_memory_;
99  unsigned int serviceId;
100  std::string name_;
101 
102  boost::mutex mutex_;
103 
108 
109 protected:
110  std::vector<std::string> keys_;
111 }; // class
112 
113 
114 class BumperEventRegister: public TouchEventRegister<naoqi_bridge_msgs::Bumper>
115 {
116 public:
117  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) {}
118 };
119 
120 class HeadTouchEventRegister: public TouchEventRegister<naoqi_bridge_msgs::HeadTouch>
121 {
122 public:
123  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) {}
124 };
125 
126 class HandTouchEventRegister: public TouchEventRegister<naoqi_bridge_msgs::HandTouch>
127 {
128 public:
129  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) {}
130 };
131 
132 //QI_REGISTER_OBJECT(BumperEventRegister, touchCallback)
133 //QI_REGISTER_OBJECT(HeadTouchEventRegister, touchCallback)
134 
136  ::qi::ObjectTypeBuilder<TouchEventRegister<naoqi_bridge_msgs::Bumper> > b;
137  QI_VAARGS_APPLY(__QI_REGISTER_ELEMENT, TouchEventRegister<naoqi_bridge_msgs::Bumper>, touchCallback)
138  b.registerType();
139  return true;
140  }
141 static bool BOOST_PP_CAT(__qi_registration, __LINE__) = _qiregisterTouchEventRegisterBumper();
142 
144  ::qi::ObjectTypeBuilder<TouchEventRegister<naoqi_bridge_msgs::HandTouch> > b;
145  QI_VAARGS_APPLY(__QI_REGISTER_ELEMENT, TouchEventRegister<naoqi_bridge_msgs::HandTouch>, touchCallback)
146  b.registerType();
147  return true;
148  }
149 static bool BOOST_PP_CAT(__qi_registration, __LINE__) = _qiregisterTouchEventRegisterHandTouch();
150 
152  ::qi::ObjectTypeBuilder<TouchEventRegister<naoqi_bridge_msgs::HeadTouch> > b;
153  QI_VAARGS_APPLY(__QI_REGISTER_ELEMENT, TouchEventRegister<naoqi_bridge_msgs::HeadTouch>, touchCallback)
154  b.registerType();
155  return true;
156  }
157 static bool BOOST_PP_CAT(__qi_registration, __LINE__) = _qiregisterTouchEventRegisterHeadTouch();
158 
159 } //naoqi
160 
161 #endif
msg
void isDumping(bool state)
void isRecording(bool state)
void isPublishing(bool state)
TouchEventRegister()
Constructor for recorder interface.
Definition: event/touch.cpp:36
HandTouchEventRegister(const std::string &name, const std::vector< std::string > keys, const float &frequency, const qi::SessionPtr &session)
HeadTouchEventRegister(const std::string &name, const std::vector< std::string > keys, const float &frequency, const qi::SessionPtr &session)
void resetPublisher(ros::NodeHandle &nh)
Definition: event/touch.cpp:73
GlobalRecorder concept interface.
Definition: event/touch.hpp:56
static bool _qiregisterTouchEventRegisterBumper()
BumperEventRegister(const std::string &name, const std::vector< std::string > keys, const float &frequency, const qi::SessionPtr &session)
void touchCallbackMessage(std::string &key, bool &state, naoqi_bridge_msgs::Bumper &msg)
boost::shared_ptr< converter::TouchEventConverter< T > > converter_
Definition: event/touch.hpp:93
void touchCallback(std::string &key, qi::AnyValue &value, qi::AnyValue &message)
static bool BOOST_PP_CAT(__qi_registration, __LINE__)
boost::shared_ptr< publisher::BasicPublisher< T > > publisher_
Definition: event/touch.hpp:94
void resetRecorder(boost::shared_ptr< naoqi::recorder::GlobalRecorder > gr)
Definition: event/touch.cpp:79
std::vector< std::string > keys_
static bool _qiregisterTouchEventRegisterHeadTouch()
static bool _qiregisterTouchEventRegisterHandTouch()
void setBufferDuration(float duration)
void writeDump(const ros::Time &time)


naoqi_driver
Author(s): Karsten Knese
autogenerated on Sat Feb 15 2020 03:24:26