当前位置:网站首页>px4源码编译之 建立自己的程序模块
px4源码编译之 建立自己的程序模块
2022-07-27 05:23:00 【星影_sysu】
前言:在网上找了一大圈,如何在px4源码examples中添加自己的程序,包括官网那个都没有用,后来发现需要在对应的编译位置对cmake文件进行修改,具体如下:
1.在你想要的位置新建文件夹,建议和你的c或者cpp文件同名,一般在module或者examples文件夹下新建你的文件夹,我是在examples下面新建的。路径为../PX4-Autopilot/src/examples/xxx
有的同学应该是../Firmware/src/examples/xxx

2.新建.c或者.cpp文件,以及CMakeLists.txt
.c或者.cpp文件 和 CMakeLists.txt的编写建议参考官网链接
First Application Tutorial (Hello Sky) | PX4 User Guide
这里贴一下我的,因为只是为了编译,内容是官网的px4_simple_app简略版
#CMakeLists.txt
px4_add_module(
MODULE examples__my_example_app
MAIN my_example_app
STACK_MAIN 200
SRCS
my_example_app.c
DEPENDS
)
#my_example_app.c
#include <px4_platform_common/px4_config.h>
#include <px4_platform_common/tasks.h>
#include <px4_platform_common/posix.h>
#include <unistd.h>
#include <stdio.h>
#include <poll.h>
#include <string.h>
#include <math.h>
#include <uORB/uORB.h>
#include <uORB/topics/sensor_combined.h>
#include <uORB/topics/vehicle_attitude.h>
__EXPORT int my_example_app_main(int argc, char *argv[]);
int my_example_app_main(int argc, char *argv[])
{
PX4_INFO("Hello Sky!");
PX4_INFO("exiting");
return OK;
}3.之前最困扰的地方,由于很多教程里提到去CMake文件夹下找configs文件夹,但我的有没有,所以一直编译不通过,后来根据
PX4代码学习系列博客(5)——在px4中添加自己的模块_千人斩的博客-CSDN博客
找到了对应的修改之处
(1)在PX4-Autopilot/boards/px4/sitl/default.cmake中进行修改,加上你的文件名就可以了

第一个注意如果你是编译的其他版本,那就在px4文件夹下找你的编译方式,我是软件在环仿真所以找的是sitl文件夹
第二个注意,如果你之前新建的文件夹是在modules文件夹下面,那你对应修改的的地方应该在modules下面
(2)在PX4-Autopilot/boards/px4/sitl/test.cmake中进行修改,加上你的文件名,步骤同上

4.修改完毕,保存文件后在终端打开,以运行jmavsim为例
make clean
make px4_sitl jmavsim之后执行 help 命令,看看给出的那一堆里面有没有你新建的那个

有的话,直接敲进去这一句,看看输出结果吧
执行完毕~
边栏推荐
猜你喜欢

Function call of shell script

logging日志的封装

PXE高效批量网络装机

Constraints and design of database

Joint query of database

Introduction to hash table

iptables防火墙

win10 添加虚拟网卡,配置op路由
![Summary of frequently asked questions in the interview [summarized after painstaking work all night]](/img/70/90543c23326305590242716b989643.png)
Summary of frequently asked questions in the interview [summarized after painstaking work all night]

About the use of TestNG related tags
随机推荐
Use of getattr, hasattr, delattr and setattr in reflectors
shell--条件语句(if语句、case语句)
Programming learning records - Lesson 6 [functions]
Solve the problems of CONDA install stop and interruption
Programming learning records - Lesson 5 [branch and loop statements]
Shell Function
iptables防火墙
Basic knowledge of English: Rules for the use of non predicates Part 1
DHCP原理与配置
C language -- string operation function and memory operation function
C language - Custom structure type
IP core summary
Linu性能调优:面对DDOS攻击,我们如何缓解局面?
Shell sentence judgment exercise
Decorator functions and the use of class decorators
Shell programming specification and redirection and pipeline operation
Concept and principle of DHCP
Programming learning record -- recursively solving the tower of Hanoi problem
互联网简单协议概括
Packaging of logging logs