添加了线性插值(待验证)

This commit is contained in:
95384 2024-11-19 17:56:39 +08:00
parent ca14efe43d
commit 3749418cee
5 changed files with 191 additions and 13 deletions

View File

@ -50,6 +50,17 @@ typedef enum
FRT_REGISTER_RSSI_RANGE = 33, /* RSSI有效范围 */
FRT_REGISTER_WAVE_DATA = 34, /* 波形数据 */
FRT_REGISTER_ERROR_LOG = 35, /* 错误日志 */
FRT_REGISTER_LINEAR_POINT_X_1 = 36, /* 线性插值原始点1 */
FRT_REGISTER_LINEAR_POINT_X_2 = 37, /* 线性插值原始点2 */
FRT_REGISTER_LINEAR_POINT_X_3 = 38, /* 线性插值原始点3 */
FRT_REGISTER_LINEAR_POINT_X_4 = 39, /* 线性插值原始点4 */
FRT_REGISTER_LINEAR_POINT_X_5 = 40, /* 线性插值原始点5 */
FRT_REGISTER_LINEAR_POINT_Y_1 = 41, /* 线性插值校准点1 */
FRT_REGISTER_LINEAR_POINT_Y_2 = 42, /* 线性插值校准点2 */
FRT_REGISTER_LINEAR_POINT_Y_3 = 43, /* 线性插值校准点3 */
FRT_REGISTER_LINEAR_POINT_Y_4 = 44, /* 线性插值校准点4 */
FRT_REGISTER_LINEAR_POINT_Y_5 = 45, /* 线性插值校准点5 */
FRT_REGISTER_LINEAR_ENABLE = 46, /* 线性插值使能 */
}FRT_MsgRegister;
#pragma pack(push,1)

View File

@ -27,6 +27,17 @@ typedef struct _config_info{
u_int16_t transducer_cfg_4R5; /* 换能器参数 */
u_int16_t transducer_cfg_8R0; /* 换能器参数 */
u_int16_t RSSI_range; /* RSSI有效范围 */
u_int16_t linear_point_1_x; /* 线性插值点1X */
u_int16_t linear_point_1_y; /* 线性插值点1Y */
u_int16_t linear_point_2_x; /* 线性插值点2X */
u_int16_t linear_point_2_y; /* 线性插值点2Y */
u_int16_t linear_point_3_x; /* 线性插值点3X */
u_int16_t linear_point_3_y; /* 线性插值点3Y */
u_int16_t linear_point_4_x; /* 线性插值点4X */
u_int16_t linear_point_4_y; /* 线性插值点4Y */
u_int16_t linear_point_5_x; /* 线性插值点5X */
u_int16_t linear_point_5_y; /* 线性插值点5Y */
u_int16_t linear_enable; /* 线性插值使能 */
u_int8_t flag_end;
}config_info;
#pragma pack(pop)

View File

