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 
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 
117 
122 
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 
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 
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
naoqi::Driver::conv_queue_
std::priority_queue< ScheduledConverter > conv_queue_
Definition: naoqi_driver.hpp:311
subscriber.hpp
naoqi::Driver::startRosLoop
void startRosLoop()
Definition: naoqi_driver.cpp:1192
naoqi::Driver::stopRecording
std::string stopRecording()
qicli call function to stop recording all registered publisher in a ROSbag
Definition: naoqi_driver.cpp:1163
naoqi::Driver::parseJsonFile
void parseJsonFile(std::string filepath, boost::property_tree::ptree &pt)
Definition: naoqi_driver.cpp:1215
naoqi::Driver::minidump
std::string minidump(const std::string &prefix)
Write a ROSbag with the last bufferized data (10s by default)
Definition: naoqi_driver.cpp:260
naoqi::Driver::setMasterURINet
void setMasterURINet(const std::string &uri, const std::string &network_interface)
qicli call function to set current master uri
Definition: naoqi_driver.cpp:984
naoqi::Driver::stopPublishing
void stopPublishing()
qicli call function to stop/disable publishing all registered publisher
Definition: naoqi_driver.cpp:1059
naoqi::Driver::event_map_
std::map< std::string, event::Event > event_map_
Definition: naoqi_driver.hpp:281
naoqi::Driver::registerMemoryConverter
bool registerMemoryConverter(const std::string &key, float frequency, const dataType::DataType &type)
qicli call function to register a converter for a given memory key
Definition: naoqi_driver.cpp:475
naoqi::converter::Converter
Converter concept interface.
Definition: converter.hpp:42
naoqi::Driver::init
void init()
Definition: naoqi_driver.cpp:151
naoqi::Driver::mutex_conv_queue_
boost::mutex mutex_conv_queue_
Definition: naoqi_driver.hpp:275
naoqi::Driver::record_enabled_
bool record_enabled_
Definition: naoqi_driver.hpp:240
naoqi::Driver::registerDefaultServices
void registerDefaultServices()
Definition: naoqi_driver.cpp:948
boost::shared_ptr
naoqi::Driver::subscribers_
std::vector< subscriber::Subscriber > subscribers_
Definition: naoqi_driver.hpp:289
naoqi::Driver::EventConstIter
std::map< std::string, event::Event >::const_iterator EventConstIter
Definition: naoqi_driver.hpp:286
naoqi::Driver::removeAllFiles
void removeAllFiles()
Definition: naoqi_driver.cpp:1394
naoqi::message_actions::PUBLISH
@ PUBLISH
Definition: message_actions.h:11
session
session
naoqi::Driver::stopLogging
void stopLogging()
Definition: naoqi_driver.cpp:1187
naoqi::Driver::EventIter
std::map< std::string, event::Event >::iterator EventIter
Definition: naoqi_driver.hpp:287
naoqi::Driver::ScheduledConverter
Definition: naoqi_driver.hpp:295
naoqi::service::Service
Service concept interface.
Definition: service.hpp:41
event.hpp
naoqi::Driver::setMasterURI
void setMasterURI(const std::string &uri)
qicli call function to set current master uri
Definition: naoqi_driver.cpp:979
naoqi::Driver::getFilesList
std::vector< std::string > getFilesList()
Definition: naoqi_driver.cpp:1379
naoqi::Driver::robot_
const robot::Robot & robot_
Definition: naoqi_driver.hpp:237
naoqi::subscriber::Subscriber
Subscriber concept interface.
Definition: subscriber.hpp:41
naoqi::Driver::log_enabled_
bool log_enabled_
Definition: naoqi_driver.hpp:241
naoqi::Driver::stopService
void stopService()
Definition: naoqi_driver.cpp:171
naoqi::Driver::buffer_duration_
float buffer_duration_
Definition: naoqi_driver.hpp:292
naoqi::Driver
Interface for naoqi driver which is registered as a naoqi2 Module, once the external roscore ip is se...
Definition: naoqi_driver.hpp:65
naoqi::Driver::registerConverter
void registerConverter(converter::Converter &conv)
registers generall converter units they are connected via callbacks to various actions such as record...
Definition: naoqi_driver.cpp:422
naoqi::Driver::ScheduledConverter::ScheduledConverter
ScheduledConverter(const ros::Time &schedule, size_t conv_index)
Definition: naoqi_driver.hpp:296
publisher.hpp
naoqi::Driver::recorder_
boost::shared_ptr< recorder::GlobalRecorder > recorder_
Definition: naoqi_driver.hpp:249
naoqi::Driver::startPublishing
void startPublishing()
qicli call function to start/enable publishing all registered publisher
Definition: naoqi_driver.cpp:1050
naoqi
Definition: converter.hpp:29
naoqi::Driver::tf2_buffer_
boost::shared_ptr< tf2_ros::Buffer > tf2_buffer_
Definition: naoqi_driver.hpp:316
naoqi::Driver::publish_enabled_
bool publish_enabled_
Definition: naoqi_driver.hpp:239
naoqi::Driver::registerEventConverter
bool registerEventConverter(const std::string &key, const dataType::DataType &type)
qicli call function to register a converter for a given memory event
Definition: naoqi_driver.cpp:1293
naoqi::Driver::stopRosLoop
void stopRosLoop()
Definition: naoqi_driver.cpp:1204
naoqi::Driver::startRecordingConverters
void startRecordingConverters(const std::vector< std::string > &names)
qicli call function to start recording given topics in a ROSbag
Definition: naoqi_driver.cpp:1109
naoqi::Driver::_registerMemoryConverter
void _registerMemoryConverter(const std::string &key, float frequency)
Definition: naoqi_driver.hpp:261
naoqi::Driver::minidumpConverters
std::string minidumpConverters(const std::string &prefix, const std::vector< std::string > &names)
Definition: naoqi_driver.cpp:319
tf2_ros
naoqi::Driver::registerDefaultConverter
void registerDefaultConverter()
Definition: naoqi_driver.cpp:537
naoqi::Driver::getBufferDuration
float getBufferDuration()
Definition: naoqi_driver.cpp:417
naoqi::Driver::registerPublisher
void registerPublisher(const std::string &conv_name, publisher::Publisher &pub)
prepare and register a publisher
Definition: naoqi_driver.cpp:431
naoqi::Driver::boot_config_
boost::property_tree::ptree boot_config_
Definition: naoqi_driver.hpp:252
naoqi::Driver::services_
std::vector< service::Service > services_
Definition: naoqi_driver.hpp:290
converter.hpp
naoqi::Driver::addMemoryConverters
void addMemoryConverters(std::string filepath)
qicli call function to add on-the-fly some memory keys extractors
Definition: naoqi_driver.cpp:1224
naoqi::Driver::~Driver
~Driver()
Destructor for naoqi driver, destroys all ros nodehandle and shutsdown all publisher.
Definition: naoqi_driver.cpp:140
naoqi::recorder::Recorder
Recorder concept interface.
Definition: recorder.hpp:46
naoqi::robot::Robot
Robot
Definition: tools.hpp:37
naoqi::Driver::getSubscribedPublishers
std::vector< std::string > getSubscribedPublishers() const
get all subscribed publishers
Definition: naoqi_driver.cpp:1068
naoqi::Driver::getAvailableConverters
std::vector< std::string > getAvailableConverters()
get all available converters
Definition: naoqi_driver.cpp:955
naoqi::Driver::Driver
Driver(qi::SessionPtr session, const std::string &prefix)
Constructor for naoqi driver.
Definition: naoqi_driver.cpp:118
naoqi::Driver::RecIter
std::map< std::string, recorder::Recorder >::iterator RecIter
Definition: naoqi_driver.hpp:285
naoqi::Driver::registerService
void registerService(service::Service srv)
registers a service
Definition: naoqi_driver.cpp:942
naoqi::Driver::removeFiles
void removeFiles(std::vector< std::string > files)
Definition: naoqi_driver.cpp:1407
naoqi::Driver::has_stereo
bool has_stereo
Definition: naoqi_driver.hpp:243
naoqi::Driver::setBufferDuration
void setBufferDuration(float duration)
Definition: naoqi_driver.cpp:404
naoqi::Driver::rec_map_
std::map< std::string, recorder::Recorder > rec_map_
Definition: naoqi_driver.hpp:280
naoqi::Driver::sessionPtr_
qi::SessionPtr sessionPtr_
Definition: naoqi_driver.hpp:235
naoqi::ros_env::prefix
static std::string prefix
Definition: ros_env.hpp:64
recorder.hpp
naoqi::message_actions::RECORD
@ RECORD
Definition: message_actions.h:12
naoqi::Driver::PubIter
std::map< std::string, publisher::Publisher >::iterator PubIter
Definition: naoqi_driver.hpp:283
naoqi::Driver::freq_
const size_t freq_
Definition: naoqi_driver.hpp:245
naoqi::Driver::pub_map_
std::map< std::string, publisher::Publisher > pub_map_
Definition: naoqi_driver.hpp:279
ros::Time
globalrecorder.hpp
naoqi::event::Event
Converter concept interface.
Definition: event.hpp:44
naoqi::Driver::nhPtr_
boost::scoped_ptr< ros::NodeHandle > nhPtr_
Definition: naoqi_driver.hpp:273
naoqi::Driver::ScheduledConverter::operator<
bool operator<(const ScheduledConverter &sp_in) const
Definition: naoqi_driver.hpp:301
naoqi::Driver::publisherThread_
boost::thread publisherThread_
Definition: naoqi_driver.hpp:246
naoqi::Driver::RecConstIter
std::map< std::string, recorder::Recorder >::const_iterator RecConstIter
Definition: naoqi_driver.hpp:284
naoqi::Driver::mutex_reinit_
boost::mutex mutex_reinit_
Definition: naoqi_driver.hpp:274
naoqi::Driver::keep_looping
bool keep_looping
Definition: naoqi_driver.hpp:242
naoqi::Driver::ScheduledConverter::schedule_
ros::Time schedule_
Definition: naoqi_driver.hpp:305
naoqi::Driver::loadBootConfig
void loadBootConfig()
Definition: naoqi_driver.cpp:161
naoqi::Driver::converters_
std::vector< converter::Converter > converters_
Definition: naoqi_driver.hpp:278
naoqi::Driver::registerDefaultSubscriber
void registerDefaultSubscriber()
Definition: naoqi_driver.cpp:933
naoqi::Driver::_whoIsYourDaddy
std::string _whoIsYourDaddy()
Definition: naoqi_driver.hpp:149
naoqi::Driver::insertEventConverter
void insertEventConverter(const std::string &key, event::Event event)
Definition: naoqi_driver.cpp:449
naoqi::Driver::registerRecorder
void registerRecorder(const std::string &conv_name, recorder::Recorder &rec, float frequency)
prepare and register a recorder
Definition: naoqi_driver.cpp:441
service.hpp
naoqi::Driver::PubConstIter
std::map< std::string, publisher::Publisher >::const_iterator PubConstIter
Definition: naoqi_driver.hpp:282
naoqi::recorder::GlobalRecorder
GlobalRecorder concept interface.
Definition: globalrecorder.hpp:57
naoqi::publisher::Publisher
Publisher concept interface.
Definition: publisher.hpp:41
naoqi::Driver::startRecording
void startRecording()
qicli call function to start recording all registered converter in a ROSbag
Definition: naoqi_driver.cpp:1084
naoqi::Driver::rosLoop
void rosLoop()
Definition: naoqi_driver.cpp:179
naoqi::Driver::startLogging
void startLogging()
Definition: naoqi_driver.cpp:1182
naoqi::Driver::registerSubscriber
void registerSubscriber(subscriber::Subscriber sub)
registers a subscriber
Definition: naoqi_driver.cpp:912
naoqi::dataType::DataType
DataType
Definition: tools.hpp:62
naoqi::Driver::getMasterURI
std::string getMasterURI() const
qicli call function to get current master uri
Definition: naoqi_driver.cpp:974
naoqi::message_actions::LOG
@ LOG
Definition: message_actions.h:13
naoqi::Driver::mutex_record_
boost::mutex mutex_record_
Definition: naoqi_driver.hpp:276
naoqi::Driver::ScheduledConverter::conv_index_
size_t conv_index_
Definition: naoqi_driver.hpp:307


naoqi_driver
Author(s): Karsten Knese
autogenerated on Sat Feb 3 2024 03:50:06