FOC系列电机入门知识
原文链接:https:/
/* * foc.c * * Created on: 2024年9月1日 * Author: 13624 */ #include"main.h" #include "foc.h" //帕克变换 float u_d;//d坐标系电压 float u_q;//q坐标系电压 float theta;//电角度 //克拉克变换 float u_alpha;// float u_beta;// //svpwm float t_a; float t_b; float t_c; float i_a; float i_b; float i_c; float i_alpha; float i_beta; float i_d; float i_q; void ipark() { sine = sin(theta); cosine = cos(theta); u_alpha = u_d * cosine - u_q * sine; u_beta = u_q * cosine + u_d * sine; } void ipark2() { u_alpha = u_d * cosine - u_q * sine; u_beta = u_q * cosine + u_d * sine; } void clarke() { i_alpha = i_a; i_beta = (i_a + 2 * i_b) *0.5773502691896257;//sqrt(3) = 0.5773502691896257; } void park() { sine = sin(theta); cosine = cos(theta); i_d = i_alpha * cosine + i_beta * sine; i_q = i_beta * cosine - i_alpha * sine; } void svpwm() { const float ts = 1; float u1 = u_beta; float u2 = -0.8660254037844386 * u_alpha - 0.5 * u_beta; float u3 = 0.8660254037844386 * u_alpha - 0.5 * u_beta; uint8_t sector = (u1 > 0.0) + ((u2 > 0.0) << 1) + ((u3 > 0.0) << 2); if (sector == 5) { float t4 = u3; float t6 = u1; float sum = t4 + t6; if (sum > ts) { k_svpwm = ts / sum; t4 = k_svpwm * t4; t6 = k_svpwm * t6; } float t7 = (ts - t4 - t6) / 2; t_a = t4 + t6 + t7; t_b = t6 + t7; t_c = t7; } else if (sector == 1) { float t2 = -u3; float t6 = -u2; float sum = t2 + t6; if (sum > ts) { k_svpwm = ts / sum; t2 = k_svpwm * t2; t6 = k_svpwm * t6; } float t7 = (ts - t2 - t6) / 2; t_a = t6 + t7; t_b = t2 + t6 + t7; t_c = t7; } else if (sector == 3) { float t2 = u1; float t3 = u2; float sum = t2 + t3; if (sum > ts) { k_svpwm = ts / sum; t2 = k_svpwm * t2; t3 = k_svpwm * t3; } float t7 = (ts - t2 - t3) / 2; t_a = t7; t_b = t2 + t3 + t7; t_c = t3 + t7; } else if (sector == 2) { float t1 = -u1; float t3 = -u3; float sum = t1 + t3; if (sum > ts) { k_svpwm = ts / sum; t1 = k_svpwm * t1; t3 = k_svpwm * t3; } float t7 = (ts - t1 - t3) / 2; t_a = t7; t_b = t3 + t7; t_c = t1 + t3 + t7; } else if (sector == 6) { float t1 = u2; float t5 = u3; float sum = t1 + t5; if (sum > ts) { k_svpwm = ts / sum; t1 = k_svpwm * t1; t5 = k_svpwm * t5; } float t7 = (ts - t1 - t5) / 2; t_a = t5 + t7; t_b = t7; t_c = t1 + t5 + t7; } else if (sector == 4) { float t4 = -u2; float t5 = -u1; float sum = t4 + t5; if (sum > ts) { k_svpwm = ts / sum; t4 = k_svpwm * t4; t5 = k_svpwm * t5; } float t7 = (ts - t4 - t5) / 2; t_a = t4 + t5 + t7; t_b = t7; t_c = t5 + t7; } } void Foc_Run() { for (double theta = 0; theta < 7; theta += 1e-3) { foc.u_d = 0.1; foc.u_q = 0; foc.theta = theta; foc.ipark(); foc.svpwm(); double u_a = foc.t_a - 0.5 * (foc.t_b + foc.t_c); double u_b = foc.t_b - 0.5 * (foc.t_a + foc.t_c); double u_c = -(u_a + u_b); __HAL_TIM_SET_COMPARE(&htim1,TIM_CHANNEL_1,u_a*4200); __HAL_TIM_SET_COMPARE(&htim1,TIM_CHANNEL_2,u_b*4200); __HAL_TIM_SET_COMPARE(&htim1,TIM_CHANNEL_3,u_c*4200); }
/*
* foc.h
*
* Created on: 2024年9月1日
* Author: 13624
*/
#ifndef INC_FOC_H_
#define INC_FOC_H_
//帕克变换
extern float u_d;//d坐标系电压
extern float u_q;//q坐标系电压
extern float theta;//电角度
//克拉克变换
extern float u_alpha;//
extern float u_beta;//
//svpwm
extern float t_a;
extern float t_b;
extern float t_c;
extern float i_a;
extern float i_b;
extern float i_c;
extern float i_alpha;
extern float i_beta;
float i_d;
float i_q;
void ipark() ;
void ipark2();
void clarke() ;
void park() ;
void svpwm() ;
void Foc_Run();
#endif /* INC_FOC_H_ */
/blog.csdn.net/qq_35947329/article/details/115483413
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Ollama——大语言模型本地部署的极速利器
· 使用C#创建一个MCP客户端
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· Windows编程----内核对象竟然如此简单?
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用