Car/TaiChi/sensorTaiChi.h

105 lines
2.2 KiB
C
Raw Normal View History

2021-02-13 12:29:42 +08:00
#ifndef SENSORTAICHI_H
#define SENSORTAICHI_H
2021-02-10 20:13:28 +08:00
//注释以关闭调试功能
2021-02-15 12:28:14 +08:00
#define SENSOR_DEBUG
2021-02-10 20:13:28 +08:00
2021-04-19 14:41:16 +08:00
#ifdef SENSOR_DEBUG
#define NeoSerialDebug NeoSerial3
#endif
//灰度传感器 OUT 接口定义
2021-02-10 20:13:28 +08:00
#define GRAY_1_OUT A0
#define GRAY_2_OUT A1
#define GRAY_3_OUT A2
#define GRAY_4_OUT A3
#define GRAY_5_OUT A4
#define GRAY_6_OUT A5
#define GRAY_7_OUT A6
2021-02-10 20:13:28 +08:00
//灰度传感器 VCC 接口定义
#define GRAY_1_VCC 48
#define GRAY_2_VCC 49
#define GRAY_3_VCC 50
#define GRAY_4_VCC 51
#define GRAY_5_VCC 52
#define GRAY_6_VCC 53
#define GRAY_7_VCC 47
2021-02-10 20:13:28 +08:00
//灰度传感器临界值
#define DEFAULT_GRAY_1_GATE 900
#define DEFAULT_GRAY_2_GATE 900
#define DEFAULT_GRAY_3_GATE 850
#define DEFAULT_GRAY_4_GATE 850
#define DEFAULT_GRAY_5_GATE 900
#define DEFAULT_GRAY_6_GATE 880
#define DEFAULT_GRAY_7_GATE 690
2021-02-10 20:13:28 +08:00
//灰度传感器闪烁时间
#define GRAY_FLASH_TIME 200
2021-02-10 20:13:28 +08:00
//灰度传感器标识定义
#define GRAY_1 0
#define GRAY_2 1
#define GRAY_3 2
#define GRAY_4 3
#define GRAY_5 4
#define GRAY_6 5
#define GRAY_7 6
2021-02-10 20:13:28 +08:00
//碰撞传感器 OUT 接口定义
2021-02-10 20:13:28 +08:00
#define BUTTON_1_OUT 2
#define BUTTON_2_OUT 3
//碰撞传感器 VCC 接口定义
#define BUTTON_1_VCC 45
#define BUTTON_2_VCC 46
2021-02-10 20:13:28 +08:00
//碰撞传感器标识定义
#define BUTTON_1 0
#define BUTTON_2 1
2021-03-19 23:53:40 +08:00
//HMC5883 的 I2C 地址
#define HMC5883_ADDRESS 0x1E
2021-02-10 20:13:28 +08:00
class Sensor
{
public:
Sensor();
//设置灰度传感器临界值
2021-03-22 12:18:27 +08:00
static void SetGrayGate(uint8_t gray_sensor_num, int gate);
//使灰度传感器闪烁
2021-03-22 12:18:27 +08:00
static void FlashGraySensor(uint8_t gray_sensor_num);
//灰度传感器判断下方是否为白色
2021-03-22 12:18:27 +08:00
static bool IsWhite(uint8_t gray_sensor_num);
2021-02-10 20:13:28 +08:00
//灰度传感器灰度值偏离比例,即 (gray_gate - gray_val) / gray_gate
2021-03-22 12:18:27 +08:00
static float GrayDeviationRate(uint8_t gray_sensor_num);
//碰撞传感器(开关)判断是否闭合
2021-03-22 12:18:27 +08:00
static bool IsPushed(uint8_t button_num);
2021-03-19 23:53:40 +08:00
//开启 HMC5883 的 I2C 通讯
2021-03-22 12:18:27 +08:00
static void StartHMC5883(void);
2021-03-19 23:53:40 +08:00
//返回朝向角
2021-03-22 12:18:27 +08:00
static float GetAngle(void);
private:
//灰度传感器临界值
2021-03-22 12:18:27 +08:00
static int gray_1_gate;
static int gray_2_gate;
static int gray_3_gate;
static int gray_4_gate;
static int gray_5_gate;
static int gray_6_gate;
static int gray_7_gate;
2021-03-19 23:53:40 +08:00
};
2021-02-10 20:13:28 +08:00
#endif