wangyingjie 2 miesięcy temu
rodzic
commit
b08007d6b4
3 zmienionych plików z 31 dodań i 34 usunięć
  1. 1 1
      sr71_drive/CMakeLists.txt
  2. 4 1
      sr71_drive/README.md
  3. 26 32
      sr71_drive/src/main.cpp

+ 1 - 1
sr71_drive/CMakeLists.txt

@@ -1,6 +1,6 @@
 cmake_minimum_required(VERSION 3.15)
 
-project(example_project)
+project(RS71_Drive)
 
 message("============== 构建项目开始 ==============")
 

+ 4 - 1
sr71_drive/README.md

@@ -13,4 +13,7 @@
 cmake 参数 -DCMAKE_TOOLCHAIN_FILE=~/env/vcpkg/scripts/buildsystems/vcpkg.cmake
 
 lsusb
-sudo chmod 777 /dev/bus/usb/001/015
+sudo chmod 777 /dev/bus/usb/001/015
+
+
+3 0 0x1 0x1c00

+ 26 - 32
sr71_drive/src/main.cpp

@@ -36,12 +36,12 @@ int main()
         for (const auto &frame: data)
         {
             // 测试打印查看 -------
-            printf("ID: 0x%X TimeStamp: %u Data:", frame.id, frame.timestamp);
-            for (auto byte: frame.data)
-            {
-                printf(" %02X", byte);
-            }
-            printf("\n");
+            // printf("ID: 0x%X TimeStamp: %u Data:", frame.id, frame.timestamp);
+            // for (auto byte: frame.data)
+            // {
+            //     printf(" %02X", byte);
+            // }
+            // printf("\n");
             // 测试打印查看 -------
 
             // 解析数据
@@ -50,9 +50,9 @@ int main()
                 TargetInfo target;
                 // 目标ID (字节0)
                 target.id = frame.data[0];
-                // 目标纵向距离
+                // 目标纵向距离 Y
                 target.distance_long = (frame.data[1] * 32 + (frame.data[2] >> 3)) * 0.1 - 500;
-                // 目标横向距离
+                // 目标横向距离 X
                 target.distance_lat = ((frame.data[2] & 0x07) * 256 + frame.data[3]) * 0.1 - 102.3;
                 // 目标纵向速度
                 target.velocity_long = (frame.data[4] * 4 + (frame.data[5] >> 6)) * 0.25 - 128;
@@ -60,39 +60,33 @@ int main()
                 target.velocity_lat = ((frame.data[5] & 0x3F) * 8 + (frame.data[6] >> 5)) * 0.25 - 64;
                 // 动态属性
                 target.dyn_prop = (frame.data[6] & 0x07);
-                // RCS
+                // RCS 雷达截面积
                 target.rcs = (frame.data[7] * 0.5) - 64;
-                // 打印结果
-                printf("Target ID: %u\n", target.id);
-                printf("Distance Longitudinal: %.2fm\n", target.distance_long);
-                printf("Distance Lateral: %.2fm\n", target.distance_lat);
-                printf("Velocity Longitudinal: %.2fm/s\n", target.velocity_long);
-                printf("Dynamic Property: %u\n", target.dyn_prop);
-                printf("Velocity Lateral: %.2fm/s\n", target.velocity_lat);
-                printf("RCS: %.2fdB㎡\n", target.rcs);
 
-                // 计算目标径向距离和角度
-                float radial_distance = sqrt(
-                    target.distance_long * target.distance_long + target.distance_lat * target.distance_lat);
-                float theta = atan2(target.distance_lat, target.distance_long) * 180 / M_PI; // 转换为度数
-                printf("Radial Distance: %.2fm\n", radial_distance);
-                printf("Angle (θ): %.2f°\n", theta);
+                printf("    ID: %u\t 纵向距离 Y: %.2fm\t 横向距离 X: %.2fm \t 纵向速度: %.2fm/s \t 横向速度: %.2fm/s \t 动态属性: %u \t RCS: %.2fdB㎡\n", target.id, target.distance_long, target.distance_lat, target.velocity_long, target.velocity_lat, target.dyn_prop, target.rcs);
+
+                // // 计算目标径向距离和角度
+                // float radial_distance = sqrt(target.distance_long * target.distance_long + target.distance_lat * target.distance_lat);
+                // float theta = atan2(target.distance_lat, target.distance_long) * 180 / M_PI; // 转换为度数
+                // // 计算目标速度
+                // float velocity = target.velocity_long * cos(theta * M_PI / 180) + target.velocity_lat * sin(theta * M_PI / 180);
+                // printf("    径向距离 : %.2fm\t 角度: %.2f°\t 速度: %.2fm/s\t\n", radial_distance, theta, velocity);
+                // float x_ = target.distance_lat;
+                // float y_ = target.distance_long;
+                // float z_ = 0;
+                // printf("    x: %.2f\t y: %.2f\t z: %.2f\t\n", x_, y_, z_);
 
-                // 计算目标速度
-                float velocity = target.velocity_long * cos(theta * M_PI / 180) + target.velocity_lat * sin(
-                                     theta * M_PI / 180);
-                printf("Velocity: %.2fm/s\n", velocity);
-            } else if (frame.id == 0x60A)
+            }
+            else if (frame.id == 0x60A)
             {
-                std::cout << "-------------" << std::endl;
+                std::cout << "----------------------" << std::endl;
                 TargetListHeader header;
 
                 // 解析目标数量
                 header.object_num = frame.data[0];
-                printf("Object Number: %d\n", header.object_num);
-                // 解析循环计数
                 header.measurement_count = (static_cast<uint16_t>(frame.data[3]) << 8) | frame.data[2];
-                printf("Measurement Count: %d\n", header.measurement_count);
+                printf("    目标数量: %d\t, 循环计数: %d\t\n", header.object_num, header.measurement_count);
+
                 // // 解析CAN接口版本号
                 // header.interface_version = (frame.data[4] >> 4) & 0x0F;
                 // printf("Interface Version: %d\n", header.interface_version);