ISAAC  0.2.11
Flight software for the ISAAC project, adding functionality to the Astrobee robot, operating inside the International Space Station.
All Classes Functions Variables Pages
inspection.h
1 /* Copyright (c) 2021, United States Government, as represented by the
2  * Administrator of the National Aeronautics and Space Administration.
3  *
4  * All rights reserved.
5  *
6  * The "ISAAC - Integrated System for Autonomous and Adaptive Caretaking
7  * platform" software is licensed under the Apache License, Version 2.0
8  * (the "License"); you may not use this file except in compliance with the
9  * License. You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16  * License for the specific language governing permissions and limitations
17  * under the License.
18  */
19 
20 #ifndef INSPECTION_INSPECTION_H_
21 #define INSPECTION_INSPECTION_H_
22 
23 // Standard ROS includes
24 #include <nodelet/nodelet.h>
25 #include <pluginlib/class_list_macros.h>
26 #include <ros/ros.h>
27 
28 // TF2 support
29 #include <tf2_ros/transform_listener.h>
30 #include <tf2_geometry_msgs/tf2_geometry_msgs.h>
31 
32 // Shared project includes
33 #include <ff_util/ff_nodelet.h>
34 #include <ff_util/ff_action.h>
35 #include <ff_util/ff_service.h>
36 #include <ff_util/ff_fsm.h>
37 #include <ff_util/config_server.h>
38 #include <ff_util/config_client.h>
39 #include <msg_conversions/msg_conversions.h>
40 #include <config_reader/config_reader.h>
41 #include <ff_util/ff_flight.h>
42 #include <isaac_util/isaac_names.h>
43 #include <inspection/camera_projection.h>
44 
45 // Point Cloud
46 #include <sensor_msgs/PointCloud.h>
47 #include <sensor_msgs/PointCloud2.h>
48 #include <sensor_msgs/point_cloud_conversion.h>
49 
50 // Software messages
51 #include <visualization_msgs/MarkerArray.h>
52 #include <ff_msgs/Zone.h>
53 #include <geometry_msgs/PoseArray.h>
54 
55 // Services
56 #include <ff_msgs/SetState.h>
57 #include <ff_msgs/GetZones.h>
58 #include <ff_msgs/GetMap.h>
59 
60 // Actions
61 #include <ff_msgs/MotionAction.h>
62 #include <ff_msgs/DockAction.h>
63 #include <isaac_msgs/ImageInspectionAction.h>
64 #include <isaac_msgs/InspectionAction.h>
65 
66 // Eigen for math
67 #include <Eigen/Dense>
68 
69 // C++ headers
70 #include <vector>
71 #include <string>
72 #include <map>
73 
77 namespace inspection {
78 
79 /*
80  This class provides the high-level logic that allows the freeflyer to
81  define the inspection poses for the different survey types.
82  It calls the survey generator and evaluates plans regarding:
83 
84  * Visibility constraints (anomaly inspection only)
85  * Keepout and Keepin zones
86  * Obstacle map
87 
88  It returns a vector of inspection poses. "In the case of an anomaly inspection,
89  if the move action fails due to planning or an unmapped obstacle, it saves the
90  sorted alternatives such that replanning isn't necessary.
91  It also constains functions that allow inspection visualization.
92 */
93 class Inspection {
94  public:
95  // Constructor
96  Inspection(ros::NodeHandle* nh, ff_util::ConfigServer* cfg);
97  // Read parameters from config server
98  void ReadParam();
99 
100  // Remove head of segment if planing failed
101  bool RemoveInspectionPose();
102  // Get te head of the inspection poses segment
103  geometry_msgs::PoseArray GetCurrentInspectionPose();
104  bool NextInspectionPose();
105  bool RedoInspectionPose();
106  geometry_msgs::PoseArray GetInspectionPoses();
107 
108  int GetCurrentCounter() {return inspection_counter_ + 1;}
109  int GetSurveySize() {return points_.size();}
110 
111  // Get distance from camera to target
112  double GetDistanceToTarget();
113 
114  // Generate the supported inspection methods
115  bool GenerateAnomalySurvey(geometry_msgs::PoseArray &points_anomaly);
116  bool GenerateGeometrySurvey(geometry_msgs::PoseArray &points_geometry);
117  bool GeneratePanoramaSurvey(geometry_msgs::PoseArray &points_panorama);
118  bool GenerateVolumetricSurvey(geometry_msgs::PoseArray &points_volume);
119 
120  protected:
121  // Ensure all clients are connected
122  void ConnectedCallback();
123  // Timeout on a zone check request
124  void CheckZonesTimeoutCallback();
125  // Timeout on a map check request
126  void CheckMapTimeoutCallback();
127 
128  // This function transforms the points from the camera rf to the body rf
129  bool TransformList(geometry_msgs::PoseArray points_in, geometry_msgs::PoseArray &points_out,
130  Eigen::Affine3d target_transform);
131  // Checks the given points agains whether the target is visible
132  // from a camera picture
133  bool VisibilityConstraint(geometry_msgs::PoseArray &points, Eigen::Affine3d target_transform);
134  bool PointInsideCuboid(geometry_msgs::Point const& x,
135  geometry_msgs::Vector3 const& cubemin,
136  geometry_msgs::Vector3 const& cubemax);
137  bool ZonesConstraint(geometry_msgs::PoseArray &points);
138  bool ObstaclesConstraint(geometry_msgs::PoseArray &points);
139 
140  // Draws the possible inspection poses
141  void DrawPoseMarkers(geometry_msgs::PoseArray &points,
142  ros::Publisher &publisher);
143  // Draws visibility frostum projection
144  void DrawCameraFrustum();
145 
146  // This function generates a sorted list based on the max viewing angle and resolution
147  bool GenerateSortedList(geometry_msgs::PoseArray &points);
148 
149  private:
150  ff_util::FreeFlyerServiceClient<ff_msgs::GetZones> client_z_;
151  ff_util::FreeFlyerServiceClient<ff_msgs::GetMap> client_o_;
152 
153  tf2_ros::Buffer tf_buffer_;
154  std::shared_ptr<tf2_ros::TransformListener> tf_listener_;
155 
156  // General inspection variables
157  std::string mode_;
158  int inspection_counter_;
159 
160  geometry_msgs::PoseArray goal_; // Vector containing inspection goals
161  std::vector<geometry_msgs::PoseArray> points_; // Vector containing inspection poses
162  Eigen::Quaterniond target_to_cam_rot_;
163 
164  // Camera Projection functions
165  std::string curr_camera_;
166  std::map<std::string, CameraView> cameras_;
167 
168  // Parameter clients
169  ff_util::ConfigServer *cfg_;
170  config_reader::ConfigReader cfg_cam_;
171 
172  // Inspection parameters
173  double horizontal_fov_;
174  double aspect_ratio_;
175  double target_size_x_;
176  double target_size_y_;
177  std::string depth_cam_;
178 
179  // Panorame parameters
180  bool auto_fov_;
181  double pan_min_;
182  double pan_max_;
183  double tilt_min_;
184  double tilt_max_;
185  double h_fov_;
186  double v_fov_;
187  double att_tol_;
188  double overlap_;
189 
190  // Publish Markers
191  ros::Publisher pub_targets_;
192  ros::Publisher pub_markers_;
193  ros::Publisher pub_cam_;
194 
195  public:
196  // This fixes the Eigen aligment issue
197  // http://eigen.tuxfamily.org/dox-devel/group__TopicUnalignedArrayAssert.html
198  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
199 };
200 
201 
202 } // namespace inspection
203 #endif // INSPECTION_INSPECTION_H_
inspection::Inspection
Definition: inspection.h:93