2024-12-28 00:38:42 +08:00
|
|
|
|
#ifndef _TRACKING_H_
|
|
|
|
|
#define _TRACKING_H_
|
|
|
|
|
|
|
|
|
|
#include "ir.h"
|
|
|
|
|
#include "motor.h"
|
|
|
|
|
#include "pid.h"
|
2025-01-01 17:53:59 +08:00
|
|
|
|
#include "storage.h"
|
2025-01-02 02:19:07 +08:00
|
|
|
|
#include "ultrasound.h"
|
2025-01-01 17:53:59 +08:00
|
|
|
|
|
2024-12-28 00:38:42 +08:00
|
|
|
|
class TrackingController {
|
|
|
|
|
public:
|
|
|
|
|
static uint8_t baseSpeed; // 基础前进速度
|
|
|
|
|
static uint8_t turnSpeed; // 转弯速度
|
2025-01-01 17:53:59 +08:00
|
|
|
|
static uint8_t rotateSensitive; // 旋转灵敏度
|
|
|
|
|
static float lastOffset; // 上一次的偏移量
|
2024-12-28 00:38:42 +08:00
|
|
|
|
|
2025-01-02 02:19:07 +08:00
|
|
|
|
// 添加避障相关常量
|
|
|
|
|
static constexpr float OBSTACLE_DISTANCE = 30.0f; // 避障距离阈值(厘米)
|
|
|
|
|
static bool isAvoiding; // 是否正在避障
|
|
|
|
|
|
2024-12-28 00:38:42 +08:00
|
|
|
|
// 初始化循迹控制器
|
|
|
|
|
static void init();
|
|
|
|
|
|
|
|
|
|
// 更新循迹状态并控制电机
|
|
|
|
|
static void update();
|
|
|
|
|
|
|
|
|
|
// 设置循迹速度
|
|
|
|
|
static void setSpeed(uint8_t baseSpeed, uint8_t turnSpeed);
|
|
|
|
|
|
2025-01-01 17:53:59 +08:00
|
|
|
|
// 设置旋转灵敏度
|
|
|
|
|
static void setRotateSensitive(uint8_t sensitive);
|
|
|
|
|
|
2024-12-28 00:38:42 +08:00
|
|
|
|
// 计算偏移量
|
|
|
|
|
static float calculateOffset(const IRData& irData);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
static constexpr float LOST_LINE = 999.0f; // 使用一个特殊值表示丢线状态
|
2025-01-01 17:53:59 +08:00
|
|
|
|
static bool isSearching; // 标记是否处于搜索模式
|
|
|
|
|
static unsigned long allHighStartTime; // 记录全高状态开始的时间
|
|
|
|
|
static bool isAllHighState; // 记录是否处于全高状态
|
|
|
|
|
static constexpr unsigned long ALL_HIGH_TIMEOUT = 1000; // 全高状态超时时间(1秒)
|
2024-12-28 00:38:42 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|