v1.1添加按键功能的中文日志说明,改进了零点逻辑,之前回零成功后再次下发回零还会移动然后撞到限位开关,现在会正确保持在零点

This commit is contained in:
编程浩
2026-03-02 14:57:34 +08:00
parent b2fedd58b2
commit 25d82ccd66
8 changed files with 1821 additions and 1535 deletions

View File

@@ -1,4 +1,4 @@
#include "main.h"
#include "main.h"
#include "tim.h"
#include "usart.h"
#include "gpio.h"
@@ -18,33 +18,43 @@
Encoder_t encoder_1 = {0};
// 静音最大速度65mm/s
// 有效运动最大速度350mm/s
// 最远运行距离230mm
Stepper_t stepper_1 = {
.dir = GPIO_PIN_RESET, // 方向(1为手轮方向0为电机方向)
.distance = 100.0f, // 距离mm
.speed = 50.0f, // 速度mm/s
.acc = 40.0f, // 加速度 mm/s^2
.dec = 40.0f, // 减速度 mm/s^2
.start_speed = 5.0f, // 启动速度
.dir = GPIO_PIN_RESET, // 方向(1为手轮方向0为电机方向)
.distance = 100.0f,
.speed = 50.0f,
.acc = 40.0f,
.dec = 40.0f,
.start_speed = 5.0f,
};
CANopenNodeSTM32 CANopenNode;
static void App_PrintKeyUsage(void)
{
debug_printf("%s", "================ 按键功能说明 ================");
debug_printf("%s", "K1 (单击): 自动回零 (HOME, 低速 5 mm/s)");
debug_printf("%s", "K2 (长按): JOG+ 正向点动, 松开后减速停止");
debug_printf("%s", "K3 (长按): JOG- 反向点动, 松开后减速停止");
debug_printf("%s", "K4 (单击): 速度档位循环 5 -> 25 -> 60 mm/s");
debug_printf("%s", "K5 (单击): 紧急停止 (立即停机)");
debug_printf("%s", "提示: 回零完成以零位开关触发为准");
debug_printf("%s", "==============================================");
}
static void CANopenNode_init(void)
{
/* 初始化CANopen */
CANopenNode.CANHandle = &hcan1; /* 使用CAN接口 */
CANopenNode.HWInitFunction = MX_CAN1_Init; /* 初始化CAN */
CANopenNode.timerHandle = &htim11; /* 使用的定时器句柄 */
CANopenNode.desiredNodeID = 3; /* Node-ID */
CANopenNode.baudrate = 500; /* 波特率单位KHz */
CANopenNode.CANHandle = &hcan1;
CANopenNode.HWInitFunction = MX_CAN1_Init;
CANopenNode.timerHandle = &htim11;
CANopenNode.desiredNodeID = 3;
CANopenNode.baudrate = 500;
canopen_app_init(&CANopenNode);
}
void app_main(void)
{
debug_printf("hello three-axis steppers");
App_PrintKeyUsage();
CANopenNode_init();
App_Motor_Init();
App_ParamStore_Init();
@@ -62,11 +72,9 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
switch (GPIO_Pin)
{
// PE2对应X_ZERO引脚
case X_ZERO_Pin:
stepper_1.x_zero = 1;
break;
// PC9对应编码器1的Z引脚
case ENCODER1_Z_Pin:
encoder_1.z++;
break;