From d1e2234a43afc1ddbc2a19e08ec58783621c4d1d Mon Sep 17 00:00:00 2001 From: spdis Date: Sat, 13 Jun 2026 13:30:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=AD=BB=E4=BB=A3=E7=A0=81=E6=B8=85=E7=90=86+?= =?UTF-8?q?=E8=B6=8A=E7=95=8C=E4=BF=AE=E5=A4=8D+=E6=9E=84=E5=BB=BA?= =?UTF-8?q?=E5=8E=BB=E9=87=8D:=20=E6=B3=A8=E9=87=8APIDController/=E5=88=A0?= =?UTF-8?q?=E9=99=A4TimerVideo,=20floodFill=E5=8D=8A=E5=BE=8410=E2=86=925,?= =?UTF-8?q?=20ctl.sh=E5=88=A0GPIO66/75,=20CMake=E5=8F=8C=E9=87=8D=E4=BA=92?= =?UTF-8?q?=E6=96=A5=E5=90=88=E5=B9=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 5 +++-- ctl.sh | 5 +---- lib/Timer.h | 28 ---------------------------- lib/video.h | 35 ----------------------------------- main/CMakeLists.txt | 10 ---------- src/Timer.cpp | 36 ------------------------------------ src/image_cv.cpp | 2 +- src/video.cpp | 20 -------------------- 8 files changed, 5 insertions(+), 136 deletions(-) delete mode 100644 lib/Timer.h delete mode 100644 lib/video.h delete mode 100644 src/Timer.cpp delete mode 100644 src/video.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 8eadcf8..be26cba 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,8 +27,9 @@ aux_source_directory(src DIR_SRCS) # 排除暂不使用的模块(源文件保留) # vl53l0x.cpp — 激光测距, 硬件未接 -# zebra_detect.cpp — 经典斑马线检测, 已由 nanodet 模型替代 -list(FILTER DIR_SRCS EXCLUDE REGEX "(vl53l0x\\.cpp|zebra_detect\\.cpp)") +# zebra_detect.cpp — 经典斑马线检测, 已被 Mild 模型替代 +# PIDController.cpp — PID 类未使用 (电机开环直驱) +list(FILTER DIR_SRCS EXCLUDE REGEX "(vl53l0x\\.cpp|zebra_detect\\.cpp|PIDController\\.cpp)") # 静态库 + 主程序 add_library(common_lib STATIC ${DIR_SRCS}) diff --git a/ctl.sh b/ctl.sh index 7774112..1043929 100644 --- a/ctl.sh +++ b/ctl.sh @@ -8,20 +8,17 @@ PWMPERIOD=50000 init_pins() { echo "[demo] 初始化引脚..." - for pin in 73 12 13 66 67 75 72; do + for pin in 73 12 13 67 72; do echo $pin > /sys/class/gpio/export 2>/dev/null done echo out > /sys/class/gpio/gpio73/direction 2>/dev/null echo out > /sys/class/gpio/gpio12/direction 2>/dev/null echo out > /sys/class/gpio/gpio13/direction 2>/dev/null - echo out > /sys/class/gpio/gpio66/direction 2>/dev/null echo in > /sys/class/gpio/gpio67/direction 2>/dev/null - echo out > /sys/class/gpio/gpio75/direction 2>/dev/null echo in > /sys/class/gpio/gpio72/direction 2>/dev/null echo 1 > /sys/class/gpio/gpio73/value 2>/dev/null echo 0 > /sys/class/gpio/gpio12/value 2>/dev/null echo 0 > /sys/class/gpio/gpio13/value 2>/dev/null - echo 0 > /sys/class/gpio/gpio66/value 2>/dev/null for ch in 1 2; do echo $ch > /sys/class/pwm/pwmchip${PWMCHIP}/export 2>/dev/null diff --git a/lib/Timer.h b/lib/Timer.h deleted file mode 100644 index 7fdde33..0000000 --- a/lib/Timer.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef TIMER_H -#define TIMER_H - -#include -#include -#include -#include -#include - -class Timer -{ -public: - Timer(int interval_ms, std::function task); - ~Timer(); - - void start(); - void stop(); - -private: - void run(); - - int interval; // Interval in milliseconds - std::function task; - std::atomic running; - std::thread worker; -}; - -#endif // TIMER_H diff --git a/lib/video.h b/lib/video.h deleted file mode 100644 index 29dc18e..0000000 --- a/lib/video.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef VIDEO_H_ -#define VIDEO_H_ - -#include -#include -#include -#include -#include -#include -#include - -#include "Timer.h" -#include "frame_buffer.h" - -class Video -{ -public: - Video(const std::string &filename, double fps); - ~Video(void); - - Timer timer; - cv::Mat frame; - std::mutex frameMutex; -private: - cv::VideoCapture cap; - cv::Mat fbImage; - cv::Mat resizedFrame; - void streamCapture(void); - int screenHeight, screenWidth; - int newWidth, newHeight; - int fb; - uint16_t *fb_buffer; -}; - -#endif \ No newline at end of file diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 4cec894..3b9a0b6 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -1,13 +1,3 @@ # 主程序 add_executable(smartcar_demo1 main.cpp) - -# 暂时排除激光测距(未使用),保留源文件 -set(EXCLUDE_VL53L0X vl53l0x.cpp) - -# 排除死代码:斑马线传统检测(已由 nanodet 模型替代)、编码器采集(开环控制不需要) -set(EXCLUDE_DEAD zebra_detect.cpp encoder.cpp) - -# 从静态库源文件列表中移除 -list(FILTER DIR_SRCS EXCLUDE REGEX "(${EXCLUDE_VL53L0X}|${EXCLUDE_DEAD})") - target_link_libraries(smartcar_demo1 common_lib ${OpenCV_LIBS}) \ No newline at end of file diff --git a/src/Timer.cpp b/src/Timer.cpp deleted file mode 100644 index 0b78115..0000000 --- a/src/Timer.cpp +++ /dev/null @@ -1,36 +0,0 @@ -#include "Timer.h" - -Timer::Timer(int interval_ms, std::function task) - : interval(interval_ms), task(task), running(false) {} - -Timer::~Timer() -{ - stop(); // Ensure the timer is stopped in the destructor -} - -void Timer::start() -{ - running = true; - worker = std::thread(&Timer::run, this); -} - -void Timer::stop() -{ - running = false; - if (worker.joinable()) - { - worker.join(); - } -} - -void Timer::run() -{ - while (running) - { - std::this_thread::sleep_for(std::chrono::milliseconds(interval)); - if (running) - { - std::thread(task).detach(); - } - } -} diff --git a/src/image_cv.cpp b/src/image_cv.cpp index 3a8f5fc..9ab62af 100644 --- a/src/image_cv.cpp +++ b/src/image_cv.cpp @@ -129,7 +129,7 @@ cv::Mat find_road(cv::Mat &frame) // 4. 在种子点位置画一个白色实心圆,确保种子点落在赛道区域内 // 避免因二值化偶尔在种子位置为黑色导致洪泛失败 - cv::circle(morphologyExFrame, seedPoint, 10, 255, -1); + cv::circle(morphologyExFrame, seedPoint, 5, 255, -1); // 5. 洪泛填充参数 cv::Scalar newVal(128); // 填充值 = 128 (标记为赛道内部) diff --git a/src/video.cpp b/src/video.cpp deleted file mode 100644 index 2cfc1a2..0000000 --- a/src/video.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include "video.h" - -Video::Video(const std::string &filename, double fps) - : timer(static_cast(1000 / fps), std::bind(&Video::streamCapture, this)), cap(filename) -{ - streamCapture(); -} - -Video::~Video(void) -{ - timer.stop(); -} - -void Video::streamCapture(void) -{ - frameMutex.lock(); - cap.read(frame); - frameMutex.unlock(); -} - \ No newline at end of file