espressif/esp-drone

Simple code did not work

yuanyanhui opened this issue · 9 comments

I cloned the repo, complied and flashed the code without any modifications. Everything was okay. I then added some code to try hovering using the flow deck. Compilation and flashing all went well, but ESP32 kept panic rebooting.

`#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/portmacro.h"
#include "nvs_flash.h"

#include "stm32_legacy.h"
#include "platform.h"
#include "system.h"
#define DEBUG_MODULE "APP_MAIN"
#include "debug_cf.h"
#include "commander.h"

static void positionSet(setpoint_t *setpoint, float x, float y, float z, float yaw)
{
// memset(setpoint, 0, sizeof(setpoint_t));

setpoint->mode.x = modeAbs;
setpoint->mode.y = modeAbs;
setpoint->mode.z = modeAbs;

setpoint->position.x = x;
setpoint->position.y = y;
setpoint->position.z = z;

setpoint->mode.yaw = modeAbs;

setpoint->attitude.yaw = yaw;

}

void app_main()
{
/*
* Initialize the platform and Launch the system task
* app_main will initialize and start everything
/
static setpoint_t setpoint;
/
initialize nvs flash prepare for Wi-Fi */
esp_err_t ret = nvs_flash_init();

if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND)
{
    ESP_ERROR_CHECK(nvs_flash_erase());
    ret = nvs_flash_init();
}

ESP_ERROR_CHECK(ret);

/*Initialize the platform.*/
if (platformInit() == false)
{
    while (1)
        ; // if  firmware is running on the wrong hardware, Halt
}

/*launch the system task */
systemLaunch();

while (1)
{
    vTaskDelay(M2T(10));
    positionSet(&setpoint, 0, 0, 1, 0);
    commanderSetSetpoint(&setpoint, 3);
}

}`

ELF file SHA256: dbdb58b15d686f3a

Rebooting...
ESP-ROM:esp32s2-rc4-20191025
Build:Oct 25 2019
rst:0xc (RTC_SW_CPU_RST),boot:0x9 (SPI_FAST_FLASH_BOOT)
Saved PC:0x4002411a
0x4002411a: esp_restart_noos at E:/ESP32/esp-idf/components/esp32s2/system_api_esp32s2.c:109 (discriminator 1)

