当前位置:网站首页>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 命令,看看给出的那一堆里面有没有你新建的那个

有的话,直接敲进去这一句,看看输出结果吧
执行完毕~
边栏推荐
- Establishment of FTP server
- 装饰器函数与类装饰器的使用
- Basic knowledge of English: Rules for the use of non predicates Part 1
- Interpretation of unity desktop version 7.6
- logging日志的封装
- Shell语句判断练习题
- 账号管理与权限
- Selenium knowledge points
- Linu性能调优:面对DDOS攻击,我们如何缓解局面?
- Shell script delete automatically clean up files that exceed the size
猜你喜欢
随机推荐
Iptables firewall, SNAT and DNAT
源码编译安装LNMP和DISCUZ论坛
哈希表简介
Vscode solves the problem of using stuck ipynb files when running
DHCP的概念和原理
Bug classification and defect and CSV file testing
数组及下标索引
Interpretation of unity desktop version 7.6
shell--条件语句(if语句、case语句)
Open source WebGIS related knowledge
项目实训经历2
DHCP原理与配置
面试常问的问题总结【呕心沥血熬了一个晚上总结的】
1. CentOS 7 安装 redis
Network troubleshooting: Ping and tracert commands
Briefly remember the top ten orders
shell函数
If conditional statement of shell
接口测试概念及Postman工具简介使用
DHCP principle and configuration









