From 445e67f23425645140f3968b9caa71d8b0d66996 Mon Sep 17 00:00:00 2001
From: "DESKTOP-KQHDCM4\\97555" <975559679@qq.com>
Date: Mon, 27 Oct 2025 17:50:31 +0800
Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E4=BF=AE=E5=A4=8D=E4=BA=86=E5=B0=8F?=
=?UTF-8?q?=E6=A6=82=E7=8E=87=E9=87=87=E9=9B=86=E5=88=B0=E9=94=99=E8=AF=AF?=
=?UTF-8?q?ad=E5=80=BC=E7=9A=84bug=202=E3=80=81=E4=BC=98=E5=8C=96=E4=BA=86?=
=?UTF-8?q?=E4=B8=AD=E9=97=B4=E6=8A=AC=E5=8D=87=E4=B8=8B=E9=99=8D=E7=9A=84?=
=?UTF-8?q?bug?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Project/HC32F460/MDK/HC32F460.uvoptx | 26 ++++++++--
Project/HC32F460/source/User/Inc/bsp.h | 4 +-
Project/HC32F460/source/User/Src/main.c | 63 ++++++++++++++++++-------
3 files changed, 71 insertions(+), 22 deletions(-)
diff --git a/Project/HC32F460/MDK/HC32F460.uvoptx b/Project/HC32F460/MDK/HC32F460.uvoptx
index 44340c8..8cd6355 100644
--- a/Project/HC32F460/MDK/HC32F460.uvoptx
+++ b/Project/HC32F460/MDK/HC32F460.uvoptx
@@ -208,7 +208,27 @@
11
1
- DcMotorDispEn
+ App.EmergencyDelay1mSCnt,0x0A
+
+
+ 12
+ 1
+ App.ADTrack.LeftLow_Org_AdZero,0x0A
+
+
+ 13
+ 1
+ Oll_diff1,0x0A
+
+
+ 14
+ 1
+ Orl_diff1,0x0A
+
+
+ 15
+ 1
+ -(App.ADTrack.Stop_VPT),0x0A
@@ -217,7 +237,7 @@
0
1
- 1
+ 0
0
0
0
@@ -1018,7 +1038,7 @@
CS1237
- 0
+ 1
0
0
0
diff --git a/Project/HC32F460/source/User/Inc/bsp.h b/Project/HC32F460/source/User/Inc/bsp.h
index 1b45351..4fa2a17 100644
--- a/Project/HC32F460/source/User/Inc/bsp.h
+++ b/Project/HC32F460/source/User/Inc/bsp.h
@@ -180,8 +180,8 @@
#define CLR_TWIN_BIT1() PORT_ResetBits(TWIN_BIT1_PORTx, TWIN_BIT1_PINx)//拉低
typedef struct {
- uint32_t ControlLevel;//控制等级
- uint32_t DBGWaveOut;//调试波形输出
+ int32_t ControlLevel;//控制等级
+ int32_t DBGWaveOut;//调试波形输出
}__attribute__ ((packed))LayoutPara_t, *LayoutPara;//上位机下发的配置参数
typedef struct {
diff --git a/Project/HC32F460/source/User/Src/main.c b/Project/HC32F460/source/User/Src/main.c
index a7b6021..87e0757 100644
--- a/Project/HC32F460/source/User/Src/main.c
+++ b/Project/HC32F460/source/User/Src/main.c
@@ -36,6 +36,10 @@ static void show(uint8_t ch,int32_t ad)
}
void LEFTUP_CS1237AinADataProcessCallBack(int32_t AD)
{
+ if(abs(AD - App.LeftUpCS1237_TrendArray[0]) > 2000000)
+ {
+ AD = App.LeftUpCS1237_TrendArray[0];
+ }
show(1,AD);
for(int i = OSC_CNT-1; i > 0; i--)
{
@@ -46,6 +50,11 @@ void LEFTUP_CS1237AinADataProcessCallBack(int32_t AD)
}
void LEFTLOW_CS1237AinADataProcessCallBack(int32_t AD)
{
+
+ if(abs(AD - App.LeftLowCS1237_TrendArray[0]) > 2000000)
+ {
+ AD = App.LeftLowCS1237_TrendArray[0];
+ }
show(2,AD);
for(int i = OSC_CNT-1; i > 0; i--)
{
@@ -56,6 +65,10 @@ void LEFTLOW_CS1237AinADataProcessCallBack(int32_t AD)
}
void RIGHTUP_CS1237AinADataProcessCallBack(int32_t AD)
{
+ if(abs(AD - App.RightUpCS1237_TrendArray[0]) > 2000000)
+ {
+ AD = App.RightUpCS1237_TrendArray[0];
+ }
show(3,AD);
for(int i = OSC_CNT-1; i > 0; i--)
{
@@ -66,6 +79,10 @@ void RIGHTUP_CS1237AinADataProcessCallBack(int32_t AD)
}
void RIGHTLOW_CS1237AinADataProcessCallBack(int32_t AD)
{
+ if(abs(AD - App.RightLowCS1237_TrendArray[0]) > 2000000)
+ {
+ AD = App.RightLowCS1237_TrendArray[0];
+ }
show(4,AD);
for(int i = OSC_CNT-1; i > 0; i--)
{
@@ -250,7 +267,7 @@ void SupportControlHandle(int32_t *lu_ad, int32_t *ll_ad, int32_t *ru_ad, int32_
App.LeftRunFalg = true;
// if((App.LeftLowCS1237_SlopeArray[0] > App.ADTrack.Slope_VPT/3))
// {
- if((Oll_diff1+Orl_diff1) < -App.ADTrack.LeftLowVPT/3)
+ if((Oll_diff1+Orl_diff1) < -(App.ADTrack.LeftLowVPT/(App.Para.Layout.ControlLevel+1)))
{
BDC_UP();
App.UpFlag = true;
@@ -263,7 +280,7 @@ void SupportControlHandle(int32_t *lu_ad, int32_t *ll_ad, int32_t *ru_ad, int32_
// }
// else if((App.LeftLowCS1237_SlopeArray[0] < -App.ADTrack.Slope_VPT/3))
// {
- if((Oll_diff1+Orl_diff1) > App.ADTrack.LeftLowVPT/3)
+ if((Oll_diff1+Orl_diff1) > App.ADTrack.LeftLowVPT/(App.Para.Layout.ControlLevel+1))
{
BDC_DOWN();
App.UpFlag = false;
@@ -278,9 +295,9 @@ void SupportControlHandle(int32_t *lu_ad, int32_t *ll_ad, int32_t *ru_ad, int32_
else if(abs(Oll_diff1) < abs(Orl_diff1))
{
App.RightRunFalg = true;
- if((App.RightLowCS1237_SlopeArray[0] > App.ADTrack.Slope_VPT/3))
- {
- if((Oll_diff1+Orl_diff1) < -App.ADTrack.RightLowVPT/3)
+// if((App.RightLowCS1237_SlopeArray[0] > App.ADTrack.Slope_VPT/3))
+// {
+ if((Oll_diff1+Orl_diff1) < -(App.ADTrack.RightLowVPT/(App.Para.Layout.ControlLevel+1)))
{
BDC_UP();
App.UpFlag = true;
@@ -290,10 +307,10 @@ void SupportControlHandle(int32_t *lu_ad, int32_t *ll_ad, int32_t *ru_ad, int32_
App.RunCollDelay1mSCnt = RUN_TIME_MS;
//App.EmergencyDelay1mSCnt = EME_START_MS;
}
- }
- else if((App.RightLowCS1237_SlopeArray[0] < -App.ADTrack.Slope_VPT/3))
- {
- if((Oll_diff1+Orl_diff1) > App.ADTrack.RightLowVPT/3)
+// }
+// else if((App.RightLowCS1237_SlopeArray[0] < -App.ADTrack.Slope_VPT/3))
+// {
+ if((Oll_diff1+Orl_diff1) > App.ADTrack.RightLowVPT/(App.Para.Layout.ControlLevel+1))
{
BDC_DOWN();
App.UpFlag = false;
@@ -303,7 +320,7 @@ void SupportControlHandle(int32_t *lu_ad, int32_t *ll_ad, int32_t *ru_ad, int32_
App.RunCollDelay1mSCnt = RUN_TIME_MS;
//App.EmergencyDelay1mSCnt = EME_START_MS;
}
- }
+// }
}
}
else if((LeftSlopeSum > RightSlopeSum && LeftDiffSum > RightDiffSum))
@@ -448,7 +465,10 @@ void SupportControlHandle(int32_t *lu_ad, int32_t *ll_ad, int32_t *ru_ad, int32_
App.StopCollDelay1mSCnt = STOP_TIME_MS;
App.EmergencyDelay1mSCnt = EME_START_MS;
}
- else if((LeftLowDiff + EME_STOP_VPT) < RightLowDiff && App.EmergencyDelay1mSCnt <= 0 && App.CentreRunFalg == false)
+ else if((abs(Oll_diff1) + EME_STOP_VPT) < abs(Orl_diff1)
+ && (abs(Oll_diff2) + EME_STOP_VPT) < abs(Orl_diff2)
+ && (abs(Oll_diff3) + EME_STOP_VPT) < abs(Orl_diff3)
+ && App.EmergencyDelay1mSCnt <= 0 && App.CentreRunFalg == false)
{
BDC_STOP();
App.EmeFlag = true;
@@ -469,7 +489,7 @@ void SupportControlHandle(int32_t *lu_ad, int32_t *ll_ad, int32_t *ru_ad, int32_
App.EmergencyDelay1mSCnt = EME_START_MS;
}
else if(((App.CentreRunFalg == false ) && (Orl_diff1 < App.ADTrack.Stop_VPT))
- || ((App.CentreRunFalg == true) && ((Oll_diff1 + Orl_diff1) < (-App.ADTrack.Stop_VPT))))
+ || ((App.CentreRunFalg == true) && ((Oll_diff1 + Orl_diff1) < (App.ADTrack.Stop_VPT))))
{
BDC_STOP();
App.StopFlag = true;
@@ -479,7 +499,10 @@ void SupportControlHandle(int32_t *lu_ad, int32_t *ll_ad, int32_t *ru_ad, int32_
App.StopCollDelay1mSCnt = STOP_TIME_MS;
App.EmergencyDelay1mSCnt = EME_START_MS;
}
- else if(LeftLowDiff > (RightLowDiff + EME_STOP_VPT) && App.EmergencyDelay1mSCnt <= 0 && App.CentreRunFalg == false)
+ else if(abs(Oll_diff1) > (abs(Orl_diff1) + EME_STOP_VPT)
+ && abs(Oll_diff2) > (abs(Orl_diff2) + EME_STOP_VPT)
+ && abs(Oll_diff3) > (abs(Orl_diff3) + EME_STOP_VPT)
+ && App.EmergencyDelay1mSCnt <= 0 && App.CentreRunFalg == false)
{
BDC_STOP();
App.EmeFlag = true;
@@ -492,7 +515,7 @@ void SupportControlHandle(int32_t *lu_ad, int32_t *ll_ad, int32_t *ru_ad, int32_
if(App.LeftRunFalg == true)
{
if(((App.CentreRunFalg == false ) && (ll_slope < -App.ADTrack.Slope_VPT))
- || ((App.CentreRunFalg == true ) && (App.LeftUpCS1237_SlopeArray[0] + App.RightUpCS1237_SlopeArray[0]) > -App.ADTrack.Slope_VPT))
+ || ((App.CentreRunFalg == true ) && (App.LeftUpCS1237_SlopeArray[0] + App.RightUpCS1237_SlopeArray[0]) > App.ADTrack.Slope_VPT))
{
BDC_STOP();
App.StopFlag = true;
@@ -503,7 +526,7 @@ void SupportControlHandle(int32_t *lu_ad, int32_t *ll_ad, int32_t *ru_ad, int32_
App.EmergencyDelay1mSCnt = EME_START_MS;
}
else if(((App.CentreRunFalg == false ) && (Oll_diff1 > -App.ADTrack.Stop_VPT))
- || ((App.CentreRunFalg == true) && ((Oll_diff1 + Orl_diff1) > -(App.ADTrack.Stop_VPT))))
+ || ((App.CentreRunFalg == true) && ((Oll_diff1 + Orl_diff1) > -App.ADTrack.Stop_VPT)))
{
BDC_STOP();
App.StopFlag = true;
@@ -513,7 +536,10 @@ void SupportControlHandle(int32_t *lu_ad, int32_t *ll_ad, int32_t *ru_ad, int32_
App.StopCollDelay1mSCnt = STOP_TIME_MS;
App.EmergencyDelay1mSCnt = EME_START_MS;
}
- else if((LeftLowDiff + EME_STOP_VPT) < RightLowDiff && App.EmergencyDelay1mSCnt <= 0 && App.CentreRunFalg == false)
+ else if((abs(Oll_diff1) + EME_STOP_VPT) < abs(Orl_diff1)
+ && (abs(Oll_diff2) + EME_STOP_VPT) < abs(Orl_diff2)
+ && (abs(Oll_diff3) + EME_STOP_VPT) < abs(Orl_diff3)
+ && App.EmergencyDelay1mSCnt <= 0 && App.CentreRunFalg == false)
{
BDC_STOP();
App.EmeFlag = true;
@@ -544,7 +570,10 @@ void SupportControlHandle(int32_t *lu_ad, int32_t *ll_ad, int32_t *ru_ad, int32_
App.StopCollDelay1mSCnt = STOP_TIME_MS;
App.EmergencyDelay1mSCnt = EME_START_MS;
}
- else if(LeftLowDiff > (RightLowDiff + EME_STOP_VPT) && App.EmergencyDelay1mSCnt <= 0 && App.CentreRunFalg == false)
+ else if(abs(Oll_diff1) > (abs(Orl_diff1) + EME_STOP_VPT)
+ && abs(Oll_diff2) > (abs(Orl_diff2) + EME_STOP_VPT)
+ && abs(Oll_diff3) > (abs(Orl_diff3) + EME_STOP_VPT)
+ && App.EmergencyDelay1mSCnt <= 0 && App.CentreRunFalg == false)
{
BDC_STOP();
App.EmeFlag = true;