From d85fa739c6841f11efccdd2cf32d5bed9a7b265d Mon Sep 17 00:00:00 2001 From: bazooka joe Date: Sun, 6 Oct 2019 12:24:42 +0300 Subject: [PATCH] added control modes added new concept of control modes which allows to separate different vehicles modes in the compile time. current control modes are: fixedwing, multicopter, vtol (vtol), rover. --- boards/px4/fmu-v5/critmonitor.cmake | 6 +++ boards/px4/fmu-v5/default.cmake | 6 +++ boards/px4/fmu-v5/fixedwing.cmake | 3 ++ boards/px4/fmu-v5/irqmonitor.cmake | 6 +++ boards/px4/fmu-v5/multicopter.cmake | 3 ++ boards/px4/fmu-v5/rover.cmake | 3 ++ boards/px4/fmu-v5/rtps.cmake | 6 +++ boards/px4/fmu-v5/stackcheck.cmake | 6 +++ boards/px4/sitl/default.cmake | 6 +++ boards/px4/sitl/rtps.cmake | 6 +++ boards/px4/sitl/test.cmake | 6 +++ cmake/px4_add_board.cmake | 5 +++ cmake/px4_add_common_flags.cmake | 29 ++++++++++++++ src/modules/land_detector/CMakeLists.txt | 28 +++++++++++-- .../land_detector/land_detector_main.cpp | 39 ++++++++++++------- .../mc_att_control/mc_att_control_main.cpp | 5 +++ 16 files changed, 146 insertions(+), 17 deletions(-) diff --git a/boards/px4/fmu-v5/critmonitor.cmake b/boards/px4/fmu-v5/critmonitor.cmake index 8a598a750a51..f523d4b261c1 100644 --- a/boards/px4/fmu-v5/critmonitor.cmake +++ b/boards/px4/fmu-v5/critmonitor.cmake @@ -11,6 +11,12 @@ px4_add_board( TESTING UAVCAN_INTERFACES 2 + CONTROL_MODES + fixed_wing + vtol + multicopter + rover + SERIAL_PORTS GPS1:/dev/ttyS0 TEL1:/dev/ttyS1 diff --git a/boards/px4/fmu-v5/default.cmake b/boards/px4/fmu-v5/default.cmake index 272a39576a5d..64d06d8e0788 100644 --- a/boards/px4/fmu-v5/default.cmake +++ b/boards/px4/fmu-v5/default.cmake @@ -11,6 +11,12 @@ px4_add_board( TESTING UAVCAN_INTERFACES 2 + CONTROL_MODES + fixed_wing + vtol + multicopter + rover + SERIAL_PORTS GPS1:/dev/ttyS0 TEL1:/dev/ttyS1 diff --git a/boards/px4/fmu-v5/fixedwing.cmake b/boards/px4/fmu-v5/fixedwing.cmake index 9dae74abe48e..aa3c9fdadf5b 100644 --- a/boards/px4/fmu-v5/fixedwing.cmake +++ b/boards/px4/fmu-v5/fixedwing.cmake @@ -10,6 +10,9 @@ px4_add_board( IO px4_io-v2_default UAVCAN_INTERFACES 2 + CONTROL_MODES + fixed_wing + SERIAL_PORTS GPS1:/dev/ttyS0 TEL1:/dev/ttyS1 diff --git a/boards/px4/fmu-v5/irqmonitor.cmake b/boards/px4/fmu-v5/irqmonitor.cmake index 05ef47c31792..8e33623b1986 100644 --- a/boards/px4/fmu-v5/irqmonitor.cmake +++ b/boards/px4/fmu-v5/irqmonitor.cmake @@ -11,6 +11,12 @@ px4_add_board( TESTING UAVCAN_INTERFACES 2 + CONTROL_MODES + fixed_wing + vtol + multicopter + rover + SERIAL_PORTS GPS1:/dev/ttyS0 TEL1:/dev/ttyS1 diff --git a/boards/px4/fmu-v5/multicopter.cmake b/boards/px4/fmu-v5/multicopter.cmake index 41751357202c..7230e87413fb 100644 --- a/boards/px4/fmu-v5/multicopter.cmake +++ b/boards/px4/fmu-v5/multicopter.cmake @@ -11,6 +11,9 @@ px4_add_board( TESTING UAVCAN_INTERFACES 2 + CONTROL_MODES + multicopter + SERIAL_PORTS GPS1:/dev/ttyS0 TEL1:/dev/ttyS1 diff --git a/boards/px4/fmu-v5/rover.cmake b/boards/px4/fmu-v5/rover.cmake index 340fc1b4c7c6..cddddc18c0fc 100644 --- a/boards/px4/fmu-v5/rover.cmake +++ b/boards/px4/fmu-v5/rover.cmake @@ -10,6 +10,9 @@ px4_add_board( IO px4_io-v2_default UAVCAN_INTERFACES 2 + CONTROL_MODES + rover + SERIAL_PORTS GPS1:/dev/ttyS0 TEL1:/dev/ttyS1 diff --git a/boards/px4/fmu-v5/rtps.cmake b/boards/px4/fmu-v5/rtps.cmake index 5dce25381b1f..c99987e44513 100644 --- a/boards/px4/fmu-v5/rtps.cmake +++ b/boards/px4/fmu-v5/rtps.cmake @@ -11,6 +11,12 @@ px4_add_board( TESTING UAVCAN_INTERFACES 2 + CONTROL_MODES + fixed_wing + vtol + multicopter + rover + SERIAL_PORTS GPS1:/dev/ttyS0 TEL1:/dev/ttyS1 diff --git a/boards/px4/fmu-v5/stackcheck.cmake b/boards/px4/fmu-v5/stackcheck.cmake index 8f4a733080a6..d9695dea28d3 100644 --- a/boards/px4/fmu-v5/stackcheck.cmake +++ b/boards/px4/fmu-v5/stackcheck.cmake @@ -11,6 +11,12 @@ px4_add_board( TESTING #UAVCAN_INTERFACES 2 + CONTROL_MODES + fixed_wing + vtol + multicopter + rover + SERIAL_PORTS GPS1:/dev/ttyS0 TEL1:/dev/ttyS1 diff --git a/boards/px4/sitl/default.cmake b/boards/px4/sitl/default.cmake index 98b058455ef6..2d23acffc1c6 100644 --- a/boards/px4/sitl/default.cmake +++ b/boards/px4/sitl/default.cmake @@ -6,6 +6,12 @@ px4_add_board( LABEL default TESTING + CONTROL_MODES + fixed_wing + vtol + multicopter + rover + DRIVERS #barometer # all available barometer drivers #batt_smbus diff --git a/boards/px4/sitl/rtps.cmake b/boards/px4/sitl/rtps.cmake index 5a676e40aaf6..a5f01904379a 100644 --- a/boards/px4/sitl/rtps.cmake +++ b/boards/px4/sitl/rtps.cmake @@ -6,6 +6,12 @@ px4_add_board( LABEL rtps TESTING + CONTROL_MODES + fixed_wing + vtol + multicopter + rover + DRIVERS #barometer # all available barometer drivers #batt_smbus diff --git a/boards/px4/sitl/test.cmake b/boards/px4/sitl/test.cmake index 737717daf685..8ad9054884c2 100644 --- a/boards/px4/sitl/test.cmake +++ b/boards/px4/sitl/test.cmake @@ -6,6 +6,12 @@ px4_add_board( LABEL test TESTING + CONTROL_MODES + fixed_wing + vtol + multicopter + rover + DRIVERS #barometer # all available barometer drivers #batt_smbus diff --git a/cmake/px4_add_board.cmake b/cmake/px4_add_board.cmake index 7dbc5e29034e..4fd57e62bc68 100644 --- a/cmake/px4_add_board.cmake +++ b/cmake/px4_add_board.cmake @@ -146,6 +146,7 @@ function(px4_add_board) SYSTEMCMDS EXAMPLES SERIAL_PORTS + CONTROL_MODES DF_DRIVERS OPTIONS CONSTRAINED_FLASH @@ -200,6 +201,10 @@ function(px4_add_board) set(board_serial_ports ${SERIAL_PORTS} PARENT_SCOPE) endif() + if(CONTROL_MODES) + set(control_modes ${CONTROL_MODES} PARENT_SCOPE) + endif() + # ROMFS if(ROMFSROOT) set(config_romfs_root ${ROMFSROOT} CACHE INTERNAL "ROMFS root" FORCE) diff --git a/cmake/px4_add_common_flags.cmake b/cmake/px4_add_common_flags.cmake index da84cc8e1040..f55112442dca 100644 --- a/cmake/px4_add_common_flags.cmake +++ b/cmake/px4_add_common_flags.cmake @@ -191,4 +191,33 @@ function(px4_add_common_flags) -D__STDC_FORMAT_MACROS ) + list(FIND control_modes "fixed_wing" control_mode_index) + if(${control_mode_index} GREATER -1) + add_definitions( + -DCONTROL_MODES_FW + ) + endif() + + list(FIND control_modes "multicopter" control_mode_index) + if(${control_mode_index} GREATER -1) + add_definitions( + -DCONTROL_MODES_MC + ) + endif() + + list(FIND control_modes "vtol" control_mode_index) + if(${control_mode_index} GREATER -1) + add_definitions( + -DCONTROL_MODES_VTOL + ) + endif() + + list(FIND control_modes "rover" control_mode_index) + if(${control_mode_index} GREATER -1) + add_definitions( + -DCONTROL_MODES_ROVER + ) + endif() + + endfunction() diff --git a/src/modules/land_detector/CMakeLists.txt b/src/modules/land_detector/CMakeLists.txt index 2ae0d3a4758c..1820ef73ed9e 100644 --- a/src/modules/land_detector/CMakeLists.txt +++ b/src/modules/land_detector/CMakeLists.txt @@ -30,6 +30,28 @@ # POSSIBILITY OF SUCH DAMAGE. # ############################################################################ + +set(CONTROL_MODES_SRCS) +list(FIND control_modes "fixed_wing" control_mode_index) +if(${control_mode_index} GREATER -1) + list(APPEND CONTROL_MODES_SRCS FixedwingLandDetector.cpp) +endif() + +list(FIND control_modes "multicopter" control_mode_index) +if(${control_mode_index} GREATER -1) + list(APPEND CONTROL_MODES_SRCS MulticopterLandDetector.cpp) +endif() + +list(FIND control_modes "vtol" control_mode_index) +if(${control_mode_index} GREATER -1) + list(APPEND CONTROL_MODES_SRCS VtolLandDetector.cpp) +endif() + +list(FIND control_modes "rover" control_mode_index) +if(${control_mode_index} GREATER -1) + list(APPEND CONTROL_MODES_SRCS RoverLandDetector.cpp) +endif() + px4_add_module( MODULE modules__land_detector MAIN land_detector @@ -37,10 +59,8 @@ px4_add_module( SRCS land_detector_main.cpp LandDetector.cpp - MulticopterLandDetector.cpp - FixedwingLandDetector.cpp - VtolLandDetector.cpp - RoverLandDetector.cpp + ${CONTROL_MODES_SRCS} + DEPENDS hysteresis ) diff --git a/src/modules/land_detector/land_detector_main.cpp b/src/modules/land_detector/land_detector_main.cpp index 5d2498e0f5d7..c8b20ee57c53 100644 --- a/src/modules/land_detector/land_detector_main.cpp +++ b/src/modules/land_detector/land_detector_main.cpp @@ -67,22 +67,35 @@ int LandDetector::task_spawn(int argc, char *argv[]) LandDetector *obj = nullptr; +#ifdef CONTROL_MODE_FW + if (strcmp(argv[1], "fixedwing") == 0) { obj = new FixedwingLandDetector(); - } else if (strcmp(argv[1], "multicopter") == 0) { - obj = new MulticopterLandDetector(); - - } else if (strcmp(argv[1], "vtol") == 0) { - obj = new VtolLandDetector(); - - } else if (strcmp(argv[1], "rover") == 0) { - obj = new RoverLandDetector(); - - } else { - print_usage("unknown mode"); - return PX4_ERROR; - } + } else +#endif +#ifdef CONTROL_MODE_MC + if (strcmp(argv[1], "multicopter") == 0) { + obj = new MulticopterLandDetector(); + + } else +#endif +#ifdef CONTROL_MODE_VT + if (strcmp(argv[1], "vtol") == 0) { + obj = new VtolLandDetector(); + + } else +#endif +#ifdef CONTROL_MODE_ROVER + if (strcmp(argv[1], "rover") == 0) { + obj = new RoverLandDetector(); + + } else +#endif + { + print_usage("unknown mode"); + return PX4_ERROR; + } if (obj == nullptr) { PX4_ERR("alloc failed"); diff --git a/src/modules/mc_att_control/mc_att_control_main.cpp b/src/modules/mc_att_control/mc_att_control_main.cpp index 87786dd08979..6d1be12488a5 100644 --- a/src/modules/mc_att_control/mc_att_control_main.cpp +++ b/src/modules/mc_att_control/mc_att_control_main.cpp @@ -159,12 +159,17 @@ MulticopterAttitudeControl::vehicle_status_poll() _actuators_id = ORB_ID(actuator_controls_virtual_mc); _attitude_sp_id = ORB_ID(mc_virtual_attitude_setpoint); +#ifdef CONTROL_MODE_VTOL int32_t vt_type = -1; if (param_get(param_find("VT_TYPE"), &vt_type) == PX4_OK) { _is_tailsitter = (static_cast(vt_type) == vtol_type::TAILSITTER); } +#else + _is_tailsitter = false; +#endif + } else { _actuators_id = ORB_ID(actuator_controls_0); _attitude_sp_id = ORB_ID(vehicle_attitude_setpoint);