Showing
8 changed files
with
2271 additions
and
0 deletions
code/modify/CMakeLists.txt
0 → 100644
1 | +############################################################################ | ||
2 | +# | ||
3 | +# Copyright (c) 2017 - 2019 PX4 Development Team. All rights reserved. | ||
4 | +# | ||
5 | +# Redistribution and use in source and binary forms, with or without | ||
6 | +# modification, are permitted provided that the following conditions | ||
7 | +# are met: | ||
8 | +# | ||
9 | +# 1. Redistributions of source code must retain the above copyright | ||
10 | +# notice, this list of conditions and the following disclaimer. | ||
11 | +# 2. Redistributions in binary form must reproduce the above copyright | ||
12 | +# notice, this list of conditions and the following disclaimer in | ||
13 | +# the documentation and/or other materials provided with the | ||
14 | +# distribution. | ||
15 | +# 3. Neither the name PX4 nor the names of its contributors may be | ||
16 | +# used to endorse or promote products derived from this software | ||
17 | +# without specific prior written permission. | ||
18 | +# | ||
19 | +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
20 | +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
21 | +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
22 | +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
23 | +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
24 | +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
25 | +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS | ||
26 | +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | ||
27 | +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
28 | +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
29 | +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
30 | +# POSSIBILITY OF SUCH DAMAGE. | ||
31 | +# | ||
32 | +############################################################################ | ||
33 | + | ||
34 | +#============================================================================= | ||
35 | +# CMAKE CODING STANDARD FOR PX4 | ||
36 | +# | ||
37 | +# Structure | ||
38 | +# --------------------------------------------------------------------------- | ||
39 | +# | ||
40 | +# * Common functions should be included in px_base.cmake. | ||
41 | +# | ||
42 | +# * OS/ board specific fucntions should be include in | ||
43 | +# px_impl_${PX4_PLATFORM}.cmake or px4_impl_${PX4_PLATFORM}_${PX4_BOARD}.cmake. | ||
44 | +# | ||
45 | +# Formatting | ||
46 | +# --------------------------------------------------------------------------- | ||
47 | +# | ||
48 | +# * Use hard indents to match the px4 source code. | ||
49 | +# | ||
50 | +# * All function and script arguments are upper case. | ||
51 | +# | ||
52 | +# * All local variables are lower case. | ||
53 | +# | ||
54 | +# * All cmake functions are lowercase. | ||
55 | +# | ||
56 | +# * For else, endif, endfunction, etc, never put the name of the statement | ||
57 | +# | ||
58 | +# Functions/Macros | ||
59 | +# --------------------------------------------------------------------------- | ||
60 | +# | ||
61 | +# * Use px4_parse_function_args to parse functions and check for required | ||
62 | +# arguments. Unless there is only one argument in the function and it is clear. | ||
63 | +# | ||
64 | +# * Never use macros. They allow overwriting global variables and this | ||
65 | +# makes variable declarations hard to locate. | ||
66 | +# | ||
67 | +# * If a target from add_custom_* is set in a function, explicitly pass it | ||
68 | +# as an output argument so that the target name is clear to the user. | ||
69 | +# | ||
70 | +# * Avoid use of global variables in functions. Functions in a nested | ||
71 | +# scope may use global variables, but this makes it difficult to | ||
72 | +# reuse functions. | ||
73 | +# | ||
74 | +# Included CMake Files | ||
75 | +# --------------------------------------------------------------------------- | ||
76 | +# | ||
77 | +# * All variables in config files must have the prefix "config_". | ||
78 | +# | ||
79 | +# * Never set global variables in an included cmake file, | ||
80 | +# you may only define functions. This excludes config and Toolchain files. | ||
81 | +# This makes it clear to the user when variables are being set or targets | ||
82 | +# are being created. | ||
83 | +# | ||
84 | +# * Setting a global variable in a CMakeLists.txt file is ok, because | ||
85 | +# each CMakeLists.txt file has scope in the current directory and all | ||
86 | +# subdirectories, so it is not truly global. | ||
87 | +# | ||
88 | +# * All toolchain files should be included in the cmake | ||
89 | +# directory and named Toolchain-"name".cmake. | ||
90 | +# | ||
91 | +# Misc | ||
92 | +# --------------------------------------------------------------------------- | ||
93 | +# | ||
94 | +# * If referencing a string variable, don't put it in quotes. | ||
95 | +# Don't do "${PX4_PLATFORM}" STREQUAL "posix", | ||
96 | +# instead type ${PX4_PLATFORM} STREQUAL "posix". This will throw an | ||
97 | +# error when ${PX4_PLATFORM} is not defined instead of silently | ||
98 | +# evaluating to false. | ||
99 | +# | ||
100 | +#============================================================================= | ||
101 | + | ||
102 | +cmake_minimum_required(VERSION 3.2 FATAL_ERROR) | ||
103 | + | ||
104 | +set(PX4_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}") | ||
105 | +set(PX4_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}") | ||
106 | + | ||
107 | +list(APPEND CMAKE_MODULE_PATH ${PX4_SOURCE_DIR}/cmake) | ||
108 | +include(px4_parse_function_args) | ||
109 | + | ||
110 | +#============================================================================= | ||
111 | +# git | ||
112 | +# | ||
113 | +include(px4_git) | ||
114 | + | ||
115 | +execute_process( | ||
116 | + COMMAND git describe --exclude ext/* --always --tags | ||
117 | + OUTPUT_VARIABLE PX4_GIT_TAG | ||
118 | + OUTPUT_STRIP_TRAILING_WHITESPACE | ||
119 | + WORKING_DIRECTORY ${PX4_SOURCE_DIR} | ||
120 | + ) | ||
121 | +message(STATUS "PX4 version: ${PX4_GIT_TAG}") | ||
122 | + | ||
123 | +define_property(GLOBAL PROPERTY PX4_MODULE_LIBRARIES | ||
124 | + BRIEF_DOCS "PX4 module libs" | ||
125 | + FULL_DOCS "List of all PX4 module libraries" | ||
126 | + ) | ||
127 | + | ||
128 | +define_property(GLOBAL PROPERTY PX4_MODULE_PATHS | ||
129 | + BRIEF_DOCS "PX4 module paths" | ||
130 | + FULL_DOCS "List of paths to all PX4 modules" | ||
131 | + ) | ||
132 | + | ||
133 | +#============================================================================= | ||
134 | +# configuration | ||
135 | +# | ||
136 | + | ||
137 | +set(CONFIG "px4_sitl_default" CACHE STRING "desired configuration") | ||
138 | + | ||
139 | +include(px4_add_module) | ||
140 | +set(config_module_list) | ||
141 | + | ||
142 | +include(px4_config) | ||
143 | +include(px4_add_board) | ||
144 | +include(${PX4_CONFIG_FILE}) | ||
145 | +message(STATUS "PX4 config: ${PX4_CONFIG}") | ||
146 | +message(STATUS "PX4 platform: ${PX4_PLATFORM}") | ||
147 | + | ||
148 | +if(${PX4_PLATFORM} STREQUAL "posix") | ||
149 | + if(ENABLE_LOCKSTEP_SCHEDULER) | ||
150 | + add_definitions(-DENABLE_LOCKSTEP_SCHEDULER) | ||
151 | + message(STATUS "PX4 lockstep: enabled") | ||
152 | + else() | ||
153 | + message(STATUS "PX4 lockstep: disabled") | ||
154 | + endif() | ||
155 | +endif() | ||
156 | + | ||
157 | +# external modules | ||
158 | +set(EXTERNAL_MODULES_LOCATION "" CACHE STRING "External modules source location") | ||
159 | + | ||
160 | +if(NOT EXTERNAL_MODULES_LOCATION STREQUAL "") | ||
161 | + get_filename_component(EXTERNAL_MODULES_LOCATION "${EXTERNAL_MODULES_LOCATION}" ABSOLUTE) | ||
162 | +endif() | ||
163 | + | ||
164 | +set_property(GLOBAL PROPERTY PX4_MODULE_CONFIG_FILES) | ||
165 | + | ||
166 | +include(platforms/${PX4_PLATFORM}/cmake/px4_impl_os.cmake) | ||
167 | +list(APPEND CMAKE_MODULE_PATH ${PX4_SOURCE_DIR}/platforms/${PX4_PLATFORM}/cmake) | ||
168 | + | ||
169 | +if(EXISTS "${PX4_SOURCE_DIR}/platforms/${PX4_PLATFORM}/cmake/init.cmake") | ||
170 | + include(init) | ||
171 | +endif() | ||
172 | + | ||
173 | +# CMake build type (Debug Release RelWithDebInfo MinSizeRel Coverage) | ||
174 | +if(NOT CMAKE_BUILD_TYPE) | ||
175 | + if(${PX4_PLATFORM} STREQUAL "nuttx") | ||
176 | + set(PX4_BUILD_TYPE "MinSizeRel") | ||
177 | + else() | ||
178 | + set(PX4_BUILD_TYPE "RelWithDebInfo") | ||
179 | + endif() | ||
180 | + | ||
181 | + set(CMAKE_BUILD_TYPE ${PX4_BUILD_TYPE} CACHE STRING "Build type" FORCE) | ||
182 | +endif() | ||
183 | + | ||
184 | +if((CMAKE_BUILD_TYPE STREQUAL "Debug") OR (CMAKE_BUILD_TYPE STREQUAL "Coverage")) | ||
185 | + set(MAX_CUSTOM_OPT_LEVEL -O0) | ||
186 | +elseif(CMAKE_BUILD_TYPE MATCHES "Sanitizer") | ||
187 | + set(MAX_CUSTOM_OPT_LEVEL -O1) | ||
188 | +elseif(CMAKE_BUILD_TYPE MATCHES "Release") | ||
189 | + set(MAX_CUSTOM_OPT_LEVEL -O3) | ||
190 | +else() | ||
191 | + if(px4_constrained_flash_build) | ||
192 | + set(MAX_CUSTOM_OPT_LEVEL -Os) | ||
193 | + else() | ||
194 | + set(MAX_CUSTOM_OPT_LEVEL -O2) | ||
195 | + endif() | ||
196 | +endif() | ||
197 | + | ||
198 | +set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug;Release;RelWithDebInfo;MinSizeRel;Coverage;AddressSanitizer;UndefinedBehaviorSanitizer") | ||
199 | +message(STATUS "cmake build type: ${CMAKE_BUILD_TYPE}") | ||
200 | + | ||
201 | +#============================================================================= | ||
202 | +# project definition | ||
203 | +# | ||
204 | +project(px4 CXX C ASM) | ||
205 | + | ||
206 | +set(package-contact "px4users@googlegroups.com") | ||
207 | + | ||
208 | +set(CMAKE_CXX_STANDARD 14) | ||
209 | +set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
210 | +set(CMAKE_C_STANDARD 11) | ||
211 | +set(CMAKE_C_STANDARD_REQUIRED ON) | ||
212 | +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) | ||
213 | + | ||
214 | +# For the catkin build process, unset build of dynamically-linked binaries | ||
215 | +# and do not change CMAKE_RUNTIME_OUTPUT_DIRECTORY | ||
216 | +if (NOT CATKIN_DEVEL_PREFIX) | ||
217 | + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PX4_BINARY_DIR}) | ||
218 | + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${PX4_BINARY_DIR}) | ||
219 | + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${PX4_BINARY_DIR}) | ||
220 | +else() | ||
221 | + SET(BUILD_SHARED_LIBS OFF) | ||
222 | +endif() | ||
223 | + | ||
224 | +#============================================================================= | ||
225 | + | ||
226 | +# gold linker - use if available (posix only for now) | ||
227 | +if(${PX4_PLATFORM} STREQUAL "posix") | ||
228 | + include(CMakeDependentOption) | ||
229 | + CMAKE_DEPENDENT_OPTION(USE_LD_GOLD | ||
230 | + "Use GNU gold linker" ON | ||
231 | + "NOT WIN32;NOT APPLE" OFF | ||
232 | + ) | ||
233 | + | ||
234 | + if(USE_LD_GOLD) | ||
235 | + execute_process(COMMAND ${CMAKE_C_COMPILER} -fuse-ld=gold -Wl,--version ERROR_QUIET OUTPUT_VARIABLE LD_VERSION) | ||
236 | + if("${LD_VERSION}" MATCHES "GNU gold") | ||
237 | + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lcrypto -fuse-ld=gold") | ||
238 | + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -lcrypto -fuse-ld=gold") | ||
239 | + else() | ||
240 | + set(USE_LD_GOLD OFF) | ||
241 | + endif() | ||
242 | + endif() | ||
243 | +endif() | ||
244 | + | ||
245 | +#============================================================================= | ||
246 | + | ||
247 | +# Setup install paths | ||
248 | +if(${PX4_PLATFORM} STREQUAL "posix") | ||
249 | + # This makes it possible to dynamically load code which depends on symbols | ||
250 | + # inside the px4 executable. | ||
251 | + set(CMAKE_POSITION_INDEPENDENT_CODE ON) | ||
252 | + set(CMAKE_ENABLE_EXPORTS ON) | ||
253 | + | ||
254 | + include(coverage) | ||
255 | + include(sanitizers) | ||
256 | + | ||
257 | + # Define GNU standard installation directories | ||
258 | + include(GNUInstallDirs) | ||
259 | + | ||
260 | + if (NOT CMAKE_INSTALL_PREFIX) | ||
261 | + set(CMAKE_INSTALL_PREFIX "/usr" CACHE PATH "Install path prefix" FORCE) | ||
262 | + endif() | ||
263 | +endif() | ||
264 | + | ||
265 | +include(ccache) | ||
266 | + | ||
267 | +#============================================================================= | ||
268 | +# find programs and packages | ||
269 | +# | ||
270 | + | ||
271 | +# see if catkin was invoked to build this | ||
272 | +if (CATKIN_DEVEL_PREFIX) | ||
273 | + message(STATUS "catkin ENABLED") | ||
274 | + find_package(catkin REQUIRED) | ||
275 | + if (catkin_FOUND) | ||
276 | + catkin_package() | ||
277 | + else() | ||
278 | + message(FATAL_ERROR "catkin not found") | ||
279 | + endif() | ||
280 | +endif() | ||
281 | + | ||
282 | +# Python | ||
283 | +# If using catkin, Python 2 is found since it points | ||
284 | +# to the Python libs installed with the ROS distro | ||
285 | +if (NOT CATKIN_DEVEL_PREFIX) | ||
286 | + find_package(PythonInterp 3) | ||
287 | + # We have a custom error message to tell users how to install python3. | ||
288 | + if (NOT PYTHONINTERP_FOUND) | ||
289 | + message(FATAL_ERROR "Python 3 not found. Please install Python 3:\n" | ||
290 | + " Ubuntu: sudo apt install python3 python3-dev python3-pip\n" | ||
291 | + " macOS: brew install python") | ||
292 | + endif() | ||
293 | +else() | ||
294 | + find_package(PythonInterp REQUIRED) | ||
295 | +endif() | ||
296 | + | ||
297 | +option(PYTHON_COVERAGE "Python code coverage" OFF) | ||
298 | +if(PYTHON_COVERAGE) | ||
299 | + message(STATUS "python coverage enabled") | ||
300 | + set(PYTHON_EXECUTABLE coverage run -p) | ||
301 | +endif() | ||
302 | + | ||
303 | +#============================================================================= | ||
304 | +# get chip and chip manufacturer | ||
305 | +# | ||
306 | +px4_os_determine_build_chip() | ||
307 | +if(NOT PX4_CHIP_MANUFACTURER) | ||
308 | + message(FATAL_ERROR "px4_os_determine_build_chip() needs to set PX4_CHIP_MANUFACTURER") | ||
309 | +endif() | ||
310 | +if(NOT PX4_CHIP) | ||
311 | + message(FATAL_ERROR "px4_os_determine_build_chip() needs to set PX4_CHIP") | ||
312 | +endif() | ||
313 | + | ||
314 | +#============================================================================= | ||
315 | +# build flags | ||
316 | +# | ||
317 | +include(px4_add_common_flags) | ||
318 | +px4_add_common_flags() | ||
319 | +px4_os_add_flags() | ||
320 | + | ||
321 | +#============================================================================= | ||
322 | +# board cmake init (optional) | ||
323 | +# | ||
324 | +if(EXISTS ${PX4_BOARD_DIR}/cmake/init.cmake) | ||
325 | + include(${PX4_BOARD_DIR}/cmake/init.cmake) | ||
326 | +endif() | ||
327 | + | ||
328 | +#============================================================================= | ||
329 | +# message, and airframe generation | ||
330 | +# | ||
331 | +include(px4_metadata) | ||
332 | + | ||
333 | +add_subdirectory(msg EXCLUDE_FROM_ALL) | ||
334 | + | ||
335 | +px4_generate_airframes_xml(BOARD ${PX4_BOARD}) | ||
336 | + | ||
337 | +#============================================================================= | ||
338 | +# external projects | ||
339 | +# | ||
340 | +set(ep_base ${PX4_BINARY_DIR}/external) | ||
341 | +set_property(DIRECTORY PROPERTY EP_BASE ${ep_base}) | ||
342 | + | ||
343 | +# add external project install folders to build | ||
344 | +# add the directories so cmake won't warn | ||
345 | +execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${ep_base}) | ||
346 | +execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${ep_base}/Install) | ||
347 | +execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${ep_base}/Install/lib) | ||
348 | +link_directories(${ep_base}/Install/lib) | ||
349 | +execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${ep_base}/Install/include) | ||
350 | +include_directories(${ep_base}/Install/include) | ||
351 | + | ||
352 | +#============================================================================= | ||
353 | +# external modules | ||
354 | +# | ||
355 | +set(external_module_paths) | ||
356 | +if (NOT EXTERNAL_MODULES_LOCATION STREQUAL "") | ||
357 | + message(STATUS "External modules: ${EXTERNAL_MODULES_LOCATION}") | ||
358 | + add_subdirectory("${EXTERNAL_MODULES_LOCATION}/src" external_modules) | ||
359 | + | ||
360 | + foreach(external_module ${config_module_list_external}) | ||
361 | + add_subdirectory(${EXTERNAL_MODULES_LOCATION}/src/${external_module} external_modules/${external_module}) | ||
362 | + list(APPEND external_module_paths ${EXTERNAL_MODULES_LOCATION}/src/${external_module}) | ||
363 | + endforeach() | ||
364 | +endif() | ||
365 | + | ||
366 | +#============================================================================= | ||
367 | +# Testing - Automatic unit and integration testing with CTest | ||
368 | +# | ||
369 | + | ||
370 | +# optionally enable cmake testing (supported only on posix) | ||
371 | +option(CMAKE_TESTING "Configure test targets" OFF) | ||
372 | +if(${PX4_CONFIG} STREQUAL "px4_sitl_test") | ||
373 | + set(CMAKE_TESTING ON) | ||
374 | +endif() | ||
375 | +if(CMAKE_TESTING) | ||
376 | + include(CTest) # sets BUILD_TESTING variable | ||
377 | +endif() | ||
378 | + | ||
379 | +# enable test filtering to run only specific tests with the ctest -R regex functionality | ||
380 | +set(TESTFILTER "" CACHE STRING "Filter string for ctest to selectively only run specific tests (ctest -R)") | ||
381 | + | ||
382 | +# if testing is enabled download and configure gtest | ||
383 | +list(APPEND CMAKE_MODULE_PATH ${PX4_SOURCE_DIR}/cmake/gtest/) | ||
384 | +include(px4_add_gtest) | ||
385 | +if(BUILD_TESTING) | ||
386 | + include(gtest) | ||
387 | + | ||
388 | + add_custom_target(test_results | ||
389 | + COMMAND GTEST_COLOR=1 ${CMAKE_CTEST_COMMAND} --output-on-failure -T Test -R ${TESTFILTER} USES_TERMINAL | ||
390 | + DEPENDS | ||
391 | + px4 | ||
392 | + examples__dyn_hello | ||
393 | + test_mixer_multirotor | ||
394 | + USES_TERMINAL | ||
395 | + COMMENT "Running tests" | ||
396 | + WORKING_DIRECTORY ${PX4_BINARY_DIR}) | ||
397 | + set_target_properties(test_results PROPERTIES EXCLUDE_FROM_ALL TRUE) | ||
398 | +endif() | ||
399 | + | ||
400 | + | ||
401 | +#============================================================================= | ||
402 | +# subdirectories | ||
403 | +# | ||
404 | +add_library(parameters_interface INTERFACE) | ||
405 | + | ||
406 | +include(px4_add_library) | ||
407 | +add_subdirectory(src/lib EXCLUDE_FROM_ALL) | ||
408 | + | ||
409 | +add_subdirectory(platforms/${PX4_PLATFORM}/src/px4) | ||
410 | +add_subdirectory(platforms EXCLUDE_FROM_ALL) | ||
411 | + | ||
412 | +if(EXISTS "${PX4_BOARD_DIR}/CMakeLists.txt") | ||
413 | + add_subdirectory(${PX4_BOARD_DIR}) | ||
414 | +endif() | ||
415 | + | ||
416 | +foreach(module ${config_module_list}) | ||
417 | + add_subdirectory(src/${module}) | ||
418 | +endforeach() | ||
419 | + | ||
420 | +# must be the last module before firmware | ||
421 | +add_subdirectory(src/lib/parameters EXCLUDE_FROM_ALL) | ||
422 | +target_link_libraries(parameters_interface INTERFACE parameters) | ||
423 | + | ||
424 | +# firmware added last to generate the builtin for included modules | ||
425 | +add_subdirectory(platforms/${PX4_PLATFORM}) | ||
426 | + | ||
427 | +#============================================================================= | ||
428 | +# uORB graph generation: add a custom target 'uorb_graph' | ||
429 | +# | ||
430 | +set(uorb_graph_config ${PX4_BOARD}) | ||
431 | + | ||
432 | +set(graph_module_list "") | ||
433 | +foreach(module ${config_module_list}) | ||
434 | + set(graph_module_list "${graph_module_list}" "--src-path" "src/${module}") | ||
435 | +endforeach() | ||
436 | + | ||
437 | +add_custom_command(OUTPUT ${uorb_graph_config} | ||
438 | + COMMAND ${PYTHON_EXECUTABLE} ${PX4_SOURCE_DIR}/Tools/uorb_graph/create.py | ||
439 | + ${graph_module_list} | ||
440 | + --exclude-path src/examples | ||
441 | + --file ${PX4_SOURCE_DIR}/Tools/uorb_graph/graph_${uorb_graph_config} | ||
442 | + WORKING_DIRECTORY ${PX4_SOURCE_DIR} | ||
443 | + COMMENT "Generating uORB graph" | ||
444 | +) | ||
445 | +add_custom_target(uorb_graph DEPENDS ${uorb_graph_config}) | ||
446 | + | ||
447 | + | ||
448 | +include(doxygen) | ||
449 | +include(metadata) | ||
450 | +include(package) | ||
451 | + | ||
452 | +# print size | ||
453 | +add_custom_target(size | ||
454 | + COMMAND size $<TARGET_FILE:px4> | ||
455 | + DEPENDS px4 | ||
456 | + WORKING_DIRECTORY ${PX4_BINARY_DIR} | ||
457 | + USES_TERMINAL | ||
458 | + ) | ||
459 | + | ||
460 | +# install python requirements using configured python | ||
461 | +add_custom_target(install_python_requirements | ||
462 | + COMMAND ${PYTHON_EXECUTABLE} -m pip install --requirement ${PX4_SOURCE_DIR}/Tools/setup/requirements.txt | ||
463 | + DEPENDS ${PX4_SOURCE_DIR}/Tools/setup/requirements.txt | ||
464 | + USES_TERMINAL | ||
465 | +) |
code/modify/Tools/ed25519sign
0 → 100755
No preview for this file type
code/modify/Tools/ed25519sign.cpp
0 → 100644
1 | +#include <openssl/pem.h> | ||
2 | +#include <openssl/evp.h> | ||
3 | +#include <openssl/bio.h> | ||
4 | +#include <openssl/err.h> | ||
5 | +#include <iostream> | ||
6 | +#include <iomanip> | ||
7 | +#include <fstream> | ||
8 | +#include <cstring> | ||
9 | +#include <algorithm> | ||
10 | + | ||
11 | + | ||
12 | +using namespace std; | ||
13 | + | ||
14 | + | ||
15 | +int generate_key() | ||
16 | +{ | ||
17 | + ofstream fout; | ||
18 | + BIO* bio; | ||
19 | + | ||
20 | + // generate key pair | ||
21 | + EVP_PKEY* key = NULL; | ||
22 | + EVP_PKEY_CTX *pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_ED25519, NULL); | ||
23 | + if(EVP_PKEY_keygen_init(pctx) != 1) | ||
24 | + { | ||
25 | + cout << "Error: EVP_PKEY_keygen_init" << endl; | ||
26 | + cout << ERR_error_string(ERR_get_error(),NULL) << endl; | ||
27 | + return 0; | ||
28 | + } | ||
29 | + if(EVP_PKEY_keygen(pctx, &key) != 1) | ||
30 | + { | ||
31 | + cout << "Error: EVP_PKEY_keygen" << endl; | ||
32 | + cout << ERR_error_string(ERR_get_error(),NULL) << endl; | ||
33 | + return 0; | ||
34 | + } | ||
35 | + EVP_PKEY_CTX_free(pctx); | ||
36 | + | ||
37 | + // save private key | ||
38 | + bio = BIO_new( BIO_s_mem() ); | ||
39 | + if(PEM_write_bio_PrivateKey(bio, key, NULL, NULL, 0, NULL, NULL) != 1) | ||
40 | + { | ||
41 | + cout << "Error: PEM_write_bio_PrivateKey" << endl; | ||
42 | + cout << ERR_error_string(ERR_get_error(),NULL) << endl; | ||
43 | + return 0; | ||
44 | + } | ||
45 | + unsigned char private_key[120] = { 0 }; | ||
46 | + BIO_read(bio, private_key, 120); | ||
47 | + BIO_free(bio); | ||
48 | + cout << private_key << endl; | ||
49 | + fout.open("private_key"); | ||
50 | + fout << private_key; | ||
51 | + fout.close(); | ||
52 | + | ||
53 | + // save public key | ||
54 | + bio = BIO_new( BIO_s_mem() ); | ||
55 | + if(PEM_write_bio_PUBKEY(bio, key) != 1) | ||
56 | + { | ||
57 | + cout << "Error: PEM_write_bio_PUBKEY" << endl; | ||
58 | + cout << ERR_error_string(ERR_get_error(),NULL) << endl; | ||
59 | + return 0; | ||
60 | + } | ||
61 | + EVP_PKEY_free(key); | ||
62 | + unsigned char public_key[120] = { 0 }; | ||
63 | + BIO_read(bio, public_key, 120); | ||
64 | + BIO_free(bio); | ||
65 | + cout << public_key << endl; | ||
66 | + fout.open("public_key"); | ||
67 | + fout << public_key; | ||
68 | + fout.close(); | ||
69 | + | ||
70 | + return 1; | ||
71 | +} | ||
72 | + | ||
73 | + | ||
74 | + | ||
75 | +int sign(char* signee_file, char* key_file) | ||
76 | +{ | ||
77 | + ifstream fin; | ||
78 | + ofstream fout; | ||
79 | + BIO* bio; | ||
80 | + EVP_PKEY* pkey = NULL; | ||
81 | + int signee_size = 0, key_size = 0; | ||
82 | + | ||
83 | + // open signee_file | ||
84 | + fin.open(signee_file); | ||
85 | + if (fin.fail()) { | ||
86 | + cout << "Error: Can't open signee file." << endl; | ||
87 | + return 0; | ||
88 | + } | ||
89 | + fin.seekg(0, ios::end); | ||
90 | + signee_size = fin.tellg(); | ||
91 | + fin.seekg(0, ios::beg); | ||
92 | + unsigned char* signee = new unsigned char[signee_size]; | ||
93 | + fin.read((char*)signee, signee_size); | ||
94 | + fin.close(); | ||
95 | + | ||
96 | + // open private key | ||
97 | + fin.open(key_file); | ||
98 | + if (fin.fail()) { | ||
99 | + cout << "Error: Can't open key file." << endl; | ||
100 | + return 0; | ||
101 | + } | ||
102 | + fin.seekg(0, ios::end); | ||
103 | + key_size = fin.tellg(); | ||
104 | + fin.seekg(0, ios::beg); | ||
105 | + unsigned char* key = new unsigned char[key_size]; | ||
106 | + fin.read((char*)key, key_size); | ||
107 | + fin.close(); | ||
108 | + cout << key << endl; | ||
109 | + bio = BIO_new( BIO_s_mem() ); | ||
110 | + BIO_write(bio, key, key_size); | ||
111 | + if(PEM_read_bio_PrivateKey(bio, &pkey, NULL, NULL) == NULL) | ||
112 | + { | ||
113 | + cout << "Error: PEM_read_bio_PrivateKey" << endl; | ||
114 | + cout << ERR_error_string(ERR_get_error(),NULL) << endl; | ||
115 | + return 0; | ||
116 | + } | ||
117 | + BIO_free(bio); | ||
118 | + | ||
119 | + // File Signing, Make Signature | ||
120 | + unsigned char sig[65] = { 0 }; | ||
121 | + size_t sig_size = 64; | ||
122 | + EVP_MD_CTX* ctx = EVP_MD_CTX_new(); | ||
123 | + if(EVP_DigestSignInit(ctx, NULL, NULL, NULL, pkey) != 1) | ||
124 | + { | ||
125 | + cout << "Error: EVP_DigestSignInit" << endl; | ||
126 | + cout << ERR_error_string(ERR_get_error(),NULL) << endl; | ||
127 | + return 0; | ||
128 | + } | ||
129 | + if(EVP_DigestSign(ctx, sig, &sig_size, signee, signee_size) != 1) | ||
130 | + { | ||
131 | + cout << "Error: EVP_DigestSign" << endl; | ||
132 | + cout << ERR_error_string(ERR_get_error(),NULL) << endl; | ||
133 | + return 0; | ||
134 | + } | ||
135 | + EVP_MD_CTX_free(ctx); | ||
136 | + EVP_PKEY_free(pkey); | ||
137 | + | ||
138 | + fout.open("./signature"); | ||
139 | + cout << hex << setfill('0'); | ||
140 | + fout << hex << setfill('0'); | ||
141 | + for(int i = 0; i < sig_size; i++) | ||
142 | + { | ||
143 | + cout << setw(2) << (int)sig[i]; | ||
144 | + fout << setw(2) << (int)sig[i]; | ||
145 | + } | ||
146 | + cout << endl; | ||
147 | + fout.close(); | ||
148 | + | ||
149 | + return 1; | ||
150 | +} | ||
151 | + | ||
152 | + | ||
153 | +/* | ||
154 | +int verify(char* signee_file, char* sig_file, char* key_file) | ||
155 | +{ | ||
156 | + ifstream fin; | ||
157 | + BIO* bio; | ||
158 | + EVP_PKEY* pkey = NULL; | ||
159 | + int signee_size = 0, key_size = 0, sig_size = 0; | ||
160 | + | ||
161 | + // open signee_file | ||
162 | + fin.open(signee_file); | ||
163 | + fin.seekg(0, ios::end); | ||
164 | + signee_size = fin.tellg(); | ||
165 | + fin.seekg(0, ios::beg); | ||
166 | + unsigned char* signee = new unsigned char[signee_size]; | ||
167 | + fin.read((char*)signee, signee_size); | ||
168 | + fin.close(); | ||
169 | + | ||
170 | + // open public key | ||
171 | + fin.open(key_file); | ||
172 | + fin.seekg(0, ios::end); | ||
173 | + key_size = fin.tellg(); | ||
174 | + fin.seekg(0, ios::beg); | ||
175 | + unsigned char* key = new unsigned char[key_size]; | ||
176 | + fin.read((char*)key, key_size); | ||
177 | + fin.close(); | ||
178 | + cout << key << endl; | ||
179 | + bio = BIO_new( BIO_s_mem() ); | ||
180 | + BIO_write(bio, key, key_size); | ||
181 | + if(PEM_read_bio_PUBKEY(bio, &pkey, NULL, NULL) == NULL) | ||
182 | + { | ||
183 | + cout << "Error: " << ERR_error_string(ERR_get_error(),NULL) << endl; | ||
184 | + return 0; | ||
185 | + } | ||
186 | + BIO_free(bio); | ||
187 | + | ||
188 | + fin.open(sig_file); | ||
189 | + fin.seekg(0, ios::end); | ||
190 | + sig_size = fin.tellg(); | ||
191 | + fin.seekg(0, ios::beg); | ||
192 | + unsigned char* sig_char = new unsigned char[sig_size]; | ||
193 | + fin.read((char*)sig_char, sig_size); | ||
194 | + fin.close(); | ||
195 | + unsigned char sig[65] = { 0 }; | ||
196 | + char temp[3] = { 0 }; | ||
197 | + for(int i = 0; i < sig_size; i+=2) | ||
198 | + { | ||
199 | + temp[0] = sig_char[i]; | ||
200 | + temp[1] = sig_char[i+1]; | ||
201 | + sig[i/2] = (unsigned char) strtol(temp, NULL, 16); | ||
202 | + } | ||
203 | + sig_size /= 2; | ||
204 | + | ||
205 | + EVP_MD_CTX* ctx = EVP_MD_CTX_new(); | ||
206 | + if(EVP_DigestVerifyInit(ctx, NULL, NULL, NULL, pkey) != 1) | ||
207 | + { | ||
208 | + cout << "Error: " << ERR_error_string(ERR_get_error(),NULL) << endl; | ||
209 | + return 0; | ||
210 | + } | ||
211 | + if(EVP_DigestVerify(ctx, sig, sig_size, signee, signee_size) != 1) | ||
212 | + { | ||
213 | + cout << "Error: " << ERR_error_string(ERR_get_error(),NULL) << endl; | ||
214 | + return 0; | ||
215 | + } | ||
216 | + EVP_PKEY_free(pkey); | ||
217 | + | ||
218 | + cout << "Success" << endl; | ||
219 | + return 1; | ||
220 | +} | ||
221 | +*/ | ||
222 | + | ||
223 | + | ||
224 | +bool cmdOptionExists(char** begin, char** end, const string& option) | ||
225 | +{ | ||
226 | + return find(begin, end, option) != end; | ||
227 | +} | ||
228 | + | ||
229 | + | ||
230 | + | ||
231 | +char* getCmdOption(char** begin, char** end, const string& option) | ||
232 | +{ | ||
233 | + char** itr = find(begin, end, option); | ||
234 | + if (itr != end && ++itr != end) | ||
235 | + return *itr; | ||
236 | + return 0; | ||
237 | +} | ||
238 | + | ||
239 | + | ||
240 | + | ||
241 | +int main(int argc, char* argv[]) | ||
242 | +{ | ||
243 | + if (cmdOptionExists(argv, argv+argc, "-h")\ | ||
244 | + || cmdOptionExists(argv, argv+argc, "--help")) | ||
245 | + { | ||
246 | + cout << "Usage" << endl; | ||
247 | + cout << "Generate key: " << argv[0] << " --genkey" << endl; | ||
248 | + cout << "Signing file: " << argv[0] << " -f signee_path -k key_path" << endl; | ||
249 | + return 0; | ||
250 | + } | ||
251 | + | ||
252 | + if (cmdOptionExists(argv, argv+argc, "--genkey")) | ||
253 | + { | ||
254 | + generate_key(); | ||
255 | + return 0; | ||
256 | + } | ||
257 | + | ||
258 | + if (cmdOptionExists(argv, argv+argc, "-f")\ | ||
259 | + && cmdOptionExists(argv, argv+argc, "-k")) | ||
260 | + { | ||
261 | + char* signee_path = getCmdOption(argv, argv+argc, "-f"); | ||
262 | + char* key_path = getCmdOption(argv, argv+argc, "-k"); | ||
263 | + if (sign(signee_path, key_path) != 1) | ||
264 | + cout << "Error occured" << endl; | ||
265 | + return 0; | ||
266 | + } | ||
267 | + else | ||
268 | + { | ||
269 | + cout << "Usage" << endl; | ||
270 | + cout << "Generate key: " << argv[0] << " --genkey" << endl; | ||
271 | + cout << "Signing file: " << argv[0] << " -f signee_path -k key_path" << endl; | ||
272 | + } | ||
273 | +// generate_key(); | ||
274 | +// sign(argv[1], argv[2]); | ||
275 | +// verify(argv[1], argv[2], argv[3]); | ||
276 | + return 0; | ||
277 | +} |
1 | +/**************************************************************************** | ||
2 | + * | ||
3 | + * Copyright (c) 2015 Mark Charlebois. All rights reserved. | ||
4 | + * Copyright (c) 2016-2019 PX4 Development Team. All rights reserved. | ||
5 | + * | ||
6 | + * Redistribution and use in source and binary forms, with or without | ||
7 | + * modification, are permitted provided that the following conditions | ||
8 | + * are met: | ||
9 | + * | ||
10 | + * 1. Redistributions of source code must retain the above copyright | ||
11 | + * notice, this list of conditions and the following disclaimer. | ||
12 | + * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | + * notice, this list of conditions and the following disclaimer in | ||
14 | + * the documentation and/or other materials provided with the | ||
15 | + * distribution. | ||
16 | + * 3. Neither the name PX4 nor the names of its contributors may be | ||
17 | + * used to endorse or promote products derived from this software | ||
18 | + * without specific prior written permission. | ||
19 | + * | ||
20 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
21 | + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
22 | + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
23 | + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
24 | + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
25 | + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
26 | + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS | ||
27 | + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | ||
28 | + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
29 | + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
30 | + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
31 | + * POSSIBILITY OF SUCH DAMAGE. | ||
32 | + * | ||
33 | + ****************************************************************************/ | ||
34 | + | ||
35 | +/** | ||
36 | + * @file simulator.cpp | ||
37 | + * | ||
38 | + * This module interfaces via MAVLink to a software in the loop simulator (SITL) | ||
39 | + * such as jMAVSim or Gazebo. | ||
40 | + */ | ||
41 | + | ||
42 | +#include <px4_platform_common/log.h> | ||
43 | +#include <px4_platform_common/tasks.h> | ||
44 | +#include <px4_platform_common/time.h> | ||
45 | +#include <systemlib/err.h> | ||
46 | +#include <drivers/drv_board_led.h> | ||
47 | +#include <openssl/evp.h> | ||
48 | +#include <openssl/pem.h> | ||
49 | +#include <openssl/bio.h> | ||
50 | +#include <openssl/err.h> | ||
51 | +#include <fstream> | ||
52 | +#include <cstring> | ||
53 | + | ||
54 | +#include "simulator.h" | ||
55 | + | ||
56 | +static px4_task_t g_sim_task = -1; | ||
57 | + | ||
58 | +Simulator *Simulator::_instance = nullptr; | ||
59 | + | ||
60 | +void Simulator::parameters_update(bool force) | ||
61 | +{ | ||
62 | + // check for parameter updates | ||
63 | + if (_parameter_update_sub.updated() || force) { | ||
64 | + // clear update | ||
65 | + parameter_update_s pupdate; | ||
66 | + _parameter_update_sub.copy(&pupdate); | ||
67 | + | ||
68 | + // update parameters from storage | ||
69 | + updateParams(); | ||
70 | + } | ||
71 | +} | ||
72 | + | ||
73 | +int Simulator::verify() | ||
74 | +{ | ||
75 | +/* | ||
76 | + char path[256]; | ||
77 | + if(getcwd(path, 256) == NULL) | ||
78 | + PX4_INFO("Test path: %s", strerror(errno)); | ||
79 | + else | ||
80 | + PX4_INFO("Test path: %s", path); | ||
81 | +*/ | ||
82 | + | ||
83 | + std::ifstream fin; | ||
84 | + BIO* bio; | ||
85 | + EVP_PKEY* pkey = NULL; | ||
86 | + | ||
87 | + const char* file_path = "../../bin/px4"; | ||
88 | +// const char* file_path = "../../../../Tools/test.txt"; | ||
89 | + const char* sig_path = "../../../../Tools/signature"; | ||
90 | + const char* key_path = "../../../../Tools/public_key"; | ||
91 | + | ||
92 | + int file_size = 0, sig_size = 0, key_size = 0; | ||
93 | + | ||
94 | + // open exe file | ||
95 | + fin.open(file_path); | ||
96 | + if (fin.fail()) { | ||
97 | + PX4_WARN("Error: Can't open exe file during signature verifying."); | ||
98 | + return 0; | ||
99 | + } | ||
100 | + fin.seekg(0, std::ios::end); | ||
101 | + file_size = fin.tellg(); | ||
102 | + fin.seekg(0, std::ios::beg); | ||
103 | + unsigned char* file = new unsigned char[file_size]; | ||
104 | + fin.read((char*)file, file_size); | ||
105 | + fin.close(); | ||
106 | + | ||
107 | + // open signature file | ||
108 | + fin.open(sig_path); | ||
109 | + if (fin.fail()) { | ||
110 | + PX4_WARN("Error: Can't open signature file during signature verifying."); | ||
111 | + return 0; | ||
112 | + } | ||
113 | + fin.seekg(0, std::ios::end); | ||
114 | + sig_size = fin.tellg(); | ||
115 | + fin.seekg(0, std::ios::beg); | ||
116 | + unsigned char* sig_char = new unsigned char[sig_size]; | ||
117 | + fin.read((char*)sig_char, sig_size); | ||
118 | + fin.close(); | ||
119 | + unsigned char sig[65] = { 0 }; | ||
120 | + char temp[3] = { 0 }; | ||
121 | + for (int i = 0; i < sig_size; i+=2) | ||
122 | + { | ||
123 | + temp[0] = sig_char[i]; | ||
124 | + temp[1] = sig_char[i+1]; | ||
125 | + sig[i/2] = (unsigned char)strtol(temp, NULL, 16); | ||
126 | + } | ||
127 | + delete[] sig_char; | ||
128 | + sig_size /= 2; | ||
129 | + | ||
130 | + // open public key file | ||
131 | + fin.open(key_path); | ||
132 | + if (fin.fail()) { | ||
133 | + PX4_WARN("Error: Can't open public key file during signature verifying."); | ||
134 | + return 0; | ||
135 | + } | ||
136 | + fin.seekg(0, std::ios::end); | ||
137 | + key_size = fin.tellg(); | ||
138 | + fin.seekg(0, std::ios::beg); | ||
139 | + unsigned char* key = new unsigned char[key_size]; | ||
140 | + fin.read((char*)key, key_size); | ||
141 | + fin.close(); | ||
142 | + | ||
143 | + // make key file to pkey | ||
144 | + bio = BIO_new( BIO_s_mem() ); | ||
145 | + BIO_write(bio, key, key_size); | ||
146 | + if (PEM_read_bio_PUBKEY(bio, &pkey, NULL, NULL) == NULL) { | ||
147 | + PX4_WARN("Error: PEM_read_bio_PUBKEY"); //ERR_error_string(ERR_get_error(), NULL) | ||
148 | + return 0; | ||
149 | + } | ||
150 | + delete[] key; | ||
151 | + BIO_free(bio); | ||
152 | + | ||
153 | + // verifying signature | ||
154 | + EVP_MD_CTX* ctx = EVP_MD_CTX_new(); | ||
155 | + if (EVP_DigestVerifyInit(ctx, NULL, NULL, NULL, pkey) != 1) { | ||
156 | + PX4_WARN("Error: EVP_DigestVerifyInit"); //ERR_error_string(ERR_get_error(), NULL) | ||
157 | + return 0; | ||
158 | + } | ||
159 | + if (EVP_DigestVerify(ctx, sig, sig_size, file, file_size) != 1) { | ||
160 | + return 0; | ||
161 | + } | ||
162 | + EVP_PKEY_free(pkey); | ||
163 | + EVP_MD_CTX_free(ctx); | ||
164 | + delete[] file; | ||
165 | + | ||
166 | + PX4_INFO("Success: Verifying Signature"); | ||
167 | + | ||
168 | + return 1; | ||
169 | +} | ||
170 | + | ||
171 | +int Simulator::start(int argc, char *argv[]) | ||
172 | +{ | ||
173 | + | ||
174 | + _instance = new Simulator(); | ||
175 | + | ||
176 | + if (_instance->verify() != 1) { | ||
177 | + PX4_ERR("Signature Verifying failed"); | ||
178 | + return 1; | ||
179 | + } | ||
180 | + | ||
181 | + if (_instance) { | ||
182 | + | ||
183 | + if (argc == 5 && strcmp(argv[3], "-u") == 0) { | ||
184 | + _instance->set_ip(InternetProtocol::UDP); | ||
185 | + _instance->set_port(atoi(argv[4])); | ||
186 | + } | ||
187 | + | ||
188 | + if (argc == 5 && strcmp(argv[3], "-c") == 0) { | ||
189 | + _instance->set_ip(InternetProtocol::TCP); | ||
190 | + _instance->set_port(atoi(argv[4])); | ||
191 | + } | ||
192 | + | ||
193 | + if (argc == 6 && strcmp(argv[3], "-t") == 0) { | ||
194 | + PX4_INFO("Simulator using TCP on remote host %s port %s", argv[4], argv[5]); | ||
195 | + PX4_WARN("Please ensure port %s is not blocked by a firewall.", argv[5]); | ||
196 | + _instance->set_ip(InternetProtocol::TCP); | ||
197 | + _instance->set_tcp_remote_ipaddr(argv[4]); | ||
198 | + _instance->set_port(atoi(argv[5])); | ||
199 | + } | ||
200 | + | ||
201 | + if (argc == 6 && strcmp(argv[3], "-h") == 0) { | ||
202 | + PX4_INFO("Simulator using TCP on remote host %s port %s", argv[4], argv[5]); | ||
203 | + PX4_WARN("Please ensure port %s is not blocked by a firewall.", argv[5]); | ||
204 | + _instance->set_ip(InternetProtocol::TCP); | ||
205 | + _instance->set_hostname(argv[4]); | ||
206 | + _instance->set_port(atoi(argv[5])); | ||
207 | + } | ||
208 | + | ||
209 | + _instance->run(); | ||
210 | + | ||
211 | + return 0; | ||
212 | + | ||
213 | + } else { | ||
214 | + PX4_WARN("Simulator creation failed"); | ||
215 | + return 1; | ||
216 | + } | ||
217 | +} | ||
218 | + | ||
219 | +static void usage() | ||
220 | +{ | ||
221 | + PX4_INFO("Usage: simulator {start -[spt] [-u udp_port / -c tcp_port] |stop|status}"); | ||
222 | + PX4_INFO("Start simulator: simulator start"); | ||
223 | + PX4_INFO("Connect using UDP: simulator start -u udp_port"); | ||
224 | + PX4_INFO("Connect using TCP: simulator start -c tcp_port"); | ||
225 | + PX4_INFO("Connect to a remote server using TCP: simulator start -t ip_addr tcp_port"); | ||
226 | + PX4_INFO("Connect to a remote server via hostname using TCP: simulator start -h hostname tcp_port"); | ||
227 | +} | ||
228 | + | ||
229 | +__BEGIN_DECLS | ||
230 | +extern int simulator_main(int argc, char *argv[]); | ||
231 | +__END_DECLS | ||
232 | + | ||
233 | + | ||
234 | +int simulator_main(int argc, char *argv[]) | ||
235 | +{ | ||
236 | + if (argc > 1 && strcmp(argv[1], "start") == 0) { | ||
237 | + | ||
238 | + if (g_sim_task >= 0) { | ||
239 | + PX4_WARN("Simulator already started"); | ||
240 | + return 0; | ||
241 | + } | ||
242 | + | ||
243 | + g_sim_task = px4_task_spawn_cmd("simulator", | ||
244 | + SCHED_DEFAULT, | ||
245 | + SCHED_PRIORITY_MAX, | ||
246 | + 1500, | ||
247 | + Simulator::start, | ||
248 | + argv); | ||
249 | + | ||
250 | +#if defined(ENABLE_LOCKSTEP_SCHEDULER) | ||
251 | + | ||
252 | + // We want to prevent the rest of the startup script from running until time | ||
253 | + // is initialized by the HIL_SENSOR messages from the simulator. | ||
254 | + while (true) { | ||
255 | + if (Simulator::getInstance() && Simulator::getInstance()->has_initialized()) { | ||
256 | + break; | ||
257 | + } | ||
258 | + | ||
259 | + system_usleep(100); | ||
260 | + } | ||
261 | + | ||
262 | +#endif | ||
263 | + | ||
264 | + } else if (argc == 2 && strcmp(argv[1], "stop") == 0) { | ||
265 | + if (g_sim_task < 0) { | ||
266 | + PX4_WARN("Simulator not running"); | ||
267 | + return 1; | ||
268 | + | ||
269 | + } else { | ||
270 | + px4_task_delete(g_sim_task); | ||
271 | + g_sim_task = -1; | ||
272 | + } | ||
273 | + | ||
274 | + } else if (argc == 2 && strcmp(argv[1], "status") == 0) { | ||
275 | + if (g_sim_task < 0) { | ||
276 | + PX4_WARN("Simulator not running"); | ||
277 | + return 1; | ||
278 | + | ||
279 | + } else { | ||
280 | + PX4_INFO("running"); | ||
281 | + } | ||
282 | + | ||
283 | + } else { | ||
284 | + usage(); | ||
285 | + return 1; | ||
286 | + } | ||
287 | + | ||
288 | + return 0; | ||
289 | +} |
1 | +/**************************************************************************** | ||
2 | + * | ||
3 | + * Copyright (c) 2015 Mark Charlebois. All rights reserved. | ||
4 | + * Copyright (c) 2016-2019 PX4 Development Team. All rights reserved. | ||
5 | + * | ||
6 | + * Redistribution and use in source and binary forms, with or without | ||
7 | + * modification, are permitted provided that the following conditions | ||
8 | + * are met: | ||
9 | + * | ||
10 | + * 1. Redistributions of source code must retain the above copyright | ||
11 | + * notice, this list of conditions and the following disclaimer. | ||
12 | + * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | + * notice, this list of conditions and the following disclaimer in | ||
14 | + * the documentation and/or other materials provided with the | ||
15 | + * distribution. | ||
16 | + * 3. Neither the name PX4 nor the names of its contributors may be | ||
17 | + * used to endorse or promote products derived from this software | ||
18 | + * without specific prior written permission. | ||
19 | + * | ||
20 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
21 | + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
22 | + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
23 | + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
24 | + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
25 | + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
26 | + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS | ||
27 | + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | ||
28 | + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
29 | + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
30 | + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
31 | + * POSSIBILITY OF SUCH DAMAGE. | ||
32 | + * | ||
33 | + ****************************************************************************/ | ||
34 | + | ||
35 | + | ||
36 | +/** | ||
37 | + * @file simulator.h | ||
38 | + * | ||
39 | + * This module interfaces via MAVLink to a software in the loop simulator (SITL) | ||
40 | + * such as jMAVSim or Gazebo. | ||
41 | + */ | ||
42 | + | ||
43 | +#pragma once | ||
44 | + | ||
45 | +#include <drivers/drv_hrt.h> | ||
46 | +#include <drivers/drv_rc_input.h> | ||
47 | +#include <lib/drivers/accelerometer/PX4Accelerometer.hpp> | ||
48 | +#include <lib/drivers/barometer/PX4Barometer.hpp> | ||
49 | +#include <lib/drivers/gyroscope/PX4Gyroscope.hpp> | ||
50 | +#include <lib/drivers/magnetometer/PX4Magnetometer.hpp> | ||
51 | +#include <lib/ecl/geo/geo.h> | ||
52 | +#include <lib/perf/perf_counter.h> | ||
53 | +#include <px4_platform_common/atomic.h> | ||
54 | +#include <px4_platform_common/bitmask.h> | ||
55 | +#include <px4_platform_common/module_params.h> | ||
56 | +#include <px4_platform_common/posix.h> | ||
57 | +#include <uORB/Publication.hpp> | ||
58 | +#include <uORB/Subscription.hpp> | ||
59 | +#include <uORB/SubscriptionInterval.hpp> | ||
60 | +#include <uORB/topics/actuator_outputs.h> | ||
61 | +#include <uORB/topics/differential_pressure.h> | ||
62 | +#include <uORB/topics/distance_sensor.h> | ||
63 | +#include <uORB/topics/irlock_report.h> | ||
64 | +#include <uORB/topics/manual_control_setpoint.h> | ||
65 | +#include <uORB/topics/optical_flow.h> | ||
66 | +#include <uORB/topics/parameter_update.h> | ||
67 | +#include <uORB/topics/sensor_gps.h> | ||
68 | +#include <uORB/topics/vehicle_angular_velocity.h> | ||
69 | +#include <uORB/topics/vehicle_attitude.h> | ||
70 | +#include <uORB/topics/vehicle_global_position.h> | ||
71 | +#include <uORB/topics/vehicle_local_position.h> | ||
72 | +#include <uORB/topics/vehicle_odometry.h> | ||
73 | +#include <uORB/topics/vehicle_status.h> | ||
74 | +#include <uORB/topics/vehicle_command.h> | ||
75 | +#include <uORB/topics/vehicle_command_ack.h> | ||
76 | + | ||
77 | +#include <random> | ||
78 | + | ||
79 | +#include <v2.0/common/mavlink.h> | ||
80 | +#include <v2.0/mavlink_types.h> | ||
81 | + | ||
82 | +using namespace time_literals; | ||
83 | + | ||
84 | +//! Enumeration to use on the bitmask in HIL_SENSOR | ||
85 | +enum class SensorSource { | ||
86 | + ACCEL = 0b111, | ||
87 | + GYRO = 0b111000, | ||
88 | + MAG = 0b111000000, | ||
89 | + BARO = 0b1101000000000, | ||
90 | + DIFF_PRESS = 0b10000000000 | ||
91 | +}; | ||
92 | +ENABLE_BIT_OPERATORS(SensorSource) | ||
93 | + | ||
94 | +//! AND operation for the enumeration and unsigned types that returns the bitmask | ||
95 | +template<typename A, typename B> | ||
96 | +static inline SensorSource operator &(A lhs, B rhs) | ||
97 | +{ | ||
98 | + // make it type safe | ||
99 | + static_assert((std::is_same<A, uint32_t>::value || std::is_same<A, SensorSource>::value), | ||
100 | + "first argument is not uint32_t or SensorSource enum type"); | ||
101 | + static_assert((std::is_same<B, uint32_t>::value || std::is_same<B, SensorSource>::value), | ||
102 | + "second argument is not uint32_t or SensorSource enum type"); | ||
103 | + | ||
104 | + typedef typename std::underlying_type<SensorSource>::type underlying; | ||
105 | + | ||
106 | + return static_cast<SensorSource>( | ||
107 | + static_cast<underlying>(lhs) & | ||
108 | + static_cast<underlying>(rhs) | ||
109 | + ); | ||
110 | +} | ||
111 | + | ||
112 | +class Simulator : public ModuleParams | ||
113 | +{ | ||
114 | +public: | ||
115 | + static Simulator *getInstance() { return _instance; } | ||
116 | + | ||
117 | + enum class InternetProtocol { | ||
118 | + TCP, | ||
119 | + UDP | ||
120 | + }; | ||
121 | + | ||
122 | + static int start(int argc, char *argv[]); | ||
123 | + | ||
124 | + void set_ip(InternetProtocol ip) { _ip = ip; } | ||
125 | + void set_port(unsigned port) { _port = port; } | ||
126 | + void set_hostname(std::string hostname) { _hostname = hostname; } | ||
127 | + void set_tcp_remote_ipaddr(char *tcp_remote_ipaddr) { _tcp_remote_ipaddr = tcp_remote_ipaddr; } | ||
128 | + | ||
129 | +#if defined(ENABLE_LOCKSTEP_SCHEDULER) | ||
130 | + bool has_initialized() { return _has_initialized.load(); } | ||
131 | +#endif | ||
132 | + | ||
133 | +private: | ||
134 | + Simulator() : ModuleParams(nullptr) | ||
135 | + { | ||
136 | + } | ||
137 | + | ||
138 | + ~Simulator() | ||
139 | + { | ||
140 | + // free perf counters | ||
141 | + perf_free(_perf_sim_delay); | ||
142 | + perf_free(_perf_sim_interval); | ||
143 | + | ||
144 | + for (size_t i = 0; i < sizeof(_dist_pubs) / sizeof(_dist_pubs[0]); i++) { | ||
145 | + delete _dist_pubs[i]; | ||
146 | + } | ||
147 | + | ||
148 | + px4_lockstep_unregister_component(_lockstep_component); | ||
149 | + | ||
150 | + for (size_t i = 0; i < sizeof(_sensor_gps_pubs) / sizeof(_sensor_gps_pubs[0]); i++) { | ||
151 | + delete _sensor_gps_pubs[i]; | ||
152 | + } | ||
153 | + | ||
154 | + _instance = nullptr; | ||
155 | + } | ||
156 | + | ||
157 | + | ||
158 | + void check_failure_injections(); | ||
159 | + | ||
160 | + int publish_flow_topic(const mavlink_hil_optical_flow_t *flow); | ||
161 | + int publish_odometry_topic(const mavlink_message_t *odom_mavlink); | ||
162 | + int publish_distance_topic(const mavlink_distance_sensor_t *dist); | ||
163 | + | ||
164 | + static Simulator *_instance; | ||
165 | + | ||
166 | + // simulated sensor instances | ||
167 | + static constexpr uint8_t ACCEL_COUNT_MAX = 3; | ||
168 | + PX4Accelerometer _px4_accel[ACCEL_COUNT_MAX] { | ||
169 | + {1310988, ROTATION_NONE}, // 1310988: DRV_IMU_DEVTYPE_SIM, BUS: 1, ADDR: 1, TYPE: SIMULATION | ||
170 | + {1310996, ROTATION_NONE}, // 1310996: DRV_IMU_DEVTYPE_SIM, BUS: 2, ADDR: 1, TYPE: SIMULATION | ||
171 | + {1311004, ROTATION_NONE}, // 1311004: DRV_IMU_DEVTYPE_SIM, BUS: 3, ADDR: 1, TYPE: SIMULATION | ||
172 | + }; | ||
173 | + | ||
174 | + static constexpr uint8_t GYRO_COUNT_MAX = 3; | ||
175 | + PX4Gyroscope _px4_gyro[GYRO_COUNT_MAX] { | ||
176 | + {1310988, ROTATION_NONE}, // 1310988: DRV_IMU_DEVTYPE_SIM, BUS: 1, ADDR: 1, TYPE: SIMULATION | ||
177 | + {1310996, ROTATION_NONE}, // 1310996: DRV_IMU_DEVTYPE_SIM, BUS: 2, ADDR: 1, TYPE: SIMULATION | ||
178 | + {1311004, ROTATION_NONE}, // 1311004: DRV_IMU_DEVTYPE_SIM, BUS: 3, ADDR: 1, TYPE: SIMULATION | ||
179 | + }; | ||
180 | + | ||
181 | + PX4Magnetometer _px4_mag_0{197388, ROTATION_NONE}; // 197388: DRV_MAG_DEVTYPE_MAGSIM, BUS: 1, ADDR: 1, TYPE: SIMULATION | ||
182 | + PX4Magnetometer _px4_mag_1{197644, ROTATION_NONE}; // 197644: DRV_MAG_DEVTYPE_MAGSIM, BUS: 2, ADDR: 1, TYPE: SIMULATION | ||
183 | + | ||
184 | + PX4Barometer _px4_baro_0{6620172}; // 6620172: DRV_BARO_DEVTYPE_BAROSIM, BUS: 1, ADDR: 4, TYPE: SIMULATION | ||
185 | + PX4Barometer _px4_baro_1{6620428}; // 6620428: DRV_BARO_DEVTYPE_BAROSIM, BUS: 2, ADDR: 4, TYPE: SIMULATION | ||
186 | + | ||
187 | + float _sensors_temperature{0}; | ||
188 | + | ||
189 | + perf_counter_t _perf_sim_delay{perf_alloc(PC_ELAPSED, MODULE_NAME": network delay")}; | ||
190 | + perf_counter_t _perf_sim_interval{perf_alloc(PC_INTERVAL, MODULE_NAME": network interval")}; | ||
191 | + | ||
192 | + // uORB publisher handlers | ||
193 | + uORB::Publication<differential_pressure_s> _differential_pressure_pub{ORB_ID(differential_pressure)}; | ||
194 | + uORB::PublicationMulti<optical_flow_s> _flow_pub{ORB_ID(optical_flow)}; | ||
195 | + uORB::Publication<irlock_report_s> _irlock_report_pub{ORB_ID(irlock_report)}; | ||
196 | + uORB::Publication<vehicle_odometry_s> _visual_odometry_pub{ORB_ID(vehicle_visual_odometry)}; | ||
197 | + uORB::Publication<vehicle_odometry_s> _mocap_odometry_pub{ORB_ID(vehicle_mocap_odometry)}; | ||
198 | + | ||
199 | + uORB::Publication<vehicle_command_ack_s> _command_ack_pub{ORB_ID(vehicle_command_ack)}; | ||
200 | + | ||
201 | + uORB::PublicationMulti<distance_sensor_s> *_dist_pubs[ORB_MULTI_MAX_INSTANCES] {}; | ||
202 | + uint32_t _dist_sensor_ids[ORB_MULTI_MAX_INSTANCES] {}; | ||
203 | + | ||
204 | + uORB::SubscriptionInterval _parameter_update_sub{ORB_ID(parameter_update), 1_s}; | ||
205 | + | ||
206 | + unsigned int _port{14560}; | ||
207 | + | ||
208 | + InternetProtocol _ip{InternetProtocol::UDP}; | ||
209 | + | ||
210 | + std::string _hostname{""}; | ||
211 | + | ||
212 | + char *_tcp_remote_ipaddr{nullptr}; | ||
213 | + | ||
214 | + double _realtime_factor{1.0}; ///< How fast the simulation runs in comparison to real system time | ||
215 | + | ||
216 | + hrt_abstime _last_sim_timestamp{0}; | ||
217 | + hrt_abstime _last_sitl_timestamp{0}; | ||
218 | + | ||
219 | + int verify(); | ||
220 | + | ||
221 | + void run(); | ||
222 | + void handle_message(const mavlink_message_t *msg); | ||
223 | + void handle_message_distance_sensor(const mavlink_message_t *msg); | ||
224 | + void handle_message_hil_gps(const mavlink_message_t *msg); | ||
225 | + void handle_message_hil_sensor(const mavlink_message_t *msg); | ||
226 | + void handle_message_hil_state_quaternion(const mavlink_message_t *msg); | ||
227 | + void handle_message_landing_target(const mavlink_message_t *msg); | ||
228 | + void handle_message_odometry(const mavlink_message_t *msg); | ||
229 | + void handle_message_optical_flow(const mavlink_message_t *msg); | ||
230 | + void handle_message_rc_channels(const mavlink_message_t *msg); | ||
231 | + void handle_message_vision_position_estimate(const mavlink_message_t *msg); | ||
232 | + | ||
233 | + void parameters_update(bool force); | ||
234 | + void poll_for_MAVLink_messages(); | ||
235 | + void request_hil_state_quaternion(); | ||
236 | + void send(); | ||
237 | + void send_controls(); | ||
238 | + void send_heartbeat(); | ||
239 | + void send_mavlink_message(const mavlink_message_t &aMsg); | ||
240 | + void update_sensors(const hrt_abstime &time, const mavlink_hil_sensor_t &sensors); | ||
241 | + | ||
242 | + static void *sending_trampoline(void *); | ||
243 | + | ||
244 | + void actuator_controls_from_outputs(mavlink_hil_actuator_controls_t *msg); | ||
245 | + | ||
246 | + | ||
247 | + // uORB publisher handlers | ||
248 | + uORB::Publication<vehicle_angular_velocity_s> _vehicle_angular_velocity_ground_truth_pub{ORB_ID(vehicle_angular_velocity_groundtruth)}; | ||
249 | + uORB::Publication<vehicle_attitude_s> _attitude_ground_truth_pub{ORB_ID(vehicle_attitude_groundtruth)}; | ||
250 | + uORB::Publication<vehicle_global_position_s> _gpos_ground_truth_pub{ORB_ID(vehicle_global_position_groundtruth)}; | ||
251 | + uORB::Publication<vehicle_local_position_s> _lpos_ground_truth_pub{ORB_ID(vehicle_local_position_groundtruth)}; | ||
252 | + uORB::Publication<input_rc_s> _input_rc_pub{ORB_ID(input_rc)}; | ||
253 | + | ||
254 | + // HIL GPS | ||
255 | + static constexpr int MAX_GPS = 3; | ||
256 | + uORB::PublicationMulti<sensor_gps_s> *_sensor_gps_pubs[MAX_GPS] {}; | ||
257 | + uint8_t _gps_ids[MAX_GPS] {}; | ||
258 | + std::default_random_engine _gen{}; | ||
259 | + | ||
260 | + // uORB subscription handlers | ||
261 | + int _actuator_outputs_sub{-1}; | ||
262 | + actuator_outputs_s _actuator_outputs{}; | ||
263 | + | ||
264 | + uORB::Subscription _vehicle_status_sub{ORB_ID(vehicle_status)}; | ||
265 | + uORB::Subscription _vehicle_command_sub{ORB_ID(vehicle_command)}; | ||
266 | + | ||
267 | + // hil map_ref data | ||
268 | + map_projection_reference_s _global_local_proj_ref{}; | ||
269 | + float _global_local_alt0{NAN}; | ||
270 | + | ||
271 | + vehicle_status_s _vehicle_status{}; | ||
272 | + | ||
273 | + bool _accel_blocked[ACCEL_COUNT_MAX] {}; | ||
274 | + bool _accel_stuck[ACCEL_COUNT_MAX] {}; | ||
275 | + sensor_accel_fifo_s _last_accel_fifo{}; | ||
276 | + matrix::Vector3f _last_accel[GYRO_COUNT_MAX] {}; | ||
277 | + | ||
278 | + bool _gyro_blocked[GYRO_COUNT_MAX] {}; | ||
279 | + bool _gyro_stuck[GYRO_COUNT_MAX] {}; | ||
280 | + sensor_gyro_fifo_s _last_gyro_fifo{}; | ||
281 | + matrix::Vector3f _last_gyro[GYRO_COUNT_MAX] {}; | ||
282 | + | ||
283 | + bool _baro_blocked{false}; | ||
284 | + bool _baro_stuck{false}; | ||
285 | + | ||
286 | + bool _mag_blocked{false}; | ||
287 | + bool _mag_stuck{false}; | ||
288 | + | ||
289 | + bool _gps_blocked{false}; | ||
290 | + bool _airspeed_blocked{false}; | ||
291 | + | ||
292 | + float _last_magx{0.0f}; | ||
293 | + float _last_magy{0.0f}; | ||
294 | + float _last_magz{0.0f}; | ||
295 | + | ||
296 | +#if defined(ENABLE_LOCKSTEP_SCHEDULER) | ||
297 | + px4::atomic<bool> _has_initialized {false}; | ||
298 | +#endif | ||
299 | + | ||
300 | + int _lockstep_component{-1}; | ||
301 | + | ||
302 | + DEFINE_PARAMETERS( | ||
303 | + (ParamInt<px4::params::MAV_TYPE>) _param_mav_type, | ||
304 | + (ParamInt<px4::params::MAV_SYS_ID>) _param_mav_sys_id, | ||
305 | + (ParamInt<px4::params::MAV_COMP_ID>) _param_mav_comp_id | ||
306 | + ) | ||
307 | +}; |
code/original/CMakeLists.txt
0 → 100644
1 | +############################################################################ | ||
2 | +# | ||
3 | +# Copyright (c) 2017 - 2019 PX4 Development Team. All rights reserved. | ||
4 | +# | ||
5 | +# Redistribution and use in source and binary forms, with or without | ||
6 | +# modification, are permitted provided that the following conditions | ||
7 | +# are met: | ||
8 | +# | ||
9 | +# 1. Redistributions of source code must retain the above copyright | ||
10 | +# notice, this list of conditions and the following disclaimer. | ||
11 | +# 2. Redistributions in binary form must reproduce the above copyright | ||
12 | +# notice, this list of conditions and the following disclaimer in | ||
13 | +# the documentation and/or other materials provided with the | ||
14 | +# distribution. | ||
15 | +# 3. Neither the name PX4 nor the names of its contributors may be | ||
16 | +# used to endorse or promote products derived from this software | ||
17 | +# without specific prior written permission. | ||
18 | +# | ||
19 | +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
20 | +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
21 | +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
22 | +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
23 | +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
24 | +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
25 | +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS | ||
26 | +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | ||
27 | +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
28 | +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
29 | +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
30 | +# POSSIBILITY OF SUCH DAMAGE. | ||
31 | +# | ||
32 | +############################################################################ | ||
33 | + | ||
34 | +#============================================================================= | ||
35 | +# CMAKE CODING STANDARD FOR PX4 | ||
36 | +# | ||
37 | +# Structure | ||
38 | +# --------------------------------------------------------------------------- | ||
39 | +# | ||
40 | +# * Common functions should be included in px_base.cmake. | ||
41 | +# | ||
42 | +# * OS/ board specific fucntions should be include in | ||
43 | +# px_impl_${PX4_PLATFORM}.cmake or px4_impl_${PX4_PLATFORM}_${PX4_BOARD}.cmake. | ||
44 | +# | ||
45 | +# Formatting | ||
46 | +# --------------------------------------------------------------------------- | ||
47 | +# | ||
48 | +# * Use hard indents to match the px4 source code. | ||
49 | +# | ||
50 | +# * All function and script arguments are upper case. | ||
51 | +# | ||
52 | +# * All local variables are lower case. | ||
53 | +# | ||
54 | +# * All cmake functions are lowercase. | ||
55 | +# | ||
56 | +# * For else, endif, endfunction, etc, never put the name of the statement | ||
57 | +# | ||
58 | +# Functions/Macros | ||
59 | +# --------------------------------------------------------------------------- | ||
60 | +# | ||
61 | +# * Use px4_parse_function_args to parse functions and check for required | ||
62 | +# arguments. Unless there is only one argument in the function and it is clear. | ||
63 | +# | ||
64 | +# * Never use macros. They allow overwriting global variables and this | ||
65 | +# makes variable declarations hard to locate. | ||
66 | +# | ||
67 | +# * If a target from add_custom_* is set in a function, explicitly pass it | ||
68 | +# as an output argument so that the target name is clear to the user. | ||
69 | +# | ||
70 | +# * Avoid use of global variables in functions. Functions in a nested | ||
71 | +# scope may use global variables, but this makes it difficult to | ||
72 | +# reuse functions. | ||
73 | +# | ||
74 | +# Included CMake Files | ||
75 | +# --------------------------------------------------------------------------- | ||
76 | +# | ||
77 | +# * All variables in config files must have the prefix "config_". | ||
78 | +# | ||
79 | +# * Never set global variables in an included cmake file, | ||
80 | +# you may only define functions. This excludes config and Toolchain files. | ||
81 | +# This makes it clear to the user when variables are being set or targets | ||
82 | +# are being created. | ||
83 | +# | ||
84 | +# * Setting a global variable in a CMakeLists.txt file is ok, because | ||
85 | +# each CMakeLists.txt file has scope in the current directory and all | ||
86 | +# subdirectories, so it is not truly global. | ||
87 | +# | ||
88 | +# * All toolchain files should be included in the cmake | ||
89 | +# directory and named Toolchain-"name".cmake. | ||
90 | +# | ||
91 | +# Misc | ||
92 | +# --------------------------------------------------------------------------- | ||
93 | +# | ||
94 | +# * If referencing a string variable, don't put it in quotes. | ||
95 | +# Don't do "${PX4_PLATFORM}" STREQUAL "posix", | ||
96 | +# instead type ${PX4_PLATFORM} STREQUAL "posix". This will throw an | ||
97 | +# error when ${PX4_PLATFORM} is not defined instead of silently | ||
98 | +# evaluating to false. | ||
99 | +# | ||
100 | +#============================================================================= | ||
101 | + | ||
102 | +cmake_minimum_required(VERSION 3.2 FATAL_ERROR) | ||
103 | + | ||
104 | +set(PX4_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}") | ||
105 | +set(PX4_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}") | ||
106 | + | ||
107 | +list(APPEND CMAKE_MODULE_PATH ${PX4_SOURCE_DIR}/cmake) | ||
108 | +include(px4_parse_function_args) | ||
109 | + | ||
110 | +#============================================================================= | ||
111 | +# git | ||
112 | +# | ||
113 | +include(px4_git) | ||
114 | + | ||
115 | +execute_process( | ||
116 | + COMMAND git describe --always --tags | ||
117 | + OUTPUT_VARIABLE PX4_GIT_TAG | ||
118 | + OUTPUT_STRIP_TRAILING_WHITESPACE | ||
119 | + WORKING_DIRECTORY ${PX4_SOURCE_DIR} | ||
120 | + ) | ||
121 | +message(STATUS "PX4 version: ${PX4_GIT_TAG}") | ||
122 | + | ||
123 | +define_property(GLOBAL PROPERTY PX4_MODULE_LIBRARIES | ||
124 | + BRIEF_DOCS "PX4 module libs" | ||
125 | + FULL_DOCS "List of all PX4 module libraries" | ||
126 | + ) | ||
127 | + | ||
128 | +define_property(GLOBAL PROPERTY PX4_MODULE_PATHS | ||
129 | + BRIEF_DOCS "PX4 module paths" | ||
130 | + FULL_DOCS "List of paths to all PX4 modules" | ||
131 | + ) | ||
132 | + | ||
133 | +#============================================================================= | ||
134 | +# configuration | ||
135 | +# | ||
136 | + | ||
137 | +set(CONFIG "px4_sitl_default" CACHE STRING "desired configuration") | ||
138 | + | ||
139 | +include(px4_add_module) | ||
140 | +set(config_module_list) | ||
141 | + | ||
142 | +include(px4_config) | ||
143 | +include(px4_add_board) | ||
144 | +include(${PX4_CONFIG_FILE}) | ||
145 | +message(STATUS "PX4 config: ${PX4_CONFIG}") | ||
146 | +message(STATUS "PX4 platform: ${PX4_PLATFORM}") | ||
147 | + | ||
148 | +if(${PX4_PLATFORM} STREQUAL "posix") | ||
149 | + if(ENABLE_LOCKSTEP_SCHEDULER) | ||
150 | + add_definitions(-DENABLE_LOCKSTEP_SCHEDULER) | ||
151 | + message(STATUS "PX4 lockstep: enabled") | ||
152 | + else() | ||
153 | + message(STATUS "PX4 lockstep: disabled") | ||
154 | + endif() | ||
155 | +endif() | ||
156 | + | ||
157 | +# external modules | ||
158 | +set(EXTERNAL_MODULES_LOCATION "" CACHE STRING "External modules source location") | ||
159 | + | ||
160 | +if(NOT EXTERNAL_MODULES_LOCATION STREQUAL "") | ||
161 | + get_filename_component(EXTERNAL_MODULES_LOCATION "${EXTERNAL_MODULES_LOCATION}" ABSOLUTE) | ||
162 | +endif() | ||
163 | + | ||
164 | +set_property(GLOBAL PROPERTY PX4_MODULE_CONFIG_FILES) | ||
165 | + | ||
166 | +include(platforms/${PX4_PLATFORM}/cmake/px4_impl_os.cmake) | ||
167 | +list(APPEND CMAKE_MODULE_PATH ${PX4_SOURCE_DIR}/platforms/${PX4_PLATFORM}/cmake) | ||
168 | + | ||
169 | +if(EXISTS "${PX4_SOURCE_DIR}/platforms/${PX4_PLATFORM}/cmake/init.cmake") | ||
170 | + include(init) | ||
171 | +endif() | ||
172 | + | ||
173 | +# CMake build type (Debug Release RelWithDebInfo MinSizeRel Coverage) | ||
174 | +if(NOT CMAKE_BUILD_TYPE) | ||
175 | + if(${PX4_PLATFORM} STREQUAL "nuttx") | ||
176 | + set(PX4_BUILD_TYPE "MinSizeRel") | ||
177 | + else() | ||
178 | + set(PX4_BUILD_TYPE "RelWithDebInfo") | ||
179 | + endif() | ||
180 | + | ||
181 | + set(CMAKE_BUILD_TYPE ${PX4_BUILD_TYPE} CACHE STRING "Build type" FORCE) | ||
182 | +endif() | ||
183 | + | ||
184 | +if((CMAKE_BUILD_TYPE STREQUAL "Debug") OR (CMAKE_BUILD_TYPE STREQUAL "Coverage")) | ||
185 | + set(MAX_CUSTOM_OPT_LEVEL -O0) | ||
186 | +elseif(CMAKE_BUILD_TYPE MATCHES "Sanitizer") | ||
187 | + set(MAX_CUSTOM_OPT_LEVEL -O1) | ||
188 | +else() | ||
189 | + if(px4_constrained_flash_build) | ||
190 | + set(MAX_CUSTOM_OPT_LEVEL -Os) | ||
191 | + else() | ||
192 | + set(MAX_CUSTOM_OPT_LEVEL -O2) | ||
193 | + endif() | ||
194 | +endif() | ||
195 | + | ||
196 | +set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug;Release;RelWithDebInfo;MinSizeRel;Coverage;AddressSanitizer;UndefinedBehaviorSanitizer") | ||
197 | +message(STATUS "cmake build type: ${CMAKE_BUILD_TYPE}") | ||
198 | + | ||
199 | +#============================================================================= | ||
200 | +# project definition | ||
201 | +# | ||
202 | +project(px4 CXX C ASM) | ||
203 | + | ||
204 | +set(package-contact "px4users@googlegroups.com") | ||
205 | + | ||
206 | +set(CMAKE_CXX_STANDARD 14) | ||
207 | +set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
208 | +set(CMAKE_C_STANDARD 11) | ||
209 | +set(CMAKE_C_STANDARD_REQUIRED ON) | ||
210 | +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) | ||
211 | + | ||
212 | +# For the catkin build process, unset build of dynamically-linked binaries | ||
213 | +# and do not change CMAKE_RUNTIME_OUTPUT_DIRECTORY | ||
214 | +if (NOT CATKIN_DEVEL_PREFIX) | ||
215 | + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PX4_BINARY_DIR}) | ||
216 | + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${PX4_BINARY_DIR}) | ||
217 | + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${PX4_BINARY_DIR}) | ||
218 | +else() | ||
219 | + SET(BUILD_SHARED_LIBS OFF) | ||
220 | +endif() | ||
221 | + | ||
222 | +#============================================================================= | ||
223 | + | ||
224 | +# gold linker - use if available (posix only for now) | ||
225 | +if(${PX4_PLATFORM} STREQUAL "posix") | ||
226 | + include(CMakeDependentOption) | ||
227 | + CMAKE_DEPENDENT_OPTION(USE_LD_GOLD | ||
228 | + "Use GNU gold linker" ON | ||
229 | + "NOT WIN32;NOT APPLE" OFF | ||
230 | + ) | ||
231 | + | ||
232 | + if(USE_LD_GOLD) | ||
233 | + execute_process(COMMAND ${CMAKE_C_COMPILER} -fuse-ld=gold -Wl,--version ERROR_QUIET OUTPUT_VARIABLE LD_VERSION) | ||
234 | + if("${LD_VERSION}" MATCHES "GNU gold") | ||
235 | + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=gold") | ||
236 | + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fuse-ld=gold") | ||
237 | + else() | ||
238 | + set(USE_LD_GOLD OFF) | ||
239 | + endif() | ||
240 | + endif() | ||
241 | +endif() | ||
242 | + | ||
243 | +#============================================================================= | ||
244 | + | ||
245 | +# Setup install paths | ||
246 | +if(${PX4_PLATFORM} STREQUAL "posix") | ||
247 | + # This makes it possible to dynamically load code which depends on symbols | ||
248 | + # inside the px4 executable. | ||
249 | + set(CMAKE_POSITION_INDEPENDENT_CODE ON) | ||
250 | + set(CMAKE_ENABLE_EXPORTS ON) | ||
251 | + | ||
252 | + include(coverage) | ||
253 | + include(sanitizers) | ||
254 | + | ||
255 | + # Define GNU standard installation directories | ||
256 | + include(GNUInstallDirs) | ||
257 | + | ||
258 | + if (NOT CMAKE_INSTALL_PREFIX) | ||
259 | + set(CMAKE_INSTALL_PREFIX "/usr" CACHE PATH "Install path prefix" FORCE) | ||
260 | + endif() | ||
261 | +endif() | ||
262 | + | ||
263 | +include(ccache) | ||
264 | + | ||
265 | +#============================================================================= | ||
266 | +# find programs and packages | ||
267 | +# | ||
268 | + | ||
269 | +# see if catkin was invoked to build this | ||
270 | +if (CATKIN_DEVEL_PREFIX) | ||
271 | + message(STATUS "catkin ENABLED") | ||
272 | + find_package(catkin REQUIRED) | ||
273 | + if (catkin_FOUND) | ||
274 | + catkin_package() | ||
275 | + else() | ||
276 | + message(FATAL_ERROR "catkin not found") | ||
277 | + endif() | ||
278 | +endif() | ||
279 | + | ||
280 | +# Python | ||
281 | +# If using catkin, Python 2 is found since it points | ||
282 | +# to the Python libs installed with the ROS distro | ||
283 | +if (NOT CATKIN_DEVEL_PREFIX) | ||
284 | + find_package(PythonInterp 3) | ||
285 | + # We have a custom error message to tell users how to install python3. | ||
286 | + if (NOT PYTHONINTERP_FOUND) | ||
287 | + message(FATAL_ERROR "Python 3 not found. Please install Python 3:\n" | ||
288 | + " Ubuntu: sudo apt install python3 python3-dev python3-pip\n" | ||
289 | + " macOS: brew install python") | ||
290 | + endif() | ||
291 | +else() | ||
292 | + find_package(PythonInterp REQUIRED) | ||
293 | +endif() | ||
294 | + | ||
295 | +option(PYTHON_COVERAGE "Python code coverage" OFF) | ||
296 | +if(PYTHON_COVERAGE) | ||
297 | + message(STATUS "python coverage enabled") | ||
298 | + set(PYTHON_EXECUTABLE coverage run -p) | ||
299 | +endif() | ||
300 | + | ||
301 | +#============================================================================= | ||
302 | +# get chip and chip manufacturer | ||
303 | +# | ||
304 | +px4_os_determine_build_chip() | ||
305 | +if(NOT PX4_CHIP_MANUFACTURER) | ||
306 | + message(FATAL_ERROR "px4_os_determine_build_chip() needs to set PX4_CHIP_MANUFACTURER") | ||
307 | +endif() | ||
308 | +if(NOT PX4_CHIP) | ||
309 | + message(FATAL_ERROR "px4_os_determine_build_chip() needs to set PX4_CHIP") | ||
310 | +endif() | ||
311 | + | ||
312 | +#============================================================================= | ||
313 | +# build flags | ||
314 | +# | ||
315 | +include(px4_add_common_flags) | ||
316 | +px4_add_common_flags() | ||
317 | +px4_os_add_flags() | ||
318 | + | ||
319 | +#============================================================================= | ||
320 | +# board cmake init (optional) | ||
321 | +# | ||
322 | +if(EXISTS ${PX4_BOARD_DIR}/cmake/init.cmake) | ||
323 | + include(${PX4_BOARD_DIR}/cmake/init.cmake) | ||
324 | +endif() | ||
325 | + | ||
326 | +#============================================================================= | ||
327 | +# message, and airframe generation | ||
328 | +# | ||
329 | +include(px4_metadata) | ||
330 | + | ||
331 | +add_subdirectory(msg EXCLUDE_FROM_ALL) | ||
332 | + | ||
333 | +px4_generate_airframes_xml(BOARD ${PX4_BOARD}) | ||
334 | + | ||
335 | +#============================================================================= | ||
336 | +# external projects | ||
337 | +# | ||
338 | +set(ep_base ${PX4_BINARY_DIR}/external) | ||
339 | +set_property(DIRECTORY PROPERTY EP_BASE ${ep_base}) | ||
340 | + | ||
341 | +# add external project install folders to build | ||
342 | +# add the directories so cmake won't warn | ||
343 | +execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${ep_base}) | ||
344 | +execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${ep_base}/Install) | ||
345 | +execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${ep_base}/Install/lib) | ||
346 | +link_directories(${ep_base}/Install/lib) | ||
347 | +execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${ep_base}/Install/include) | ||
348 | +include_directories(${ep_base}/Install/include) | ||
349 | + | ||
350 | +#============================================================================= | ||
351 | +# external modules | ||
352 | +# | ||
353 | +set(external_module_paths) | ||
354 | +if (NOT EXTERNAL_MODULES_LOCATION STREQUAL "") | ||
355 | + message(STATUS "External modules: ${EXTERNAL_MODULES_LOCATION}") | ||
356 | + add_subdirectory("${EXTERNAL_MODULES_LOCATION}/src" external_modules) | ||
357 | + | ||
358 | + foreach(external_module ${config_module_list_external}) | ||
359 | + add_subdirectory(${EXTERNAL_MODULES_LOCATION}/src/${external_module} external_modules/${external_module}) | ||
360 | + list(APPEND external_module_paths ${EXTERNAL_MODULES_LOCATION}/src/${external_module}) | ||
361 | + endforeach() | ||
362 | +endif() | ||
363 | + | ||
364 | +#============================================================================= | ||
365 | +# Testing - Automatic unit and integration testing with CTest | ||
366 | +# | ||
367 | + | ||
368 | +# optionally enable cmake testing (supported only on posix) | ||
369 | +option(CMAKE_TESTING "Configure test targets" OFF) | ||
370 | +if(${PX4_CONFIG} STREQUAL "px4_sitl_test") | ||
371 | + set(CMAKE_TESTING ON) | ||
372 | +endif() | ||
373 | +if(CMAKE_TESTING) | ||
374 | + include(CTest) # sets BUILD_TESTING variable | ||
375 | +endif() | ||
376 | + | ||
377 | +# enable test filtering to run only specific tests with the ctest -R regex functionality | ||
378 | +set(TESTFILTER "" CACHE STRING "Filter string for ctest to selectively only run specific tests (ctest -R)") | ||
379 | + | ||
380 | +# if testing is enabled download and configure gtest | ||
381 | +list(APPEND CMAKE_MODULE_PATH ${PX4_SOURCE_DIR}/cmake/gtest/) | ||
382 | +include(px4_add_gtest) | ||
383 | +if(BUILD_TESTING) | ||
384 | + include(gtest) | ||
385 | + | ||
386 | + add_custom_target(test_results | ||
387 | + COMMAND GTEST_COLOR=1 ${CMAKE_CTEST_COMMAND} --output-on-failure -T Test -R ${TESTFILTER} USES_TERMINAL | ||
388 | + DEPENDS | ||
389 | + px4 | ||
390 | + examples__dyn_hello | ||
391 | + test_mixer_multirotor | ||
392 | + USES_TERMINAL | ||
393 | + COMMENT "Running tests" | ||
394 | + WORKING_DIRECTORY ${PX4_BINARY_DIR}) | ||
395 | + set_target_properties(test_results PROPERTIES EXCLUDE_FROM_ALL TRUE) | ||
396 | +endif() | ||
397 | + | ||
398 | + | ||
399 | +#============================================================================= | ||
400 | +# subdirectories | ||
401 | +# | ||
402 | +add_library(parameters_interface INTERFACE) | ||
403 | + | ||
404 | +include(px4_add_library) | ||
405 | +add_subdirectory(src/lib EXCLUDE_FROM_ALL) | ||
406 | + | ||
407 | +add_subdirectory(platforms/${PX4_PLATFORM}/src/px4) | ||
408 | +add_subdirectory(platforms EXCLUDE_FROM_ALL) | ||
409 | + | ||
410 | +if(EXISTS "${PX4_BOARD_DIR}/CMakeLists.txt") | ||
411 | + add_subdirectory(${PX4_BOARD_DIR}) | ||
412 | +endif() | ||
413 | + | ||
414 | +foreach(module ${config_module_list}) | ||
415 | + add_subdirectory(src/${module}) | ||
416 | +endforeach() | ||
417 | + | ||
418 | +# must be the last module before firmware | ||
419 | +add_subdirectory(src/lib/parameters EXCLUDE_FROM_ALL) | ||
420 | +target_link_libraries(parameters_interface INTERFACE parameters) | ||
421 | + | ||
422 | +# firmware added last to generate the builtin for included modules | ||
423 | +add_subdirectory(platforms/${PX4_PLATFORM}) | ||
424 | + | ||
425 | +#============================================================================= | ||
426 | +# uORB graph generation: add a custom target 'uorb_graph' | ||
427 | +# | ||
428 | +set(uorb_graph_config ${PX4_BOARD}) | ||
429 | + | ||
430 | +set(graph_module_list "") | ||
431 | +foreach(module ${config_module_list}) | ||
432 | + set(graph_module_list "${graph_module_list}" "--src-path" "src/${module}") | ||
433 | +endforeach() | ||
434 | + | ||
435 | +add_custom_command(OUTPUT ${uorb_graph_config} | ||
436 | + COMMAND ${PYTHON_EXECUTABLE} ${PX4_SOURCE_DIR}/Tools/uorb_graph/create.py | ||
437 | + ${graph_module_list} | ||
438 | + --exclude-path src/examples | ||
439 | + --file ${PX4_SOURCE_DIR}/Tools/uorb_graph/graph_${uorb_graph_config} | ||
440 | + WORKING_DIRECTORY ${PX4_SOURCE_DIR} | ||
441 | + COMMENT "Generating uORB graph" | ||
442 | +) | ||
443 | +add_custom_target(uorb_graph DEPENDS ${uorb_graph_config}) | ||
444 | + | ||
445 | + | ||
446 | +include(doxygen) | ||
447 | +include(metadata) | ||
448 | +include(package) | ||
449 | + | ||
450 | +# print size | ||
451 | +add_custom_target(size | ||
452 | + COMMAND size $<TARGET_FILE:px4> | ||
453 | + DEPENDS px4 | ||
454 | + WORKING_DIRECTORY ${PX4_BINARY_DIR} | ||
455 | + USES_TERMINAL | ||
456 | + ) | ||
457 | + | ||
458 | +# install python requirements using configured python | ||
459 | +add_custom_target(install_python_requirements | ||
460 | + COMMAND ${PYTHON_EXECUTABLE} -m pip install --requirement ${PX4_SOURCE_DIR}/Tools/setup/requirements.txt | ||
461 | + DEPENDS ${PX4_SOURCE_DIR}/Tools/setup/requirements.txt | ||
462 | + USES_TERMINAL | ||
463 | +) |
1 | +/**************************************************************************** | ||
2 | + * | ||
3 | + * Copyright (c) 2015 Mark Charlebois. All rights reserved. | ||
4 | + * Copyright (c) 2016-2019 PX4 Development Team. All rights reserved. | ||
5 | + * | ||
6 | + * Redistribution and use in source and binary forms, with or without | ||
7 | + * modification, are permitted provided that the following conditions | ||
8 | + * are met: | ||
9 | + * | ||
10 | + * 1. Redistributions of source code must retain the above copyright | ||
11 | + * notice, this list of conditions and the following disclaimer. | ||
12 | + * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | + * notice, this list of conditions and the following disclaimer in | ||
14 | + * the documentation and/or other materials provided with the | ||
15 | + * distribution. | ||
16 | + * 3. Neither the name PX4 nor the names of its contributors may be | ||
17 | + * used to endorse or promote products derived from this software | ||
18 | + * without specific prior written permission. | ||
19 | + * | ||
20 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
21 | + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
22 | + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
23 | + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
24 | + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
25 | + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
26 | + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS | ||
27 | + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | ||
28 | + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
29 | + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
30 | + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
31 | + * POSSIBILITY OF SUCH DAMAGE. | ||
32 | + * | ||
33 | + ****************************************************************************/ | ||
34 | + | ||
35 | +/** | ||
36 | + * @file simulator.cpp | ||
37 | + * | ||
38 | + * This module interfaces via MAVLink to a software in the loop simulator (SITL) | ||
39 | + * such as jMAVSim or Gazebo. | ||
40 | + */ | ||
41 | + | ||
42 | +#include <px4_platform_common/log.h> | ||
43 | +#include <px4_platform_common/tasks.h> | ||
44 | +#include <px4_platform_common/time.h> | ||
45 | +#include <systemlib/err.h> | ||
46 | +#include <drivers/drv_board_led.h> | ||
47 | + | ||
48 | +#include "simulator.h" | ||
49 | + | ||
50 | +static px4_task_t g_sim_task = -1; | ||
51 | + | ||
52 | +Simulator *Simulator::_instance = nullptr; | ||
53 | + | ||
54 | +void Simulator::parameters_update(bool force) | ||
55 | +{ | ||
56 | + // check for parameter updates | ||
57 | + if (_parameter_update_sub.updated() || force) { | ||
58 | + // clear update | ||
59 | + parameter_update_s pupdate; | ||
60 | + _parameter_update_sub.copy(&pupdate); | ||
61 | + | ||
62 | + // update parameters from storage | ||
63 | + updateParams(); | ||
64 | + } | ||
65 | +} | ||
66 | + | ||
67 | +int Simulator::start(int argc, char *argv[]) | ||
68 | +{ | ||
69 | + _instance = new Simulator(); | ||
70 | + | ||
71 | + if (_instance) { | ||
72 | + if (argc == 5 && strcmp(argv[3], "-u") == 0) { | ||
73 | + _instance->set_ip(InternetProtocol::UDP); | ||
74 | + _instance->set_port(atoi(argv[4])); | ||
75 | + } | ||
76 | + | ||
77 | + if (argc == 5 && strcmp(argv[3], "-c") == 0) { | ||
78 | + _instance->set_ip(InternetProtocol::TCP); | ||
79 | + _instance->set_port(atoi(argv[4])); | ||
80 | + } | ||
81 | + | ||
82 | + if (argc == 6 && strcmp(argv[3], "-t") == 0) { | ||
83 | + _instance->set_ip(InternetProtocol::TCP); | ||
84 | + _instance->set_tcp_remote_ipaddr(argv[4]); | ||
85 | + _instance->set_port(atoi(argv[5])); | ||
86 | + } | ||
87 | + | ||
88 | + _instance->run(); | ||
89 | + | ||
90 | + return 0; | ||
91 | + | ||
92 | + } else { | ||
93 | + PX4_WARN("Simulator creation failed"); | ||
94 | + return 1; | ||
95 | + } | ||
96 | +} | ||
97 | + | ||
98 | +static void usage() | ||
99 | +{ | ||
100 | + PX4_INFO("Usage: simulator {start -[spt] [-u udp_port / -c tcp_port] |stop|status}"); | ||
101 | + PX4_INFO("Start simulator: simulator start"); | ||
102 | + PX4_INFO("Connect using UDP: simulator start -u udp_port"); | ||
103 | + PX4_INFO("Connect using TCP: simulator start -c tcp_port"); | ||
104 | + PX4_INFO("Connect to a remote server using TCP: simulator start -t ip_addr tcp_port"); | ||
105 | +} | ||
106 | + | ||
107 | +__BEGIN_DECLS | ||
108 | +extern int simulator_main(int argc, char *argv[]); | ||
109 | +__END_DECLS | ||
110 | + | ||
111 | + | ||
112 | +int simulator_main(int argc, char *argv[]) | ||
113 | +{ | ||
114 | + if (argc > 1 && strcmp(argv[1], "start") == 0) { | ||
115 | + | ||
116 | + if (g_sim_task >= 0) { | ||
117 | + PX4_WARN("Simulator already started"); | ||
118 | + return 0; | ||
119 | + } | ||
120 | + | ||
121 | + g_sim_task = px4_task_spawn_cmd("simulator", | ||
122 | + SCHED_DEFAULT, | ||
123 | + SCHED_PRIORITY_MAX, | ||
124 | + 1500, | ||
125 | + Simulator::start, | ||
126 | + argv); | ||
127 | + | ||
128 | +#if defined(ENABLE_LOCKSTEP_SCHEDULER) | ||
129 | + | ||
130 | + // We want to prevent the rest of the startup script from running until time | ||
131 | + // is initialized by the HIL_SENSOR messages from the simulator. | ||
132 | + while (true) { | ||
133 | + if (Simulator::getInstance() && Simulator::getInstance()->has_initialized()) { | ||
134 | + break; | ||
135 | + } | ||
136 | + | ||
137 | + system_usleep(100); | ||
138 | + } | ||
139 | + | ||
140 | +#endif | ||
141 | + | ||
142 | + } else if (argc == 2 && strcmp(argv[1], "stop") == 0) { | ||
143 | + if (g_sim_task < 0) { | ||
144 | + PX4_WARN("Simulator not running"); | ||
145 | + return 1; | ||
146 | + | ||
147 | + } else { | ||
148 | + px4_task_delete(g_sim_task); | ||
149 | + g_sim_task = -1; | ||
150 | + } | ||
151 | + | ||
152 | + } else if (argc == 2 && strcmp(argv[1], "status") == 0) { | ||
153 | + if (g_sim_task < 0) { | ||
154 | + PX4_WARN("Simulator not running"); | ||
155 | + return 1; | ||
156 | + | ||
157 | + } else { | ||
158 | + PX4_INFO("running"); | ||
159 | + } | ||
160 | + | ||
161 | + } else { | ||
162 | + usage(); | ||
163 | + return 1; | ||
164 | + } | ||
165 | + | ||
166 | + return 0; | ||
167 | +} |
1 | +/**************************************************************************** | ||
2 | + * | ||
3 | + * Copyright (c) 2015 Mark Charlebois. All rights reserved. | ||
4 | + * Copyright (c) 2016-2019 PX4 Development Team. All rights reserved. | ||
5 | + * | ||
6 | + * Redistribution and use in source and binary forms, with or without | ||
7 | + * modification, are permitted provided that the following conditions | ||
8 | + * are met: | ||
9 | + * | ||
10 | + * 1. Redistributions of source code must retain the above copyright | ||
11 | + * notice, this list of conditions and the following disclaimer. | ||
12 | + * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | + * notice, this list of conditions and the following disclaimer in | ||
14 | + * the documentation and/or other materials provided with the | ||
15 | + * distribution. | ||
16 | + * 3. Neither the name PX4 nor the names of its contributors may be | ||
17 | + * used to endorse or promote products derived from this software | ||
18 | + * without specific prior written permission. | ||
19 | + * | ||
20 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
21 | + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
22 | + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
23 | + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
24 | + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
25 | + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
26 | + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS | ||
27 | + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | ||
28 | + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
29 | + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
30 | + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
31 | + * POSSIBILITY OF SUCH DAMAGE. | ||
32 | + * | ||
33 | + ****************************************************************************/ | ||
34 | + | ||
35 | + | ||
36 | +/** | ||
37 | + * @file simulator.h | ||
38 | + * | ||
39 | + * This module interfaces via MAVLink to a software in the loop simulator (SITL) | ||
40 | + * such as jMAVSim or Gazebo. | ||
41 | + */ | ||
42 | + | ||
43 | +#pragma once | ||
44 | + | ||
45 | +#include <drivers/drv_hrt.h> | ||
46 | +#include <drivers/drv_rc_input.h> | ||
47 | +#include <lib/drivers/accelerometer/PX4Accelerometer.hpp> | ||
48 | +#include <lib/drivers/barometer/PX4Barometer.hpp> | ||
49 | +#include <lib/drivers/gyroscope/PX4Gyroscope.hpp> | ||
50 | +#include <lib/drivers/magnetometer/PX4Magnetometer.hpp> | ||
51 | +#include <lib/ecl/geo/geo.h> | ||
52 | +#include <lib/perf/perf_counter.h> | ||
53 | +#include <px4_platform_common/atomic.h> | ||
54 | +#include <px4_platform_common/bitmask.h> | ||
55 | +#include <px4_platform_common/module_params.h> | ||
56 | +#include <px4_platform_common/posix.h> | ||
57 | +#include <uORB/Publication.hpp> | ||
58 | +#include <uORB/Subscription.hpp> | ||
59 | +#include <uORB/SubscriptionInterval.hpp> | ||
60 | +#include <uORB/topics/actuator_outputs.h> | ||
61 | +#include <uORB/topics/differential_pressure.h> | ||
62 | +#include <uORB/topics/distance_sensor.h> | ||
63 | +#include <uORB/topics/irlock_report.h> | ||
64 | +#include <uORB/topics/manual_control_setpoint.h> | ||
65 | +#include <uORB/topics/optical_flow.h> | ||
66 | +#include <uORB/topics/parameter_update.h> | ||
67 | +#include <uORB/topics/sensor_gps.h> | ||
68 | +#include <uORB/topics/vehicle_angular_velocity.h> | ||
69 | +#include <uORB/topics/vehicle_attitude.h> | ||
70 | +#include <uORB/topics/vehicle_global_position.h> | ||
71 | +#include <uORB/topics/vehicle_local_position.h> | ||
72 | +#include <uORB/topics/vehicle_odometry.h> | ||
73 | +#include <uORB/topics/vehicle_status.h> | ||
74 | +#include <uORB/topics/vehicle_command.h> | ||
75 | +#include <uORB/topics/vehicle_command_ack.h> | ||
76 | + | ||
77 | +#include <random> | ||
78 | + | ||
79 | +#include <v2.0/common/mavlink.h> | ||
80 | +#include <v2.0/mavlink_types.h> | ||
81 | + | ||
82 | +using namespace time_literals; | ||
83 | + | ||
84 | +//! Enumeration to use on the bitmask in HIL_SENSOR | ||
85 | +enum class SensorSource { | ||
86 | + ACCEL = 0b111, | ||
87 | + GYRO = 0b111000, | ||
88 | + MAG = 0b111000000, | ||
89 | + BARO = 0b1101000000000, | ||
90 | + DIFF_PRESS = 0b10000000000 | ||
91 | +}; | ||
92 | +ENABLE_BIT_OPERATORS(SensorSource) | ||
93 | + | ||
94 | +//! AND operation for the enumeration and unsigned types that returns the bitmask | ||
95 | +template<typename A, typename B> | ||
96 | +static inline SensorSource operator &(A lhs, B rhs) | ||
97 | +{ | ||
98 | + // make it type safe | ||
99 | + static_assert((std::is_same<A, uint32_t>::value || std::is_same<A, SensorSource>::value), | ||
100 | + "first argument is not uint32_t or SensorSource enum type"); | ||
101 | + static_assert((std::is_same<B, uint32_t>::value || std::is_same<B, SensorSource>::value), | ||
102 | + "second argument is not uint32_t or SensorSource enum type"); | ||
103 | + | ||
104 | + typedef typename std::underlying_type<SensorSource>::type underlying; | ||
105 | + | ||
106 | + return static_cast<SensorSource>( | ||
107 | + static_cast<underlying>(lhs) & | ||
108 | + static_cast<underlying>(rhs) | ||
109 | + ); | ||
110 | +} | ||
111 | + | ||
112 | +class Simulator : public ModuleParams | ||
113 | +{ | ||
114 | +public: | ||
115 | + static Simulator *getInstance() { return _instance; } | ||
116 | + | ||
117 | + enum class InternetProtocol { | ||
118 | + TCP, | ||
119 | + UDP | ||
120 | + }; | ||
121 | + | ||
122 | + static int start(int argc, char *argv[]); | ||
123 | + | ||
124 | + void set_ip(InternetProtocol ip) { _ip = ip; } | ||
125 | + void set_port(unsigned port) { _port = port; } | ||
126 | + void set_tcp_remote_ipaddr(char *tcp_remote_ipaddr) { _tcp_remote_ipaddr = tcp_remote_ipaddr; } | ||
127 | + | ||
128 | +#if defined(ENABLE_LOCKSTEP_SCHEDULER) | ||
129 | + bool has_initialized() { return _has_initialized.load(); } | ||
130 | +#endif | ||
131 | + | ||
132 | +private: | ||
133 | + Simulator() : ModuleParams(nullptr) | ||
134 | + { | ||
135 | + } | ||
136 | + | ||
137 | + ~Simulator() | ||
138 | + { | ||
139 | + // free perf counters | ||
140 | + perf_free(_perf_sim_delay); | ||
141 | + perf_free(_perf_sim_interval); | ||
142 | + | ||
143 | + for (size_t i = 0; i < sizeof(_dist_pubs) / sizeof(_dist_pubs[0]); i++) { | ||
144 | + delete _dist_pubs[i]; | ||
145 | + } | ||
146 | + | ||
147 | + px4_lockstep_unregister_component(_lockstep_component); | ||
148 | + | ||
149 | + for (size_t i = 0; i < sizeof(_sensor_gps_pubs) / sizeof(_sensor_gps_pubs[0]); i++) { | ||
150 | + delete _sensor_gps_pubs[i]; | ||
151 | + } | ||
152 | + | ||
153 | + _instance = nullptr; | ||
154 | + } | ||
155 | + | ||
156 | + | ||
157 | + void check_failure_injections(); | ||
158 | + | ||
159 | + int publish_flow_topic(const mavlink_hil_optical_flow_t *flow); | ||
160 | + int publish_odometry_topic(const mavlink_message_t *odom_mavlink); | ||
161 | + int publish_distance_topic(const mavlink_distance_sensor_t *dist); | ||
162 | + | ||
163 | + static Simulator *_instance; | ||
164 | + | ||
165 | + // simulated sensor instances | ||
166 | + static constexpr uint8_t ACCEL_COUNT_MAX = 3; | ||
167 | + PX4Accelerometer _px4_accel[ACCEL_COUNT_MAX] { | ||
168 | + {1310988, ROTATION_NONE}, // 1310988: DRV_IMU_DEVTYPE_SIM, BUS: 1, ADDR: 1, TYPE: SIMULATION | ||
169 | + {1310996, ROTATION_NONE}, // 1310996: DRV_IMU_DEVTYPE_SIM, BUS: 2, ADDR: 1, TYPE: SIMULATION | ||
170 | + {1311004, ROTATION_NONE}, // 1311004: DRV_IMU_DEVTYPE_SIM, BUS: 3, ADDR: 1, TYPE: SIMULATION | ||
171 | + }; | ||
172 | + | ||
173 | + static constexpr uint8_t GYRO_COUNT_MAX = 3; | ||
174 | + PX4Gyroscope _px4_gyro[GYRO_COUNT_MAX] { | ||
175 | + {1310988, ROTATION_NONE}, // 1310988: DRV_IMU_DEVTYPE_SIM, BUS: 1, ADDR: 1, TYPE: SIMULATION | ||
176 | + {1310996, ROTATION_NONE}, // 1310996: DRV_IMU_DEVTYPE_SIM, BUS: 2, ADDR: 1, TYPE: SIMULATION | ||
177 | + {1311004, ROTATION_NONE}, // 1311004: DRV_IMU_DEVTYPE_SIM, BUS: 3, ADDR: 1, TYPE: SIMULATION | ||
178 | + }; | ||
179 | + | ||
180 | + PX4Magnetometer _px4_mag_0{197388, ROTATION_NONE}; // 197388: DRV_MAG_DEVTYPE_MAGSIM, BUS: 1, ADDR: 1, TYPE: SIMULATION | ||
181 | + PX4Magnetometer _px4_mag_1{197644, ROTATION_NONE}; // 197644: DRV_MAG_DEVTYPE_MAGSIM, BUS: 2, ADDR: 1, TYPE: SIMULATION | ||
182 | + | ||
183 | + PX4Barometer _px4_baro_0{6620172}; // 6620172: DRV_BARO_DEVTYPE_BAROSIM, BUS: 1, ADDR: 4, TYPE: SIMULATION | ||
184 | + PX4Barometer _px4_baro_1{6620428}; // 6620428: DRV_BARO_DEVTYPE_BAROSIM, BUS: 2, ADDR: 4, TYPE: SIMULATION | ||
185 | + | ||
186 | + float _sensors_temperature{0}; | ||
187 | + | ||
188 | + perf_counter_t _perf_sim_delay{perf_alloc(PC_ELAPSED, MODULE_NAME": network delay")}; | ||
189 | + perf_counter_t _perf_sim_interval{perf_alloc(PC_INTERVAL, MODULE_NAME": network interval")}; | ||
190 | + | ||
191 | + // uORB publisher handlers | ||
192 | + uORB::Publication<differential_pressure_s> _differential_pressure_pub{ORB_ID(differential_pressure)}; | ||
193 | + uORB::PublicationMulti<optical_flow_s> _flow_pub{ORB_ID(optical_flow)}; | ||
194 | + uORB::Publication<irlock_report_s> _irlock_report_pub{ORB_ID(irlock_report)}; | ||
195 | + uORB::Publication<vehicle_odometry_s> _visual_odometry_pub{ORB_ID(vehicle_visual_odometry)}; | ||
196 | + uORB::Publication<vehicle_odometry_s> _mocap_odometry_pub{ORB_ID(vehicle_mocap_odometry)}; | ||
197 | + | ||
198 | + uORB::Publication<vehicle_command_ack_s> _command_ack_pub{ORB_ID(vehicle_command_ack)}; | ||
199 | + | ||
200 | + uORB::PublicationMulti<distance_sensor_s> *_dist_pubs[ORB_MULTI_MAX_INSTANCES] {}; | ||
201 | + uint32_t _dist_sensor_ids[ORB_MULTI_MAX_INSTANCES] {}; | ||
202 | + | ||
203 | + uORB::SubscriptionInterval _parameter_update_sub{ORB_ID(parameter_update), 1_s}; | ||
204 | + | ||
205 | + unsigned int _port{14560}; | ||
206 | + | ||
207 | + InternetProtocol _ip{InternetProtocol::UDP}; | ||
208 | + | ||
209 | + char *_tcp_remote_ipaddr{nullptr}; | ||
210 | + | ||
211 | + double _realtime_factor{1.0}; ///< How fast the simulation runs in comparison to real system time | ||
212 | + | ||
213 | + hrt_abstime _last_sim_timestamp{0}; | ||
214 | + hrt_abstime _last_sitl_timestamp{0}; | ||
215 | + | ||
216 | + | ||
217 | + void run(); | ||
218 | + void handle_message(const mavlink_message_t *msg); | ||
219 | + void handle_message_distance_sensor(const mavlink_message_t *msg); | ||
220 | + void handle_message_hil_gps(const mavlink_message_t *msg); | ||
221 | + void handle_message_hil_sensor(const mavlink_message_t *msg); | ||
222 | + void handle_message_hil_state_quaternion(const mavlink_message_t *msg); | ||
223 | + void handle_message_landing_target(const mavlink_message_t *msg); | ||
224 | + void handle_message_odometry(const mavlink_message_t *msg); | ||
225 | + void handle_message_optical_flow(const mavlink_message_t *msg); | ||
226 | + void handle_message_rc_channels(const mavlink_message_t *msg); | ||
227 | + void handle_message_vision_position_estimate(const mavlink_message_t *msg); | ||
228 | + | ||
229 | + void parameters_update(bool force); | ||
230 | + void poll_for_MAVLink_messages(); | ||
231 | + void request_hil_state_quaternion(); | ||
232 | + void send(); | ||
233 | + void send_controls(); | ||
234 | + void send_heartbeat(); | ||
235 | + void send_mavlink_message(const mavlink_message_t &aMsg); | ||
236 | + void update_sensors(const hrt_abstime &time, const mavlink_hil_sensor_t &sensors); | ||
237 | + | ||
238 | + static void *sending_trampoline(void *); | ||
239 | + | ||
240 | + void actuator_controls_from_outputs(mavlink_hil_actuator_controls_t *msg); | ||
241 | + | ||
242 | + | ||
243 | + // uORB publisher handlers | ||
244 | + uORB::Publication<vehicle_angular_velocity_s> _vehicle_angular_velocity_ground_truth_pub{ORB_ID(vehicle_angular_velocity_groundtruth)}; | ||
245 | + uORB::Publication<vehicle_attitude_s> _attitude_ground_truth_pub{ORB_ID(vehicle_attitude_groundtruth)}; | ||
246 | + uORB::Publication<vehicle_global_position_s> _gpos_ground_truth_pub{ORB_ID(vehicle_global_position_groundtruth)}; | ||
247 | + uORB::Publication<vehicle_local_position_s> _lpos_ground_truth_pub{ORB_ID(vehicle_local_position_groundtruth)}; | ||
248 | + uORB::Publication<input_rc_s> _input_rc_pub{ORB_ID(input_rc)}; | ||
249 | + | ||
250 | + // HIL GPS | ||
251 | + static constexpr int MAX_GPS = 3; | ||
252 | + uORB::PublicationMulti<sensor_gps_s> *_sensor_gps_pubs[MAX_GPS] {}; | ||
253 | + uint8_t _gps_ids[MAX_GPS] {}; | ||
254 | + std::default_random_engine _gen{}; | ||
255 | + | ||
256 | + // uORB subscription handlers | ||
257 | + int _actuator_outputs_sub{-1}; | ||
258 | + actuator_outputs_s _actuator_outputs{}; | ||
259 | + | ||
260 | + uORB::Subscription _vehicle_status_sub{ORB_ID(vehicle_status)}; | ||
261 | + uORB::Subscription _vehicle_command_sub{ORB_ID(vehicle_command)}; | ||
262 | + | ||
263 | + // hil map_ref data | ||
264 | + map_projection_reference_s _global_local_proj_ref{}; | ||
265 | + float _global_local_alt0{NAN}; | ||
266 | + | ||
267 | + vehicle_status_s _vehicle_status{}; | ||
268 | + | ||
269 | + bool _accel_blocked[ACCEL_COUNT_MAX] {}; | ||
270 | + bool _accel_stuck[ACCEL_COUNT_MAX] {}; | ||
271 | + sensor_accel_fifo_s _last_accel_fifo{}; | ||
272 | + matrix::Vector3f _last_accel[GYRO_COUNT_MAX] {}; | ||
273 | + | ||
274 | + bool _gyro_blocked[GYRO_COUNT_MAX] {}; | ||
275 | + bool _gyro_stuck[GYRO_COUNT_MAX] {}; | ||
276 | + sensor_gyro_fifo_s _last_gyro_fifo{}; | ||
277 | + matrix::Vector3f _last_gyro[GYRO_COUNT_MAX] {}; | ||
278 | + | ||
279 | + bool _baro_blocked{false}; | ||
280 | + bool _baro_stuck{false}; | ||
281 | + | ||
282 | + bool _mag_blocked{false}; | ||
283 | + bool _mag_stuck{false}; | ||
284 | + | ||
285 | + bool _gps_blocked{false}; | ||
286 | + bool _airspeed_blocked{false}; | ||
287 | + | ||
288 | + float _last_magx{0.0f}; | ||
289 | + float _last_magy{0.0f}; | ||
290 | + float _last_magz{0.0f}; | ||
291 | + | ||
292 | +#if defined(ENABLE_LOCKSTEP_SCHEDULER) | ||
293 | + px4::atomic<bool> _has_initialized {false}; | ||
294 | +#endif | ||
295 | + | ||
296 | + int _lockstep_component{-1}; | ||
297 | + | ||
298 | + DEFINE_PARAMETERS( | ||
299 | + (ParamInt<px4::params::MAV_TYPE>) _param_mav_type, | ||
300 | + (ParamInt<px4::params::MAV_SYS_ID>) _param_mav_sys_id, | ||
301 | + (ParamInt<px4::params::MAV_COMP_ID>) _param_mav_comp_id | ||
302 | + ) | ||
303 | +}; |
-
Please register or login to post a comment