TTL-Send_solver #2
@@ -4,6 +4,7 @@
|
|||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <opencv2/opencv.hpp>
|
#include <opencv2/opencv.hpp>
|
||||||
|
|
||||||
@@ -25,7 +26,7 @@ void output_control_data(const cv::Point2f* ballistic_point,
|
|||||||
bool use_ttl) {
|
bool use_ttl) {
|
||||||
// Only send data when TTL is enabled, meets frame interval, and has valid target
|
// Only send data when TTL is enabled, meets frame interval, and has valid target
|
||||||
if (use_ttl && frame_counter % 5 == 0 && ballistic_point != nullptr) {
|
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)
|
// Calculate offset (based on actual image center)
|
||||||
int ballistic_offset_x = static_cast<int>(ballistic_point->x - img_center.x);
|
int ballistic_offset_x = static_cast<int>(ballistic_point->x - img_center.x);
|
||||||
@@ -37,11 +38,14 @@ void output_control_data(const cv::Point2f* ballistic_point,
|
|||||||
else if (target_color == "blue") simplified_color = "b";
|
else if (target_color == "blue") simplified_color = "b";
|
||||||
|
|
||||||
// Construct send string
|
// 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
|
// Send data
|
||||||
if (ttl_communicator != nullptr) {
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ bool TTLCommunicator::send_data(const std::string& data) {
|
|||||||
std::cerr << "Error writing to serial port: " << strerror(errno) << std::endl;
|
std::cerr << "Error writing to serial port: " << strerror(errno) << std::endl;
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
std::cout << "Sent " << bytes_written << " bytes: " << data << std::endl;
|
std::cout << "Sent " << bytes_written << " bytes: " << data;
|
||||||
fsync(serial_fd); // Ensure data is sent
|
fsync(serial_fd); // Ensure data is sent
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user