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
49 public fawkes::ROSAspect,
52{
53public:
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) noexcept;
63
64 // for BlackBoardInterfaceListener
65 virtual void bb_interface_data_refreshed(fawkes::Interface *interface) noexcept;
66 virtual void bb_interface_writer_removed(fawkes::Interface *interface,
67 fawkes::Uuid instance_serial) noexcept;
68 virtual void bb_interface_reader_removed(fawkes::Interface *interface,
69 fawkes::Uuid instance_serial) noexcept;
70
71private:
72 void laser_scan_message_cb(const ros::MessageEvent<sensor_msgs::LaserScan const> &msg_evt);
73 void conditional_close(fawkes::Interface *interface) noexcept;
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() */
77protected:
78 virtual void
80 {
81 Thread::run();
82 }
83
84private:
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
Thread to exchange point clouds between Fawkes and ROS.
virtual void bb_interface_reader_removed(fawkes::Interface *interface, fawkes::Uuid instance_serial) noexcept
A reading instance has been closed for a watched interface.
virtual void finalize()
Finalize the thread.
virtual void bb_interface_data_refreshed(fawkes::Interface *interface) noexcept
BlackBoard data refreshed notification.
virtual void loop()
Code to execute in the thread.
virtual void bb_interface_writer_removed(fawkes::Interface *interface, fawkes::Uuid instance_serial) noexcept
A writing instance has been closed for a watched interface.
virtual void run()
Stub to see name in backtrace for easier debugging.
virtual void bb_interface_created(const char *type, const char *id) noexcept
BlackBoard interface created notification.
virtual ~RosLaserScanThread()
Destructor.
virtual void init()
Initialize the thread.
RosLaserScanThread()
Constructor.
Thread aspect to access to BlackBoard.
Definition: blackboard.h:34
BlackBoard interface listener.
BlackBoard interface observer.
Thread aspect to use blocked timing.
Thread aspect to access configuration data.
Definition: configurable.h:33
Base class for all Fawkes BlackBoard interfaces.
Definition: interface.h:80
Thread aspect to log output.
Definition: logging.h:33
Mutex mutual exclusion lock.
Definition: mutex.h:33
Thread aspect to get access to a ROS node handle.
Definition: ros.h:39
Thread class encapsulation of pthreads.
Definition: thread.h:46
A convenience class for universally unique identifiers (UUIDs).
Definition: uuid.h:29