死代码清理+越界修复+构建去重: 注释PIDController/删除TimerVideo, floodFill半径10→5, ctl.sh删GPIO66/75, CMake双重互斥合并
This commit is contained in:
+3
-2
@@ -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})
|
||||
|
||||
@@ -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
|
||||
|
||||
-28
@@ -1,28 +0,0 @@
|
||||
#ifndef TIMER_H
|
||||
#define TIMER_H
|
||||
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
#include <atomic>
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
|
||||
class Timer
|
||||
{
|
||||
public:
|
||||
Timer(int interval_ms, std::function<void()> task);
|
||||
~Timer();
|
||||
|
||||
void start();
|
||||
void stop();
|
||||
|
||||
private:
|
||||
void run();
|
||||
|
||||
int interval; // Interval in milliseconds
|
||||
std::function<void()> task;
|
||||
std::atomic<bool> running;
|
||||
std::thread worker;
|
||||
};
|
||||
|
||||
#endif // TIMER_H
|
||||
-35
@@ -1,35 +0,0 @@
|
||||
#ifndef VIDEO_H_
|
||||
#define VIDEO_H_
|
||||
|
||||
#include <opencv2/opencv.hpp>
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <fcntl.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <linux/fb.h>
|
||||
|
||||
#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
|
||||
@@ -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})
|
||||
@@ -1,36 +0,0 @@
|
||||
#include "Timer.h"
|
||||
|
||||
Timer::Timer(int interval_ms, std::function<void()> 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -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 (标记为赛道内部)
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
#include "video.h"
|
||||
|
||||
Video::Video(const std::string &filename, double fps)
|
||||
: timer(static_cast<int>(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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user