NASA Astrobee Robot Software  0.19.1
Flight software for the Astrobee robots operating inside the International Space Station.
ros_graph_localizer_wrapper.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 #ifndef ROS_GRAPH_LOCALIZER_ROS_GRAPH_LOCALIZER_WRAPPER_H_
19 #define ROS_GRAPH_LOCALIZER_ROS_GRAPH_LOCALIZER_WRAPPER_H_
20 
21 #include <ff_msgs/EkfState.h>
22 #include <ff_msgs/Feature2dArray.h>
23 #include <ff_msgs/FlightMode.h>
24 #include <ff_msgs/GraphVIOState.h>
25 #include <ff_msgs/GraphLocState.h>
26 #include <ff_msgs/VisualLandmarks.h>
27 // #include <ff_msgs/SerializedGraph.h>
35 
36 #include <sensor_msgs/Imu.h>
37 
38 #include <memory>
39 #include <string>
40 
41 namespace ros_graph_localizer {
42 // Converts ROS messages and passes these to the GraphLocalizer graph.
43 // Creates msgs from pose nodes in the graph.
44 // Waits until a valid map-match is received to initialize the localizer.
46  public:
47  explicit RosGraphLocalizerWrapper(const std::string& graph_config_path_prefix = "");
48 
49  // Load configs for graph_localizer
50  void LoadConfigs(const std::string& graph_config_path_prefix);
51 
52  // Store IMU msgs for world_T_dock estimation
53  void ImuCallback(const sensor_msgs::Imu& imu_msg);
54 
55  // Add flight mode msg to IMU filter.
56  void FlightModeCallback(const ff_msgs::FlightMode& flight_mode);
57 
58  // Add sparse map visual landmarks msg to graph_localizer.
59  void SparseMapVisualLandmarksCallback(const ff_msgs::VisualLandmarks& visual_landmarks_msg);
60 
61  // Add AR tag visual landmarks msg to graph_localizer.
62  void ARVisualLandmarksCallback(const ff_msgs::VisualLandmarks& visual_landmarks_msg);
63 
64  // Add graph vio state to graph localizer.
65  bool GraphVIOStateCallback(const ff_msgs::GraphVIOState& graph_vio_state_msg);
66 
67  // Updates the graph_localizer if it has been initialized.
68  void Update();
69 
70  // Returns whether the graph_localizer has been initialized.
71  bool Initialized() const;
72 
73  // Resets the graph.
74  void ResetLocalizer();
75 
76  // Resets the world_T_dock frame relative transform.
77  void ResetWorldTDock();
78 
79  // Returns the latest timestamp in the graph if it exists.
80  boost::optional<localization_common::Time> LatestTimestamp() const;
81 
82  // Returns the latest pose in the graph if it exists.
83  boost::optional<gtsam::Pose3> LatestPose() const;
84 
85  // Returns latest world_T_dock if it exists.
86  boost::optional<gtsam::Pose3> WorldTDock() const;
87 
88  // Creates graph loc state msg using latest pose and graph information
89  // in graph localizer.
90  // Returns boost::none if no state is available or no changes have occured since last msg.
91  boost::optional<ff_msgs::GraphLocState> GraphLocStateMsg();
92 
93  // Accessor to graph localizer
94  std::unique_ptr<graph_localizer::GraphLocalizer>& graph_localizer();
95 
96  // Const accessor to graph localizer
97  const std::unique_ptr<graph_localizer::GraphLocalizer>& graph_localizer() const;
98 
99  private:
100  // Initialize the graph
101  void Initialize();
102 
103  std::unique_ptr<graph_localizer::GraphLocalizer> graph_localizer_;
104  std::unique_ptr<imu_integration::ImuIntegrator> imu_integrator_;
105  localization_common::PoseInterpolater odom_interpolator_;
107  RosGraphLocalizerWrapperParams wrapper_params_;
109  boost::optional<localization_common::CombinedNavState> latest_vio_state_;
110  boost::optional<localization_common::Time> latest_msg_time_;
111  boost::optional<localization_common::Time> last_vio_msg_time_;
112  boost::optional<gtsam::Pose3> world_T_dock_;
113  int latest_num_detected_ml_features_;
114  int latest_num_detected_ar_features_;
115 };
116 } // namespace ros_graph_localizer
117 
118 #endif // ROS_GRAPH_LOCALIZER_ROS_GRAPH_LOCALIZER_WRAPPER_H_
ros_graph_localizer::RosGraphLocalizerWrapper::FlightModeCallback
void FlightModeCallback(const ff_msgs::FlightMode &flight_mode)
Definition: ros_graph_localizer_wrapper.cc:225
ros_graph_localizer::RosGraphLocalizerWrapper::LatestTimestamp
boost::optional< localization_common::Time > LatestTimestamp() const
Definition: ros_graph_localizer_wrapper.cc:251
ros_graph_localizer::RosGraphLocalizerWrapper::ARVisualLandmarksCallback
void ARVisualLandmarksCallback(const ff_msgs::VisualLandmarks &visual_landmarks_msg)
Definition: ros_graph_localizer_wrapper.cc:100
ros_graph_localizer::RosGraphLocalizerWrapperParams
Definition: ros_graph_localizer_wrapper_params.h:26
ros_graph_localizer::RosGraphLocalizerWrapper::GraphVIOStateCallback
bool GraphVIOStateCallback(const ff_msgs::GraphVIOState &graph_vio_state_msg)
Definition: ros_graph_localizer_wrapper.cc:180
ros_graph_localizer_wrapper_params.h
ros_graph_localizer::RosGraphLocalizerWrapper::ImuCallback
void ImuCallback(const sensor_msgs::Imu &imu_msg)
Definition: ros_graph_localizer_wrapper.cc:221
ros_graph_localizer
Definition: parameter_reader.h:27
ros_graph_localizer::RosGraphLocalizerWrapper::LoadConfigs
void LoadConfigs(const std::string &graph_config_path_prefix)
Definition: ros_graph_localizer_wrapper.cc:48
graph_localizer.h
ros_graph_localizer::RosGraphLocalizerWrapper::ResetLocalizer
void ResetLocalizer()
Definition: ros_graph_localizer_wrapper.cc:235
timestamped_set.h
localization_common::TimestampedSet< ff_msgs::GraphVIOState >
ros_graph_localizer::RosGraphLocalizerWrapper::Initialized
bool Initialized() const
Definition: ros_graph_localizer_wrapper.cc:233
ros_graph_localizer::RosGraphLocalizerWrapper::SparseMapVisualLandmarksCallback
void SparseMapVisualLandmarksCallback(const ff_msgs::VisualLandmarks &visual_landmarks_msg)
Definition: ros_graph_localizer_wrapper.cc:58
ros_graph_localizer::RosGraphLocalizerWrapper::GraphLocStateMsg
boost::optional< ff_msgs::GraphLocState > GraphLocStateMsg()
Definition: ros_graph_localizer_wrapper.cc:279
ros_graph_localizer::RosGraphLocalizerWrapper::WorldTDock
boost::optional< gtsam::Pose3 > WorldTDock() const
Definition: ros_graph_localizer_wrapper.cc:269
localization_common::TimestampedInterpolater
Definition: timestamped_interpolater.h:40
imu_integrator.h
graph_localizer::GraphLocalizerParams
Definition: graph_localizer_params.h:31
ros_graph_localizer::RosGraphLocalizerWrapper::LatestPose
boost::optional< gtsam::Pose3 > LatestPose() const
Definition: ros_graph_localizer_wrapper.cc:259
ros_graph_localizer::RosGraphLocalizerWrapper::Update
void Update()
Definition: ros_graph_localizer_wrapper.cc:229
ros_graph_localizer::RosGraphLocalizerWrapper
Definition: ros_graph_localizer_wrapper.h:45
ros_graph_localizer::RosGraphLocalizerWrapper::graph_localizer
std::unique_ptr< graph_localizer::GraphLocalizer > & graph_localizer()
Definition: ros_graph_localizer_wrapper.cc:271
ros_graph_localizer::RosGraphLocalizerWrapper::RosGraphLocalizerWrapper
RosGraphLocalizerWrapper(const std::string &graph_config_path_prefix="")
Definition: ros_graph_localizer_wrapper.cc:40
imu_measurement.h
fan_speed_mode.h
ros_graph_localizer::RosGraphLocalizerWrapper::ResetWorldTDock
void ResetWorldTDock()
Definition: ros_graph_localizer_wrapper.cc:267
pose_interpolater.h