From 3053029f140de11fae01e6f54a3377dd45eaeed2 Mon Sep 17 00:00:00 2001 From: lyf <169361657@qq.com> Date: Sun, 30 Nov 2025 21:26:07 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E8=BF=99=E9=87=8C=E5=AF=B9=E4=BA=8Ettl?= =?UTF-8?q?=E5=8F=91=E9=80=81=E7=9A=84=E5=AD=97=E7=AC=A6=E5=BD=A2=E5=BC=8F?= =?UTF-8?q?=E5=81=9A=E5=87=BA=E6=94=B9=E5=8F=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MindVisionMain.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/MindVisionMain.cpp b/src/MindVisionMain.cpp index 1250ebc..7ce0269 100644 --- a/src/MindVisionMain.cpp +++ b/src/MindVisionMain.cpp @@ -25,7 +25,7 @@ void output_control_data(const cv::Point2f* ballistic_point, bool use_ttl) { // Only send data when TTL is enabled, meets frame interval, and has valid target if (use_ttl && frame_counter % 5 == 0 && ballistic_point != nullptr) { - std::string send_str; + std::ostringstream send_str; // Calculate offset (based on actual image center) int ballistic_offset_x = static_cast(ballistic_point->x - img_center.x); @@ -37,11 +37,13 @@ void output_control_data(const cv::Point2f* ballistic_point, else if (target_color == "blue") simplified_color = "b"; // Construct send string - send_str = "s " + simplified_color + " " + std::to_string(ballistic_offset_x) + " " + std::to_string(ballistic_offset_y); + send_str << "s " << simplified_color << " " << std::to_string(ballistic_offset_x) << " " << std::to_string(ballistic_offset_y); // Send data if (ttl_communicator != nullptr) { - ttl_communicator->send_data(send_str); + ttl_communicator->send_data(send_str.str()); + }else{ + std::cerr << "Error: TTLCommunicator is a null pointer!" << std::endl; } } } From c2be6378b7d6eaed5df9775f60a05ab133ec85cf Mon Sep 17 00:00:00 2001 From: lyf <169361657@qq.com> Date: Mon, 1 Dec 2025 18:41:43 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E7=B2=98=E5=8C=85=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E5=B7=B2=E8=A7=A3=E5=86=B3=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MindVisionMain.cpp | 4 +++- src/TTLCommunicator.cpp | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/MindVisionMain.cpp b/src/MindVisionMain.cpp index 7ce0269..3e96743 100644 --- a/src/MindVisionMain.cpp +++ b/src/MindVisionMain.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include @@ -37,11 +38,12 @@ void output_control_data(const cv::Point2f* ballistic_point, else if (target_color == "blue") simplified_color = "b"; // Construct send string - send_str << "s " << simplified_color << " " << std::to_string(ballistic_offset_x) << " " << std::to_string(ballistic_offset_y); + send_str << "s " << simplified_color << " " << std::to_string(ballistic_offset_x) << " " << std::to_string(ballistic_offset_y) << "\n"; // Send data if (ttl_communicator != nullptr) { ttl_communicator->send_data(send_str.str()); + }else{ std::cerr << "Error: TTLCommunicator is a null pointer!" << std::endl; } diff --git a/src/TTLCommunicator.cpp b/src/TTLCommunicator.cpp index cc0e9da..f0bdd19 100644 --- a/src/TTLCommunicator.cpp +++ b/src/TTLCommunicator.cpp @@ -52,7 +52,7 @@ bool TTLCommunicator::send_data(const std::string& data) { std::cerr << "Error writing to serial port: " << strerror(errno) << std::endl; return false; } else { - std::cout << "Sent " << bytes_written << " bytes: " << data << std::endl; + std::cout << "Sent " << bytes_written << " bytes: " << data; fsync(serial_fd); // Ensure data is sent return true; }