提交提速逻辑的备份

This commit is contained in:
xqq27 2026-05-11 10:11:13 +08:00
parent d1eb8f4d88
commit 97b81a197d
3 changed files with 67 additions and 30 deletions

View File

@ -1,12 +1,17 @@
#include "dehy_test.h" #include "dehy_test.h"
#include "mw_soft_timer.h" #include "mw_soft_timer.h"
#define DEHY_SPEED_MIN (0u)
#define DEHY_SPEED_MAX (800u)
#define DEHY_SPEED_UPDATE_MS (1000u)
#define SPEEDUP_INIT_CMD (0x5AA5)
/*
current_speed取值范围为0至800 target_speed为0400500600700800result_speed后speed_set_valspeed_set_val来让current_speed达到speed_set_val的速度current_speed会掉下去
1. result_speed的初值设为此时的current_speedacc_val的值往上加acc_valresult_speed1 result_speed = result_speed+acc_valresult_speed继续加acc_valresult_speed超过了target_speedresult_speed改为目标速度result_speed一直保持在target_speed
2. target_speed突然变小current_speed大于新的target_speedresult_speed一直保持在当前速度不改变result_speed继续根据加速度a来加
3. target_speed突然变大result_speed继续根据加速度acc_val来增加target_speed
4. target_speed为0result_speed就要变成0.
5.
6. result_speed不要下降
*/
/* 脱水速度设置 枚举变量 */ /* 脱水速度设置 枚举变量 */

View File

@ -10,23 +10,54 @@
6. result_speed不要下降 6. result_speed不要下降
*/ */
void dehy_speed_set(uint16_t init_cmd, uint16_t acc_val, uint16_t current_speed, uint16_t target_speed) /* 脱水速度设置 枚举变量 */
typedef enum
{
DEHY_SPEEDSET_INIT, // 初始化
DEHY_SPEEDSET_SPEED_UP, // 加速
DEHY_SPEEDSET_SPEED_KEEP, // 稳速
DEHY_SPEEDSET_SPEED_STOP, // 超震停机
DEHY_SPEEDSET_NUM
}SPEEDUP_ENUM_T;
/* 外部调用 速度设置值 */
static uint16_t speed_set_val = 0u;
/*************************************************************************************
* @brief
* @param[in/out] val
*
* @warning
* @note
*************************************************************************************/
void motor_speed_set(uint16_t val)
{
speed_set_val = val;
}
void dehy_speed_up(LOGIC_STATE_ENUM_T init_cmd, uint16_t acc_val, uint16_t current_speed, uint16_t target_speed)
{ {
static uint32_t timetick = 0; // 时间戳 static uint32_t timetick = 0; // 时间戳
static uint16_t add_speed_state = 0; // 本函数的状态机 static SPEEDUP_ENUM_T add_speed_state = DEHY_SPEEDSET_INIT; // 本函数的状态机
static uint16_t result_speed = 0; // 预设速度 static uint16_t result_speed = 0; // 预设速度
static uint16_t target_speed_cache = 0; // 缓存目标速度 static uint16_t target_speed_cache = 0; // 缓存目标速度
// static uint16_t current_speed_cache = 0; // 缓存当前速度 // static uint16_t current_speed_cache = 0; // 缓存当前速度
if(init_cmd == 0x5AA5) if(init_cmd == LOGIC_INIT)
{ {
add_speed_state = 0; add_speed_state = DEHY_SPEEDSET_INIT;
}
else
{
;
} }
switch(add_speed_state) switch(add_speed_state)
{ {
// init // init
case 0: case DEHY_SPEEDSET_INIT:
// 时间戳 初始化 // 时间戳 初始化
timetick = get_systick_ms(); timetick = get_systick_ms();
// 预设速度 初始化 // 预设速度 初始化
@ -36,14 +67,14 @@ void dehy_speed_set(uint16_t init_cmd, uint16_t acc_val, uint16_t current_speed,
// // 刷新 当前速度缓存 // // 刷新 当前速度缓存
// current_speed_cache = current_speed; // current_speed_cache = current_speed;
// 进入下一阶段 // 进入下一阶段
add_speed_state = 1; add_speed_state = DEHY_SPEEDSET_SPEED_UP;
break; break;
// 加速 // 加速
case 1: case DEHY_SPEEDSET_SPEED_UP:
// 当前 触发超震 // 当前 触发超震
if(target_speed == 0) if(target_speed == 0)
{ {
add_speed_state = 3; add_speed_state = DEHY_SPEEDSET_SPEED_STOP;
result_speed = 0; result_speed = 0;
} }
// 周期到 // 周期到
@ -70,7 +101,7 @@ void dehy_speed_set(uint16_t init_cmd, uint16_t acc_val, uint16_t current_speed,
// 记录当前速度 // 记录当前速度
result_speed = current_speed; result_speed = current_speed;
// 切到速度保持 // 切到速度保持
add_speed_state = 2; add_speed_state = DEHY_SPEEDSET_SPEED_KEEP;
} }
} }
else else
@ -85,44 +116,45 @@ void dehy_speed_set(uint16_t init_cmd, uint16_t acc_val, uint16_t current_speed,
if(result_speed >= target_speed) if(result_speed >= target_speed)
{ {
result_speed = target_speed; result_speed = target_speed;
add_speed_state = 2; add_speed_state = DEHY_SPEEDSET_SPEED_KEEP;
} }
} }
// 刷新 目标速度缓存 // 刷新 目标速度缓存
target_speed_cache = target_speed; target_speed_cache = target_speed;
/* 设置速度 */
speed_set_val = result_speed;
} }
break; break;
// 速度保持 // 速度保持
case 2: case DEHY_SPEEDSET_SPEED_KEEP:
// 超震停机 // 超震停机
if(target_speed == 0) if(target_speed == 0)
{ {
result_speed = 0; result_speed = 0;
add_speed_state = 3; add_speed_state = DEHY_SPEEDSET_SPEED_STOP;
} }
// 目标速度变好了 外面超震小了 // 目标速度变好了 外面超震小了
else if(target_speed > target_speed_cache) else if(target_speed > target_speed_cache)
{ {
// 若预定速度 小于 新的目标速度,则回去加速
if(result_speed < target_speed)
{
// 回加速
add_speed_state = DEHY_SPEEDSET_SPEED_UP;
}
target_speed_cache = target_speed; target_speed_cache = target_speed;
// // 刷新 当前速度缓存 // // 刷新 当前速度缓存
// current_speed_cache = current_speed; // current_speed_cache = current_speed;
// 回第一步
add_speed_state = 1;
} }
/* 设置速度 */
speed_set_val = result_speed;
break; break;
// 超震停机 // 超震停机
case 3: case DEHY_SPEEDSET_SPEED_STOP:
result_speed = 0; result_speed = 0;
/* 设置速度 */
speed_set_val = result_speed;
break; break;
default: default:
break; break;
} }
/* 设置速度 */
motor_speed_set(result_speed);
} }

