Files
car_stm32f103vet6/Core/Bsp/bsp_track_ir.h
wangbeihong a5f8e8149a feat: 修正红外循迹方向符号,解决循迹偏差越修越偏问题
- 反转了循迹P控制输出的角速度修正方向,保证检测到黑线时车辆向正确方向修正
- 同步修正丢线回找时的转向方向
- 相关代码在 track_ir_algo.c
- 编译通过,功能已现场验证
2026-04-16 00:44:01 +08:00

54 lines
1.6 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#ifndef __BSP_TRACK_IR_H
#define __BSP_TRACK_IR_H
#include "main.h"
/*
* 红外循迹 4 路状态位定义bit=1 表示检测到黑线)
* bit0 -> H1, bit1 -> H2, bit2 -> H3, bit3 -> H4
*/
#define TRACK_IR_H1_BIT (1U << 0)
#define TRACK_IR_H2_BIT (1U << 1)
#define TRACK_IR_H3_BIT (1U << 2)
#define TRACK_IR_H4_BIT (1U << 3)
/*
* 红外模块有效电平:
* 根据用户描述探测黑线输出低电平GPIO_PIN_RESET白线输出高电平。
* 超出范围(丢线/悬空)也输出低电平。
*/
#ifndef TRACK_IR_ACTIVE_LEVEL
#define TRACK_IR_ACTIVE_LEVEL GPIO_PIN_RESET
#endif
/**
* @brief 基础循迹判定结果
*/
typedef enum {
TRACK_IR_STATE_LOST = 0, // 全灭,丢线
TRACK_IR_STATE_LEFT, // 线偏左
TRACK_IR_STATE_CENTER, // 居中
TRACK_IR_STATE_RIGHT, // 线偏右
TRACK_IR_STATE_CROSS // 十字/大面积黑线
} track_ir_state_t;
/* 初始化接口当前仅预留GPIO 配置由 CubeMX 负责) */
void track_ir_init(void);
/* 读取原始电平状态bit=1 表示 GPIO 为高电平) */
uint8_t track_ir_get_raw_mask(void);
/* 读取线状态掩码bit=1 表示对应通道检测到黑线) */
uint8_t track_ir_get_line_mask(void);
/* 读取带去抖的线状态掩码(内部多次采样做多数投票) */
uint8_t track_ir_get_line_mask_filtered(void);
/* 最基础方向判定:丢线 / 左偏 / 居中 / 右偏 / 十字 */
track_ir_state_t track_ir_basic_judge(void);
/* 便于日志输出的状态字符串 */
const char *track_ir_state_to_string(track_ir_state_t state);
#endif /* __BSP_TRACK_IR_H */