docs(config): 新增软件和硬件版本号定义
- 定义SOFTWARE_VERSION 26.1.19.1 - 定义HARDWARE_VERSION 25.12.01.0 - 定义BOOT_VERSION 26.1.12.0 feat(motor-control): 实现FOC控制算法速度环优化 refactor(can-protocol): 升级CANFD通信协议支持版本管理 - 实现版本号管理和CANFD_VERSION_ID协议 - 扩展CMD_ID消息解析支持PID参数动态配置 - 添加版本管理器实例并实现版本信息发送功能 - 优化CANFD异步发送数据长度判断逻辑 fix(angle-sensor): 修正角度传感器方向和偏移校准 - 添加ANGLESENS_OFFSET补偿参数 - 反转角度传感器读数方向(DIR = -1.0f) - 在角度计算中应用负向因子和偏移量 chore(memory-layout): 调整Flash存储布局和版本配置 - 扩展BOOTLOADER_SIZE从16KB到24KB - 更新APPLATEST_START_ADDR和APPBACK_START_ADDR偏移 - 重新分配OTA配置参数存储区域 - 增加EEP_DEBUG调试开关 refactor(pid-controller): 增强PID控制器功能接口 - 添加set_P_percent方法支持百分比参数设置 - 格式化PID计算代码提升可读性 - 保留积分和微分环节的约束保护机制
This commit is contained in:
+34
-15
@@ -10,6 +10,7 @@
|
||||
#include "gd32c10x_dma.h"
|
||||
#include "gd32c10x_fmc.h"
|
||||
#include "gd32c10x_gpio.h"
|
||||
#include "initial.h"
|
||||
#include "motor.h"
|
||||
#include "systick.h"
|
||||
#include <cstdio>
|
||||
@@ -29,6 +30,7 @@ extern angle_sensor KTH7823;
|
||||
extern EncoderAngleKalman Angle_kalman; // 角度滤波
|
||||
extern EncoderVelocityKalman Vel_kalman; // 速度滤波
|
||||
extern FlashEEPROM flashEEP;
|
||||
extern VersionManager Version; // 声明外部版本管理器实例
|
||||
|
||||
// 添加DMA相关变量
|
||||
dma_parameter_struct dma_rx_parameter;
|
||||
@@ -574,48 +576,65 @@ void CAN_transmiter::communication_check() {
|
||||
// printf(" %02x", receive_message.rx_data[i]);
|
||||
// }
|
||||
if (receive_message.rx_efid == CANFD_CMD_ID) {
|
||||
// 控制模式
|
||||
FOC.control_mode = receive_message.rx_data[0];
|
||||
if (float(unpack_bytes_to_u16(receive_message.rx_data, 1)) / 1000 !=
|
||||
FOC.limit_voltage) {
|
||||
FOC.limit_voltage =
|
||||
float(unpack_bytes_to_u16(receive_message.rx_data, 1)) /
|
||||
1000;
|
||||
}
|
||||
if (unpack_bytes_to_float(receive_message.rx_data, 3).f !=
|
||||
FOC.limit_velocity) {
|
||||
FOC.limit_velocity =
|
||||
unpack_bytes_to_float(receive_message.rx_data, 3).f;
|
||||
}
|
||||
// 目标角度
|
||||
FOC.limit_voltage =
|
||||
float(unpack_bytes_to_u16(receive_message.rx_data, 1)) / 1000;
|
||||
// 目标电流&目标速度
|
||||
FOC.limit_velocity =
|
||||
unpack_bytes_to_float(receive_message.rx_data, 3).f;
|
||||
FOC.target_current = FOC.limit_velocity;
|
||||
// 目标角度
|
||||
target_angle_union.f =
|
||||
unpack_bytes_to_float(receive_message.rx_data, 7).f;
|
||||
FOC.target_angle = target_angle_union.f;
|
||||
|
||||
// 目标速度
|
||||
target_velocity_union.f =
|
||||
unpack_bytes_to_float(receive_message.rx_data, 11).f;
|
||||
FOC.target_velocity = target_velocity_union.f;
|
||||
FOC.target_current = FOC.target_velocity * 10.0f;
|
||||
|
||||
// 解析PID参数
|
||||
u16 P_config = unpack_bytes_to_u16(receive_message.rx_data, 15);
|
||||
FOC.current_loop.set_P_percent(current_loop_p * P_config);
|
||||
P_config = unpack_bytes_to_u16(receive_message.rx_data, 17);
|
||||
FOC.vel_loop.set_P_percent(vel_loop_p * P_config);
|
||||
P_config = unpack_bytes_to_u16(receive_message.rx_data, 19);
|
||||
FOC.angle_loop.set_P_percent(angle_loop_p * P_config);
|
||||
P_config = unpack_bytes_to_u16(receive_message.rx_data, 21);
|
||||
FOC.vel_inVelAngloop.set_P_percent(vel_angloop_p * P_config);
|
||||
} else if (receive_message.rx_efid == CANFD_RESET_ID) {
|
||||
u8 first_byte = receive_message.rx_data[0];
|
||||
u8 eigth_byte = receive_message.rx_data[7];
|
||||
// 电机重置
|
||||
if (first_byte & 0x01) {
|
||||
motor_reset();
|
||||
}
|
||||
// EEPROM重置
|
||||
if (first_byte >> 1 & 0x01) {
|
||||
flashEEP.format();
|
||||
// flashEEP.format();
|
||||
}
|
||||
// 系统参数保存
|
||||
if (first_byte >> 2 & 0x01) {
|
||||
flashEEP.save_system_config(false);
|
||||
}
|
||||
// 角度传感器重置
|
||||
if (first_byte >> 3 & 0x01) {
|
||||
KTH7823.angle_set(0);
|
||||
Angle_kalman.init(0); // 角度滤波
|
||||
Vel_kalman.init(0); // 角度滤波
|
||||
}
|
||||
// 休眠
|
||||
if (eigth_byte & 0x80 >> 7) {
|
||||
app_prepare_deep_sleep(true);
|
||||
// CAN_Sleep();
|
||||
}
|
||||
} else if (receive_message.rx_efid == CANFD_VERSION_ID) {
|
||||
// 处理版本号请求,发送当前系统版本信息
|
||||
Version.sendVersionInfoViaCan();
|
||||
} else if (receive_message.rx_efid == CANFD_BOOT_ID) {
|
||||
flashEEP.save_system_config(false);
|
||||
fmc_unlock();
|
||||
OTA_SET(n_APP_LATEST_EN_ADDR, OTA_NOT_AVAL); // 设置APP为不激活
|
||||
fmc_lock();
|
||||
@@ -805,9 +824,9 @@ u8 CAN_transmiter::CANFD_AsyncSend(u32 id, u8 length, u8 *data) {
|
||||
valid_length = 16;
|
||||
} else if (length > 16 and length < 21) {
|
||||
valid_length = 20;
|
||||
} else if (length > 20 and length < 24) {
|
||||
} else if (length > 20 and length < 25) {
|
||||
valid_length = 24;
|
||||
} else if (length > 28 and length < 33) {
|
||||
} else if (length > 24 and length < 33) {
|
||||
valid_length = 32;
|
||||
} else if (length > 32 and length < 49) {
|
||||
valid_length = 48;
|
||||
|
||||
Reference in New Issue
Block a user