@ -526,7 +526,7 @@ void wind_task(void const * argument)
av_speed = 0;
av_angle = 0;
}
// term_printf("x:%.2f y:%.2f win_speed %.2f m/s angle %.2f \r\n",av_speedx,av_speedy,av_speed,av_angle);
/// term_printf("x:%.2f y:%.2f win_speed %.2f m/s angle %.2f \r\n",av_speedx,av_speedy,av_speed,av_angle);
}
///term_printf("win_speed %.2f \r\n",weather_info.wind_velocity);
@ -704,8 +704,59 @@ float sum(float arr[], int n)
return total;
}
int times_1s_3sec = 0;
int times_1s_1min = 0;
//int times_1s_3sec = 0;
//int times_1s_1min = 0;
// 线性插值函数
//float linear_interpolation(float x0, float y0, float x1, float y1, float x) {
float linear_interpolation(float x) {
float y;
//开始插值
uint16_t x1 = g_stConfigInfo.linear_point_1_x;
uint16_t y1 = g_stConfigInfo.linear_point_1_y;
uint16_t x2 = g_stConfigInfo.linear_point_2_x;
uint16_t y2 = g_stConfigInfo.linear_point_2_y;
uint16_t x3 = g_stConfigInfo.linear_point_3_x;
uint16_t y3 = g_stConfigInfo.linear_point_3_y;
uint16_t x4 = g_stConfigInfo.linear_point_4_x;
uint16_t y4 = g_stConfigInfo.linear_point_4_y;
uint16_t x5 = g_stConfigInfo.linear_point_5_x;
uint16_t y5 = g_stConfigInfo.linear_point_5_y;
if(g_stConfigInfo.linear_enable == 0x01)
{
if (x1 == x2 || x2 == x3 || x3 == x4 || x4 == x5)
{
// 有问题就返回初始值
return x;
}
if(x>=0&&x<x1)
{
y = 0 + (x - 0) * (y1 - 0) / (x1 - 0);
}
if(x>=x1&&x<x2)
{
y = y1 + (x - x1) * (y2 - y1) / (x2 - x1);
}
if(x>=x2&&x<x3)
{
y = y2 + (x - x2) * (y3 - y2) / (x3 - x2);
}
if(x>=x3&&x<x4)
{
y = y3 + (x - x3) * (y4 - y3) / (x4 - x3);
}
// if(x>=x4&&x<x5)
if(x>=x4)
{
y = y4 + (x - x4) * (y5 - y4) / (x5 - x4);
}
return y;
}
else
{
return x;
}
}
void my_update_mcs_param(float new_wind_speed, float new_wind_dirction)
{
@ -719,7 +770,6 @@ void my_update_mcs_param(float new_wind_speed, float new_wind_dirction)
}
if(win_10min.count > g_stConfigInfo.speed_average_time/*AVE_TIME*/){win_10min.count = /*AVE_TIME*/g_stConfigInfo.speed_average_time;}
//计算10min风速滑动平均值
win_10min.ave_speed_data[win_10min.index] = sum(win_10min.speed_data, win_10min.count) / win_10min.count;
//计算10min风向滑动平均值风向滑动平均值需要过零算法
@ -744,6 +794,13 @@ void my_update_mcs_param(float new_wind_speed, float new_wind_dirction)
win_10min.ave_direction_data[win_10min.index] += 360;
}
/** 线性插值 **/
/** win_10min.ave_speed_data[win_10min.index]为风速 **/
/** win_10min.ave_direction_data[win_10min.index]为风向 **/
/** 风向不要插值 **/
win_10min.ave_speed_data[win_10min.index] = linear_interpolation(win_10min.ave_speed_data[win_10min.index]);
/** 线性插值 **/
//默认第一个数据为最大或者最小
float temp_min_direction = win_10min.ave_direction_data[0];
float temp_max_direction = win_10min.ave_direction_data[0];

View File

