From 691e9c80bdddcb0e1ddd569eb8c4d67e600f5a64 Mon Sep 17 00:00:00 2001 From: Orange <2314753575@qq.com> Date: Wed, 22 Jul 2026 17:32:00 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=8C=E7=BB=B4=E7=A0=81=E6=A3=80=E6=B5=8B?= =?UTF-8?q?=EF=BC=9A=E6=B7=BB=E5=8A=A0=E4=BA=86=E5=88=A4=E6=96=AD=E9=A1=BA?= =?UTF-8?q?=E9=80=86=E6=97=B6=E9=92=88=E7=9A=84=E8=A7=84=E5=88=99=E5=92=8C?= =?UTF-8?q?=E5=8F=91=E5=B8=83=E5=86=85=E5=AE=B9=EF=BC=9B=E4=B8=B4=E6=97=B6?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=8F=91=E5=B8=83=E8=AF=9D=E9=A2=98=E5=88=B0?= =?UTF-8?q?=E4=BA=86vlm=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/qr_detection/launch/qr_detect.launch.py | 5 +--- .../launch/qr_usb_camera.launch.py | 24 +++++++++---------- src/qr_detection/src/qr_detect.cpp | 19 ++++++++++----- .../include/racing_control/racing_control.hpp | 8 +++---- src/racing_control/src/racing_control.cpp | 7 ++++++ 5 files changed, 36 insertions(+), 27 deletions(-) diff --git a/src/qr_detection/launch/qr_detect.launch.py b/src/qr_detection/launch/qr_detect.launch.py index b5fbc3c..8f300c5 100644 --- a/src/qr_detection/launch/qr_detect.launch.py +++ b/src/qr_detection/launch/qr_detect.launch.py @@ -9,12 +9,9 @@ from launch_ros.actions import Node def generate_launch_description(): - image_topic = LaunchConfiguration("image_topic", default="/image_raw") + image_topic = LaunchConfiguration("image_topic", default="/image") return LaunchDescription([ - DeclareLaunchArgument("image_topic", - default_value="/image_raw", - description="相机图像话题 (bgr8 / rgb8 / nv12 / mono8)"), Node( package="qr_detection", diff --git a/src/qr_detection/launch/qr_usb_camera.launch.py b/src/qr_detection/launch/qr_usb_camera.launch.py index 7577018..beee20a 100644 --- a/src/qr_detection/launch/qr_usb_camera.launch.py +++ b/src/qr_detection/launch/qr_usb_camera.launch.py @@ -16,17 +16,17 @@ def generate_launch_description(): use_buffer = LaunchConfiguration("use_buffer", default="true") # USB 相机驱动 (v4l2) - v4l2_camera = Node( - package="v4l2_camera", - executable="v4l2_camera_node", - name="usb_camera", - parameters=[{ - "video_device": camera_device, - "image_size": [640, 480], - "pixel_format": "YUYV", - }], - remappings=[("image_raw", image_topic)], - ) + # camera = Node( + # package="hobot_usb_cam", + # executable="hobot_usb_cam", + # name="hobot_usb_cam", + # parameters=[{ + # "video_device": camera_device, + # "image_size": [640, 480], + # "pixel_format": "YUYV", + # }], + # remappings=[("image_raw", image_topic)], + # ) # QR 识别 qr_detector = Node( @@ -60,6 +60,6 @@ def generate_launch_description(): DeclareLaunchArgument("use_buffer", default_value="true", description="信号消失后保持最近结果"), - v4l2_camera, + # v4l2_camera, qr_detector, ]) diff --git a/src/qr_detection/src/qr_detect.cpp b/src/qr_detection/src/qr_detect.cpp index 50969c2..225e13a 100644 --- a/src/qr_detection/src/qr_detect.cpp +++ b/src/qr_detection/src/qr_detect.cpp @@ -34,8 +34,9 @@ public: std::bind(&QrDetectNode::sign_cb, this, std::placeholders::_1)); pub_ = create_publisher("qr_results", 10); + pub_tts_ = create_publisher("/vlm_result", 10); - RCLCPP_INFO(get_logger(), "QR Detect ready, topic=%s", image_topic_.c_str()); + RCLCPP_INFO(get_logger(), "QR Detect ready, topic=%s, tts topic=/vlm_result", image_topic_.c_str()); } private: @@ -84,13 +85,18 @@ private: auto out = std_msgs::msg::String(); if (n > 0) { - out.data = zimg.symbol_begin()->get_data(); - if (out.data != last_) { - RCLCPP_INFO(get_logger(), "QR: %s", out.data.c_str()); - last_ = out.data; + const std::string qr_data = zimg.symbol_begin()->get_data(); + if (qr_data != last_) { + RCLCPP_INFO(get_logger(), "QR: %s", qr_data.c_str()); + last_ = qr_data; + } + + if (!qr_data.empty() && qr_data.find_first_not_of("0123456789") == std::string::npos) { + out.data = qr_data + " " + (((qr_data.back() - '0') % 2 == 1) ? "顺时针" : "逆时针"); + pub_->publish(out); + pub_tts_->publish(out); // 同时发给TTS播报 } } - pub_->publish(out); } void sign_cb(const std_msgs::msg::Int32::SharedPtr msg) @@ -102,6 +108,7 @@ private: rclcpp::Subscription::SharedPtr sub_; rclcpp::Subscription::SharedPtr sign_sub_; rclcpp::Publisher::SharedPtr pub_; + rclcpp::Publisher::SharedPtr pub_tts_; // 发给TTS语音播报 bool enabled_; std::string image_topic_; diff --git a/src/racing_control/include/racing_control/racing_control.hpp b/src/racing_control/include/racing_control/racing_control.hpp index d2b8b2d..cb1d3db 100644 --- a/src/racing_control/include/racing_control/racing_control.hpp +++ b/src/racing_control/include/racing_control/racing_control.hpp @@ -6,6 +6,7 @@ 3 - 到达任务二起始阶段,执行顺/逆时针绕圈(可集成图生文) 4 - 减速拍照,图像传入图生文节点,随后回到3(备用) 5 - 完整走完一圈,执行任务三 + 6 - 到达终点,停止 2. 全部流程 启动小车->slamtoolbox开始建图,并开始发布导航命令(这时候小车还不能动)->打开电机开关,小车开始行动->走到一半扫到二维码,发布在/qr_results上->停掉二维码节点(sign=5)和导航1,同时开始导航2到任务二入口并顺逆时针转圈->到达指定位置触发一次vlm请求->开始语音播报同时完成任务二、三 */ @@ -17,16 +18,13 @@ static int ENTRY = 2; static int CIRCLE = 3; static int VLM = 4; static int TASK3 = 5; +static int END = 6; class RacingControl : public rclcpp::Node { public: - RacingControl() : Node("racing_control") - { - // 初始化状态指令 - state_command_ = QR_SEARCHING; - } + RacingControl(); private: // 状态指令变量 int state_command_; diff --git a/src/racing_control/src/racing_control.cpp b/src/racing_control/src/racing_control.cpp index e69de29..8c04fbe 100644 --- a/src/racing_control/src/racing_control.cpp +++ b/src/racing_control/src/racing_control.cpp @@ -0,0 +1,7 @@ +#include "racing_control/racing_control.hpp" + +RacingControl : Node("racing_control") + { + // 初始化状态指令 + state_command_ = QR_SEARCHING; + } \ No newline at end of file