示例: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/Pixhawk---uORB深入理解和应用

    The Instructions of uORB PX4 Pixhawk 软件体系结构 uORB 主题发布 主题订阅 1 简介 1 1 PX4 Pixhawk的软件体系结构 PX4 Pixhawk的软件体系结构主要被分为四个层次 xff0c
  • PX4 SITL Gazebo 仿真时 libgazebo_multirotor_base_plugin 插件运行时出错

    PX4 SITL Gazebo 仿真时 libgazebo multirotor base plugin 插件运行时出错 问题描述原因分析解决办法总结 问题描述 在 Gazebo 中进行 PX4 的软件在环仿真时 xff0c 执 make
  • PX4位置控制offboard模式说明

    offboard模式的开发及应用 一 px4固件的模式 px4固件支持10几种飞行模式 xff0c 从代码结构上分析 xff0c 分为基本模式 自定义模式和自定义子模式 1 基本模式 基本模式又分为 xff0c 位置控制模式 自稳模式 手动
  • PX4无人机 - 键盘控制飞行代码

    PX4无人机 键盘控制飞行代码 仿真效果 实机效果 由于图片限制5M以内 xff0c 只能上传一小段了 xff0c 整段视频请点击链接 Pixhawk 6c 无人机 键盘控制无人机 Offboard模式 核心 xff1a 发布 mavros
  • Ubuntu下构建PX4软件

    本搭建过程基于http dev px4 io starting building html xff0c 希望大家互相交流学习 原文 xff1a Building PX4 Software xff08 构建PX4软件 xff09 PX4 ca
  • PX4飞控之PWM输出控制

    PX4飞控之PWM输出控制 多旋翼电调如好盈XRotor xff0c DJI通用电调等都支持PWM信号来传输控制信号 常用的400Hz电调信号对应周期2500us xff0c 一般使用高电平时间1000us 2000us为有效信号区间 xf
  • ROS通信架构上——Topic和Msg

    Topic 异步通信方式 Node间通过publish subscribe机制通信 相关的命令 xff1a rostopic rostopic list 列出当前所有topicrostopic info topic name 显示某个top
  • PX4 ---- Mixer

    文章目录 Mixer 混合控制 作用输入输出装载混控文件MAVROS代码解析总结示例MAINAUX Mixer 混合控制 作用 经过位置控制和姿态控制后 xff0c 控制量通过 actuator controls发布 xff0c 其中 co
  • PX4模块设计之一:SITL & HITL模拟框架

    PX4模块设计之一 xff1a SITL amp HITL模拟框架 1 模拟框架1 1 SITL模拟框架1 2 HITL模拟框架 2 模拟器类型3 MAVLink API4 总结 基于PX4开源软件框架简明简介的框架设计 xff0c 逐步分
  • PX4模块设计之二十三:自定义FlightTask

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

    PX4模块设计之三十一 xff1a ManualControl模块 1 ManualControl模块简介2 模块入口函数2 1 主入口manual control main2 2 自定义子命令custom command 3 Manual
  • PX4模块设计之四十六:dataman模块

    PX4模块设计之四十六 xff1a dataman模块 1 dataman模块简介2 模块入口函数dataman main3 dataman模块重要函数3 1 start3 2 stop3 3 status3 4 task main 4 A
  • 关于github px4 gps 驱动的开发的总结

    源码编译上边已经写过文章了 遇到的几个问题 1 解决虚拟机不能共享文件夹的问题 一开始虚拟机的更新 vmware tools 是灰色的 xff0c 不能点 xff0c 然后通过关掉虚拟机 xff0c 然后再开启的时候 xff0c 在没有启动
  • uORB和MAVLink通讯例程

    uORB uORB 是一种异步 publish subscribe 的消息传递 API xff0c 用于进程或者线程间通信 IPC 添加新的Topic xff08 主题 xff09 在msg 目录下创建一个新的 msg文件 xff0c 并将
  • px4仿真无法起飞问题(Failsafe enabled: no datalink)

    报错信息 问题描述 xff1a 使用JMAVSim和gazebo仿真px4起飞时报错如下 xff1a WARN commander Failsafe enabled no datalink 说不安全 解决方法 打开QGC 就可以起飞了
  • PX4模块设计之二十七:LandDetector模块

    PX4模块设计之二十七 xff1a LandDetector模块 1 LandDetector模块简介2 模块入口函数2 1 主入口land detector main2 2 自定义子命令custom command 3 LandDetec
  • 步骤三:PX4,Mavros的下载安装及代码测试

    1 安装Mavros sudo apt install ros melodic mavros ros melodic mavros extras 2 安装Mavros相关的 geographiclib dataset 此处已经加了ghpro
  • PX4项目学习::(七)飞控栈:commander

    PX4的飞行控制程序通过模块来实现 xff0c 与飞控相关的模块主要有commander xff0c navigator xff0c pos control xff0c att control这几个 xff0c 分别可以在src modul
  • 无人机PX4使用动捕系统mocap的位置实现控制+MAVROS

    动捕系统Optitrack xff0c 有很高的定位精度 xff0c 能够给无人机提供比较精确的位置信息 xff0c 因此如果实验室有条件 xff0c 都可以买一套动捕系统 动捕系统的原理 xff1a 光学式动作捕捉依靠一整套精密而复杂的光
  • 飞行姿态解算(三)

    继之前研究了一些飞行姿态理论方面的问题后 又找到了之前很流行的一段外国大神写的代码 来分析分析 第二篇文章的最后 讲到了文章中的算法在实际使用中有重大缺陷 大家都知道 分析算法理论的时候很多情况下我们没有考虑太多外界干扰的情况 原因是很多情

随机推荐

  • 安装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