WS #1
|
@ -47,6 +47,7 @@ typedef struct
|
|||
|
||||
void sts_weight_scale_init(void);
|
||||
void sts_weight_scale(sts_sensor_t *sensor_data);
|
||||
uint32_t KalmanFilter(uint32_t inData);
|
||||
void HX711_Init(void);
|
||||
void Init_HX711pin(void);
|
||||
uint32_t HX711_Read(void);
|
||||
|
|
|
@ -84,7 +84,7 @@ void MX_GPIO_Init(void)
|
|||
// HX711_SCK
|
||||
GPIO_InitStruct.Pin = HX711_SCK_PIN;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP; //GPIO_NOPULL
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
||||
HAL_GPIO_Init(HX711_SCK_PORT, &GPIO_InitStruct);
|
||||
|
||||
|
|
|
@ -148,6 +148,7 @@ uint32_t HX711_Read(void) //增益128
|
|||
void Get_GrossWeight(void)
|
||||
{
|
||||
gross_weight = HX711_Read();
|
||||
gross_weight = KalmanFilter(gross_weight);
|
||||
APP_LOG(TS_OFF, VLEVEL_M, "\r\n ##### Gross Weight =%d <<<<<< \r\n",gross_weight);
|
||||
}
|
||||
|
||||
|
@ -167,11 +168,30 @@ void Get_NetWeight(void)
|
|||
//因为不同的传感器特性曲线不一样,因此,每一个传感器需要矫正这里的GapValue这个除数。
|
||||
//当发现测试出来的重量偏大时,增加该数值。
|
||||
|
||||
net_weight = KalmanFilter(net_weight);
|
||||
APP_LOG(TS_OFF, VLEVEL_M, "\r\n ##### Net Weight =%d \r\n", net_weight);//如果测试出来的重量偏小时,减小改数值。
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//卡尔曼滤波
|
||||
uint32_t KalmanFilter(uint32_t inData)
|
||||
{
|
||||
static float prevData = 0; //先前数值
|
||||
static float p = 10, q = 0.001, r = 0.001, kGain = 0; // q控制误差 r控制响应速度
|
||||
|
||||
p = p + q;
|
||||
kGain = p / ( p + r ); //计算卡尔曼增益
|
||||
inData = prevData + ( kGain * ( inData - prevData ) ); //计算本次滤波估计值
|
||||
p = ( 1 - kGain ) * p; //更新测量方差
|
||||
prevData = inData;
|
||||
return inData; //返回滤波值
|
||||
|
||||
|
||||
}
|
||||
|
||||
//原文链接:https://blog.csdn.net/m0_63629044/article/details/138615848
|
||||
|
||||
//延时nus
|
||||
//nus为要延时的us数.
|
||||
static uint8_t fac_us=0;//us延时倍乘数
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
|
||||
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
|
||||
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
|
||||
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="-1200016478792897337" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
|
||||
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="1048471218779752885" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
|
||||
<language-scope id="org.eclipse.cdt.core.gcc"/>
|
||||
<language-scope id="org.eclipse.cdt.core.g++"/>
|
||||
</provider>
|
||||
|
@ -16,7 +16,7 @@
|
|||
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
|
||||
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
|
||||
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
|
||||
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="-1200016478792897337" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
|
||||
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="1048471218779752885" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
|
||||
<language-scope id="org.eclipse.cdt.core.gcc"/>
|
||||
<language-scope id="org.eclipse.cdt.core.g++"/>
|
||||
</provider>
|
||||
|
|
Loading…
Reference in New Issue