From 14c87856e72145d08a7160ea8bb376828df4664d Mon Sep 17 00:00:00 2001 From: lyf <169361657@qq.com> Date: Sat, 28 Mar 2026 04:31:23 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B7=9F=E6=96=B0=E5=8F=91=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../armor_finder/send_target/send_target.cpp | 57 ++++++++++++------- 1 file changed, 35 insertions(+), 22 deletions(-) diff --git a/armor/src/armor_finder/send_target/send_target.cpp b/armor/src/armor_finder/send_target/send_target.cpp index ee643b9..c61a9d0 100644 --- a/armor/src/armor_finder/send_target/send_target.cpp +++ b/armor/src/armor_finder/send_target/send_target.cpp @@ -5,42 +5,55 @@ #include #include #include +#include +#include -static bool sendTarget(Serial &serial, double x, double y, double z, uint16_t shoot_delay) { - static short x_tmp, y_tmp, z_tmp; - uint8_t buff[10]; +// ANGLE_SCALE: 角度单位换算系数。发出的整数 = yaw_deg / ANGLE_SCALE +// 例: 1.0f → 单位为度; 0.01f → 单位为厘度(精度更高) +static constexpr float ANGLE_SCALE = 1.0f; +static bool sendTarget(Serial &serial, double yaw_deg, double pitch_deg, double dist, + uint16_t shoot_delay, char type = 'r') { + // static short x_tmp, y_tmp, z_tmp; + // uint8_t buff[10]; #ifdef WITH_COUNT_FPS static time_t last_time = time(nullptr); static int fps; time_t t = time(nullptr); if (last_time != t) { last_time = t; - cout << "Armor: fps:" << fps << ", (" << x << "," << y << "," << z << ")" << endl; + cout << "Armor: fps:" << fps << ", yaw=" << yaw_deg + << " pitch=" << pitch_deg << " dist=" << dist << endl; fps = 0; } fps += 1; #endif -#define MINMAX(value, min, max) value = ((value) < (min)) ? (min) : ((value) > (max) ? (max) : (value)) + // ---- 新格式: 字符串帧 ---- + // 格式: "# s *\n" + // type: 'r'=红色装甲板, 'b'=蓝色, 'u'=未知 + int16_t yaw_tmp = static_cast(yaw_deg / ANGLE_SCALE); + int16_t pitch_tmp = static_cast(pitch_deg / ANGLE_SCALE); + std::string frame = fmt::format("s {} {} {} {} e\n", yaw_tmp, pitch_tmp, dist, shoot_delay); + return serial.WriteData(reinterpret_cast(frame.data()), frame.size()); - x_tmp = static_cast(x * (32768 - 1) / 100); - y_tmp = static_cast(y * (32768 - 1) / 100); - z_tmp = static_cast(z * (32768 - 1) / 1000); - - buff[0] = 's'; - buff[1] = static_cast((x_tmp >> 8) & 0xFF); - buff[2] = static_cast((x_tmp >> 0) & 0xFF); - buff[3] = static_cast((y_tmp >> 8) & 0xFF); - buff[4] = static_cast((y_tmp >> 0) & 0xFF); - buff[5] = static_cast((z_tmp >> 8) & 0xFF); - buff[6] = static_cast((z_tmp >> 0) & 0xFF); - buff[7] = static_cast((shoot_delay >> 8) & 0xFF); - buff[8] = static_cast((shoot_delay >> 0) & 0xFF); - buff[9] = 'e'; -// if(buff[7]<<8 | buff[8]) -// cout << (buff[7]<<8 | buff[8]) << endl; - return serial.WriteData(buff, sizeof(buff)); + // ---- 原始二进制打包(已注释)---- + // static short x_tmp, y_tmp, z_tmp; + // uint8_t buff[10]; + // x_tmp = static_cast(yaw_deg * (32768 - 1) / 100); + // y_tmp = static_cast(pitch_deg * (32768 - 1) / 100); + // z_tmp = static_cast(dist * (32768 - 1) / 1000); + // buff[0] = 's'; + // buff[1] = static_cast((x_tmp >> 8) & 0xFF); + // buff[2] = static_cast((x_tmp >> 0) & 0xFF); + // buff[3] = static_cast((y_tmp >> 8) & 0xFF); + // buff[4] = static_cast((y_tmp >> 0) & 0xFF); + // buff[5] = static_cast((z_tmp >> 8) & 0xFF); + // buff[6] = static_cast((z_tmp >> 0) & 0xFF); + // buff[7] = static_cast((shoot_delay >> 8) & 0xFF); + // buff[8] = static_cast((shoot_delay >> 0) & 0xFF); + // buff[9] = 'e'; + // return serial.WriteData(buff, sizeof(buff)); } bool ArmorFinder::sendBoxPosition(uint16_t shoot_delay) {