esp32-car/include/tracking.h

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