ROS2Visualizer.h
Go to the documentation of this file.
1 /*
2  * OpenVINS: An Open Platform for Visual-Inertial Research
3  * Copyright (C) 2018-2023 Patrick Geneva
4  * Copyright (C) 2018-2023 Guoquan Huang
5  * Copyright (C) 2018-2023 OpenVINS Contributors
6  * Copyright (C) 2018-2019 Kevin Eckenhoff
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <https://www.gnu.org/licenses/>.
20  */
21 
22 #ifndef OV_MSCKF_ROS2VISUALIZER_H
23 #define OV_MSCKF_ROS2VISUALIZER_H
24 
25 #include <geometry_msgs/msg/pose_stamped.hpp>
26 #include <geometry_msgs/msg/pose_with_covariance_stamped.hpp>
27 #include <geometry_msgs/msg/transform_stamped.hpp>
32 #include <nav_msgs/msg/odometry.hpp>
33 #include <nav_msgs/msg/path.hpp>
34 #include <rclcpp/rclcpp.hpp>
35 #include <sensor_msgs/msg/camera_info.hpp>
36 #include <sensor_msgs/msg/image.hpp>
37 #include <sensor_msgs/msg/imu.hpp>
38 #include <sensor_msgs/msg/nav_sat_fix.hpp>
39 #include <sensor_msgs/msg/point_cloud.hpp>
40 #include <sensor_msgs/msg/point_cloud2.hpp>
41 #include <sensor_msgs/point_cloud2_iterator.hpp>
42 #include <std_msgs/msg/float64.hpp>
45 #include <tf2_geometry_msgs/tf2_geometry_msgs.h>
47 
48 #include <atomic>
49 #include <fstream>
50 #include <memory>
51 #include <mutex>
52 
53 #include <Eigen/Eigen>
54 #include <boost/date_time/posix_time/posix_time.hpp>
55 #include <boost/filesystem.hpp>
56 #include <cv_bridge/cv_bridge.h>
57 
58 namespace ov_core {
59 class YamlParser;
60 struct CameraData;
61 } // namespace ov_core
62 
63 namespace ov_msckf {
64 
65 class VioManager;
66 class Simulator;
67 
79 
80 public:
87  ROS2Visualizer(std::shared_ptr<rclcpp::Node> node, std::shared_ptr<VioManager> app, std::shared_ptr<Simulator> sim = nullptr);
88 
93  void setup_subscribers(std::shared_ptr<ov_core::YamlParser> parser);
94 
98  void visualize();
99 
105  void visualize_odometry(double timestamp);
106 
110  void visualize_final();
111 
113  void callback_inertial(const sensor_msgs::msg::Imu::SharedPtr msg);
114 
116  void callback_monocular(const sensor_msgs::msg::Image::SharedPtr msg0, int cam_id0);
117 
119  void callback_stereo(const sensor_msgs::msg::Image::ConstSharedPtr msg0, const sensor_msgs::msg::Image::ConstSharedPtr msg1, int cam_id0,
120  int cam_id1);
121 
122 protected:
124  void publish_state();
125 
127  void publish_images();
128 
130  void publish_features();
131 
133  void publish_groundtruth();
134 
136  void publish_loopclosure_information();
137 
139  std::shared_ptr<rclcpp::Node> _node;
140 
142  std::shared_ptr<VioManager> _app;
143 
145  std::shared_ptr<Simulator> _sim;
146 
147  // Our publishers
148  image_transport::Publisher it_pub_tracks, it_pub_loop_img_depth, it_pub_loop_img_depth_color;
149  rclcpp::Publisher<geometry_msgs::msg::PoseWithCovarianceStamped>::SharedPtr pub_poseimu;
150  rclcpp::Publisher<nav_msgs::msg::Odometry>::SharedPtr pub_odomimu;
151  rclcpp::Publisher<nav_msgs::msg::Path>::SharedPtr pub_pathimu;
152  rclcpp::Publisher<sensor_msgs::msg::PointCloud2>::SharedPtr pub_points_msckf, pub_points_slam, pub_points_aruco, pub_points_sim;
153  rclcpp::Publisher<nav_msgs::msg::Odometry>::SharedPtr pub_loop_pose, pub_loop_extrinsic;
154  rclcpp::Publisher<sensor_msgs::msg::PointCloud>::SharedPtr pub_loop_point;
155  rclcpp::Publisher<sensor_msgs::msg::CameraInfo>::SharedPtr pub_loop_intrinsics;
156  std::shared_ptr<tf2_ros::TransformBroadcaster> mTfBr;
157 
158  // Our subscribers and camera synchronizers
159  rclcpp::Subscription<sensor_msgs::msg::Imu>::SharedPtr sub_imu;
160  std::vector<rclcpp::Subscription<sensor_msgs::msg::Image>::SharedPtr> subs_cam;
162  std::vector<std::shared_ptr<message_filters::Synchronizer<sync_pol>>> sync_cam;
163  std::vector<std::shared_ptr<message_filters::Subscriber<sensor_msgs::msg::Image>>> sync_subs_cam;
164 
165  // For path viz
166  std::vector<geometry_msgs::msg::PoseStamped> poses_imu;
167 
168  // Groundtruth infomation
169  rclcpp::Publisher<nav_msgs::msg::Path>::SharedPtr pub_pathgt;
170  rclcpp::Publisher<geometry_msgs::msg::PoseStamped>::SharedPtr pub_posegt;
171  double summed_mse_ori = 0.0;
172  double summed_mse_pos = 0.0;
173  double summed_nees_ori = 0.0;
174  double summed_nees_pos = 0.0;
175  size_t summed_number = 0;
176 
177  // Start and end timestamps
178  bool start_time_set = false;
179  boost::posix_time::ptime rT1, rT2;
180 
181  // Thread atomics
182  std::atomic<bool> thread_update_running;
183 
188  std::deque<ov_core::CameraData> camera_queue;
189  std::mutex camera_queue_mtx;
190 
191  // Last camera message timestamps we have received (mapped by cam id)
192  std::map<int, double> camera_last_timestamp;
193 
194  // Last timestamp we visualized at
195  double last_visualization_timestamp = 0;
196  double last_visualization_timestamp_image = 0;
197 
198  // Our groundtruth states
199  std::map<double, Eigen::Matrix<double, 17, 1>> gt_states;
200 
201  // For path viz
202  std::vector<geometry_msgs::msg::PoseStamped> poses_gt;
203  bool publish_global2imu_tf = true;
204  bool publish_calibration_tf = true;
205 
206  // Files and if we should save total state
207  bool save_total_state = false;
208  std::ofstream of_state_est, of_state_std, of_state_gt;
209 };
210 
211 } // namespace ov_msckf
212 
213 #endif // OV_MSCKF_ROS2VISUALIZER_H
app
rclcpp::Publisher< nav_msgs::msg::Odometry >::SharedPtr pub_odomimu
rclcpp::Publisher< sensor_msgs::msg::CameraInfo >::SharedPtr pub_loop_intrinsics
rclcpp::Publisher< nav_msgs::msg::Path >::SharedPtr pub_pathimu
Extended Kalman Filter estimator.
Definition: VioManager.h:46
std::deque< ov_core::CameraData > camera_queue
std::shared_ptr< tf2_ros::TransformBroadcaster > mTfBr
rclcpp::Publisher< sensor_msgs::msg::PointCloud >::SharedPtr pub_loop_point
rclcpp::Publisher< sensor_msgs::msg::PointCloud2 >::SharedPtr pub_points_slam
message_filters::sync_policies::ApproximateTime< sensor_msgs::msg::Image, sensor_msgs::msg::Image > sync_pol
std::vector< std::shared_ptr< message_filters::Synchronizer< sync_pol > > > sync_cam
rclcpp::Publisher< geometry_msgs::msg::PoseStamped >::SharedPtr pub_posegt
std::vector< geometry_msgs::msg::PoseStamped > poses_imu
std::vector< geometry_msgs::msg::PoseStamped > poses_gt
std::shared_ptr< rclcpp::Node > _node
Global node handler.
std::shared_ptr< Simulator > sim
rclcpp::Publisher< nav_msgs::msg::Odometry >::SharedPtr pub_loop_pose
image_transport::Publisher it_pub_tracks
std::shared_ptr< Simulator > _sim
Simulator (is nullptr if we are not sim&#39;ing)
std::atomic< bool > thread_update_running
std::vector< std::shared_ptr< message_filters::Subscriber< sensor_msgs::msg::Image > > > sync_subs_cam
rclcpp::Subscription< sensor_msgs::msg::Imu >::SharedPtr sub_imu
Helper class that will publish results onto the ROS framework.
parser
boost::posix_time::ptime rT2
rclcpp::Publisher< nav_msgs::msg::Path >::SharedPtr pub_pathgt
std::shared_ptr< VioManager > _app
Core application of the filter system.
std::vector< rclcpp::Subscription< sensor_msgs::msg::Image >::SharedPtr > subs_cam
std::map< int, double > camera_last_timestamp
rclcpp::Publisher< geometry_msgs::msg::PoseWithCovarianceStamped >::SharedPtr pub_poseimu
std::map< double, Eigen::Matrix< double, 17, 1 > > gt_states


ov_msckf
Author(s): Patrick Geneva , Kevin Eckenhoff , Guoquan Huang
autogenerated on Wed Jun 21 2023 03:05:43