@小鱼 抱歉,我这一节都是直接复制黏贴,没注意看源码,其实原文"2.话题之RCLCPP实现"那里用API设计发布者时展示的源码只是面向对象设计的类TopicPublisher01,没有main函数,导致编译时报错了
330709390 发布的最新帖子
-
RE: ros2用colcon编译时报错文件依赖找不到
-
RE: ros2用colcon编译时报错文件依赖找不到
@小鱼
这是cmakelistcmake_minimum_required(VERSION 3.8) project(example_topic_rclcpp) 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(rclcpp REQUIRED) find_package(std_msgs REQUIRED) if(BUILD_TESTING) find_package(ament_lint_auto REQUIRED) # the following line skips the linter which checks for copyrights # comment the line when a copyright and license is added to all source files set(ament_cmake_copyright_FOUND TRUE) # the following line skips cpplint (only works in a git repo) # comment the line when this package is in a git repo and when # a copyright and license is added to all source files set(ament_cmake_cpplint_FOUND TRUE) ament_lint_auto_find_test_dependencies() endif() add_executable(topic_publisher_01 src/topic_publisher_01.cpp) ament_target_dependencies(topic_publisher_01 rclcpp std_msgs) ament_package()
这是package.xml
<?xml version="1.0"?> <?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?> <package format="3"> <name>example_topic_rclcpp</name> <version>0.0.0</version> <description>TODO: Package description</description> <maintainer email="bigbean@todo.todo">bigbean</maintainer> <license>TODO: License declaration</license> <buildtool_depend>ament_cmake</buildtool_depend> <depend>rclcpp</depend> <depend>std_msgs</depend> <test_depend>ament_lint_auto</test_depend> <test_depend>ament_lint_common</test_depend> <export> <build_type>ament_cmake</build_type> </export> </package>
这是cpp文件
#include "rclcpp/rclcpp.hpp" #include "std_msgs/msg/string.hpp" class TopicPublisher01 : public rclcpp::Node { public: // 构造函数,有一个参数为节点名称 TopicPublisher01(std::string name) : Node(name) { RCLCPP_INFO(this->get_logger(), "大家好,我是%s.", name.c_str()); // 创建发布者 command_publisher_ = this->create_publisher<std_msgs::msg::String>("command", 10); // 创建定时器,500ms为周期,定时发布 timer_ = this->create_wall_timer(std::chrono::milliseconds(500), std::bind(&TopicPublisher01::timer_callback, this)); } private: void timer_callback() { // 创建消息 std_msgs::msg::String message; message.data = "forward"; // 日志打印 RCLCPP_INFO(this->get_logger(), "Publishing: '%s'", message.data.c_str()); // 发布消息 command_publisher_->publish(message); } // 声名定时器指针 rclcpp::TimerBase::SharedPtr timer_; // 声明话题发布者指针 rclcpp::Publisher<std_msgs::msg::String>::SharedPtr command_publisher_; };
这是文件夹顺序
chapt3_ws
--|src
--|--|example_topic_rclcpp
--|--|--|src
--|--|--|--|topic_publisher_01,cpp
--|--|--|CMakeLists.txt
--|--|--|package.xml
--|--|--|include
--|--|--|--|example_topic_rclcpp -
RE: MicroROS开发时将程序烧录失败错误代码1
@小鱼 嗯,还有一个问题,就是docker那边已经下载好了,但启动很缓慢,几十分钟都还没好,没有达到手册里的那几个步骤,请问初次启动是这么慢吗
一直卡在以下界面1692670448.813736] info | TermiosAgentLinux.cpp | init | running... | fd: 3 [1692670448.815704] info | Root.cpp | set_verbose_level | logger setup | verbose_level: 6
-
MicroROS开发时将程序烧录失败错误代码1
Warning! Please install `99-platformio-udev.rules`. More details: https://docs.platformio.org/en/latest/core/installation/udev-rules.html CURRENT: upload_protocol = esptool Looking for upload port... Auto-detected: /dev/ttyUSB0 Uploading .pio/build/featheresp32/firmware.bin esptool.py v4.2.1 Serial port /dev/ttyUSB0 Connecting.... Traceback (most recent call last): File "/home/bigbean/.platformio/packages/tool-esptoolpy/esptool.py", line 34, in <module> esptool._main() File "/home/bigbean/.platformio/packages/tool-esptoolpy/esptool/__init__.py", line 1004, in _main main() File "/home/bigbean/.platformio/packages/tool-esptoolpy/esptool/__init__.py", line 646, in main esp = esp or get_default_connected_device( File "/home/bigbean/.platformio/packages/tool-esptoolpy/esptool/__init__.py", line 895, in get_default_connected_device _esp.connect(before, connect_attempts) File "/home/bigbean/.platformio/packages/tool-esptoolpy/esptool/loader.py", line 631, in connect last_error = self._connect_attempt( File "/home/bigbean/.platformio/packages/tool-esptoolpy/esptool/loader.py", line 572, in _connect_attempt self.sync() File "/home/bigbean/.platformio/packages/tool-esptoolpy/esptool/loader.py", line 435, in sync val, _ = self.command( File "/home/bigbean/.platformio/packages/tool-esptoolpy/esptool/loader.py", line 375, in command p = self.read() File "/home/bigbean/.platformio/packages/tool-esptoolpy/esptool/loader.py", line 307, in read return next(self._slip_reader) File "/home/bigbean/.platformio/packages/tool-esptoolpy/esptool/loader.py", line 1402, in slip_reader read_bytes = port.read(1 if waiting == 0 else waiting) File "/home/bigbean/.platformio/penv/lib/python3.10/site-packages/serial/serialposix.py", line 595, in read raise SerialException( serial.serialutil.SerialException: device reports readiness to read but returned no data (device disconnected or multiple access on port?) *** [upload] Error 1 ===================================== [FAILED] Took 3.75 seconds ===================================== * 终端进程“platformio 'run', '--target', 'upload'”已终止,退出代码: 1。 * 终端将被任务重用,按任意键关闭。 * 正在文件夹 example10_hello_microros 中执行任务: platformio run --target upload Processing featheresp32 (platform: espressif32; board: featheresp32; framework: arduino) ------------------------------------------------------------------------------------------------------- Verbose mode can be enabled via `-v, --verbose` option CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/featheresp32.html PLATFORM: Espressif 32 (5.2.0) > Adafruit ESP32 Feather HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash DEBUG: Current (cmsis-dap) External (cmsis-dap, esp-bridge, esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa) PACKAGES: - framework-arduinoespressif32 @ 3.20005.220925 (2.0.5) - tool-esptoolpy @ 1.40201.0 (4.2.1) - tool-mkfatfs @ 2.0.1 - tool-mklittlefs @ 1.203.210628 (2.3) - tool-mkspiffs @ 2.230.0 (2.30) - toolchain-xtensa-esp32 @ 8.4.0+2021r2-patch3 LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf LDF Modes: Finder ~ chain, Compatibility ~ soft Installing pyyaml with pip at PlatformIO environment /home/bigbean/.platformio/penv/bin/python -m pip install pyyaml Requirement already satisfied: pyyaml in /home/bigbean/.platformio/penv/lib/python3.10/site-packages (6.0.1) Installing markupsafe==2.0.1 with pip at PlatformIO environment /home/bigbean/.platformio/penv/bin/python -m pip install markupsafe==2.0.1 Requirement already satisfied: markupsafe==2.0.1 in /home/bigbean/.platformio/penv/lib/python3.10/site-packages (2.0.1) Configuring featheresp32 with transport serial micro-ROS already built Found 33 compatible libraries Scanning dependencies... Dependency Graph |-- micro_ros_platformio @ 0.0.1+sha.085c5dd Building in release mode Retrieving maximum program size .pio/build/featheresp32/firmware.elf Checking size .pio/build/featheresp32/firmware.elf Advanced Memory Usage is available via "PlatformIO Home > Project Inspect" RAM: [= ] 15.0% (used 49144 bytes from 327680 bytes) Flash: [== ] 22.6% (used 296213 bytes from 1310720 bytes) Configuring upload protocol... AVAILABLE: cmsis-dap, esp-bridge, esp-prog, espota, esptool, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa CURRENT: upload_protocol = esptool Looking for upload port... Warning! Please install `99-platformio-udev.rules`. More details: https://docs.platformio.org/en/latest/core/installation/udev-rules.html Auto-detected: /dev/ttyUSB0 Uploading .pio/build/featheresp32/firmware.bin esptool.py v4.2.1 Serial port /dev/ttyUSB0 Connecting..... Traceback (most recent call last): File "/home/bigbean/.platformio/packages/tool-esptoolpy/esptool.py", line 34, in <module> esptool._main() File "/home/bigbean/.platformio/packages/tool-esptoolpy/esptool/__init__.py", line 1004, in _main main() File "/home/bigbean/.platformio/packages/tool-esptoolpy/esptool/__init__.py", line 646, in main esp = esp or get_default_connected_device( File "/home/bigbean/.platformio/packages/tool-esptoolpy/esptool/__init__.py", line 895, in get_default_connected_device _esp.connect(before, connect_attempts) File "/home/bigbean/.platformio/packages/tool-esptoolpy/esptool/loader.py", line 631, in connect last_error = self._connect_attempt( File "/home/bigbean/.platformio/packages/tool-esptoolpy/esptool/loader.py", line 572, in _connect_attempt self.sync() File "/home/bigbean/.platformio/packages/tool-esptoolpy/esptool/loader.py", line 445, in sync val, _ = self.command() File "/home/bigbean/.platformio/packages/tool-esptoolpy/esptool/loader.py", line 375, in command p = self.read() File "/home/bigbean/.platformio/packages/tool-esptoolpy/esptool/loader.py", line 307, in read return next(self._slip_reader) File "/home/bigbean/.platformio/packages/tool-esptoolpy/esptool/loader.py", line 1402, in slip_reader read_bytes = port.read(1 if waiting == 0 else waiting) File "/home/bigbean/.platformio/penv/lib/python3.10/site-packages/serial/serialposix.py", line 595, in read raise SerialException( serial.serialutil.SerialException: device reports readiness to read but returned no data (device disconnected or multiple access on port?) *** [upload] Error 1
-
ros2用colcon编译时报错文件依赖找不到
Starting >>> example_topic_rclcpp --- stderr: example_topic_rclcpp /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/Scrt1.o: in function `_start': (.text+0x1b): undefined reference to `main' collect2: error: ld returned 1 exit status gmake[2]: *** [CMakeFiles/topic_publisher_01.dir/build.make:159: topic_publisher_01] Error 1 gmake[1]: *** [CMakeFiles/Makefile2:137: CMakeFiles/topic_publisher_01.dir/all] Error 2 gmake: *** [Makefile:146: all] Error 2 --- Failed <<< example_topic_rclcpp [0.74s, exited with code 2] Summary: 0 packages finished [0.88s] 1 package failed: example_topic_rclcpp 1 package had stderr output: example_topic_rclcpp
求问各位这里怎么出错的,一步一步跟着小鱼的教程来的,功能包也编译进去了,cmakelist和package都改了,文件目录也没错,但节点文件依旧标红,编译时也确实报了错