修复四个关键bug: dest_fps限速/底行越界/255应为-1/删除debug文件重载
This commit is contained in:
+8
-11
@@ -33,27 +33,24 @@ int main(void)
|
||||
if (avoid_range_val > 0) g_cfg.cone_avoid_range = avoid_range_val;
|
||||
if (hold_frames_val > 0) g_cfg.cone_hold_frames = hold_frames_val;
|
||||
|
||||
if (CameraInit(0, dest_fps, 320, 240) < 0) {
|
||||
int frame_delay = CameraInit(0, dest_fps, 320, 240);
|
||||
if (frame_delay < 0) {
|
||||
std::cerr << "CameraInit failed" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
ControlInit();
|
||||
std::cout << "All services started" << std::endl;
|
||||
|
||||
int tick = 0;
|
||||
while (running.load())
|
||||
{
|
||||
auto t_start = std::chrono::steady_clock::now();
|
||||
CameraHandler();
|
||||
|
||||
if (++tick % 7 == 0) {
|
||||
g_cfg.debug = readFlag(debug_file);
|
||||
}
|
||||
|
||||
if (g_cfg.debug) {
|
||||
cfg_load_all();
|
||||
}
|
||||
|
||||
target_speed = g_cfg.speed;
|
||||
|
||||
auto elapsed = std::chrono::steady_clock::now() - t_start;
|
||||
auto remain = std::chrono::milliseconds(frame_delay) - elapsed;
|
||||
if (remain > std::chrono::milliseconds(1))
|
||||
std::this_thread::sleep_for(remain);
|
||||
}
|
||||
|
||||
std::cout << "Stopping..." << std::endl;
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
#!/bin/bash
|
||||
# pack_code.sh — 将所有代码源文件打包为单个 txt
|
||||
# 用法: bash pack_code.sh [输出文件名]
|
||||
# 默认输出: smartcar2_code.txt
|
||||
|
||||
OUT="${1:-smartcar2_code.txt}"
|
||||
> "$OUT"
|
||||
|
||||
# 分隔符
|
||||
sep() { echo "" >> "$OUT"; echo "============================================================" >> "$OUT"; }
|
||||
|
||||
# 逐个追入,带文件路径头
|
||||
append_file() {
|
||||
local f="$1"
|
||||
if [ ! -f "$f" ]; then return; fi
|
||||
sep
|
||||
echo "// FILE: $f" >> "$OUT"
|
||||
sep
|
||||
cat "$f" >> "$OUT"
|
||||
}
|
||||
|
||||
# ── src/ 源文件 ──
|
||||
for f in src/*.cpp src/*.hpp; do
|
||||
[ -f "$f" ] && append_file "$f"
|
||||
done
|
||||
|
||||
# ── lib/ 头文件 ──
|
||||
for f in lib/*.h; do
|
||||
[ -f "$f" ] && append_file "$f"
|
||||
done
|
||||
|
||||
# ── main/ ──
|
||||
append_file main/main.cpp
|
||||
append_file main/CMakeLists.txt
|
||||
|
||||
# ── 顶层构建/配置 ──
|
||||
append_file CMakeLists.txt
|
||||
append_file cross.cmake
|
||||
append_file ctl.sh
|
||||
append_file start.sh
|
||||
append_file .gitignore
|
||||
|
||||
# ── 独立 demo ──
|
||||
append_file encoder_brake_demo.cpp
|
||||
|
||||
# ── 统计 ──
|
||||
LINES=$(wc -l < "$OUT")
|
||||
FILES=$(grep -c "// FILE:" "$OUT")
|
||||
echo ""
|
||||
echo "=== 打包完成 ==="
|
||||
echo " 输出: $OUT"
|
||||
echo " 文件数: $FILES"
|
||||
echo " 总行数: $LINES"
|
||||
+1
-1
@@ -437,7 +437,7 @@ int CameraHandler(void)
|
||||
if (g_cfg.start) {
|
||||
int foresee = (int)g_cfg.foresee;
|
||||
int check_row = foresee / calc_scale;
|
||||
if (check_row >= 0 && check_row < line_tracking_height && mid_line[check_row] != 255) {
|
||||
if (check_row >= 0 && check_row < line_tracking_height && mid_line[check_row] != -1) {
|
||||
double deviation = mid_line[check_row] * calc_scale - newWidth / 2;
|
||||
deviation -= g_cfg.center_bias;
|
||||
g_steer_deviation = deviation / (newWidth / 2.0);
|
||||
|
||||
+16
-1
@@ -261,7 +261,8 @@ void image_main()
|
||||
}
|
||||
|
||||
// ── 6. 中线计算 + 丢线补全 ─────
|
||||
for (int row = line_tracking_height - 1; row >= 10; --row)
|
||||
// 从倒数第二行开始向上,底行(row=height-1)单独兜底避免 mid_line[row+1] 越界
|
||||
for (int row = line_tracking_height - 2; row >= 10; --row)
|
||||
{
|
||||
// ── 6a. 丢线补全 ──────────────────────────────
|
||||
if (left_line[row] == -1 && right_line[row] == -1)
|
||||
@@ -290,4 +291,18 @@ void image_main()
|
||||
mid_line[row] = (left_line[row] + right_line[row]) / 2;
|
||||
}
|
||||
}
|
||||
// 底行兜底:正常计算,丢线时用图像中心
|
||||
{
|
||||
const int row = line_tracking_height - 1;
|
||||
if (left_line[row] == -1 && right_line[row] == -1)
|
||||
{
|
||||
mid_line[row] = line_tracking_width / 2;
|
||||
left_line[row] = 0;
|
||||
right_line[row] = line_tracking_width - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
mid_line[row] = (left_line[row] + right_line[row]) / 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user