View File

@ -2022,7 +2022,7 @@ Image component sizes
672 134 48 32 36 44105 bsp_timer.o 672 134 48 32 36 44105 bsp_timer.o
478 36 0 4 2088 6070 bsp_usart.o 478 36 0 4 2088 6070 bsp_usart.o
0 0 0 0 0 32 core_cm3.o 0 0 0 0 0 32 core_cm3.o
264 22 0 14 0 2470 dehy_test.o 264 22 0 14 0 2366 dehy_test.o
60 4 0 0 0 572 interrupt_handler.o 60 4 0 0 0 572 interrupt_handler.o
204 120 0 0 0 220839 main.o 204 120 0 0 0 220839 main.o
20 10 0 0 0 675 misc.o 20 10 0 0 0 675 misc.o
@ -2036,7 +2036,7 @@ Image component sizes
328 28 0 20 0 3161 system_stm32f10x.o 328 28 0 20 0 3161 system_stm32f10x.o
---------------------------------------------------------------------- ----------------------------------------------------------------------
5900 770 318 136 3248 602755 Object Totals 5900 770 318 136 3248 602651 Object Totals
0 0 32 0 0 0 (incl. Generated) 0 0 32 0 0 0 (incl. Generated)
10 0 2 4 4 0 (incl. Padding) 10 0 2 4 4 0 (incl. Padding)
@ -2079,8 +2079,8 @@ Image component sizes
Code (inc. data) RO Data RW Data ZI Data Debug Code (inc. data) RO Data RW Data ZI Data Debug
6542 800 318 136 3248 599251 Grand Totals 6542 800 318 136 3248 599147 Grand Totals
6542 800 318 136 3248 599251 ELF Image Totals 6542 800 318 136 3248 599147 ELF Image Totals
6542 800 318 136 0 0 ROM Totals 6542 800 318 136 0 0 ROM Totals
============================================================================== ==============================================================================