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 <aspect/blackboard.h>
26 #include <aspect/blocked_timing.h>
27 #include <aspect/configurable.h>
28 #include <aspect/logging.h>
29 #include <blackboard/interface_listener.h>
30 #include <blackboard/interface_observer.h>
31 #include <core/threading/mutex.h>
32 #include <core/threading/thread.h>
33 #include <interfaces/Laser1080Interface.h>
34 #include <interfaces/Laser360Interface.h>
35 #include <interfaces/Laser720Interface.h>
36 #include <plugins/ros/aspect/ros.h>
37 #include <ros/node_handle.h>
38 #include <sensor_msgs/LaserScan.h>
39 #include <utils/time/time.h>
40 
41 #include <list>
42 #include <queue>
43 
44 class RosLaserScanThread : public fawkes::Thread,
45  public fawkes::LoggingAspect,
49  public fawkes::ROSAspect,
52 {
53 public:
55  virtual ~RosLaserScanThread();
56 
57  virtual void init();
58  virtual void loop();
59  virtual void finalize();
60 
61  // for BlackBoardInterfaceObserver
62  virtual void bb_interface_created(const char *type, const char *id) throw();
63 
64  // for BlackBoardInterfaceListener
65  virtual void bb_interface_data_changed(fawkes::Interface *interface) throw();
66  virtual void bb_interface_writer_removed(fawkes::Interface *interface,
67  unsigned int instance_serial) throw();
68  virtual void bb_interface_reader_removed(fawkes::Interface *interface,
69  unsigned int instance_serial) throw();
70 
71 private:
72  void laser_scan_message_cb(const ros::MessageEvent<sensor_msgs::LaserScan const> &msg_evt);
73  void conditional_close(fawkes::Interface *interface) throw();
74  std::string topic_name(const char *if_id, const char *suffix);
75 
76  /** Stub to see name in backtrace for easier debugging. @see Thread::run() */
77 protected:
78  virtual void
79  run()
80  {
81  Thread::run();
82  }
83 
84 private:
85  std::list<fawkes::Laser360Interface *> ls360_ifs_;
86  std::list<fawkes::Laser720Interface *> ls720_ifs_;
87  std::list<fawkes::Laser1080Interface *> ls1080_ifs_;
88 
89  ros::Subscriber sub_ls_;
90 
91  /// @cond INTERNALS
92  typedef struct
93  {
94  ros::Publisher pub;
95  sensor_msgs::LaserScan msg;
96  } PublisherInfo;
97  /// @endcond
98  std::map<std::string, PublisherInfo> pubs_;
99 
100  fawkes::Mutex * ls_msg_queue_mutex_;
101  unsigned int active_queue_;
102  std::queue<ros::MessageEvent<sensor_msgs::LaserScan const>> ls_msg_queues_[2];
103 
104  std::map<std::string, fawkes::Laser360Interface *> ls360_wifs_;
105 
106  fawkes::Mutex *seq_num_mutex_;
107  unsigned int seq_num_;
108 };
109 
110 #endif
RosLaserScanThread::loop
virtual void loop()
Code to execute in the thread.
Definition: laserscan_thread.cpp:196
RosLaserScanThread::init
virtual void init()
Initialize the thread.
Definition: laserscan_thread.cpp:70
fawkes::Mutex
Definition: mutex.h:36
RosLaserScanThread::RosLaserScanThread
RosLaserScanThread()
Constructor.
Definition: laserscan_thread.cpp:38
RosLaserScanThread
Definition: laserscan_thread.h:43
fawkes::BlackBoardInterfaceListener
Definition: interface_listener.h:45
fawkes::BlockedTimingAspect
Definition: blocked_timing.h:54
RosLaserScanThread::~RosLaserScanThread
virtual ~RosLaserScanThread()
Destructor.
Definition: laserscan_thread.cpp:48
RosLaserScanThread::bb_interface_reader_removed
virtual void bb_interface_reader_removed(fawkes::Interface *interface, unsigned int instance_serial)
A reading instance has been closed for a watched interface.
Definition: laserscan_thread.cpp:469
fawkes::BlackBoardAspect
Definition: blackboard.h:36
fawkes::LoggingAspect
Definition: logging.h:36
fawkes::ROSAspect
Definition: ros.h:37
fawkes::BlackBoardInterfaceObserver
Definition: interface_observer.h:40
fawkes::Interface
Definition: interface.h:77
RosLaserScanThread::bb_interface_data_changed
virtual void bb_interface_data_changed(fawkes::Interface *interface)
BlackBoard data changed notification.
Definition: laserscan_thread.cpp:258
fawkes::Thread
Definition: thread.h:44
RosLaserScanThread::finalize
virtual void finalize()
Finalize the thread.
Definition: laserscan_thread.cpp:166
fawkes::ConfigurableAspect
Definition: configurable.h:36
RosLaserScanThread::bb_interface_writer_removed
virtual void bb_interface_writer_removed(fawkes::Interface *interface, unsigned int instance_serial)
A writing instance has been closed for a watched interface.
Definition: laserscan_thread.cpp:462
RosLaserScanThread::run
virtual void run()
Stub to see name in backtrace for easier debugging.
Definition: laserscan_thread.h:82
RosLaserScanThread::bb_interface_created
virtual void bb_interface_created(const char *type, const char *id)
BlackBoard interface created notification.
Definition: laserscan_thread.cpp:333