Initial commit: SmartCar Framework v0.1 — 龙芯2K0300智能车开发框架\n\n- HAL: GPIO/PWM/Encoder/Framebuffer 驱动\n- Control: PID/IMU/Motor/Servo 控制\n- Vision: HSV双Otsu→4点标定IPM→洪泛填充→逐行搜线\n- Strategy: 三区前瞻偏差+速度策略\n- Debug: 文件热调参+LCD预览+cv截帧\n- Scheduler: 5ms timerfd+epoll 中央调度器
This commit is contained in:
20
debug/config.cpp
Normal file
20
debug/config.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
#include "config.hpp"
|
||||
#include <fstream>
|
||||
|
||||
double read_config_double(const char* filename, double default_val)
|
||||
{
|
||||
std::ifstream f(filename);
|
||||
if (!f.is_open()) return default_val;
|
||||
double v = default_val;
|
||||
f >> v;
|
||||
return v;
|
||||
}
|
||||
|
||||
bool read_config_flag(const char* filename, bool default_val)
|
||||
{
|
||||
std::ifstream f(filename);
|
||||
if (!f.is_open()) return default_val;
|
||||
int v = default_val ? 1 : 0;
|
||||
f >> v;
|
||||
return v != 0;
|
||||
}
|
||||
4
debug/config.hpp
Normal file
4
debug/config.hpp
Normal file
@@ -0,0 +1,4 @@
|
||||
#pragma once
|
||||
|
||||
double read_config_double(const char* filename, double default_val = 0);
|
||||
bool read_config_flag(const char* filename, bool default_val = false);
|
||||
88
debug/draw.cpp
Normal file
88
debug/draw.cpp
Normal file
@@ -0,0 +1,88 @@
|
||||
#include "draw.hpp"
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
DebugOverlay g_dbg;
|
||||
|
||||
static uint16* g_buf = nullptr;
|
||||
static int g_w = 0;
|
||||
static int g_h = 0;
|
||||
|
||||
static inline uint16 rgb565(uint8 r, uint8 g, uint8 b)
|
||||
{
|
||||
return ((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3);
|
||||
}
|
||||
|
||||
static inline bool in_screen(int x, int y)
|
||||
{
|
||||
return x >= 0 && x < g_w && y >= 0 && y < g_h;
|
||||
}
|
||||
|
||||
void dbg_draw_init(uint16* fb_buffer, int w, int h)
|
||||
{
|
||||
g_buf = fb_buffer;
|
||||
g_w = w; g_h = h;
|
||||
}
|
||||
|
||||
void dbg_draw_line(int x0, int y0, int x1, int y1, uint8 r, uint8 g, uint8 b)
|
||||
{
|
||||
if (!g_buf) return;
|
||||
uint16 color = rgb565(r, g, b);
|
||||
int dx = std::abs(x1 - x0), sx = x0 < x1 ? 1 : -1;
|
||||
int dy = -std::abs(y1 - y0), sy = y0 < y1 ? 1 : -1;
|
||||
int err = dx + dy;
|
||||
|
||||
while (true)
|
||||
{
|
||||
if (in_screen(x0, y0)) g_buf[y0 * g_w + x0] = color;
|
||||
if (x0 == x1 && y0 == y1) break;
|
||||
int e2 = 2 * err;
|
||||
if (e2 >= dy) { err += dy; x0 += sx; }
|
||||
if (e2 <= dx) { err += dx; y0 += sy; }
|
||||
}
|
||||
}
|
||||
|
||||
void dbg_draw_cross(int cx, int cy, int size, uint8 r, uint8 g, uint8 b)
|
||||
{
|
||||
dbg_draw_line(cx - size, cy, cx + size, cy, r, g, b);
|
||||
dbg_draw_line(cx, cy - size, cx, cy + size, r, g, b);
|
||||
}
|
||||
|
||||
void dbg_draw_rect(int x, int y, int w, int h, uint8 r, uint8 g, uint8 b)
|
||||
{
|
||||
dbg_draw_line(x, y, x + w, y, r, g, b);
|
||||
dbg_draw_line(x + w, y, x + w, y + h, r, g, b);
|
||||
dbg_draw_line(x + w, y + h, x, y + h, r, g, b);
|
||||
dbg_draw_line(x, y + h, x, y, r, g, b);
|
||||
}
|
||||
|
||||
void dbg_draw_points(const int points[][2], int count, uint8 r, uint8 g, uint8 b)
|
||||
{
|
||||
if (!g_buf) return;
|
||||
uint16 color = rgb565(r, g, b);
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
int x = points[i][0], y = points[i][1];
|
||||
if (in_screen(x, y)) g_buf[y * g_w + x] = color;
|
||||
}
|
||||
}
|
||||
|
||||
void dbg_draw_edge_zoom(const EdgeLines& lines, uint8 r, uint8 g, uint8 b)
|
||||
{
|
||||
const int thick = 7; // 车道线宽度 (像素)
|
||||
|
||||
for (int y = 0; y < IPM_ROW_COUNT; ++y)
|
||||
{
|
||||
if (lines.left[y] > 0)
|
||||
for (int dx = -thick; dx <= thick; ++dx)
|
||||
dbg_draw_line(lines.left[y] + dx, y, lines.left[y] + dx, y, r, g, b);
|
||||
|
||||
if (lines.right[y] > 0)
|
||||
for (int dx = -thick; dx <= thick; ++dx)
|
||||
dbg_draw_line(lines.right[y] + dx, y, lines.right[y] + dx, y, 0, 255, 0);
|
||||
|
||||
if (lines.mid[y] > 0)
|
||||
for (int dx = -thick; dx <= thick; ++dx)
|
||||
dbg_draw_line(lines.mid[y] + dx, y, lines.mid[y] + dx, y, 255, 255, 0);
|
||||
}
|
||||
}
|
||||
17
debug/draw.hpp
Normal file
17
debug/draw.hpp
Normal file
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include "types.hpp"
|
||||
|
||||
struct DebugOverlay {
|
||||
bool enable = true;
|
||||
int mode = DBG_OVERLAY;
|
||||
};
|
||||
|
||||
extern DebugOverlay g_dbg;
|
||||
|
||||
void dbg_draw_init(uint16* fb_buffer, int w, int h);
|
||||
void dbg_draw_line(int x0, int y0, int x1, int y1, uint8 r, uint8 g, uint8 b);
|
||||
void dbg_draw_cross(int cx, int cy, int size, uint8 r, uint8 g, uint8 b);
|
||||
void dbg_draw_rect(int x, int y, int w, int h, uint8 r, uint8 g, uint8 b);
|
||||
void dbg_draw_points(const int points[][2], int count, uint8 r, uint8 g, uint8 b);
|
||||
void dbg_draw_edge_zoom(const EdgeLines& lines, uint8 r, uint8 g, uint8 b);
|
||||
25
debug/tcp.cpp
Normal file
25
debug/tcp.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#include "tcp.hpp"
|
||||
#include <cstdio>
|
||||
|
||||
bool tcp_init(const char* host, int port)
|
||||
{
|
||||
// TODO: 实现 TCP 客户端连接逐飞助手
|
||||
// 当前为占位实现,后续接入 seekfree_assistant 协议
|
||||
printf("[TCP] 占位: 连接 %s:%d (未实现)\n", host, port);
|
||||
return false;
|
||||
}
|
||||
|
||||
void tcp_send_image(const EdgeLines& lines)
|
||||
{
|
||||
// TODO: 发送 RGB565 调试图像
|
||||
}
|
||||
|
||||
void tcp_send_osc(float ch1, float ch2, float ch3, float ch4)
|
||||
{
|
||||
// TODO: 发送虚拟示波器数据
|
||||
}
|
||||
|
||||
void tcp_close()
|
||||
{
|
||||
// TODO: 关闭 TCP 连接
|
||||
}
|
||||
8
debug/tcp.hpp
Normal file
8
debug/tcp.hpp
Normal file
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
#include "types.hpp"
|
||||
#include "vision/search.hpp"
|
||||
|
||||
bool tcp_init(const char* host = "192.168.31.20", int port = 8086);
|
||||
void tcp_send_image(const EdgeLines& lines); // 发送带叠加线的图传
|
||||
void tcp_send_osc(float ch1, float ch2, float ch3, float ch4);
|
||||
void tcp_close();
|
||||
Reference in New Issue
Block a user