131 lines
3.4 KiB
C
131 lines
3.4 KiB
C
#include "driver/i2c_master.h"
|
|||
|
|
|
||
|
|
#ifndef __SC7U22_H_
|
||
|
|
#define __SC7U22_H_
|
||
|
|
|
||
|
|
|
||
|
|
#define SC7U22_CONFIG 0x1A
|
||
|
|
#define SC7U22_GYRO_CONFIG 0x42
|
||
|
|
#define SC7U22_ACCEL_CONFIG 0x40
|
||
|
|
|
||
|
|
#define SC7U22_ACCEL_XOUT_H 0x0C
|
||
|
|
#define SC7U22_ACCEL_XOUT_L 0x0D
|
||
|
|
#define SC7U22_ACCEL_YOUT_H 0x0E
|
||
|
|
#define SC7U22_ACCEL_YOUT_L 0x0F
|
||
|
|
#define SC7U22_ACCEL_ZOUT_H 0x10
|
||
|
|
#define SC7U22_ACCEL_ZOUT_L 0x11
|
||
|
|
#define SC7U22_GYRO_XOUT_H 0x12
|
||
|
|
#define SC7U22_GYRO_XOUT_L 0x13
|
||
|
|
#define SC7U22_GYRO_YOUT_H 0x14
|
||
|
|
#define SC7U22_GYRO_YOUT_L 0x15
|
||
|
|
#define SC7U22_GYRO_ZOUT_H 0x16
|
||
|
|
#define SC7U22_GYRO_ZOUT_L 0x17
|
||
|
|
|
||
|
|
#define SC7U22_WHO_AM_I 0x01
|
||
|
|
|
||
|
|
#define SC7U22_I2C_ADDR 0x18
|
||
|
|
#define NST112_I2C_ADDR 0x48
|
||
|
|
#define MS523_I2C_ADDR 0x28
|
||
|
|
#define I2C_MASTER_FREQ_HZ 800000 // kHz 800000
|
||
|
|
#define I2C_MASTER_FREQ_TEMP_HZ 100000 // kHz 800000
|
||
|
|
#define GRAVITY_EARTH (9.80665f)
|
||
|
|
#define ALPHA 0.90f // 高通系数
|
||
|
|
#define BUM_THRESHOLD 4.0e8f // 颠簸能量阈值(暂定)
|
||
|
|
#define turn_gyro_threshold 30.0f //急转弯角速度阈值
|
||
|
|
#define turn_accel_threshold 2.0f //急转弯向心加速度阈值
|
||
|
|
#define rapid_accel_threshold 3.0f //急加速阈值
|
||
|
|
#define rapid_decel_threshold -3.0f //急刹车阈值
|
||
|
|
#define DATA_BUFFER_SIZE 200
|
||
|
|
#define is_stop_magnitude 0.35f //启动
|
||
|
|
#define stop_proportion_threshold 0.5f //停止时间比例阈值
|
||
|
|
#define start_stop_threshold 15 //启停次数阈值
|
||
|
|
|
||
|
|
// 驾驶事件冷却屏蔽(10秒内不再触发表情)
|
||
|
|
#define EVENT_COOLDOWN_MS 10000 // 冷却时间 10 秒
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
extern float ax,ay,az,gx,gy,gz;
|
||
|
|
|
||
|
|
|
||
|
|
typedef struct
|
||
|
|
{
|
||
|
|
int16_t Ax;
|
||
|
|
int16_t Ay;
|
||
|
|
int16_t Az;
|
||
|
|
int16_t Gx;
|
||
|
|
int16_t Gy;
|
||
|
|
int16_t Gz;
|
||
|
|
}SC7U22_DataType;
|
||
|
|
|
||
|
|
struct acc_offset
|
||
|
|
{
|
||
|
|
float acc_x_offset;
|
||
|
|
float acc_y_offset;
|
||
|
|
float acc_z_offset;
|
||
|
|
|
||
|
|
float gyr_x_offset;
|
||
|
|
float gyr_y_offset;
|
||
|
|
float gyr_z_offset;
|
||
|
|
};
|
||
|
|
|
||
|
|
typedef struct{
|
||
|
|
float accx_noise;
|
||
|
|
float accy_noise;
|
||
|
|
float accz_noise;
|
||
|
|
float gyrx_noise;
|
||
|
|
float gyry_noise;
|
||
|
|
float gyrz_noise;
|
||
|
|
}noise_datatype;
|
||
|
|
|
||
|
|
typedef struct {
|
||
|
|
float accel_x;
|
||
|
|
float accel_y;
|
||
|
|
float accel_z;
|
||
|
|
float gyro_x;
|
||
|
|
float gyro_y;
|
||
|
|
float gyro_z;
|
||
|
|
int64_t timestamp;
|
||
|
|
} sensor_data_t;
|
||
|
|
|
||
|
|
typedef enum {
|
||
|
|
EVENT_NONE = 0,
|
||
|
|
EVENT_SUDDEN_ACCEL, // 急加速
|
||
|
|
EVENT_SUDDEN_BRAKE, // 急刹车
|
||
|
|
EVENT_SHARP_LTURN, //急左转弯
|
||
|
|
EVENT_SHARP_RTURN, //急右转弯
|
||
|
|
} driving_event_t;
|
||
|
|
|
||
|
|
void SC7U22_init(i2c_master_bus_handle_t i2c_bus);
|
||
|
|
esp_err_t SC7U22_Reg_W(uint8_t reg_addr, uint8_t data);
|
||
|
|
esp_err_t SC7U22_Reg_R(uint8_t reg_addr, uint8_t *data);
|
||
|
|
// void SC7U22_DataGet(SC7U22_DataType* SC7U22_DataStucture);
|
||
|
|
|
||
|
|
void mySC7_getdata(void); //获得处理后的数据
|
||
|
|
void SC7U22_Sensor_enable(void);
|
||
|
|
void noise_threshold_get(void);
|
||
|
|
void accel_Getoffset(void);
|
||
|
|
float lsb_to_mps2(int16_t val, float g_range, uint8_t bit_width);
|
||
|
|
float lsb_to_dps(int16_t val, float dps, uint8_t bit_width);
|
||
|
|
|
||
|
|
void bum_energy_get(void);
|
||
|
|
bool is_bump(void);
|
||
|
|
void sharp_turn_detect(void);
|
||
|
|
driving_event_t is_sharp_turn(void);
|
||
|
|
void start_stop_state(void);
|
||
|
|
void detect_driving_events(void);
|
||
|
|
driving_event_t is_rapid_acc_or_dec(void);
|
||
|
|
bool is_jam(void);
|
||
|
|
void imu_task(void *param);
|
||
|
|
i2c_master_bus_handle_t get_i2c_master_bus_handle(void);
|
||
|
|
|
||
|
|
esp_err_t BMI_init(void);
|
||
|
|
esp_err_t NST112_init(void);
|
||
|
|
esp_err_t MS523_init(void);
|
||
|
|
#endif
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|