OKVIS ROS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Subscriber.hpp
Go to the documentation of this file.
1 /*********************************************************************************
2  * OKVIS - Open Keyframe-based Visual-Inertial SLAM
3  * Copyright (c) 2015, Autonomous Systems Lab / ETH Zurich
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  * * Neither the name of Autonomous Systems Lab / ETH Zurich nor the names of
14  * its contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  *
29  * Created on: Mar 23, 2012
30  * Author: Stefan Leutenegger (s.leutenegger@imperial.ac.uk)
31  * Modified: Andreas Forster (an.forster@gmail.com)
32  *********************************************************************************/
33 
41 #ifndef INCLUDE_OKVIS_SUBSCRIBER_HPP_
42 #define INCLUDE_OKVIS_SUBSCRIBER_HPP_
43 
44 #include <deque>
45 #include <memory>
46 
47 #include <boost/shared_ptr.hpp>
48 #pragma GCC diagnostic push
49 #pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
50 #include <ros/ros.h>
51 #include <image_geometry/pinhole_camera_model.h>
52 #include <dynamic_reconfigure/server.h>
53 #include <okvis_ros/CameraConfig.h> // generated
54 #pragma GCC diagnostic pop
55 #include <image_transport/image_transport.h>
56 #include "sensor_msgs/Imu.h"
57 #pragma GCC diagnostic push
58 #pragma GCC diagnostic ignored "-Woverloaded-virtual"
59 #include <opencv2/opencv.hpp>
60 #pragma GCC diagnostic pop
61 #include <Eigen/Core>
62 
63 #ifdef HAVE_LIBVISENSOR
64  #include <visensor/visensor_api.hpp>
65 #endif
66 
67 #include <okvis/Time.hpp>
69 #include <okvis/VioInterface.hpp>
70 #include <okvis/ThreadedKFVio.hpp>
71 #include <okvis/assert_macros.hpp>
72 #include <okvis/Publisher.hpp>
75 
77 namespace okvis {
78 
83 {
84  public:
85  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
86  OKVIS_DEFINE_EXCEPTION(Exception, std::runtime_error)
87 
88  ~Subscriber();
96  Subscriber(ros::NodeHandle& nh, okvis::VioInterface* vioInterfacePtr,
97  const okvis::VioParametersReader& param_reader);
98 
100  void setNodeHandle(ros::NodeHandle& nh);
101 
102  protected:
105 
107  void imageCallback(const sensor_msgs::ImageConstPtr& msg,/*
108  const sensor_msgs::CameraInfoConstPtr& info,*/
109  unsigned int cameraIndex);
112  void depthImageCallback(const sensor_msgs::ImageConstPtr& /*msg*/,
113  unsigned int /*cameraIndex*/) {
114  OKVIS_THROW(Exception, "Subscriber::depthImageCallback() is not implemented.");
115  }
116 
118  void imuCallback(const sensor_msgs::ImuConstPtr& msg);
119 
123 
124 #ifdef HAVE_LIBVISENSOR
129  void startSensors(const std::vector<unsigned int>& camRate,
130  const unsigned int imuRate);
132  void directImuCallback(boost::shared_ptr<visensor::ViImuMsg> imu_ptr,
133  visensor::ViErrorCode error);
135  void directFrameCallback(visensor::ViFrame::Ptr frame_ptr,
136  visensor::ViErrorCode error);
139  void directFrameCornerCallback(visensor::ViFrame::Ptr frame_ptr,
140  visensor::ViCorner::Ptr corners_ptr);
142  void configCallback(okvis_ros::CameraConfig &config, uint32_t level);
143 #endif
144 
148 
149  ros::NodeHandle* nh_;
150  image_transport::ImageTransport* imgTransport_;
151  std::vector<image_transport::Subscriber> imageSubscribers_;
152  ros::Subscriber subImu_;
153 
155 
156 #ifdef HAVE_LIBVISENSOR
157  std::shared_ptr<visensor::ViSensorDriver> sensor_;
158  dynamic_reconfigure::Server<okvis_ros::CameraConfig> cameraConfigReconfigureService_;
159 #endif
160 
163 };
164 }
165 
166 #endif /* INCLUDE_OKVIS_SUBSCRIBER_HPP_ */
Header file for the NCameraSystem class.
Subscriber(ros::NodeHandle &nh, okvis::VioInterface *vioInterfacePtr, const okvis::VioParametersReader &param_reader)
Constructor. This will either subscribe to the relevant ROS topics or start up the sensor and registe...
Definition: Subscriber.cpp:56
void imageCallback(const sensor_msgs::ImageConstPtr &msg, unsigned int cameraIndex)
The image callback.
Definition: Subscriber.cpp:105
image_transport::ImageTransport * imgTransport_
The image transporter.
Definition: Subscriber.hpp:150
void directImuCallback(boost::shared_ptr< visensor::ViImuMsg > imu_ptr, visensor::ViErrorCode error)
The IMU callback.
Definition: Subscriber.cpp:198
Header file for the ThreadedKFVio class.
Header file for the Publisher class.
ros::Subscriber subImu_
The IMU message subscriber.
Definition: Subscriber.hpp:152
Header file for the TimeBase, Time and WallTime class.
void imuCallback(const sensor_msgs::ImuConstPtr &msg)
The IMU callback.
Definition: Subscriber.cpp:129
EIGEN_MAKE_ALIGNED_OPERATOR_NEW ~Subscriber()
Definition: Subscriber.cpp:50
void depthImageCallback(const sensor_msgs::ImageConstPtr &, unsigned int)
The depth image callback.
Definition: Subscriber.hpp:112
#define OKVIS_THROW(exceptionType, message)
Definition: assert_macros.hpp:98
void initialiseDriverCallbacks()
Initialise callbacks. Called in constructor.
Definition: Subscriber.cpp:140
void directFrameCallback(visensor::ViFrame::Ptr frame_ptr, visensor::ViErrorCode error)
The image callback.
Definition: Subscriber.cpp:219
ros::NodeHandle * nh_
The node handle.
Definition: Subscriber.hpp:149
#define OKVIS_DEFINE_EXCEPTION(exceptionName, exceptionParent)
Macro for defining an exception with a given parent.
Definition: assert_macros.hpp:52
std::vector< image_transport::Subscriber > imageSubscribers_
The image message subscriber.
Definition: Subscriber.hpp:151
void setNodeHandle(ros::NodeHandle &nh)
Set the node handle. This sets up the callbacks. This is called in the constructor.
Definition: Subscriber.cpp:82
This file contains some useful assert macros.
void directFrameCornerCallback(visensor::ViFrame::Ptr frame_ptr, visensor::ViCorner::Ptr corners_ptr)
The callback for images including detected corners.
Definition: Subscriber.cpp:269
Header file for the VioParametersReader class.
Struct to combine all parameters and settings.
Definition: Parameters.hpp:280
okvis::VioInterface * vioInterface_
The VioInterface. (E.g. ThreadedKFVio)
Definition: Subscriber.hpp:161
void startSensors(const std::vector< unsigned int > &camRate, const unsigned int imuRate)
Start up sensor.
Definition: Subscriber.cpp:174
An abstract base class for interfaces between Front- and Backend.
Definition: VioInterface.hpp:66
Header file for the VioInterface class.
Header file for the Transformation class.
This class handles all the buffering of incoming data.
Definition: Subscriber.hpp:82
void configCallback(okvis_ros::CameraConfig &config, uint32_t level)
Dynamic reconfigure callback.
Definition: Subscriber.cpp:277
dynamic_reconfigure::Server< okvis_ros::CameraConfig > cameraConfigReconfigureService_
dynamic reconfigure service.
Definition: Subscriber.hpp:158
std::shared_ptr< visensor::ViSensorDriver > sensor_
The sensor API.
Definition: Subscriber.hpp:157
okvis::VioParameters vioParameters_
The parameters and settings.
Definition: Subscriber.hpp:162
This class reads and parses config file.
Definition: VioParametersReader.hpp:60