@ -46,11 +46,28 @@ static u_int16_t FRT_ReadRegTransducerCFG8R0(void *pMsg);
static u_int16_t FRT_ReadRegRSSIRange(void *pMsg);
static u_int16_t FRT_ReadRegWaveData(void *pMsg);
static u_int16_t FRT_ReadRegErrorData(void *pMsg);
static u_int16_t FRT_ReadRegPoint_1X(void *pMsg);
static u_int16_t FRT_ReadRegPoint_2X(void *pMsg);
static u_int16_t FRT_ReadRegPoint_3X(void *pMsg);
static u_int16_t FRT_ReadRegPoint_4X(void *pMsg);
static u_int16_t FRT_ReadRegPoint_5X(void *pMsg);
static u_int16_t FRT_ReadRegPoint_1Y(void *pMsg);
static u_int16_t FRT_ReadRegPoint_2Y(void *pMsg);
static u_int16_t FRT_ReadRegPoint_3Y(void *pMsg);
static u_int16_t FRT_ReadRegPoint_4Y(void *pMsg);
static u_int16_t FRT_ReadRegPoint_5Y(void *pMsg);
static u_int16_t FRT_ReadRegLinearEnable(void *pMsg);
/* 写配置 */
static u_int16_t FRT_WriteRegTransducerCFG1R5(void *pMsg);
static u_int16_t FRT_WriteRegTransducerCFG4R5(void *pMsg);
static u_int16_t FRT_WriteRegTransducerCFG8R0(void *pMsg);
static u_int16_t FRT_WriteRegRSSIRange(void *pMsg);
static u_int16_t FRT_WriteRegPoint_1Y(void *pMsg);
static u_int16_t FRT_WriteRegPoint_2Y(void *pMsg);
static u_int16_t FRT_WriteRegPoint_3Y(void *pMsg);
static u_int16_t FRT_WriteRegPoint_4Y(void *pMsg);
static u_int16_t FRT_WriteRegPoint_5Y(void *pMsg);
static u_int16_t FRT_WriteRegLinearEnable(void *pMsg);
static void pdebug_mcs_info();
@ -85,6 +102,17 @@ FRT_RegProcTable_s g_RegTbl[] =
{ FRT_REGISTER_TRANSDUCER_CFG_8R0, FRT_ReadRegTransducerCFG8R0 }, /* 读换能器参数寄存器值8R0 */
{ FRT_REGISTER_RSSI_RANGE, FRT_ReadRegRSSIRange }, /* 读RSSI有效范围 */
{ FRT_REGISTER_ERROR_LOG, FRT_ReadRegErrorData }, /* 读错误日志 */
{ FRT_REGISTER_LINEAR_POINT_X_1, FRT_ReadRegPoint_1X }, /* 线性插值原始点1 */
{ FRT_REGISTER_LINEAR_POINT_X_2, FRT_ReadRegPoint_2X }, /* 线性插值原始点2 */
{ FRT_REGISTER_LINEAR_POINT_X_3, FRT_ReadRegPoint_3X }, /* 线性插值原始点3 */
{ FRT_REGISTER_LINEAR_POINT_X_4, FRT_ReadRegPoint_4X }, /* 线性插值原始点4 */
{ FRT_REGISTER_LINEAR_POINT_X_5, FRT_ReadRegPoint_5X }, /* 线性插值原始点5 */
{ FRT_REGISTER_LINEAR_POINT_Y_1, FRT_ReadRegPoint_1Y }, /* 线性插值校准点1 */
{ FRT_REGISTER_LINEAR_POINT_Y_2, FRT_ReadRegPoint_2Y }, /* 线性插值校准点2 */
{ FRT_REGISTER_LINEAR_POINT_Y_3, FRT_ReadRegPoint_3Y }, /* 线性插值校准点3 */
{ FRT_REGISTER_LINEAR_POINT_Y_4, FRT_ReadRegPoint_4Y }, /* 线性插值校准点4 */
{ FRT_REGISTER_LINEAR_POINT_Y_5, FRT_ReadRegPoint_5Y }, /* 线性插值校准点5 */
{ FRT_REGISTER_LINEAR_ENABLE, FRT_ReadRegLinearEnable }, /* 线性插值使能 */
};
/* 写寄存器处理表 */
@ -100,6 +128,12 @@ FRT_RegProcTable_s g_Write_RegTbl[] =
{ FRT_REGISTER_TRANSDUCER_CFG_4R5, FRT_WriteRegTransducerCFG4R5 }, /* 写换能器参数寄存器值4R5 */
{ FRT_REGISTER_TRANSDUCER_CFG_8R0, FRT_WriteRegTransducerCFG8R0 }, /* 写换能器参数寄存器值8R0 */
{ FRT_REGISTER_RSSI_RANGE, FRT_WriteRegRSSIRange }, /* 写RSSI有效范围 */
{ FRT_REGISTER_LINEAR_POINT_Y_1, FRT_WriteRegPoint_1Y }, /* 线性插值校准点1 */
{ FRT_REGISTER_LINEAR_POINT_Y_2, FRT_WriteRegPoint_2Y }, /* 线性插值校准点2 */
{ FRT_REGISTER_LINEAR_POINT_Y_3, FRT_WriteRegPoint_3Y }, /* 线性插值校准点3 */
{ FRT_REGISTER_LINEAR_POINT_Y_4, FRT_WriteRegPoint_4Y }, /* 线性插值校准点4 */
{ FRT_REGISTER_LINEAR_POINT_Y_5, FRT_WriteRegPoint_5Y }, /* 线性插值校准点5 */
{ FRT_REGISTER_LINEAR_ENABLE, FRT_WriteRegLinearEnable }, /* 线性插值使能 */
};
/**
@ -480,6 +514,40 @@ static u_int16_t FRT_ReadRegErrorData(void *pMsg)
return FRT_swap_endian_16(value);
}
static u_int16_t FRT_ReadRegPoint_1X(void *pMsg)
{
}
static u_int16_t FRT_ReadRegPoint_2X(void *pMsg)
{
}
static u_int16_t FRT_ReadRegPoint_3X(void *pMsg)
{
}
static u_int16_t FRT_ReadRegPoint_4X(void *pMsg)
{
}
static u_int16_t FRT_ReadRegPoint_5X(void *pMsg)
{
}
static u_int16_t FRT_ReadRegPoint_1Y(void *pMsg)
{
}
static u_int16_t FRT_ReadRegPoint_2Y(void *pMsg)
{
}
static u_int16_t FRT_ReadRegPoint_3Y(void *pMsg)
{
}
static u_int16_t FRT_ReadRegPoint_4Y(void *pMsg)
{
}
static u_int16_t FRT_ReadRegPoint_5Y(void *pMsg)
{
}
static u_int16_t FRT_ReadRegLinearEnable(void *pMsg)
{
}
/**
* @brief 1R5
* @param
@ -544,6 +612,25 @@ static u_int16_t FRT_WriteRegRSSIRange(void *pMsg)
return 0;
}
static u_int16_t FRT_WriteRegPoint_1Y(void *pMsg)
{
}
static u_int16_t FRT_WriteRegPoint_2Y(void *pMsg)
{
}
static u_int16_t FRT_WriteRegPoint_3Y(void *pMsg)
{
}
static u_int16_t FRT_WriteRegPoint_4Y(void *pMsg)
{
}
static u_int16_t FRT_WriteRegPoint_5Y(void *pMsg)
{
}
static u_int16_t FRT_WriteRegLinearEnable(void *pMsg)
{
}
/**
* @brief

View File

@ -10,7 +10,7 @@
* 65
*
*/
/* 默认参数 */
config_info g_stConfigInfo={
.flag_head = FLAG_SAVE_INFLASH_HEAD,
.addr = 0x30, /* 默认地址 */
@ -25,6 +25,18 @@ config_info g_stConfigInfo={
.transducer_cfg_4R5 = 35, /* 无锡电声换能器参数 */
.transducer_cfg_8R0 = 65, /* 无锡电声换能器参数 */
.RSSI_range = 20, /* RSSI大于0.2有效 */
.linear_point_1_x = 0, /* 线性插值点1 */
.linear_point_1_y = 0, /* 线性插值点1 */
.linear_point_2_x = 0, /* 线性插值点2 */
.linear_point_2_y = 0, /* 线性插值点2 */
.linear_point_3_x = 0, /* 线性插值点3 */
.linear_point_3_y = 0, /* 线性插值点3 */
.linear_point_4_x = 0, /* 线性插值点4 */
.linear_point_4_y = 0, /* 线性插值点4 */
.linear_point_5_x = 0, /* 线性插值点5 */
.linear_point_5_y = 0, /* 线性插值点5 */
.linear_enable = 0, /* 线性插值使能 */
.flag_end = FLAG_SAVE_INFLASH_END,
};