refactor(main): 统一外设初始化流程
集中所有外设初始化于main函数起始处,通过返回值确认各模块是否成功启动; refactor(adc): 修改采样器初始化返回值 将sampler构造函数替换为带返回值的init方法,在main函数中加入初始化结果判断, 确保系统启动时硬件配置正确加载。 feat(motor): 引入motor模块并重构电机控制逻辑 将GPIO操作封装进motor_sleep和motor_resume函数,提升代码可读性和维护性。 引入motor.h头文件,并在main.cpp中进行电机初始化统一管理。 修改FOC控制器中的shutdown与resume方法调用新接口。 refactor(filter): 优化卡尔曼滤波器实现 重命名状态变量xp为x,简化访问逻辑;移除冗余注释及未使用的getlastAngle方法; 调整getVelocity计算系数,提高速度估算精度;增加init方法支持初始状态设置。 refactor(angle_sensor): 移除冗余速度计算功能 删除传感器内部的速度估算相关数组和方法,交由外部滤波器处理以降低耦合度。 更新SPI片选宏定义以区分不同设备,并增强错误处理机制。 refactor(can): 调整CAN通信ID及初始化流程 更改状态与配置帧的标识符ID,添加对特定命令ID的响应处理如电机复位指令。 将CAN_transmiter构造函数改为init方法,配合主程序完成模块化初始化检查。
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
#include <cmath>
|
||||
#include <gd32c10x.h>
|
||||
#include <stdint.h>
|
||||
#include "motor.h"
|
||||
|
||||
constexpr double PI = 3.1415926535897932384626433832795f;
|
||||
constexpr float ANGLE_FACTOR = 25.0f / 360.0f * 2.0f * 3.14159265358979323846f;
|
||||
@@ -112,7 +113,7 @@ inline void FOC_Controlroller::setPhaseVoltage(float Uq, float Ud) {
|
||||
*/
|
||||
void FOC_Controlroller::shut_down() {
|
||||
is_shut_down = 1;
|
||||
gpio_bit_reset(GPIOB, GPIO_PIN_12);
|
||||
motor_sleep();
|
||||
}
|
||||
/**
|
||||
* @brief 占空比置0
|
||||
@@ -138,7 +139,7 @@ void FOC_Controlroller::resume() {
|
||||
over_current = false;
|
||||
voltage_error = false;
|
||||
is_shut_down = false;
|
||||
gpio_bit_set(GPIOB, GPIO_PIN_12);
|
||||
motor_resume();
|
||||
}
|
||||
/**
|
||||
* @brief 更新电源电压
|
||||
@@ -235,13 +236,13 @@ float FOC_Controlroller::angle_control_NPID(float target_angle) {
|
||||
*/
|
||||
float FOC_Controlroller::velocity_control(float target_velocity) {
|
||||
// PID 控制计算
|
||||
float Uq = vel_loop(target_velocity - rt_velocity);
|
||||
float Uq = vel_loop((target_velocity - rt_velocity)*25);
|
||||
|
||||
// 获取电机轴角度
|
||||
shaft_angle = KTH7823.getcurrent_sensorangle() * DEG2RAD;
|
||||
// 设置相电压
|
||||
setPhaseVoltage(Uq, 0.0f);
|
||||
CAN0_transmiter.testfloat_union.f =
|
||||
// CAN0_transmiter.testfloat_union.f =
|
||||
cal_Iq_Id(sampler.get_current('U'), sampler.get_current('V'), sampler.get_current('W'));
|
||||
return rt_velocity;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user