#ifndef SENSOR_HANDLER_H #define SENSOR_HANDLER_H #include "config.h" #include // TCRT5000 循迹传感器阈值 (如果使用数字模式或需要软件比较) // 这个值需要根据实际传感器和线路进行校准 #define TCRT5000_THRESHOLD 500 // 假设模拟读取值,高于此值为检测到线,低于则为背景 void sensor_setup(); // 超声波传感器 long get_ultrasonic_distance_cm(int trig_pin, int echo_pin); long get_front_obstacle_distance(); // 获取前方障碍物距离 (cm) long get_side_spot_distance(); // 获取侧方充电桩距离 (cm) // TCRT5000 循迹传感器 // 返回值可以根据具体循迹算法设计,例如: // 0: 均在线上或中间 // -1: 左边传感器在线上,车体偏右 // 1: 右边传感器在线上,车体偏左 // -2: 左边传感器出界 // 2: 右边传感器出界 // 或者直接返回左右传感器的原始值/数字值 struct LineFollowValues { bool left_on_line; bool right_on_line; // 可以添加原始模拟值如果需要 // int raw_left; // int raw_right; }; LineFollowValues get_line_follow_values(); // 辅助函数,判断是否在线上 (基于模拟值和阈值) bool is_on_line(int sensor_pin, int threshold = TCRT5000_THRESHOLD); #endif // SENSOR_HANDLER_H