MAVROS二次开发(四)添加消息处理插件

2023-05-16

转载自:https://blog.csdn.net/qq_38981124/article/details/104861900

MAVROS二次开发(四)添加消息处理插件

小柏QAQ 2020-03-14 15:58:37 310 收藏 2

文章标签: 自动驾驶

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。

本文链接:https://blog.csdn.net/qq_38981124/article/details/104861900

版权

MAVROS二次开发

四、添加消息处理插件

mavros插件所在路径:~/catkin_ws/src/mavros/mavros/src/plugins

1、自定义消息处理插件的编写

  • 参考代码:~/catkin_ws/src/mavros/mavros/src/plugins/manual_control.cpp(很典型)
  • 插件文件名称:crawl_control.cpp
  • 文件路径:~/catkin_ws/src/mavros/mavros/src/plugins/crawl_control.cpp
  • 文件内容:
/**
 * @brief CrawlControls plugin
 * @file crawl_controls.cpp
 * @author Yanfeng <962353916@qq.com>
 *
 * @addtogroup plugin
 */

#include <mavros/mavros_plugin.h>

#include <mavros_msgs/CrawlControlStatus.h>
#include <mavros_msgs/CrawlControlSet.h>

namespace mavros {
namespace std_plugins {
/**
 * @brief Crawl Control plugin
 */
class CrawlControlPlugin : public plugin::PluginBase {
public:
	CrawlControlPlugin() : PluginBase(),
		crawl_control_nh("~crawl_control")
	{ }

	void initialize(UAS &uas_)
	{
		PluginBase::initialize(uas_);

		control_pub = crawl_control_nh.advertise<mavros_msgs::CrawlControlStatus>("status", 10);
		send_service = crawl_control_nh.advertiseService("send", &CrawlControlPlugin::send_cb, this);
	}
    //用来获取mavlink解析到的消息
	Subscriptions get_subscriptions() {
		return {
			make_handler(&CrawlControlPlugin::handle_crawl_control),
		};
	}

private:
	ros::NodeHandle crawl_control_nh;

	ros::Publisher control_pub;
	ros::ServiceServer send_service;

	/* -*- rx handlers -*- */
    //mavlink::crawl_control_status::msg::CRAWL_CONTROL_STATUS为自动生成的消息头文件中所定义的,也是依据此来解析收到的mavlink消息。
	void handle_crawl_control(const mavlink::mavlink_message_t *msg, mavlink::crawl_control_status::msg::CRAWL_CONTROL_STATUS &crawl_control)
	{
		auto crawl_control_msg = boost::make_shared<mavros_msgs::CrawlControlStatus>();
		
		// crawl_control_msg->header.stamp = ros::Time::now();
		crawl_control_msg->sw_state = crawl_control.sw_state;
		crawl_control_msg->clamp_state = crawl_control.clamp_state;
		crawl_control_msg->crawl_state = crawl_control.crawl_state;
		crawl_control_msg->clamp_speed = crawl_control.clamp_speed;
		crawl_control_msg->crawl_speed = crawl_control.crawl_speed;
		//将解析到的消息发布至topic
		control_pub.publish(crawl_control_msg);
	}

	/* -*- callbacks -*- */

	bool send_cb(mavros_msgs::CrawlControlSet::Request &req, mavros_msgs::CrawlControlSet::Response &responce)
	{
		mavlink::crawl_control_set::msg::CRAWL_CONTROL_SET msg;
		//讲server收到的request赋值给mavlink消息
		msg.clamp_state_set = req.clamp_set;
		msg.crawl_state_set = req.crawl_set;
		msg.clamp_speed_set = req.clamp_speed;
		msg.crawl_speed_set = req.crawl_speed;
		//响应发送成功
		responce.send_success = true;
		//调用mavlink消息发送API
		UAS_FCU(m_uas)->send_message_ignore_drop(msg);
		return true;
	}
};
}	// namespace std_plugins
}	// namespace mavros

#include <pluginlib/class_list_macros.h>
PLUGINLIB_EXPORT_CLASS(mavros::std_plugins::CrawlControlPlugin, mavros::plugin::PluginBase)

2、添加自定义插件到插件列表中

  • 路径:~/catkin_ws/src/mavros/mavros/mavros_plugins.xml
  • 作用:用于MAVROS自动加载插件
  • 添加内容:
	<class name="crawl_control" type="mavros::std_plugins::CrawlControlPlugin" base_class_type="mavros::plugin::PluginBase">
		<description>Handle the crawl_control messages</description>
	</class>

3、添加至CMakeLists.txt

  • 路径:~/catkin_ws/src/mavros/mavros/CMakeLists.txt
  • 作用:将插件添加至编译
  • 添加内容:
add_library(mavros_plugins
  src/plugins/crawl_control.cpp #add
)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