SPIWP:0xee
mode:DIO, clock div:1
load:0x3ffe6100,len:0x1944
load:0x4004c000,len:0xc9c
load:0x40050000,len:0x2ce0
entry 0x4004c21c
I (24) boot: ESP-IDF v4.3.1-dirty 2nd stage bootloader
I (24) boot: compile time 15:11:17
I (24) boot: chip revision: 0
I (27) qio_mode: Enabling default flash chip QIO
I (32) boot.esp32s2: SPI Speed : 80MHz
I (37) boot.esp32s2: SPI Mode : QIO
I (41) boot.esp32s2: SPI Flash Size : 4MB
I (46) boot: Enabling RNG early entropy source...
I (52) boot: Partition Table:
I (55) boot: ## Label Usage Type ST Offset Length
I (62) boot: 0 nvs WiFi data 01 02 00009000 00006000
I (70) boot: 1 phy_init RF data 01 01 0000f000 00001000
I (77) boot: 2 factory factory app 00 00 00010000 00100000
I (85) boot: End of partition table
I (89) esp_image: segment 0: paddr=00010020 vaddr=3f000020 size=1c2ech (115436) map
I (117) esp_image: segment 1: paddr=0002c314 vaddr=3ffc7f60 size=03d04h ( 15620) load
I (121) esp_image: segment 2: paddr=00030020 vaddr=40080020 size=7f08ch (520332) map
I (212) esp_image: segment 3: paddr=000af0b4 vaddr=3ffcbc64 size=00c08h ( 3080) load
I (213) esp_image: segment 4: paddr=000afcc4 vaddr=40022000 size=15f58h ( 89944) load
I (238) esp_image: segment 5: paddr=000c5c24 vaddr=50000000 size=00010h ( 16) load
I (249) boot: Loaded app from partition at offset 0x10000
I (249) boot: Disabling RNG early entropy source...
I (261) cache: Instruction cache : size 8KB, 4Ways, cache line size 32Byte
I (261) cpu_start: Pro cpu up.
I (274) cpu_start: Pro cpu start user code
I (274) cpu_start: cpu freq: 240000000
I (275) cpu_start: Application information:
I (279) cpu_start: Project name: ESPDrone
I (284) cpu_start: App version: cc41b33-dirty
I (290) cpu_start: Compile time: Dec 13 2021 15:10:16
I (296) cpu_start: ELF file SHA256: dbdb58b15d686f3a...
I (302) cpu_start: ESP-IDF: v4.3.1-dirty
I (307) heap_init: Initializing. RAM available for dynamic allocation:
I (314) heap_init: At 3FF9E000 len 00002000 (8 KiB): RTCRAM
I (321) heap_init: At 3FFDE020 len 0001DFE0 (119 KiB): DRAM
I (327) heap_init: At 3FFFC000 len 00003A10 (14 KiB): DRAM
I (333) spi_flash: detected chip: generic
I (338) spi_flash: flash io: qio
I (345) cpu_start: Starting scheduler on PRO CPU.
I (360) PLATFORM: set active config
I (360) gpio: GPIO[7]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
I (367) gpio: GPIO[8]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
I (376) gpio: GPIO[9]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
I (387) wifi:wifi driver task: 3ffe5c00, prio:23, stack:6656, core=0
I (392) system_api: Base MAC address is not set
I (397) system_api: read default base MAC address from EFUSE
I (407) wifi:wifi firmware version: 88c8747
I (407) wifi:wifi certification version: v7.0
I (411) wifi:config NVS flash: enabled
I (414) wifi:config nano formating: disabled
I (418) wifi:Init data frame dynamic rx buffer num: 32
I (423) wifi:Init management frame dynamic rx buffer num: 32
I (429) wifi:Init management short buffer num: 32
I (433) wifi:Init dynamic tx buffer num: 32
I (437) wifi:Init static rx buffer size: 1600
I (441) wifi:Init static rx buffer num: 10
I (445) wifi:Init dynamic rx buffer num: 32
I (449) wifi_init: rx ba win: 6
I (453) wifi_init: tcpip mbox: 32
I (457) wifi_init: udp mbox: 6
I (460) wifi_init: tcp mbox: 6
I (464) wifi_init: tcp tx win: 5744
I (468) wifi_init: tcp rx win: 5744
I (472) wifi_init: tcp mss: 1440
I (476) wifi_init: WiFi IRAM OP enabled
I (481) wifi_init: WiFi RX IRAM OP enabled
I (979) phy_init: phy_version 1800,e7ef680,Apr 13 2021,11:45:08
I (1062) wifi:mode : softAP (7c:df:a1:18:ad:2d)
I (1064) wifi:Total power save buffer number: 16
I (1064) wifi:Init max length of beacon: 752/752
I (1064) wifi:Init max length of beacon: 752/752
I (1070) WIFI_UDP: wifi_init_softap complete.SSID:ESP-DRONE_7CDFA118AD2D password:12345678
I (1078) WIFI_UDP: Socket created
I (1082) WIFI_UDP: Socket bound, port 2390
I (1086) WIFI_UDP: UDP server create socket succeed!!!
assertion "( pxQueue )" failed: file "E:/ESP32/esp-idf/components/freertos/queue.c", line 1656, function: xQueuePeek

abort() was called at PC 0x40019fbe on core 0

Backtrace:0x4002b3ee:0x3ffdf530 0x4002bcc5:0x3ffdf550 0x40033282:0x3ffdf570 0x40019fbe:0x3ffdf5e0 0x4001a42b:0x3ffdf600 0x4002cade:0x3ffdf630 0x400879b4:0x3ffdf670 0x400877f9:0x3ffdf6b0 0x400fedfd:0x3ffdf6d0
0x4002b3ee: panic_abort at E:/ESP32/esp-idf/components/esp_system/panic.c:379

0x4002bcc5: esp_system_abort at E:/ESP32/esp-idf/components/esp_system/system_api.c:112

0x40033282: abort at E:/ESP32/esp-idf/components/newlib/abort.c:46

