NASA Astrobee Robot Software  0.19.1
Flight software for the Astrobee robots operating inside the International Space Station.
ros_graph_vio_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_VIO_ROS_GRAPH_VIO_WRAPPER_H_
19 #define ROS_GRAPH_VIO_ROS_GRAPH_VIO_WRAPPER_H_
20 
21 #include <ff_msgs/DepthOdometry.h>
22 #include <ff_msgs/Feature2dArray.h>
23 #include <ff_msgs/FlightMode.h>
24 #include <ff_msgs/GraphVIOState.h>
25 // #include <ff_msgs/SerializedGraph.h>
26 #include <graph_vio/graph_vio.h>
31 
32 #include <sensor_msgs/Imu.h>
33 
34 #include <string>
35 #include <utility>
36 
37 namespace ros_graph_vio {
38 // Converts ROS messages and passes these to the GraphVIO graph.
39 // Initializes the biases fro the graph using IMU messages.
40 // Creates msgs from latest combined nav states in the graph.
42  public:
43  explicit RosGraphVIOWrapper(const std::string& graph_config_path_prefix = "");
44 
45  // Load configs for graph_vio and IMU bias initializer.
46  void LoadConfigs(const std::string& graph_config_path_prefix);
47 
48  // Add feature points msg to graph_vio.
49  void FeaturePointsCallback(const ff_msgs::Feature2dArray& feature_array_msg);
50 
51  // Add imu msg to graph_vio and IMU bias initializer if necessary.
52  // If the graph hasn't been initialized and an imu bias is
53  // available in the initializer, initializes the graph.
54  void ImuCallback(const sensor_msgs::Imu& imu_msg);
55 
56  // Add depth odometry msg to graph_vio.
57  void DepthOdometryCallback(const ff_msgs::DepthOdometry& depth_odometry_msg);
58 
59  // Add flight mode msg to graph_vio and IMU bias initializer.
60  void FlightModeCallback(const ff_msgs::FlightMode& flight_mode);
61 
62  // Updates the graph_vio if it has been initialized.
63  void Update();
64 
65  // Returns whether the graph_vio has been initialized.
66  bool Initialized() const;
67 
68  // Resets the graph with the latest biases.
69  void ResetVIO();
70 
71  // Resets the graph and biases. Biases need to be estimated again by the bias initializer.
72  void ResetBiasesAndVIO();
73 
74  // Resets the graph and and loads biases from a saved file.
76 
77  // Creates a GraphVIOState msg using the history
78  // of nav states and covariances in graph_vio.
79  // Returns boost::none if no states available or no changes
80  // have occured since last msg.
81  boost::optional<ff_msgs::GraphVIOState> GraphVIOStateMsg();
82 
83  // Const accessor to graph_vio object
84  const std::unique_ptr<graph_vio::GraphVIO>& graph_vio() const;
85 
86  // Accessor to graph_vio object
87  std::unique_ptr<graph_vio::GraphVIO>& graph_vio();
88 
89  private:
90  // Initialize the graph if the IMU bias is initialized.
91  void Initialize();
92 
93  std::unique_ptr<graph_vio::GraphVIO> graph_vio_;
94  std::unique_ptr<ImuBiasInitializer> imu_bias_initializer_;
96  boost::optional<localization_common::Time> latest_msg_time_;
97  RosGraphVIOWrapperParams wrapper_params_;
98  int feature_point_count_;
99 };
100 } // namespace ros_graph_vio
101 
102 #endif // ROS_GRAPH_VIO_ROS_GRAPH_VIO_WRAPPER_H_
ros_graph_vio::RosGraphVIOWrapper::GraphVIOStateMsg
boost::optional< ff_msgs::GraphVIOState > GraphVIOStateMsg()
Definition: ros_graph_vio_wrapper.cc:165
ros_graph_vio::RosGraphVIOWrapper::ResetVIO
void ResetVIO()
Definition: ros_graph_vio_wrapper.cc:120
ros_graph_vio_wrapper_params.h
ros_graph_vio
Definition: imu_bias_initializer.h:31
imu_bias_initializer.h
ros_graph_vio::RosGraphVIOWrapper
Definition: ros_graph_vio_wrapper.h:41
ros_graph_vio::RosGraphVIOWrapper::FlightModeCallback
void FlightModeCallback(const ff_msgs::FlightMode &flight_mode)
Definition: ros_graph_vio_wrapper.cc:108
ros_graph_vio::RosGraphVIOWrapper::ResetBiasesFromFileAndResetVIO
void ResetBiasesFromFileAndResetVIO()
Definition: ros_graph_vio_wrapper.cc:159
graph_vio::GraphVIOParams
Definition: graph_vio_params.h:34
graph_vio.h
ros_graph_vio::RosGraphVIOWrapper::ResetBiasesAndVIO
void ResetBiasesAndVIO()
Definition: ros_graph_vio_wrapper.cc:153
ros_graph_vio::RosGraphVIOWrapper::Update
void Update()
Definition: ros_graph_vio_wrapper.cc:114
ros_graph_vio::RosGraphVIOWrapper::ImuCallback
void ImuCallback(const sensor_msgs::Imu &imu_msg)
Definition: ros_graph_vio_wrapper.cc:62
ros_graph_vio::RosGraphVIOWrapper::FeaturePointsCallback
void FeaturePointsCallback(const ff_msgs::Feature2dArray &feature_array_msg)
Definition: ros_graph_vio_wrapper.cc:53
ros_graph_vio::RosGraphVIOWrapper::DepthOdometryCallback
void DepthOdometryCallback(const ff_msgs::DepthOdometry &depth_odometry_msg)
Definition: ros_graph_vio_wrapper.cc:58
ros_graph_vio::RosGraphVIOWrapper::LoadConfigs
void LoadConfigs(const std::string &graph_config_path_prefix)
Definition: ros_graph_vio_wrapper.cc:40
ros_graph_vio::RosGraphVIOWrapperParams
Definition: ros_graph_vio_wrapper_params.h:22
ros_graph_vio::RosGraphVIOWrapper::RosGraphVIOWrapper
RosGraphVIOWrapper(const std::string &graph_config_path_prefix="")
Definition: ros_graph_vio_wrapper.cc:36
ros_graph_vio::RosGraphVIOWrapper::graph_vio
const std::unique_ptr< graph_vio::GraphVIO > & graph_vio() const
Definition: ros_graph_vio_wrapper.cc:221
imu_measurement.h
fan_speed_mode.h
ros_graph_vio::RosGraphVIOWrapper::Initialized
bool Initialized() const
Definition: ros_graph_vio_wrapper.cc:118