变更
This commit is contained in:
27
BoooomCTL/Common/PID/PID.c
Normal file
27
BoooomCTL/Common/PID/PID.c
Normal file
@@ -0,0 +1,27 @@
|
||||
//
|
||||
// Created by ZK on 2023/3/14.
|
||||
//
|
||||
|
||||
#include "PID.h"
|
||||
|
||||
float PID_Generate(PID *pid) {
|
||||
pid->error = pid->target - pid->value;
|
||||
|
||||
if (pid->error > pid->errMin || pid->error < -pid->errMin)
|
||||
pid->errSum += pid->error * pid->ki;
|
||||
|
||||
if (pid->errSum > pid->errSumMax)
|
||||
pid->errSum = pid->errSumMax;
|
||||
else if (pid->errSum < -pid->errSumMax)
|
||||
pid->errSum = -pid->errSumMax;
|
||||
|
||||
pid->errDt = pid->error - pid->lastErr;
|
||||
pid->lastErr = pid->error;
|
||||
|
||||
pid->result = pid->kp * pid->error + pid->errSum + pid->kd * pid->errDt;
|
||||
|
||||
if (pid->result > pid->valMax)
|
||||
pid->result = pid->valMax;
|
||||
else if (pid->result < -pid->valMax)
|
||||
pid->result = -pid->valMax;
|
||||
}
|
||||
32
BoooomCTL/Common/PID/PID.h
Normal file
32
BoooomCTL/Common/PID/PID.h
Normal file
@@ -0,0 +1,32 @@
|
||||
//
|
||||
// Created by ZK on 2023/3/14.
|
||||
//
|
||||
|
||||
#ifndef BOOOOMFOC_STSPIN32G4_EVB_PID_H
|
||||
#define BOOOOMFOC_STSPIN32G4_EVB_PID_H
|
||||
|
||||
typedef struct pid {
|
||||
float kp;//比例系数
|
||||
float ki;//积分系数
|
||||
float kd;//微分系数
|
||||
|
||||
float target;
|
||||
float value;
|
||||
float error;
|
||||
|
||||
float errSum;
|
||||
float errSumMax;
|
||||
|
||||
float errMin;
|
||||
float valMax;
|
||||
|
||||
float lastErr;
|
||||
float errDt;
|
||||
|
||||
float result;
|
||||
} PID;
|
||||
|
||||
float PID_Generate(PID *pid);
|
||||
|
||||
|
||||
#endif //BOOOOMFOC_STSPIN32G4_EVB_PID_H
|
||||
43
BoooomCTL/Communication/Communication.c
Normal file
43
BoooomCTL/Communication/Communication.c
Normal file
@@ -0,0 +1,43 @@
|
||||
//
|
||||
// Created by ZK on 2023/3/14.
|
||||
//
|
||||
|
||||
//#include "Communication.h"
|
||||
#include "APP_Main.h"
|
||||
|
||||
#define BYTE0(dwTemp) (*(char*)(&dwTemp))
|
||||
#define BYTE1(dwTemp) (*((char*)(&dwTemp) + 1))
|
||||
#define BYTE2(dwTemp) (*((char*)(&dwTemp) + 2))
|
||||
#define BYTE3(dwTemp) (*((char*)(&dwTemp) + 3))
|
||||
|
||||
uint8_t USBCDC_SendBuffur[APP_TX_DATA_SIZE];
|
||||
|
||||
void SendCurrent_Vofa(float a, float b, float c) {
|
||||
uint16_t USBCDC_SendBuffur_count = 0;
|
||||
|
||||
USBCDC_SendBuffur[USBCDC_SendBuffur_count++] = BYTE0(a);
|
||||
USBCDC_SendBuffur[USBCDC_SendBuffur_count++] = BYTE1(a);
|
||||
USBCDC_SendBuffur[USBCDC_SendBuffur_count++] = BYTE2(a);
|
||||
USBCDC_SendBuffur[USBCDC_SendBuffur_count++] = BYTE3(a);
|
||||
USBCDC_SendBuffur[USBCDC_SendBuffur_count++] = BYTE0(b);
|
||||
USBCDC_SendBuffur[USBCDC_SendBuffur_count++] = BYTE1(b);
|
||||
USBCDC_SendBuffur[USBCDC_SendBuffur_count++] = BYTE2(b);
|
||||
USBCDC_SendBuffur[USBCDC_SendBuffur_count++] = BYTE3(b);
|
||||
USBCDC_SendBuffur[USBCDC_SendBuffur_count++] = BYTE0(c);
|
||||
USBCDC_SendBuffur[USBCDC_SendBuffur_count++] = BYTE1(c);
|
||||
USBCDC_SendBuffur[USBCDC_SendBuffur_count++] = BYTE2(c);
|
||||
USBCDC_SendBuffur[USBCDC_SendBuffur_count++] = BYTE3(c);
|
||||
// USBCDC_SendBuffur[USBCDC_SendBuffur_count++] = BYTE0(a);
|
||||
// USBCDC_SendBuffur[USBCDC_SendBuffur_count++] = BYTE1(a);
|
||||
// USBCDC_SendBuffur[USBCDC_SendBuffur_count++] = BYTE0(b);
|
||||
// USBCDC_SendBuffur[USBCDC_SendBuffur_count++] = BYTE1(b);
|
||||
// USBCDC_SendBuffur[USBCDC_SendBuffur_count++] = BYTE0(c);
|
||||
// USBCDC_SendBuffur[USBCDC_SendBuffur_count++] = BYTE1(c);
|
||||
|
||||
USBCDC_SendBuffur[USBCDC_SendBuffur_count++] = 0x00;
|
||||
USBCDC_SendBuffur[USBCDC_SendBuffur_count++] = 0x00;
|
||||
USBCDC_SendBuffur[USBCDC_SendBuffur_count++] = 0x80;
|
||||
USBCDC_SendBuffur[USBCDC_SendBuffur_count++] = 0x7f;
|
||||
|
||||
CDC_Transmit_FS(USBCDC_SendBuffur, USBCDC_SendBuffur_count);
|
||||
}
|
||||
12
BoooomCTL/Communication/Communication.h
Normal file
12
BoooomCTL/Communication/Communication.h
Normal file
@@ -0,0 +1,12 @@
|
||||
//
|
||||
// Created by ZK on 2023/3/14.
|
||||
//
|
||||
|
||||
#ifndef BOOOOMFOC_STSPIN32G4_EVB_COMMUNICATION_H
|
||||
#define BOOOOMFOC_STSPIN32G4_EVB_COMMUNICATION_H
|
||||
|
||||
|
||||
void SendCurrent_Vofa(float a, float b, float c);
|
||||
|
||||
|
||||
#endif //BOOOOMFOC_STSPIN32G4_EVB_COMMUNICATION_H
|
||||
62
BoooomCTL/Communication/Vofa/VOFA.c
Normal file
62
BoooomCTL/Communication/Vofa/VOFA.c
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* author <20><><EFBFBD><EFBFBD>A<EFBFBD><41>
|
||||
* date: 2022/10/21
|
||||
* description: <20><>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>Ƽ<EFBFBD>ʹ<EFBFBD><CAB9>vofa <20><>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>ÿ<EFBFBD><C3BF><EFBFBD>Ƶ<EFBFBD>ʿ<EFBFBD><CABF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĺܸߣ<DCB8><DFA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʲô<CAB2>ı<EFBFBD>ɽ<EFBFBD>ⷽ<EFBFBD><E2B7BD><EFBFBD><EFBFBD>ˡ<EFBFBD>
|
||||
* ɽ<><C9BD><EFBFBD>Ǹ<EFBFBD>̫<EFBFBD><CCAB><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>Ŀǰ<C4BF><C7B0>justfloat<61><74> <20>ɱ<EFBFBD><C9B1><EFBFBD><EFBFBD> <20>ȽϷ<C8BD><CFB7><EFBFBD>
|
||||
*
|
||||
*/
|
||||
#include <stdarg.h>
|
||||
//#include "zf_device_wireless_uart.h" //<2F><><EFBFBD><EFBFBD><EFBFBD>滻Ϊ<E6BBBB><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ߴ<EFBFBD><DFB4><EFBFBD>ͷ<EFBFBD>ļ<EFBFBD> <20><>ʹ<EFBFBD>õ<EFBFBD><C3B5><EFBFBD>zf <20><><EFBFBD>ߴ<EFBFBD><DFB4><EFBFBD>
|
||||
#include "VOFA.h"
|
||||
#include "APP_Main.h"
|
||||
/**
|
||||
* @description: <20><><EFBFBD>ݷ<EFBFBD><DDB7>ͽӿڷ<D3BF>װ<EFBFBD><D7B0><EFBFBD>뽫<EFBFBD>Լ<EFBFBD><D4BC>Ĵ<EFBFBD><C4B4>ڷ<EFBFBD><DAB7><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>װ<EFBFBD><D7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* Э<><D0AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD><EFBFBD>ɺ<EFBFBD><C9BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݷ<EFBFBD><DDB7>ͳ<EFBFBD>ȥ
|
||||
* @param
|
||||
* buf : <20><>Ҫ<EFBFBD><D2AA><EFBFBD>͵<EFBFBD><CDB5>ַ<EFBFBD><D6B7><EFBFBD>
|
||||
* len : <20>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* @return:
|
||||
*
|
||||
* @demo
|
||||
* uart_send_buf_fcn(send_buf, 8); //<2F><>send_buf<75><66><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͳ<EFBFBD>ȥ<EFBFBD><C8A5><EFBFBD><EFBFBD><EFBFBD>ͳ<EFBFBD><CDB3><EFBFBD>Ϊ8
|
||||
*/
|
||||
static inline void uart_send_buf_fcn(uint8_t *buf, uint16_t len) //<2F><><EFBFBD>ݱ<EFBFBD><DDB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ؼ<EFBFBD><D8BC>ֿ<EFBFBD><D6BF>ܲ<EFBFBD>ͬ,ȥ<><C8A5>inlineЧ<65>ʻ<EFBFBD><CABB><EFBFBD><EFBFBD><CEA2>һЩ
|
||||
{
|
||||
for(int i=0;i<len;i++)
|
||||
{
|
||||
// wireless_uart_send_byte(*buf++); //<2F><><EFBFBD><EFBFBD>ʹ<EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ߴ<EFBFBD><DFB4><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ij<DEB8><C4B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: <20><><EFBFBD>ؼ<EFBFBD><D8BC><EFBFBD>λ<EFBFBD><CEBB> JustFloat ģʽ<C4A3><CABD><EFBFBD>ɱ䳤<C9B1><E4B3A4>Э<EFBFBD>鷢<EFBFBD><E9B7A2>
|
||||
* @param
|
||||
* len : <20><>Ҫ<EFBFBD><D2AA><EFBFBD>͵<EFBFBD><CDB5><EFBFBD><EFBFBD>ݸ<EFBFBD><DDB8><EFBFBD>
|
||||
* ... : <20><>Ҫ<EFBFBD><D2AA><EFBFBD>͵<EFBFBD><CDB5><EFBFBD><EFBFBD><EFBFBD>(<28><><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)<29><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(<28><><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)<29><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* ǿת<C7BF><D7AA>float<61><74><EFBFBD><EFBFBD>
|
||||
* @return:
|
||||
*
|
||||
* @demo
|
||||
* vodka_JustFloat_send(5, data1, data2, 3.14f, data4, data5);
|
||||
* vodka_JustFloat_send(1,(float)int<6E><74><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>);
|
||||
*/
|
||||
float justfloat_send_buf[kWaveNumMax+1] = {0};
|
||||
void vodka_JustFloat_send(int len,...)
|
||||
{
|
||||
float* pfloat = justfloat_send_buf; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
int32_t* pend = NULL; //֡β
|
||||
uint8_t* psend = (uint8_t*)justfloat_send_buf; //<2F><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>
|
||||
if(len > kWaveNumMax) return;
|
||||
va_list float_data;
|
||||
va_start(float_data, len);
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
*pfloat++ = (float)va_arg(float_data, double);
|
||||
}
|
||||
va_end(float_data);
|
||||
// pend = (int*)pfloat;
|
||||
*pend = (int)(0x7f800000);
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ô<EFBFBD><C3B4><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>psend<6E><64><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȥ */
|
||||
uart_send_buf_fcn(psend, (len+1)*sizeof(float));
|
||||
}
|
||||
|
||||
5
BoooomCTL/Communication/Vofa/VOFA.h
Normal file
5
BoooomCTL/Communication/Vofa/VOFA.h
Normal file
@@ -0,0 +1,5 @@
|
||||
#ifndef VOFA_H_
|
||||
#define VOFA_H_
|
||||
#define kWaveNumMax 20
|
||||
void vodka_JustFloat_send(int len,...); //<2F>ɱ䳤<C9B1><E4B3A4><EFBFBD><EFBFBD>(<28><><EFBFBD>÷<EFBFBD><C3B7><EFBFBD>)
|
||||
#endif
|
||||
6
BoooomCTL/Controller/Controller.c
Normal file
6
BoooomCTL/Controller/Controller.c
Normal file
@@ -0,0 +1,6 @@
|
||||
//
|
||||
// Created by ZK on 2023/3/14.
|
||||
//
|
||||
|
||||
#include "Controller.h"
|
||||
|
||||
8
BoooomCTL/Controller/Controller.h
Normal file
8
BoooomCTL/Controller/Controller.h
Normal file
@@ -0,0 +1,8 @@
|
||||
//
|
||||
// Created by ZK on 2023/3/14.
|
||||
//
|
||||
|
||||
#ifndef BOOOOMFOC_STSPIN32G4_EVB_CONTROLLER_H
|
||||
#define BOOOOMFOC_STSPIN32G4_EVB_CONTROLLER_H
|
||||
|
||||
#endif //BOOOOMFOC_STSPIN32G4_EVB_CONTROLLER_H
|
||||
23
BoooomCTL/Controller/PreDrive/PreDrive.c
Normal file
23
BoooomCTL/Controller/PreDrive/PreDrive.c
Normal file
@@ -0,0 +1,23 @@
|
||||
//
|
||||
// Created by ZK on 2023/3/14.
|
||||
//
|
||||
|
||||
#include "PreDrive.h"
|
||||
|
||||
|
||||
|
||||
uint8_t PreDrive_Init_Buffur[2] = {0x00, 0x00};
|
||||
|
||||
|
||||
bool PreDrive_Init(void){
|
||||
while (HAL_I2C_Mem_Write(&hi2c3, 0x8e, 0x0c, I2C_MEMADD_SIZE_8BIT, PreDrive_Init_Buffur, 1, 1000) != HAL_OK) {}
|
||||
PreDrive_Init_Buffur[0] = 0x00;
|
||||
while (HAL_I2C_Mem_Write(&hi2c3, 0x8e, 0x0c, I2C_MEMADD_SIZE_8BIT, PreDrive_Init_Buffur, 1, 1000) != HAL_OK) {}
|
||||
PreDrive_Init_Buffur[0] = 0xff;
|
||||
while (HAL_I2C_Mem_Write(&hi2c3, 0x8e, 0x09, I2C_MEMADD_SIZE_8BIT, PreDrive_Init_Buffur, 1, 1000) != HAL_OK) {}
|
||||
PreDrive_Init_Buffur[0] = 0x00;
|
||||
while (HAL_I2C_Mem_Write(&hi2c3, 0x8e, 0x09, I2C_MEMADD_SIZE_8BIT, PreDrive_Init_Buffur, 1, 1000) != HAL_OK) {}
|
||||
HAL_Delay(10);
|
||||
|
||||
return 0;
|
||||
}
|
||||
13
BoooomCTL/Controller/PreDrive/PreDrive.h
Normal file
13
BoooomCTL/Controller/PreDrive/PreDrive.h
Normal file
@@ -0,0 +1,13 @@
|
||||
//
|
||||
// Created by ZK on 2023/3/14.
|
||||
//
|
||||
|
||||
#ifndef BOOOOMFOC_STSPIN32G4_EVB_PREDRIVE_H
|
||||
#define BOOOOMFOC_STSPIN32G4_EVB_PREDRIVE_H
|
||||
|
||||
#include "APP_Main.h"
|
||||
|
||||
bool PreDrive_Init(void);
|
||||
|
||||
|
||||
#endif //BOOOOMFOC_STSPIN32G4_EVB_PREDRIVE_H
|
||||
128
BoooomCTL/Controller/SVPWM/SVPWM.c
Normal file
128
BoooomCTL/Controller/SVPWM/SVPWM.c
Normal file
@@ -0,0 +1,128 @@
|
||||
//
|
||||
// Created by ZK on 2023/3/16.
|
||||
//
|
||||
|
||||
#include "SVPWM.h"
|
||||
|
||||
|
||||
inline int svpwm(float alpha, float beta, float *tA, float *tB, float *tC) {
|
||||
int Sextant;
|
||||
if (beta >= 0.0f) {
|
||||
if (alpha >= 0.0f) {
|
||||
//quadrant I
|
||||
if (ONE_BY_SQRT3 * beta > alpha)
|
||||
Sextant = 2; //sextant v2-v3
|
||||
else
|
||||
Sextant = 1; //sextant v1-v2
|
||||
|
||||
} else {
|
||||
//quadrant II
|
||||
if (-ONE_BY_SQRT3 * beta > alpha)
|
||||
Sextant = 3; //sextant v3-v4
|
||||
else
|
||||
Sextant = 2; //sextant v2-v3
|
||||
}
|
||||
} else {
|
||||
if (alpha >= 0.0f) {
|
||||
//quadrant IV
|
||||
if (-ONE_BY_SQRT3 * beta > alpha)
|
||||
Sextant = 5; //sextant v5-v6
|
||||
else
|
||||
Sextant = 6; //sextant v6-v1
|
||||
} else {
|
||||
//quadrant III
|
||||
if (ONE_BY_SQRT3 * beta > alpha)
|
||||
Sextant = 4; //sextant v4-v5
|
||||
else
|
||||
Sextant = 5; //sextant v5-v6
|
||||
}
|
||||
}
|
||||
|
||||
switch (Sextant) {
|
||||
// sextant v1-v2
|
||||
case 1: {
|
||||
// Vector on-times
|
||||
float t1 = alpha - ONE_BY_SQRT3 * beta;
|
||||
float t2 = TWO_BY_SQRT3 * beta;
|
||||
|
||||
// PWM timings
|
||||
*tA = (1.0f - t1 - t2) * 0.5f;
|
||||
*tB = *tA + t1;
|
||||
*tC = *tB + t2;
|
||||
}
|
||||
break;
|
||||
|
||||
// sextant v2-v3
|
||||
case 2: {
|
||||
// Vector on-times
|
||||
float t2 = alpha + ONE_BY_SQRT3 * beta;
|
||||
float t3 = -alpha + ONE_BY_SQRT3 * beta;
|
||||
|
||||
// PWM timings
|
||||
*tB = (1.0f - t2 - t3) * 0.5f;
|
||||
*tA = *tB + t3;
|
||||
*tC = *tA + t2;
|
||||
}
|
||||
break;
|
||||
|
||||
// sextant v3-v4
|
||||
case 3: {
|
||||
// Vector on-times
|
||||
float t3 = TWO_BY_SQRT3 * beta;
|
||||
float t4 = -alpha - ONE_BY_SQRT3 * beta;
|
||||
|
||||
// PWM timings
|
||||
*tB = (1.0f - t3 - t4) * 0.5f;
|
||||
*tC = *tB + t3;
|
||||
*tA = *tC + t4;
|
||||
}
|
||||
break;
|
||||
|
||||
// sextant v4-v5
|
||||
case 4: {
|
||||
// Vector on-times
|
||||
float t4 = -alpha + ONE_BY_SQRT3 * beta;
|
||||
float t5 = -TWO_BY_SQRT3 * beta;
|
||||
|
||||
// PWM timings
|
||||
*tC = (1.0f - t4 - t5) * 0.5f;
|
||||
*tB = *tC + t5;
|
||||
*tA = *tB + t4;
|
||||
}
|
||||
break;
|
||||
|
||||
// sextant v5-v6
|
||||
case 5: {
|
||||
// Vector on-times
|
||||
float t5 = -alpha - ONE_BY_SQRT3 * beta;
|
||||
float t6 = alpha - ONE_BY_SQRT3 * beta;
|
||||
|
||||
// PWM timings
|
||||
*tC = (1.0f - t5 - t6) * 0.5f;
|
||||
*tA = *tC + t5;
|
||||
*tB = *tA + t6;
|
||||
}
|
||||
break;
|
||||
|
||||
// sextant v6-v1
|
||||
case 6: {
|
||||
// Vector on-times
|
||||
float t6 = -TWO_BY_SQRT3 * beta;
|
||||
float t1 = alpha + ONE_BY_SQRT3 * beta;
|
||||
|
||||
// PWM timings
|
||||
*tA = (1.0f - t6 - t1) * 0.5f;
|
||||
*tC = *tA + t1;
|
||||
*tB = *tC + t6;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// if any of the results becomes NaN, result_valid will evaluate to false
|
||||
int result_valid =
|
||||
*tA >= 0.0f && *tA <= 1.0f
|
||||
&& *tB >= 0.0f && *tB <= 1.0f
|
||||
&& *tC >= 0.0f && *tC <= 1.0f;
|
||||
|
||||
return result_valid ? 0 : -1;
|
||||
}
|
||||
14
BoooomCTL/Controller/SVPWM/SVPWM.h
Normal file
14
BoooomCTL/Controller/SVPWM/SVPWM.h
Normal file
@@ -0,0 +1,14 @@
|
||||
//
|
||||
// Created by ZK on 2023/3/16.
|
||||
//
|
||||
|
||||
#ifndef BOOOOMFOC_STSPIN32G4_EVB_SVPWM_H
|
||||
#define BOOOOMFOC_STSPIN32G4_EVB_SVPWM_H
|
||||
|
||||
#define M_PI (3.14159265358f)
|
||||
#define M_2PI (6.28318530716f)
|
||||
#define ONE_BY_SQRT3 (0.57735026919f)
|
||||
#define TWO_BY_SQRT3 (2.0f * 0.57735026919f)
|
||||
#define SQRT3_BY_2 (0.86602540378f)
|
||||
|
||||
#endif //BOOOOMFOC_STSPIN32G4_EVB_SVPWM_H
|
||||
31
BoooomCTL/Data/Angle/Angle.c
Normal file
31
BoooomCTL/Data/Angle/Angle.c
Normal file
@@ -0,0 +1,31 @@
|
||||
//
|
||||
// Created by ZK on 2023/3/14.
|
||||
//
|
||||
|
||||
#include "Angle.h"
|
||||
|
||||
|
||||
//#define EncoderName MT6816
|
||||
float32_t getAngle_MT6816() {
|
||||
// printf("Test");
|
||||
|
||||
return M_PI;
|
||||
}
|
||||
|
||||
float32_t getAngle_AS5600() {
|
||||
// printf("Test");
|
||||
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
bool Data_Init(tData *data) {
|
||||
switch (data->Angle.EncoderModel) {
|
||||
case MT6816:
|
||||
data->Angle.getAngle = getAngle_MT6816;
|
||||
break;
|
||||
case AS5600:
|
||||
data->Angle.getAngle = getAngle_AS5600;
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
66
BoooomCTL/Data/Angle/Angle.h
Normal file
66
BoooomCTL/Data/Angle/Angle.h
Normal file
@@ -0,0 +1,66 @@
|
||||
//
|
||||
// Created by ZK on 2023/3/14.
|
||||
//
|
||||
|
||||
#ifndef BOOOOMFOC_STSPIN32G4_EVB_ANGLE_H
|
||||
#define BOOOOMFOC_STSPIN32G4_EVB_ANGLE_H
|
||||
|
||||
#include "APP_Main.h"
|
||||
|
||||
typedef enum {
|
||||
MT6816,
|
||||
AS5600
|
||||
} tEncoderModel;
|
||||
|
||||
typedef struct {
|
||||
tEncoderModel EncoderModel;
|
||||
|
||||
float32_t (*getAngle)();
|
||||
} tAngle;
|
||||
|
||||
typedef struct {
|
||||
tAngle Angle;
|
||||
|
||||
float32_t (*Angle_Init)();
|
||||
} tData;
|
||||
|
||||
float32_t getAngle_MT6816();
|
||||
|
||||
float32_t getAngle_AS5600();
|
||||
|
||||
bool Data_Init(tData *data);
|
||||
|
||||
|
||||
typedef struct sMT6825 {
|
||||
bool no_mag;
|
||||
bool over_speed;
|
||||
uint32_t angle;
|
||||
|
||||
uint8_t rx_err_count;
|
||||
uint8_t check_err_count;
|
||||
} tMT6825;
|
||||
|
||||
typedef struct sEncoder {
|
||||
int raw;
|
||||
int count_in_cpr;
|
||||
int count_in_cpr_prev;
|
||||
|
||||
int64_t shadow_count;
|
||||
|
||||
// pll use
|
||||
float pos_cpr_counts;
|
||||
float vel_estimate_counts;
|
||||
|
||||
float pos;
|
||||
float vel;
|
||||
|
||||
float phase;
|
||||
float phase_vel;
|
||||
|
||||
float pll_kp;
|
||||
float pll_ki;
|
||||
float interpolation;
|
||||
float snap_threshold;
|
||||
} tEncoder;
|
||||
|
||||
#endif //BOOOOMFOC_STSPIN32G4_EVB_ANGLE_H
|
||||
5
BoooomCTL/Data/Angle/MT6816/MT6816.c
Normal file
5
BoooomCTL/Data/Angle/MT6816/MT6816.c
Normal file
@@ -0,0 +1,5 @@
|
||||
//
|
||||
// Created by ZK on 2023/3/14.
|
||||
//
|
||||
|
||||
#include "MT6816.h"
|
||||
8
BoooomCTL/Data/Angle/MT6816/MT6816.h
Normal file
8
BoooomCTL/Data/Angle/MT6816/MT6816.h
Normal file
@@ -0,0 +1,8 @@
|
||||
//
|
||||
// Created by ZK on 2023/3/14.
|
||||
//
|
||||
|
||||
#ifndef BOOOOMFOC_STSPIN32G4_EVB_MT6816_H
|
||||
#define BOOOOMFOC_STSPIN32G4_EVB_MT6816_H
|
||||
|
||||
#endif //BOOOOMFOC_STSPIN32G4_EVB_MT6816_H
|
||||
5
BoooomCTL/Data/Current/Current.c
Normal file
5
BoooomCTL/Data/Current/Current.c
Normal file
@@ -0,0 +1,5 @@
|
||||
//
|
||||
// Created by ZK on 2023/3/14.
|
||||
//
|
||||
|
||||
#include "Current.h"
|
||||
8
BoooomCTL/Data/Current/Current.h
Normal file
8
BoooomCTL/Data/Current/Current.h
Normal file
@@ -0,0 +1,8 @@
|
||||
//
|
||||
// Created by ZK on 2023/3/14.
|
||||
//
|
||||
|
||||
#ifndef BOOOOMFOC_STSPIN32G4_EVB_CURRENT_H
|
||||
#define BOOOOMFOC_STSPIN32G4_EVB_CURRENT_H
|
||||
|
||||
#endif //BOOOOMFOC_STSPIN32G4_EVB_CURRENT_H
|
||||
21
BoooomCTL/Data/Current/InteriorADC/InteriorADC.c
Normal file
21
BoooomCTL/Data/Current/InteriorADC/InteriorADC.c
Normal file
@@ -0,0 +1,21 @@
|
||||
//
|
||||
// Created by ZK on 2023/3/14.
|
||||
//
|
||||
|
||||
#include "InteriorADC.h"
|
||||
|
||||
|
||||
bool InteriorADC_Init(void) {
|
||||
//使能ADC注入
|
||||
HAL_ADCEx_Calibration_Start(&hadc1, ADC_SINGLE_ENDED);
|
||||
HAL_ADCEx_Calibration_Start(&hadc2, ADC_SINGLE_ENDED);
|
||||
|
||||
HAL_Delay(100);
|
||||
HAL_ADCEx_InjectedStart(&hadc1);
|
||||
__HAL_ADC_ENABLE_IT(&hadc1, ADC_IT_JEOC);
|
||||
HAL_ADCEx_InjectedStart(&hadc2);
|
||||
__HAL_ADC_ENABLE_IT(&hadc2, ADC_IT_JEOC);
|
||||
|
||||
|
||||
return 0;//返回值为零表示初始化成功
|
||||
}
|
||||
12
BoooomCTL/Data/Current/InteriorADC/InteriorADC.h
Normal file
12
BoooomCTL/Data/Current/InteriorADC/InteriorADC.h
Normal file
@@ -0,0 +1,12 @@
|
||||
//
|
||||
// Created by ZK on 2023/3/14.
|
||||
//
|
||||
|
||||
#ifndef BOOOOMFOC_STSPIN32G4_EVB_INTERIORADC_H
|
||||
#define BOOOOMFOC_STSPIN32G4_EVB_INTERIORADC_H
|
||||
#include "APP_Main.h"
|
||||
|
||||
|
||||
bool InteriorADC_Init(void);
|
||||
|
||||
#endif //BOOOOMFOC_STSPIN32G4_EVB_INTERIORADC_H
|
||||
5
BoooomCTL/Data/Data.c
Normal file
5
BoooomCTL/Data/Data.c
Normal file
@@ -0,0 +1,5 @@
|
||||
//
|
||||
// Created by ZK on 2023/3/14.
|
||||
//
|
||||
|
||||
#include "Data.h"
|
||||
8
BoooomCTL/Data/Data.h
Normal file
8
BoooomCTL/Data/Data.h
Normal file
@@ -0,0 +1,8 @@
|
||||
//
|
||||
// Created by ZK on 2023/3/14.
|
||||
//
|
||||
|
||||
#ifndef BOOOOMFOC_STSPIN32G4_EVB_DATA_H
|
||||
#define BOOOOMFOC_STSPIN32G4_EVB_DATA_H
|
||||
|
||||
#endif //BOOOOMFOC_STSPIN32G4_EVB_DATA_H
|
||||
5
BoooomCTL/Data/Temperature/Temperature.c
Normal file
5
BoooomCTL/Data/Temperature/Temperature.c
Normal file
@@ -0,0 +1,5 @@
|
||||
//
|
||||
// Created by ZK on 2023/3/14.
|
||||
//
|
||||
|
||||
#include "Temperature.h"
|
||||
8
BoooomCTL/Data/Temperature/Temperature.h
Normal file
8
BoooomCTL/Data/Temperature/Temperature.h
Normal file
@@ -0,0 +1,8 @@
|
||||
//
|
||||
// Created by ZK on 2023/3/14.
|
||||
//
|
||||
|
||||
#ifndef BOOOOMFOC_STSPIN32G4_EVB_TEMPERATURE_H
|
||||
#define BOOOOMFOC_STSPIN32G4_EVB_TEMPERATURE_H
|
||||
|
||||
#endif //BOOOOMFOC_STSPIN32G4_EVB_TEMPERATURE_H
|
||||
5
BoooomCTL/Data/Voltage/Voltage.c
Normal file
5
BoooomCTL/Data/Voltage/Voltage.c
Normal file
@@ -0,0 +1,5 @@
|
||||
//
|
||||
// Created by ZK on 2023/3/14.
|
||||
//
|
||||
|
||||
#include "Voltage.h"
|
||||
8
BoooomCTL/Data/Voltage/Voltage.h
Normal file
8
BoooomCTL/Data/Voltage/Voltage.h
Normal file
@@ -0,0 +1,8 @@
|
||||
//
|
||||
// Created by ZK on 2023/3/14.
|
||||
//
|
||||
|
||||
#ifndef BOOOOMFOC_STSPIN32G4_EVB_VOLTAGE_H
|
||||
#define BOOOOMFOC_STSPIN32G4_EVB_VOLTAGE_H
|
||||
|
||||
#endif //BOOOOMFOC_STSPIN32G4_EVB_VOLTAGE_H
|
||||
5
BoooomCTL/Parameter/Parameter.c
Normal file
5
BoooomCTL/Parameter/Parameter.c
Normal file
@@ -0,0 +1,5 @@
|
||||
//
|
||||
// Created by ZK on 2023/3/14.
|
||||
//
|
||||
|
||||
#include "Parameter.h"
|
||||
8
BoooomCTL/Parameter/Parameter.h
Normal file
8
BoooomCTL/Parameter/Parameter.h
Normal file
@@ -0,0 +1,8 @@
|
||||
//
|
||||
// Created by ZK on 2023/3/14.
|
||||
//
|
||||
|
||||
#ifndef BOOOOMFOC_STSPIN32G4_EVB_PARAMETER_H
|
||||
#define BOOOOMFOC_STSPIN32G4_EVB_PARAMETER_H
|
||||
|
||||
#endif //BOOOOMFOC_STSPIN32G4_EVB_PARAMETER_H
|
||||
7361
BoooomCTL/Utils/arm_math.h
Normal file
7361
BoooomCTL/Utils/arm_math.h
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user