示例:PX4——添加msg、uORB

2023-05-16

git clone https://github.com/PX4/Firmware

cd Firmware

git submodule update --init --recursive

git checkout v1.11.0-beta1

make distclean

在Firmware/msg/目录下添加文件test_tof.msg,内容如下

uint64 timestamp
uint32 tof_distance
uint32 tof_phase
uint32 tof_amp
uint16 tof_mode

在Firmware/msg/CMakeLists.txt中添加一行

test_tof.msg

在Firmware目录下编译

make px4_fmu-v5_default

 在Firmware/build/px4_fmu-v5_default/uORB/topics/目录下生成test_tof.h文件

发布订阅代码参考Firmware/src/examples/px4_simple_app

/**
 * @file px4_simple_app.c
 * Minimal application example for PX4 autopilot
 *
 * @author Example User <mail@example.com>
 */

#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 px4_simple_app_main(int argc, char *argv[]);

int px4_simple_app_main(int argc, char *argv[])
{
	PX4_INFO("Hello Sky!");

	/* subscribe to sensor_combined topic */
	int sensor_sub_fd = orb_subscribe(ORB_ID(sensor_combined));
	/* limit the update rate to 5 Hz */
	orb_set_interval(sensor_sub_fd, 200);

	/* advertise attitude topic */
	struct vehicle_attitude_s att;
	memset(&att, 0, sizeof(att));
	orb_advert_t att_pub = orb_advertise(ORB_ID(vehicle_attitude), &att);

	/* one could wait for multiple topics with this technique, just using one here */
	px4_pollfd_struct_t fds[] = {
		{ .fd = sensor_sub_fd,   .events = POLLIN },
		/* there could be more file descriptors here, in the form like:
		 * { .fd = other_sub_fd,   .events = POLLIN },
		 */
	};

	int error_counter = 0;

	for (int i = 0; i < 5; i++) {
		/* wait for sensor update of 1 file descriptor for 1000 ms (1 second) */
		int poll_ret = px4_poll(fds, 1, 1000);

		/* handle the poll result */
		if (poll_ret == 0) {
			/* this means none of our providers is giving us data */
			PX4_ERR("Got no data within a second");

		} else if (poll_ret < 0) {
			/* this is seriously bad - should be an emergency */
			if (error_counter < 10 || error_counter % 50 == 0) {
				/* use a counter to prevent flooding (and slowing us down) */
				PX4_ERR("ERROR return value from poll(): %d", poll_ret);
			}

			error_counter++;

		} else {

			if (fds[0].revents & POLLIN) {
				/* obtained data for the first file descriptor */
				struct sensor_combined_s raw;
				/* copy sensors raw data into local buffer */
				orb_copy(ORB_ID(sensor_combined), sensor_sub_fd, &raw);
				PX4_INFO("Accelerometer:\t%8.4f\t%8.4f\t%8.4f",
					 (double)raw.accelerometer_m_s2[0],
					 (double)raw.accelerometer_m_s2[1],
					 (double)raw.accelerometer_m_s2[2]);

				/* set att and publish this information for other apps
				 the following does not have any meaning, it's just an example
				*/
				att.q[0] = raw.accelerometer_m_s2[0];
				att.q[1] = raw.accelerometer_m_s2[1];
				att.q[2] = raw.accelerometer_m_s2[2];

				orb_publish(ORB_ID(vehicle_attitude), att_pub, &att);
			}

			/* there could be more file descriptors here, in the form like:
			 * if (fds[1..n].revents & POLLIN) {}
			 */
		}
	}

	PX4_INFO("exiting");

	return 0;
}

 在Firmware/src/modules/目录下创建test_tof文件夹(发布订阅实例),并在其中创建test_tof.c和CMakeLists.txt文件 

/**
 * @file px4_simple_app.c
 * Minimal application example for PX4 autopilot
 *
 * @author Example User <mail@example.com>
 */


#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>

/* 添加要是用的topics , test_tof*/
#include <uORB/uORB.h>
#include <../build/px4_fmu-v5_default/uORB/topics/test_tof.h>

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