MAVROS二次开发(四)添加消息处理插件 的相关文章

  • 常用MAVROS话题和服务

    https zhuanlan zhihu com p 364872655 一 常用接收的话题 1 1 系统状态 消息名称 xff1a mavros state 类型 xff1a mavros msgs State 头文件 xff1a mav
  • t265 通过mavros传递定位信息px4

    https github com thien94 vision to mavros 通过话题 mavros vision pose pose 向PX4发送位置数据 t265两种安装方式 xff1a USB口朝右镜头向前和向下安装 如需其它方
  • ros+mavros+gazebo仿真实践要点总结

    1 安装ros时要看好对应的版本 xff0c ubuntu16 4对应的kenitic版本 xff0c Ubuntu18 04对应的melodic版本 2 通过ssh方式clone px4 firmware比http方式快的多 3 参考教程
  • 【PX4 二次开发 初级】 02 飞控软硬件体系

    PX4 二次开发初级 PX4 飞控软硬件体系 飞控硬件体系PIXHAWK 控制硬件 软件体系PX4 体系原生固件原生固件官网原生固件地面站 APM 体系APM官网 xff1a 原生固件地面站 特点 标题 xff1a PX4二次开发教程 xf
  • 【Mavros解析 】02 ROS服务以及在mavros中体现

    Mavros解析 02 ROS服务以及在mavros中体现 简介实现步骤步骤 1 xff1a 连接服务步骤 2 xff1a 实例化服务参数 xff1a 步骤 3 xff1a 请求服务 Demo头文件订阅回调函数主函数初始化订阅mavrso
  • PX4 与 MAVROS 实现offboard

    目录 一 虚拟机仿真环境 1 创建工作空间 2 创建ROS节点功能包 3 运行PX4的gazebo仿真 4 启动PX4与Mavros之间的连接 二 真机控制 1 硬件连接 2 软件设置 3 出现问题 Ubuntu xff1a 20 04 x
  • PX4 offboard模式能接收的mavros指令

    以下内容针对px4 v1 11 3 xff08 2021 01 xff09 px4 offboard模式下可以接收上位机发送来的setpoint值 xff0c 可以利用ROS包mavros来发送这些setpoint xff08 期望值 xf
  • roslaunch px4 multi_uav_mavros_sitl_sdf.launch报错

    转载自 xff1a https www cnblogs com pig fly p 13971458 html 在试图运行multi uav mavros sitl sdf launch时报错 xff1a while processing
  • 树莓派+ubuntu18.04+ROS-melodic+MAVROS+librealsense+vio+realsense_ros

    目录 一 树莓派安装ubuntu18 04 1 下载ubuntu系统文件 2 将系统文件烧入SD卡 3 强制修改HDMI输出分辨率 xff08 此步骤可忽略 xff09 4 设置wifi xff08 此步骤也可忽略 xff0c 后续连接网线
  • MAVROS二次开发(二)(三)添加自定义消息

    MAVROS二次开发 二 MAVROS消息添加 1 自定义rostopic消息 路径 xff1a catkin ws src mavros mavros msgs msg 自定义消息文件名称 xff1a CrawlControlStatus
  • ROS安装和MAVROS以及PX4的安装

    只能说怀着沉重的心情 xff0c 本来不想写的 xff0c 但是又还是害怕后续出什么幺蛾子 xff0c 就记录一下 xff0c 希望自己永远没有机会在看这篇文章 文章目录 ROS安装 ubuntu18 04安装melodic 1 Ubunt
  • PX4+ROS+gazebo+mavros,Ubuntu18.04搭建SITL仿真环境

    前言 介绍 SITL Software in the Loop 软件在环仿真平台 xff0c 与之对应的有 HITL 硬件在环仿真 本文目的是搭建一个无人机软件仿真环境 xff0c 使用PX4开源飞控 xff0c gazebo作为仿真器 x
  • mavros操作飞机时方向位置改为机体坐标系下指令

    前面试了很多 xff0c 看官网里的说明 用 mavros setpoint raw local 34 里的frame id改为 34 base link 34 不行 又直接发mavros msgs PositionTarget 修改里面的
  • 海康威视工业相机SDK二次开发(VS+Opencv+QT+海康SDK+C++)(一)

    最近在做一个项目 xff0c 涉及到工业相机 xff0c 需要对其进行二次开发 相机方面选择了海康威视 xff0c 网上关于海康威视工业相机SDK的开发资料很少 xff0c 官方文档里面虽然写的是支持C 43 43 开发的 xff0c 但其
  • ubuntu20 安装px4、mavros、QGroundControl

    一 安装PX4 jjm2是我的主文件夹名 xff0c 可以根据自己的主文件夹名修改 下载PX4 git clone https github com PX4 PX4 Autopilot git recursive 由于网速原因 xff0c
  • MAVROS(1)offboard模式(手动和roslaunch启动)

    官方教程 xff1a https docs px4 io master en ros mavros offboard html 1 编写功能包 参考 xff1a https blog csdn net weixin 44917390 art
  • APM-SITL Gazebo MAVROS 仿真

    1 配置APM SITL环境 1 下载安装Ardupilot 参考链接 xff1a 官方教程 注意 xff1a 文件install prereqs ubuntu sh路径在 ardupilot Tools environment insta
  • PX4 Offboard Control Using MAVROS on ROS

    这篇是下面这位大神推荐的 xff0c 我看了下确实也不错 https blog csdn net zhengyuxin0507 article details 80357405 摘自 xff1a https 404warehouse net
  • PX4 Offboard Control with MAVROS--Takeoff(一键起飞)

    警告 xff1a 请先在仿真环境下进行测试 xff0c 能达到预期效果后在进行实际飞行测试 xff0c 以免发生意外 本篇文章只是用作学习交流 xff0c 实际飞行时如出现意外情况作者不予以负责 所需材料 1 PIXhawk或者Pixrac
  • 关于OpenAI的Gym中的step方法

    文章目录 导读 Gym的step方法 最后的话 导读 本文就只是关于step方法的参数与返回值的一个小小的学习笔记 这也是没有第一时间查官方文档而造成的时间消耗 所以 这篇博客就是逼自己查一下 Gym的step方法 既然都已经用pip下载了

随机推荐