0

我使用cuav nora和 PX4 作为我的飞行控制。我按照官方指南设置我的工具链并构建我的第一个应用程序(链接:https ://docs.px4.io/master/en/modules/hello_sky.html )。成功了!

但是当我想驾驶我的 RoboMaster C610 ECS 时。我发现它需要can bus来做。飞控具有物理CAN总线接口。但是,我找不到可以指导我如何编写 PX4 应用程序来驱动我的 RM C610 ECS 的参考资料。换句话说,我不知道如何编写代码来使用PX4中的UAVCAN或CAN。

我试图像官方指南一样编写这些代码。


#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#include <unistd.h>

#include <px4_platform_common/px4_config.h>
#include <px4_platform_common/tasks.h>
#include <px4_platform_common/posix.h>
#include <uORB/uORB.h>
#include <uORB/topics/vehicle_acceleration.h>
#include <uORB/topics/vehicle_attitude.h>

#include "chip.h"
#include "nvic.h"

#include "uavcan.h"
#include "can.h"




void can_test(){
    uint32_t id = 0;
    
    uint32_t length = 8;
    
    uint8_t payload[CanPayloadLength];
    payload[0] = 50;
    payload[1] = 50;
    payload[2] = 50;
    payload[3] = 50;
    payload[4] = 50;
    payload[5] = 50;
    payload[6] = 50;
    payload[7] = 0;     // protocol.tail_init.u8

    uint8_t mailbox = 0;

    can_tx(id, length, frame_data, mailbox);
}


__EXPORT int can_verification_app_main(int argc, char *argv[]);

int can_verification_app_main(int argc, char *argv[])
{
    PX4_INFO("TEST uavcan and can:");
    
    // CAN 部分
    
    can_test();
    

    PX4_INFO("exiting");

    return 0;
}

这是我的 CMakeLists.txt

px4_add_module(
    MODULE examples__can_verification_app
    MAIN can_verification_app
    SRCS
        can_verification_app.cpp
    DEPENDS
    )

但它告诉我这个错误。

[1096/1347] Building CXX object src/examples/can_...verification_app.dir/can_verification_app.cpp.obj
FAILED: src/examples/can_verification_app/CMakeFiles/examples__can_verification_app.dir/can_verification_app.cpp.obj 
/usr/bin/ccache /opt/gcc-arm-none-eabi-9-2020-q2-update/bin/arm-none-eabi-g++  -DCONFIG_ARCH_BOARD_CUAV_NORA -DMODULE_NAME=\"can_verification_app\" -DPX4_MAIN=can_verification_app_app_main -D_SYS_CDEFS_H_ -D_SYS_REENT_H_ -D__CUSTOM_FILE_IO__ -D__PX4_NUTTX -D__STDC_FORMAT_MACROS -isystem ../../platforms/nuttx/NuttX/include/cxx -isystem NuttX/nuttx/include/cxx -isystem NuttX/nuttx/include -I../../boards/cuav/nora/src -I../../platforms/nuttx/src/px4/common/include -I. -Isrc/lib -I../../platforms/nuttx/src/px4/stm/stm32h7/include -I../../platforms/common -I../../platforms/common/include -I../../src -I../../src/include -I../../src/lib -I../../src/lib/matrix -I../../src/modules -INuttX/nuttx/arch/arm/src/armv7-m -INuttX/nuttx/arch/arm/src/chip -INuttX/nuttx/arch/arm/src/common -INuttX/apps/include -Iexternal/Install/include -mcpu=cortex-m7 -mthumb -mfpu=fpv5-d16 -mfloat-abi=hard -Os -DNDEBUG   -g -fdata-sections -ffunction-sections -fomit-frame-pointer -fmerge-all-constants -fno-signed-zeros -fno-trapping-math -freciprocal-math -fno-math-errno -fno-strict-aliasing -fvisibility=hidden -include visibility.h -Wall -Wextra -Werror -Warray-bounds -Wcast-align -Wdisabled-optimization -Wdouble-promotion -Wfatal-errors -Wfloat-equal -Wformat-security -Winit-self -Wlogical-op -Wpointer-arith -Wshadow -Wuninitialized -Wunknown-pragmas -Wunused-variable -Wno-missing-field-initializers -Wno-missing-include-dirs -Wno-unused-parameter -fdiagnostics-color=always -Wno-stringop-truncation -fno-builtin-printf -fno-strength-reduce -Wformat=1 -Wunused-but-set-variable -Wno-format-truncation -fcheck-new -fno-exceptions -fno-rtti -fno-threadsafe-statics -Wreorder -Wno-overloaded-virtual -nostdinc++ -fno-sized-deallocation -Wframe-larger-than=2048 -std=gnu++14 -MD -MT src/examples/can_verification_app/CMakeFiles/examples__can_verification_app.dir/can_verification_app.cpp.obj -MF src/examples/can_verification_app/CMakeFiles/examples__can_verification_app.dir/can_verification_app.cpp.obj.d -o src/examples/can_verification_app/CMakeFiles/examples__can_verification_app.dir/can_verification_app.cpp.obj -c ../../src/examples/can_verification_app/can_verification_app.cpp
../../src/examples/can_verification_app/can_verification_app.cpp:63:10: fatal error: uavcan.h: No such file or directory
   63 | #include "uavcan.h"
      |          ^~~~~~~~~~
compilation terminated.
[1097/1347] Building CXX object src/systemcmds/to...ds__topic_listener.dir/listener_generated.cpp.obj
ninja: build stopped: subcommand failed.
Makefile:219: recipe for target 'cuav_nora_default' failed
make: *** [cuav_nora_default] Error 1

你能给我看一些代码或者给我一些这个问题的链接吗?在 PX4 中使用 UAVCAN 或 CAN。谢谢。

4

0 回答 0