NASA Astrobee Robot Software  0.19.1
Flight software for the Astrobee robots operating inside the International Space Station.
localization_graph_display.h
Go to the documentation of this file.
1 /* Copyright (c) 2017, United States Government, as represented by the
2  * Administrator of the National Aeronautics and Space Administration.
3  *
4  * All rights reserved.
5  *
6  * The Astrobee platform is licensed under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with the
8  * License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15  * License for the specific language governing permissions and limitations
16  * under the License.
17  */
18 
19 // Header file must go in src directory for Qt/Rviz plugin
20 #ifndef LOCALIZATION_RVIZ_PLUGINS_LOCALIZATION_GRAPH_DISPLAY_H_ // NOLINT
21 #define LOCALIZATION_RVIZ_PLUGINS_LOCALIZATION_GRAPH_DISPLAY_H_ // NOLINT
22 
23 // Required for Qt
24 #ifndef Q_MOC_RUN
25 #include <camera/camera_params.h>
26 #include <ff_msgs/LocalizationGraph.h>
28 #include <graph_localizer/loc_projection_factor.h>
29 #include <gtsam/geometry/Pose3.h>
30 #include <gtsam/navigation/CombinedImuFactor.h>
31 #include <image_transport/image_transport.h>
32 #include <ros/publisher.h>
33 #include <ros/subscriber.h>
34 #include <rviz/message_filter_display.h>
35 #include <rviz/ogre_helpers/arrow.h>
36 #include <rviz/ogre_helpers/axes.h>
37 #include <rviz/ogre_helpers/line.h>
38 #include <rviz/ogre_helpers/shape.h>
39 #include <rviz/properties/float_property.h>
40 #include <opencv2/core/types.hpp>
41 #include <map>
42 #include <string>
43 #include <vector>
44 #include "slider_property.h" // NOLINT
45 #endif
46 
47 // Forward declarations for ogre and rviz
48 namespace Ogre {
49 class SceneNode;
50 }
51 
52 namespace localization_rviz_plugins {
53 // TODO(rsoussan): put these somewhere else!
54 using Calibration = gtsam::Cal3_S2;
55 using Camera = gtsam::PinholePose<Calibration>;
57 
58 class LocalizationGraphDisplay : public rviz::MessageFilterDisplay<ff_msgs::LocalizationGraph> {
59  Q_OBJECT // NOLINT
60  public : // NOLINT
62  ~LocalizationGraphDisplay() = default;
63 
64  // private:
65  protected:
66  void onInitialize() final;
67  void reset() final;
68 
69  private Q_SLOTS: // NOLINT
70  void addSmartFactorsProjectionVisual();
71 
72  private:
73  void processMessage(const ff_msgs::LocalizationGraph::ConstPtr& graph_msg);
74  void imageCallback(const sensor_msgs::ImageConstPtr& image_msg);
75  void clearDisplay();
76  void addImuVisual(const graph_localizer::GraphLocalizer& graph_localizer,
77  const gtsam::CombinedImuFactor* const imu_factor);
78  void addProjectionVisual(const gtsam::CameraSet<Camera>& cameras, const Camera::MeasurementVector& measurements,
79  const gtsam::Point3& world_t_landmark, std::vector<cv::Mat>& images);
80  void addLocProjectionVisual(const std::vector<gtsam::LocProjectionFactor<>*> loc_projection_factors,
81  const graph_localizer::CombinedNavStateGraphValues& graph_values);
82  void addOpticalFlowVisual(const graph_localizer::FeatureTrackIdMap& feature_tracks,
83  const localization_common::Time latest_graph_time);
84  void clearImageBuffer(const localization_common::Time oldest_graph_time);
85  sensor_msgs::ImageConstPtr getImage(const localization_common::Time time);
86  void addSmartFactorProjectionVisual(const SmartFactor& smart_factor,
87  const graph_localizer::CombinedNavStateGraphValues& graph_values);
88  cv::Scalar textColor(const double val, const double green_threshold, const double yellow_threshold);
89 
90  std::vector<std::unique_ptr<rviz::Axes>> graph_pose_axes_;
91  std::vector<std::unique_ptr<rviz::Arrow>> imu_factor_arrows_;
92  std::unique_ptr<rviz::BoolProperty> show_pose_axes_;
93  std::unique_ptr<rviz::FloatProperty> pose_axes_size_;
94  std::unique_ptr<rviz::BoolProperty> show_imu_factor_arrows_;
95  std::unique_ptr<rviz::FloatProperty> imu_factor_arrows_diameter_;
96  std::unique_ptr<rviz::BoolProperty> publish_optical_flow_images_;
97  std::unique_ptr<rviz::BoolProperty> publish_smart_factor_images_;
98  std::unique_ptr<rviz::BoolProperty> publish_loc_projection_factor_images_;
99  std::unique_ptr<rviz::BoolProperty> publish_projection_factor_images_;
100  std::unique_ptr<rviz::BoolProperty> show_projection_factor_visual_;
101  std::unique_ptr<rviz::SliderProperty> projection_factor_slider_;
102  image_transport::Publisher optical_flow_image_pub_;
103  image_transport::Publisher smart_factor_projection_image_pub_;
104  image_transport::Publisher projection_image_pub_;
105  image_transport::Publisher loc_projection_factor_image_pub_;
106  image_transport::Subscriber image_sub_;
107  ros::NodeHandle nh_;
108  std::map<localization_common::Time, sensor_msgs::ImageConstPtr> img_buffer_;
109  std::unique_ptr<camera::CameraParameters> nav_cam_params_;
110  std::vector<std::unique_ptr<rviz::Shape>> landmark_points_;
111  std::vector<std::unique_ptr<rviz::Axes>> camera_pose_axes_;
112  std::vector<std::unique_ptr<rviz::Line>> camera_t_landmark_lines_;
113  std::unique_ptr<graph_localizer::GraphLocalizer> latest_graph_localizer_;
114  std::vector<SmartFactor*> latest_smart_factors_;
115 };
116 } // namespace localization_rviz_plugins
117 #endif // LOCALIZATION_RVIZ_PLUGINS_LOCALIZATION_GRAPH_DISPLAY_H_ NOLINT
Ogre
Definition: trajectory_display.h:28
gtsam::LocProjectionFactor
Definition: loc_projection_factor.h:38
localization_rviz_plugins::LocalizationGraphDisplay::LocalizationGraphDisplay
LocalizationGraphDisplay()
Definition: localization_graph_display.cc:49
graph_localizer.h
graph_localizer::GraphLocalizer
Definition: graph_localizer.h:37
slider_property.h
localization_rviz_plugins::LocalizationGraphDisplay
Definition: localization_graph_display.h:58
Calibration
Definition: vive.h:91
localization_rviz_plugins::Camera
gtsam::PinholePose< Calibration > Camera
Definition: localization_graph_display.h:55
localization_rviz_plugins::LocalizationGraphDisplay::reset
void reset() final
Definition: localization_graph_display.cc:95
gtsam::RobustSmartProjectionPoseFactor
Definition: robust_smart_projection_pose_factor.h:31
localization_rviz_plugins
Definition: depth_odometry_display.cc:42
graph_localizer
Definition: graph_localizer.h:32
localization_rviz_plugins::LocalizationGraphDisplay::onInitialize
void onInitialize() final
Definition: localization_graph_display.cc:93
localization_common::Time
double Time
Definition: time.h:23
camera_params.h
localization_rviz_plugins::LocalizationGraphDisplay::~LocalizationGraphDisplay
~LocalizationGraphDisplay()=default