FOC开环调试成功

This commit is contained in:
cbb
2025-10-16 21:43:34 +08:00
parent 35801d6f48
commit aaee40f36b
12 changed files with 365 additions and 147 deletions
+30 -16
View File
@@ -1,4 +1,5 @@
#include "Can.h"
#include "DengFOC.h"
#include "gd32c10x.h"
#include "gd32c10x_can.h"
#include <cstdio>
@@ -17,6 +18,7 @@
#define DEV_CAN_LOOPBACK_ID 0x0000
extern CAN_transmiter CAN0_transmiter;
extern FOC_Controlroller FOC;
/*!
\brief initialize CAN GPIO
@@ -276,7 +278,6 @@ void canfd_loopback_test(void) {
}
}
/**
\brief CAN0 回环测试
\param[in] none
@@ -360,17 +361,20 @@ CAN_transmiter::CAN_transmiter() {
\brief CAN 数据更新
*/
void CAN_transmiter::update(void) {
limit_velocity_union.f = 0;
limit_voltage = 0 * 1000;
limit_velocity_union.f = FOC.limit_velocity;
limit_voltage = FOC.limit_voltage * 1000;
mcu_temp = get_mcu_temp() * 100;
motor_temp = get_drv_temp() * 100;
Power_Voltage = get_vbus_voltage() * 1000;
rt_angle_union.f = 0;
rt_velocity_union.f = 0;
Status_code = (gpio_input_bit_get(GPIOB, GPIO_PIN_2) == SET) ? 1 : 0;
target_angle_union.f = 0;
Target_Control_Mode = 0;
target_velocity_union.f = 0;
rt_angle_union.f = 0.0f;
rt_velocity_union.f = 0.0f;
Status_code = (gpio_input_bit_get(GPIOB, GPIO_PIN_2) == SET) ? 0 : 1;
Target_Control_Mode = FOC.control_mode;
controller_Mode = FOC.control_mode;
target_angle_union.f = FOC.target_angle;
target_velocity_union.f = FOC.target_velocity;
u_current_union.f = get_current('U') * 1000;
w_current_union.f = get_current('W') * 1000;
v_current_union.f = get_current('V') * 1000;
@@ -522,13 +526,13 @@ u8 CAN_transmiter::CAN_all_Send() {
// 打包Status_FEED
transmit_data[0] = Status_code;
transmit_data[1] = controller_Mode;
pack_short_to_bytes(transmit_data, 2, motor_temp);
pack_short_to_bytes(transmit_data, 4, mcu_temp);
pack_short_to_bytes(transmit_data, 6, Power_Voltage);
pack_u16_to_bytes(transmit_data, 2, motor_temp);
pack_u16_to_bytes(transmit_data, 4, mcu_temp);
pack_u16_to_bytes(transmit_data, 6, Power_Voltage);
success_flag += CAN_Send(Status_FEED, 8, transmit_data);
// 打包Limit_Vel_Vol_FEED
pack_float_to_bytes(transmit_data, 0, limit_velocity_union);
pack_short_to_bytes(transmit_data, 4, limit_voltage);
pack_u16_to_bytes(transmit_data, 4, limit_voltage);
success_flag += CAN_Send(Limit_Vel_Vol_FEED, 6, transmit_data);
return success_flag;
@@ -545,8 +549,8 @@ u8 CAN_transmiter::CANFD_all_Send() {
constexpr u32 STATUS_ID = 0x18FF0100;
constexpr u32 CONFIG_ID = 0x18FF0101;
// 打包status数据
pack_short_to_bytes(transmit_data, 0, mcu_temp);
pack_short_to_bytes(transmit_data, 2, motor_temp);
pack_u16_to_bytes(transmit_data, 0, mcu_temp);
pack_u16_to_bytes(transmit_data, 2, motor_temp);
pack_u16_to_bytes(transmit_data, 4, u16(u_current_union.f));
pack_u16_to_bytes(transmit_data, 6, u16(w_current_union.f));
pack_u16_to_bytes(transmit_data, 8, u16(v_current_union.f));
@@ -589,11 +593,21 @@ void CAN_transmiter::communication_check() {
// for (i = 0; i < receive_message.rx_dlen; i++) {
// printf(" %02x", receive_message.rx_data[i]);
// }
if (receive_message.rx_efid == 0x18ff0200) {
FOC.control_mode = receive_message.rx_data[0];
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_angle =
unpack_bytes_to_float(receive_message.rx_data, 7).f;
FOC.target_velocity =
unpack_bytes_to_float(receive_message.rx_data, 11).f;
}
can0_receive_flag = RESET;
}
}
/**
* @brief CAN0中断服务程序
* @retval 无