naoqi_driver.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 
19 #ifndef NAOQI_DRIVER_HPP
20 #define NAOQI_DRIVER_HPP
21 
22 #include <vector>
23 #include <queue>
24 
25 /*
26 * BOOST
27 */
28 #include <boost/property_tree/ptree.hpp>
29 #include <boost/thread/thread.hpp>
30 #include <boost/thread/mutex.hpp>
31 #include <boost/scoped_ptr.hpp>
32 
33 /*
34 * ALDEB
35 */
36 #include <qi/session.hpp>
37 
38 /*
39 * PUBLIC INTERFACE
40 */
48 
49 namespace tf2_ros
50 {
51  class Buffer;
52 }
53 
54 namespace naoqi
55 {
56 
57 namespace recorder
58 {
59  class GlobalRecorder;
60 }
65 class Driver
66 {
67 public:
72  Driver( qi::SessionPtr session, const std::string& prefix );
73 
78  ~Driver();
79 
80  void init();
81 
82  void startRosLoop();
83  void stopRosLoop();
87  std::string minidump(const std::string& prefix);
88  std::string minidumpConverters(const std::string& prefix, const std::vector<std::string>& names);
89 
90  void setBufferDuration(float duration);
91  float getBufferDuration();
92 
97  void registerConverter( converter::Converter& conv );
98 
104  void registerPublisher( const std::string& conv_name, publisher::Publisher& pub);
105 
111  void registerRecorder(const std::string& conv_name, recorder::Recorder& rec, float frequency);
112 
116  void registerConverter(converter::Converter conv, publisher::Publisher pub, recorder::Recorder rec );
117 
121  void registerPublisher(converter::Converter conv, publisher::Publisher pub );
122 
126  void registerRecorder(converter::Converter conv, recorder::Recorder rec );
127 
131  bool registerMemoryConverter(const std::string& key, float frequency, const dataType::DataType& type );
132 
136  bool registerEventConverter(const std::string& key, const dataType::DataType& type);
137 
138 
142  std::vector<std::string> getAvailableConverters();
143 
147  std::vector<std::string> getSubscribedPublishers() const;
148 
149  std::string _whoIsYourDaddy()
150  {
151  return "A sugar bear";
152  }
153 
161  void registerSubscriber( subscriber::Subscriber sub );
162 
170  void registerService( service::Service srv );
175  std::string getMasterURI() const;
176 
182  void setMasterURINet( const std::string& uri, const std::string& network_interface );
183 
188  void setMasterURI( const std::string& uri );
189 
193  void startPublishing();
194 
198  void stopPublishing();
199 
203  void startRecording();
204 
208  void startRecordingConverters(const std::vector<std::string>& names);
209 
213  std::string stopRecording();
214 
215  void startLogging();
216 
217  void stopLogging();
218 
222  void addMemoryConverters(std::string filepath);
223 
224  void parseJsonFile(std::string filepath, boost::property_tree::ptree& pt);
225 
226  void stopService();
227 
228  std::vector<std::string> getFilesList();
229 
230  void removeAllFiles();
231 
232  void removeFiles(std::vector<std::string> files);
233 
234 private:
235  qi::SessionPtr sessionPtr_;
236 
238 
244 
245  const size_t freq_;
246  boost::thread publisherThread_;
247  //ros::Rate r_;
248 
250 
251  /* boot config */
252  boost::property_tree::ptree boot_config_;
253  void loadBootConfig();
254 
255  void registerDefaultConverter();
256  void registerDefaultSubscriber();
257  void registerDefaultServices();
258  void insertEventConverter(const std::string& key, event::Event event);
259 
260  template <typename T1, typename T2, typename T3>
261  void _registerMemoryConverter( const std::string& key, float frequency ) {
262  boost::shared_ptr<T1> mfp = boost::make_shared<T1>( key );
263  boost::shared_ptr<T2> mfr = boost::make_shared<T2>( key );
264  boost::shared_ptr<T3> mfc = boost::make_shared<T3>( key , frequency, sessionPtr_, key );
265  mfc->registerCallback( message_actions::PUBLISH, boost::bind(&T1::publish, mfp, _1) );
266  mfc->registerCallback( message_actions::RECORD, boost::bind(&T2::write, mfr, _1) );
267  mfc->registerCallback( message_actions::LOG, boost::bind(&T2::bufferize, mfr, _1) );
268  registerConverter( mfc, mfp, mfr );
269  }
270 
271  void rosLoop();
272 
273  boost::scoped_ptr<ros::NodeHandle> nhPtr_;
274  boost::mutex mutex_reinit_;
275  boost::mutex mutex_conv_queue_;
276  boost::mutex mutex_record_;
277 
278  std::vector< converter::Converter > converters_;
279  std::map< std::string, publisher::Publisher > pub_map_;
280  std::map< std::string, recorder::Recorder > rec_map_;
281  std::map< std::string, event::Event > event_map_;
282  typedef std::map< std::string, publisher::Publisher>::const_iterator PubConstIter;
283  typedef std::map< std::string, publisher::Publisher>::iterator PubIter;
284  typedef std::map< std::string, recorder::Recorder>::const_iterator RecConstIter;
285  typedef std::map< std::string, recorder::Recorder>::iterator RecIter;
286  typedef std::map< std::string, event::Event>::const_iterator EventConstIter;
287  typedef std::map< std::string, event::Event>::iterator EventIter;
288 
289  std::vector< subscriber::Subscriber > subscribers_;
290  std::vector< service::Service > services_;
291 
293 
296  ScheduledConverter(const ros::Time& schedule, size_t conv_index) :
297  schedule_(schedule), conv_index_(conv_index)
298  {
299  }
300 
301  bool operator < (const ScheduledConverter& sp_in) const {
302  return schedule_ > sp_in.schedule_;
303  }
307  size_t conv_index_;
308  };
309 
311  std::priority_queue<ScheduledConverter> conv_queue_;
312 
317 };
318 
319 } // naoqi
320 
321 #endif
Converter concept interface.
Definition: converter.hpp:42
std::map< std::string, recorder::Recorder >::iterator RecIter
qi::SessionPtr sessionPtr_
std::vector< converter::Converter > converters_
Recorder concept interface.
Definition: recorder.hpp:46
static std::string prefix
Definition: ros_env.hpp:64
Subscriber concept interface.
Definition: subscriber.hpp:41
boost::mutex mutex_conv_queue_
std::map< std::string, publisher::Publisher >::iterator PubIter
boost::property_tree::ptree boot_config_
const size_t freq_
std::vector< subscriber::Subscriber > subscribers_
boost::scoped_ptr< ros::NodeHandle > nhPtr_
boost::thread publisherThread_
Converter concept interface.
Definition: event.hpp:44
Interface for naoqi driver which is registered as a naoqi2 Module, once the external roscore ip is se...
Publisher concept interface.
Definition: publisher.hpp:41
std::map< std::string, event::Event > event_map_
std::map< std::string, publisher::Publisher >::const_iterator PubConstIter
static std::string getMasterURI()
Definition: ros_env.hpp:100
GlobalRecorder concept interface.
static void setMasterURI(const std::string &uri, const std::string &network_interface)
Definition: ros_env.hpp:77
boost::shared_ptr< tf2_ros::Buffer > tf2_buffer_
boost::shared_ptr< recorder::GlobalRecorder > recorder_
boost::mutex mutex_record_
const robot::Robot & robot_
std::priority_queue< ScheduledConverter > conv_queue_
void _registerMemoryConverter(const std::string &key, float frequency)
std::vector< service::Service > services_
ScheduledConverter(const ros::Time &schedule, size_t conv_index)
std::string _whoIsYourDaddy()
std::map< std::string, event::Event >::const_iterator EventConstIter
std::map< std::string, recorder::Recorder >::const_iterator RecConstIter
boost::mutex mutex_reinit_
std::map< std::string, recorder::Recorder > rec_map_
std::map< std::string, event::Event >::iterator EventIter
float buffer_duration_
Service concept interface.
Definition: service.hpp:41
std::map< std::string, publisher::Publisher > pub_map_


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