int test_tof_main(int argc, char *argv[])
{
	PX4_INFO("Init Tof !!!");

	/* 定义两个test_tof_s 数据结构体,tof用于发布数据,tof_copy用于订阅后复制数据 */
	struct test_tof_s tof;
    struct test_tof_s tof_copy;
	memset(&tof, 0, sizeof(tof));
   / * 公告一个消息,目的是发布这个消息 */
	orb_advert_t tof_pub = orb_advertise(ORB_ID(test_tof), &tof);
    /* 对数据进行虚假赋值*/
    tof.tof_amp = 100;
    tof.tof_distance = 200;
    tof.tof_phase = 300;

   /*发送数据*/
    orb_publish(ORB_ID(test_tof),tof_pub,&tof);

   	/* subscribe to sensor_combined topic(订阅一个消息ID) */
	int sensor_tof_fd = orb_subscribe(ORB_ID(test_tof));
	/* limit the update rate to 5 Hz */
   //设置sensor_combined消息的订阅时间间隔200毫秒一次
	orb_set_interval(sensor_tof_fd, 200);
   /* 将数据copy到新的结构体中进行验证*/
    orb_copy(ORB_ID(test_tof),sensor_tof_fd,&tof_copy);
  /* 打印数据进行验证*/
    PX4_INFO("[px4_tof] amp %d, distance %d ,phase %d\r\n", tof_copy.tof_amp,tof_copy.tof_distance,tof_copy.tof_phase);

	PX4_INFO("exiting");

	return 0;
}
px4_add_module(
	MODULE tof__px4_tof_app
	MAIN px4_tof_app
	SRCS
		px4_tof_app.c
	DEPENDS
	)

在Firmware/boards/px4/fmu-v5/default.cmake中的MODULES中添加test_tof

然后编译/下载

make px4_fmu-v5_default upload

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

