20201015组会

frc controller

  1. 改进pid算法

blockformula_editor u[T] = K_p \cdot err[T] + K_i \cdot \Sigma _{i = 0}^{T} err[i] \cdot \Delta T[i] + K_d \cdot (err[T] - err[T - 1])

C++实现

uint32_t currTime = micros();
uint32_t dt = currTime - prevTime;
err = ref - feedback;
integral += err * (float) dt / 1000000;
output = kp * err + ki * integral + kd * (err - lastError);
lastError = err;
prevTime = currTime;

MicroPython

lib/utils/pyexec.c中有int pyexec_friendly_repl(void)函数。

qstr.h

enum {
    #ifndef NO_QSTR
#define QDEF(id, str) id,
    #include "genhdr/qstrdefs.generated.h"
#undef QDEF
    #endif
    MP_QSTRnumber_of, // no underscore so it can't clash with any of the above
};

调用gendhr/导致报错 NO_QSTR来自py/mkrules.mk

void mp_init(void) {
...
soft_reset:
    // initialise the stack pointer for the main thread
    mp_stack_set_top((void *)sp);
    mp_stack_set_limit(MP_TASK_STACK_SIZE - 1024);
    gc_init(mp_task_heap, mp_task_heap + mp_task_heap_size);
    mp_init();
    /* ----  ---- */
    // mp_obj_list_init(mp_sys_path, 0);
    // mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR_));
    // mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_lib));
    // mp_obj_list_init(mp_sys_argv, 0);
    /* ----  ---- */
    readline_init0();

...
}
C:\Users\rui\.platformio\packages\framework-espidf\components\libsodium\libsodium\src\libsodium\sodium\core.c:51:5: error: implicit declaration of function '_sodium_runtime_get_cpu_features' [-Werror=implicit-function-declaration]
     _sodium_runtime_get_cpu_features();

推测是idf版本问题

2020.10.16

发现是有个文件夹复制过来没删掉.c文件。

删除后编译出现undefined reference to 'esp_eth_enable'之类的问题,使用esp-idf 4.0重新编译后除了BLE之外还出现如下错误

undefined reference to `pppapi_pppos_create'
undefined reference to `pppapi_free'
undefined reference to `pppapi_close'
...
undefined reference to `xQueueCreateMutexStatic'

去掉BLE之后依然存在这些错误

