NASA Astrobee Robot Software  0.19.1
Flight software for the Astrobee robots operating inside the International Space Station.
ros_graph_localizer_nodelet.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_NODELET_H_
19 #define ROS_GRAPH_LOCALIZER_ROS_GRAPH_LOCALIZER_NODELET_H_
20 
22 #include <ff_msgs/GraphVIOState.h>
23 #include <ff_msgs/VisualLandmarks.h>
24 #include <ff_msgs/Heartbeat.h>
25 #include <ff_msgs/ResetMap.h>
26 #include <ff_msgs/SetEkfInput.h>
27 #include <ff_util/ff_nodelet.h>
33 
34 #include <image_transport/image_transport.h>
35 #include <ros/node_handle.h>
36 #include <ros/publisher.h>
37 #include <ros/subscriber.h>
38 #include <sensor_msgs/PointCloud2.h>
39 #include <std_srvs/Empty.h>
40 #include <tf2_ros/transform_broadcaster.h>
41 
42 #include <string>
43 #include <vector>
44 
45 namespace ros_graph_localizer {
47  public:
49 
50  private:
51  // Subscribes to and advertises topics. Calls Run() to start processing loop.
52  void Initialize(ros::NodeHandle* nh) final;
53 
54  // Subscribes to and advertises topics.
55  void SubscribeAndAdvertise(ros::NodeHandle* nh);
56 
57  // Set mode for Localizer. Disables if mode is none, resets and enables if swtiched from none.
58  bool SetMode(ff_msgs::SetEkfInput::Request& req, ff_msgs::SetEkfInput::Response& res);
59 
60  // Disabled Localizer and VIO. Prevents any messages from being added, halts publishing
61  // messages, and halts updating Localizer and VIO.
62  void DisableLocalizerAndVIO();
63 
64  // Enables Localizer and VIO.
65  void EnableLocalizerAndVIO();
66 
67  // Whether Localizer and VIO are enabled.
68  bool localizer_and_vio_enabled() const;
69 
70  // Resets VIO using re-estimation of biases and resets the localizer.
71  bool ResetBiasesAndLocalizer(std_srvs::Empty::Request& req, std_srvs::Empty::Response& res);
72 
73  // Resets VIO using biases in file (if available) and resets the localizer.
74  bool ResetBiasesFromFileAndResetLocalizer(std_srvs::Empty::Request& req, std_srvs::Empty::Response& res);
75 
76  // Resets VIO using biases in file (if available) and resets the localizer.
77  bool ResetBiasesFromFileAndResetLocalizer();
78 
79  // Resets the localizer.
80  void ResetAndEnableLocalizer();
81 
82  // Resets the localizer and clears the sparse map matched projections buffer
83  // so old measurements aren't used with a new map.
84  bool ResetMap(ff_msgs::ResetMap::Request& req, ff_msgs::ResetMap::Response& res);
85 
86  // Publish latest graph localizer state msg.
87  void PublishGraphLocalizerState();
88 
89  // Publishes empty reset message.
90  void PublishReset() const;
91 
92  // Publishes Loc pose message and other graph messages if Localizer is enabled.
93  void PublishGraphLocalizerMessages();
94 
95  // Publishes heartbeat message.
96  void PublishHeartbeat();
97 
98  // Publishes world_T_body transform
99  void PublishWorldTBodyTF();
100 
101  // Publishes world_T_dock transform
102  void PublishWorldTDockTF();
103 
104  // Passes ar tag visual landmarks msg to ros_graph_localizer_wrapper if Localizer is enabled.
105  void ARVisualLandmarksCallback(const ff_msgs::VisualLandmarks::ConstPtr& visual_landmarks_msg);
106 
107  // Passes sparse map visual landmarks msg to ros_graph_localizer_wrapper if Localizer is enabled.
108  void SparseMapVisualLandmarksCallback(const ff_msgs::VisualLandmarks::ConstPtr& visual_landmarks_msg);
109 
110  // Passes feature points msg to ros_graph_vio_wrapper if VIO is enabled.
111  void FeaturePointsCallback(const ff_msgs::Feature2dArray::ConstPtr& feature_array_msg);
112 
113  // Passes depth odometry msg to ros_graph_vio_wrapper if VIO is enabled.
114  void DepthOdometryCallback(const ff_msgs::DepthOdometry::ConstPtr& depth_odom_msg);
115 
116  // Passes depth point cloud msg to depth_odometry_wrapper if VIO is enabled.
117  void DepthPointCloudCallback(const sensor_msgs::PointCloud2ConstPtr& point_cloud_msg);
118 
119  // Passes depth image msg to depth_odometry_wrapper if VIO is enabled.
120  void DepthImageCallback(const sensor_msgs::ImageConstPtr& image_msg);
121 
122  // Passes IMU msg to ros_graph_vio_wrapper if VIO is enabled.
123  void ImuCallback(const sensor_msgs::Imu::ConstPtr& imu_msg);
124 
125  // Passes flight mode msg to ros_graph_vio_wrapper if VIO is enabled.
126  void FlightModeCallback(ff_msgs::FlightMode::ConstPtr const& mode);
127 
128  // Adds messages to ros_graph_localizer_wrapper from callback queue, updates
129  // the ros_graph_localizer_wrapper, and pubishes messages.
130  // Runs iteratively on start up at a max 100Hz rate.
131  void Run();
132 
133  ros_graph_localizer::RosGraphLocalizerWrapper ros_graph_localizer_wrapper_;
134  ros_graph_vio::RosGraphVIOWrapper ros_graph_vio_wrapper_;
135  depth_odometry::DepthOdometryWrapper depth_odometry_wrapper_;
136  ros::NodeHandle private_nh_;
137  ros::CallbackQueue private_queue_;
138  bool localizer_and_vio_enabled_ = true;
139  ros::Subscriber sparse_map_vl_sub_, ar_tag_vl_sub_;
140  ros::Publisher graph_loc_pub_, reset_pub_, heartbeat_pub_;
141  tf2_ros::TransformBroadcaster transform_pub_;
142  ros::ServiceServer bias_srv_, bias_from_file_srv_, reset_map_srv_, reset_srv_, input_mode_srv_;
143  std::string platform_name_;
144  ff_msgs::Heartbeat heartbeat_;
146  int last_mode_ = -1;
147 
148  ros::Time last_heartbeat_time_;
149  ros::Time last_tf_body_time_;
150  ros::Time last_tf_dock_time_;
151 
152  // VIO
153  ros::Publisher graph_vio_state_pub_, graph_vio_pub_, depth_odom_pub_;
154  ros::Subscriber imu_sub_, depth_point_cloud_sub_, depth_odom_sub_, fp_sub_, flight_mode_sub_;
155  image_transport::Subscriber depth_image_sub_;
156 };
157 } // namespace ros_graph_localizer
158 
159 #endif // ROS_GRAPH_LOCALIZER_ROS_GRAPH_LOCALIZER_NODELET_H_
mode
uint8_t mode
Definition: signal_lights.h:74
depth_odometry_wrapper.h
ros_graph_vio_wrapper.h
ros_graph_vio::RosGraphVIOWrapper
Definition: ros_graph_vio_wrapper.h:41
ros_graph_localizer
Definition: parameter_reader.h:27
ff_nodelet.h
depth_odometry::DepthOdometryWrapper
Definition: depth_odometry_wrapper.h:39
timer.h
ff_util::FreeFlyerNodelet
Definition: ff_nodelet.h:57
ros_graph_localizer_nodelet_params.h
ros_graph_localizer::RosGraphLocalizerNodeletParams
Definition: ros_graph_localizer_nodelet_params.h:22
ros_timer.h
ros_graph_localizer::RosGraphLocalizerNodelet::RosGraphLocalizerNodelet
RosGraphLocalizerNodelet()
Definition: ros_graph_localizer_nodelet.cc:33
ros_graph_localizer::RosGraphLocalizerWrapper
Definition: ros_graph_localizer_wrapper.h:45
ros_graph_localizer_wrapper.h
localization_common::Time
double Time
Definition: time.h:23
ros_graph_localizer::RosGraphLocalizerNodelet
Definition: ros_graph_localizer_nodelet.h:46