当前位置:网站首页>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个数据,未出现任何异常:
边栏推荐
- js基础知识整理之 —— 判断语句和三元运算符
- 优秀论文以及思路分析02
- 年近30 ,4月无情被辞,想给划水的兄弟提个醒...
- 几种常见的跨域解决方法
- airflow db init 报错
- 程序员的七夕浪漫时刻
- TensorFlow学习记录(一):基本介绍
- Connect the Snowflake of CKAN tutorial CKAN to release to open data portal
- Day117. Shangyitong: Generate registered order module
- Technology Sharing | How to do assertion verification for xml format in interface automation testing?
猜你喜欢
随机推荐
flutter空安全问题,平时用到的数据一定要注意
@GetMapping、@PostMapping、@PutMapping、@DeleteMapping的区别
MySQL最大建议行数2000w, 靠谱吗?
心电记录电路设计(框图/波形以及信号放大器的选择)
可编程逻辑控制器(PLC) : 基础、类型和应用
6、Powershell命令配置Citrix PVS云桌面桌面注销不关机
程序员如何优雅地解决线上问题?
2022第十一届财经峰会:优炫软件斩获双项大奖
为了面试阿里,熬夜肝完这份软件测试笔记后,Offer终于到手了
公司招个程序员,34岁以上两年一跳的不要,开出工资以为看错了
数据库主键一定要自增吗?有哪些场景不建议自增?
flutter 时间戳转日期
【代码扫描修复】MD5加密弱HASH漏洞
CAS:1445723-73-8,DSPE-PEG-NHS,磷脂-聚乙二醇-活性酯两亲性脂质PEG共轭物
如何突破测试/开发程序员思维?一种不一样的感觉......
Swift中的类型相关内容
新公链时代的跨链安全性解决方案
CKAN教程之在 AWS 上部署 CKAN 应用程序
基于rt-thread studio的STM32裸机开发——LED
【多线程】线程与进程、以及线程进程的调度