Fawkes API  Fawkes Development Version
tf_thread.h
1 
2 /***************************************************************************
3  * tf_thread.h - Thread to exchange transforms
4  *
5  * Created: Wed Oct 26 00:50:12 2011
6  * Copyright 2011 Tim Niemueller [www.niemueller.de]
7  ****************************************************************************/
8 
9 /* This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU Library General Public License for more details.
18  *
19  * Read the full text in the LICENSE.GPL file in the doc directory.
20  */
21 
22 #ifndef __PLUGINS_ROS_TF_THREAD_H_
23 #define __PLUGINS_ROS_TF_THREAD_H_
24 
25 #include <core/threading/thread.h>
26 #include <aspect/blocked_timing.h>
27 #include <aspect/clock.h>
28 #include <aspect/configurable.h>
29 #include <aspect/logging.h>
30 #include <aspect/blackboard.h>
31 #include <aspect/tf.h>
32 #include <plugins/ros/aspect/ros.h>
33 #include <blackboard/interface_listener.h>
34 #include <blackboard/interface_observer.h>
35 #include <interfaces/TransformInterface.h>
36 #include <core/threading/mutex.h>
37 
38 #include <list>
39 #include <queue>
40 
41 // from ROS
42 #include <ros/node_handle.h>
43 #include <tf/tfMessage.h>
44 
46 : public fawkes::Thread,
47  public fawkes::ClockAspect,
48  public fawkes::LoggingAspect,
53  public fawkes::ROSAspect,
56 {
57  public:
58  RosTfThread();
59  virtual ~RosTfThread();
60 
61  virtual void init();
62  virtual void loop();
63  virtual void finalize();
64 
65  // for BlackBoardInterfaceObserver
66  virtual void bb_interface_created(const char *type, const char *id) throw();
67 
68  // for BlackBoardInterfaceListener
69  virtual void bb_interface_data_changed(fawkes::Interface *interface) throw();
70  virtual void bb_interface_writer_removed(fawkes::Interface *interface,
71  unsigned int instance_serial) throw();
72  virtual void bb_interface_reader_removed(fawkes::Interface *interface,
73  unsigned int instance_serial) throw();
74 
75  private:
76  void tf_message_cb(const ::tf::tfMessage::ConstPtr &msg);
77  void conditional_close(fawkes::Interface *interface) throw();
78 
79  /** Stub to see name in backtrace for easier debugging. @see Thread::run() */
80  protected: virtual void run() { Thread::run(); }
81 
82  private:
83  std::list<fawkes::TransformInterface *> __tfifs;
84 
85  ros::Subscriber __sub_tf;
86  ros::Publisher __pub_tf;
87 
88  fawkes::Mutex *__tf_msg_queue_mutex;
89  unsigned int __active_queue;
90  std::queue<tf::tfMessage::ConstPtr> __tf_msg_queues[2];
91 
92  fawkes::Mutex *__seq_num_mutex;
93  unsigned int __seq_num;
94 
95 };
96 
97 #endif
Thread aspect to access to BlackBoard.
Definition: blackboard.h:34
Thread aspect that allows to obtain the current time from the clock.
Definition: clock.h:36
Thread aspect to get access to a ROS node handle.
Definition: ros.h:39
virtual void bb_interface_data_changed(fawkes::Interface *interface)
BlackBoard data changed notification.
Definition: tf_thread.cpp:141
Thread to exchange transforms between Fawkes and ROS.
Definition: tf_thread.h:45
Thread class encapsulation of pthreads.
Definition: thread.h:42
Base class for all Fawkes BlackBoard interfaces.
Definition: interface.h:80
Thread aspect to access the transform system.
Definition: tf.h:38
Thread aspect to use blocked timing.
virtual void finalize()
Finalize the thread.
Definition: tf_thread.cpp:94
Thread aspect to log output.
Definition: logging.h:35
BlackBoard interface observer.
Thread aspect to access configuration data.
Definition: configurable.h:35
RosTfThread()
Constructor.
Definition: tf_thread.cpp:38
virtual void loop()
Code to execute in the thread.
Definition: tf_thread.cpp:111
virtual void bb_interface_reader_removed(fawkes::Interface *interface, unsigned int instance_serial)
A reading instance has been closed for a watched interface.
Definition: tf_thread.cpp:213
virtual void bb_interface_writer_removed(fawkes::Interface *interface, unsigned int instance_serial)
A writing instance has been closed for a watched interface.
Definition: tf_thread.cpp:206
Mutex mutual exclusion lock.
Definition: mutex.h:32
virtual void init()
Initialize the thread.
Definition: tf_thread.cpp:58
virtual void bb_interface_created(const char *type, const char *id)
BlackBoard interface created notification.
Definition: tf_thread.cpp:178
virtual ~RosTfThread()
Destructor.
Definition: tf_thread.cpp:49
BlackBoard interface listener.
virtual void run()
Stub to see name in backtrace for easier debugging.
Definition: tf_thread.h:80