Fawkes API  Fawkes Development Version
laserscan_thread.h
1 
2 /***************************************************************************
3  * laserscan_thread.h - Thread to exchange laser scans
4  *
5  * Created: Tue May 29 19:32:39 2012
6  * Copyright 2011-2012 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_LASERSCAN_THREAD_H_
23 #define __PLUGINS_ROS_LASERSCAN_THREAD_H_
24 
25 #include <core/threading/thread.h>
26 #include <aspect/blocked_timing.h>
27 #include <aspect/configurable.h>
28 #include <aspect/logging.h>
29 #include <aspect/blackboard.h>
30 #include <plugins/ros/aspect/ros.h>
31 #include <blackboard/interface_listener.h>
32 #include <blackboard/interface_observer.h>
33 #include <interfaces/Laser360Interface.h>
34 #include <interfaces/Laser720Interface.h>
35 #include <interfaces/Laser1080Interface.h>
36 #include <core/threading/mutex.h>
37 #include <utils/time/time.h>
38 
39 #include <list>
40 #include <queue>
41 
42 #include <ros/node_handle.h>
43 #include <sensor_msgs/LaserScan.h>
44 
46 : public fawkes::Thread,
47  public fawkes::LoggingAspect,
51  public fawkes::ROSAspect,
54 {
55  public:
57  virtual ~RosLaserScanThread();
58 
59  virtual void init();
60  virtual void loop();
61  virtual void finalize();
62 
63  // for BlackBoardInterfaceObserver
64  virtual void bb_interface_created(const char *type, const char *id) throw();
65 
66  // for BlackBoardInterfaceListener
67  virtual void bb_interface_data_changed(fawkes::Interface *interface) throw();
68  virtual void bb_interface_writer_removed(fawkes::Interface *interface,
69  unsigned int instance_serial) throw();
70  virtual void bb_interface_reader_removed(fawkes::Interface *interface,
71  unsigned int instance_serial) throw();
72 
73  private:
74  void laser_scan_message_cb(const ros::MessageEvent<sensor_msgs::LaserScan const> &msg_evt);
75  void conditional_close(fawkes::Interface *interface) throw();
76  std::string topic_name(const char *if_id, const char *suffix);
77 
78  /** Stub to see name in backtrace for easier debugging. @see Thread::run() */
79  protected: virtual void run() { Thread::run(); }
80 
81  private:
82  std::list<fawkes::Laser360Interface *> __ls360_ifs;
83  std::list<fawkes::Laser720Interface *> __ls720_ifs;
84  std::list<fawkes::Laser1080Interface *> __ls1080_ifs;
85 
86  ros::Subscriber __sub_ls;
87 
88  /// @cond INTERNALS
89  typedef struct {
90  ros::Publisher pub;
91  sensor_msgs::LaserScan msg;
92  } PublisherInfo;
93  /// @endcond
94  std::map<std::string, PublisherInfo> __pubs;
95 
96  fawkes::Mutex *__ls_msg_queue_mutex;
97  unsigned int __active_queue;
98  std::queue<ros::MessageEvent<sensor_msgs::LaserScan const> > __ls_msg_queues[2];
99 
100  std::map<std::string, fawkes::Laser360Interface *> __ls360_wifs;
101 
102  fawkes::Mutex *__seq_num_mutex;
103  unsigned int __seq_num;
104 
105 };
106 
107 #endif
virtual void bb_interface_data_changed(fawkes::Interface *interface)
BlackBoard data changed notification.
Thread aspect to access to BlackBoard.
Definition: blackboard.h:34
Thread aspect to get access to a ROS node handle.
Definition: ros.h:39
virtual void finalize()
Finalize the thread.
Thread class encapsulation of pthreads.
Definition: thread.h:42
Base class for all Fawkes BlackBoard interfaces.
Definition: interface.h:79
virtual void loop()
Code to execute in the thread.
Thread to exchange point clouds between Fawkes and ROS.
Thread aspect to use blocked timing.
virtual void bb_interface_writer_removed(fawkes::Interface *interface, unsigned int instance_serial)
A writing instance has been closed for a watched interface.
virtual void bb_interface_reader_removed(fawkes::Interface *interface, unsigned int instance_serial)
A reading instance has been closed for a watched interface.
Thread aspect to log output.
Definition: logging.h:35
BlackBoard interface observer.
Thread aspect to access configuration data.
Definition: configurable.h:35
virtual void run()
Stub to see name in backtrace for easier debugging.
virtual ~RosLaserScanThread()
Destructor.
virtual void init()
Initialize the thread.
RosLaserScanThread()
Constructor.
Mutex mutual exclusion lock.
Definition: mutex.h:32
BlackBoard interface listener.
virtual void bb_interface_created(const char *type, const char *id)
BlackBoard interface created notification.