From 1366e141921cfa373b383bcc907522b3f5196193 Mon Sep 17 00:00:00 2001 From: raiden00pl Date: Sat, 19 Feb 2022 21:10:09 +0100 Subject: [PATCH] libdsp: initialize flux_link in params, remove flux_link from pmsm_phy_params --- include/dsp.h | 6 +++--- include/dspb16.h | 9 ++++----- libs/libdsp/lib_motor.c | 8 +++++--- libs/libdsp/lib_motor_b16.c | 8 +++++--- libs/libdsp/lib_pmsm_model.c | 4 ++-- libs/libdsp/lib_pmsm_model_b16.c | 4 ++-- 6 files changed, 21 insertions(+), 18 deletions(-) diff --git a/include/dsp.h b/include/dsp.h index a1b4726221..c6f1e14c5d 100644 --- a/include/dsp.h +++ b/include/dsp.h @@ -383,7 +383,7 @@ struct motor_phy_params_f32_s { uint8_t p; /* Number of the motor pole pairs */ float flux_link; /* Flux linkage */ - float res; /* Phase-to-neutral resistance */ + float res; /* Average phase-to-neutral resistance */ float ind; /* Average phase-to-neutral inductance */ float one_by_ind; /* Inverse phase-to-neutral inductance */ float one_by_p; /* Inverse number of motor pole pairs */ @@ -395,7 +395,6 @@ struct pmsm_phy_params_f32_s { struct motor_phy_params_f32_s motor; /* Motor common PHY */ float iner; /* Rotor inertia */ - float flux_link; /* Flux linkage */ float ind_d; /* d-inductance */ float ind_q; /* q-inductance */ float one_by_iner; /* One by intertia */ @@ -583,7 +582,8 @@ float motor_angle_e_get(FAR struct motor_angle_f32_s *angle); /* Motor physical parameters */ void motor_phy_params_init(FAR struct motor_phy_params_f32_s *phy, - uint8_t poles, float res, float ind); + uint8_t poles, float res, float ind, + float fluxlink); /* PMSM physical parameters functions */ diff --git a/include/dspb16.h b/include/dspb16.h index 41ce1276fc..5763627901 100644 --- a/include/dspb16.h +++ b/include/dspb16.h @@ -294,9 +294,8 @@ struct foc_data_b16_s struct motor_phy_params_b16_s { uint8_t p; /* Number of the motor pole pairs */ - b16_t res; /* Phase-to-neutral temperature compensated - * resistance - */ + b16_t flux_link; /* Flux linkage */ + b16_t res; /* Average phase-to-neutral resistance */ b16_t ind; /* Average phase-to-neutral inductance */ b16_t one_by_ind; /* Inverse phase-to-neutral inductance */ b16_t one_by_p; /* Inverse number of motor pole pairs */ @@ -308,7 +307,6 @@ struct pmsm_phy_params_b16_s { struct motor_phy_params_b16_s motor; /* Motor common PHY */ b16_t iner; /* Rotor inertia */ - b16_t flux_link; /* Flux linkage */ b16_t ind_d; /* d-inductance */ b16_t ind_q; /* q-inductance */ b16_t one_by_iner; /* One by J */ @@ -467,7 +465,8 @@ b16_t motor_angle_e_get_b16(FAR struct motor_angle_b16_s *angle); /* Motor physical parameters */ void motor_phy_params_init_b16(FAR struct motor_phy_params_b16_s *phy, - uint8_t poles, b16_t res, b16_t ind); + uint8_t poles, b16_t res, b16_t ind, + b16_t fluxlink); /* PMSM physical parameters functions */ diff --git a/libs/libdsp/lib_motor.c b/libs/libdsp/lib_motor.c index 20959a873d..6411c0ea8d 100644 --- a/libs/libdsp/lib_motor.c +++ b/libs/libdsp/lib_motor.c @@ -355,6 +355,7 @@ float motor_angle_e_get(FAR struct motor_angle_f32_s *angle) * res - (in) average phase-to-neutral base motor resistance * (without temperature compensation) * ind - (in) average phase-to-neutral motor inductance + * flux - (in) flux linkage * * Returned Value: * None @@ -362,13 +363,15 @@ float motor_angle_e_get(FAR struct motor_angle_f32_s *angle) ****************************************************************************/ void motor_phy_params_init(FAR struct motor_phy_params_f32_s *phy, - uint8_t poles, float res, float ind) + uint8_t poles, float res, float ind, + float flux_link) { LIBDSP_DEBUGASSERT(phy != NULL); memset(phy, 0, sizeof(struct motor_phy_params_f32_s)); phy->p = poles; + phy->flux_link = flux_link; phy->res = res; phy->ind = ind; phy->one_by_ind = (1.0f / ind); @@ -406,12 +409,11 @@ void pmsm_phy_params_init(FAR struct pmsm_phy_params_f32_s *phy, /* Initialize motor phy */ - motor_phy_params_init(&phy->motor, poles, res, ind); + motor_phy_params_init(&phy->motor, poles, res, ind, flux); /* Iniitalize PMSM specific data */ phy->iner = iner; - phy->flux_link = flux; phy->ind_d = ind_d; phy->ind_q = ind_q; phy->one_by_iner = (1.0f / iner); diff --git a/libs/libdsp/lib_motor_b16.c b/libs/libdsp/lib_motor_b16.c index d7af1680d5..1ddb5a266c 100644 --- a/libs/libdsp/lib_motor_b16.c +++ b/libs/libdsp/lib_motor_b16.c @@ -307,6 +307,7 @@ b16_t motor_angle_e_get_b16(FAR struct motor_angle_b16_s *angle) * res - (in) average phase-to-neutral base motor resistance * (without temperature compensation) * ind - (in) average phase-to-neutral motor inductance + * flux - (in) flux linkage * * Returned Value: * None @@ -314,13 +315,15 @@ b16_t motor_angle_e_get_b16(FAR struct motor_angle_b16_s *angle) ****************************************************************************/ void motor_phy_params_init_b16(FAR struct motor_phy_params_b16_s *phy, - uint8_t poles, b16_t res, b16_t ind) + uint8_t poles, b16_t res, b16_t ind, + b16_t flux_link) { LIBDSP_DEBUGASSERT(phy != NULL); memset(phy, 0, sizeof(struct motor_phy_params_b16_s)); phy->p = poles; + phy->flux_link = flux_link; phy->res = res; phy->ind = ind; phy->one_by_ind = b16divb16(b16ONE, ind); @@ -358,12 +361,11 @@ void pmsm_phy_params_init_b16(FAR struct pmsm_phy_params_b16_s *phy, /* Initialize motor phy */ - motor_phy_params_init_b16(&phy->motor, poles, res, ind); + motor_phy_params_init_b16(&phy->motor, poles, res, ind, flux); /* Iniitalize PMSM specific data */ phy->iner = iner; - phy->flux_link = flux; phy->ind_d = ind_d; phy->ind_q = ind_q; phy->one_by_iner = b16divb16(b16ONE, iner); diff --git a/libs/libdsp/lib_pmsm_model.c b/libs/libdsp/lib_pmsm_model.c index cc7f6588b2..4a2c687118 100644 --- a/libs/libdsp/lib_pmsm_model.c +++ b/libs/libdsp/lib_pmsm_model.c @@ -187,7 +187,7 @@ int pmsm_model_elec(FAR struct pmsm_model_f32_s *model, tmp1 = model->phy.motor.res * model->state.i_dq.q; tmp2 = model->phy.ind_d * model->state.i_dq.d; - tmp3 = tmp2 + model->phy.flux_link; + tmp3 = tmp2 + model->phy.motor.flux_link; tmp4 = model->state.omega_e * tmp3; tmp5 = model->state.v_dq.q - tmp1 - tmp4; tmp6 = model->per * tmp5; @@ -248,7 +248,7 @@ int pmsm_model_mech(FAR struct pmsm_model_f32_s *model, float load) tmp1 = model->phy.ind_d - model->phy.ind_q; tmp2 = tmp1 * model->state.i_dq.d; - tmp3 = model->phy.flux_link - tmp2; + tmp3 = model->phy.motor.flux_link - tmp2; tmp4 = 1.5f * model->phy.motor.p; tmp5 = tmp4 * model->state.i_dq.q; diff --git a/libs/libdsp/lib_pmsm_model_b16.c b/libs/libdsp/lib_pmsm_model_b16.c index c85beb7f02..b2bd9bc6c8 100644 --- a/libs/libdsp/lib_pmsm_model_b16.c +++ b/libs/libdsp/lib_pmsm_model_b16.c @@ -100,7 +100,7 @@ int pmsm_model_elec_b16(FAR struct pmsm_model_b16_s *model, tmp1 = b16mulb16(model->phy.motor.res, model->state.i_dq.q); tmp2 = b16mulb16(model->phy.ind_d, model->state.i_dq.d); - tmp3 = tmp2 + model->phy.flux_link; + tmp3 = tmp2 + model->phy.motor.flux_link; tmp4 = b16mulb16(model->state.omega_e, tmp3); tmp5 = model->state.v_dq.q - tmp1 - tmp4; tmp6 = b16mulb16(model->per, tmp5); @@ -161,7 +161,7 @@ int pmsm_model_mech_b16(FAR struct pmsm_model_b16_s *model, b16_t load) tmp1 = model->phy.ind_d - model->phy.ind_q; tmp2 = b16mulb16(tmp1, model->state.i_dq.d); - tmp3 = model->phy.flux_link - tmp2; + tmp3 = model->phy.motor.flux_link - tmp2; tmp4 = b16mulb16((b16ONE + b16HALF), itob16(model->phy.motor.p)); tmp5 = b16mulb16(tmp4, model->state.i_dq.q);