示例:PX4——添加msg、uORB 的相关文章

  • PX4 SITL Gazebo 仿真时 libgazebo_multirotor_base_plugin 插件运行时出错

    PX4 SITL Gazebo 仿真时 libgazebo multirotor base plugin 插件运行时出错 问题描述原因分析解决办法总结 问题描述 在 Gazebo 中进行 PX4 的软件在环仿真时 xff0c 执 make
  • Nuttx下移植uorb笔记

    Nuttx下移植uorb笔记 之前接触过ros下的消息机制 xff08 生产者 消费者 xff09 模型 xff0c 第一感觉是灵活好用 xff0c 但是在资源有限的嵌入式环境里面 xff0c 邮箱 消息 显得就有点不那么灵活 xff0c
  • [pixhawk笔记]6-uORB流程及关键函数解析

    本文中将结合代码 文档及注释 xff0c 给出uORB执行流程及关键函数的解析 xff0c 由于uORB的机制实现较为复杂 xff0c 所以本文主要学习如何使用uORB的接口来实现通信 回到上一篇笔记中的代码 xff1a include l
  • UORB

    转载地址 xff1a http blog arm so armteg pixhawk 183 0503 html Pixhawk 飞控 系统是基于ARM的四轴以上飞行器的飞行控制器 xff0c 它的前身是PX4 IMU xff0c Pixh
  • 初学PX4之环境搭建

    文章转自 xff1a http www jianshu com p 36dac548106b 前言 前段时间linux崩溃了 xff0c 桌面进去后只有背景 xff0c 折腾好久没搞定 xff0c 为了节省时间索性重装了系统 xff0c 同
  • PX4进入系统控制台以及运行程序

    这里提供进入控制台两种办法 1 运行 Tools mavlink shell py dev ttyACM0 是我进入Px4系统控制台的命令 xff0c 进入之后应该是这样 Pixhawk src Firmware Tools mavlink
  • PX4模块设计之三:自定义uORB消息

    PX4模块设计之三 xff1a 自定义uORB消息 1 新增自定义uORB消息步骤2 应用ext hello world消息示例3 编译执行结果4 参考资料 基于PX4开源软件框架简明简介和PX4模块设计之二 xff1a uORB消息代理
  • PX4模块设计之四:MAVLink简介

    PX4模块设计之四 xff1a MAVLink简介 1 MAVLink PX4 应用简介2 MAVLink v2 0新特性3 MAVLink协议版本4 MAVLink通信协议帧4 1 MAVLink v1 0 帧格式4 2 MAVLink
  • PX4模块设计之二十三:自定义FlightTask

    PX4模块设计之二十三 xff1a 自定义FlightTask Step1 创建飞行模式文件夹Step2 创建飞行模式源代码和CMakeLists txt文件Step3 更新CMakeLists txt文件Step4 更新FlightTas
  • PX4模块设计之二十六:BatteryStatus模块

    PX4模块设计之二十六 xff1a BatteryStatus模块 1 BatteryStatus模块简介2 模块入口函数2 1 主入口battery status main2 2 自定义子命令custom command 3 Batter
  • PX4模块设计之三十:Hysteresis类

    PX4模块设计之三十 xff1a Hysteresis类 1 Hysteresis类简介2 Hysteresis类成员变量介绍3 Hysteresis类迟滞逻辑4 Hysteresis类重要方法4 1 Hysteresis bool ini
  • mavros连接px4失败的usb-ttl原因

    问题描述 xff1a 最近在搞mavros xff0c 以方便协处理器和pixhawk通讯 xff0c 在按照官网教程安装mavros xff0c 设置px4 xff0c 连接硬件之后发现mavros卡在中间下不去 xff1a MAVROS
  • PX4中自定义MAVLink消息(记录)

    简单记录一下这个过程 一 自定义uORB消息 这一步比较简单 xff0c 首先在msg 中新建ca trajectory msg文件 uint64 timestamp time since system start span class t
  • 报错{“msg“:“invalid token“,“code“:401}问题的解决

    报错 msg invalid token code 401 问题的解决 xff1a 解决办法 xff1a 将精确的路由放在最上面 xff0c 模糊的路由放在最下面 xff0c 防止精确的路由被覆盖
  • 自定义msg使用C++

    在之前创建talker的src文件夹中创建person cpp并编写如下 include 34 ros ros h 34 include 34 learning communication Person h 34 include lt ss
  • PX4项目学习::(七)飞控栈:commander

    PX4的飞行控制程序通过模块来实现 xff0c 与飞控相关的模块主要有commander xff0c navigator xff0c pos control xff0c att control这几个 xff0c 分别可以在src modul
  • 四、无人机知识笔记(初级:基本运动原理)

    笔记来源于 沈阳无距科技 工业级无人机的中国名片 编程外星人 目录 一 多旋翼直升机 二 基本飞行姿态 三 多旋翼飞行原理 四 反扭力与偏航运动 五 螺旋桨 六 有刷电机和无刷电机 七 电调与PWM信号 八 动力电池 九 遥控器 十 机架设
  • 大神浅谈无人机飞控软件设计 系统性总结

    写在前面 深感自己对飞控软件 算法的知识点过于杂乱 很久没有进行系统的总结了 因此决定写几篇文章记录一些飞控开发过程的知识点 主要是针对一些软件 算法部分进行讨论 如内容有错误 欢迎指出 1 飞控软件的基本模块 无人机能够飞行主要是依靠传感
  • 用于打开 MSG 文件的 C# Outlook 互操作和 OpenSharedItem [已关闭]

    Closed 此问题正在寻求书籍 工具 软件库等的推荐 不满足堆栈溢出指南 目前不接受答案 为了使用 OpenSharedItem Outlook 互操作方法 我可以遵循任何教程或资源吗 我的目标是使用它读取 MSG 文件 因为它可以显然
  • 使用 python 解析 Outlook .msg 文件

    环顾四周 没有找到满意的答案 有谁知道如何使用 Python 解析 Outlook 中的 msg 文件 我尝试使用 mimetools 和 email parser 但没有成功 帮助将不胜感激 这对我有用 import win32com c

