Files
mqtt_power/esp32_robot_firmware/navigation.h

45 lines
1.6 KiB
C

#ifndef NAVIGATION_H
#define NAVIGATION_H
#include "config.h"
#include "motor_control.h"
#include "sensor_handler.h"
#include "mqtt_handler.h" // 可能需要访问机器人状态定义
// 循迹PID控制参数 (如果使用PID)
#define KP 0.5 // 比例常数
#define KI 0.1 // 积分常数
#define KD 0.2 // 微分常数
// 导航状态,用于 moveToSpot 函数的内部状态管理
enum NavigationState {
NAV_IDLE,
NAV_FOLLOWING_LINE,
NAV_AVOIDING_OBSTACLE,
NAV_AT_SPOT_CANDIDATE, // 检测到侧方可能是充电桩
NAV_TARGET_REACHED,
NAV_ERROR
};
void navigation_setup();
// 主要的移动到指定车位函数
// target_spot_uid: 目标车位的ID (如 "001", "002")
// current_robot_status_ptr: 指向主程序中当前机器人状态的指针,用于更新
// returns: true 如果成功到达, false 如果失败或被中断
bool navigation_move_to_spot(const char* target_spot_uid, RobotStatus* current_robot_status_ptr, String* current_location_ptr);
// 内部辅助函数,也可以根据需要公开
void navigation_follow_line_once(); // 执行一次循迹逻辑并调整电机/舵机
bool navigation_check_obstacle(); // 检查前方障碍物
void navigation_handle_obstacle(); // 处理障碍物 (例如停止或简单避障)
bool navigation_check_spot_arrival(const char* target_spot_uid); // 检查是否到达目标车位
// 简单的自计数车位识别逻辑
void navigation_reset_spot_counter();
int navigation_get_current_spot_count();
// 获取当前导航模块内部状态(用于调试或复杂逻辑)
NavigationState navigation_get_state();
#endif // NAVIGATION_H