pppapi相关函数来自network_ppp.c,用于PPPoS(PPP over Serial,GSM Modem。

port/esp32/Makefile中的SRC_C中去掉这个文件,再次编译静态库,然后在playformio中编译,剩下三个错误:

libmicropython.a(modnetwork.o):(.rodata.mp_module_network_globals_table+0x1c): undefined reference to `ppp_make_new_obj'
libmicropython.a(mpthreadport.o):(.literal.mp_thread_mutex_init+0x0): undefined reference to `xQueueCreateMutexStatic'
\libmicropython.a(mpthreadport.o): in function `mp_thread_mutex_init':
mpthreadport.c:(.text.mp_thread_mutex_init+0x7): undefined reference to `xQueueCreateMutexStatic'

modnetwork.c中引用ppp_make_new_obj,这个错误在之前有network_ppp.c的时候没有出现。应该是有依赖关系。

vscode中查找ppp_make_new_obj没找到定义。如果再把modnetwork.c去掉又会出现新的错误。所以还是把network_ppp.c加回去了。

参考Makefile把该加的头文件加上

LIB_SRC_C = $(addprefix lib/,\
	mbedtls_errors/mp_mbedtls_errors.c \
	mp-readline/readline.c \
	netutils/netutils.c \
	timeutils/timeutils.c \
	utils/pyexec.c \
	utils/interrupt_char.c \
	utils/sys_stdio_mphal.c \
	)

没变化。

ble报错的原因可能是.vscode/c_cpp_properties.json的includePath没加入.platformio/packages/framework-espidf/components/bt之类的路径,对应Makefile中的

ifeq ($(CONFIG_BT_NIMBLE_ENABLED),y)
INC_ESPCOMP += -I$(ESPCOMP)/bt/include
INC_ESPCOMP += -I$(ESPCOMP)/bt/common/osi/include
INC_ESPCOMP += -I$(ESPCOMP)/bt/common/btc/include
INC_ESPCOMP += -I$(ESPCOMP)/bt/common/include
INC_ESPCOMP += -I$(ESPCOMP)/bt/host/nimble/nimble/porting/nimble/include
INC_ESPCOMP += -I$(ESPCOMP)/bt/host/nimble/port/include
INC_ESPCOMP += -I$(ESPCOMP)/bt/host/nimble/nimble/nimble/include
INC_ESPCOMP += -I$(ESPCOMP)/bt/host/nimble/nimble/nimble/host/include
INC_ESPCOMP += -I$(ESPCOMP)/bt/host/nimble/nimble/nimble/host/services/ans/include
INC_ESPCOMP += -I$(ESPCOMP)/bt/host/nimble/nimble/nimble/host/services/bas/include
INC_ESPCOMP += -I$(ESPCOMP)/bt/host/nimble/nimble/nimble/host/services/gap/include
INC_ESPCOMP += -I$(ESPCOMP)/bt/host/nimble/nimble/nimble/host/services/gatt/include
INC_ESPCOMP += -I$(ESPCOMP)/bt/host/nimble/nimble/nimble/host/services/ias/include
INC_ESPCOMP += -I$(ESPCOMP)/bt/host/nimble/nimble/nimble/host/services/lls/include
INC_ESPCOMP += -I$(ESPCOMP)/bt/host/nimble/nimble/nimble/host/services/tps/include
INC_ESPCOMP += -I$(ESPCOMP)/bt/host/nimble/nimble/nimble/host/util/include
INC_ESPCOMP += -I$(ESPCOMP)/bt/host/nimble/nimble/nimble/host/store/ram/include
INC_ESPCOMP += -I$(ESPCOMP)/bt/host/nimble/nimble/nimble/host/store/config/include
INC_ESPCOMP += -I$(ESPCOMP)/bt/host/nimble/nimble/porting/npl/freertos/include
INC_ESPCOMP += -I$(ESPCOMP)/bt/host/nimble/nimble/ext/tinycrypt/include
INC_ESPCOMP += -I$(ESPCOMP)/bt/host/nimble/esp-hci/include
endif
ifeq ($(CONFIG_NIMBLE_ENABLED),y)
INC_ESPCOMP += -I$(ESPCOMP)/bt/include
INC_ESPCOMP += -I$(ESPCOMP)/nimble/nimble/porting/nimble/include
INC_ESPCOMP += -I$(ESPCOMP)/nimble/port/include
INC_ESPCOMP += -I$(ESPCOMP)/nimble/nimble/nimble/include
INC_ESPCOMP += -I$(ESPCOMP)/nimble/nimble/nimble/host/include
INC_ESPCOMP += -I$(ESPCOMP)/nimble/nimble/nimble/host/services/ans/include
INC_ESPCOMP += -I$(ESPCOMP)/nimble/nimble/nimble/host/services/bas/include
INC_ESPCOMP += -I$(ESPCOMP)/nimble/nimble/nimble/host/services/gap/include
INC_ESPCOMP += -I$(ESPCOMP)/nimble/nimble/nimble/host/services/gatt/include
INC_ESPCOMP += -I$(ESPCOMP)/nimble/nimble/nimble/host/services/ias/include
INC_ESPCOMP += -I$(ESPCOMP)/nimble/nimble/nimble/host/services/lls/include
INC_ESPCOMP += -I$(ESPCOMP)/nimble/nimble/nimble/host/services/tps/include
INC_ESPCOMP += -I$(ESPCOMP)/nimble/nimble/nimble/host/util/include
INC_ESPCOMP += -I$(ESPCOMP)/nimble/nimble/nimble/host/store/ram/include
INC_ESPCOMP += -I$(ESPCOMP)/nimble/nimble/nimble/host/store/config/include
INC_ESPCOMP += -I$(ESPCOMP)/nimble/nimble/porting/npl/freertos/include
INC_ESPCOMP += -I$(ESPCOMP)/nimble/nimble/ext/tinycrypt/include
INC_ESPCOMP += -I$(ESPCOMP)/nimble/esp-hci/include
endif

PPPoS相关的未定义函数似乎都来自pppapi.hpppapi.c,这两个文件来自lib/lwip/src/includelib/lwip/src/netif,相关文件都编译到了build-GENERIC/esp-idf/lwip/liblwip.a这个静态库中

$ readelf -s liblwip.a | grep "pppapi.o" -C 5
    32: 00000000    90 FUNC    GLOBAL DEFAULT   18 magic_random_bytes
    33: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND memcpy
    34: 00000000    17 FUNC    GLOBAL DEFAULT   20 magic
    35: 00000000    28 FUNC    GLOBAL DEFAULT   22 magic_pow

File: liblwip.a(pppapi.o)

Symbol table '.symtab' contains 59 entries:
   Num:    Value  Size Type    Bind   Vis      Ndx Name
     0: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND
     1: 00000000     0 FILE    LOCAL  DEFAULT  ABS pppapi.c

查看符号表

File: liblwip.a(pppapi.o)

Symbol table '.symtab' contains 59 entries:
   Num:    Value  Size Type    Bind   Vis      Ndx Name
     0: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND
     1: 00000000     0 FILE    LOCAL  DEFAULT  ABS pppapi.c
    ...
    45: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND ppp_set_auth
    46: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND pppos_create
    47: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND ppp_connect
    48: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND ppp_close
    49: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND ppp_free
    50: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND ppp_ioctl
    51: 00000000    21 FUNC    GLOBAL DEFAULT   46 pppapi_set_default
    52: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND tcpip_api_call
    53: 00000000    26 FUNC    GLOBAL DEFAULT   48 pppapi_set_auth
    54: 00000000    30 FUNC    GLOBAL DEFAULT   50 pppapi_pppos_create
    55: 00000000    25 FUNC    GLOBAL DEFAULT   52 pppapi_connect
    56: 00000000    25 FUNC    GLOBAL DEFAULT   54 pppapi_close
    57: 00000000    21 FUNC    GLOBAL DEFAULT   56 pppapi_free
    58: 00000000    26 FUNC    GLOBAL DEFAULT   58 pppapi_ioctl

修改Makefile,将ESPIDF_LWIP_O也编入静态库中


本文章使用limfx的vscode插件快速发布