鱼香ROS社区
    • 版块
    • 最新
    • 未解决
    • 已解决
    • 群组
    • 注册
    • 登录
    紧急通知:禁止一切关于政治&VPN翻墙等话题,发现相关帖子会立马删除封号
    提问前必看的发帖注意事项: 社区问答规则(小鱼个人)更新 | 高质量帖子发布指南

    【分享】STM32上运行ROS2(MicroROS)

    已定时 已固定 已锁定 已移动
    MicroROS
    fishros microros stm32
    5
    6
    2.5k
    正在加载更多帖子
    • 从旧到新
    • 从新到旧
    • 最多赞同
    回复
    • 在新帖中回复
    登录后回复
    此主题已被删除。只有拥有主题管理权限的用户可以查看。
    • 小鱼小
      小鱼 技术大佬
      最后由 小伊 编辑

      c9683f72-b246-4aa5-b558-f11cef330f59-output_image (16).png

      1. 用PIO新建工程,开发板选择 stm32f407zg 或其他STM32开发板
      2. 开发框架使用Arduino
      3. 添加 lib_deps 依赖

      完成配置如下:

      [env:black_f407zg]
      platform = ststm32
      board = black_f407zg
      framework = arduino
      upload_protocol = cmsis-dap
      lib_deps =
      	 https://gitee.com/ohhuo/micro_ros_platformio.git
      
      

      主函数代码:

      #include <Arduino.h>
      #include <micro_ros_platformio.h>
      
      #include <rcl/rcl.h>
      #include <rclc/rclc.h>
      #include <rclc/executor.h>
      
      rclc_executor_t executor;
      rclc_support_t support;
      rcl_allocator_t allocator;
      rcl_node_t node;
      
      void setup()
      {
        Serial.begin(115200);
        // 设置通过串口进行MicroROS通信
        set_microros_serial_transports(Serial);
        // 延时时一段时间,等待设置完成
        delay(2000);
        // 初始化内存分配器
        allocator = rcl_get_default_allocator();
        // 创建初始化选项
        rclc_support_init(&support, 0, NULL, &allocator);
        // 创建节点 hello_microros
        rclc_node_init_default(&node, "hello_microros_stm32", "", &support);
        // 创建执行器
        rclc_executor_init(&executor, &support.context, 1, &allocator);
      }
      
      void loop()
      {
        delay(100);
        // 循环处理数据
        rclc_executor_spin_some(&executor, RCL_MS_TO_NS(100));
      }
      
      

      编译下载即可。

      测试 结果如下 :

      sudo docker run -it --rm -v /dev:/dev -v /dev/shm:/dev/shm --privileged --net=host microros/micro-ros-agent:$ROS_DISTRO serial --dev /dev/ttyUSB0 -v6
      [sudo] fishros 的密码: 
      [1698816645.808775] info     | TermiosAgentLinux.cpp | init                     | running...             | fd: 3
      [1698816645.808882] info     | Root.cpp           | set_verbose_level        | logger setup           | verbose_level: 6
      0000: 81 00 00 00 04 01 0B 00 00 00 58 52 43 45 01 00 01 0F 00
      [1698816650.428791] debug    | SerialAgentLinux.cpp | recv_message             | [==>> SER <<==]        | client_key: 0x7E54E1E4, len: 52, data: 
      0000: 81 80 00 00 01 07 2C 00 00 0A 00 01 01 03 00 00 1D 00 00 00 00 01 F9 23 15 00 00 00 68 65 6C 6C
      0020: 6F 5F 6D 69 63 72 6F 72 6F 73 5F 73 74 6D 33 32 00 00 00 00
      [1698816650.440143] info     | ProxyClient.cpp    | create_participant       | participant created    | client_key: 0x7E54E1E4, participant_id: 0x000(1)
      [1698816650.440353] debug    | SerialAgentLinux.cpp | send_message             | [** <<SER>> **]        | client_key: 0x7E54E1E4, len: 14, data: 
      0000: 81 80 00 00 05 01 06 00 00 0A 00 01 00 00
      [1698816650.440376] debug    | SerialAgentLinux.cpp | send_message             | [** <<SER>> **]        | client_key: 0x7E54E1E4, len: 13, data: 
      0000: 81 00 00 00 0A 01 05 00 01 00 00 00 80
      [1698816650.446161] debug    | SerialAgentLinux.cpp | recv_message             | [==>> SER <<==]        | client_key: 0x7E54E1E4, len: 13, data: 
      0000: 81 00 00 00 0A 01 05 00 01 00 00 00 80
      
      
      $ ros2 node list
      /hello_microros_stm32
      

      有很多同学可能会问,用Arduino 开发STM32,是不是就不能使用比较核心的 STM32 API了,不是这样的,stm32的arduino库是基于 HAL库的二次封装,比如你可以在 main.cpp 中包含 #include <stm32f4xx_hal_gpio.h> 然后使 HAL_GPIO_Init(); 带来 pinMode(); 设置,当然有更简单的方法可以使用,为什么要舍近求远呢。

      新书配套视频:https://www.bilibili.com/video/BV1GW42197Ck/

      27842780782 1 条回复 最后回复 回复 引用 0
      • 27842780782
        Te Fuir @小鱼
        最后由 编辑

        @小鱼 1e210be1-77a8-4bec-a3c8-d0709939cbee-faca54a8e9bc02c0b6b70f03fcbbc2f.png
        您知道这怎么解决吗

        小鱼小 U 2 条回复 最后回复 回复 引用 0
        • 小鱼小
          小鱼 技术大佬 @2784278078
          最后由 编辑

          @2784278078 换成micros仓库官方地址:https://github.com/micro-ROS/micro_ros_platformio

          新书配套视频:https://www.bilibili.com/video/BV1GW42197Ck/

          greatxin1121G 1 条回复 最后回复 回复 引用 1
          • greatxin1121G
            greatxin1121 @小鱼
            最后由 编辑

            @小鱼 在 【分享】STM32上运行ROS2(MicroROS) 中说:

            https://github.com/micro-ROS/micro_ros_platformio

            小鱼你好,我也遇到这个错误,把那个lip-deps换成官方链接后,直接不通过了
            Snipaste_2024-01-04_13-21-27.png

            13248971951 1 条回复 最后回复 回复 引用 0
            • 13248971951
              ฅʕ•̫͡•ʔฅ @greatxin1121
              最后由 编辑

              @greatxin1121 您好,请问您解决这个问题了么?

              1 条回复 最后回复 回复 引用 0
              • U
                universe7476 @2784278078
                最后由 编辑

                @2784278078 您好,我遇到了和您相同的问题,请问您找到解决方法了吗?

                1 条回复 最后回复 回复 引用 0
                • 第一个帖子
                  最后一个帖子
                皖ICP备16016415号-7
                Powered by NodeBB | 鱼香ROS