add config.h ; try to OpenLoop control, not passed

This commit is contained in:
2025-11-13 15:16:24 +08:00
parent c67d13de54
commit ab6d7c0dd9
9 changed files with 133 additions and 35 deletions

View File

@@ -1,11 +1,14 @@
#include <stdlib.h>
#include <stdio.h>
#include "pwm.h"
#include "mt6701.h"
#include "delay.h"
#include "lowpass_filter.h"
#include "pid_control.h"
#include <math.h>
#include <ti_msp_dl_config.h>
#include "config.h"
#define PI 3.14159265359f
#define _3PI_2 4.71238898f
@@ -20,6 +23,8 @@ float zero_electric_Angle = 0.0;
extern int pp;
extern int Dir;
void Motor_en()
{
// GPIO_InitTypeDef GPIO_InitStructure;
@@ -66,9 +71,16 @@ void SetPwm(float Ua, float Ub, float Uc)
dc_b = constrain(U_b / voltage_power_supply, 0.0f, 1.0f);
dc_c = constrain(U_c / voltage_power_supply, 0.0f, 1.0f);
PWM_Channel1(dc_a * 4800.0f); // 频率15k
PWM_Channel2(dc_b * 4800.0f);
PWM_Channel3(dc_c * 4800.0f);
PWM_Channel1(dc_a * 1000.0f); // 频率15k
PWM_Channel2(dc_b * 1000.0f);
PWM_Channel3(dc_c * 1000.0f);
if(DEBUG_ENABLED & DEBUG_DFOC)
{
printf("dc_a %f \n", dc_a);
printf("dc_b %f \n", dc_b);
printf("dc_c %f \n", dc_c);
}
}
@@ -120,7 +132,40 @@ void Set_Angle(float Target)
SetPhaseVoltage(Uq, 0, electricAngle());
}
double shaft_angle;
double openloop_timestamp;
float velocityopenloop(float target)
{
float Uq = 0.0;
double Ts = 0.0;
uint32_t now_ts = DL_SYSTICK_getValue();
if(now_ts < openloop_timestamp)
{
Ts = (openloop_timestamp - now_ts) / 32.0f * 1e-6f;
}
else
{
Ts = (0xFFFFFF - now_ts + openloop_timestamp) / 32.0f * 1e-6f;
}
if(Ts < 0 || Ts >= 0.005)
{
Ts = 0.001f;
}
shaft_angle = normalizeAngle(shaft_angle + pp * target * Ts);
Uq = voltage_limit;
SetPhaseVoltage(Uq, 0, shaft_angle);
openloop_timestamp = now_ts;
return Uq;
}