Files
linear-Slide/Application/app_main.c

90 lines
2.1 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#include "main.h"
#include "tim.h"
#include "usart.h"
#include "gpio.h"
#include "app_main.h"
#include "Com_type.h"
#include "Com_debug.h"
#include "Int_Encoder.h"
#include "Int_TMC2209.h"
#include "app_key.h"
#include "app_motor.h"
#include "app_param_store.h"
#include "app_test.h"
#include "CANopen.h"
#include "CO_app_STM32.h"
#include "can.h"
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, // 启动速度
};
CANopenNodeSTM32 CANopenNode;
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 */
canopen_app_init(&CANopenNode);
}
void app_main(void)
{
debug_printf("hello three-axis steppers");
CANopenNode_init();
App_Motor_Init();
App_ParamStore_Init();
(void)App_ParamStore_LoadAndApply();
while (1)
{
App_key_run(&stepper_1);
canopen_app_process();
App_Motor_Process();
App_ParamStore_Process();
}
}
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;
default:
break;
}
}
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
if (htim == CANopenNode.timerHandle)
{
canopen_app_interrupt();
}
if (htim->Instance == TIM12)
{
App_Motor_StepLossCheck();
}
}