当前位置:网站首页>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个数据,未出现任何异常:
边栏推荐
猜你喜欢
随机推荐
为了面试阿里,熬夜肝完这份软件测试笔记后,Offer终于到手了
js基础知识整理之 —— 判断语句和三元运算符
js基础知识整理之 —— 闭包
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?
2022暑假牛客多校1 (A/G/D/I)
Day117. Shangyitong: Generate registered order module
高数---二重积分
js基础知识整理之 —— 变量和数据类型
用了这么多年的LinkedList,作者说自己从来不用它?为什么?
ORA-55610: Invalid DDL statement on history-tracked table
数据库审计 - 网络安全的重要组成部分
d合并json
CAS:1445723-73-8,DSPE-PEG-NHS,磷脂-聚乙二醇-活性酯两亲性脂质PEG共轭物
What is the matter that programmers often say "the left hand is knuckled and the right hand is hot"?
令人心动的AI综述(1)
fifa将采用半自动越位技术计算进球
新公链时代的跨链安全性解决方案
mPEG-Cholesterol,mPEG-CLS,甲氧基-聚乙二醇-胆固醇可用于脂质体制备
TensorFlow学习记录(一):基本介绍
如何使用vlookup+excel数组公式 完成逆向查找?