随机推荐

  • 安装laravel

    安装laravel之前首先应该设置好安装好php xff0c 配置好环境变量 之后安装好compser 1 安装php环境变量 我使用的php环境安装包是upupw xff0c xff08 php环境安装包有很多 xff0c 例如phpst
  • git关联远程仓库(本地库被其他远程库占用解决方案)

    关联远程库两种方式 1 你现在文件夹里有项目 xff0c 远程库还没建 xff0c 这个情况 先在远程库新建项目 xff0c 然后git clone git 64 github com xxxx lzzz git 到本地文件夹空文件夹内 然
  • 无人机坐标系定义与转换

    x 作者简介 xff1a 热爱科研的无人机 xff08 机器人 xff09 导航 制导 控制开发者 如有错误 xff0c 请指正 xff0c 不吝感谢 xff01 1 前言 我们在研究无人机 机器人 无人车等相关领域的导航 制导与控制算法时
  • PX4 EKF模块解读含matlab代码

    这里主要介绍px4里面的定位模块 xff0c 即EKF库 1 状态向量与协方差的预测 1 Px4的状态向量为24维 xff0c 其如下所示 xff1a x 61
  • Cent OS 7 关闭防火墙

    临时关闭 systemctl stop firewalld service 禁止开机启动 systemctl disable firewalld service Removed symlink etc systemd system mult
  • (解决)flink 单机部署,启动后进程没有StandaloneSessionClusterEntrypoint,web无法访问8081端口

    以下为解决 原因 xff1a 一般都是8081端口被占用 报错日志 xff1a 仔细阅读可以看到8081端口被占用 2021 06 17 15 47 11 069 INFO org apache flink runtime entrypoi
  • centos7 更新内核

    1 查看当前内核版本 uname r 3 10 0 514 el7 x86 64 uname a Linux k8s master 3 10 0 514 el7 x86 64 1 SMP Tue Nov 22 16 42 41 UTC 20
  • 使用npm link关联自己的node modules(项目)

    在进行自己的模块开发时 xff0c 一般我们至少会创建2个项目 xff0c 一个项目进行自己的modules开发 xff08 项目aaa xff09 另一个项目引入自己开发的modules xff0c 进行测试并使用 xff08 项目bbb
  • 正点原子STM32F407+ESP8266开发上篇

    说起机智云 xff0c 真是对物联网技术小白来说太人性化了 xff0c 对物联网感兴趣的的小白 xff0c 只需会学会看懂代码中的接口 xff0c 可以先不用学会网络协议 xff08 当然这个肯定要学的 xff09 xff0c 即可轻松将数
  • ubuntu下安装cmake及cmake简单使用,CmakeList的编写和参数详解

    安装过程 首先去官网下载安装包 选择 XX tar gz 源码安装包 输入如下命令 tar zxvf xx tar gz bootstrap make make install 输入以上命令后就已经可以在ubuntu上安装好cmake 编写
  • ROS中两个电脑之间ssh通信(ROS多机通信计算机网络配置)

    ROS中两个电脑之间ssh通信 PC 即个人电脑 xff0c ip是202 204 53 186 图一 xff1a PC bashrc 图二 xff1a PC hosts pc上终端启动 xff1a ssh robot 64 202 204
  • rosdep init

    本文之后 xff0c 世上再无rosdep更新失败问题 xff01 如果有 小鱼就
  • Hadoop中查看HDFS中的一个文件的位置信息

    指令 hadoop fsck user hadoop filename files blocks locations racks files 文件分块信息 xff0c blocks 在带 files参数后才显示block信息 locatio
  • ROS 安装与测试& RVIZ 运行仿真机械臂

    本文用于学习记录 文章目录 前言一 ROS 安装1 1 设置安装源1 2 设置 key1 3 更新 apt1 4 安装 ros 二 ROS 环境配置2 1 配置环境变量2 2 安装构建依赖相关工具2 3 初始化 rosdep2 4 替换 2
  • 自抗扰控制器-1.跟踪微分器 TD

    传统控制方法大都基于设定值与系统输出的残差的生成控制量 xff0c 这就是让有惯性输出信号跟踪存在跳变的设定值信号 xff0c 最初阶段残差过大 xff0c 容易导致超调 为了克服这个缺陷 xff0c 研究人员采用微分器来获得信号的微分信号
  • 自抗扰控制器-3.状态观测器(一)

    状态观测器 ESO 状态观测器 Extended State Observer ESO 定义 xff1a 根据外部变量的观测来确定系统内部状态变量的装置叫做状态观测器 xff0c 即根据测量到的系统输入 xff08 控制量 xff09 和系
  • 自抗扰控制器-6线性自抗扰控制器LADRC

    二阶线性自抗扰控制器结构图如下图所示 xff1a xff08 1 xff09 线性扩张状态观测器 LESO 依然属于 LADRC 的中枢核心环节 xff0c 而且 LESO 和 ESO 的功能基本 一致 xff0c 都是针对系统 总扰动 进
  • 无人机学习Pix4

    pix4学习 IMU xff08 惯性测量单元 xff09 IMU用来检测当前飞机的姿态 xff0c 飞控根据当前姿态做出调整 xff0c 保证飞机飞行稳定 俯仰角 pitch xff08 前后翻滚 xff09 横滚角 roll xff08
  • 修改Mysql root密码

    最近新装好的mysql在进入mysql工具时 xff0c 总是有错误提示 mysql uroot p Enter password ERROR 1045 28000 Access denied for user 39 root 39 64
  • 示例:PX4——添加msg、uORB

    git clone https github com PX4 Firmware cd Firmware git submodule update init recursive git checkout v1 11 0 beta1 make