examples/foc: initialize motor phy
This commit is contained in:
parent
9ee4daea43
commit
9bcca69967
@ -98,6 +98,37 @@ config EXAMPLES_FOC_SENSORED
|
||||
|
||||
endchoice #
|
||||
|
||||
menu "Motor phy"
|
||||
|
||||
config EXAMPLES_FOC_MOTOR_POLES
|
||||
int "FOC example motor poles pairs"
|
||||
default 0
|
||||
|
||||
config EXAMPLES_FOC_MOTOR_RES
|
||||
int "FOC example motor phase resistance (x1000000)"
|
||||
default 0
|
||||
---help---
|
||||
The unit is micro-ohm (1/1000000 ohm).
|
||||
|
||||
config EXAMPLES_FOC_MOTOR_IND
|
||||
int "FOC example motor phase inductance (x1000000)"
|
||||
default 0
|
||||
---help---
|
||||
The unit is micro micro-henry (1/1000000 henry).
|
||||
|
||||
config EXAMPLES_FOC_MOTOR_FLUXLINK
|
||||
int "FOC example motor flux linkage (x1000000)"
|
||||
default 0
|
||||
---help---
|
||||
The unit is micro-Vs (1/1000000 Vs).
|
||||
Flux linkage can be obtained from the formula:
|
||||
lambda_pm = (1 / sqrt(3)) * (60 / 2*PI) * (Ke / P) [Vs]
|
||||
where:
|
||||
Ke - motor voltage constant Ke [V/rpm]
|
||||
P - motor pole pairs
|
||||
|
||||
endmenu # Motor phy
|
||||
|
||||
if EXAMPLES_FOC_SENSORED
|
||||
|
||||
choice
|
||||
@ -115,10 +146,6 @@ endchoice # FOC sensored sensor selection
|
||||
|
||||
if EXAMPLES_FOC_HAVE_QENCO
|
||||
|
||||
config EXAMPLES_FOC_MOTOR_POLES
|
||||
int "FOC example motor poles pairs"
|
||||
default 0
|
||||
|
||||
config EXAMPLES_FOC_QENCO_POSMAX
|
||||
int "FOC example qencoder maximum position"
|
||||
default 0
|
||||
|
@ -364,11 +364,13 @@ static int foc_motor_configure(FAR struct foc_motor_b16_s *motor)
|
||||
|
||||
foc_handler_cfg_b16(&motor->handler, &ctrl_cfg, &mod_cfg);
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_FOC_MOTOR_POLES
|
||||
/* Configure motor poles */
|
||||
/* Configure motor phy */
|
||||
|
||||
motor->poles = CONFIG_EXAMPLES_FOC_MOTOR_POLES;
|
||||
#endif
|
||||
motor_phy_params_init_b16(&motor->phy,
|
||||
CONFIG_EXAMPLES_FOC_MOTOR_POLES,
|
||||
ftob16(CONFIG_EXAMPLES_FOC_MOTOR_RES / 1000000.0f),
|
||||
ftob16(CONFIG_EXAMPLES_FOC_MOTOR_IND / 1000000.0f),
|
||||
ftob16(CONFIG_EXAMPLES_FOC_MOTOR_FLUXLINK / 1000000.0f));
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_FOC_STATE_USE_MODEL_PMSM
|
||||
/* Initialize PMSM model */
|
||||
@ -1200,7 +1202,8 @@ int foc_motor_get(FAR struct foc_motor_b16_s *motor)
|
||||
/* Convert mechanical angle to electrical angle */
|
||||
|
||||
motor->angle_el = (b16muli(motor->angle_m,
|
||||
motor->poles) % MOTOR_ANGLE_E_MAX_B16);
|
||||
motor->phy.poles) %
|
||||
MOTOR_ANGLE_E_MAX_B16);
|
||||
}
|
||||
|
||||
else
|
||||
|
@ -133,7 +133,7 @@ struct foc_motor_b16_s
|
||||
struct foc_model_b16_s model; /* Model handler */
|
||||
struct foc_model_state_b16_s model_state; /* PMSM model state */
|
||||
#endif
|
||||
uint8_t poles; /* Motor poles */
|
||||
struct motor_phy_params_b16_s phy; /* Motor phy */
|
||||
|
||||
/* Motor velocity and angle handlers **************************************/
|
||||
|
||||
|
@ -362,11 +362,13 @@ static int foc_motor_configure(FAR struct foc_motor_f32_s *motor)
|
||||
|
||||
foc_handler_cfg_f32(&motor->handler, &ctrl_cfg, &mod_cfg);
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_FOC_MOTOR_POLES
|
||||
/* Configure motor poles */
|
||||
/* Configure motor phy */
|
||||
|
||||
motor->poles = CONFIG_EXAMPLES_FOC_MOTOR_POLES;
|
||||
#endif
|
||||
motor_phy_params_init(&motor->phy,
|
||||
CONFIG_EXAMPLES_FOC_MOTOR_POLES,
|
||||
CONFIG_EXAMPLES_FOC_MOTOR_RES / 1000000.0f,
|
||||
CONFIG_EXAMPLES_FOC_MOTOR_IND / 1000000.0f,
|
||||
CONFIG_EXAMPLES_FOC_MOTOR_FLUXLINK / 1000000.0f);
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_FOC_STATE_USE_MODEL_PMSM
|
||||
/* Initialize PMSM model */
|
||||
@ -1185,7 +1187,7 @@ int foc_motor_get(FAR struct foc_motor_f32_s *motor)
|
||||
|
||||
/* Convert mechanical angle to electrical angle */
|
||||
|
||||
motor->angle_el = fmodf(motor->angle_m * motor->poles,
|
||||
motor->angle_el = fmodf(motor->angle_m * motor->phy.poles,
|
||||
MOTOR_ANGLE_E_MAX);
|
||||
}
|
||||
|
||||
|
@ -133,7 +133,7 @@ struct foc_motor_f32_s
|
||||
struct foc_model_f32_s model; /* Model handler */
|
||||
struct foc_model_state_f32_s model_state; /* PMSM model state */
|
||||
#endif
|
||||
uint8_t poles; /* Motor poles */
|
||||
struct motor_phy_params_f32_s phy; /* Motor phy */
|
||||
|
||||
/* Motor velocity and angle handlers **************************************/
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user