当前位置:网站首页>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个数据,未出现任何异常:
边栏推荐
- flutter 时间戳转日期
- SAP 电商云 Spartacus UI 的持续集成 - Continous integration
- 停止使用 Storyboards 和 Interface Builder
- Technology Sharing | How to do assertion verification for xml format in interface automation testing?
- 牛客网剑指offer刷题练习之链表中环的入口结点
- 2022暑假牛客多校1 (A/G/D/I)
- js基础知识整理之 —— 全局作用域
- 服务间歇性停顿问题优化|得物技术
- 程序员英语自我介绍
- 几种常见的跨域解决方法
猜你喜欢

Technology Sharing | How to do assertion verification for xml format in interface automation testing?

【Autosar RTM】

2022杭电多校第一场(K/L/B/C)

精心整理16条MySQL使用规范,减少80%问题,推荐分享给团队

# DWD层及DIM层构建## ,220801 ,

CKAN教程之在 AWS 上部署 CKAN 应用程序

如何使用vlookup+excel数组公式 完成逆向查找?

分库分表索引设计:二级索引、全局索引的最佳设计实践

3、Xendesktop更改发布桌面的显示名称(MCS静态桌面)

即席查询—— Kylin使用
随机推荐
random.nextint()详解
1 - vector R language self-study
2022中国眼博会,山东眼健康展,视力矫正仪器展,护眼产品展
LVM与磁盘配额原理及配置
CKAN教程之将 Snowflake 连接到 CKAN 以发布到开放数据门户
C# 异步编程(async和await)
Technology Sharing | How to do assertion verification for xml format in interface automation testing?
Moco of Mock tools use tutorial
微信小程序实现lot开发09 接入微信登录
Swift中的类型相关内容
WAF WebShell Trojan free to kill
【多线程】线程与进程、以及线程进程的调度
程序员如何优雅地解决线上问题?
简单聊聊MySQL中的六种日志
基于rt-thread studio的STM32裸机开发——LED
flutter 时间戳转日期
十年架构五年生活-05第一次出差
智能电视竞争白热化,利用小程序共建生态突围
Connect the Snowflake of CKAN tutorial CKAN to release to open data portal
分库分表索引设计:二级索引、全局索引的最佳设计实践