mirror of https://github.com/rusefi/bldc.git
Add MTPA support
Signed-off-by: Marcos Chaparro <mchaparro@powerdesigns.ca>
This commit is contained in:
parent
b1915b06a7
commit
42926d530e
|
@ -72,6 +72,7 @@ int32_t confgenerator_serialize_mcconf(uint8_t *buffer, const mc_configuration *
|
|||
buffer_append_float32_auto(buffer, conf->foc_pll_kp, &ind);
|
||||
buffer_append_float32_auto(buffer, conf->foc_pll_ki, &ind);
|
||||
buffer_append_float32_auto(buffer, conf->foc_motor_l, &ind);
|
||||
buffer_append_float32_auto(buffer, conf->foc_motor_ld_lq_diff, &ind);
|
||||
buffer_append_float32_auto(buffer, conf->foc_motor_r, &ind);
|
||||
buffer_append_float32_auto(buffer, conf->foc_motor_flux_linkage, &ind);
|
||||
buffer_append_float32_auto(buffer, conf->foc_observer_gain, &ind);
|
||||
|
@ -365,6 +366,7 @@ bool confgenerator_deserialize_mcconf(const uint8_t *buffer, mc_configuration *c
|
|||
conf->foc_pll_kp = buffer_get_float32_auto(buffer, &ind);
|
||||
conf->foc_pll_ki = buffer_get_float32_auto(buffer, &ind);
|
||||
conf->foc_motor_l = buffer_get_float32_auto(buffer, &ind);
|
||||
conf->foc_motor_ld_lq_diff = buffer_get_float32_auto(buffer, &ind);
|
||||
conf->foc_motor_r = buffer_get_float32_auto(buffer, &ind);
|
||||
conf->foc_motor_flux_linkage = buffer_get_float32_auto(buffer, &ind);
|
||||
conf->foc_observer_gain = buffer_get_float32_auto(buffer, &ind);
|
||||
|
@ -654,6 +656,7 @@ void confgenerator_set_defaults_mcconf(mc_configuration *conf) {
|
|||
conf->foc_pll_kp = MCCONF_FOC_PLL_KP;
|
||||
conf->foc_pll_ki = MCCONF_FOC_PLL_KI;
|
||||
conf->foc_motor_l = MCCONF_FOC_MOTOR_L;
|
||||
conf->foc_motor_ld_lq_diff = MCCONF_FOC_MOTOR_LD_LQ_DIFF;
|
||||
conf->foc_motor_r = MCCONF_FOC_MOTOR_R;
|
||||
conf->foc_motor_flux_linkage = MCCONF_FOC_MOTOR_FLUX_LINKAGE;
|
||||
conf->foc_observer_gain = MCCONF_FOC_OBSERVER_GAIN;
|
||||
|
|
|
@ -8,8 +8,8 @@
|
|||
#include <stdbool.h>
|
||||
|
||||
// Constants
|
||||
#define MCCONF_SIGNATURE 1775793947
|
||||
#define APPCONF_SIGNATURE 2662993821
|
||||
#define MCCONF_SIGNATURE 2013508732
|
||||
#define APPCONF_SIGNATURE 2460147246
|
||||
|
||||
// Functions
|
||||
int32_t confgenerator_serialize_mcconf(uint8_t *buffer, const mc_configuration *conf);
|
||||
|
|
|
@ -277,6 +277,7 @@ typedef struct {
|
|||
float foc_encoder_cos_gain;
|
||||
float foc_encoder_sincos_filter_constant;
|
||||
float foc_motor_l;
|
||||
float foc_motor_ld_lq_diff;
|
||||
float foc_motor_r;
|
||||
float foc_motor_flux_linkage;
|
||||
float foc_observer_gain;
|
||||
|
|
|
@ -263,6 +263,9 @@
|
|||
#ifndef MCCONF_FOC_MOTOR_FLUX_LINKAGE
|
||||
#define MCCONF_FOC_MOTOR_FLUX_LINKAGE 0.00245
|
||||
#endif
|
||||
#ifndef MCCONF_FOC_MOTOR_LD_LQ_DIFF
|
||||
#define MCCONF_FOC_MOTOR_LD_LQ_DIFF 0.0
|
||||
#endif
|
||||
#ifndef MCCONF_FOC_OBSERVER_GAIN
|
||||
#define MCCONF_FOC_OBSERVER_GAIN 9e7 // Can be something like 600 / L
|
||||
#endif
|
||||
|
|
14
mcpwm_foc.c
14
mcpwm_foc.c
|
@ -195,6 +195,7 @@ static void terminal_plot_hfi(int argc, const char **argv);
|
|||
static void timer_update(volatile motor_all_state_t *motor, float dt);
|
||||
static void input_current_offset_measurement( void );
|
||||
static void hfi_update(volatile motor_all_state_t *motor);
|
||||
static void apply_mtpa(float *id, float *iq, volatile motor_all_state_t *motor);
|
||||
|
||||
// Threads
|
||||
static THD_WORKING_AREA(timer_thread_wa, 1024);
|
||||
|
@ -2541,6 +2542,8 @@ void mcpwm_foc_adc_int_handler(void *p, uint32_t flags) {
|
|||
motor_now->m_motor_state.phase = motor_now->m_phase_now_override;
|
||||
}
|
||||
|
||||
apply_mtpa(&id_set_tmp, &iq_set_tmp, motor_now);
|
||||
|
||||
// Apply current limits
|
||||
// TODO: Consider D axis current for the input current as well.
|
||||
const float mod_q = motor_now->m_motor_state.mod_q;
|
||||
|
@ -3981,3 +3984,14 @@ static void terminal_plot_hfi(int argc, const char **argv) {
|
|||
commands_printf("This command requires one argument.\n");
|
||||
}
|
||||
}
|
||||
|
||||
static void apply_mtpa(float *id, float *iq, volatile motor_all_state_t *motor) {
|
||||
float ld_lq_diff = motor->m_conf->foc_motor_ld_lq_diff;
|
||||
|
||||
if(ld_lq_diff != 0.0){
|
||||
float lambda = motor->m_conf->foc_motor_flux_linkage;
|
||||
|
||||
*id = (lambda - sqrtf(SQ(lambda) + 8.0 * SQ(ld_lq_diff) * SQ(*iq))) / (4.0 * ld_lq_diff);
|
||||
*iq = SIGN(*iq) * sqrtf(SQ(*iq) - SQ(*id));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue