• 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个数据,未出现任何异常:

     

     

  • 相关阅读:
    麻了,这让人绝望的大事务提交
    Java——状态管理
    【ijkplayer】解码流程梳理(三)
    redis-操作数据库
    前端开发:export 和 export default的区别
    如何选择消息队列
    单例模式之懒汉式和饿汉式
    Educational Codeforces Round 129 F. Unique Occurrences(树上问题)
    idea中启动maven项目报错-java: 程序包lombok.extern.slf4j不存在问题如何解决
    vue学习(基础下)
  • 原文地址:https://blog.csdn.net/ZhangRelay/article/details/126126969