From 4cfad588ffadcb4beb0358bff91a6bef2ae80263 Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Sat, 8 Aug 2015 23:49:18 +0200 Subject: [PATCH 01/14] IO: Add param for S.BUS output --- src/drivers/px4io/px4io_params.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/drivers/px4io/px4io_params.c b/src/drivers/px4io/px4io_params.c index 057bcaf150..51d39e97ba 100644 --- a/src/drivers/px4io/px4io_params.c +++ b/src/drivers/px4io/px4io_params.c @@ -129,3 +129,14 @@ PARAM_DEFINE_INT32(PWM_MAIN_REV7, 0); * @group PWM Outputs */ PARAM_DEFINE_INT32(PWM_MAIN_REV8, 0); + +/** + * Enable S.BUS out + * + * Set to 1 to enable S.BUS version 1 output instead of RSSI. + * + * @min 0 + * @max 1 + * @group PWM Outputs + */ +PARAM_DEFINE_INT32(PWM_SBUS_MODE, 0); From e07e4743c5bd10e582f2d64f341ad0da051a2308 Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Sat, 8 Aug 2015 23:50:05 +0200 Subject: [PATCH 02/14] PX4IO: Enable S.BUS if config param is set, ignore if no param present --- src/drivers/px4io/px4io.cpp | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/src/drivers/px4io/px4io.cpp b/src/drivers/px4io/px4io.cpp index be3c2e1375..716a89d254 100644 --- a/src/drivers/px4io/px4io.cpp +++ b/src/drivers/px4io/px4io.cpp @@ -1116,25 +1116,42 @@ PX4IO::task_main() (void)io_reg_set(PX4IO_PAGE_SETUP, PX4IO_P_SETUP_PWM_REVERSE, pwm_invert_mask); float trim_val; - param_t trim_parm; + param_t parm_handle; - trim_parm = param_find("TRIM_ROLL"); - if (trim_parm != PARAM_INVALID) { - param_get(trim_parm, &trim_val); + parm_handle = param_find("TRIM_ROLL"); + if (parm_handle != PARAM_INVALID) { + param_get(parm_handle, &trim_val); (void)io_reg_set(PX4IO_PAGE_SETUP, PX4IO_P_SETUP_TRIM_ROLL, FLOAT_TO_REG(trim_val)); } - trim_parm = param_find("TRIM_PITCH"); - if (trim_parm != PARAM_INVALID) { - param_get(trim_parm, &trim_val); + parm_handle = param_find("TRIM_PITCH"); + if (parm_handle != PARAM_INVALID) { + param_get(parm_handle, &trim_val); (void)io_reg_set(PX4IO_PAGE_SETUP, PX4IO_P_SETUP_TRIM_PITCH, FLOAT_TO_REG(trim_val)); } - trim_parm = param_find("TRIM_YAW"); - if (trim_parm != PARAM_INVALID) { - param_get(trim_parm, &trim_val); + parm_handle = param_find("TRIM_YAW"); + if (parm_handle != PARAM_INVALID) { + param_get(parm_handle, &trim_val); (void)io_reg_set(PX4IO_PAGE_SETUP, PX4IO_P_SETUP_TRIM_YAW, FLOAT_TO_REG(trim_val)); } + + /* S.BUS output */ + int sbus_mode; + parm_handle = param_find("PWM_SBUS_MODE"); + if (parm_handle != PARAM_INVALID) { + param_get(parm_handle, &sbus_mode); + if (sbus_mode == 1) { + /* enable S.BUS 1 */ + (void)io_reg_modify(PX4IO_PAGE_SETUP, PX4IO_P_SETUP_FEATURES, 0, PX4IO_P_SETUP_FEATURES_SBUS1_OUT); + } else if (sbus_mode == 2) { + /* enable S.BUS 2 */ + (void)io_reg_modify(PX4IO_PAGE_SETUP, PX4IO_P_SETUP_FEATURES, 0, PX4IO_P_SETUP_FEATURES_SBUS2_OUT); + } else { + /* disable S.BUS */ + (void)io_reg_modify(PX4IO_PAGE_SETUP, PX4IO_P_SETUP_FEATURES, (PX4IO_P_SETUP_FEATURES_SBUS1_OUT | PX4IO_P_SETUP_FEATURES_SBUS2_OUT), 0); + } + } } } From ff360aa75a5383a307397915eff2531566c5da2d Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Mon, 10 Aug 2015 16:34:47 +0200 Subject: [PATCH 03/14] NuttX configs: Add hotfix for RX DMA buffer sizes --- nuttx-configs/aerocore/nsh/defconfig | 2 ++ nuttx-configs/px4-stm32f4discovery/nsh/defconfig | 2 ++ nuttx-configs/px4fmu-v2/nsh/defconfig | 2 ++ 3 files changed, 6 insertions(+) diff --git a/nuttx-configs/aerocore/nsh/defconfig b/nuttx-configs/aerocore/nsh/defconfig index e314bf1d82..655dd1406e 100644 --- a/nuttx-configs/aerocore/nsh/defconfig +++ b/nuttx-configs/aerocore/nsh/defconfig @@ -268,6 +268,8 @@ CONFIG_STM32_USART=y # # U[S]ART Configuration # +# Hot fix for lost data +CONFIG_STM32_RXDMA_BUFFER_SIZE_OVERRIDE=256 # CONFIG_USART1_RS485 is not set CONFIG_USART1_RXDMA=y # CONFIG_USART2_RS485 is not set diff --git a/nuttx-configs/px4-stm32f4discovery/nsh/defconfig b/nuttx-configs/px4-stm32f4discovery/nsh/defconfig index 03092256e9..7be5399629 100644 --- a/nuttx-configs/px4-stm32f4discovery/nsh/defconfig +++ b/nuttx-configs/px4-stm32f4discovery/nsh/defconfig @@ -263,6 +263,8 @@ CONFIG_STM32_USART=y # # U[S]ART Configuration # +# Hot fix for lost data +CONFIG_STM32_RXDMA_BUFFER_SIZE_OVERRIDE=256 # CONFIG_USART2_RS485 is not set CONFIG_USART2_RXDMA=y # CONFIG_USART6_RS485 is not set diff --git a/nuttx-configs/px4fmu-v2/nsh/defconfig b/nuttx-configs/px4fmu-v2/nsh/defconfig index ef9c673785..e828e42be0 100644 --- a/nuttx-configs/px4fmu-v2/nsh/defconfig +++ b/nuttx-configs/px4fmu-v2/nsh/defconfig @@ -294,6 +294,8 @@ CONFIG_STM32_USART=y # # U[S]ART Configuration # +# Hot fix for lost data +CONFIG_STM32_RXDMA_BUFFER_SIZE_OVERRIDE=256 # CONFIG_USART1_RS485 is not set CONFIG_USART1_RXDMA=y # CONFIG_USART2_RS485 is not set From 138daf3b36a99c19cd90fea2ef45e3319b76152f Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Mon, 10 Aug 2015 16:35:10 +0200 Subject: [PATCH 04/14] FMUv1: Use small buffer for RX DMA hotfix --- nuttx-configs/px4fmu-v1/nsh/defconfig | 2 ++ 1 file changed, 2 insertions(+) diff --git a/nuttx-configs/px4fmu-v1/nsh/defconfig b/nuttx-configs/px4fmu-v1/nsh/defconfig index 2c9a21f212..874615d3b2 100644 --- a/nuttx-configs/px4fmu-v1/nsh/defconfig +++ b/nuttx-configs/px4fmu-v1/nsh/defconfig @@ -260,6 +260,8 @@ CONFIG_STM32_USART=y # # U[S]ART Configuration # +# Hot fix for lost data +CONFIG_STM32_RXDMA_BUFFER_SIZE_OVERRIDE=64 # CONFIG_USART1_RS485 is not set # CONFIG_USART1_RXDMA is not set # CONFIG_USART2_RS485 is not set From 05d752ae3426649252531c216ed5a4572c245145 Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Mon, 10 Aug 2015 17:07:11 +0200 Subject: [PATCH 05/14] MAVLink: Limit use to 3 instances, which is what is realistically being used. --- src/modules/mavlink/mavlink_main.cpp | 6 ++++++ src/modules/mavlink/module.mk | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/modules/mavlink/mavlink_main.cpp b/src/modules/mavlink/mavlink_main.cpp index 1e0b3ddb3e..f2dcd33d79 100644 --- a/src/modules/mavlink/mavlink_main.cpp +++ b/src/modules/mavlink/mavlink_main.cpp @@ -1789,6 +1789,12 @@ Mavlink::start(int argc, char *argv[]) // before returning to the shell int ic = Mavlink::instance_count(); + if (ic == MAVLINK_COMM_NUM_BUFFERS) { + warnx("Maximum MAVLink instance count of %d reached.", + (int)MAVLINK_COMM_NUM_BUFFERS); + return 1; + } + // Instantiate thread char buf[24]; sprintf(buf, "mavlink_if%d", ic); diff --git a/src/modules/mavlink/module.mk b/src/modules/mavlink/module.mk index e82b8bd935..509fd9e495 100644 --- a/src/modules/mavlink/module.mk +++ b/src/modules/mavlink/module.mk @@ -53,6 +53,6 @@ MAXOPTIMIZATION = -Os MODULE_STACKSIZE = 1200 -EXTRACXXFLAGS = -Weffc++ -Wno-attributes -Wno-packed +EXTRACXXFLAGS = -Weffc++ -Wno-attributes -Wno-packed -DMAVLINK_COMM_NUM_BUFFERS=3 -EXTRACFLAGS = -Wno-packed +EXTRACFLAGS = -Wno-packed -DMAVLINK_COMM_NUM_BUFFERS=3 From cab6d8b77090eca7484c913da81a5b64478304f0 Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Mon, 10 Aug 2015 17:07:30 +0200 Subject: [PATCH 06/14] System lib: Remove unused variable from CPU load tracking --- src/modules/systemlib/cpuload.c | 4 ---- src/modules/systemlib/cpuload.h | 1 - 2 files changed, 5 deletions(-) diff --git a/src/modules/systemlib/cpuload.c b/src/modules/systemlib/cpuload.c index b41896abd9..ffbeb608b5 100644 --- a/src/modules/systemlib/cpuload.c +++ b/src/modules/systemlib/cpuload.c @@ -78,8 +78,6 @@ void cpuload_initialize_once() system_load.tasks[i].valid = false; } - uint64_t now = hrt_absolute_time(); - int static_tasks_count = 2; // there are at least 2 threads that should be initialized statically - "idle" and "init" #ifdef CONFIG_PAGING @@ -94,7 +92,6 @@ void cpuload_initialize_once() // perform static initialization of "system" threads for (system_load.total_count = 0; system_load.total_count < static_tasks_count; system_load.total_count++) { - system_load.tasks[system_load.total_count].start_time = now; system_load.tasks[system_load.total_count].total_runtime = 0; system_load.tasks[system_load.total_count].curr_start_time = 0; system_load.tasks[system_load.total_count].tcb = sched_gettcb( @@ -111,7 +108,6 @@ void sched_note_start(FAR struct tcb_s *tcb) for (i = 1; i < CONFIG_MAX_TASKS; i++) { if (!system_load.tasks[i].valid) { /* slot is available */ - system_load.tasks[i].start_time = hrt_absolute_time(); system_load.tasks[i].total_runtime = 0; system_load.tasks[i].curr_start_time = 0; system_load.tasks[i].tcb = tcb; diff --git a/src/modules/systemlib/cpuload.h b/src/modules/systemlib/cpuload.h index 16d132fdb8..adc60671ec 100644 --- a/src/modules/systemlib/cpuload.h +++ b/src/modules/systemlib/cpuload.h @@ -42,7 +42,6 @@ __BEGIN_DECLS struct system_load_taskinfo_s { uint64_t total_runtime; ///< Runtime since start (start_time - total_runtime)/(start_time - current_time) = load uint64_t curr_start_time; ///< Start time of the current scheduling slot - uint64_t start_time; ///< FIRST start time of task FAR struct tcb_s *tcb; ///< bool valid; ///< Task is currently active / valid }; From f7ef77371e8d014ffa09e6f5b4c985553eef92ad Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Mon, 10 Aug 2015 17:13:20 +0200 Subject: [PATCH 07/14] Fix startup order of FLOW sensor --- ROMFS/px4fmu_common/init.d/rc.sensors | 5 ----- ROMFS/px4fmu_common/init.d/rcS | 5 +++++ 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ROMFS/px4fmu_common/init.d/rc.sensors b/ROMFS/px4fmu_common/init.d/rc.sensors index e5d527dd71..718a5e8212 100644 --- a/ROMFS/px4fmu_common/init.d/rc.sensors +++ b/ROMFS/px4fmu_common/init.d/rc.sensors @@ -110,11 +110,6 @@ else fi fi -# Check for flow sensor -if px4flow start & -then -fi - if ll40ls start then fi diff --git a/ROMFS/px4fmu_common/init.d/rcS b/ROMFS/px4fmu_common/init.d/rcS index dfa270b048..1c9fd9445b 100644 --- a/ROMFS/px4fmu_common/init.d/rcS +++ b/ROMFS/px4fmu_common/init.d/rcS @@ -708,6 +708,11 @@ fi # Boot is complete, inform MAVLink app(s) that the system is now fully up and running mavlink boot_complete +# Check for flow sensor - as it is a background task, launch it last +if px4flow start & +then +fi + if [ $EXIT_ON_END == yes ] then echo "Exit from nsh" From 7052ddf3db01a95bb85b5689974baa05f9e797b5 Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Mon, 10 Aug 2015 17:14:36 +0200 Subject: [PATCH 08/14] Q Att estimator: Remove excessive stack use --- src/modules/attitude_estimator_q/attitude_estimator_q_main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/attitude_estimator_q/attitude_estimator_q_main.cpp b/src/modules/attitude_estimator_q/attitude_estimator_q_main.cpp index a1c56aa1f8..53c81b64cd 100644 --- a/src/modules/attitude_estimator_q/attitude_estimator_q_main.cpp +++ b/src/modules/attitude_estimator_q/attitude_estimator_q_main.cpp @@ -205,7 +205,7 @@ int AttitudeEstimatorQ::start() { _control_task = task_spawn_cmd("attitude_estimator_q", SCHED_DEFAULT, SCHED_PRIORITY_MAX - 5, - 2500, + 2000, (main_t)&AttitudeEstimatorQ::task_main_trampoline, nullptr); From 825880ab5505d5a36e5772c3291ab916347269d4 Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Mon, 10 Aug 2015 22:26:09 +0200 Subject: [PATCH 09/14] Only start PX4FLOW driver on FMUv2 --- ROMFS/px4fmu_common/init.d/rcS | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/ROMFS/px4fmu_common/init.d/rcS b/ROMFS/px4fmu_common/init.d/rcS index 1c9fd9445b..ff873adac0 100644 --- a/ROMFS/px4fmu_common/init.d/rcS +++ b/ROMFS/px4fmu_common/init.d/rcS @@ -705,12 +705,17 @@ then # End of autostart fi +# There is no further script processing, so we can free some RAM +# XXX potentially unset all script variables. +unset TUNE_ERR + # Boot is complete, inform MAVLink app(s) that the system is now fully up and running mavlink boot_complete -# Check for flow sensor - as it is a background task, launch it last -if px4flow start & +if ver hwcmp PX4FMU_V2 then + # Check for flow sensor - as it is a background task, launch it last + px4flow start & fi if [ $EXIT_ON_END == yes ] @@ -719,7 +724,3 @@ then exit fi unset EXIT_ON_END - -# There is no further processing, so we can free some RAM -# XXX potentially unset all script variables. -unset TUNE_ERR From 134c1d991a6a003f5079d84b8a623f6f703cc2e1 Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Tue, 11 Aug 2015 09:24:13 +0200 Subject: [PATCH 10/14] Commander: Time out if not starting successfully --- src/modules/commander/commander.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/modules/commander/commander.cpp b/src/modules/commander/commander.cpp index 57e175ed19..a01b33087f 100644 --- a/src/modules/commander/commander.cpp +++ b/src/modules/commander/commander.cpp @@ -275,7 +275,7 @@ int commander_main(int argc, char *argv[]) if (!strcmp(argv[1], "start")) { if (thread_running) { - warnx("commander already running"); + warnx("already running"); /* this is not an error */ exit(0); } @@ -288,11 +288,18 @@ int commander_main(int argc, char *argv[]) commander_thread_main, (argv) ? (char * const *)&argv[2] : (char * const *)NULL); - while (!thread_running) { - usleep(200); + unsigned constexpr max_wait_us = 1000000; + unsigned constexpr max_wait_steps = 2000; + + unsigned i; + for (i = 0; i < max_wait_steps; i++) { + usleep(max_wait_us / max_wait_steps); + if (thread_running) { + break; + } } - exit(0); + exit(!(i < max_wait_steps)); } if (!strcmp(argv[1], "stop")) { From c8ca147b4d06edaec12ecd3140c24a7ddfa2a739 Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Tue, 11 Aug 2015 09:24:21 +0200 Subject: [PATCH 11/14] sdlog2: Waiting for full boot --- src/modules/sdlog2/sdlog2.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/modules/sdlog2/sdlog2.c b/src/modules/sdlog2/sdlog2.c index bedd854af6..71ac96350a 100644 --- a/src/modules/sdlog2/sdlog2.c +++ b/src/modules/sdlog2/sdlog2.c @@ -344,7 +344,20 @@ int sdlog2_main(int argc, char *argv[]) 3000, sdlog2_thread_main, (char * const *)argv); - exit(0); + + /* wait for the task to launch */ + unsigned const max_wait_us = 1000000; + unsigned const max_wait_steps = 2000; + + unsigned i; + for (i = 0; i < max_wait_steps; i++) { + usleep(max_wait_us / max_wait_steps); + if (thread_running) { + break; + } + } + + exit(!(i < max_wait_steps)); } if (!strcmp(argv[1], "stop")) { @@ -1228,8 +1241,6 @@ int sdlog2_thread_main(int argc, char *argv[]) /* close stdout */ close(1); - thread_running = true; - /* initialize thread synchronization */ pthread_mutex_init(&logbuffer_mutex, NULL); pthread_cond_init(&logbuffer_cond, NULL); @@ -1263,6 +1274,9 @@ int sdlog2_thread_main(int argc, char *argv[]) sdlog2_start_log(); } + /* running, report */ + thread_running = true; + while (!main_thread_should_exit) { usleep(sleep_delay); From 72c3f4b815da5ae2a3554d79a866a0336b4a5d43 Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Tue, 11 Aug 2015 09:24:56 +0200 Subject: [PATCH 12/14] Flow: Shrink boot handler size --- src/drivers/px4flow/module.mk | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/drivers/px4flow/module.mk b/src/drivers/px4flow/module.mk index ecd3e804a1..8d6964d103 100644 --- a/src/drivers/px4flow/module.mk +++ b/src/drivers/px4flow/module.mk @@ -41,4 +41,6 @@ SRCS = px4flow.cpp MAXOPTIMIZATION = -Os +MODULE_STACKSIZE = 1200 + EXTRACXXFLAGS = -Wno-attributes From f57d09aca0f9bccf48ecbada421db14edff05dd1 Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Tue, 11 Aug 2015 09:45:49 +0200 Subject: [PATCH 13/14] FMUv1: Do not load AUX outputs --- ROMFS/px4fmu_common/init.d/rc.interface | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ROMFS/px4fmu_common/init.d/rc.interface b/ROMFS/px4fmu_common/init.d/rc.interface index f3761200a1..e305713377 100644 --- a/ROMFS/px4fmu_common/init.d/rc.interface +++ b/ROMFS/px4fmu_common/init.d/rc.interface @@ -97,6 +97,12 @@ then fi fi +# This is a FMUv2+ thing +if ver hwcmp PX4FMU_V1 +then + set MIXER_AUX none +fi + if [ $MIXER_AUX != none ] then # From fc4754f8e597dfeaae6780c0b164edf928916968 Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Tue, 11 Aug 2015 10:43:54 +0200 Subject: [PATCH 14/14] Updated MAVLink submodule --- mavlink/include/mavlink/v1.0 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mavlink/include/mavlink/v1.0 b/mavlink/include/mavlink/v1.0 index 645a0e1b1e..d23a551e10 160000 --- a/mavlink/include/mavlink/v1.0 +++ b/mavlink/include/mavlink/v1.0 @@ -1 +1 @@ -Subproject commit 645a0e1b1eb09efeeaa14cc18d2474628a31ab53 +Subproject commit d23a551e108d92c7a49a66d162cb9d542bbe6be1