当前位置:网站首页>esp32和ros2基础篇草稿-micro-ros-
esp32和ros2基础篇草稿-micro-ros-
2022-08-02 23:40:00 【zhangrelay】
博客中两两三三记录了一些使用micro-ros建立esp32与ros2之间通信的一些调试记录。
也参考了如下的内容:
1 zhuanlan.zhihu.com/p/542563252
2 blog.csdn.net/qq_62096941/article/details/125638469除了如下博文中提及的工具:
micro-ros arduino esp32 ros2 笔记
还需要:
Micro-XRCE-DDS-Agent
主要参考如下:
arduino配置好后,支持ros1,ros2多种模式通信。
- micro-ros(ros2 dashing foxy humble)
- ros2arduino(ros2 dashing foxy humble)
- rosserial(ros1 kinetic melodic noetic)
这些都测试过,也都非常稳定,如果不用arduino。
参考如下这篇:
micro-ROS之esp32与ros2资料(freertos)_zhangrelay的博客-CSDN博客
使用arduino esp32 micro-ros发布一个主题的代码如下:
#include <micro_ros_arduino.h>
#include <stdio.h>
#include <rcl/rcl.h>
#include <rcl/error_handling.h>
#include <rclc/rclc.h>
#include <rclc/executor.h>
#include <std_msgs/msg/int32.h>
#if !defined(ESP32) && !defined(TARGET_PORTENTA_H7_M7) && !defined(ARDUINO_NANO_RP2040_CONNECT)
#error This example is only avaible for Arduino Portenta, Arduino Nano RP2040 Connect and ESP32 Dev module
#endif
rcl_publisher_t publisher;
std_msgs__msg__Int32 msg;
rclc_support_t support;
rcl_allocator_t allocator;
rcl_node_t node;
#define LED_PIN 13
#define RCCHECK(fn) { rcl_ret_t temp_rc = fn; if((temp_rc != RCL_RET_OK)){error_loop();}}
#define RCSOFTCHECK(fn) { rcl_ret_t temp_rc = fn; if((temp_rc != RCL_RET_OK)){}}
void error_loop(){
while(1){
digitalWrite(LED_PIN, !digitalRead(LED_PIN));
delay(100);
}
}
void timer_callback(rcl_timer_t * timer, int64_t last_call_time)
{
RCLC_UNUSED(last_call_time);
if (timer != NULL) {
RCSOFTCHECK(rcl_publish(&publisher, &msg, NULL));
msg.data++;
}
}
void setup() {
set_microros_wifi_transports("***", "***", "***", 8888);
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, HIGH);
delay(2000);
allocator = rcl_get_default_allocator();
//create init_options
RCCHECK(rclc_support_init(&support, 0, NULL, &allocator));
// create node
RCCHECK(rclc_node_init_default(&node, "micro_ros_arduino_wifi_node", "", &support));
// create publisher
RCCHECK(rclc_publisher_init_best_effort(
&publisher,
&node,
ROSIDL_GET_MSG_TYPE_SUPPORT(std_msgs, msg, Int32),
"topic_name"));
msg.data = 0;
}
void loop() {
RCSOFTCHECK(rcl_publish(&publisher, &msg, NULL));
msg.data++;
}其中:
set_microros_wifi_transports("***", "***", "***", 8888);
分别为wifi名,wifi密码,agent地址,agent端口。
测试效果稳定。
需要启动agent。
测试共稳定接受22585890个数据,未出现任何异常:
边栏推荐
猜你喜欢

TensorFlow学习记录(一):基本介绍

Jmeter二次开发实现rsa加密

js基础知识整理之 —— 五种输出方式

【系统架构设计师】第三章 数据库系统

【多线程】线程与进程、以及线程进程的调度

MySQL最大建议行数2000w, 靠谱吗?

The latest real software test interview questions are shared. Are you afraid that you will not be able to enter the big factory after collecting them?

程序员如何优雅地解决线上问题?

服务间歇性停顿问题优化|得物技术

1 - vector R language self-study
随机推荐
基于STM32设计的老人防摔倒报警设备(OneNet)
解决错误:Optional int parameter ‘pageSize‘ is present but cannot be translated into a null value due to
DownMusic summary record
几种常见的跨域解决方法
剑指 Offer 21. 调整数组顺序使奇数位于偶数前面
2022第十一届财经峰会:优炫软件斩获双项大奖
合并两个excel表格工具
令人心动的AI综述(1)
pytest-常用运行参数
js基础知识整理之 —— 获取元素和命名规范
最近公共祖先(LCA)学习笔记 | P3379 【模板】最近公共祖先(LCA)题解
优秀论文以及思路分析02
2022中国眼博会,山东眼健康展,视力矫正仪器展,护眼产品展
C语言:链表
优秀论文以及思路分析01
DB2数据库-获取表结构异常:[jcc][t4][1065][12306][4.26.14]CharConvertionException ERRORCODE=-4220,SQLSTATE=null
NLP commonly used Backbone model cheat sheet (1)
我们来浅谈代码语言的魅力
D experimental new anomaly
D with json