• esp32和ros2基础篇草稿-micro-ros-


    博客中两两三三记录了一些使用micro-ros建立esp32与ros2之间通信的一些调试记录。

    也参考了如下的内容:

    1. 1 zhuanlan.zhihu.com/p/542563252
    2. 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发布一个主题的代码如下:

    1. #include
    2. #include
    3. #include
    4. #include
    5. #include
    6. #include
    7. #include
    8. #if !defined(ESP32) && !defined(TARGET_PORTENTA_H7_M7) && !defined(ARDUINO_NANO_RP2040_CONNECT)
    9. #error This example is only avaible for Arduino Portenta, Arduino Nano RP2040 Connect and ESP32 Dev module
    10. #endif
    11. rcl_publisher_t publisher;
    12. std_msgs__msg__Int32 msg;
    13. rclc_support_t support;
    14. rcl_allocator_t allocator;
    15. rcl_node_t node;
    16. #define LED_PIN 13
    17. #define RCCHECK(fn) { rcl_ret_t temp_rc = fn; if((temp_rc != RCL_RET_OK)){error_loop();}}
    18. #define RCSOFTCHECK(fn) { rcl_ret_t temp_rc = fn; if((temp_rc != RCL_RET_OK)){}}
    19. void error_loop(){
    20. while(1){
    21. digitalWrite(LED_PIN, !digitalRead(LED_PIN));
    22. delay(100);
    23. }
    24. }
    25. void timer_callback(rcl_timer_t * timer, int64_t last_call_time)
    26. {
    27. RCLC_UNUSED(last_call_time);
    28. if (timer != NULL) {
    29. RCSOFTCHECK(rcl_publish(&publisher, &msg, NULL));
    30. msg.data++;
    31. }
    32. }
    33. void setup() {
    34. set_microros_wifi_transports("***", "***", "***", 8888);
    35. pinMode(LED_PIN, OUTPUT);
    36. digitalWrite(LED_PIN, HIGH);
    37. delay(2000);
    38. allocator = rcl_get_default_allocator();
    39. //create init_options
    40. RCCHECK(rclc_support_init(&support, 0, NULL, &allocator));
    41. // create node
    42. RCCHECK(rclc_node_init_default(&node, "micro_ros_arduino_wifi_node", "", &support));
    43. // create publisher
    44. RCCHECK(rclc_publisher_init_best_effort(
    45. &publisher,
    46. &node,
    47. ROSIDL_GET_MSG_TYPE_SUPPORT(std_msgs, msg, Int32),
    48. "topic_name"));
    49. msg.data = 0;
    50. }
    51. void loop() {
    52. RCSOFTCHECK(rcl_publish(&publisher, &msg, NULL));
    53. msg.data++;
    54. }

    其中:

    set_microros_wifi_transports("***", "***", "***", 8888);

    分别为wifi名,wifi密码,agent地址,agent端口。


    测试效果稳定。

     

    需要启动agent。

    测试共稳定接受22585890个数据,未出现任何异常:

     

     

  • 相关阅读:
    [数据结构与算法] 线性表之数组基本操作代码实现详解
    判断链表是否成环
    golang面试题:对未初始化的的chan进行读写,会怎么样?为什么?
    使用git、git-flow与gitlab工作
    GPIO 模拟SPI
    聚观早报 |红魔9 Pro支持165W快充;2023Q3欧洲手机市场报告
    Kubernetes rancher、prometheus、ELK的安装
    一个很强大的人脸识别库face_recognition
    小米汽车超级工厂智能物流
    HTTP常用状态码
  • 原文地址:https://blog.csdn.net/ZhangRelay/article/details/126126969