0x4002cade: xQueuePeek at E:/ESP32/esp-idf/components/freertos/queue.c:1656 (discriminator
1)

0x400879b4: systemTest at E:\ESP32\esp-drone\build/../components/core/crazyflie/modules/src/system.c:159

0x400877f9: platformParseDeviceTypeString at E:\ESP32\esp-drone\build/../components/platform/platform.c:74

0x400fedfd: heap_bubble_down at E:/ESP32/esp-idf/components/log/log.c:285

After adding delay of 3 sec, the system initializes properly, however there is no response from the motors afterwards. The debug message is printed out as expected.

` /*launch the system task */
systemLaunch();

vTaskDelay(M2T(3000));

while (1)
{
    vTaskDelay(M2T(10));
    positionSet(&setpoint, 0, 0, 1, 0);
    commanderSetSetpoint(&setpoint, 3);
    DEBUG_PRINT_LOCAL("...");
}`

ESP-ROM:esp32s2-rc4-20191025
Build:Oct 25 2019
rst:0x1 (POWERON),boot:0x9 (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:DIO, clock div:1
load:0x3ffe6100,len:0x1944
load:0x4004c000,len:0xc9c
load:0x40050000,len:0x2ce0
entry 0x4004c21c
I (21) boot: ESP-IDF v4.3.1-dirty 2nd stage bootloader
I (21) boot: compile time 19:09:08
I (21) boot: chip revision: 0
I (25) qio_mode: Enabling default flash chip QIO
I (30) boot.esp32s2: SPI Speed : 80MHz
I (34) boot.esp32s2: SPI Mode : QIO
I (39) boot.esp32s2: SPI Flash Size : 4MB
I (44) boot: Enabling RNG early entropy source...
I (49) boot: Partition Table:
I (53) boot: ## Label Usage Type ST Offset Length
I (60) boot: 0 nvs WiFi data 01 02 00009000 00006000
I (68) boot: 1 phy_init RF data 01 01 0000f000 00001000
I (75) boot: 2 factory factory app 00 00 00010000 00100000
I (83) boot: End of partition table
I (87) esp_image: segment 0: paddr=00010020 vaddr=3f000020 size=1c314h (115476) map
I (115) esp_image: segment 1: paddr=0002c33c vaddr=3ffc7f60 size=03cdch ( 15580) load
I (118) esp_image: segment 2: paddr=00030020 vaddr=40080020 size=7f0b4h (520372) map
I (210) esp_image: segment 3: paddr=000af0dc vaddr=3ffcbc3c size=00c30h ( 3120) load
I (211) esp_image: segment 4: paddr=000afd14 vaddr=40022000 size=15f58h ( 89944) load
I (236) esp_image: segment 5: paddr=000c5c74 vaddr=50000000 size=00010h ( 16) load
I (247) boot: Loaded app from partition at offset 0x10000
I (247) boot: Disabling RNG early entropy source...
I (259) ca�f�~�����Սѥ���cache : size 8KB, 4Ways, cache line size 32Byte
I (259) cpu_start: Pro cpu up.
I (272) cpu_start: Pro cpu start user code
I (272) cpu_start: cpu freq: 240000000
I (272) cpu_start: Application information:
I (277) cpu_start: Project name: ESPDrone
I (282) cpu_start: App version: cc41b33-dirty
I (288) cpu_start: Compile time: Dec 13 2021 19:08:09
I (294) cpu_start: ELF file SHA256: 9f0793aa91e2a694...
I (300) cpu_start: ESP-IDF: v4.3.1-dirty
I (305) heap_init: Initializing. RAM available for dynamic allocation:
I (312) heap_init: At 3FF9E000 len 00002000 (8 KiB): RTCRAM
I (318) heap_init: At 3FFDE020 len 0001DFE0 (119 KiB): DRAM
I (325) heap_init: At 3FFFC000 len 00003A10 (14 KiB): DRAM
I (331) spi_flash: detected chip: generic
I (336) spi_flash: flash io: qio
I (343) cpu_start: Starting scheduler on PRO CPU.
I (358) PLATFORM: set active config
I (358) gpio: GPIO[7]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
I (365) gpio: GPIO[8]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
I (374) gpio: GPIO[9]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
I (385) wifi:wifi driver task: 3ffe5c00, prio:23, stack:6656, core=0
I (390) system_api: Base MAC address is not set
I (395) system_api: read default base MAC address from EFUSE
I (405) wifi:wifi firmware version: 88c8747
I (405) wifi:wifi certification version: v7.0
I (409) wifi:config NVS flash: enabled
I (412) wifi:config nano formating: disabled
I (416) wifi:Init data frame dynamic rx buffer num: 32
I (421) wifi:Init management frame dynamic rx buffer num: 32
I (427) wifi:Init management short buffer num: 32
I (431) wifi:Init dynamic tx buffer num: 32
I (435) wifi:Init static rx buffer size: 1600
I (439) wifi:Init static rx buffer num: 10
I (443) wifi:Init dynamic rx buffer num: 32
I (447) wifi_init: rx ba win: 6
I (451) wifi_init: tcpip mbox: 32
I (455) wifi_init: udp mbox: 6
I (458) wifi_init: tcp mbox: 6
I (462) wifi_init: tcp tx win: 5744
I (466) wifi_init: tcp rx win: 5744
I (470) wifi_init: tcp mss: 1440
I (474) wifi_init: WiFi IRAM OP enabled
I (479) wifi_init: WiFi RX IRAM OP enabled
I (957) phy_init: phy_version 1800,e7ef680,Apr 13 2021,11:45:08
I (1041) wifi:mode : softAP (7c:df:a1:18:ad:2d)
I (1043) wifi:Total power save buffer number: 16
I (1043) wifi:Init max length of beacon: 752/752
I (1044) wifi:Init max length of beacon: 752/752
I (1050) WIFI_UDP: wifi_init_softap complete.SSID:ESP-DRONE_7CDFA118AD2D password:12345678
I (1057) WIFI_UDP: Socket created
I (1061) WIFI_UDP: Socket bound, port 2390
I (1066) WIFI_UDP: UDP server create socket succeed!!!
I (1571) SYS: ----------------------------

I (1571) SYS: ESPlane 2.0 is up and running!

I (1571) I2CDRV: i2c 1 driver install return = 0
I (1575) EEPROM: spi_flash_init ... !
I (1579) EEPROM: spi_flash_read ok !
eFuse Two Point: Supported
Characterized using Two Point Value
I (2397) I2CDRV: i2c 0 driver install return = 0
I (2397) SENSORS: MPU6050 I2C connection [OK].

I (2764) ZR2: Z-down sensor [OK]

I (2764) SENSORS: VL53L1X I2C connection [OK].

I (2764) gpio: GPIO[34]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
I (2868) MODE: FlightMode = 2
I (2868) SENSORS: PMW3901 SPI connection [OK].

I (2868) SENSORS: sensors init done
I (2870) SENSORS: pitch_calib = 0.000000,roll_calib = 0.000000
I (2877) gpio: GPIO[12]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:1
I (2886) ESTIMATOR: Using Kalman (2) estimator

I (2892) POSITION_CONTROLLER: thrustBase = 24000,thrustMin = 5000
I (2899) SYS: wifilinkTest = 1
I (3402) SYS: pmTest = 1
I (3402) SYS: workerTest = 1
I (3402) SYS: systemTest = 1
I (3402) SYS: configblockTest = 1
I (3405) COMM: wifilinkTest = 1
I (3409) COMM: crtpTest = 1
I (3413) COMM: crtpserviceTest = 1
I (3417) COMM: platformserviceTest = 1
I (3421) COMM: consoleTest = 1
I (3425) COMM: paramTest = 1
I (3429) SYS: commTest = 1
I (3432) SYS: commanderTest = 1
I (5250) SYS: stabilizerTest = 1
I (5250) SYS: estimatorKalmanTaskTest = 1
I (5250) SYS: memTest = 1
I (5251) STAB: Wait for sensor calibration...

I (5256) SYS: systemStart ! selftestPassed = 1
I (5394) APP_MAIN: ...
I (5404) APP_MAIN: ...
....................................
I (6455) APP_MAIN: ...
I (6465) APP_MAIN: ...
I (6475) APP_MAIN: ...
I (6482) SENSORS: isBiasValueFound!
I (6483) STAB: Ready to fly.

...............................................
I (6518) APP_MAIN: ...
I (6528) APP_MAIN: ...
I (6538) APP_MAIN: ...
I (6548) APP_MAIN: ...
I (6558) APP_MAIN: ...
I (6571) APP_MAIN: ...
I (6573) SYSLOAD: Task dump

I (6575) SYSLOAD: Load Stack left Name PRI

I (6579) SYSLOAD: 0.15 1632 Tmr Svc 1

I (6581) APP_MAIN: ...
I (6582) SYSLOAD: 0.37 1560 KALMAN 1

I (6590) SYSLOAD: 67.68 1208 IDLE 0

I (6595) APP_MAIN: ...
I (6595) SYSLOAD: 0.25 1516 PWRMGNT 0

I (6600) SYSLOAD: 0.64 960 FLOW 3

I (6605) SYSLOAD: 0.20 644 UDP_TX 3

I (6605) APP_MAIN: ...
I (6609) SYSLOAD: 0.45 2384 main 1

I (6616) SYSLOAD: 0.01 2760 CRTP-RX 2

I (6621) SYSLOAD: 0.04 2576 tiT 18

I (6626) SYSLOAD: 3.25 980 SENSORS 4

I (6623) APP_MAIN: ...
I (6632) SYSLOAD: 1.62 860 ZRANGER2 2

I (6640) SYSLOAD: 0.00 1484 UDP_RX 3

I (6642) SYSLOAD: 0.00 232 WIFILINK 3

I (6643) APP_MAIN: ...
I (6650) SYSLOAD: 0.00 744 CRTP-TX 2

I (6662) SYSLOAD: 0.00 1224 LOG 2

I (6664) SYSLOAD: 0.00 724 PARAM 2

I (6666) APP_MAIN: ...
I (6670) SYSLOAD: 0.00 680 CMDHL 2

I (6676) SYSLOAD: 3.40 892 SYSTEM 2

I (6682) SYSLOAD: 12.36 3604 esp_timer 22

I (6684) APP_MAIN: ...
I (6686) SYSLOAD: 8.96 4644 wifi 23

I (6690) SYSLOAD: 0.00 576 LEDSEQCMD 1

I (6696) APP_MAIN: ...
I (6697) SYSLOAD: 0.59 984 STABILIZER 5

I (6704) SYSLOAD: 0.00 2108 sys_evt 20

I (6709) SYSLOAD: Free heap: 59892 bytes

I (6710) APP_MAIN: ...
I (6726) APP_MAIN: ...
I (6739) APP_MAIN: ...
I (6752) APP_MAIN: ...
I (6764) APP_MAIN: ...
I (6776) APP_MAIN: ...
I (6788) APP_MAIN: ...

Checked the outputs (z, vx, vy) of the flow deck which looked quite normal. The drone still could not take off. After initialization, the motors accelerated for 1 second to a high velocity and then stopped.

@yuanyanhui Please test with the esp-drone APP for your first flight

Tried the phone app. When thrust was increased to about 50%, motors shut off and I had to manually reset to reconnect again. Not sure if this is a hardware problem.

@yuanyanhui The battery voltage needs to be stable when the motor is operating, power lithium batteries are recommended.

The battery shouldn't be the problem, as it's fully charged.

There is some progress... Somehow thrust control became normal in phone app. Also found out that the Z coordinate axis actually points upward, so to set hovering height, setpoint->position.z should be assigned a negative number. However, the drone still could not take off. At the beginning, all four motors were spinning. After a few seconds, one or two motors would stop. The other two or three motors kept spinning at a high speed.

About the Z coordinate axis, it seems it can only be global, as discussed here.
https://forum.bitcraze.io/viewtopic.php?p=23136&hilit=coordinate+system#p23136
https://www.bitcraze.io/documentation/system/platform/cf2-coordinate-system/

So to hover, setpoint->position.z should be positive??? Log on height measurement of flow deck is also positive.

Changed motors and propellers to 720 and 55mm. After tweaking pid and thrust parameters, the drone could hover. Position z was set to a positive number.

Can you show the full code of the successful firmware?