导航

CV学习日志:CV开发之常用头文件

Posted on 2020-01-30 00:10  dzyBK  阅读(453)  评论(0编辑  收藏  举报

1.CV开发常用库

        (1)语言/视觉:CPP、OpenCV、OpenGV

        (2)通信/模拟:Asio、ROS、Gazebo、Webots

        (3)日志/数学:Eigen、Gflags、Glog、Ceres、Sophus、CLI11、Spdlog、Cereal

        (4)其它可能库:Octomap、QT、TBB

 

1.MACXX头文件

        保存非通信/模拟库到macxx文件:

  1 //1.C headers and Reference: http://www.cplusplus.com/reference/clibrary/
  2 //1.1 C89 headers(18)
  3 //#include <assert.h>
  4 //#include <ctype.h>
  5 //#include <errno.h>
  6 //#include <float.h>
  7 //#include <iso646.h>
  8 //#include <limits.h>
  9 //#include <locale.h>
 10 //#include <math.h>
 11 //#include <setjmp.h>
 12 //#include <signal.h>
 13 //#include <stdarg.h>
 14 //#include <stddef.h>
 15 //#include <stdio.h>
 16 //#include <stdlib.h>
 17 //#include <string.h>
 18 //#include <time.h>
 19 //#include <wchar.h>
 20 //#include <wctype.h>
 21 ////1.2 C99 headers(6)
 22 //#include <complex.h>
 23 //#include <fenv.h>
 24 //#include <inttypes.h>
 25 //#include <stdbool.h>
 26 //#include <stdint.h>
 27 //#include <tgmath.h>
 28 ////1.3 C11 headers(5)
 29 //#include <stdalign.h>
 30 //#include <stdatomic.h>
 31 //#include <stdnoreturn.h>
 32 //#include <threads.h>
 33 //#include <uchar.h>
 34 
 35 //2.CPP headers(50) and Reference: http://en.cppreference.com/w/cpp/header
 36 //2.1 C++98 and C++03 headers(50)
 37 #include <cassert>
 38 #include <cctype>
 39 #include <cerrno>
 40 #include <cfloat>
 41 #include <ciso646>
 42 #include <climits>
 43 #include <clocale>
 44 #include <cmath>
 45 #include <csetjmp>
 46 #include <csignal>
 47 #include <cstdarg>
 48 #include <cstddef>
 49 #include <cstdio>
 50 #include <cstdlib>
 51 #include <cstring>
 52 #include <ctime>
 53 #include <cwchar>
 54 #include <cwctype>
 55 #include <deque>
 56 #include <list>
 57 #include <vector>
 58 #include <set>
 59 #include <map>
 60 #include <queue>
 61 #include <stack>
 62 #include <algorithm>
 63 #include <string>
 64 #include <iterator>
 65 #include <memory>
 66 #include <new>
 67 #include <ios>
 68 #include <iosfwd>
 69 #include <iomanip>
 70 #include <iostream>
 71 #include <istream>
 72 #include <ostream>
 73 #include <fstream>
 74 #include <sstream>
 75 #include <streambuf>
 76 #include <exception>
 77 #include <stdexcept>
 78 #include <complex>
 79 #include <limits>
 80 #include <numeric>
 81 #include <valarray>
 82 #include <locale>
 83 #include <bitset>
 84 #include <functional>
 85 #include <typeinfo>
 86 #include <utility>
 87 //2.2 C++11 and C++14 headers(25)
 88 #include <typeindex>
 89 #include <type_traits>
 90 #include <chrono>
 91 #include <initializer_list>
 92 #include <tuple>
 93 #include <scoped_allocator>
 94 #include <cstdint>
 95 #include <cinttypes>
 96 #include <system_error>
 97 #include <cuchar>
 98 #include <array>
 99 #include <forward_list>
100 #include <unordered_map>
101 #include <unordered_set>
102 #include <random>
103 #include <ratio>
104 #include <cfenv>
105 #include <codecvt>
106 #include <regex>
107 #include <atomic>
108 #include <thread>
109 #include <mutex>
110 #include <shared_mutex>
111 #include <future>
112 #include <condition_variable>
113 
114 //3.Qt5.x headers
115 #include <asio.hpp>
116 #include <QtGui/QtGui>
117 #include <QtCore/QtCore>
118 #include <QtWidgets/QtWidgets>
119 #include <QtNetwork/QtNetwork>
120 #include <QtSerialPort/QtSerialPort>
121 #include <QtMultimedia/QtMultimedia>
122 #include <QtMultimediaWidgets/QtMultimediaWidgets>
123 #include <QtSql/QtSql>
124 #include <QtCharts/QtCharts>
125 #include <QtDataVisualization/QtDataVisualization>
126 
127 //4.Eigen&Ceres&Sophus&Asio&CLI11&Spdlog headers
128 #include <Eigen/Eigen>
129 #include <ceres/ceres.h>
130 #include <ceres/rotation.h>
131 #include <sophus/geometry.hpp>
132 #include <CLI/CLI.hpp>
133 #include <spdlog/spdlog.h>
134 #include <spdlog/async.h>
135 #include <spdlog/sinks/basic_file_sink.h>
136 #include <spdlog/sinks/rotating_file_sink.h>
137 
138 //5.OpenCV4.x headers
139 #include <opencv2/opencv.hpp>
140 #include <opencv2/core/async.hpp>
141 #include <opencv2/core/utils/filesystem.hpp>
142 #include <opencv2/viz.hpp>
143 #include <opencv2/plot.hpp>
144 #include <opencv2/aruco.hpp>
145 #include <opencv2/xphoto.hpp>
146 #include <opencv2/ximgproc.hpp>
147 #include <opencv2/xobjdetect.hpp>
148 #include <opencv2/ccalib/multicalib.hpp>
149 #include <opencv2/core/core_c.h> //for CvLevMarq
150 #include <opencv2/calib3d/calib3d_c.h> //for CvLevMarq
151 
152 //6.ROS2&Gazebo11&Webots202x headers
153 #include "maros.h"
154 
155 //9.Namespaces used often
156 using namespace std;
157 using namespace cv;
158 using namespace QtDataVisualization;
159 
160 //10.Additional headers
161 //10.1Octomap headers
162 #include <octomap/OcTree.h>
163 #include <octomap/ColorOcTree.h>
164 #include <octomap/OcTreeStamped.h>
165 #include <octomap/CountingOcTree.h>
166 #include <octomap/MapCollection.h>
View Code

 

2.MAROS头文件

        保存通信/模拟库到maros文件:

  1 #define stdmsg std_msgs::msg
  2 #define stdsrv std_srvs::srv
  3 #define geomsg geometry_msgs::msg
  4 #define ssrmsg sensor_msgs::msg
  5 
  6 #if 1
  7 #include <webots/GPS.hpp>
  8 #include <webots/LED.hpp>
  9 #include <webots/Pen.hpp>
 10 #include <webots/Gyro.hpp>
 11 #include <webots/Node.hpp>
 12 #include <webots/Skin.hpp>
 13 #include <webots/Brake.hpp>
 14 #include <webots/Field.hpp>
 15 #include <webots/Lidar.hpp>
 16 #include <webots/Motor.hpp>
 17 #include <webots/Mouse.hpp>
 18 #include <webots/Radar.hpp>
 19 #include <webots/Robot.hpp>
 20 #include <webots/Camera.hpp>
 21 #include <webots/Device.hpp>
 22 #include <webots/Compass.hpp>
 23 #include <webots/Display.hpp>
 24 #include <webots/Emitter.hpp>
 25 #include <webots/Speaker.hpp>
 26 #include <webots/ImageRef.hpp>
 27 #include <webots/Joystick.hpp>
 28 #include <webots/Keyboard.hpp>
 29 #include <webots/Receiver.hpp>
 30 #include <webots/Connector.hpp>
 31 #include <webots/Supervisor.hpp>
 32 #include <webots/LightSensor.hpp>
 33 #include <webots/RangeFinder.hpp>
 34 #include <webots/TouchSensor.hpp>
 35 #include <webots/vehicle/Car.hpp>
 36 #include <webots/InertialUnit.hpp>
 37 #include <webots/utils/Motion.hpp>
 38 #include <webots/Accelerometer.hpp>
 39 #include <webots/DistanceSensor.hpp>
 40 #include <webots/PositionSensor.hpp>
 41 #include <webots/vehicle/Driver.hpp>
 42 #include <webots/utils/AnsiCodes.hpp>
 43 #include <webots/DifferentialWheels.hpp>
 44 #endif
 45 
 46 #if 1
 47 
 48 //ament_index_cpp
 49 #include <ament_index_cpp/get_resource.hpp>
 50 #include <ament_index_cpp/has_resource.hpp>
 51 #include <ament_index_cpp/get_resources.hpp>
 52 #include <ament_index_cpp/get_search_paths.hpp>
 53 #include <ament_index_cpp/get_package_prefix.hpp>
 54 #include <ament_index_cpp/get_packages_with_prefixes.hpp>
 55 #include <ament_index_cpp/get_package_share_directory.hpp>
 56 
 57 //rclcpp
 58 #include <rclcpp/qos.hpp>
 59 #include <rclcpp/node.hpp>
 60 #include <rclcpp/rate.hpp>
 61 #include <rclcpp/time.hpp>
 62 #include <rclcpp/clock.hpp>
 63 #include <rclcpp/event.hpp>
 64 #include <rclcpp/timer.hpp>
 65 #include <rclcpp/client.hpp>
 66 #include <rclcpp/logger.hpp>
 67 #include <rclcpp/macros.hpp>
 68 #include <rclcpp/rclcpp.hpp>
 69 #include <rclcpp/context.hpp>
 70 #include <rclcpp/logging.hpp>
 71 #include <rclcpp/service.hpp>
 72 #include <rclcpp/duration.hpp>
 73 #include <rclcpp/executor.hpp>
 74 #include <rclcpp/wait_set.hpp>
 75 #include <rclcpp/waitable.hpp>
 76 #include <rclcpp/executors.hpp>
 77 #include <rclcpp/parameter.hpp>
 78 #include <rclcpp/publisher.hpp>
 79 #include <rclcpp/qos_event.hpp>
 80 #include <rclcpp/utilities.hpp>
 81 #include <rclcpp/exceptions.hpp>
 82 #include <rclcpp/scope_exit.hpp>
 83 #include <rclcpp/time_source.hpp>
 84 #include <rclcpp/wait_result.hpp>
 85 #include <rclcpp/create_timer.hpp>
 86 #include <rclcpp/init_options.hpp>
 87 #include <rclcpp/message_info.hpp>
 88 #include <rclcpp/node_options.hpp>
 89 #include <rclcpp/subscription.hpp>
 90 #include <rclcpp/create_client.hpp>
 91 #include <rclcpp/parameter_map.hpp>
 92 #include <rclcpp/serialization.hpp>
 93 #include <rclcpp/any_executable.hpp>
 94 #include <rclcpp/callback_group.hpp>
 95 #include <rclcpp/create_service.hpp>
 96 #include <rclcpp/graph_listener.hpp>
 97 #include <rclcpp/loaned_message.hpp>
 98 #include <rclcpp/publisher_base.hpp>
 99 #include <rclcpp/function_traits.hpp>
100 #include <rclcpp/guard_condition.hpp>
101 #include <rclcpp/memory_strategy.hpp>
102 #include <rclcpp/parameter_value.hpp>
103 #include <rclcpp/create_publisher.hpp>
104 #include <rclcpp/executor_options.hpp>
105 #include <rclcpp/parameter_client.hpp>
106 #include <rclcpp/wait_result_kind.hpp>
107 #include <rclcpp/memory_strategies.hpp>
108 #include <rclcpp/parameter_service.hpp>
109 #include <rclcpp/publisher_factory.hpp>
110 #include <rclcpp/publisher_options.hpp>
111 #include <rclcpp/subscription_base.hpp>
112 #include <rclcpp/type_support_decl.hpp>
113 #include <rclcpp/wait_set_template.hpp>
114 #include <rclcpp/future_return_code.hpp>
115 #include <rclcpp/serialized_message.hpp>
116 #include <rclcpp/visibility_control.hpp>
117 #include <rclcpp/create_subscription.hpp>
118 #include <rclcpp/subscription_traits.hpp>
119 #include <rclcpp/any_service_callback.hpp>
120 #include <rclcpp/subscription_factory.hpp>
121 #include <rclcpp/subscription_options.hpp>
122 #include <rclcpp/intra_process_setting.hpp>
123 #include <rclcpp/topic_statistics_state.hpp>
124 #include <rclcpp/message_memory_strategy.hpp>
125 #include <rclcpp/parameter_events_filter.hpp>
126 #include <rclcpp/any_subscription_callback.hpp>
127 #include <rclcpp/intra_process_buffer_type.hpp>
128 #include <rclcpp/subscription_wait_set_mask.hpp>
129 #include <rclcpp/expand_topic_or_service_name.hpp>
130 
131 //rclcpp_action
132 #include <rclcpp_action/qos.hpp>
133 #include <rclcpp_action/types.hpp>
134 #include <rclcpp_action/client.hpp>
135 #include <rclcpp_action/server.hpp>
136 #include <rclcpp_action/exceptions.hpp>
137 #include <rclcpp_action/create_client.hpp>
138 #include <rclcpp_action/create_server.hpp>
139 #include <rclcpp_action/rclcpp_action.hpp>
140 #include <rclcpp_action/client_goal_handle.hpp>
141 #include <rclcpp_action/server_goal_handle.hpp>
142 #include <rclcpp_action/visibility_control.hpp>
143 
144 //std_msgs
145 #include <std_msgs/msg/bool.hpp>
146 #include <std_msgs/msg/byte.hpp>
147 #include <std_msgs/msg/char.hpp>
148 #include <std_msgs/msg/int8.hpp>
149 #include <std_msgs/msg/empty.hpp>
150 #include <std_msgs/msg/int16.hpp>
151 #include <std_msgs/msg/int32.hpp>
152 #include <std_msgs/msg/int64.hpp>
153 #include <std_msgs/msg/header.hpp>
154 #include <std_msgs/msg/string.hpp>
155 #include <std_msgs/msg/u_int8.hpp>
156 #include <std_msgs/msg/float32.hpp>
157 #include <std_msgs/msg/float64.hpp>
158 #include <std_msgs/msg/u_int16.hpp>
159 #include <std_msgs/msg/u_int32.hpp>
160 #include <std_msgs/msg/u_int64.hpp>
161 #include <std_msgs/msg/color_rgba.hpp>
162 #include <std_msgs/msg/byte_multi_array.hpp>
163 #include <std_msgs/msg/int8_multi_array.hpp>
164 #include <std_msgs/msg/int16_multi_array.hpp>
165 #include <std_msgs/msg/int32_multi_array.hpp>
166 #include <std_msgs/msg/int64_multi_array.hpp>
167 #include <std_msgs/msg/multi_array_layout.hpp>
168 #include <std_msgs/msg/u_int8_multi_array.hpp>
169 #include <std_msgs/msg/float32_multi_array.hpp>
170 #include <std_msgs/msg/float64_multi_array.hpp>
171 #include <std_msgs/msg/u_int16_multi_array.hpp>
172 #include <std_msgs/msg/u_int32_multi_array.hpp>
173 #include <std_msgs/msg/u_int64_multi_array.hpp>
174 #include <std_msgs/msg/multi_array_dimension.hpp>
175 
176 //std_srvs
177 #include <std_srvs/srv/empty.hpp>
178 #include <std_srvs/srv/trigger.hpp>
179 #include <std_srvs/srv/set_bool.hpp>
180 
181 //builtin_interfaces
182 #include <builtin_interfaces/msg/time.hpp>
183 #include <builtin_interfaces/msg/duration.hpp>
184 
185 //sensor_msgs
186 #include <sensor_msgs/fill_image.hpp>
187 #include <sensor_msgs/image_encodings.hpp>
188 #include <sensor_msgs/distortion_models.hpp>
189 #include <sensor_msgs/point_cloud2_iterator.hpp>
190 #include <sensor_msgs/point_cloud_conversion.hpp>
191 #include <sensor_msgs/point_field_conversion.hpp>
192 #include <sensor_msgs/msg/imu.hpp>
193 #include <sensor_msgs/msg/joy.hpp>
194 #include <sensor_msgs/msg/image.hpp>
195 #include <sensor_msgs/msg/range.hpp>
196 #include <sensor_msgs/msg/laser_echo.hpp>
197 #include <sensor_msgs/msg/laser_scan.hpp>
198 #include <sensor_msgs/msg/camera_info.hpp>
199 #include <sensor_msgs/msg/illuminance.hpp>
200 #include <sensor_msgs/msg/joint_state.hpp>
201 #include <sensor_msgs/msg/nav_sat_fix.hpp>
202 #include <sensor_msgs/msg/point_cloud.hpp>
203 #include <sensor_msgs/msg/point_field.hpp>
204 #include <sensor_msgs/msg/temperature.hpp>
205 #include <sensor_msgs/msg/joy_feedback.hpp>
206 #include <sensor_msgs/msg/point_cloud2.hpp>
207 #include <sensor_msgs/msg/battery_state.hpp>
208 #include <sensor_msgs/msg/fluid_pressure.hpp>
209 #include <sensor_msgs/msg/magnetic_field.hpp>
210 #include <sensor_msgs/msg/nav_sat_status.hpp>
211 #include <sensor_msgs/msg/time_reference.hpp>
212 #include <sensor_msgs/msg/channel_float32.hpp>
213 #include <sensor_msgs/msg/compressed_image.hpp>
214 #include <sensor_msgs/msg/relative_humidity.hpp>
215 #include <sensor_msgs/msg/joy_feedback_array.hpp>
216 #include <sensor_msgs/msg/region_of_interest.hpp>
217 #include <sensor_msgs/msg/multi_dof_joint_state.hpp>
218 #include <sensor_msgs/msg/multi_echo_laser_scan.hpp>
219 #include <sensor_msgs/srv/set_camera_info.hpp>
220 
221 //geometry_msgs
222 #include <geometry_msgs/msg/pose.hpp>
223 #include <geometry_msgs/msg/accel.hpp>
224 #include <geometry_msgs/msg/point.hpp>
225 #include <geometry_msgs/msg/twist.hpp>
226 #include <geometry_msgs/msg/wrench.hpp>
227 #include <geometry_msgs/msg/inertia.hpp>
228 #include <geometry_msgs/msg/point32.hpp>
229 #include <geometry_msgs/msg/polygon.hpp>
230 #include <geometry_msgs/msg/pose2_d.hpp>
231 #include <geometry_msgs/msg/vector3.hpp>
232 #include <geometry_msgs/msg/transform.hpp>
233 #include <geometry_msgs/msg/pose_array.hpp>
234 #include <geometry_msgs/msg/quaternion.hpp>
235 #include <geometry_msgs/msg/pose_stamped.hpp>
236 #include <geometry_msgs/msg/accel_stamped.hpp>
237 #include <geometry_msgs/msg/point_stamped.hpp>
238 #include <geometry_msgs/msg/twist_stamped.hpp>
239 #include <geometry_msgs/msg/wrench_stamped.hpp>
240 #include <geometry_msgs/msg/inertia_stamped.hpp>
241 #include <geometry_msgs/msg/polygon_stamped.hpp>
242 #include <geometry_msgs/msg/vector3_stamped.hpp>
243 #include <geometry_msgs/msg/transform_stamped.hpp>
244 #include <geometry_msgs/msg/quaternion_stamped.hpp>
245 #include <geometry_msgs/msg/pose_with_covariance.hpp>
246 #include <geometry_msgs/msg/accel_with_covariance.hpp>
247 #include <geometry_msgs/msg/twist_with_covariance.hpp>
248 #include <geometry_msgs/msg/pose_with_covariance_stamped.hpp>
249 #include <geometry_msgs/msg/accel_with_covariance_stamped.hpp>
250 #include <geometry_msgs/msg/twist_with_covariance_stamped.hpp>
251 
252 //trajectory_msgs
253 #include <trajectory_msgs/msg/joint_trajectory.hpp>
254 #include <trajectory_msgs/msg/joint_trajectory_point.hpp>
255 #include <trajectory_msgs/msg/multi_dof_joint_trajectory.hpp>
256 #include <trajectory_msgs/msg/multi_dof_joint_trajectory_point.hpp>
257 
258 //move_base_msgs
259 #include <move_base_msgs/action/move_base.hpp>
260 
261 //stereo_msgs
262 #include <stereo_msgs/msg/disparity_image.hpp>
263 
264 //shape_msgs
265 #include <shape_msgs/msg/mesh.hpp>
266 #include <shape_msgs/msg/plane.hpp>
267 #include <shape_msgs/msg/mesh_triangle.hpp>
268 #include <shape_msgs/msg/solid_primitive.hpp>
269 
270 //map_msgs
271 #include <map_msgs/msg/projected_map.hpp>
272 #include <map_msgs/msg/projected_map_info.hpp>
273 #include <map_msgs/msg/point_cloud2_update.hpp>
274 #include <map_msgs/msg/occupancy_grid_update.hpp>
275 #include <map_msgs/srv/save_map.hpp>
276 #include <map_msgs/srv/get_map_roi.hpp>
277 #include <map_msgs/srv/get_point_map.hpp>
278 #include <map_msgs/srv/get_point_map_roi.hpp>
279 #include <map_msgs/srv/projected_maps_info.hpp>
280 #include <map_msgs/srv/set_map_projections.hpp>
281 
282 //nav_msgs
283 #include <nav_msgs/msg/path.hpp>
284 #include <nav_msgs/msg/odometry.hpp>
285 #include <nav_msgs/msg/grid_cells.hpp>
286 #include <nav_msgs/msg/map_meta_data.hpp>
287 #include <nav_msgs/msg/occupancy_grid.hpp>
288 #include <nav_msgs/srv/get_map.hpp>
289 #include <nav_msgs/srv/set_map.hpp>
290 #include <nav_msgs/srv/get_plan.hpp>
291 
292 //visualization_msgs
293 #include <visualization_msgs/msg/marker.hpp>
294 #include <visualization_msgs/msg/menu_entry.hpp>
295 #include <visualization_msgs/msg/image_marker.hpp>
296 #include <visualization_msgs/msg/marker_array.hpp>
297 #include <visualization_msgs/msg/interactive_marker.hpp>
298 #include <visualization_msgs/msg/interactive_marker_init.hpp>
299 #include <visualization_msgs/msg/interactive_marker_pose.hpp>
300 #include <visualization_msgs/msg/interactive_marker_update.hpp>
301 #include <visualization_msgs/msg/interactive_marker_control.hpp>
302 #include <visualization_msgs/msg/interactive_marker_feedback.hpp>
303 #include <visualization_msgs/srv/get_interactive_markers.hpp>
304 
305 //diagnostic_msgs
306 #include <diagnostic_msgs/msg/key_value.hpp>
307 #include <diagnostic_msgs/msg/diagnostic_array.hpp>
308 #include <diagnostic_msgs/msg/diagnostic_status.hpp>
309 #include <diagnostic_msgs/srv/self_test.hpp>
310 #include <diagnostic_msgs/srv/add_diagnostics.hpp>
311 
312 //test_msgs
313 #include <test_msgs/msg/empty.hpp>
314 #include <test_msgs/msg/arrays.hpp>
315 #include <test_msgs/msg/nested.hpp>
316 #include <test_msgs/msg/strings.hpp>
317 #include <test_msgs/msg/builtins.hpp>
318 #include <test_msgs/msg/defaults.hpp>
319 #include <test_msgs/msg/constants.hpp>
320 #include <test_msgs/msg/w_strings.hpp>
321 #include <test_msgs/msg/basic_types.hpp>
322 #include <test_msgs/msg/multi_nested.hpp>
323 #include <test_msgs/msg/bounded_sequences.hpp>
324 #include <test_msgs/msg/unbounded_sequences.hpp>
325 #include <test_msgs/srv/empty.hpp>
326 #include <test_msgs/srv/arrays.hpp>
327 #include <test_msgs/srv/basic_types.hpp>
328 #include <test_msgs/action/fibonacci.hpp>
329 #include <test_msgs/action/nested_message.hpp>
330 
331 //action_msgs
332 #include <action_msgs/msg/goal_info.hpp>
333 #include <action_msgs/msg/goal_status.hpp>
334 #include <action_msgs/msg/goal_status_array.hpp>
335 #include <action_msgs/srv/cancel_goal.hpp>
336 
337 //actionlib_msgs
338 #include <actionlib_msgs/msg/goal_id.hpp>
339 #include <actionlib_msgs/msg/goal_status.hpp>
340 #include <actionlib_msgs/msg/goal_status_array.hpp>
341 
342 //lifecycle_msgs
343 #include <lifecycle_msgs/msg/state.hpp>
344 #include <lifecycle_msgs/msg/transition.hpp>
345 #include <lifecycle_msgs/msg/transition_event.hpp>
346 #include <lifecycle_msgs/msg/transition_description.hpp>
347 #include <lifecycle_msgs/srv/get_state.hpp>
348 #include <lifecycle_msgs/srv/change_state.hpp>
349 #include <lifecycle_msgs/srv/get_available_states.hpp>
350 #include <lifecycle_msgs/srv/get_available_transitions.hpp>
351 
352 //rosgraph_msgs
353 #include <rosgraph_msgs/msg/clock.hpp>
354 
355 //pendulum_msgs
356 #include <pendulum_msgs/msg/joint_state.hpp>
357 #include <pendulum_msgs/msg/joint_command.hpp>
358 #include <pendulum_msgs/msg/rttest_results.hpp>
359 
360 //composition_interfaces
361 #include <composition_interfaces/srv/load_node.hpp>
362 #include <composition_interfaces/srv/list_nodes.hpp>
363 #include <composition_interfaces/srv/unload_node.hpp>
364 
365 //unique_identifier_msgs
366 #include <unique_identifier_msgs/msg/uuid.hpp>
367 
368 //tf2_msgs
369 #include <tf2_msgs/msg/tf2_error.hpp>
370 #include <tf2_msgs/msg/tf_message.hpp>
371 #include <tf2_msgs/srv/frame_graph.hpp>
372 #include <tf2_msgs/action/lookup_transform.hpp>
373 
374 //tf2_sensor_msgs
375 
376 //tf2_geometry_msgs
377 
378 #endif
View Code

 

3.ROS2测试用例与MAROS提取脚本

        依赖于OpenCV、ROS2和Spdlog,封装为类MATEST:

             (1)AirRobot:发布结点,终端一执行 ./mattest airRobot。

             (2)LandRobot:订阅结点,终端一执行 ./mattest landRobot。

             (3)createWebotsHPP:提取Webots的所有HPP头文件(去掉注释也可提取所有H头文件)。

             (4)createROSHPP:提取ROS2相关包的所有HPP头文件(按相应格式追加包即可提取对应包的所有HPP头文件)。

             (5)globPaths:获取所有文件或目录或文件目录。

             (6)serialPath:获取指定基名和扩展名的尚不存在的路径。

  1 #ifndef __MATEST_h__
  2 #define __MATEST_h__
  3 
  4 #include <cscv/macxx.h>
  5 
  6 #ifndef tsns
  7 #define tsns chrono::time_point_cast<chrono::nanoseconds>(chrono::system_clock::now()).time_since_epoch().count()
  8 #define tsus chrono::time_point_cast<chrono::microseconds>(chrono::system_clock::now()).time_since_epoch().count()
  9 #define tsms chrono::time_point_cast<chrono::milliseconds>(chrono::system_clock::now()).time_since_epoch().count()
 10 #define tsse chrono::time_point_cast<chrono::seconds>(chrono::system_clock::now()).time_since_epoch().count()
 11 #define tsmi chrono::time_point_cast<chrono::minutes>(chrono::system_clock::now()).time_since_epoch().count()
 12 #define tsho chrono::time_point_cast<chrono::hours>(chrono::system_clock::now()).time_since_epoch().count()
 13 #endif
 14 
 15 class MATEST
 16 {
 17 public:
 18     static void AirRobot(int argc = 0, char** argv = 0)
 19     {
 20         //0.InitROS
 21         rclcpp::init(argc, argv);
 22 
 23         //1.PreROS
 24         int64 nPubFrame = 0;
 25         rclcpp::Node::SharedPtr nodAirRobot = rclcpp::Node::make_shared("airRobot", "acv");
 26         rclcpp::Publisher<ssrmsg::Image>::SharedPtr pubRawFrame = nodAirRobot->create_publisher<ssrmsg::Image>("rawFrame", 2);
 27         rclcpp::TimerBase::SharedPtr TimerTimestamp = nodAirRobot->create_wall_timer(200ms, [&]()->void
 28             {
 29                 //1.PrepareData
 30                 int64 ts = tsns;
 31                 ssrmsg::Image::UniquePtr ima = make_unique<ssrmsg::Image>();
 32                 ima->header.frame_id = std::to_string(++nPubFrame);
 33                 ima->header.stamp.sec = ts / 1000000000;
 34                 ima->header.stamp.nanosec = ts % 1000000000;
 35                 ima->width = 640;
 36                 ima->height = 480;
 37                 ima->step = 3 * ima->width;
 38                 ima->is_bigendian = 0;
 39                 ima->encoding = CV_8UC3;
 40                 ima->data.assign(ima->step * ima->height, 128);
 41                 cv::putText(Mat_<Vec3b>(ima->height, ima->width, (Vec3b*)ima->data.data()), ima->header.frame_id, Point(300, 220), FONT_HERSHEY_PLAIN, 4, Scalar(255, 0, 0), 4);
 42 
 43                 //2.PublishData
 44                 pubRawFrame->publish(std::move(ima));
 45 
 46                 //3.PrintDetails
 47                 spdlog::info("nPubFrame: {}", nPubFrame);
 48                 spdlog::info("\tNode::get_name: {}", nodAirRobot->get_name());
 49                 spdlog::info("\tNode::get_namespace: {}", nodAirRobot->get_namespace());
 50                 spdlog::info("\tNode::get_sub_namespace: {}", nodAirRobot->get_sub_namespace());
 51                 spdlog::info("\tNode::get_effective_namespace: {}", nodAirRobot->get_effective_namespace());
 52                 spdlog::info("\tNode::get_fully_qualified_name: {}", nodAirRobot->get_fully_qualified_name());
 53             });
 54 
 55         //2.SpinROS
 56         rclcpp::spin(nodAirRobot);
 57 
 58         //3.StopROS
 59         rclcpp::shutdown();
 60     }
 61 
 62     static void LandRobot(int argc = 0, char** argv = 0)
 63     {
 64         //0.InitROS
 65         rclcpp::init(argc, argv);
 66 
 67         //1.PreROS
 68         int64 nSubRawFrame = 0;
 69         rclcpp::Node::SharedPtr nodLandRobot = rclcpp::Node::make_shared("landRobot", "acv");
 70         rclcpp::Subscription<ssrmsg::Image>::SharedPtr subRawFrame = nodLandRobot->create_subscription<ssrmsg::Image>("rawFrame", 2, [&](ssrmsg::Image::UniquePtr frame)
 71             {
 72                 cv::imshow("RawFrame", Mat_<Vec3b>(frame->height, frame->width, (Vec3b*)frame->data.data()));
 73                 cv::waitKey(10);
 74                 spdlog::info("nSubRawFrame: {}", ++nSubRawFrame);
 75                 spdlog::info("\tNode::get_name: {}", nodLandRobot->get_name());
 76                 spdlog::info("\tNode::get_namespace: {}", nodLandRobot->get_namespace());
 77                 spdlog::info("\tNode::get_sub_namespace: {}", nodLandRobot->get_sub_namespace());
 78                 spdlog::info("\tNode::get_effective_namespace: {}", nodLandRobot->get_effective_namespace());
 79                 spdlog::info("\tNode::get_fully_qualified_name: {}", nodLandRobot->get_fully_qualified_name());
 80             });
 81 
 82         //2.SpinROS
 83         rclcpp::spin(nodLandRobot);
 84 
 85         //3.StopROS
 86         rclcpp::shutdown();
 87     }
 88 
 89 public:
 90     static void createWebotHPP(string webotsHomePath = "/usr/local/webots")
 91     {
 92         string hDir = webotsHomePath + "/include/controller/c/webots";
 93         string hppDir = webotsHomePath + "/include/controller/cpp/webots";
 94         vector<string> webotsHs = globPaths(hDir, "*.h", 0, true);
 95         vector<string> webotsHpps = globPaths(hppDir, "*.hpp", 0, true);
 96         FILE* file = fopen(serialPath(webotsHomePath, "abc", "hpp", -1).c_str(), "w");
 97         //for (size_t k = 0; k < webotsHs.size(); ++k) fprintf(file, "#include <webots%s>\n", webotsHs[k].substr(hDir.size()).c_str()); //C
 98         for (size_t k = 0; k < webotsHpps.size(); ++k) fprintf(file, "#include <webots%s>\n", webotsHpps[k].substr(hppDir.size()).c_str());//CPP
 99         fclose(file);
100     }
101 
102     static void createROSHPP(string rosHomePath = "/opt/ros/foxy")
103     {
104         //0.
105         auto writeROSHPP = [](string modDir, int choice/*1=cur 2=msg 4=srv 8=action*/, FILE* file)->void
106         {
107             string modName = modDir.substr(modDir.find_last_of('/') + 1);
108             string msgDir = modDir + "/msg";
109             string srvDir = modDir + "/srv";
110             string actionDir = modDir + "/action";
111             vector<string> selfHeaders = cv::utils::fs::exists(modDir) && choice & 1 ? globPaths(modDir, "*.hpp", 0, false) : vector<string>();
112             vector<string> msgHeaders = cv::utils::fs::exists(msgDir) && choice & 2 ? globPaths(msgDir, "*.hpp", 0, false) : vector<string>();
113             vector<string> srvHeaders = cv::utils::fs::exists(srvDir) && choice & 4 ? globPaths(srvDir, "*.hpp", 0, false) : vector<string>();
114             vector<string> actionHeaders = cv::utils::fs::exists(actionDir) && choice & 8 ? globPaths(actionDir, "*.hpp", 0, false) : vector<string>();
115             vector<string> allHeaders = { "\n//" + modName + "\n" };
116             for (size_t k = 0; k < selfHeaders.size(); ++k)
117                 if (selfHeaders[k].find("__") == string::npos && selfHeaders[k].find("impl") == string::npos)
118                     allHeaders.push_back("#include <" + modName + selfHeaders[k].substr(selfHeaders[k].find_last_of('/')) + ">\n");
119             for (size_t k = 0; k < msgHeaders.size(); ++k)
120                 if (msgHeaders[k].find("__") == string::npos && msgHeaders[k].find("impl") == string::npos)
121                     allHeaders.push_back("#include <" + modName + "/msg" + msgHeaders[k].substr(msgHeaders[k].find_last_of('/')) + ">\n");
122             for (size_t k = 0; k < srvHeaders.size(); ++k)
123                 if (srvHeaders[k].find("__") == string::npos && srvHeaders[k].find("impl") == string::npos)
124                     allHeaders.push_back("#include <" + modName + "/srv" + srvHeaders[k].substr(srvHeaders[k].find_last_of('/')) + ">\n");
125             for (size_t k = 0; k < actionHeaders.size(); ++k)
126                 if (actionHeaders[k].find("__") == string::npos && actionHeaders[k].find("impl") == string::npos)
127                     allHeaders.push_back("#include <" + modName + "/action" + actionHeaders[k].substr(actionHeaders[k].find_last_of('/')) + ">\n");
128             if (file != nullptr) for (size_t k = 0; k < allHeaders.size(); ++k) fprintf(file, allHeaders[k].c_str());
129             //return allHeaders;
130         };
131         FILE* file = fopen(serialPath(rosHomePath, "abc", "hpp", -1).c_str(), "w");
132         rosHomePath += "/include";
133 
134         //1:Cores
135         writeROSHPP(rosHomePath + "/ament_index_cpp", 1, file); //depend on env AMENT_PREFIX_PATH
136         writeROSHPP(rosHomePath + "/rclcpp", 1, file);
137         writeROSHPP(rosHomePath + "/rclcpp_action", 1, file);
138 
139         //2:Standards
140         writeROSHPP(rosHomePath + "/std_msgs", 14, file);
141         writeROSHPP(rosHomePath + "/std_srvs", 14, file);
142         writeROSHPP(rosHomePath + "/builtin_interfaces", 14, file);
143         writeROSHPP(rosHomePath + "/sensor_msgs", 15, file);
144         writeROSHPP(rosHomePath + "/geometry_msgs", 14, file);
145         writeROSHPP(rosHomePath + "/trajectory_msgs", 14, file);
146         writeROSHPP(rosHomePath + "/move_base_msgs", 14, file);
147         writeROSHPP(rosHomePath + "/stereo_msgs", 14, file);
148         writeROSHPP(rosHomePath + "/shape_msgs", 14, file);
149         writeROSHPP(rosHomePath + "/map_msgs", 14, file);
150         writeROSHPP(rosHomePath + "/nav_msgs", 14, file);
151         writeROSHPP(rosHomePath + "/visualization_msgs", 14, file);
152 
153         //3.Introspections
154         writeROSHPP(rosHomePath + "/diagnostic_msgs", 14, file);
155         writeROSHPP(rosHomePath + "/test_msgs", 14, file);
156         writeROSHPP(rosHomePath + "/action_msgs", 14, file);
157         writeROSHPP(rosHomePath + "/actionlib_msgs", 14, file);
158         writeROSHPP(rosHomePath + "/lifecycle_msgs", 14, file);
159         writeROSHPP(rosHomePath + "/rosgraph_msgs", 14, file);
160         writeROSHPP(rosHomePath + "/pendulum_msgs", 14, file);
161         writeROSHPP(rosHomePath + "/composition_interfaces", 14, file);
162         writeROSHPP(rosHomePath + "/unique_identifier_msgs", 14, file);
163 
164         //4:SalientFields: TF2+URDF
165         writeROSHPP(rosHomePath + "/tf2_msgs", 14, file);
166         writeROSHPP(rosHomePath + "/tf2_sensor_msgs", 14, file);
167         writeROSHPP(rosHomePath + "/tf2_geometry_msgs", 14, file);
168 
169         //
170         fclose(file);
171     }
172 
173 public:
174     static vector<string> globPaths(string dir, string pattern = "*", int type = 0/*0=file 1=dir 2=all*/, bool recursive = false)
175     {
176         //0.FormatInput
177         if (utils::fs::exists(dir) == false) return vector<string>();
178 
179         //1.RecurPaths
180         vector<string> srcPaths;
181         utils::fs::glob(dir, pattern, srcPaths, recursive, true);
182         for (size_t k = 0, pos = 0; k < srcPaths.size(); ++k)
183             for (size_t ind = 0; ; ++ind)
184             {
185                 ind = srcPaths[k].find('\\', ind);
186                 if (ind != string::npos) srcPaths[k].replace(ind, 1, "/");
187                 else break;
188             }
189 
190         //2.ClassifyPaths
191         vector<string> dirPaths, filePaths;
192         for (size_t k = 0; k < srcPaths.size(); ++k) utils::fs::isDirectory(srcPaths[k]) ? dirPaths.push_back(srcPaths[k]) : filePaths.push_back(srcPaths[k]);
193 
194         //3.SortPaths
195         if (dirPaths.size() > 1) stable_sort(dirPaths.begin(), dirPaths.end(), less<string>());
196         if (dirPaths.size() > 1) stable_sort(dirPaths.begin(), dirPaths.end(), [](string str1, string str2)->bool {return str1.length() < str2.length(); });
197         if (filePaths.size() > 1) stable_sort(filePaths.begin(), filePaths.end(), less<string>());
198         if (filePaths.size() > 1) stable_sort(filePaths.begin(), filePaths.end(), [](string str1, string str2)->bool {return str1.length() < str2.length(); });
199 
200         //4.CollectPaths
201         if (type == 0) return filePaths;
202         if (type == 1) return dirPaths;
203         if (type == 2) for (size_t k = 0; k < dirPaths.size(); ++k) filePaths.push_back(dirPaths[k]);
204         return filePaths;
205     }
206  
207     static string serialPath(string dir, string basename, string extname = ""/*empty for directory*/, int64 firstId = -1/*negtive for maximum*/)
208     {
209         if (firstId >= 0)
210         {
211             string fullPath;
212             do
213             {
214                 fullPath = fmt::format("{}/{}{}{}", dir, basename, firstId, (extname.empty() ? extname : "." + extname));
215                 if (utils::fs::exists(fullPath) == false) break;
216             } while (++firstId);
217             return fullPath;
218         }
219         else
220         {
221             vector<string> paths = globPaths(dir, basename + "*", extname.empty() ? 1 : 0, false);
222             if (paths.empty()) return fmt::format("{}/{}{}{}", dir, basename, 0, (extname.empty() ? extname : "." + extname));
223             if (extname.empty())
224             {
225                 int64 ind = paths[paths.size() - 1].find(basename) + basename.length();
226                 int64 id = atoll(paths[paths.size() - 1].substr(ind).c_str()) + 1;
227                 return fmt::format("{}/{}{}", dir, basename, id);
228             }
229             else
230             {
231                 int64 ind1 = paths[paths.size() - 1].find(basename) + basename.length();
232                 int64 ind2 = paths[paths.size() - 1].find_last_of(".");
233                 int64 id = atoll(paths[paths.size() - 1].substr(ind1, ind2 - ind1).c_str()) + 1;
234                 return fmt::format("{}/{}{}.{}", dir, basename, id, extname);
235             }
236         }
237     }
238 };
239 
240 #ifdef MATESTTest
241 int main(int argc, char** argv)
242 {
243     if (argc < 2) { spdlog::critical("appName nodeName(airRobot/landRobot)"); return -1; }
244 
245     if (strcmp(argv[1], "airRobot") == 0) MATEST::AirRobot(argc, argv);
246     else if (strcmp(argv[1], "landRobot") == 0) MATEST::LandRobot(argc, argv);
247 
248     return 0;
249 }
250 int main1(int argc, char** argv)
251 {
252     if (argc < 2) { spdlog::critical("appName nodeName(airRobot/landRobot)"); return -1; }
253 
254     if (strcmp(argv[1], "airRobot") == 0) MATEST::AirRobot(argc, argv);
255     else if (strcmp(argv[1], "landRobot") == 0) MATEST::LandRobot(argc, argv);
256 
257     return 0;
258 }
259 int main2(int argc, char** argv)
260 {
261     if (argc < 3) spdlog::critical("Usage: appName whichLib(ros or webots) homePath(/usr/local/webots or /opt/ros/foxy)");
262     else spdlog::info("Save the result to {}/abcx.xxx", argv[2]);
263     if (argc >= 3 && strcmp(argv[1], "ros") == 0)  MATEST::createROSHPP(argv[2]);
264     if (argc >= 3 && strcmp(argv[1], "webots") == 0)  MATEST::createWebotHPP(argv[2]);
265 
266     return 0;
267 }
268 #endif
269 
270 #endif
View Code

 

 

Asio、