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

    下载编译小鱼的ros2 serial包 编译示例报错

    已定时 已固定 已锁定 已移动
    ROS 2相关问题
    ros2 fishtool
    2
    11
    798
    正在加载更多帖子
    • 从旧到新
    • 从新到旧
    • 最多赞同
    回复
    • 在新帖中回复
    登录后回复
    此主题已被删除。只有拥有主题管理权限的用户可以查看。
    • 王涛王
      王涛
      最后由 编辑

      51c3c195f30e777badd3d9b01e262ec.png

      小鱼小 1 条回复 最后回复 回复 引用 0
      • 小鱼小
        小鱼 技术大佬 @王涛
        最后由 小鱼 编辑

        @王涛 看一下代码的README文件的最后,尝试以下步骤

        sudo sh -c "echo '/usr/local/lib' >> /etc/ld.so.conf"
        sudo ldconfig
        

        另外确定第一步安装有正常被安装

        其他问题可以查看github issue。

        • https://github.com/fishros/fish_protocol/issues/1
        • https://github.com/fishros/fish_protocol/issues/2

        另外尽量复制粘贴哈,方便我和其他人搜索。


        关于社区提问的一些注意事项,请看提问的智慧一节。

        比如你这里把源码地址贴出来,我就可以直接到README里复制粘贴出来,避免二次寻找源码地址。

        @小鱼 在 提问前必看!一定要看!必须看一下! 中说:

        一个好的提问不仅能够帮助自己理清楚问题,还有助于别人快速帮助到你。——提问的智慧

        问题一定要描述清楚,终端打印一定复制粘贴(你可以在linux系统上打开浏览器进社区)
        基本的Markdown语法一定要学习下,有的小伙伴图片代码一团糟
        提问时一定要提供尽可能多的信息,包括你的目的,比如你其实想装装某个库遇到问题,不要只说这个问题,因为可能有更好的替代方案
        先搜索再提问,很多问题其实都有解决方案,确保你自己对自己的问题有一定了解再提问
        尽量一句话说完,不要把社区当微信聊天一样用,每一个回复都尽量提供更多的的信息。

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

        王涛王 2 条回复 最后回复 回复 引用 0
        • 王涛王
          王涛 @小鱼
          最后由 编辑

          @小鱼 /usr/bin/ld: CMakeFiles/serial_test.dir/src/serial_test.cpp.o: in function main': serial_test.cpp:(.text+0x403): undefined reference to fish_protocol::GetProtocolByConfig(fish_protocol::ProtocolConfig const&)'
          /usr/bin/ld: serial_test.cpp:(.text+0x4a8): undefined reference to `fish_protocol::FishProtocol::SetDataRecvCallback(std::function<void (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)>)'
          collect2: error: ld returned 1 exit status
          make[2]: *** [CMakeFiles/serial_test.dir/build.make:131:serial_test] 错误 1
          make[1]: *** [CMakeFiles/Makefile2:78:CMakeFiles/serial_test.dir/all] 错误 2
          make: *** [Makefile:141:all] 错误 2

          Failed <<< serial_demon [1.93s, exited with code 2]

          Summary: 0 packages finished [3.53s]
          1 package failed: serial_demon
          1 package had stderr output: serial_demon

          ae5fe4b427f3bcb62dc77102f84ec9c.png 1e325a8beb60a88d30b70ae1b5113ef.png

          还是不行呢

          小鱼小 1 条回复 最后回复 回复 引用 0
          • 王涛王
            王涛 @小鱼
            最后由 编辑

            @小鱼 #include "fish_protocol/fish_protocol.h"
            #include "rclcpp/rclcpp.hpp"

            int main(int argc, char** argv) {
            /* 初始化rclcpp */
            rclcpp::init(argc, argv);
            /产生一个node_01的节点/
            auto node = std::make_sharedrclcpp::Node("example_fish_protocol");
            // 打印一句自我介绍
            RCLCPP_INFO(node->get_logger(), "example_fish_protocol节点已经启动.");

            fish_protocol::ProtocolConfig proto_config;
            proto_config.protocol_type_ = fish_protocol::PROTOCOL_TYPE::SERIAL;
            proto_config.serial_baut_ = 115200;
            proto_config.serial_address_ = "/dev/ttyS12";
            // 初始化
            auto protocol = GetProtocolByConfig(proto_config);
            // 发送数据
            protocol->ProtocolSendRawData("Hello FishBot!");
            // 接收数据
            protocol->SetDataRecvCallback([](const std::string& data) -> void {
            std::cout << "recv" << data << std::endl;
            });
            // 销毁
            protocol->ProtocolDestory();

            /* 运行节点,并检测退出信号 Ctrl+C*/
            rclcpp::spin(node);
            /* 停止运行 */
            rclcpp::shutdown();
            return 0;
            }

            这是源码

            1 条回复 最后回复 回复 引用 0
            • 小鱼小
              小鱼 技术大佬 @王涛
              最后由 编辑

              @王涛 前面的安装步骤是否执行了,可以分步骤执行看一下结果,另外你的系统平台和ROS版本是多少?

              sudo apt install libboost-dev
              git clone https://gh.api.99988866.xyz/https://github.com/fishros/fish_protocol.git 
              cd fish_protocol && mkdir build  && cd build
              cmake .. && sudo make install # 将安装到系统库
              

              注意格式哈~

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

              王涛王 1 条回复 最后回复 回复 引用 0
              • 王涛王
                王涛 @小鱼
                最后由 编辑

                @小鱼 a56707c4c371614d43ed9fb15a25748.png

                已经确定4个步骤全部正常安装

                然后
                1新建一个新的工作空间
                2新建一个功能包
                3新建cpp文件把 上述测试源码复制进去 并修改了cmakelist
                4 编译报错

                510d5f0ebdc90590e086ca6490356d8.png

                用虚拟机运行的20.04 ros版本是foxy

                小鱼小 1 条回复 最后回复 回复 引用 0
                • 小鱼小
                  小鱼 技术大佬 @王涛
                  最后由 编辑

                  @王涛 贴一下你新建空间的CMAKELISTS.txt文件


                  另外注意格式,终端日志尽量复制粘贴

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

                  王涛王 1 条回复 最后回复 回复 引用 0
                  • 王涛王
                    王涛 @小鱼
                    最后由 编辑

                    @小鱼 cmake_minimum_required(VERSION 3.8)
                    project(serial_demon)

                    if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
                    add_compile_options(-Wall -Wextra -Wpedantic)
                    endif()

                    find dependencies

                    find_package(ament_cmake REQUIRED)
                    find_package(rclcpp REQUIRED)
                    find_package(rclpy REQUIRED)
                    find_package(std_msgs REQUIRED)

                    add_executable(serial_demon src/serial_demon.cpp)
                    ament_target_dependencies(
                    serial_demon
                    "rclcpp"
                    "rclpy"
                    "std_msgs"
                    )

                    install(TARGETS
                    serial_demon
                    DESTINATION lib/${PROJECT_NAME})

                    if(BUILD_TESTING)
                    find_package(ament_lint_auto REQUIRED)

                    the following line skips the linter which checks for copyrights

                    uncomment the line when a copyright and license is not present in all source files

                    #set(ament_cmake_copyright_FOUND TRUE)

                    the following line skips cpplint (only works in a git repo)

                    uncomment the line when this package is not in a git repo

                    #set(ament_cmake_cpplint_FOUND TRUE)
                    ament_lint_auto_find_test_dependencies()
                    endif()

                    ament_package()

                    小鱼小 1 条回复 最后回复 回复 引用 0
                    • 小鱼小
                      小鱼 技术大佬 @王涛
                      最后由 编辑

                      @王涛 应该是这里的问题了,你用了第三方库,一定要添加依赖。你可以对比我给的示例工程下的CmakeLists.txt文件。

                      cmake_minimum_required(VERSION 3.8)
                      project(example_fish_protocol)
                      
                      if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
                        add_compile_options(-Wall -Wextra -Wpedantic)
                      endif()
                      
                      # find dependencies
                      find_package(ament_cmake REQUIRED)
                      find_package(rclcpp REQUIRED)
                      find_package(fish_protocol REQUIRED)
                      
                      add_executable(example_fish_protocol src/example_fish_protocol.cpp)
                      target_include_directories(example_fish_protocol PUBLIC
                        $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
                        $<INSTALL_INTERFACE:include>)
                      target_compile_features(example_fish_protocol PUBLIC c_std_99 cxx_std_17)  # Require C99 and C++17
                      ament_target_dependencies(
                        example_fish_protocol
                        "rclcpp"
                      
                      )
                      
                      target_link_libraries(example_fish_protocol
                        "fish_protocol"
                      )
                      
                      install(TARGETS example_fish_protocol
                        DESTINATION lib/${PROJECT_NAME})
                      
                      if(BUILD_TESTING)
                        find_package(ament_lint_auto REQUIRED)
                        # the following line skips the linter which checks for copyrights
                        # uncomment the line when a copyright and license is not present in all source files
                        #set(ament_cmake_copyright_FOUND TRUE)
                        # the following line skips cpplint (only works in a git repo)
                        # uncomment the line when this package is not in a git repo
                        #set(ament_cmake_cpplint_FOUND TRUE)
                        ament_lint_auto_find_test_dependencies()
                      endif()
                      
                      ament_package()
                      

                      重点在这几句

                      find_package(fish_protocol REQUIRED)
                      
                      target_link_libraries(example_fish_protocol
                        "fish_protocol"
                      )
                      

                      另外代码块记得包裹下

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

                      王涛王 1 条回复 最后回复 回复 引用 0
                      • 王涛王
                        王涛 @小鱼
                        最后由 编辑

                        @小鱼 在 下载编译小鱼的ros2 serial包 编译示例报错 中说:

                        target_link_libraries(example_fish_protocol
                        "fish_protocol"
                        )感谢大佬 问题已经解决

                        还有一个新的问题 我想发送和接受 16进制的数据 不是字符串 该怎么使用这两个函数呢

                        小鱼小 1 条回复 最后回复 回复 引用 0
                        • 小鱼小
                          小鱼 技术大佬 @王涛
                          最后由 小鱼 编辑

                          @王涛 针对新的问题请发新的帖子提问哈,一个帖子只围绕一个问题讨论。

                          记住一句话——万物皆可字符串,无论什么数据都可以转换成string格式。

                          一个16进制数据可以用4个二进制组成,一个字节=8个二进制,所以任意两个16进制数据可以由一个字节组成,一个字节就是一个byte,也就是我们常见的char类型,而string=char[]+长度信息组成的。

                          随手找了一个,你可以参考:

                          8820e6e3-78e1-451c-9f6e-6ce67a12156d-image.png

                          589aaa46-362c-49b6-8a23-ac12d0ec9126-image.png

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

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