ROS基于MQTT通信

ROS基于MQTT通信

最近在学习ROS通过MQTT通信,在此记录下。
版本:ubuntu20.04 ros-noetic

一、源码运行

创建工作空间并克隆mqtt_bridge源代码

mkdir -p mqtt_bridge/src
cd mqtt_bridge/src
git clone https://github.com/groove-x/mqtt_bridge

配置相关环境&安装依赖

sudo apt install ros-noetic-rosbridge-library
sudo apt install mosquitto mosquitto-clients
sudo apt install python3-pip
pip freeze > requirements.txt
pip3 install -r requirements.txt
pip install -i
pip3 install inject
pip3 install msgpack
pip -m pip install pymongo

编译

cd mqtt_bridge/
catkin_make
source devel/setup.bash

运行

roslaunch mqtt_bridge demo.launch

开一个新的终端A

source devel/setup.bash
rostopic echo /back

再开一个终端B

source devel/setup.bash
rostopic pub /echo std_msgs/String "data: 'hello'"

查看终端A的结果如下

data: hello
---

yaml文件
路径: 用户文件夹/mqtt_bridge/src/mqtt_bridge_config

mqtt:
  client:
    protocol: 4      # MQTTv311
  connection:
    host: localhost 
    port: 1883
    keepalive: 60
  private_path:

你可能感兴趣的:(信息与通信,ubuntu)