DRV8313兼容版

refactor(algorithm): 移除冗余头文件
移除不必要的stdint.h头文件引用,统一使用<cstdint>

refactor(sys): 清理系统级头文件依赖
移除未使用的头文件引用,统一整型类型定义,优化初始
化过程中的GPIO配置
This commit is contained in:
cbb
2026-01-24 01:50:39 +08:00
parent 3f24292ac1
commit 1596b2beb0
24 changed files with 76 additions and 64 deletions
+2 -2
View File
@@ -10,7 +10,6 @@
#include <arm_math.h>
#include <cmath>
#include <gd32c10x.h>
#include <stdint.h>
FOC_Controlroller FOC; // FOC控制初始化
@@ -58,7 +57,7 @@ inline float FOC_Controlroller::cal_Iq_Id(float current_a, float current_b,
// arm_park_f32(I_alpha, I_beta, &I_d, &I_q, sin_el, cos_el);
return I_q * 1000.0f -
KE_FACTOR * rt_velocity; // 返回Iq值,乘以1000以转换为mA
KE_FACTOR * rt_velocity; // 返回Iq值,乘以100以转换为mA
}
/**
@@ -79,6 +78,7 @@ u8 FOC_Controlroller::init() {
ang_inVelAngloop.set_PID(ang_angloop_p * 100 / limit_voltage, 0.0f,
5e-4); // 设置电机角度控制参数
return 0;
}
+12 -3
View File
@@ -3,12 +3,15 @@
#define _FOC_H
#include "config.h"
#include "pid.h"
#include <stdint.h>
#include <cstdint>
class FOC_Controlroller {
public:
FOC_Controlroller();
// 初始化函数
u8 init();
u8 control_mode = 0;
float limit_voltage = 0.0f;
@@ -22,10 +25,9 @@ class FOC_Controlroller {
bool voltage_error = false;
bool is_shut_down = false;
float voltage_power_supply = 24.0f; // 电源电压
float v_safe = voltage_power_supply * 1.05f;
float v_safe = voltage_power_supply * 0.95f;
float duty_a = 0, duty_b = 0, duty_c = 0;
float Ua = 0, Ub = 0, Uc = 0;
u8 init(void);
float velocity_open_loop(void);
float angle_control(void);
float angle_control_with_velocity_limit(void);
@@ -50,6 +52,13 @@ class FOC_Controlroller {
PIDController ang_inVelAngloop =
PIDController{ang_angloop_p * 100, 0.0f, 5e-4, 1000000, 999};
void update_pid_limits() {
vel_loop.limit = voltage_power_supply;
angle_loop.limit = voltage_power_supply;
current_loop.limit = voltage_power_supply;
vel_inVelAngloop.limit = voltage_power_supply;
}
protected:
float shaft_angle = 0;
float Ualpha, Ubeta = 0;
-1
View File
@@ -4,7 +4,6 @@
#include "config.h"
#include <algorithm>
#include <cstring>
#include <stdint.h>
extern angle_sensor KTH7823;
extern CAN_transmiter CAN0_transmiter;
+1 -1
View File
@@ -14,7 +14,7 @@ extern "C" {
#ifdef __cplusplus
#include <cstring>
#include <stdint.h>
#include <cstdint>
float medium_filter(float values[], u8 size);
+2 -1
View File
@@ -2,7 +2,8 @@
#define _constrain(amt, low, high) \
((amt) < (low) ? (low) : ((amt) > (high) ? (high) : (amt)))
#include "Can.h"
#include "math.h"
#include <algorithm>
#include <cmath>
extern CAN_transmiter CAN0_transmiter;
constexpr float TIME_SLICE = 1e-4;
+16 -17
View File
@@ -1,26 +1,25 @@
#ifndef PID_H
#define PID_H
class PIDController
{
public:
PIDController(float P, float I, float D, float ramp, float limit);
~PIDController() = default;
class PIDController {
public:
PIDController(float P, float I, float D, float ramp, float limit);
~PIDController() = default;
float operator() (float error);
float operator()(float error);
void set_PID(float P, float I, float D);
void set_P_percent(float pp);
float P; //!< 比例增益(P环增益)
float I; //!< 积分增益(I环增益)
float D; //!< 微分增益(D环增益)
float output_ramp;
float limit;
protected:
float error_prev; //!< 最后的跟踪误差值
float output_prev; //!< 最后一个 pid 输出值
float integral_prev; //!< 最后一个积分分量值
unsigned long timestamp_prev; //!< 上次执行时间戳
};
float P; //!< 比例增益(P环增益)
float I; //!< 积分增益(I环增益)
float D; //!< 微分增益(D环增益)
float output_ramp;
float limit;
protected:
float error_prev; //!< 最后的跟踪误差值
float output_prev; //!< 最后一个 pid 输出值
float integral_prev; //!< 最后一个积分分量值
unsigned long timestamp_prev; //!< 上次执行时间戳
};
#endif